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

Commit6401583

Browse files
committed
Call set_rel_pathlist_hook before generate_gather_paths, not after.
The previous ordering of these steps satisfied the nominal requirementthat set_rel_pathlist_hook could editorialize on the whole set of Pathsconstructed for a base relation. In practice, though, trying to changethe set of partial paths was impossible. Adding one didn't work because(a) it was too late to be included in Gather paths made by the core code,and (b) calling add_partial_path after generate_gather_paths is unsafe,because it might try to delete a path it thinks is dominated, but thatis already embedded in some Gather path(s). Nor could the hook safelyremove partial paths, for the same reason that they might already beembedded in Gathers.Better to call extensions first, let them add partial paths as desired,and then gather. In v11 and up, we already doubled down on that orderingby postponing gathering even further for single-relation queries; so evenif the hook wished to editorialize on Gather path construction, it couldnot.Report and patch by KaiGai Kohei. Back-patch to 9.6 where Gather pathswere added.Discussion:https://postgr.es/m/CAOP8fzahwpKJRTVVTqo2AE=mDTz_efVzV6Get_0=U3SO+-ha1A@mail.gmail.com
1 parent4446565 commit6401583

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

‎doc/src/sgml/custom-scan.sgml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
<para>
3838
A custom scan provider will typically add paths for a base relation by
3939
setting the following hook, which is called after the core code has
40-
generated what it believes to be the complete and correct set of access
41-
paths for the relation.
40+
generated all the access paths it can for the relation (except for
41+
Gather paths, which are made after this call so that they can use
42+
partial paths added by the hook):
4243
<programlisting>
4344
typedef void (*set_rel_pathlist_hook_type) (PlannerInfo *root,
4445
RelOptInfo *rel,

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -529,31 +529,34 @@ set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
529529
}
530530
}
531531

532+
/*
533+
* Allow a plugin to editorialize on the set of Paths for this base
534+
* relation. It could add new paths (such as CustomPaths) by calling
535+
* add_path(), or add_partial_path() if parallel aware. It could also
536+
* delete or modify paths added by the core code.
537+
*/
538+
if (set_rel_pathlist_hook)
539+
(*set_rel_pathlist_hook) (root,rel,rti,rte);
540+
532541
/*
533542
* If this is a baserel, we should normally consider gathering any partial
534-
* paths we may have created for it.
543+
* paths we may have created for it. We have to do this after calling the
544+
* set_rel_pathlist_hook, else it cannot add partial paths to be included
545+
* here.
535546
*
536547
* However, if this is an inheritance child, skip it. Otherwise, we could
537548
* end up with a very large number of gather nodes, each trying to grab
538549
* its own pool of workers. Instead, we'll consider gathering partial
539550
* paths for the parent appendrel.
540551
*
541552
* Also, if this is the topmost scan/join rel (that is, the only baserel),
542-
* we postponethis until the final scan/jointargelist is available (see
543-
* grouping_planner).
553+
* we postponegathering until the final scan/jointargetlist is available
554+
*(seegrouping_planner).
544555
*/
545556
if (rel->reloptkind==RELOPT_BASEREL&&
546557
bms_membership(root->all_baserels)!=BMS_SINGLETON)
547558
generate_gather_paths(root,rel, false);
548559

549-
/*
550-
* Allow a plugin to editorialize on the set of Paths for this base
551-
* relation. It could add new paths (such as CustomPaths) by calling
552-
* add_path(), or delete or modify paths added by the core code.
553-
*/
554-
if (set_rel_pathlist_hook)
555-
(*set_rel_pathlist_hook) (root,rel,rti,rte);
556-
557560
/* Now find the cheapest of the paths for this rel */
558561
set_cheapest(rel);
559562

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp