Meituan-Dianping / Meituan-Dianping/SQLAdvisor

优化出现一个报错

Open
#29 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
5.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

sql是可以查询的,但是优化过程出现了select * from * 结果报错,想请您帮忙看下,谢谢

优化sql:SELECT e.id, e.target_id, e.target_num, e.client_name, e.business_name, e.collection_name, e.client_order_num, e.region, e.pick_time, e.late_age, e.households, e.amount, e.BALANCEMONEY, ( e.amount - e.BALANCEMONEY - e.apply_money ) chargeMoney, e.agent_term, e.rateStr, ( SELECT f.KEY_VALUE FROM t_data_dictionary f WHERE f.KEY_NAME = 'targetState' AND f.KEY_PROP = e.audit_status ) audit_status, e.CREATE_TIME, e.UPDATE_TIME, e.target_type, e.signTarget, e.collection_commission, e.platform_rate, m.debt_type_1 debtType1, e.come_from, e.CREATE_TIME, e.due_time, m.balance_type balanceType, m.typeBank5, m.typeCount1, m.typeCount2, m.typeCount3, m.typeCount4, m.typeCount5, m.typeCountName1, m.typeCountName2, m.typeCountName5, e.audit_status auditStatusFalg, e.apply_money, e.collection_info_id FROM e_client_target e, ( SELECT m.balance_type, m.typeBank5, m.typeCount1, m.typeCount2, m.typeCount3, m.typeCount4, m.typeCount5, m.typeCountName1, m.typeCountName2, m.typeCountName5, m.debt_type_1, m.client_target_id FROM d_debtor_info m GROUP BY m.client_target_id ) m WHERE e.target_id = m.client_target_id GROUP BY m.client_target_id ORDER BY e.pick_time DESC

优化输出
2017-05-03 11:10:01 2341 [Note] 第1步: 对SQL解析优化之后得到的SQL:select e.id AS id,e.target_id AS target_id,e.target_num AS target_num,e.client_name AS client_name,e.business_name AS business_name,e.collection_name AS collection_name,e.client_order_num AS client_order_num,e.region AS region,e.pick_time AS pick_time,e.late_age AS late_age,e.households AS households,e.amount AS amount,e.BALANCEMONEY AS BALANCEMONEY,((e.amount - e.BALANCEMONEY) - e.apply_money) AS chargeMoney,e.agent_term AS agent_term,e.rateStr AS rateStr,(...) AS audit_status,e.CREATE_TIME AS CREATE_TIME,e.UPDATE_TIME AS UPDATE_TIME,e.target_type AS target_type,e.signTarget AS signTarget,e.collection_commission AS collection_commission,e.platform_rate AS platform_rate,m.debt_type_1 AS debtType1,e.come_from AS come_from,e.CREATE_TIME AS CREATE_TIME,e.due_time AS due_time,m.balance_type AS `balan
2017-05-03 11:10:01 2341 [Note] 第2步:开始解析join on条件:e.target_id=m.client_target_id

2017-05-03 11:10:01 2341 [Note] 第3步:表* 是临时表,不进行处理

2017-05-03 11:10:01 2341 [Note] 第4步:开始选择驱动表,一共有2个候选驱动表

2017-05-03 11:10:01 2341 [Note] explain select * from e_client_target

2017-05-03 11:10:01 2341 [Note] 第5步:候选驱动表e_client_target的结果集行数为:629

2017-05-03 11:10:01 2341 [Note] explain select * from *

2017-05-03 11:10:01 2341 [Note] 第6步:SQLAdvisor结束!错误日志: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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported SQL and tracing the optimizer log around the message that the table * is temporary, especially the generated EXPLAIN statements. Check how the derived subquery is represented when selecting a driving table; done means the optimizer no longer generates invalid EXPLAIN SQL such as select * from * and reports or completes the optimization correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, mysql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.