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
Drop unmapped enum support, but not ability to work with them as strings #2404
There is no good reason to support conversion from an unmapped enum to the corresponding CLR type, so dropping it. The user should create relationship between CLR and PostgreSQL types. Otherwise, it should be possible to work with values as strings only.
Hang on, people have actually asked for this in various places. Since enums are actually transmitted as strings over the wire, supporting unmapped enums doesn't degrade performance or complicate our lives too much (unlike unmapped composites).
Reacted by Austin Drenski, Brar Piening, Dmitry Morozov, Max Grebeniuk and aanthony-twist
There's probably some work to be done with the unmapped enum support, but dropping it altogether would pose a challenge. (Among other things, this would impact existing EF Core workloads, right?)
But, for instance, there are a number of TODO items in the handler:
What was a reason to bring mapped types to Npgsql then? They are backed by unmapped type handlers which as you're saying desired by users. Does it make sense to drop mapping of types and generate handlers on the fly?
Why I want to drop unmapped enum support? The reason is simple - it has no difference from mapped enum support and actually the mapped handler is backed by the unmapped one.
Since the unmapped handler allows to pass a string as a value and read it back, we could just cut UnmappedEnumHandler to work only with strings. Is it acceptable for @dmitry-a-morozov?
Otherwise, I see no value in mapped enums. With meta programming magic I can achieve the same performance for unmapped enums as it can be done for mapped, without any boxing. If we go this way, composite mapping can be dropped to.
@YohDeadfall I'm not sure I'm following :) Do you want to drop mapped, or unmapped enums? :)
I think you may be saying that we can drop the mapping step, and just allow users to read and write CLR enums (and possibly composites) directly. The type handler would no longer be instantiated for one specific CLR enum type, but would rather accept any for writing and reading. If you think we can do this, retain current APIs (allow users to read/write both CLR enum types and strings) and maintain the same perf, then why not. The idea with a separate, explicit mapping step was to allow us to prepare a type handler that's optimized for the given CLR type (exactly the kind of work you're doing in the composite handler, generating delegates etc.).
If, on the other hand, you think we should eliminate the possibility of reading/writing both CLR enums and strings, then I'm not so sure. Mapped enums (and composites) are an important feature - they allow users to use their strongly-typed CLR type all the way to the database. They can define a regular, CLR enum and use that in their application, and also write it into the database. This isn't about performance - it's about providing a good API.
Unmapped enums indeed seem less important to me - but many users use these, and it seems that some layers (e.g. @dmitry-a-morozov's) depend on them. The advantage for layers is that you don't need to somehow generate a CLR enum in order to read/write an enum from PostgreSQL. Since the wire format for enums is a string, this also doesn't imply any perf degradation compared to a real enum type.
Otherwise, I see no value in mapped enums. With meta programming magic I can achieve the same performance for unmapped enums as it can be done for mapped, without any boxing. If we go this way, composite mapping can be dropped to.
This seems to be talking about the internal implementation of our handlers - I definitely don't have any problems with that.
Just one of them. The original proposal was about cutting off reading and writing enum values as CLR types. Sorry for being unclear, updated the description.
I think you may be saying that we can drop the mapping step
Yes, it's a second way which I can implement. This is how serializers work.
Just one of them. The original proposal was about cutting off reading and writing enum values as CLR types. Sorry for being unclear, updated the description.
So re dropping the ability to work with mapped and unmapped enums, I don't see why we should. Mapped CLR enums are obviously are better way for users to interact with a database driver, simply because CLR enums are how enums are represented in any .NET application. Unmapped enums seem useful for cases where you don't want to use a CLR type (or can't), e.g. layers.
Re dropping the mapping step, which is a totally different thing... Another point I forgot to mention above is to allow users to say which PostgreSQL enum corresponds to their CLR enum - the naming may be completely different. It's true we could achieve the same with an attribute ([PgName]) but a method-based option also makes sense - some users (like me) don't like to pollute their CLR objects with mapping attributes (see how EF Core supports both a fluent API and attributes).
@YohDeadfall although this issue isn't for 5.0, I think we should be clear about what we're discussing here... If this is just about an internal refactor between the mapped/unmapped type handlers - with no impact on the user - then I personally have no problem problem with anything. This is what it seems like from your code sample above. If this is the case, we can rename this issue to "Refactor unmapped enum support" and remove the breaking change label.
If, on the other hand, you're proposing to remove some ability which users currently have (breaking change), then I still don't understand what that ability is, and why we want to remove it.
I'm still not convinced that this is going to happen.
Especially if it breaks existing features in dependent code without providing a workaround.
The only reason pro this that we've heard yet is from @YohDeadfall:
On handlers am working on and which had no time to publish (again), there is no way to support this feature because of lack of generic dispatch.
We haven't seen the new handler design yet but in my opinion there should be a pretty high bar for removing existing and used functionality because of a redesign of an internal API.
I wouldn't say it can't happen but there need to be very clear and measurable advantages that would justify this.
You had a chance, I published an archive in our private channel (: But to be short, new handlers are strongly typed and optimized to have only one virtual call without generic dispatch, so each pair of CLR and PostgreSQL types has their own handler produced by a factory.
@dmitry-a-morozov and @daz10000, do I correctly understand that the library uses unmapped enums and there is no way to the user to specify which types should be mapped?
@YohDeadfall, correct. The purpose of the type provider is to generate strongly typed access to db based on schema definitions. Users do not know enums that exist in db beforehand.
This hasn't happened, and we won't be making this change. We'd likely even expand support as detailed by #3303 to align better with other ADO.NET providers
Activity
roji commentedon Mar 28, 2019
Hang on, people have actually asked for this in various places. Since enums are actually transmitted as strings over the wire, supporting unmapped enums doesn't degrade performance or complicate our lives too much (unlike unmapped composites).
austindrenski commentedon Mar 28, 2019
There's probably some work to be done with the unmapped enum support, but dropping it altogether would pose a challenge. (Among other things, this would impact existing EF Core workloads, right?)
But, for instance, there are a number of
TODOitems in the handler:npgsql/src/Npgsql/TypeHandlers/UnmappedEnumHandler.cs
Lines 44 to 45 in 7e2c31f
npgsql/src/Npgsql/TypeHandlers/UnmappedEnumHandler.cs
Lines 71 to 74 in 7e2c31f
npgsql/src/Npgsql/TypeHandlers/UnmappedEnumHandler.cs
Lines 77 to 79 in 7e2c31f
npgsql/src/Npgsql/TypeHandlers/UnmappedEnumHandler.cs
Lines 108 to 111 in 7e2c31f
YohDeadfall commentedon Mar 29, 2019
What are real use cases? When isn't possible to use mapped enums instead of unmapped?
Brar commentedon Mar 29, 2019
@YohDeadfall #1736 otherwise just search closed issues for "unmapped enum"
Brar commentedon Mar 29, 2019
@dmitry-a-morozov you might want to chime in here and perhaps also at #2403
YohDeadfall commentedon Mar 29, 2019
What was a reason to bring mapped types to Npgsql then? They are backed by unmapped type handlers which as you're saying desired by users. Does it make sense to drop mapping of types and generate handlers on the fly?
YohDeadfall commentedon Mar 29, 2019
@kspeakman You are welcome here too.
YohDeadfall commentedon Mar 30, 2019
Why I want to drop unmapped enum support? The reason is simple - it has no difference from mapped enum support and actually the mapped handler is backed by the unmapped one.
Since the unmapped handler allows to pass a string as a value and read it back, we could just cut
UnmappedEnumHandlerto work only with strings. Is it acceptable for @dmitry-a-morozov?Otherwise, I see no value in mapped enums. With meta programming magic I can achieve the same performance for unmapped enums as it can be done for mapped, without any boxing. If we go this way, composite mapping can be dropped to.
roji commentedon Apr 1, 2019
@YohDeadfall I'm not sure I'm following :) Do you want to drop mapped, or unmapped enums? :)
I think you may be saying that we can drop the mapping step, and just allow users to read and write CLR enums (and possibly composites) directly. The type handler would no longer be instantiated for one specific CLR enum type, but would rather accept any for writing and reading. If you think we can do this, retain current APIs (allow users to read/write both CLR enum types and strings) and maintain the same perf, then why not. The idea with a separate, explicit mapping step was to allow us to prepare a type handler that's optimized for the given CLR type (exactly the kind of work you're doing in the composite handler, generating delegates etc.).
If, on the other hand, you think we should eliminate the possibility of reading/writing both CLR enums and strings, then I'm not so sure. Mapped enums (and composites) are an important feature - they allow users to use their strongly-typed CLR type all the way to the database. They can define a regular, CLR enum and use that in their application, and also write it into the database. This isn't about performance - it's about providing a good API.
Unmapped enums indeed seem less important to me - but many users use these, and it seems that some layers (e.g. @dmitry-a-morozov's) depend on them. The advantage for layers is that you don't need to somehow generate a CLR enum in order to read/write an enum from PostgreSQL. Since the wire format for enums is a string, this also doesn't imply any perf degradation compared to a real enum type.
This seems to be talking about the internal implementation of our handlers - I definitely don't have any problems with that.
[-]Drop unmapped enum support[/-][+]Drop unmapped enum support, but not ability to work with them as strings[/+]YohDeadfall commentedon Apr 1, 2019
Just one of them. The original proposal was about cutting off reading and writing enum values as CLR types. Sorry for being unclear, updated the description.
Yes, it's a second way which I can implement. This is how serializers work.
roji commentedon Apr 1, 2019
So re dropping the ability to work with mapped and unmapped enums, I don't see why we should. Mapped CLR enums are obviously are better way for users to interact with a database driver, simply because CLR enums are how enums are represented in any .NET application. Unmapped enums seem useful for cases where you don't want to use a CLR type (or can't), e.g. layers.
Re dropping the mapping step, which is a totally different thing... Another point I forgot to mention above is to allow users to say which PostgreSQL enum corresponds to their CLR enum - the naming may be completely different. It's true we could achieve the same with an attribute (
[PgName]) but a method-based option also makes sense - some users (like me) don't like to pollute their CLR objects with mapping attributes (see how EF Core supports both a fluent API and attributes).13 remaining items
roji commentedon Sep 17, 2020
Rediscuss for 6.0 whether we want to do this or not.
roji commentedon Sep 26, 2020
@YohDeadfall although this issue isn't for 5.0, I think we should be clear about what we're discussing here... If this is just about an internal refactor between the mapped/unmapped type handlers - with no impact on the user - then I personally have no problem problem with anything. This is what it seems like from your code sample above. If this is the case, we can rename this issue to "Refactor unmapped enum support" and remove the breaking change label.
If, on the other hand, you're proposing to remove some ability which users currently have (breaking change), then I still don't understand what that ability is, and why we want to remove it.
YohDeadfall commentedon Oct 12, 2020
On handlers am working on and which had no time to publish (again), there is no way to support this feature because of lack of generic dispatch.
daz10000 commentedon Oct 14, 2020
I'm sorry I haven't had a chance to test this assumption or comment, but from reading the thread, I think there's a good chance this will completely break enum support in https://github.com/demetrixbio/FSharp.Data.Npgsql because we handle enums generically.
Brar commentedon Oct 14, 2020
@daz10000 I think you can try https://github.com/YohDeadfall/npgsql/tree/drop-unmapped-enum now to verify your assumptions.
I'm still not convinced that this is going to happen.
Especially if it breaks existing features in dependent code without providing a workaround.
The only reason pro this that we've heard yet is from
@YohDeadfall:
We haven't seen the new handler design yet but in my opinion there should be a pretty high bar for removing existing and used functionality because of a redesign of an internal API.
I wouldn't say it can't happen but there need to be very clear and measurable advantages that would justify this.
YohDeadfall commentedon Oct 14, 2020
You had a chance, I published an archive in our private channel (: But to be short, new handlers are strongly typed and optimized to have only one virtual call without generic dispatch, so each pair of CLR and PostgreSQL types has their own handler produced by a factory.
@dmitry-a-morozov and @daz10000, do I correctly understand that the library uses unmapped enums and there is no way to the user to specify which types should be mapped?
melanore commentedon Oct 14, 2020
@YohDeadfall, correct. The purpose of the type provider is to generate strongly typed access to db based on schema definitions. Users do not know enums that exist in db beforehand.
YohDeadfall commentedon Oct 14, 2020
Does it generates wrappers around Npgsql or is it a proxy? Or would be better to ask how does it work?
NinoFloris commentedon Aug 15, 2023
This hasn't happened, and we won't be making this change. We'd likely even expand support as detailed by #3303 to align better with other ADO.NET providers