Don’t Quote Your Numbers
It’s a fairly simple rule, and something that should be obeyed for your health and sanity.
There are a couple of bugs which you could run into, when quoting large numbers. First of all, Bug #34384. This is concerning quoting large INTs in the WHERE condition of an UPDATE or DELETE. It seems that this will cause a table scan, which is going to be slooooow on big tables.
Similarly, there is the more recently discovered Bug #43319. You can run into this if you quote large INTs in the IN clause of a SELECT … WHERE. For example:
mysql> EXPLAIN SELECT * FROM a WHERE a IN('9999999999999999999999')\G *************************** 1. row *************************** id: 1 select_type: SIMPLE TABLE: NULL type: NULL possible_keys: NULL KEY: NULL key_len: NULL ref: NULL rows: NULL Extra: Impossible WHERE noticed after reading const TABLES 1 row IN SET (0.00 sec) mysql> EXPLAIN SELECT * FROM a WHERE a IN('9999999999999999999999', '9999999999999999999999')\G *************************** 1. row *************************** id: 1 select_type: SIMPLE TABLE: a type: ALL possible_keys: PRIMARY KEY: NULL key_len: NULL ref: NULL rows: 655360 Extra: USING WHERE 1 row IN SET (0.00 sec)
Note that you only run into it when you quote multiple large numbers.
Anyway, the long and the short of this post is: if at all possible, don’t quote numbers. MySQL will love you for it.
Comments
2 Responses to “Don’t Quote Your Numbers”
Leave a Reply



i.e. supply all data types explicitly — which is just a nuicance — or don’t use parameterized queries with DBD::mysql? cruel world.
You make a good point. I’ve submitted a bug report to DBD::mysql to not quote numbers:
https://rt.cpan.org/Ticket/Display.html?id=43822