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:
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.my $sth = $dbh->prepare($sql); $sth->{"mysql_use_result"} = 1;
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.
_ _ _ _ (_|| | |(_|>< _|
In Section
Seekers of Perl Wisdom