-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new collation + merge join get wrong result #23693
Comments
query plan with the correct result (removed some irrelevant fields for clarity)
query plan with the wrong result
Seems the bug is related to the merge join. |
you can add hint to the query to make the reproduce step stable. |
how did you find this bug? |
Yes. The hint should make it more stable to reproduce, but it's not 100% when I'm trying. In fact, the hint is necessary to reproduce it most times, but tidb reported a warning against this hint, which should mean this hint is ineffective. There may be some other reasons.
It occurred when I'm testing clustered index using random test. |
tidb> select /*+ merge_join(tbl_2, tbl_2)*/ tbl_2.* from tbl_2 use index(primary) where col_13 in ( select col_10 from tbl_2 where tbl_2.col_13 in ( 'Vftbh' , 'YjwPNaVCAJtKs' , 'DXMcdpfWCs' , 'peiJPqRH' , 'KInBGfejejv' , 'OFZi' , 'MBlDV' ) ) order by col_10 , col_11 , col_12 , col_13 , col_14 limit 901 ;
Empty set, 1 warning (0.00 sec)
-- without order by
tidb> select /*+ merge_join(tbl_2, tbl_2)*/ tbl_2.* from tbl_2 use index(primary) where col_13 in ( select col_10 from tbl_2 where tbl_2.col_13 in ( 'DXMcdpfWCs' , 'peiJPqRH' , 'KInBGfejejv' , 'OFZi' , 'MBlDV' ) ) ;
+---------------+----------+--------------+--------+--------+
| col_10 | col_11 | col_12 | col_13 | col_14 |
+---------------+----------+--------------+--------+--------+
| h | 3.04000 | HnyTNtGOGQcq | E | 239 |
| zVImrWKTcuSlk | 43.37300 | LTwNDBR | E | 88 |
+---------------+----------+--------------+--------+--------+ |
tidb> desc select /*+ merge_join(tbl_2, tbl_2)*/ tbl_2.* from tbl_2 use index(primary) where col_13 in ( select col_10 from tbl_2 where tbl_2.col_13 in ( 'Vftbh' , 'YjwPNaVCAJtKs' , 'DXMcdpfWCs' , 'peiJPqRH' , 'KInBGfejejv' , 'OFZi' , 'MBlDV' ) ) order by col_10 , col_11 , col_12 , col_13 , col_14 limit 901 ;
+------------------------------------------+---------+-----------+----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+------------------------------------------+---------+-----------+----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| Limit_17 | 790.40 | root | | offset:0, count:901 |
| └─Sort_76 | 790.40 | root | | test.tbl_2.col_10, test.tbl_2.col_11, test.tbl_2.col_12, test.tbl_2.col_13, test.tbl_2.col_14 |
| └─MergeJoin_51 | 790.40 | root | | semi join, left key:test.tbl_2.col_13, right key:test.tbl_2.col_10 |
| ├─Sort_75(Build) | 6.91 | root | | test.tbl_2.col_10 |
| │ └─IndexLookUp_74 | 6.91 | root | | |
| │ ├─IndexRangeScan_71(Build) | 6.92 | cop[tikv] | table:tbl_2, index:idx_5(col_13, col_14) | range:["DX","DX"], ["KI","KI"], ["MB","MB"], ["OF","OF"], ["pe","pe"], ["Vf","Vf"], ["Yj","Yj"], keep order:false, stats:pseudo |
| │ └─Selection_73(Probe) | 6.91 | cop[tikv] | | in(test.tbl_2.col_13, "Vftbh", "YjwPNaVCAJtKs", "DXMcdpfWCs", "peiJPqRH", "KInBGfejejv", "OFZi", "MBlDV"), not(isnull(test.tbl_2.col_10)) |
| │ └─TableRowIDScan_72 | 6.92 | cop[tikv] | table:tbl_2 | keep order:false, stats:pseudo |
| └─Projection_59(Probe) | 988.00 | root | | test.tbl_2.col_10, test.tbl_2.col_11, test.tbl_2.col_12, test.tbl_2.col_13, test.tbl_2.col_14 |
| └─IndexLookUp_58 | 988.00 | root | | |
| ├─IndexFullScan_56(Build) | 988.00 | cop[tikv] | table:tbl_2, index:PRIMARY(col_13, col_11, col_14) | keep order:true, stats:pseudo |
| └─TableRowIDScan_57(Probe) | 988.00 | cop[tikv] | table:tbl_2 | keep order:false, stats:pseudo |
+------------------------------------------+---------+-----------+----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
12 rows in set, 1 warning (0.00 sec) -- without order by
tidb> desc select /*+ merge_join(tbl_2, tbl_2)*/ tbl_2.* from tbl_2 use index(primary) where col_13 in ( select col_10 from tbl_2 where tbl_2.col_13 in ( 'DXMcdpfWCs' , 'peiJPqRH' , 'KInBGfejejv' , 'OFZi' , 'MBlDV' ) ) ;
+------------------------------------+---------+-----------+----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+------------------------------------+---------+-----------+----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+
| MergeJoin_9 | 790.40 | root | | semi join, other cond:eq(test.tbl_2.col_13, test.tbl_2.col_10) |
| ├─IndexLookUp_27(Build) | 4.94 | root | | |
| │ ├─IndexRangeScan_24(Build) | 4.94 | cop[tikv] | table:tbl_2, index:idx_5(col_13, col_14) | range:["DX","DX"], ["KI","KI"], ["MB","MB"], ["OF","OF"], ["pe","pe"], keep order:false, stats:pseudo |
| │ └─Selection_26(Probe) | 4.94 | cop[tikv] | | in(test.tbl_2.col_13, "DXMcdpfWCs", "peiJPqRH", "KInBGfejejv", "OFZi", "MBlDV"), not(isnull(test.tbl_2.col_10)) |
| │ └─TableRowIDScan_25 | 4.94 | cop[tikv] | table:tbl_2 | keep order:false, stats:pseudo |
| └─IndexLookUp_12(Probe) | 988.00 | root | | |
| ├─IndexFullScan_10(Build) | 988.00 | cop[tikv] | table:tbl_2, index:PRIMARY(col_13, col_11, col_14) | keep order:false, stats:pseudo |
| └─TableRowIDScan_11(Probe) | 988.00 | cop[tikv] | table:tbl_2 | keep order:false, stats:pseudo |
+------------------------------------+---------+-----------+----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+ |
Please edit this comment or add a new comment to complete the following informationNot a bug
Duplicate bug
BugNote: Make Sure that 'component', and 'severity' labels are added 1. Root Cause Analysis (RCA) (optional)2. Symptom (optional)3. All Trigger Conditions (optional)4. Workaround (optional)5. Affected versions6. Fixed versions |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
new collation: on (confirmed that this is needed to trigger this bug)
clustered_index_go_c.tbl_2-schema.sql.txt
clustered_index_go_c.tbl_2.000000000.sql.txt
Sometimes the bug might not appear because the query plan is unstable.
2. What did you expect to see? (Required)
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
master
The text was updated successfully, but these errors were encountered: