Skip to content

MySql drove me crazy!

August 10, 2009

Today, I was trying to optimize some mysql query in our experiment framework.I came across to two query explains that I cannot understand.

Here are the two queries:

explain select * from TABLE_NAME where created > ‘2009-08-09 19:10:44′

explain select * from TABLE_NAME where created > ‘2009-08-09 20:10:44

′and here are the explain results:

mysql> explain select * from TABLE_NAME where created > ‘2009-08-09 19:10:44′;

+—-+————-+——————+——+—————+——+———+——+———+————-+

| id | select_type | table            | type | possible_keys | key  | key_len | ref  | rows    | Extra       |+—-+————-+——————+——+—————+——+———+——+———+————-+

|  1 | SIMPLE      | TABLE_NAME | ALL  | ou_created    | NULL | NULL    | NULL | 1226122 | Using where

|+—-+————-+——————+——+—————+——+———+——+———+————-+

1 row in set (0.00 sec)

mysql>explain select * from TABLE_NAME where created > ‘2009-08-09 20:10:44′;

+—-+————-+——————+——-+—————+————+———+——+——–+————-+

| id | select_type | table            | type  | possible_keys | key        | key_len | ref  | rows   | Extra       |+—-+————-+——————+——-+—————+————+———+——+——–+————-+

|  1 | SIMPLE      | TABLE_NAME | range | ou_created    | ou_created | 4       | NULL | 206400 | Using where |

+—-+————-+——————+——-+—————+————+———+——+——–+————-+

1 row in set (0.00 sec)when you change the parameter you search, mysql changes query plan in a wrong way,interesting, isn’t it ? (fyi, my mysql version is: 5.0.51a)

Advertisement

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.