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

Commit767c598

Browse files
committed
Work around implementation restriction in adjust_appendrel_attrs.
adjust_appendrel_attrs can't transfer nullingrel labeling to a non-Vartranslation expression (mainly because it's too late to wrap such anexpression in a PlaceHolderVar). I'd supposed in commit2489d76that that restriction was unreachable because we'd not attempt to pushproblematic clauses down to an appendrel child relation. I forgot thatset_append_rel_size blindly converts all the parent rel's joininfoclauses to child clauses, and that list could well contain clausesfrom above a nulling outer join.We might eventually have to devise a direct fix for this implementationrestriction, but for now it seems enough to filter out troublesomeclauses while constructing the child's joininfo list. Such clausesare certainly not useful while constructing paths for the child rel;they'll have to be applied later when we join the completed appendrelto something else. So we don't need them here, and omitting them fromthe list should save a few cycles while processing the child rel.Per bug #17832 from Marko Tiikkaja.Discussion:https://postgr.es/m/17832-d0a8106cdf1b722e@postgresql.org
1 parent872e3d1 commit767c598

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

‎src/backend/optimizer/path/allpaths.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,10 @@ set_append_rel_size(PlannerInfo *root, RelOptInfo *rel,
979979
intchildRTindex;
980980
RangeTblEntry*childRTE;
981981
RelOptInfo*childrel;
982+
List*childrinfos;
982983
ListCell*parentvars;
983984
ListCell*childvars;
985+
ListCell*lc;
984986

985987
/* append_rel_list contains all append rels; ignore others */
986988
if (appinfo->parent_relid!=parentRTindex)
@@ -1021,17 +1023,35 @@ set_append_rel_size(PlannerInfo *root, RelOptInfo *rel,
10211023
* Constraint exclusion failed, so copy the parent's join quals and
10221024
* targetlist to the child, with appropriate variable substitutions.
10231025
*
1026+
* We skip join quals that came from above outer joins that can null
1027+
* this rel, since they would be of no value while generating paths
1028+
* for the child. This saves some effort while processing the child
1029+
* rel, and it also avoids an implementation restriction in
1030+
* adjust_appendrel_attrs (it can't apply nullingrels to a non-Var).
1031+
*/
1032+
childrinfos=NIL;
1033+
foreach(lc,rel->joininfo)
1034+
{
1035+
RestrictInfo*rinfo= (RestrictInfo*)lfirst(lc);
1036+
1037+
if (!bms_overlap(rinfo->clause_relids,rel->nulling_relids))
1038+
childrinfos=lappend(childrinfos,
1039+
adjust_appendrel_attrs(root,
1040+
(Node*)rinfo,
1041+
1,&appinfo));
1042+
}
1043+
childrel->joininfo=childrinfos;
1044+
1045+
/*
1046+
* Now for the child's targetlist.
1047+
*
10241048
* NB: the resulting childrel->reltarget->exprs may contain arbitrary
10251049
* expressions, which otherwise would not occur in a rel's targetlist.
10261050
* Code that might be looking at an appendrel child must cope with
10271051
* such. (Normally, a rel's targetlist would only include Vars and
10281052
* PlaceHolderVars.) XXX we do not bother to update the cost or width
10291053
* fields of childrel->reltarget; not clear if that would be useful.
10301054
*/
1031-
childrel->joininfo= (List*)
1032-
adjust_appendrel_attrs(root,
1033-
(Node*)rel->joininfo,
1034-
1,&appinfo);
10351055
childrel->reltarget->exprs= (List*)
10361056
adjust_appendrel_attrs(root,
10371057
(Node*)rel->reltarget->exprs,

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3613,6 +3613,28 @@ from int4_tbl t1
36133613
One-Time Filter: false
36143614
(3 rows)
36153615

3616+
-- Test handling of qual pushdown to appendrel members with non-Var outputs
3617+
explain (verbose, costs off)
3618+
select * from int4_tbl left join (
3619+
select text 'foo' union all select text 'bar'
3620+
) ss(x) on true
3621+
where ss.x is null;
3622+
QUERY PLAN
3623+
-----------------------------------------
3624+
Nested Loop Left Join
3625+
Output: int4_tbl.f1, ('foo'::text)
3626+
Filter: (('foo'::text) IS NULL)
3627+
-> Seq Scan on public.int4_tbl
3628+
Output: int4_tbl.f1
3629+
-> Materialize
3630+
Output: ('foo'::text)
3631+
-> Append
3632+
-> Result
3633+
Output: 'foo'::text
3634+
-> Result
3635+
Output: 'bar'::text
3636+
(12 rows)
3637+
36163638
--
36173639
-- test inlining of immutable functions
36183640
--

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,13 @@ from int4_tbl t1
11891189
left joininformation_schema.column_udt_usageonnull)
11901190
onnull;
11911191

1192+
-- Test handling of qual pushdown to appendrel members with non-Var outputs
1193+
explain (verbose, costs off)
1194+
select*from int4_tblleft join (
1195+
selecttext'foo'union allselecttext'bar'
1196+
) ss(x)on true
1197+
wheress.x isnull;
1198+
11921199
--
11931200
-- test inlining of immutable functions
11941201
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp