Hi

(I hope I'm not asking to many 'stupid' questions... :)

This query runs very fast (time 0.01 seconds):
SELECT * from DB_GNIST.varer WHERE kategori = 24010 ORDER BY utgivelses_aar
DESC LIMIT 10;

This one is slow (time 0.73seconds):
SELECT * from DB_GNIST.varer WHERE kategori = '24010' ORDER BY
utgivelses_aar DESC LIMIT 10;

Fast (0.49 seconds):
SELECT count(*) from DB_GNIST.varer WHERE kategori = '24010' ODER BY
utgivelses_aar DESC LIMIT 10;
slow (10.47seconds):
SELECT count(*) from DB_GNIST.varer WHERE kategori = 24010 ODER BY
utgivelses_aar DESC LIMIT 10;

Fast (0.83)
SELECT * from DB_GNIST.varer a LEFT JOIN DB_GNIST.vare_bilder b ON a.isbn =
b.isbn WHERE kategori = '24010' ODER BY utgivelses_aar DESC LIMIT 10;
Slow (10.30)
SELECT * from DB_GNIST.varer a LEFT JOIN DB_GNIST.vare_bilder b ON a.isbn =
b.isbn WHERE kategori = 24010 ODER BY utgivelses_aar DESC LIMIT 10;


I can't seem to find the any documentation about how "col = 'something'" is
handled by mysql and how "col = something" is handled. They are obviously
handled in different ways. If you look at the two first queries, the fast
one is 73 times faster than the slow one. That's a huge difference.

On the last two queries the one with "kategori = 24010" will return a few
more records than the first one. But if I replace "=" with "LIKE" both
queries returns the same number of records, but the first one will still be
much faster.

Anyway, if I have missed something in the manual, please just tell me and
I'll go back reading it.


Erlend Stromsvik



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to