Skip to content

Commit

Permalink
planner: check whether values are const in constant propagation (#45119)
Browse files Browse the repository at this point in the history
close #45086
  • Loading branch information
qw4990 committed Jul 3, 2023
1 parent e7e8fc1 commit 6f79794
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion expression/constant_propagation.go
Expand Up @@ -56,7 +56,7 @@ func (s *basePropConstSolver) insertCol(col *Column) {
// tryToUpdateEQList tries to update the eqList. When the eqList has store this column with a different constant, like
// a = 1 and a = 2, we set the second return value to false.
func (s *basePropConstSolver) tryToUpdateEQList(col *Column, con *Constant) (bool, bool) {
if con.Value.IsNull() {
if con.ConstItem(s.ctx.GetSessionVars().StmtCtx) && con.Value.IsNull() {
return false, true
}
id := s.getColID(col)
Expand Down
14 changes: 13 additions & 1 deletion planner/core/plan_cache_test.go
Expand Up @@ -52,6 +52,18 @@ func TestInitLRUWithSystemVar(t *testing.T) {
require.NotNil(t, lru)
}

func TestIssue45086(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec(`use test`)

tk.MustExec(`CREATE TABLE t (a int(11) DEFAULT NULL, b date DEFAULT NULL)`)
tk.MustExec(`INSERT INTO t VALUES (1, current_date())`)

tk.MustExec(`PREPARE stmt FROM 'SELECT * FROM t WHERE b=current_date()'`)
require.Equal(t, len(tk.MustQuery(`EXECUTE stmt`).Rows()), 1)
}

func TestIssue43311(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down Expand Up @@ -955,7 +967,7 @@ func TestIssue43852(t *testing.T) {
tk.MustExec(`set tidb_enable_non_prepared_plan_cache=1`)
tk.MustQuery(`select * from t6 where a in (2015, '8')`).Check(testkit.Rows())
tk.MustQuery(`select * from t6 where a in (2009, '2023-01-21')`).Check(testkit.Rows(`2023-01-21 2023-01-05`))
tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0"))
tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1"))
}

func TestNonPreparedPlanTypeRandomly(t *testing.T) {
Expand Down

0 comments on commit 6f79794

Please sign in to comment.