Benchmark needed: WHERE id='$id' ... vs. WHERE id=$id [message #1573] |
Mon, 06 August 2007 11:19  |
Spuerhund Messages: 4 Registered: August 2007 |
Junior Member |
|
|
Has somebody ever run a test to measure time differences of queries like:
SELECT foo FROM bar WHERE id='$id'
and
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'
against
SELECT foo FROM bar WHERE a=$a AND b=$b AND c=$c AND d=$d
Anybody who can offer some statistics?
[Updated on: Mon, 06 August 2007 11:20]
|
|
|
| Re: Benchmark needed: WHERE id='$id' ... vs. WHERE id=$id [message #1577 is a reply to message #1573 ] |
Tue, 07 August 2007 12:58   |
Speeple Messages: 91 Registered: August 2006 |
Member |
|
|
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.
Martin Gallagher | Speeple: The latest news
|
|
|
|
| Re: Benchmark needed: WHERE id='$id' ... vs. WHERE id=$id [message #1643 is a reply to message #1580 ] |
Fri, 17 August 2007 06:41  |
Peter Messages: 405 Registered: August 2006 |
Senior Member Super Guru |
|
|
Passing numbers in quotes normally works fine it is unquoted strings which is the problem
VARCHARCOL=1 and VARCHARCOL="1" have very different meaning.
In your case of integer columns you should have only minor parsing overhead - query execution will go same in most cases.
Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
|
|
|