Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
56.1. Creating Custom Scan Paths
Prev UpChapter 56. Writing A Custom Scan ProviderHome Next

56.1. Creating Custom Scan Paths

A custom scan provider will typically add paths for a base relation by setting the following hook, which is called after the core code has generated what it believes to be the complete and correct set of access paths for the relation.

typedef void (*set_rel_pathlist_hook_type) (PlannerInfo *root,                                            RelOptInfo *rel,                                            Index rti,                                            RangeTblEntry *rte);extern PGDLLIMPORT set_rel_pathlist_hook_type set_rel_pathlist_hook;

Although this hook function can be used to examine, modify, or remove paths generated by the core system, a custom scan provider will typically confine itself to generatingCustomPath objects and adding them torel usingadd_path. The custom scan provider is responsible for initializing theCustomPath object, which is declared like this:

typedef struct CustomPath{    Path      path;    uint32    flags;    List     *custom_paths;    List     *custom_private;    const CustomPathMethods *methods;} CustomPath;

path must be initialized as for any other path, including the row-count estimate, start and total cost, and sort ordering provided by this path.flags is a bit mask, which should includeCUSTOMPATH_SUPPORT_BACKWARD_SCAN if the custom path can support a backward scan andCUSTOMPATH_SUPPORT_MARK_RESTORE if it can support mark and restore. Both capabilities are optional. An optionalcustom_paths is a list ofPath nodes used by this custom-path node; these will be transformed intoPlan nodes by planner.custom_private can be used to store the custom path's private data. Private data should be stored in a form that can be handled bynodeToString, so that debugging routines that attempt to print the custom path will work as designed.methods must point to a (usually statically allocated) object implementing the required custom path methods, of which there are currently only two, as further detailed below.

A custom scan provider can also provide join paths. Just as for base relations, such a path must produce the same output as would normally be produced by the join it replaces. To do this, the join provider should set the following hook, and then within the hook function, createCustomPath path(s) for the join relation.

typedef void (*set_join_pathlist_hook_type) (PlannerInfo *root,                                             RelOptInfo *joinrel,                                             RelOptInfo *outerrel,                                             RelOptInfo *innerrel,                                             JoinType jointype,                                             JoinPathExtraData *extra);extern PGDLLIMPORT set_join_pathlist_hook_type set_join_pathlist_hook;

This hook will be invoked repeatedly for the same join relation, with different combinations of inner and outer relations; it is the responsibility of the hook to minimize duplicated work.

56.1.1. Custom Scan Path Callbacks

Plan *(*PlanCustomPath) (PlannerInfo *root,                         RelOptInfo *rel,                         CustomPath *best_path,                         List *tlist,                         List *clauses,                         List *custom_plans);

Convert a custom path to a finished plan. The return value will generally be aCustomScan object, which the callback must allocate and initialize. SeeSection 56.2 for more details.

void (*TextOutCustomPath) (StringInfo str,                           const CustomPath *node);

Generate additional output whennodeToString is invoked on this custom path. This callback is optional. SincenodeToString will automatically dump all fields in the structure that it can see, includingcustom_private, this is only useful if theCustomPath is actually embedded in a larger struct containing additional fields.


Prev Up Next
Chapter 56. Writing A Custom Scan Provider Home 56.2. Creating Custom Scan Plans
pdfepub
Go to Postgres Pro Standard 9.5
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp