Don’t Quote Your Numbers

March 3, 2009 · Posted in MySQL · 2 Comments 

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.

  • Gary Pendergast, noun: Gamer, developer, MySQL, WordPress, web and music geek. Currently taking a leave of absence from life as a MySQL Support Engineer for Oracle to tour around Europe. Can be observed in his natural habit at pento.net, or usually in Bologna, Italy.

  • My Twitter

    • Touristing until early next week. Replies will be sporadic, at best. 5 days ago
    • Somewhat surprised at the number of #WordPress sites I see using "ugly" urls, /?page_id=555 5 days ago
    • Learned something today: .it domains need 1-2 days to change DNS servers, I guess the registry approves these changes manually. Oh, Italy. 6 days ago
    • SVN commit message to make me drop everything and run `svn up`: "Fix typo making all users admins" 6 days ago
    • Huh, #Filezilla owns #WinSCP for uploading large numbers of small files. 6 days ago
    • More updates...