diff --git a/pkg/planner/core/rule_column_pruning.go b/pkg/planner/core/rule_column_pruning.go index 38d0a8875c695..ececf5ba0ef85 100644 --- a/pkg/planner/core/rule_column_pruning.go +++ b/pkg/planner/core/rule_column_pruning.go @@ -131,6 +131,7 @@ func (p *LogicalSelection) PruneColumns(parentUsedCols []*expression.Column, opt if err != nil { return nil, err } + addConstOneForEmptyProjection(p.children[0]) return p, nil } diff --git a/tests/integrationtest/r/planner/core/issuetest/planner_issue.result b/tests/integrationtest/r/planner/core/issuetest/planner_issue.result index 1622440144656..6aec31bdbb7a4 100644 --- a/tests/integrationtest/r/planner/core/issuetest/planner_issue.result +++ b/tests/integrationtest/r/planner/core/issuetest/planner_issue.result @@ -241,6 +241,15 @@ id value 3 0 4 4 5 5 +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 CREATE TABLE `t_o9_7_f` ( `c_ob5k0` int(11) NOT NULL, `c_r5axbk` tinyint(4) DEFAULT NULL, diff --git a/tests/integrationtest/t/planner/core/issuetest/planner_issue.test b/tests/integrationtest/t/planner/core/issuetest/planner_issue.test index 45a09895b527a..6ff5f8a3beea8 100644 --- a/tests/integrationtest/t/planner/core/issuetest/planner_issue.test +++ b/tests/integrationtest/t/planner/core/issuetest/planner_issue.test @@ -183,6 +183,16 @@ where test2.id in ); select * from test2; +# 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); # https://github.com/pingcap/tidb/issues/52687 CREATE TABLE `t_o9_7_f` ( `c_ob5k0` int(11) NOT NULL,