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 a panic during column pruning (#47883) #48810

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
51 changes: 51 additions & 0 deletions pkg/executor/explain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,57 @@ func checkMemoryInfo(t *testing.T, tk *testkit.TestKit, sql string) {
}
}

func TestIssue47331(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1")
tk.MustExec(`create table t1(
id1 varchar(2) DEFAULT '00',
id2 varchar(30) NOT NULL,
id3 datetime DEFAULT NULL,
id4 varchar(100) NOT NULL DEFAULT 'ecifdata',
id5 datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
id6 int(11) DEFAULT NULL,
id7 int(11) DEFAULT NULL,
UNIQUE KEY UI_id2 (id2),
KEY ix_id1 (id1)
)`)
tk.MustExec("drop table if exists t2")
tk.MustExec(`create table t2(
id10 varchar(40) NOT NULL,
id2 varchar(30) NOT NULL,
KEY IX_id2 (id2),
PRIMARY KEY (id10)
)`)
tk.MustExec("drop table if exists t3")
tk.MustExec(`create table t3(
id20 varchar(40) DEFAULT NULL,
UNIQUE KEY IX_id20 (id20)
)`)
tk.MustExec(`
explain
UPDATE t1 a
SET a.id1 = '04',
a.id3 = CURRENT_TIMESTAMP,
a.id4 = SUBSTRING_INDEX(USER(), '@', 1),
a.id5 = CURRENT_TIMESTAMP
WHERE a.id1 = '03'
AND a.id6 - IFNULL(a.id7, 0) =
(
SELECT COUNT(1)
FROM t2 b, t3 c
WHERE b.id10 = c.id20
AND b.id2 = a.id2
AND b.id2 in (
SELECT rn.id2
FROM t1 rn
WHERE rn.id1 = '03'
)
);
`)
}

func TestMemoryAndDiskUsageAfterClose(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
3 changes: 2 additions & 1 deletion pkg/planner/core/rule_join_reorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ func (s *joinReOrderSolver) optimizeRecursive(ctx sessionctx.Context, p LogicalP
proj := LogicalProjection{
Exprs: expression.Column2Exprs(originalSchema.Columns),
}.Init(p.SCtx(), p.SelectBlockOffset())
proj.SetSchema(originalSchema)
// Clone the schema here, because the schema may be changed by column pruning rules.
proj.SetSchema(originalSchema.Clone())
proj.SetChildren(p)
p = proj
}
Expand Down