From 1739dfdf9b0bc4cc200849c9ec99894c09f9245e Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Mon, 10 Jun 2024 09:52:40 +0800 Subject: [PATCH 1/3] fix conflict Signed-off-by: hi-rustin --- cmd/explaintest/r/planner_issue.result | 49 ++++++++++++++++++++++++++ cmd/explaintest/t/planner_issue.test | 11 ++++++ planner/core/rule_column_pruning.go | 7 +++- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/cmd/explaintest/r/planner_issue.result b/cmd/explaintest/r/planner_issue.result index ac5638a01e053..248c38851afda 100644 --- a/cmd/explaintest/r/planner_issue.result +++ b/cmd/explaintest/r/planner_issue.result @@ -187,3 +187,52 @@ t_q1 as ref_14 where (ref_14.c_z like 'o%fiah'))) where (t_kg74.c_obnq8s7_s2 = case when (t_kg74.c_a1tv2 is NULL) then t_kg74.c_g else t_kg74.c_obnq8s7_s2 end ); +drop table if exists t0, t1; +CREATE TABLE t0(c0 NUMERIC); +CREATE TABLE t1(c0 NUMERIC); +INSERT INTO t0 VALUES (0), (NULL), (1), (2); +INSERT INTO t1(c0) VALUES (NULL), (3), (4), (5); +drop view if exists v0; +CREATE VIEW v0(c0) AS SELECT t0.c0 FROM t0; +SELECT t0.c0 FROM v0, t0 LEFT JOIN t1 ON t0.c0 WHERE ((INET_ATON('5V')) IS NULL) +c0 +0 +0 +0 +0 +NULL +NULL +NULL +NULL +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 diff --git a/cmd/explaintest/t/planner_issue.test b/cmd/explaintest/t/planner_issue.test index b7a595ee3f165..fa346e6e60d97 100644 --- a/cmd/explaintest/t/planner_issue.test +++ b/cmd/explaintest/t/planner_issue.test @@ -174,3 +174,14 @@ update t_kg74 set where (ref_14.c_z like 'o%fiah'))) where (t_kg74.c_obnq8s7_s2 = case when (t_kg74.c_a1tv2 is NULL) then t_kg74.c_g else t_kg74.c_obnq8s7_s2 end ); + +# https://github.com/pingcap/tidb/issues/49109 +drop table if exists t0, t1; +CREATE TABLE t0(c0 NUMERIC); +CREATE TABLE t1(c0 NUMERIC); +INSERT INTO t0 VALUES (0), (NULL), (1), (2); +INSERT INTO t1(c0) VALUES (NULL), (3), (4), (5); +drop view if exists v0; +CREATE VIEW v0(c0) AS SELECT t0.c0 FROM t0; + +SELECT t0.c0 FROM v0, t0 LEFT JOIN t1 ON t0.c0 WHERE ((INET_ATON('5V')) IS NULL) diff --git a/planner/core/rule_column_pruning.go b/planner/core/rule_column_pruning.go index fcf503e23b2aa..2a0d956d0e441 100644 --- a/planner/core/rule_column_pruning.go +++ b/planner/core/rule_column_pruning.go @@ -87,7 +87,12 @@ func (p *LogicalProjection) PruneColumns(parentUsedCols []*expression.Column, op func (p *LogicalSelection) PruneColumns(parentUsedCols []*expression.Column, opt *logicalOptimizeOp) error { child := p.children[0] parentUsedCols = expression.ExtractColumnsFromExpressions(parentUsedCols, p.Conditions, nil) - return child.PruneColumns(parentUsedCols, opt) + err := child.PruneColumns(parentUsedCols, opt) + if err != nil { + return err + } + addConstOneForEmptyProjection(p.children[0]) + return nil } // PruneColumns implements LogicalPlan interface. From bd64249cccfac20e92e7a2c1a0966c765444dae2 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Tue, 11 Jun 2024 20:41:20 +0800 Subject: [PATCH 2/3] fix tests --- cmd/explaintest/r/planner_issue.result | 8 +++++++- cmd/explaintest/t/planner_issue.test | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/explaintest/r/planner_issue.result b/cmd/explaintest/r/planner_issue.result index 7d66a4313c518..92bd1e8fdb0ba 100644 --- a/cmd/explaintest/r/planner_issue.result +++ b/cmd/explaintest/r/planner_issue.result @@ -187,6 +187,11 @@ t_q1 as ref_14 where (ref_14.c_z like 'o%fiah'))) where (t_kg74.c_obnq8s7_s2 = case when (t_kg74.c_a1tv2 is NULL) then t_kg74.c_g else t_kg74.c_obnq8s7_s2 end ); +set @cur_sql_mode = @@sql_mode; +set @@sql_mode = ''; +select @@sql_mode; +@@sql_mode + drop table if exists t0, t1; CREATE TABLE t0(c0 NUMERIC); CREATE TABLE t1(c0 NUMERIC); @@ -194,7 +199,7 @@ INSERT INTO t0 VALUES (0), (NULL), (1), (2); INSERT INTO t1(c0) VALUES (NULL), (3), (4), (5); drop view if exists v0; CREATE VIEW v0(c0) AS SELECT t0.c0 FROM t0; -SELECT t0.c0 FROM v0, t0 LEFT JOIN t1 ON t0.c0 WHERE ((INET_ATON('5V')) IS NULL) +SELECT t0.c0 FROM v0, t0 LEFT JOIN t1 ON t0.c0 WHERE ((INET_ATON('5V')) IS NULL); c0 0 0 @@ -236,6 +241,7 @@ NULL 2 2 2 +set @@sql_mode=@cur_sql_mode; drop table if exists t1, t2; create table t1(id int primary key, a varchar(128)); create table t2(id int primary key, b varchar(128), c varchar(128)); diff --git a/cmd/explaintest/t/planner_issue.test b/cmd/explaintest/t/planner_issue.test index 50e994ea502dd..c5528683042ed 100644 --- a/cmd/explaintest/t/planner_issue.test +++ b/cmd/explaintest/t/planner_issue.test @@ -176,6 +176,9 @@ where (t_kg74.c_obnq8s7_s2 = case when (t_kg74.c_a1tv2 is NULL) then t_kg74.c_g ); # https://github.com/pingcap/tidb/issues/49109 +set @cur_sql_mode = @@sql_mode; +set @@sql_mode = ''; +select @@sql_mode; drop table if exists t0, t1; CREATE TABLE t0(c0 NUMERIC); CREATE TABLE t1(c0 NUMERIC); @@ -184,7 +187,8 @@ INSERT INTO t1(c0) VALUES (NULL), (3), (4), (5); drop view if exists v0; CREATE VIEW v0(c0) AS SELECT t0.c0 FROM t0; -SELECT t0.c0 FROM v0, t0 LEFT JOIN t1 ON t0.c0 WHERE ((INET_ATON('5V')) IS NULL) +SELECT t0.c0 FROM v0, t0 LEFT JOIN t1 ON t0.c0 WHERE ((INET_ATON('5V')) IS NULL); +set @@sql_mode=@cur_sql_mode; # https://github.com/pingcap/tidb/issues/53236 drop table if exists t1, t2; From ef9653ea3f074728d03faf7dbb588ece159a76b0 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Wed, 12 Jun 2024 02:15:55 +0800 Subject: [PATCH 3/3] remove tests --- cmd/explaintest/r/planner_issue.result | 55 -------------------------- cmd/explaintest/t/planner_issue.test | 15 ------- 2 files changed, 70 deletions(-) diff --git a/cmd/explaintest/r/planner_issue.result b/cmd/explaintest/r/planner_issue.result index 92bd1e8fdb0ba..5bd4de7cbc691 100644 --- a/cmd/explaintest/r/planner_issue.result +++ b/cmd/explaintest/r/planner_issue.result @@ -187,61 +187,6 @@ t_q1 as ref_14 where (ref_14.c_z like 'o%fiah'))) where (t_kg74.c_obnq8s7_s2 = case when (t_kg74.c_a1tv2 is NULL) then t_kg74.c_g else t_kg74.c_obnq8s7_s2 end ); -set @cur_sql_mode = @@sql_mode; -set @@sql_mode = ''; -select @@sql_mode; -@@sql_mode - -drop table if exists t0, t1; -CREATE TABLE t0(c0 NUMERIC); -CREATE TABLE t1(c0 NUMERIC); -INSERT INTO t0 VALUES (0), (NULL), (1), (2); -INSERT INTO t1(c0) VALUES (NULL), (3), (4), (5); -drop view if exists v0; -CREATE VIEW v0(c0) AS SELECT t0.c0 FROM t0; -SELECT t0.c0 FROM v0, t0 LEFT JOIN t1 ON t0.c0 WHERE ((INET_ATON('5V')) IS NULL); -c0 -0 -0 -0 -0 -NULL -NULL -NULL -NULL -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -set @@sql_mode=@cur_sql_mode; drop table if exists t1, t2; create table t1(id int primary key, a varchar(128)); create table t2(id int primary key, b varchar(128), c varchar(128)); diff --git a/cmd/explaintest/t/planner_issue.test b/cmd/explaintest/t/planner_issue.test index c5528683042ed..49d4423c6e83c 100644 --- a/cmd/explaintest/t/planner_issue.test +++ b/cmd/explaintest/t/planner_issue.test @@ -175,21 +175,6 @@ update t_kg74 set where (t_kg74.c_obnq8s7_s2 = case when (t_kg74.c_a1tv2 is NULL) then t_kg74.c_g else t_kg74.c_obnq8s7_s2 end ); -# https://github.com/pingcap/tidb/issues/49109 -set @cur_sql_mode = @@sql_mode; -set @@sql_mode = ''; -select @@sql_mode; -drop table if exists t0, t1; -CREATE TABLE t0(c0 NUMERIC); -CREATE TABLE t1(c0 NUMERIC); -INSERT INTO t0 VALUES (0), (NULL), (1), (2); -INSERT INTO t1(c0) VALUES (NULL), (3), (4), (5); -drop view if exists v0; -CREATE VIEW v0(c0) AS SELECT t0.c0 FROM t0; - -SELECT t0.c0 FROM v0, t0 LEFT JOIN t1 ON t0.c0 WHERE ((INET_ATON('5V')) IS NULL); -set @@sql_mode=@cur_sql_mode; - # https://github.com/pingcap/tidb/issues/53236 drop table if exists t1, t2; create table t1(id int primary key, a varchar(128));