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

在PostgreSQL中创建新钩子方法时出错,postgresql,Postgresql,我已经为我的学术需求为PostgreSQL编写了一个插件模块(版本:PostgreSQL9.3.4)。我正在使用钩子来影响这个插件模块中的计划者行为。我能够成功使用join_search_hook、planner_hook。但是我想为一个尚未定义钩子的方法创建一个新钩子 我想给它定义一个钩子 void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel) costsize.c中的方法 size_estimates_hook

我已经为我的学术需求为PostgreSQL编写了一个插件模块(版本:PostgreSQL9.3.4)。我正在使用钩子来影响这个插件模块中的计划者行为。我能够成功使用join_search_hook、planner_hook。但是我想为一个尚未定义钩子的方法创建一个新钩子

我想给它定义一个钩子

void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
costsize.c中的方法

size_estimates_hook_type size_estimates_hook = NULL;
我在优化器/path.h中声明了一个钩子

typedef void (*size_estimates_hook_type) (PlannerInfo *root, RelOptInfo *rels);
extern PGDLLIMPORT size_estimates_hook_type size_estimates_hook;
并在allpath.c的顶部初始化它

size_estimates_hook_type size_estimates_hook = NULL;
我在一个方法的allpath.c中添加了这个检查,以决定是否调用hooked方法

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编译的。

使用以下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
MODULES=模块名称
ifdef使用_PGXS
PG_配置=
PGXS:=$(shell$(PG_配置)——PGXS)
包括$(PGX)
其他的
subdir=contrib/模块名称
top_builddir=../。。
包括$(top_builddir)/src/Makefile.global
包括$(top_srcdir)/contrib/contrib-global.mk
恩迪夫

猜测一下,您的模块没有包含您修改的
优化器/path.h
。您是在使用PGXS,还是在
contrib/mymodulename
中的树中编译模块?如果您正在使用自制Makefile,请立即停止并使用PGXS。使用现有的插件进行指导,以及。很好的问题,顺便说一句,除了实际的Makefile之外的所有细节。@CraigRinger:正如你所猜测的,Makefile就是问题所在。我将在这里发布工作makefile