pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
36.94k stars 5.81k forks source link

support baseline capturing for `UNION ALL`/`INTERSECT`/`EXCEPT` #21049

Open rebelice opened 3 years ago

rebelice commented 3 years ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

This issue is associated with #19932 and the PR for it doesn't consider baseline capturing.

1. Minimal reproduce step (Required)

drop table if exists t;
create table t(a int, b int, index a(a));
set @@tidb_capture_plan_baselines = on;
select * from t union all select * from t;
select * from t union all select * from t;
show global bindings;

2. What did you expect to see? (Required)

Not empty set.

3. What did you see instead (Required)

Empty set.

4. What is your TiDB version? (Required)

MySQL [test]> select tidb_version();
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()

                                                                    |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v4.0.0-beta.2-1559-g6e3d2ecb4
Edition: Community
Git Commit Hash: 6e3d2ecb48a931e835ad4826013e915051c6ebc4
Git Branch: HEAD
UTC Build Time: 2020-11-13 08:38:58
GoVersion: go1.15.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.001 sec)
rebelice commented 3 years ago

/label sig/execution, sig/planner, epic/sql-plan-management

rebelice commented 3 years ago

/assign @rebelice

rebelice commented 3 years ago

/label sig/execution

rebelice commented 3 years ago

The hints of UNION/INTERSECT/EXCEPT will involve a problem. UNION will generate an AGG that is not under any SELECT and INTERSECT/EXCEPT will generate a JOIN that is not under any SELECT. It is not easy to implement on the existing framework, and the changes are large. So it needs design doc and discussion.

XuHuaiyu commented 3 years ago

If we can only reproduce this problem after set @@tidb_capture_plan_baselines = on;, I suppose to change the label from bug to feature-request. @rebelice