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
PgIndex: typed indexes with expression and JSON-member keys and typed filters #27
PgIndex.BTree | Hash | Gist | SpGist | Gin | Brin, keys typed by method, pg.Unique, where:, include:, storage parameters per method, concurrently:; JSON members rendered as Npgsql's queries render them; the mapping taken from the declared property and store object, not from the column's first mapping; the 5.x index readers; the handover matcher (#10).
Done when
The P1 probes hold against the real assembly; the planner uses each JSON-member and expression index for the query EF generates; a 5.x project's snapshot diffs to nothing or to the documented migration.
Nothing is built yet. This says what was measured first, the slices, and five questions. Where a question has a recommendation, the slices below assume it.
Measured first
On Npgsql EF 11.0.0, and on PostgreSQL 16 and 18, which answer alike.
JSON members, as Npgsql's queries write them (ToQueryString()):
Member
In a query
text
"Payload" ->> 'Title'
int, bool, Guid, int?
CAST("Payload" ->> 'Rank' AS integer), … AS boolean, … AS uuid
nested
"Payload" #>> '{Inner,Code}'
DateTime
CAST("Payload" ->> 'At' AS timestamp with time zone)
An index on each of the first three forms, and on lower("Payload" ->> 'Title'), is used by the planner for the matching query (Index Scan, both servers).
A timestamp with time zone member cannot be indexed as the query writes it:CREATE INDEX is refused (42P17, the cast is not immutable). 5.x kept such a member as text, which is an index no query of EF Core's uses.
Native HasIndex on 11.0.0 (the design's section 12 describes rc.2):
A JSON-member index now scaffolds: CreateIndex(column: "Payload") with Npgsql:JsonIndexTypes, and the path is read from the model when the migration is applied. That is the form the plan's rule 5 keeps SchemaKit away from.
An index over a JSON member and a plain column together is refused by EF Core. A PgIndex can hold both, since each key is an expression or a column.
A complex-type column index is IX_People_Address_City, the name 5.x gives it.
What EF Core's operations do to an index is measured already (spike E): a rename of a column or the table and a schema move follow, an altered column leaves the index alone, a dropped column takes the index with it in silence, whether the index reads it as a key, in an expression, in INCLUDE or in its condition.
What 5.x stored for an index (read from its source at 5.6.0):
On the entity type, CustomIndex:CompositeIndexes: a JSON list of paths or parts (path, expr or tmpl, with desc and nulls), unique, filter, name, and props, which holds the provider's options under Npgsql's own annotation names.
On a property, CustomIndex:IsIndexed with IsUnique, Filter, Name and the same option keys as annotations of their own.
The model's CustomIndex:RenderingVersion changes what a declaration means. Version 1 (before 5.4.0) wrote a JSON member as text without a cast and built an expression's default name from the rendered SQL. From 2 on it writes a member as the queries do, from 3 on a TPC type's index has a copy per table.
Slices
Each is a sub-issue of #27 with its own PR, as before.
Slice
Holds when
A
PgIndex.BTree and pg.Unique, end to end: column and expression keys, Desc, NullsFirst, NullsLast, where:, include:, nullsDistinct:, name:; the stored form (owner Pg.Index); the contributor; the index's rows in PgImpact; the name claim (a relation of its schema); default name IX_{table}_{keys}
The catalog after a migration is what EnsureCreated() builds, on 16 and 18. A duplicate row is refused by a unique index. The planner uses an expression index for the query EF Core writes. A model against its own snapshot is no operations
B
Hash, Gist, SpGist, Gin, Brin; keys typed by method (PgKey<T> and the six key types); operator classes; Collate; the storage parameters of each method
The nine P1 probes and P3.collate-on-integer hold against the shipped assembly. An operator class the column's store type does not take is refused at the diff
JSON members as keys and in conditions, with the resolver's part of #43 and the sweep's rows behind ParityCatalogue.JsonMembers
Each rendering equals ToQueryString(), and the planner uses each index, live
E
The 5.x index readers and a fixture scaffolded by the published 5.6.0 with every kind of index
The snapshot diffs to nothing against the same model declared here, both ways, and 5.x's migration leaves the catalog EnsureCreated() builds
The handover to native HasIndex (#10) and the replay of 5.x's migrations (#28) come after E and stay their own issues. E changes the guard of #93: an index annotation with its reader registered leaves it.
What the slices need from the kernel
Nothing for A and B.ColumnRole.Included, StoreType, segments and the binder are there.
C needs the dialect to say whether an idempotent script carries a statement outside a transaction, and the statement to say which object it is for (question 2).
E needs a reader for an annotation on a property.LegacyDeclarationReader<T> is asked for one annotation of an entity type; 5.x's property-level index has none there. I would add the shape with E and show it then, under the experimental mark.
Questions
1. The order, and all five in preview.2. The plan's preview.2 holds all of it. A and B are the surface, C is small once its question is answered, D and E are the long ones. Recommended: this order, and no release cut in between.
2. Where an index created CONCURRENTLY is refused in an idempotent script (#155).Recommended: in the generator decorator, which is told Idempotent, asking the dialect: PostgreSQL's says such a script cannot carry the statement, the kernel's says it can (SQL Server carries one, measured in spike D). To name the index, SchemaSql stamps the statement's operation with what it is for; spike D measured that such an annotation reaches the generator on every path. That annotation sits in consumers' migrations, so its name is permanent once it ships. concurrently: is for the create alone: a drop and a rename are written as for any index.
3. What is changed in place.Recommended: a rename only (ALTER INDEX … RENAME TO), everything else a rebuild, a storage parameter included. ALTER INDEX … SET (fillfactor = …) would be cheaper, but it leaves the existing pages as they were, so the index is not the one a fresh database gets. An issue for it, not this cut.
4. A JSON member whose cast is not immutable (DateTime, and whatever else slice D measures). Recommended: refused where it is declared as a key, with the member and its store type named, and Sql.Raw as the way to write the expression by hand. Not 5.x's text fallback.
5. A 5.x snapshot of rendering version 1. Its JSON members and its expression indexes' default names are not what a declaration here resolves to: read as declarations, the diff would be empty while the database holds other expressions and other names. Recommended: the reader refuses such an index by name when the snapshot is of version 1, as the exclusion reader refuses a TPC root from before 5.5.0, and reads everything else of version 1. The way off it is not measured yet: whether moving to 5.6.0 first brings the database to the current rendering is slice E's to find out before the guide says so.
Not in this
No server-version gate. Everything here exists on PostgreSQL 14 but NULLS NOT DISTINCT (15); the tests run on 16 and 18.
5.x's shortening of a TPC copy's name (~, ~1) is not ported, as for exclusion constraints: a name that is too long is refused.
Activity
CaffeinatedCoder commentedon Nov 25, 2026
Proposal, 2026-11-25: how
PgIndexis builtNothing is built yet. This says what was measured first, the slices, and five questions. Where a question has a recommendation, the slices below assume it.
Measured first
On Npgsql EF 11.0.0, and on PostgreSQL 16 and 18, which answer alike.
JSON members, as Npgsql's queries write them (
ToQueryString()):"Payload" ->> 'Title'int,bool,Guid,int?CAST("Payload" ->> 'Rank' AS integer),… AS boolean,… AS uuid"Payload" #>> '{Inner,Code}'DateTimeCAST("Payload" ->> 'At' AS timestamp with time zone)lower("Payload" ->> 'Title'), is used by the planner for the matching query (Index Scan, both servers).timestamp with time zonemember cannot be indexed as the query writes it:CREATE INDEXis refused (42P17, the cast is not immutable). 5.x kept such a member as text, which is an index no query of EF Core's uses.Native
HasIndexon 11.0.0 (the design's section 12 describes rc.2):CreateIndex(column: "Payload")withNpgsql:JsonIndexTypes, and the path is read from the model when the migration is applied. That is the form the plan's rule 5 keeps SchemaKit away from.PgIndexcan hold both, since each key is an expression or a column.IX_People_Address_City, the name 5.x gives it.What EF Core's operations do to an index is measured already (spike E): a rename of a column or the table and a schema move follow, an altered column leaves the index alone, a dropped column takes the index with it in silence, whether the index reads it as a key, in an expression, in
INCLUDEor in its condition.What 5.x stored for an index (read from its source at 5.6.0):
CustomIndex:CompositeIndexes: a JSON list ofpathsorparts(path,exprortmpl, withdescandnulls),unique,filter,name, andprops, which holds the provider's options under Npgsql's own annotation names.CustomIndex:IsIndexedwithIsUnique,Filter,Nameand the same option keys as annotations of their own.CustomIndex:RenderingVersionchanges what a declaration means. Version 1 (before 5.4.0) wrote a JSON member as text without a cast and built an expression's default name from the rendered SQL. From 2 on it writes a member as the queries do, from 3 on a TPC type's index has a copy per table.Slices
Each is a sub-issue of #27 with its own PR, as before.
PgIndex.BTreeandpg.Unique, end to end: column and expression keys,Desc,NullsFirst,NullsLast,where:,include:,nullsDistinct:,name:; the stored form (ownerPg.Index); the contributor; the index's rows inPgImpact; the name claim (a relation of its schema); default nameIX_{table}_{keys}EnsureCreated()builds, on 16 and 18. A duplicate row is refused by a unique index. The planner uses an expression index for the query EF Core writes. A model against its own snapshot is no operationsHash,Gist,SpGist,Gin,Brin; keys typed by method (PgKey<T>and the six key types); operator classes;Collate; the storage parameters of each methodP3.collate-on-integerhold against the shipped assembly. An operator class the column's store type does not take is refused at the diffconcurrently:, with #155ParityCatalogue.JsonMembersToQueryString(), and the planner uses each index, liveEnsureCreated()buildsThe handover to native
HasIndex(#10) and the replay of 5.x's migrations (#28) come after E and stay their own issues. E changes the guard of #93: an index annotation with its reader registered leaves it.What the slices need from the kernel
ColumnRole.Included,StoreType, segments and the binder are there.LegacyDeclarationReader<T>is asked for one annotation of an entity type; 5.x's property-level index has none there. I would add the shape with E and show it then, under the experimental mark.Questions
1. The order, and all five in
preview.2. The plan'spreview.2holds all of it. A and B are the surface, C is small once its question is answered, D and E are the long ones. Recommended: this order, and no release cut in between.2. Where an index created
CONCURRENTLYis refused in an idempotent script (#155). Recommended: in the generator decorator, which is toldIdempotent, asking the dialect: PostgreSQL's says such a script cannot carry the statement, the kernel's says it can (SQL Server carries one, measured in spike D). To name the index,SchemaSqlstamps the statement's operation with what it is for; spike D measured that such an annotation reaches the generator on every path. That annotation sits in consumers' migrations, so its name is permanent once it ships.concurrently:is for the create alone: a drop and a rename are written as for any index.3. What is changed in place. Recommended: a rename only (
ALTER INDEX … RENAME TO), everything else a rebuild, a storage parameter included.ALTER INDEX … SET (fillfactor = …)would be cheaper, but it leaves the existing pages as they were, so the index is not the one a fresh database gets. An issue for it, not this cut.4. A JSON member whose cast is not immutable (
DateTime, and whatever else slice D measures). Recommended: refused where it is declared as a key, with the member and its store type named, andSql.Rawas the way to write the expression by hand. Not 5.x's text fallback.5. A 5.x snapshot of rendering version 1. Its JSON members and its expression indexes' default names are not what a declaration here resolves to: read as declarations, the diff would be empty while the database holds other expressions and other names. Recommended: the reader refuses such an index by name when the snapshot is of version 1, as the exclusion reader refuses a TPC root from before 5.5.0, and reads everything else of version 1. The way off it is not measured yet: whether moving to 5.6.0 first brings the database to the current rendering is slice E's to find out before the guide says so.
Not in this
NULLS NOT DISTINCT(15); the tests run on 16 and 18.~,~1) is not ported, as for exclusion constraints: a name that is too long is refused.