9.3 9.4 9.5 9.6 10 11 12 13
阿里云PostgreSQL 问题报告 纠错本页面

56.1. 创建自定义扫描路径

自定义扫描提供程序通常通过设置以下hook来为基本关系添加路径, 该hook在核心代码生成了它认为是关系的完整和正确的访问路径集合之后被调用。

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;

虽然这个hook函数可以用于检查,修改或删除由核心系统生成的路径, 但自定义扫描提供程序通常仅限于生成CustomPath 对象并使用add_path将它们添加到rel。 自定义扫描提供程序负责初始化CustomPath对象,其声明如下:

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

path必须按任何其他路径初始化,包括行计数估计, 开始和总成本以及此路径提供的排序顺序。flags是一个位掩码, 如果自定义路径可以支持反向扫描,则应该包含CUSTOMPATH_SUPPORT_BACKWARD_SCAN, 并且如果它可以支持标记和恢复,则应该包含CUSTOMPATH_SUPPORT_MARK_RESTORE。 这两种功能都是可选的。可选的custom_paths是由该自定义路径节点使用的 Path节点的列表;这些将由计划器转换成Plan节点。 custom_private可用于存储自定义路径的私有数据。 私有数据应以可由nodeToString处理的形式存储, 以便尝试打印自定义路径的调试例程将按设计工作。methods 必须指向实现所需的自定义路径方法的(通常是静态分配的)对象, 其中目前仅有两个,见下面进一步详细描述。

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, create CustomPath path(s) for the join relation. 自定义扫描提供程序还可以提供连接路径。正如对于基本关系一样, 这样的路径必须产生与它替换的连接通常产生的输出相同的输出。为此, 连接提供程序应设置以下hook,然后在hook函数中为连接关系创建 CustomPath路径。

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;

这个hook将针对相同的连接关系被重复调用,以内部和外部关系的不同组合; 最小化重复工作是hook的责任。

56.1.1. 自定义扫描路径回调

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

将自定义路径转换为完成的计划。返回值通常是一个CustomScan对象, 回调必须分配和初始化它。有关详情,请参阅第 56.2 节

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

当在此自定义路径上调用nodeToString时生成附加输出。此回调是可选的。 因为nodeToString将自动转储结构中可以看到的所有字段, 包括custom_private,所以只有当CustomPath 实际嵌入在包含其他字段的较大结构中时是有用的。

<
/BODY >