help with making my code more efficient
rosuav at gmail.com
Fri Dec 21 03:56:52 CET 2012
On Fri, Dec 21, 2012 at 11:43 AM, Larry.Martell at gmail.com
<Larry.Martell at gmail.com> wrote:
> It came from a database. Originally I was getting just the data I wanted using SQL, but that was taking too long also. I was selecting just the messages I wanted, then for each one of those doing another query to get the data within the time diff of each. That was resulting in tens of thousands of queries. So I changed it to pull all the potential matches at once and then process it in python.
Then the best thing to do is figure out how to solve your problem in
SQL. Any decent database engine will be able to optimize that
beautifully, and without multiple recursive searches. You may need to
create an index, but maybe not even that.
I can't speak for other engines, but PostgreSQL has an excellently
helpful mailing list, if you have problems with that side of it. But
have a shot at writing the SQL; chances are it'll work out easily.
More information about the Python-list