Repository navigation
fix: a column an element's expression reads holds the drop, it is not lost with it - #123
Merged
Merged
Conversation
…mn, it holds the drop
PgExclusionContributor.ImpactOf answered Lost for a dropped column that any
element reads. PostgreSQL drops an exclusion constraint with a column only
when the column is an element by itself. A column that an element's
expression reads, (lower("Note")) WITH =, is held like one in the condition:
the drop is refused while the constraint is there (2BP01). The migration
scaffolded and failed at apply, for a plain drop and for an alteration that
Npgsql writes as drop and add.
Measured on PostgreSQL 16 and 18, one row for each way a constraint reads a
column: an element by itself takes the constraint with it whatever else reads
the column too; a column read only through an expression, only by the
condition, or by SQL that names no column is held. The descriptor keeps the
columns that are elements by themselves, outside its comparison, and answers
Lost for those and RebuildAround for every other.
Closes #102
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #102
Problem
An exclusion constraint has an element that is an expression,
pg.Equal(x => x.Note!.ToLower()). The columnNoteis dropped and its element is taken out of the declaration. The migration scaffolds and fails at apply:The same when the declaration stays and
Notebecomes a stored computed column, which Npgsql writes as a drop and an add (#80).PgExclusionContributor.ImpactOfansweredLostfor a dropped column that any element reads. PostgreSQL drops the constraint with the column only when the column is an element by itself. Spike E measured that case and the condition's; a column inside an element's expression was not a cell of the table.Change
Lostfor a column that is an element by itself,RebuildAroundfor every other column the constraint reads. The descriptor keeps the columns that are elements by themselves (KeyColumns), in anOperational<>field outside its comparison: the elements say it already, so no model differs from its snapshot for it.CLAUDE.mdsays where a new kind of element gets its row.Tests
Locally: 517 kernel tests, 192 of the PostgreSQL package with the live ones on PostgreSQL 16.x and 18.x, 125 probes. Twelve tests of the PostgreSQL package are new, eight of them on a live server.
The server's word, as one test (
The_server_drops_the_constraint_with_an_elements_column_and_holds_every_other_column_it_reads):ALTER TABLE … DROP COLUMNby hand with the constraint in place, alike on 16 and 18.The statements of each diff (
PgExclusionMigrationTests): the constraint dropped beforeDropColumnOperationand before theAlterColumnOperationof a computed column for an expression's column; no drop for an element's column that something else reads too; beside SQL that names no column, an element's column goes and any other is rebuilt around; a rename and a type change of an expression's column leave the constraint alone.Each of those pairs applied (
PgExclusionLiveTests, throughAssertMigratesTo): the catalog after the migration is the catalogEnsureCreated()builds for the target.Guards shown to fail, four defects seeded one at a time in a scratch copy on PostgreSQL 18:
Decisions in this PR that are not confirmed
KeyColumnson the descriptor, outside its comparison, rather than a flag per element or reading the element's text.PgExclusionLiveTests, not by spike E.Not in this PR
PgIndextoo. An index is lost with a column in its expression; the constraint is not.🤖 Generated with Claude Code