Monday, October 27, 2014

Re: Slow SQL query

Hi Erik,

No luck...

mysql> show indexes in order_order;
+-------------+------------+----------------------+--------------+----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table       | Non_unique | Key_name             | Seq_in_index | Column_name    | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------------+------------+----------------------+--------------+----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| order_order |          0 | PRIMARY              |            1 | id             | A         |      311492 |     NULL | NULL   |      | BTREE      |         |               |
| order_order |          1 | order_order_8df3c379 |            1 | order_number   | A         |      311492 |     NULL | NULL   |      | BTREE      |         |               |
| order_order |          1 | order_order_fbfc09f1 |            1 | user_id        | A         |           8 |     NULL | NULL   | YES  | BTREE      |         |               |
| order_order |          1 | order_order_979d4f1e |            1 | account_number | A         |      311492 |     NULL | NULL   |      | BTREE      |         |               |
| order_order |          1 | order_order_48fb58bb |            1 | status         | A         |          10 |     NULL | NULL   |      | BTREE      |         |               |
| order_order |          1 | order_order_482713d4 |            1 | user_id        | A         |          12 |     NULL | NULL   | YES  | BTREE      |         |               |
| order_order |          1 | order_order_482713d4 |            2 | account_number | A         |      155746 |     NULL | NULL   |      | BTREE      |         |               |
| order_order |          1 | order_order_fb3214ea |            1 | status         | A         |         215 |     NULL | NULL   |      | BTREE      |         |               |
| order_order |          1 | order_order_fb3214ea |            2 | account_number | A         |         215 |     NULL | NULL   |      | BTREE      |         |               |
| order_order |          1 | order_order_55eb7e10 |            1 | status         | A         |         215 |     NULL | NULL   |      | BTREE      |         |               |
| order_order |          1 | order_order_55eb7e10 |            2 | user_id        | A         |         215 |     NULL | NULL   | YES  | BTREE      |         |               |
+-------------+------------+----------------------+--------------+----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+

mysql
> explain SELECT COUNT(*) FROM `order_order` WHERE `order_order`.`status` != 4  AND (`order_order`.`user_id` = 12345 OR `order_order`.`account_number` = 123456);
+----+-------------+-------------+------+-------------------------------------------------------------------------------------------------------------------------------+------+---------+------+--------+-------------+
| id | select_type | table       | type | possible_keys                                                                                                                 | key  | key_len | ref  | rows   | Extra       |
+----+-------------+-------------+------+-------------------------------------------------------------------------------------------------------------------------------+------+---------+------+--------+-------------+
|  1 | SIMPLE      | order_order | ALL  | order_order_fbfc09f1,order_order_979d4f1e,order_order_48fb58bb,order_order_482713d4,order_order_fb3214ea,order_order_55eb7e10 | NULL | NULL    | NULL | 311492 | Using where |
+----+-------------+-------------+------+-------------------------------------------------------------------------------------------------------------------------------+------+---------+------+--------+-------------+

Thanks,
Collin

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/43b46cf3-891c-436a-8cd1-9dd4a0e6af18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment