优化建立索引有问题
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Reproduce the reported SQLAdvisor index recommendation with the three tables and query from the issue, then trace the index-suggestion entry point that produces the ALTER statement for table c. The fix is complete when the recommendation contains user_id only once and the generated ALTER statement executes without the duplicate-column error.
Written by the indexing model from the issue text.
Description
有a/b/c三张表
create table a (id int auto_increment,seller_id bigint,seller_name varchar(100) collate utf8_bin ,gmt_create varchar(30),primary key(id));
create table b (id int auto_increment,seller_name varchar(100),user_id varchar(50),user_name varchar(100),sales bigint,gmt_create varchar(30),primary key(id));
create table c (id int auto_increment,user_id varchar(50),order_id varchar(100),state bigint,gmt_create varchar(30),primary key(id));
使用sql
select a.seller_id,a.seller_name,b.user_name,c.state
from a,b,c
where a.seller_name=b.seller_name
and b.user_id=c.user_id
and c.user_id=17
and a.gmt_create BETWEEN DATE_ADD(NOW(), INTERVAL - 600 MINUTE)
AND DATE_ADD(NOW(), INTERVAL 600 MINUTE)
order by a.gmt_create
然后在建议c表时出现如下优化语句:
2017-07-19 11:15:53 4364 [Note] 第31步:开始验证 字段user_id是不是主键。表名:c
2017-07-19 11:15:53 4364 [Note] show index from c where Key_name = 'PRIMARY' and Column_name ='user_id' and Seq_in_index = 1
2017-07-19 11:15:53 4364 [Note] 第32步:字段user_id不是主键。表名:c
2017-07-19 11:15:53 4364 [Note] 第33步:开始验证 字段user_id是不是主键。表名:c
2017-07-19 11:15:53 4364 [Note] show index from c where Key_name = 'PRIMARY' and Column_name ='user_id' and Seq_in_index = 1
2017-07-19 11:15:53 4364 [Note] 第34步:字段user_id不是主键。表名:c
2017-07-19 11:15:53 4364 [Note] 第35步:开始验证表中是否已存在相关索引。表名:c, 字段名:user_id, 在索引中的位置:1
2017-07-19 11:15:53 4364 [Note] show index from c where Column_name ='user_id' and Seq_in_index =1
2017-07-19 11:15:53 4364 [Note] 第36步:开始验证 字段user_id是不是主键。表名:c
2017-07-19 11:15:53 4364 [Note] show index from c where Key_name = 'PRIMARY' and Column_name ='user_id' and Seq_in_index = 1
2017-07-19 11:15:53 4364 [Note] 第37步:字段user_id不是主键。表名:c
2017-07-19 11:15:53 4364 [Note] 第38步:开始验证表中是否已存在相关索引。表名:c, 字段名:user_id, 在索引中的位置:2
2017-07-19 11:15:53 4364 [Note] show index from c where Column_name ='user_id' and Seq_in_index =2
2017-07-19 11:15:53 4364 [Note] 第39步:开始输出表c索引优化建议:
2017-07-19 11:15:53 4364 [Note] Create_Index_SQL:alter table c add index idx_user_id_user_id(user_id,user_id)
这个建议有两个user_id,但是语句执行错误的
[Err] 1060 - Duplicate column name 'user_id' 。
麻烦看一下。
- Dominant language
- C
- Stars
- 5.6k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Meituan-Dianping/SQLAdvisor
-
修复了一些安装问题和代码bugOpen
Difficulty 5/5 Over a week Newbie friendliness 25/100
Meituan-Dianping/SQLAdvisor#100 ·
-
有纯洁的docker 镜像么?Open
Difficulty 4/5 3-5 days Newbie friendliness 20/100
-
连接访问不到Open
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
Meituan-Dianping/SQLAdvisor#97 · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
All issues in Meituan-Dianping/SQLAdvisor
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
johnsonjh/emu2-cpm86#68 · 1 comment ·
Maintainers usually reply within 1 day
-
Zenmap CrashOpenZenmap
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
fastfetch-cli/fastfetch#2619 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Template: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
betaflight/betaflight#15759 ·
Maintainers usually reply within 1 day