diff --git a/pkg/planner/core/rule_column_pruning.go b/pkg/planner/core/rule_column_pruning.go index 9e77a249c9152..714b92a6f0b2c 100644 --- a/pkg/planner/core/rule_column_pruning.go +++ b/pkg/planner/core/rule_column_pruning.go @@ -134,6 +134,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 7819d1d080b35..85420b9079be8 100644 --- a/tests/integrationtest/r/planner/core/issuetest/planner_issue.result +++ b/tests/integrationtest/r/planner/core/issuetest/planner_issue.result @@ -520,3 +520,12 @@ 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 diff --git a/tests/integrationtest/t/planner/core/issuetest/planner_issue.test b/tests/integrationtest/t/planner/core/issuetest/planner_issue.test index f849ad75a2bdc..d63531761cd10 100644 --- a/tests/integrationtest/t/planner/core/issuetest/planner_issue.test +++ b/tests/integrationtest/t/planner/core/issuetest/planner_issue.test @@ -378,3 +378,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);