You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Better support for official extension types, and 3rd party types in npgsql v3+ #696
I would like to start a discussion on how improve the type mapping system to enable handling of official extension types from the following modules: citext, isn, ltree, hstore and cube, as well as types from 3rd-party extension modules like PostGIS.
It would be extremely useful to be able to write your own type handling for extension types. Also, it is extremely annoying to have to jump through "hoops" when using official extension types such as citext. For citext you have to manually cast the citext type to text in the queries you write (afaik this wasn't the case in 2.2.5).
It seems like the TypeHandlerRegistry is not allowing any changes or additions to the default type mapping npgsql as it is marked "internal". I realize it is not possible to simply open this class up, but I guess this is basically what needs to be done.
I'm fairly new to the npgsql codebase/project so I'm not sure if the regular maintainers see any big issues or obstacles if custom type mapping should be added to npgsql.
@JohannesEH, you're absolutely right that the official/standard types should be well-supported. This should have happened for the 3.0.0 release but it slipped through the cracks with the massive amount of work we had.
Note that hstore is already supported in 3.0.0, and citext support has already been done for 3.0.1 (#695).
My approach is to simply add support for all the standard types, one-by-one (I'll look into the missing ones from your list ASAP). We definitely don't expect anyone to cast citext to text or anything like that: it's just a very temporary situation until we get things done.
We discussed allowing users to register external type handlers, and the new type handling system in 3.0 definitely goes in that direction. However, since everything is so new it seems much too early to allow people to go off and code against this API - I'd like to be able to change it without breaking too much. In addition, the list of additional types isn't huge - there aren't a million people writing PostgreSQL extensions out there (I think). So IMHO it's better at this stage to cover the few missing popular types (and accept PRs for others from the community) rather than open up the API for 3rd-party type handlers.
By the way, PostGIS is a more complicated case because the type system involved is non-trivial. We already merged a PR for all PostGIS 2D types (#665), but we still need the remaining (3D) types, and in any case this will most probably be released for 3.1.
Hi @roji. Thank you for your replies. It sounds like you got it all handled and thought out. That was essentially all I needed to hear. It seems as if all the isn types is handled as 64bit integers internally.So wouldn't that be the binary format? From the postgres 9.4 docs:
Internally, all these types use the same representation (a 64-bit integer), and all are interchangeable. Multiple types are provided to control display formatting and to permit tighter validity checking of input that is supposed to denote one particular type of number.
As far as 3rd party types I figured you had some plans based on the type registry. And I respect that you have to stabilize the api before releasing it. Please let me know if I can be of assistance. I'm fairly bogged down atm, but I'll see if I can free up some hours if you need me to.
Finally, thank you for all the hard and awesome work you are doing on this library! 👍
@JohannesEH, thanks for the kind words and the offer to help :)
From a quick look, it seems that that cube and isn don't support binary transfer, which isn't good news. Regardless of the internal representation of a type within PostgreSQL, a type also defines text and binary I/O functions, and these types unfortunately define only text transfer. Npgsql 3.0 only supports binary transfer (it was a complicated discussion). Without binary transfer, a type can only be transferred as text. This is frequently inefficient and sometimes is unstable as text representations of types depend on parameters and other things.
I've added a FAQ section with a workaround for non-binary types. However, the best thing would be to simply contribute binary I/O functions for the problematic types. In addition, if all the isn types are internally represented as a 64-bit integer, it should be very easy to implement and provide a substantial performance boost (compare transferring one long to the long string representation of an ISBN, plus parsing time...).
So if you'd like to help and have some C know-how, it would be great if you could help out with a patch for that (please let me know, otherwise maybe someone else can do it). Otherwise there's work to do :) Let me know.
@roji it sounds like the right way to go but unfortunately I have little to none C programming experience so I probably wouldn't be the right person for the job. Not that I wouldn't take the challenge, but I guess it should be left as an exercise for an experienced C developer. 😉
I've opened issues #697, #698 and #699 to track support for isn, cube and ltree. Unfortunately all three of these modules are text-only, so patches for adding binary I/O need to be sent to the PostgreSQL team first.
Take a look at our open issues list and especially those with the "up for grabs" label if you're interested in contributing. It out be great to have you helping out.
Activity
roji commentedon Aug 11, 2015
@JohannesEH, you're absolutely right that the official/standard types should be well-supported. This should have happened for the 3.0.0 release but it slipped through the cracks with the massive amount of work we had.
Note that hstore is already supported in 3.0.0, and citext support has already been done for 3.0.1 (#695).
My approach is to simply add support for all the standard types, one-by-one (I'll look into the missing ones from your list ASAP). We definitely don't expect anyone to cast citext to text or anything like that: it's just a very temporary situation until we get things done.
We discussed allowing users to register external type handlers, and the new type handling system in 3.0 definitely goes in that direction. However, since everything is so new it seems much too early to allow people to go off and code against this API - I'd like to be able to change it without breaking too much. In addition, the list of additional types isn't huge - there aren't a million people writing PostgreSQL extensions out there (I think). So IMHO it's better at this stage to cover the few missing popular types (and accept PRs for others from the community) rather than open up the API for 3rd-party type handlers.
By the way, PostGIS is a more complicated case because the type system involved is non-trivial. We already merged a PR for all PostGIS 2D types (#665), but we still need the remaining (3D) types, and in any case this will most probably be released for 3.1.
Let me know your thoughts.
roji commentedon Aug 11, 2015
isn seems to have no binary support...
JohannesEH commentedon Aug 11, 2015
Hi @roji. Thank you for your replies. It sounds like you got it all handled and thought out. That was essentially all I needed to hear. It seems as if all the isn types is handled as 64bit integers internally.So wouldn't that be the binary format? From the postgres 9.4 docs:
As far as 3rd party types I figured you had some plans based on the type registry. And I respect that you have to stabilize the api before releasing it. Please let me know if I can be of assistance. I'm fairly bogged down atm, but I'll see if I can free up some hours if you need me to.
Finally, thank you for all the hard and awesome work you are doing on this library! 👍
roji commentedon Aug 11, 2015
@JohannesEH, thanks for the kind words and the offer to help :)
From a quick look, it seems that that cube and isn don't support binary transfer, which isn't good news. Regardless of the internal representation of a type within PostgreSQL, a type also defines text and binary I/O functions, and these types unfortunately define only text transfer. Npgsql 3.0 only supports binary transfer (it was a complicated discussion). Without binary transfer, a type can only be transferred as text. This is frequently inefficient and sometimes is unstable as text representations of types depend on parameters and other things.
I've added a FAQ section with a workaround for non-binary types. However, the best thing would be to simply contribute binary I/O functions for the problematic types. In addition, if all the isn types are internally represented as a 64-bit integer, it should be very easy to implement and provide a substantial performance boost (compare transferring one long to the long string representation of an ISBN, plus parsing time...).
So if you'd like to help and have some C know-how, it would be great if you could help out with a patch for that (please let me know, otherwise maybe someone else can do it). Otherwise there's work to do :) Let me know.
JohannesEH commentedon Aug 11, 2015
@roji it sounds like the right way to go but unfortunately I have little to none C programming experience so I probably wouldn't be the right person for the job. Not that I wouldn't take the challenge, but I guess it should be left as an exercise for an experienced C developer. 😉
roji commentedon Aug 12, 2015
@JohannesEH no problem :)
I've opened issues #697, #698 and #699 to track support for isn, cube and ltree. Unfortunately all three of these modules are text-only, so patches for adding binary I/O need to be sent to the PostgreSQL team first.
Take a look at our open issues list and especially those with the "up for grabs" label if you're interested in contributing. It out be great to have you helping out.