Skip to content
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

Internal error: UnionExec chunk column count mismatch #26554

Closed
ChenPeng2013 opened this issue Jul 26, 2021 · 4 comments · Fixed by #27798
Closed

Internal error: UnionExec chunk column count mismatch #26554

ChenPeng2013 opened this issue Jul 26, 2021 · 4 comments · Fixed by #27798
Assignees
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@ChenPeng2013
Copy link
Contributor

ChenPeng2013 commented Jul 26, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

use test;
drop table if exists IDT_HP24172;
CREATE TABLE `IDT_HP24172` (
  `COL1` mediumint(16) DEFAULT NULL,
  `COL2` varchar(20) DEFAULT NULL,
  `COL4` datetime DEFAULT NULL,
  `COL3` bigint(20) DEFAULT NULL,
  `COL5` float DEFAULT NULL,
  KEY `UM_COL` (`COL1`,`COL3`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY HASH( `COL1`+`COL3` )
PARTITIONS 8;
insert into IDT_HP24172(col1) values(8388607);
select col2 from IDT_HP24172 where col1 = 8388607 and col1 in (select col1 from IDT_HP24172);

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

mysql> select col2 from IDT_HP24172 where col1 = 8388607 and col1 in (select col1 from IDT_HP24172);
+------+
| col2 |
+------+
| NULL |
+------+
1 row in set (0.01 sec)

3. What did you see instead (Required)

mysql> select col2 from IDT_HP24172 where col1 = 8388607 and col1 in (select col1 from IDT_HP24172);
ERROR 1105 (HY000): Internal error: UnionExec chunk column count mismatch, req: 2, result: 1

4. What is your TiDB version? (Required)

It can be reproduced on branch release-5.0, release-5.1 and master
The release-4.0 branch doesn't have the issue

Release Version: v5.1.0-64-gfb0eaf7b4
Edition: Community
Git Commit Hash: fb0eaf7b44b9ddb1494bf8194d8e361c538146dc
Git Branch: release-5.1
UTC Build Time: 2021-07-26 06:50:38
GoVersion: go1.16.5
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
@ChenPeng2013 ChenPeng2013 added type/bug The issue is confirmed as a bug. sig/execution SIG execution severity/major labels Jul 26, 2021
@xxchan
Copy link
Contributor

xxchan commented Aug 1, 2021

a smaller reproduction:

CREATE TABLE t (
  a int,
  b int
)
PARTITION BY HASH( a )
PARTITIONS 2;
insert into t values(1,2);
select * from t where b = 2 and b in (select b from t);
> explain select * from t where b = 2 and b in (select b from t);
+------------------------------+-----------+-----------+-----------------------+-------------------------------------------------------+
| id                           |   estRows | task      | access object         | operator info                                         |
|------------------------------+-----------+-----------+-----------------------+-------------------------------------------------------|
| HashJoin_21                  |     90.01 | root      |                       | CARTESIAN inner join                                  |
| ├─HashAgg_30(Build)          |      9    | root      |                       | group by:test.t.b, funcs:firstrow(1)->Column#8        |
| │ └─PartitionUnion_31        |      9    | root      |                       |                                                       |
| │   ├─HashAgg_34             |      8    | root      |                       | group by:test.t.b, funcs:firstrow(test.t.b)->test.t.b |
| │   │ └─TableReader_41       |     10    | root      |                       | data:Selection_40                                     |
| │   │   └─Selection_40       |     10    | cop[tikv] |                       | eq(2, test.t.b)                                       |
| │   │     └─TableFullScan_39 |  10000    | cop[tikv] | table:t, partition:p0 | keep order:false, stats:pseudo                        |
| │   └─HashAgg_44             |      1    | root      |                       | group by:test.t.b, funcs:firstrow(test.t.b)->test.t.b |
| │     └─TableReader_51       |      0    | root      |                       | data:Selection_50                                     |
| │       └─Selection_50       |      0    | cop[tikv] |                       | eq(2, test.t.b)                                       |
| │         └─TableFullScan_49 |      1    | cop[tikv] | table:t, partition:p1 | keep order:false, stats:pseudo                        |
| └─PartitionUnion_23(Probe)   |     10    | root      |                       |                                                       |
|   ├─TableReader_26           |     10    | root      |                       | data:Selection_25                                     |
|   │ └─Selection_25           |     10    | cop[tikv] |                       | eq(test.t.b, 2)                                       |
|   │   └─TableFullScan_24     |  10000    | cop[tikv] | table:t, partition:p0 | keep order:false, stats:pseudo                        |
|   └─TableReader_29           |      0    | root      |                       | data:Selection_28                                     |
|     └─Selection_28           |      0    | cop[tikv] |                       | eq(test.t.b, 2)                                       |
|       └─TableFullScan_27     |      1    | cop[tikv] | table:t, partition:p1 | keep order:false, stats:pseudo                        |
+------------------------------+-----------+-----------+-----------------------+-------------------------------------------------------+

It seems that HashAgg children caused the problem? (I don't know how to fix it 🤔)

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Aug 9, 2021

  • UnionStore does not have this problem
  • Reproduced when using TiKV

@wshwsh12
Copy link
Contributor

wshwsh12 commented Aug 9, 2021

Release 4.0 also has this problem, but doesn't throw error.
Because in release 4.0, UnionExec doesn't have the following check:

tidb/executor/executor.go

Lines 1617 to 1620 in 880c9b5

if result.chk.NumCols() != req.NumCols() {
return errors.Errorf("Internal error: UnionExec chunk column count mismatch, req: %d, result: %d",
req.NumCols(), result.chk.NumCols())
}

@github-actions
Copy link

github-actions bot commented Sep 6, 2021

Please check whether the issue should be labeled with 'affects-x.y' or 'backport-x.y.z',
and then remove 'needs-more-info' label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
5 participants