Benchmark needed: WHERE id='$id' ... vs. WHERE id=$id

Has somebody ever run a test to measure time differences of queries like:

SELECT foo FROM bar WHERE id=’$id’


SELECT foo FROM bar WHERE id=$id

assumed that column id is an integer?

What i would like to know is how mutch these ‘…’ influence the evaluation. I bet there is some difference (some CPU cycles needed for the string-to-integer cast) and i guess that it is really small compared to the time needed for seeking, ordering, joining, etc…

Nevertheless it could be interesting to know. Maybe the difference would be bigger when several expressions are combined like:

SELECT foo FROM bar WHERE a=’$a’ AND b=’$b’ AND c=’$c’ AND d=’$d’


SELECT foo FROM bar WHERE a=$a AND b=$b AND c=$c AND d=$d

Anybody who can offer some statistics?

Without the quotes is required for the column to be compared as an integer. Otherwise, MySQL may be forced to cast the internally stored id integer as a string type before comparing it to the value in the quotes.

This would mean indexes wouldn’t be utalized and the query wouldn’t run optimally.

Of course, without the quotes the query will fail if one of the columns is not an integer. Therefore i assumed that all columns are integers, i didn’t want to benchmark error messages. :wink:

I once checked a query with quotes via EXPLAIN and MySQL did use the primary index. Without quotes EXPLAIN showed the same information, so index usage was not affected by the ‘’ and the cast.

Unfortunately i have neither the experience nor the environment to run serious benchmarks here and i have no bigger database which i could use for it (as i guess that with only 150 rows no difference can be seen). Maybe somebody with more experience, a dedicated MySQL server and a large database could help me by running this benchmark?