Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaca695f

Browse files
committed
Remove bogus Assert and dead code in remove_useless_results_recurse().
The JOIN_SEMI case Assert'ed that there are no PlaceHolderVars thatneed to be evaluated at the semijoin's RHS, which is wrong becausethere could be some in the semijoin's qual condition. However, therecould not be any references further up than that, and within the qualthere is not any way that such a PHV could have gone to null yet, sowe don't really need the PHV and there is no need to avoid making theRHS-removal optimization. The upshot is that there's no actual bugin production code, and we ought to just remove this misguided Assert.While we're here, also drop the JOIN_RIGHT case, which is dead codebecause reduce_outer_joins() already got rid of JOIN_RIGHT.Per bug #17700 from Xin Wen. Uselessness of the JOIN_RIGHT casepointed out by Richard Guo. Back-patch to v12 where this codewas added.Discussion:https://postgr.es/m/17700-2b5c10d917c30687@postgresql.org
1 parent68d89d8 commitaca695f

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

‎src/backend/optimizer/prep/prepjointree.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,16 +3176,6 @@ remove_useless_results_recurse(PlannerInfo *root, Node *jtnode)
31763176
jtnode=j->larg;
31773177
}
31783178
break;
3179-
caseJOIN_RIGHT:
3180-
/* Mirror-image of the JOIN_LEFT case */
3181-
if ((varno=get_result_relid(root,j->larg))!=0&&
3182-
(j->quals==NULL||
3183-
!find_dependent_phvs(root,varno)))
3184-
{
3185-
remove_result_refs(root,varno,j->rarg);
3186-
jtnode=j->rarg;
3187-
}
3188-
break;
31893179
caseJOIN_SEMI:
31903180

31913181
/*
@@ -3194,14 +3184,17 @@ remove_useless_results_recurse(PlannerInfo *root, Node *jtnode)
31943184
* LHS, since we should either return the LHS row or not. For
31953185
* simplicity we inject the filter qual into a new FromExpr.
31963186
*
3197-
* Unlike the LEFT/RIGHT cases, we just Assert that there are
3198-
* no PHVs that need to be evaluated at the semijoin's RHS,
3199-
* since the rest of the query couldn't reference any outputs
3200-
* of the semijoin's RHS.
3187+
* There is a fine point about PHVs that are supposed to be
3188+
* evaluated at the RHS. Such PHVs could only appear in the
3189+
* semijoin's qual, since the rest of the query cannot
3190+
* reference any outputs of the semijoin's RHS. Therefore,
3191+
* they can't actually go to null before being examined, and
3192+
* it'd be OK to just remove the PHV wrapping. We don't have
3193+
* infrastructure for that, but remove_result_refs() will
3194+
* relabel them as to be evaluated at the LHS, which is fine.
32013195
*/
32023196
if ((varno=get_result_relid(root,j->rarg))!=0)
32033197
{
3204-
Assert(!find_dependent_phvs(root,varno));
32053198
remove_result_refs(root,varno,j->larg);
32063199
if (j->quals)
32073200
jtnode= (Node*)
@@ -3215,6 +3208,7 @@ remove_useless_results_recurse(PlannerInfo *root, Node *jtnode)
32153208
/* We have no special smarts for these cases */
32163209
break;
32173210
default:
3211+
/* Note: JOIN_RIGHT should be gone at this point */
32183212
elog(ERROR,"unrecognized join type: %d",
32193213
(int)j->jointype);
32203214
break;

‎src/test/regress/expected/join.out

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3376,6 +3376,26 @@ where b;
33763376
0 | t | t
33773377
(2 rows)
33783378

3379+
-- Test PHV in a semijoin qual, which confused useless-RTE removal (bug #17700)
3380+
explain (verbose, costs off)
3381+
with ctetable as not materialized ( select 1 as f1 )
3382+
select * from ctetable c1
3383+
where f1 in ( select c3.f1 from ctetable c2 full join ctetable c3 on true );
3384+
QUERY PLAN
3385+
----------------------------
3386+
Result
3387+
Output: 1
3388+
One-Time Filter: (1 = 1)
3389+
(3 rows)
3390+
3391+
with ctetable as not materialized ( select 1 as f1 )
3392+
select * from ctetable c1
3393+
where f1 in ( select c3.f1 from ctetable c2 full join ctetable c3 on true );
3394+
f1
3395+
----
3396+
1
3397+
(1 row)
3398+
33793399
--
33803400
-- test inlining of immutable functions
33813401
--

‎src/test/regress/sql/join.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,16 @@ select * from
10831083
select aas b)as t3
10841084
where b;
10851085

1086+
-- Test PHV in a semijoin qual, which confused useless-RTE removal (bug #17700)
1087+
explain (verbose, costs off)
1088+
with ctetableas not materialized (select1as f1 )
1089+
select*from ctetable c1
1090+
where f1in (selectc3.f1from ctetable c2 fulljoin ctetable c3on true );
1091+
1092+
with ctetableas not materialized (select1as f1 )
1093+
select*from ctetable c1
1094+
where f1in (selectc3.f1from ctetable c2 fulljoin ctetable c3on true );
1095+
10861096
--
10871097
-- test inlining of immutable functions
10881098
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp