Reputation: 1771
I want to create a new data type and new operators in PostgreSQL. I saw that in the documentation, it is possible to incorporate new source files in C (for example) and create a new data type and operators. PostgreSQL is extensible in that direction. More information at: documentation
But also the PostgreSQL has open source, and I could alter the source code and add a new data type, compiling a new version.
With that, I want to know what the differences, advantages and disadvantages of each method of including a new data type in PostgreSQL. I'm very concerned about the performance in query processing. Thank you.
Upvotes: 2
Views: 689
Reputation: 45770
There are no differences between internal operators and datatypes and custom operators and datatypes - and then it has same performance. Outer and inner implementation respects same rules and patters. So there is not reason for hacking Postgres for it.
We have patched PostgreSQL in GoodData - and we have a own extensions too - everywhere where it is possible and practical, we use a custom extensions - and where it is not possible, we use a own hacks - backports from 9.2, 9.3, some enhancing pg_dump and psql, statistics - but we have a active PostgreSQL's hackers in company. It is not usual. For users without experience with PostgreSQL hacking are creating extensions safe and good performance solution.
Upvotes: 0
Reputation: 9157
I fully agree with Jachim's answer. Another thing is:
Developing your own C-Language extension in PostgreSQL is (rather) well documented - simple programs can be done by compiling just one function of code and writing the corresponding functions. Adding a custom datatype is a bit more complicated, but still doable. The extension I developed was even written in C++ with just a bit of wrapper glue between PostgreSQL's plain C - that made developing much more flexible.
Altering the PostgreSQL core however is more complicated in terms of how do you start and what do you do. And in the end, you archive the same.
To sum it up: C-Language functions gives you all the advantages:
I can not see any advantages of altering PostgreSQLs core, but many disadvantages:
If you need an example of a lot of different ways to use the C-Language interface, have a look at the PostGis source code - they use nearly all function types and have a lot of fancy tricks in their code.
Upvotes: 0
Reputation: 409166
If you modify PostgreSQL you have to maintain the whole code-base, and you have to do your patching every time you want to upgrade even between minor versions. If you make an extension you only have your little extension to maintain. And it's also much more easy to distribute a small extension program if you ever want to do that.
Upvotes: 8