在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

Percona MySQL 5.6 WHERE条件中OR的索引测试该怎么进行

214次阅读
没有评论

共计 9551 个字符,预计需要花费 24 分钟才能阅读完成。

本篇文章给大家分享的是有关 Percona MySQL 5.6 WHERE 条件中 OR 的索引测试该怎么进行,丸趣 TV 小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着丸趣 TV 小编一起来看看吧。

在测试表的两列上分别创建索引。
mysql select * from test;
+——+——-+
| id  | name  |
+——+——-+
|  10 | neo  |
|  20 | John  |
|  30 | Lucy  |
|  40 | Larry |
|  50 | Lilly |
+——+——-+
5 rows in set (0.00 sec)
mysql show keys from test;
Empty set (0.01 sec)

mysql create index idx_test_id on test(id);
Query OK, 0 rows affected (0.34 sec)
Records: 0  Duplicates: 0  Warnings: 0
mysql create index idx_test_name on test(name);
Query OK, 0 rows affected (0.72 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql show keys from test;
+——-+————+—————+————–+————-+———–+————-+———-+——–+——+————+———+—————+
| Table | Non_unique | Key_name  | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+——-+————+—————+————–+————-+———–+————-+———-+——–+——+————+———+—————+
| test  |  1 | idx_test_id  |  1 | id  | A  |  5 |  NULL | NULL  | YES  | BTREE  |  |  |
| test  |  1 | idx_test_name |  1 | name  | A  |  5 |  NULL | NULL  | YES  | BTREE  |  |  |
+——-+————+—————+————–+————-+———–+————-+———-+——–+——+————+———+—————+
2 rows in set (0.02 sec)

在 OR 条件中分别涵盖这两列,会使用到这两个索引。

mysql explain select * from test where id=10;
+—-+————-+——-+——+—————+————-+———+——-+——+——-+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra |
+—-+————-+——-+——+—————+————-+———+——-+——+——-+
|  1 | SIMPLE  | test  | ref  | idx_test_id  | idx_test_id | 5  | const |  1 | NULL  |
+—-+————-+——-+——+—————+————-+———+——-+——+——-+
1 row in set (0.00 sec)

mysql explain select * from test where name= Lucy
+—-+————-+——-+——+—————+—————+———+——-+——+———————–+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra  |
+—-+————-+——-+——+—————+—————+———+——-+——+———————–+
|  1 | SIMPLE  | test  | ref  | idx_test_name | idx_test_name | 18  | const |  1 | Using index condition |
+—-+————-+——-+——+—————+—————+———+——-+——+———————–+
1 row in set (0.00 sec)

mysql explain select * from test where id=10 or name= Lucy
+—-+————-+——-+——+—————————+——+———+——+——+————-+
| id | select_type | table | type | possible_keys  | key  | key_len | ref  | rows | Extra  |
+—-+————-+——-+——+—————————+——+———+——+——+————-+
|  1 | SIMPLE  | test  | ALL  | idx_test_id,idx_test_name | NULL | NULL  | NULL |  5 | Using where |
+—-+————-+——-+——+—————————+——+———+——+——+————-+
1 row in set (0.00 sec)

mysql explain select * from test where id=20 or name= Lucy
+—-+————-+——-+——+—————————+——+———+——+——+————-+
| id | select_type | table | type | possible_keys  | key  | key_len | ref  | rows | Extra  |
+—-+————-+——-+——+—————————+——+———+——+——+————-+
|  1 | SIMPLE  | test  | ALL  | idx_test_id,idx_test_name | NULL | NULL  | NULL |  5 | Using where |
+—-+————-+——-+——+—————————+——+———+——+——+————-+
1 row in set (0.00 sec)

mysql explain select * from test where id=50 or name= neo
+—-+————-+——-+——+—————————+——+———+——+——+————-+
| id | select_type | table | type | possible_keys  | key  | key_len | ref  | rows | Extra  |
+—-+————-+——-+——+—————————+——+———+——+——+————-+
|  1 | SIMPLE  | test  | ALL  | idx_test_id,idx_test_name | NULL | NULL  | NULL |  5 | Using where |
+—-+————-+——-+——+—————————+——+———+——+——+————-+
1 row in set (0.00 sec)

删除这两个索引,重建一个索引,在 OR 条件中会使用到这一个索引。

mysql drop index idx_test_id;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near at line 1
mysql drop index idx_test_id on test;
Query OK, 0 rows affected (0.33 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql drop index idx_test_name on test;
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql create index idx_test_id on test(id);
Query OK, 0 rows affected (0.09 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql explain select * from test where id=50 or name= neo
+—-+————-+——-+——+—————+——+———+——+——+————-+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra  |
+—-+————-+——-+——+—————+——+———+——+——+————-+
|  1 | SIMPLE  | test  | ALL  | idx_test_id  | NULL | NULL  | NULL |  5 | Using where |
+—-+————-+——-+——+—————+——+———+——+——+————-+
1 row in set (0.00 sec)

mysql explain select * from test where name= neo
+—-+————-+——-+——+—————+——+———+——+——+————-+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra  |
+—-+————-+——-+——+—————+——+———+——+——+————-+
|  1 | SIMPLE  | test  | ALL  | NULL  | NULL | NULL  | NULL |  5 | Using where |
+—-+————-+——-+——+—————+——+———+——+——+————-+
1 row in set (0.00 sec)

mysql explain select * from test where name= Lucy
+—-+————-+——-+——+—————+——+———+——+——+————-+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra  |
+—-+————-+——-+——+—————+——+———+——+——+————-+
|  1 | SIMPLE  | test  | ALL  | NULL  | NULL | NULL  | NULL |  5 | Using where |
+—-+————-+——-+——+—————+——+———+——+——+————-+
1 row in set (0.00 sec)

删除表中的索引,创建一个包含这两列的联合索引,在 OR 条件中会使用到这个索引。发现在 MySQL 里面联合索引的应用规则和 Oracle 中不同,单独查询条件中只含一列的 WHERE 条件,如创建联合索引的字段顺位为 A、B,在 B 上的查询也会使用联合索引。

mysql drop index idx_test_name on test;
ERROR 1091 (42000): Can t DROP idx_test_name check that column/key exists
mysql drop index idx_test_id on test;
Query OK, 0 rows affected (0.09 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql create index idx_test_id_name on test(id,name);
Query OK, 0 rows affected (0.21 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql show keys from test;
+——-+————+——————+————–+————-+———–+————-+———-+——–+——+————+———+—————+
| Table | Non_unique | Key_name  | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+——-+————+——————+————–+————-+———–+————-+———-+——–+——+————+———+—————+
| test  |  1 | idx_test_id_name |  1 | id  | A  |  5 |  NULL | NULL  | YES  | BTREE  |  |  |
| test  |  1 | idx_test_id_name |  2 | name  | A  |  5 |  NULL | NULL  | YES  | BTREE  |  |  |
+——-+————+——————+————–+————-+———–+————-+———-+——–+——+————+———+—————+
2 rows in set (0.00 sec)

mysql explain select * from test where name= Lucy
+—-+————-+——-+——-+—————+——————+———+——+——+————————–+
| id | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra  |
+—-+————-+——-+——-+—————+——————+———+——+——+————————–+
|  1 | SIMPLE  | test  | index | NULL  | idx_test_id_name | 23  | NULL |  5 | Using where; Using index |
+—-+————-+——-+——-+—————+——————+———+——+——+————————–+
1 row in set (0.00 sec)

mysql explain select * from test where name= neo
+—-+————-+——-+——-+—————+——————+———+——+——+————————–+
| id | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra  |
+—-+————-+——-+——-+—————+——————+———+——+——+————————–+
|  1 | SIMPLE  | test  | index | NULL  | idx_test_id_name | 23  | NULL |  5 | Using where; Using index |
+—-+————-+——-+——-+—————+——————+———+——+——+————————–+
1 row in set (0.00 sec)

mysql explain select * from test where id=10;
+—-+————-+——-+——+——————+——————+———+——-+——+————-+
| id | select_type | table | type | possible_keys  | key  | key_len | ref  | rows | Extra  |
+—-+————-+——-+——+——————+——————+———+——-+——+————-+
|  1 | SIMPLE  | test  | ref  | idx_test_id_name | idx_test_id_name | 5  | const |  1 | Using index |
+—-+————-+——-+——+——————+——————+———+——-+——+————-+
1 row in set (0.00 sec)

mysql explain select * from test where id=10 or name= Lucy
+—-+————-+——-+——-+——————+——————+———+——+——+————————–+
| id | select_type | table | type  | possible_keys  | key  | key_len | ref  | rows | Extra  |
+—-+————-+——-+——-+——————+——————+———+——+——+————————–+
|  1 | SIMPLE  | test  | index | idx_test_id_name | idx_test_id_name | 23  | NULL |  5 | Using where; Using index |
+—-+————-+——-+——-+——————+——————+———+——+——+————————–+
1 row in set (0.00 sec)

以上就是 Percona MySQL 5.6 WHERE 条件中 OR 的索引测试该怎么进行,丸趣 TV 小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注丸趣 TV 行业资讯频道。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-27发表,共计9551字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 毛片在线免费观看网站 | 欧美色图另类小说 | 久久精品岛国av一区二区无码 | 黄色片网址 | 日本一区二区三区免费高清 | 亚洲 欧美 日韩 在线 香蕉 | 四虎影视无码永久免费 | 亚洲男人的天堂一区二区 | 久久国产首页 | 熟妇人妻va精品中文字幕 | 俺去啦最新官网 | 伊人伊成久久人综合网777 | 天堂网在线.www天堂在线资源 | 久久综合伊人中文字幕 | 亚洲av综合av一区 | 日韩人妻一区二区三区免费 | 日本一区二区三区四区五区 | 精品丝袜人妻久久久久久 | 成人一级黄色大片 | 日本韩无专砖码高清 | 毛片视频免费 | 日韩亚洲人成在线综合日本 | 在线观看特色大片免费网站 | 四虎影院在线观看免费 | 欧美一级艳片视频免费观看 | 精品少妇人妻av一区二区 | 女子张开腿让男人桶视频 | 亚洲精品国产第一区第二区国 | 亚洲av永久无码天堂网 | 蜜桃影片在线播放网站免费观看 | 99久在线观看 | 506rr亚洲欧美 | 亚洲av成人综合网久久成人 | 中文字幕欧美日韩久久 | 中文字幕日本特黄aa毛片 | 99久久精品毛片免费播放高潮 | 久久社区 | 亚洲精品福利一区二区 | 欧美精品久久久久久久自慰 | 欧美日韩国产另类一区二区三区 | 无码国产精成人午夜视频一区二区 |