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: fix select statement error on table which partitioned by column with floor func #42363

Merged
merged 2 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix partition floor
  • Loading branch information
jiyfhust committed Mar 17, 2023
commit eecc7150087a87b478c504278b1f99cf0bd2bc89
17 changes: 17 additions & 0 deletions planner/core/integration_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1496,3 +1496,20 @@ func TestPartitionProcessorWithUninitializedTable(t *testing.T) {
}
tk.MustQuery("explain format=brief select * from q1,q2").CheckAt([]int{0}, rows)
}

func TestIssue42323(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("create database issue42323")
defer tk.MustExec("drop database issue42323")

tk.MustExec("use issue42323")
tk.MustExec("set @@session.tidb_partition_prune_mode = 'dynamic';")
tk.MustExec(`CREATE TABLE t(col1 int(11) NOT NULL DEFAULT '0' ) PARTITION BY RANGE (FLOOR(col1))(
PARTITION p2021 VALUES LESS THAN (202200),
PARTITION p2022 VALUES LESS THAN (202300),
PARTITION p2023 VALUES LESS THAN (202400))`)
tk.MustExec("insert into t values(202303)")
jiyfhust marked this conversation as resolved.
Show resolved Hide resolved
tk.MustQuery(`select * from t where col1 = 202303`).Check(testkit.Rows("202303"))
tk.MustQuery(`select * from t where col1 = floor(202303)`).Check(testkit.Rows("202303"))
}
3 changes: 1 addition & 2 deletions planner/core/rule_partition_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1480,8 +1480,7 @@ func replaceColumnWithConst(partFn *expression.ScalarFunction, con *expression.C
args := partFn.GetArgs()
// The partition function may be floor(unix_timestamp(ts)) instead of a simple fn(col).
if partFn.FuncName.L == ast.Floor {
ut := args[0].(*expression.ScalarFunction)
if ut.FuncName.L == ast.UnixTimestamp {
if ut, ok := args[0].(*expression.ScalarFunction); ok && ut.FuncName.L == ast.UnixTimestamp {
args = ut.GetArgs()
args[0] = con
return partFn
Expand Down