Skip to content

Commit eae0e20

Browse files
committed
Remove over-optimistic Assert.
In commit 2489d76, I'd thought it'd be safe to assert that a PlaceHolderVar appearing in a scan-level expression has empty nullingrels. However this is not so, as when we determine that a join relation is certainly empty we'll put its targetlist into a Result-with-constant-false-qual node, and nothing is done to adjust the nullingrels of the Vars or PHVs therein. (Arguably, a Result used in this way isn't really a scan-level node, but it certainly isn't an upper node either ...) It's not clear this is worth any close analysis, so let's just take out the faulty Assert. Per report from Robins Tharakan. I added a test case based on his example, just in case somebody tries to tighten this up. Discussion: https://postgr.es/m/CAEP4nAz7Enq3+DEthGG7j27DpuwSRZnW0Nh6jtNh75yErQ_nbA@mail.gmail.com
1 parent 3db72eb commit eae0e20

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/backend/optimizer/plan/setrefs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2205,7 +2205,7 @@ fix_scan_expr_mutator(Node *node, fix_scan_expr_context *context)
22052205
/* At scan level, we should always just evaluate the contained expr */
22062206
PlaceHolderVar *phv = (PlaceHolderVar *) node;
22072207

2208-
Assert(phv->phnullingrels == NULL);
2208+
/* XXX can we assert something about phnullingrels? */
22092209
return fix_scan_expr_mutator((Node *) phv->phexpr, context);
22102210
}
22112211
if (IsA(node, AlternativeSubPlan))

src/test/regress/expected/join.out

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,6 +3599,20 @@ where f1 in ( select c3.f1 from ctetable c2 full join ctetable c3 on true );
35993599
1
36003600
(1 row)
36013601

3602+
-- Test PHV that winds up in a Result node, despite having nonempty nullingrels
3603+
explain (verbose, costs off)
3604+
select table_catalog, table_name
3605+
from int4_tbl t1
3606+
inner join (int8_tbl t2
3607+
left join information_schema.column_udt_usage on null)
3608+
on null;
3609+
QUERY PLAN
3610+
-------------------------------------------------------------------------------------------------------------------
3611+
Result
3612+
Output: (current_database())::information_schema.sql_identifier, (c.relname)::information_schema.sql_identifier
3613+
One-Time Filter: false
3614+
(3 rows)
3615+
36023616
--
36033617
-- test inlining of immutable functions
36043618
--

src/test/regress/sql/join.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,14 @@ with ctetable as not materialized ( select 1 as f1 )
11811181
select * from ctetable c1
11821182
where f1 in ( select c3.f1 from ctetable c2 full join ctetable c3 on true );
11831183

1184+
-- Test PHV that winds up in a Result node, despite having nonempty nullingrels
1185+
explain (verbose, costs off)
1186+
select table_catalog, table_name
1187+
from int4_tbl t1
1188+
inner join (int8_tbl t2
1189+
left join information_schema.column_udt_usage on null)
1190+
on null;
1191+
11841192
--
11851193
-- test inlining of immutable functions
11861194
--

0 commit comments

Comments
 (0)