PostgreSQL 12でpg_hint_planをインストールする方法

brew install postgresql でインストールした postgres で pg_hint を使えるようにする方法が分からなかったのでメモ。

URL一覧

インストール方法

OSDN の v1.3.4 の rpm に含まれているのは Postgres 11 用らしく、 Postgres 12 で動くか不安だったので使うのは避けた。

そして、 v1.3.4 のソースも Postgres 11 用なのか、ビルドはエラーになった。

$ make
clang -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -O2  -I. -I./ -I/usr/local/include/postgresql/server -I/usr/local/include/postgresql/internal -I/usr/local/Cellar/icu4c/64.2/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/readline/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2   -c -o pg_hint_plan.o pg_hint_plan.c
pg_hint_plan.c:20:10: fatal error: 'nodes/relation.h' file not found
#include "nodes/relation.h"
         ^~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [pg_hint_plan.o] Error 1

GitHubのmasterブランチ

GitHub からソースを取得し、 22a770c で make すると、今度は別のエラーが出た。

$ make
clang -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -O2  pg_hint_plan.o -L/usr/local/lib -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib  -Wl,-dead_strip_dylibs  -Wl,--build-id  -bundle -bundle_loader /usr/local/Cellar/postgresql/12.1/bin/postgres -o pg_hint_plan.so
ld: unknown option: --build-id
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_hint_plan.so] Error 1

よく分からないけど --build-id のオプションがダメらしいので、消してみたら make と make install が実行できた。

$ git diff
diff --git a/Makefile b/Makefile
index de9f5c5..bde9cdc 100644
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,7 @@ TARSOURCES = Makefile *.c  *.h COPYRIGHT* \
        doc/* expected/*.out sql/*.sql sql/maskout.sh \
        data/data.csv input/*.source output/*.source SPECS/*.spec

-LDFLAGS+=-Wl,--build-id
+LDFLAGS+=-Wl

 installcheck: $(REGRESSION_EXPECTED)

これで pg_hint_plan は使えるようになったけど、これが正式なやり方かは謎。