国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

mysql 5.7.11查詢分區表的一個難題

2024-07-24 12:31:30
字體:
來源:轉載
供稿:網友
      mysql 查詢一個分區表,當查詢條件存在數據時執行效率OK,當不存在數據時執行不完,一直在sending data,當去掉desc就沒問題。換個版本貌似也沒問題。
 
      mysql> select version();
 
+------------+
 
| version()  |
 
+------------+
 
| 5.7.11-log |
 
+------------+
 
1 row in set (0.00 sec)
 
2 rows in set (0.00 sec)
 
     mysql> explain SELECT * FROM history h WHERE h.itemid='106107' AND h.clock>1533723653 ORDER BY h.clock DESC LIMIT 2 OFFSET 0;
 
+----+-------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------+-------+-----------------------------+-----------+---------+------+------+----------+-----------------------+
 
      | id | select_type | table | partitions                                                                                                                              | type  | possible_keys               | key       | key_len | ref  | rows | filtered | Extra                 |
 
+----+-------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------+-------+-----------------------------+-----------+---------+------+------+----------+-----------------------+
 
      |  1 | SIMPLE      | h     | p201808,p201809,p201810,p201811,p201812,p201901,p201902,p201903,p201904,p201905,p201906,p201907,p201908,p201909,p201910,p201911,p201912 | range | history_1,idx_history_clock | history_1 | 12      | NULL |  172 |   100.00 | Using index condition |
 
+----+-------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------+-------+-----------------------------+-----------+---------+------+------+----------+-----------------------+
 
1 row in set, 1 warning (0.05 sec)
 
ysql> SELECT * FROM history h WHERE h.itemid='1061055' AND h.clock>1533723653 ORDER BY h.clock DESC LIMIT 2 OFFSET 0;
 
 
mysql> SELECT * FROM history h WHERE h.itemid='1061055' AND h.clock>1533723653 ORDER BY h.clock  LIMIT 2 OFFSET 0;
 
Empty set (0.00 sec)
 
mysql> explain SELECT * FROM history h WHERE h.itemid='1061055' AND h.clock>1533723653 ORDER BY h.clock  LIMIT 2 OFFSET 0;
 
+----+-------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------+-------+-----------------------------+-----------+---------+------+------+----------+-----------------------+
 
| id | select_type | table | partitions                                                                                                                              | type  | possible_keys               | key       | key_len | ref  | rows | filtered | Extra                 |
 
+----+-------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------+-------+-----------------------------+-----------+---------+------+------+----------+-----------------------+
 
|  1 | SIMPLE      | h     | p201808,p201809,p201810,p201811,p201812,p201901,p201902,p201903,p201904,p201905,p201906,p201907,p201908,p201909,p201910,p201911,p201912 | range | history_1,idx_history_clock | history_1 | 12      | NULL |    1 |   100.00 | Using index condition |
 
+----+-------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------+-------+-----------------------------+-----------+---------+------+------+----------+-----------------------+
 
1 row in set, 1 warning (0.00 sec)
 
創建了降序索引,效率提升
 
mysql> create index idx_history_2 on  history (itemid desc);
 
Query OK, 0 rows affected (36 min 50.11 sec)
 
Records: 0  Duplicates: 0  Warnings: 0
 
mysql>
 
mysql>  SELECT * FROM history h WHERE h.itemid='1060001055' AND h.clock>1533723653 ORDER BY h.clock DESC LIMIT 2 OFFSET 0;
 
Empty set (0.00 sec)
 
mysql> explain SELECT * FROM history h WHERE h.itemid='1060001055' AND h.clock>1533723653 ORDER BY h.clock DESC LIMIT 2 OFFSET 0;
 
+----+-------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------+------+-------------------------------------------+-----------+---------+-------+------+----------+-------------+
 
| id | select_type | table | partitions                                                                                                                              | type | possible_keys                             | key       | key_len | ref   | rows | filtered | Extra       |
 
+----+-------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------+------+-------------------------------------------+-----------+---------+-------+------+----------+-------------+
 
|  1 | SIMPLE      | h     | p201808,p201809,p201810,p201811,p201812,p201901,p201902,p201903,p201904,p201905,p201906,p201907,p201908,p201909,p201910,p201911,p201912 | ref  | history_1,idx_history_clock,idx_history_2 | history_1 | 8       | const |    1 |    31.59 | Using where |
 
+----+-------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------+------+-------------------------------------------+-----------+---------+-------+------+----------+-------------+
 
1 row in set, 1 warning (0.00 sec)
 
 
mysql> explain  SELECT * FROM history h WHERE h.itemid='1060001055' AND h.clock>1533723653 ORDER BY h.clock DESC LIMIT 2 OFFSET 0;
 
+----+-------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------+-------+-----------------------------+-----------+---------+------+------+----------+-----------------------+
 
| id | select_type | table | partitions                                                                                                                              | type  | possible_keys               | key       | key_len | ref  | rows | filtered | Extra                 |
 
+----+-------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------+-------+-----------------------------+-----------+---------+------+------+----------+-----------------------+
 
|  1 | SIMPLE      | h     | p201808,p201809,p201810,p201811,p201812,p201901,p201902,p201903,p201904,p201905,p201906,p201907,p201908,p201909,p201910,p201911,p201912 | range | history_1,idx_history_clock | history_1 | 12      | NULL |    1 |   100.00 | Using index condition |
 
+----+-------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------+-------+-----------------------------+-----------+---------+------+------+----------+-----------------------+
 
1 row in set, 1 warning (0.00 sec)

(編輯:武林網)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 甘肃省| 平乐县| 武邑县| 施甸县| 和顺县| 淮南市| 那曲县| 蓬溪县| 建湖县| 和平县| 临泽县| 衢州市| 当阳市| 崇阳县| 始兴县| 潜江市| 侯马市| 巢湖市| 东兴市| 泽州县| 马尔康县| 深圳市| 马公市| 闽清县| 新龙县| 霍邱县| 建瓯市| 潍坊市| 安西县| 德清县| 于都县| 泗阳县| 米易县| 泊头市| 武邑县| 灵宝市| 新营市| 黔江区| 商丘市| 永川市| 年辖:市辖区|