Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: DBI/mysql gathering all rows on execute

by gmax (Abbot)
on Nov 24, 2003 at 20:39 UTC ( #309672=note: print w/replies, xml ) Need Help??


in reply to DBI/mysql gathering all rows on execute

There are two possible causes, perhaps both of them at the same time:

  • If there is no index in any of link1.link_from, url1.urlid, link1.link_to, and url2.urlid, then the join takes much longer than it should. If this is the case, add an appropriate index, using an ALTER TABLE statement.
  • Your query is returning an huge amount of rows, which are clogging both your server and client memory. The reason is that MySQL default mode of fetching is All-At-Once (mysql_store_result). You can affect this behavior by setting the appropriate mode identifier after preparing the statement:
    my $sth = $dbh->prepare($sql); $sth->{"mysql_use_result"} = 1;
    Be aware that this mode requires that you either fetch all the records or use a "finish" method before issuing another request to the server.
    See MySQL manual for an explanation of this behavior (it's related to the C API) and DBD::mysql for more details on this modifier in the DBD interface.
    With "mysql_use_result", as opposed to "mysql_store_result", the server won't send any record to the client until you use a "fetch" method. What happens with the default mode is that the server sends all the records at once, and the "fetch" method is just browsing a local copy of the data.
 _  _ _  _  
(_|| | |(_|><
 _|   

Replies are listed 'Best First'.
Re: Re: DBI/mysql gathering all rows on execute
by sgifford (Prior) on Nov 24, 2003 at 21:17 UTC

    Thanks, it was $sth->{"mysql_use_result"} = 1; that I needed!

    The right indexes are all in place (and EXPLAIN SELECT agrees), there are just a huge number of rows in the result set.

    Now here's the other weird thing, which doesn't matter for my real project but is still unusual. When I make this change, the test program I posted above works better, but now it hangs for a long time during the finish. That surprises me; I would expect it to cancel the query and return immediately. Anybody know what's going on?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2023-03-27 17:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (65 votes). Check out past polls.

    Notices?