Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Much slower DBI on RHEL6

by Tux (Monsignor)
on Feb 06, 2014 at 12:44 UTC ( #1073703=note: print w/ replies, xml ) Need Help??


in reply to Re: Much slower DBI on RHEL6
in thread Much slower DBI on RHEL6

Nice start, but fetching hashrefs is the slowest possible access method. Binding return values might improve a lot

my $dbh = $me->{DBHANDLE}; my %labels; # Get all the different ids my $sth = $dbh->prepare ("select distinct id from list_index"); $sth->execute; $sth->bind_columns (\my $id); my $sth2 = $dbh->prepare (qq; select description from list_index where id = ? order by rpt_key desc; # -- I don't know if limit 1 is needed ); $sth2->execute (0); $sth2->bind_columns (\my $desc); while ($sth->fetch) { $sth2->execute ($id); while ($sth2->fetch) { $labels{$id} = "$id - $desc"; } } $_->finish for $sth, $sth2; return \%labels;

Enjoy, Have FUN! H.Merijn


Comment on Re^2: Much slower DBI on RHEL6
Download Code
Re^3: Much slower DBI on RHEL6
by McA (Priest) on Feb 06, 2014 at 13:02 UTC

    Hi Tux,

    the focus in my proposal was on using bind variables and using a prepared statement more than once. But you're right, when someone is hunting the milliseconds, your approach should be faster.

    Thank you and ++.

    Best regards
    McA

      More than milliseconds. Last time I tested on MySQL, it was 5 to 10 times faster. (also this table where higher numbers are better)


      Enjoy, Have FUN! H.Merijn

        Probably a big number of milliseconds... ;-)

        I start to be curious about the timings in our environment. Especially when you really want a list of hash refs as the result of a db querying function. So, is it worth to build up the hash on your own or let DBI do the stuff for you.

        Probably I have the time to investigate this question. But anyways thank you again for the link.

        Best regards
        McA

Re^3: Much slower DBI on RHEL6
by MPM (Novice) on Feb 06, 2014 at 21:15 UTC

    thank you EVERYBODY for the responses. I didn't mention it before but I had tried optimizing things by using different types of fetches, binding, etc. but nothing seemed to help that much. However, I do have things working much faster now( even faster than it was on RHEL 4)!. I don't know why, but here is what I found thanks to tux's post. I do need the "limit 1" because otherwise, I don't get the most recent description, I get the oldest. However, for whatever reason, when I use desc AND limit 1 things are slloooww. Without "limit 1" things are fast... So, it is much faster for me to iterate through all of the rows of ids just to get the "latest" than it is for me to sort in descending order and get just 1. Hope that makes sense. Thanks again everyone. My code is much more optimized and I'm sure throughout the application there are things can be optimized and more secure so I am going to work on that. So, in short, still don't know why the same exact Perl code, with the same data, is much slower on RHEL 6 but my issue is resolved. So this is the code I ended up using and it is faster and seems to give me the correct results

    my $dbh = $me->{DBHANDLE}; my %labels; # Get all the different ids my $sth = $dbh->prepare ("select distinct id from list_index"); $sth->execute; $sth->bind_columns (\my $id); my $sth2 = $dbh->prepare (qq; select description from list_index where id = ? order by rpt_key; ); $sth2->execute (0); $sth2->bind_columns (\my $desc); while ($sth->fetch) { $sth2->execute ($id); while ($sth2->fetch) { $labels{$id} = "$id - $desc"; } } $_->finish for $sth, $sth2; return \%labels;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1073703]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2014-12-25 10:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls