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
plan,table: fix select null value for table partition #7452
Changes from all commits
dbeffb5
583eba8
73e1fb1
78d356f
4fc1d76
f79a6f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,14 +98,17 @@ func newPartitionedTable(tbl *Table, tblInfo *model.TableInfo) (table.Table, err | |
// p1 values less than (y1) | ||
// p2 values less than (y2) | ||
// p3 values less than (y3)) | ||
// Ranges: (x < y1); (y1 <= x < y2); (y2 <= x < y3) | ||
// Ranges: (x < y1 or x is null); (y1 <= x < y2); (y2 <= x < y3) | ||
// UpperBounds: (x < y1); (x < y2); (x < y3) | ||
type PartitionExpr struct { | ||
// Column is the column appeared in the by range expression, partition pruning need this to work. | ||
Column *expression.Column | ||
Ranges []expression.Expression | ||
UpperBounds []expression.Expression | ||
} | ||
|
||
func generatePartitionExpr(tblInfo *model.TableInfo) (*PartitionExpr, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to add some ut for this function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
var column *expression.Column | ||
// The caller should assure partition info is not nil. | ||
pi := tblInfo.GetPartitionInfo() | ||
ctx := mock.NewContext() | ||
|
@@ -129,6 +132,19 @@ func generatePartitionExpr(tblInfo *model.TableInfo) (*PartitionExpr, error) { | |
|
||
if i > 0 { | ||
fmt.Fprintf(&buf, " and ((%s) >= (%s))", pi.Expr, pi.Definitions[i-1].LessThan[0]) | ||
} else { | ||
// NULL will locate in the first partition, so its expression is (expr < value or expr is null). | ||
fmt.Fprintf(&buf, " or ((%s) is null)", pi.Expr) | ||
|
||
// Extracts the column of the partition expression, it will be used by partition prunning. | ||
if tmp, err1 := expression.ParseSimpleExprWithTableInfo(ctx, pi.Expr, tblInfo); err1 == nil { | ||
if col, ok := tmp.(*expression.Column); ok { | ||
column = col | ||
} | ||
} | ||
if column == nil { | ||
log.Warnf("partition pruning won't work on this expr:%s", pi.Expr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't need to log a warning. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without partition pruning, a query need to scan all partitions, we'd better warn the user about this.
The warning log is not frequent, it's happen when creating table, and normal expression will not print the warning. |
||
} | ||
} | ||
|
||
expr, err = expression.ParseSimpleExprWithTableInfo(ctx, buf.String(), tblInfo) | ||
|
@@ -141,6 +157,7 @@ func generatePartitionExpr(tblInfo *model.TableInfo) (*PartitionExpr, error) { | |
buf.Reset() | ||
} | ||
return &PartitionExpr{ | ||
Column: column, | ||
Ranges: partitionPruneExprs, | ||
UpperBounds: locateExprs, | ||
}, nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these kind of tests can not show the detail about the filters, it's better to add some explain tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll port this one https://github.com/twitter/mysql/blob/master/mysql-test/t/partition_pruning.test
It will certainly cover more cases, but it's a file and I could not do it in this PR.