-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
select failed for partition table with generated column with error needPartitionHandle != ret, tp(1)
#58475
Labels
affects-7.5
This bug affects the 7.5.x(LTS) versions.
affects-8.1
This bug affects the 8.1.x(LTS) versions.
affects-8.5
This bug affects the 8.5.x(LTS) versions.
component/tablepartition
This issue is related to Table Partition of TiDB.
fuzz/randomtest
severity/major
sig/sql-infra
SIG: SQL Infra
type/bug
The issue is confirmed as a bug.
Comments
diff --git a/pkg/planner/core/physical_plans.go b/pkg/planner/core/physical_plans.go
index 1887ea8d39..cf5fa3b9a5 100644
--- a/pkg/planner/core/physical_plans.go
+++ b/pkg/planner/core/physical_plans.go
@@ -1061,14 +1061,25 @@ func ExpandVirtualColumn(columns []*model.ColumnInfo, schema *expression.Schema,
colsInfo []*model.ColumnInfo) []*model.ColumnInfo {
copyColumn := make([]*model.ColumnInfo, len(columns))
copy(copyColumn, columns)
- var extraColumn *expression.Column
- var extraColumnModel *model.ColumnInfo
- if schema.Columns[len(schema.Columns)-1].ID == model.ExtraHandleID {
- extraColumn = schema.Columns[len(schema.Columns)-1]
- extraColumnModel = copyColumn[len(copyColumn)-1]
- schema.Columns = schema.Columns[:len(schema.Columns)-1]
- copyColumn = copyColumn[:len(copyColumn)-1]
+
+ oldNumColumns := len(schema.Columns)
+ numExtraColumns := 0
+ for i := oldNumColumns - 1; i >= 0; i-- {
+ cid := schema.Columns[i].ID
+ if cid != model.ExtraHandleID && cid != model.ExtraPhysTblID {
+ break
+ }
+ numExtraColumns++
}
+
+ extraColumns := make([]*expression.Column, numExtraColumns)
+ copy(extraColumns, schema.Columns[oldNumColumns-numExtraColumns:])
+ schema.Columns = schema.Columns[:oldNumColumns-numExtraColumns]
+
+ extraColumnModels := make([]*model.ColumnInfo, numExtraColumns)
+ copy(extraColumnModels, copyColumn[len(copyColumn)-numExtraColumns:])
+ copyColumn = copyColumn[:len(copyColumn)-numExtraColumns]
+
schemaColumns := schema.Columns
for _, col := range schemaColumns {
if col.VirtualExpr == nil {
@@ -1083,10 +1094,9 @@ func ExpandVirtualColumn(columns []*model.ColumnInfo, schema *expression.Schema,
}
}
}
- if extraColumn != nil {
- schema.Columns = append(schema.Columns, extraColumn)
- copyColumn = append(copyColumn, extraColumnModel) // nozero
- }
+
+ schema.Columns = append(schema.Columns, extraColumns...)
+ copyColumn = append(copyColumn, extraColumnModels...)
return copyColumn
} Apply this patch can solve the problems in the issue, but I'm not sure whether its the correct solution. |
jebter
added
sig/sql-infra
SIG: SQL Infra
severity/major
component/tablepartition
This issue is related to Table Partition of TiDB.
labels
Dec 24, 2024
ti-chi-bot
bot
added
may-affects-5.4
This bug maybe affects 5.4.x versions.
may-affects-6.1
may-affects-6.5
may-affects-7.1
may-affects-7.5
may-affects-8.1
may-affects-8.5
labels
Dec 24, 2024
The diff patch looks great, I think you could push a PR to fix this issue. |
Defined2014
added
affects-7.5
This bug affects the 7.5.x(LTS) versions.
affects-8.1
This bug affects the 8.1.x(LTS) versions.
affects-8.5
This bug affects the 8.5.x(LTS) versions.
and removed
may-affects-5.4
This bug maybe affects 5.4.x versions.
may-affects-6.1
may-affects-6.5
may-affects-7.1
may-affects-7.5
may-affects-8.1
may-affects-8.5
labels
Dec 24, 2024
13 tasks
13 tasks
ti-chi-bot
pushed a commit
to ti-chi-bot/tidb
that referenced
this issue
Dec 27, 2024
13 tasks
13 tasks
13 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
affects-7.5
This bug affects the 7.5.x(LTS) versions.
affects-8.1
This bug affects the 8.1.x(LTS) versions.
affects-8.5
This bug affects the 8.5.x(LTS) versions.
component/tablepartition
This issue is related to Table Partition of TiDB.
fuzz/randomtest
severity/major
sig/sql-infra
SIG: SQL Infra
type/bug
The issue is confirmed as a bug.
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
The text was updated successfully, but these errors were encountered: