Extensibility on PostgreSQL

2020-07-18 08:02发布

问题:

I created my own R-tree: "rtree.h"

I want to create an extension in postgres with my own data structure (Using PostGis), already I read about Interfacing Extensions To Indexes and now I'm reading some examples here, but to be honest, I don't get it at all how can I use my own R-Tree to create an Extensibility, I understand the concepts about operators, indexes, etc, But I don't know how to do it.

So, How can I connect my file to PostGis and then create an extensibility on PostgreSQL?

Since the extensibilities are functions, let say the one example in PostgreSQL's website:

CREATE OR REPLACE FUNCTION my_consistent(internal, data_type, smallint, oid, internal)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;

How exactly it works? MODULE_PATHNAME is equal to /path/rtree.h?

回答1:

In terms of how to define a function written in C in postgres you have to compile the object first, so the 'MODULE PATHNAME' would be rtree.so on Linux systems and probably a dll on Windows. The code in the functions directory here provide an outline of the function definitions in C, and the SQL function to declare the function in Postgres.

In terms of how you would implement the R-Tree, I would use the GIST resource that you have already found. I don't think you can just compile your R-Tree.c program and it just work, you have to work with the GIST construct. It looks like there was once an r-tree implementation in the Postgres trunk that you may be able to find, or you could have a look at this B-tree gist extension which is in the current trunk: https://github.com/postgres/postgres/tree/master/contrib/btree_gist.