If I copy the the SQL Query right into mysql the same thing happens, so it is actually kind of a mysql problem, but since Django created the query, I thought I might get help here.
I did not call any select_related or something.
On my dev machine I am using sqlite and the same query does not cause any trouble and returns within 4 ms.
There are less not more than 5 rows in each table, so database size cannot be a problem.
Any ideas? where to start debugging this?
In the mysql shell:
EXPLAIN SELECT ...
Cheers
Tom
> In the mysql shell:
>
> EXPLAIN SELECT ...
unfortunately same problem. CPU turns to 100% and it is stuck.
Is it possible that there is some sort of circular inner joints or something?
http://dev.mysql.com/doc/refman/5.0/en/controlling-optimizer.html
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_optimizer_search_depth
My query had over 20 INNER JOINTS and it made the optimizer search a long process.
So at the moment a value of 3 is fine.
SQL is like regular expressions. You can go complex (with one mega query/expression) but it could create a maintenance nightmare. See if you cannot simplify the query into multiple queries and a bit of code (for loops and using the joining columns) to lash them together. The code sequence should be such that you limit access to a huge amount of rows; so you filter the data accessed. It is usually easier to debug as well. And using Tom's advice (EXPLAIN SELECT ...) on smaller join queries is often more useful (than the explain on a mega join query).
In my experience it often runs way faster if the query is simplified.
Regards
Chris
http://dev.mysql.com/doc/refman/5.0/en/controlling-optimizer.html
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_optimizer_search_depth
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
thanks for the info. My tables won’t have many rows and I don’t have the time for optimazation, especially if it is not necessary, but I will keep your words in mind!
Cheers
Ivo