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

sorting index merge result in partition union reports 'index out of range' #23919

Closed
wjhuang2016 opened this issue Apr 8, 2021 · 2 comments · Fixed by #23936
Closed

sorting index merge result in partition union reports 'index out of range' #23919

wjhuang2016 opened this issue Apr 8, 2021 · 2 comments · Fixed by #23936
Assignees
Labels
severity/moderate sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@wjhuang2016
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `t` (
  `col_5` text NOT NULL,
  `col_6` tinyint(3) unsigned DEFAULT NULL,
  `col_7` float DEFAULT '4779.165058537128',
  `col_8` smallint(6) NOT NULL DEFAULT '-24790',
  `col_9` date DEFAULT '2031-01-15',
  `col_37` int(11) DEFAULT '1350204687',
  PRIMARY KEY (`col_5`(6),`col_8`) /*T![clustered_index] NONCLUSTERED */,
  UNIQUE KEY `idx_6` (`col_9`,`col_7`,`col_8`),
  KEY `idx_8` (`col_8`,`col_6`,`col_5`(6),`col_9`,`col_7`),
  KEY `idx_9` (`col_9`,`col_7`,`col_8`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY RANGE ( `col_8` ) (
  PARTITION `p0` VALUES LESS THAN (-17650),
  PARTITION `p1` VALUES LESS THAN (-13033),
  PARTITION `p2` VALUES LESS THAN (2521),
  PARTITION `p3` VALUES LESS THAN (7510)
);
insert into t values ("", NULL, 6304.0146, -24790, "2031-01-15", 1350204687);
select  var_samp(col_7) aggCol from (select  /*+ use_index_merge( t ) */ * from t where t.col_9 in ( '2002-06-22' ) or t.col_5 in ( 'PkfzI'  ) or t.col_8 in ( -24874 ) and t.col_6 > null and t.col_5 > 'r' and t.col_9 in ( '1979-09-04' ) and t.col_7 < 8143.667552769195 or t.col_5 in ( 'iZhfEjRWci' , 'T' , ''  ) or t.col_9 <> '1976-09-11' and t.col_7 = 8796.436181615773 and
t.col_8 = 7372 order by col_5,col_8  ) ordered_tbl group by col_6;

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

No panic

3. What did you see instead (Required)

mysql> select  var_samp(col_7) aggCol from (select  /*+ use_index_merge( t ) */ * from t where t.col_9 in ( '2002-06-22' ) or t.col_5 in ( 'PkfzI'  ) or t.col_8 in ( -24874 ) and t.col_6 > null and t.col_5 > 'r' and t.col_9 in ( '1979-09-04' ) and t.col_7 < 8143.667552769195 or t.col_5 in ( 'iZhfEjRWci' , 'T' , ''  ) or t.col_9 <> '1976-09-11' and t.col_7 = 8796.436181615773 and
t.col_8 = 7372 order by col_5,col_8  ) ordered_tbl group by col_6;
ERROR 1105 (HY000): runtime error: index out of range [5] with length 5

4. What is your TiDB version? (Required)

master

@wjhuang2016 wjhuang2016 added the type/bug The issue is confirmed as a bug. label Apr 8, 2021
@tangenta tangenta self-assigned this Apr 9, 2021
@tangenta
Copy link
Contributor

tangenta commented Apr 9, 2021

Minimal reproducible case:

drop table if exists t;
create table t (a int, b int, index(a), index(b)) partition by hash (a) partitions 2;
insert into t values (1, 5);
select /*+ use_index_merge( t ) */ * from t where a in (3) or b in (5) order by a;

This bug occurs when the following conditions are satisfied:

  1. The table contains _tidb_rowid
  2. The query has partition_union operator(partitions)
  3. The query has index_merge operator
  4. The query has sort operator(order by)
  5. The table contains matched data

Introduced in #18699.

@tangenta tangenta changed the title partition table panic sorting index merge result in partition union reports 'index out of range' Apr 9, 2021
@jebter jebter added the sig/execution SIG execution label Apr 9, 2021
@ti-srebot
Copy link
Contributor

ti-srebot commented Apr 19, 2021

Please edit this comment or add a new comment to complete the following information

Bug

1. Root Cause Analysis (RCA) (optional)

The schema is inconsistent between Sort operator and IndexMerge operator. For details, see #23936.

2. Symptom (optional)

"index out of range" error or "invalid encoded key" error.

3. All Trigger Conditions (optional)

  1. The table contains _tidb_rowid
  2. The query has partition_union operator(partitions)
  3. The query has index_merge operator
  4. The query has sort operator(order by)
  5. The table contains matched data

4. Workaround (optional)

5. Affected versions

[v5.0.0:v5.0.1]

6. Fixed versions

v5.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants