在PostgreSQL中创建新的钩子方法时出错

时间:2014-08-14 16:32:35

标签: postgresql

我已根据我的学术要求为PostgreSQL编写了一个插件模块(版本:PostgreSQL9.3.4)我使用钩子来影响此插件模块中的计划程序行为。我能够成功使用join_search_hook,planner_hook。但是我想为一个尚未定义钩子的方法创建一个新的钩子。

我想为

定义一个钩子
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
costsize.c

中的

方法

我在 optimizer / paths.h

中声明了一个钩子
typedef void (*size_estimates_hook_type) (PlannerInfo *root, RelOptInfo *rels);
extern PGDLLIMPORT size_estimates_hook_type size_estimates_hook;

并将其初始化为 allpaths.c

size_estimates_hook_type size_estimates_hook = NULL;

我在allpaths.c中添加了这个检查方法,以决定是否调用钩子方法。

if (size_estimates_hook)
    (*size_estimates_hook) (root, rel);
else
    set_baserel_size_estimates(root, rel);

现在来看插件模块代码,

static join_search_hook_type prev_join_search = NULL;
static size_estimates_hook_type prev_size_estimates = NULL;

第一行编译正常,但第二行编译错误

"error: unknown type name ‘size_estimates_hook_type’"

我错过了定义新钩子方法的一些步骤吗? 注意:插件是使用专用的Makefile编译的。

1 个答案:

答案 0 :(得分:1)

使用以下makefile编译插件模块解决了这个问题。

MODULES = module_name
ifdef USE_PGXS
PG_CONFIG = <path to /backend/bin/pg_config>
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir = contrib/module_name
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
相关问题