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

partition prune has index out of range problem #35181

Closed
AilinKid opened this issue Jun 6, 2022 · 6 comments · Fixed by #35298
Closed

partition prune has index out of range problem #35181

AilinKid opened this issue Jun 6, 2022 · 6 comments · Fixed by #35298
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. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@AilinKid
Copy link
Contributor

AilinKid commented Jun 6, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `t` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY RANGE (`a`)
(PARTITION `p0` VALUES LESS THAN (2021),
PARTITION `p1` VALUES LESS THAN (3000))

insert into t select * from t where a=3000;

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

Success

3. What did you see instead (Required)

tidb> insert into t select * from t where a=3000;
ERROR 1105 (HY000): runtime error: index out of range [2] with length 2

4. What is your TiDB version? (Required)

master

@AilinKid AilinKid added the type/bug The issue is confirmed as a bug. label Jun 6, 2022
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.0 may-affects-6.1 labels Jun 7, 2022
@seiya-annie seiya-annie added 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. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 sig/sql-infra SIG: SQL Infra and removed may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-6.0 may-affects-6.1 labels Jun 7, 2022
@lcwangchao
Copy link
Collaborator

lcwangchao commented Jun 7, 2022

Seems here has a bug:

if start > 0 && pruner.lessThan.data[start-1] == dataForPrune.c && (pruner.lessThan.data[start]-1) == dataForPrune.c {

When a condition a=xxx cannot match any partition, the start will get a value with len(pruner.lessThan.data)

@AilinKid
Copy link
Contributor Author

AilinKid commented Jun 7, 2022

Seems here has a bug:

if start > 0 && pruner.lessThan.data[start-1] == dataForPrune.c && (pruner.lessThan.data[start]-1) == dataForPrune.c {

When a condition a=xxx cannot match any partition, the start will get a value with len(pruner.lessThan.data)

Yes, better use a=x for easy reproduction. x is the upper bound of your last partition (NO MAXVALUE)

@zimulala
Copy link
Contributor

zimulala commented Jun 7, 2022

@lcwangchao Do you interest to fix this issue?

@mjonss
Copy link
Contributor

mjonss commented Jun 7, 2022

I think the optimization for removing a prune condition should be removed. It was added in #22079, and has reported issues: #33966.

The only time it would be beneficial is when there is only a single value mapping to a partition (like a single value RANGE or LIST partition) and it is not a part of an index. And the benefit is only one less evaluation, so I think the optimization and the added switch tidb_keep_pruned_conds should be removed.

@yiwen92
Copy link
Contributor

yiwen92 commented Jun 20, 2022

The root cause here is for this sql-"insert into t select * from t where a=3000; " the 'a= 3000' is out of the range of defined partition value? So what will the behavior for the Minimal reproduce be like?

@mjonss
Copy link
Contributor

mjonss commented Jun 20, 2022

The root cause here is for this sql-"insert into t select * from t where a=3000; " the 'a= 3000' is out of the range of defined partition value? So what will the behavior for the Minimal reproduce be like?

Since the select * from t where a=3000 would not find a matching row (due to no such partition defined), it will not return any row, so the insert would not insert any row either. The issue here was an optimization that did not handle this case, and that optimization was considered to be useful for only a very limited use case, and it was not fully implemented, which could be seen in this and other bugs.

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. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants