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

planner: Fix rebuild range for prepared plan #23316

Closed
wants to merge 14 commits into from
40 changes: 40 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8082,6 +8082,46 @@ func (s *testSuiteP1) TestIssue22941(c *C) {
rs.Check(testkit.Rows("<nil> 1 0"))
}

func (s *testSuite) TestIssue23304(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t_issue_23304")
tk.MustExec("CREATE TABLE t_issue_23304(col102 bigint(20),col1 bigint(20) GENERATED ALWAYS AS (col102 ^ 10) STORED NOT NULL,PRIMARY KEY (col1) USING BTREE);")
tk.MustExec("INSERT INTO `t_issue_23304` VALUES (11111, DEFAULT), (22222, DEFAULT), (33333, DEFAULT);")
tk.MustExec("prepare stmt1 from 'select col1 from t_issue_23304 where col1 in (?, ?, ?);';")
tk.MustExec("set @a=11117, @b=22212, @c=33343;")
tk.MustQuery("execute stmt1 using@a,@b,@c;").Check(testkit.Rows("11117", "22212", "33343"))
tk.MustExec("set @a=11117, @b=11117, @c=22212;")
tk.MustQuery("execute stmt1 using@a,@b,@c;").Check(testkit.Rows("11117", "22212"))
tk.MustExec("set @a=11117, @b=11117, @c=11117;")
tk.MustQuery("execute stmt1 using@a,@b,@c;").Check(testkit.Rows("11117"))

tk.MustExec("prepare stmt2 from 'select col1 from t_issue_23304 where col1 in (?, ?, ?);';")
tk.MustExec("set @a=11117, @b=11117, @c=11117;")
tk.MustQuery("execute stmt2 using@a,@b,@c;").Check(testkit.Rows("11117"))
tk.MustExec("set @a=11117, @b=11117, @c=22212;")
tk.MustQuery("execute stmt2 using@a,@b,@c;").Check(testkit.Rows("11117", "22212"))
tk.MustExec("set @a=11117, @b=22212, @c=33343;")
tk.MustQuery("execute stmt2 using@a,@b,@c;").Check(testkit.Rows("11117", "22212", "33343"))
}

func (s *testSuite) TestIssue23290(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t_issue_23290")
tk.MustExec("CREATE TABLE t_issue_23290( `COL102` mediumint(25) DEFAULT NULL, `COL103` mediumint(25) DEFAULT NULL, `COL1` mediumint(25) GENERATED ALWAYS AS (`COL102` / 10) STORED NOT NULL, `COL2` varchar(20) DEFAULT NULL, `COL4` datetime DEFAULT NULL, `COL3` bigint(20) DEFAULT NULL, `COL5` float DEFAULT NULL, PRIMARY KEY (`COL1`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;")

tk.MustExec("insert into t_issue_23290 (COL102,COL103,COL2,COL4,COL3,COL5) values(11,19,\"abcd\",\"9289\\-01\\-03\\ 22:36:43\",-7766341800212896104,2.335516840459477e+38);")
tk.MustExec("insert into t_issue_23290 (COL102,COL103,COL2,COL4,COL3,COL5) values(22,12,\"abcd\",\"0335\\-11\\-19\\ 22:51:03\",-4154892179550291056,-3.23035740051128e+38);")
tk.MustExec("insert into t_issue_23290 (COL102,COL103,COL2,COL4,COL3,COL5) values(33,9,\"abcd\",\"5703\\-06\\-21\\ 10:01:55\",-8469066621231379353,1.478085071191862e+38); ")

tk.MustExec("prepare stmt from 'select col1, col2 from t_issue_23290 where col1 between ? and ?;';")
tk.MustExec("set @a=1, @b=1;")
tk.MustQuery("execute stmt using@a,@b;").Check(testkit.Rows("1 abcd"))
tk.MustExec("set @a=1, @b=10;")
tk.MustQuery("execute stmt using@a,@b;").Check(testkit.Rows("1 abcd", "2 abcd", "3 abcd"))
}

func (s *testSerialSuite) TestTxnWriteThroughputSLI(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
20 changes: 19 additions & 1 deletion planner/core/common_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,14 @@ func (e *Execute) rebuildRange(p Plan) error {
if err != nil {
return err
}
if len(ranges) > 1 {
return errors.New("Should not use PointGet plan")
}
highVal := ranges[0].HighVal[0].GetInt64()
lowVal := ranges[0].LowVal[0].GetInt64()
if highVal != lowVal {
return errors.New("Should not use PointGet plan")
}
x.Handle = kv.IntHandle(ranges[0].LowVal[0].GetInt64())
}
}
Expand Down Expand Up @@ -597,9 +605,19 @@ func (e *Execute) rebuildRange(p Plan) error {
if err != nil {
return err
}
if len(ranges) <= 1 {
return errors.New("Should not use BatchPointGet plan")
}
newHandles := make([]kv.Handle, 0, len(ranges))
for i := range ranges {
x.Handles[i] = kv.IntHandle(ranges[i].LowVal[0].GetInt64())
highVal := ranges[i].HighVal[0].GetInt64()
lowVal := ranges[i].LowVal[0].GetInt64()
if highVal != lowVal {
return errors.New("Should not use BatchPointGet plan")
}
newHandles = append(newHandles, kv.IntHandle(ranges[i].LowVal[0].GetInt64()))
}
x.Handles = newHandles
}
}
}
Expand Down