51Testing软件测试论坛
标题:
Mysql两表关联不使用索引的问题
[打印本页]
作者:
测试积点老人
时间:
2020-10-9 13:33
标题:
Mysql两表关联不使用索引的问题
Mysql两表关联不使用索引的问题
两张表test_a,test_b结构和索引信息如下,通过主键inner join关联时,外表为什么不走索引呢?
<p>create table test_a (
id int,
birthday date not null,
comment varchar (50) not null,
primary key test_a_pk (id),
index test_a_index (birthday)
) engine = innodb default charset = utf8;</p><p>create table test_b (
id int,
salary double not null,
struct varchar (50) not null,
primary key test_b_pk (id),
index test_b_index (salary)
) engine = innodb default charset = utf8;</p><p>mysql> show index from test_a\G
*************************** 1. row ***************************
Table: test_a
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: id
Collation: A
Cardinality: 5375084
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 2. row ***************************
Table: test_a
Non_unique: 1
Key_name: test_a_index
Seq_in_index: 1
Column_name: birthday
Collation: A
Cardinality: 2728
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
2 rows in set (0.00 sec)</p><p>mysql> show index from test_b\G
*************************** 1. row ***************************
Table: test_b
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: id
Collation: A
Cardinality: 5291561
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 2. row ***************************
Table: test_b
Non_unique: 1
Key_name: test_b_index
Seq_in_index: 1
Column_name: salary
Collation: A
Cardinality: 943640
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
2 rows in set (0.00 sec)</p>
复制代码
作者:
海海豚
时间:
2020-10-10 09:37
https://bbs.csdn.net/topics/397786880?list=78425671
参考下
作者:
qqq911
时间:
2020-10-10 10:45
检查下是否都做了索引
作者:
郭小贱
时间:
2020-10-10 15:12
可以参考这篇文章看下:
https://q.cnblogs.com/q/129478/
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2