Add lower_columns index option for case-insensitive lookups #171
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.66) × (1 − Review Confidence (0.58)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.66 · 587 lines diff across 10 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 10%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.382
Shallow Review Depth
shallow_review_depth
0.289
No Reviewer Assigned
no_reviewer_assigned
0.120
Real PR Conversation Timeline
1 comments
"Review active on #171"
general
weight: 0.35
alan-lee-12
What
Adds a typed index option
lower_columnstoMessageOptions.Index:Listed entries of
columnsare wrapped inlower()in the generated index expression.Columnsis still populated as before; the expression goes through the existingOverrideExpressionpath, using the same string-breakout form aspartial_deleted_at_is_null, soio.ColumnNameapplies the top-level or nested column prefix at runtime.Example (
example/models/food/v1/food.proto,PastaIngredient):Generated literal:
index2sqloutput (partitioned table, so no CONCURRENTLY):With a nested prefix (
Nested("11$")) the expression renders aspb$tenant_id, lower(pb$11$pasta_id). Generated column names are lower snake case or numeric behind thepb$prefix, so the unquoted identifiers are valid. Postgres stores them aslower("pb$pasta_id")inpg_indexes.Validation
Generation panics, in the same way as the existing "could not find field for index" case, when:
lower_columnsentry is not listed incolumnsmethodis notINDEX_METHOD_BTREEbit_hamming_opsis setMESSAGE_BEHAVIOR_INET_ADDRstrings (stored asinet) are rejected.Existing options behave the same as before. Indexes without
lower_columnsgenerate identical code.Safe query builder
getSafeFields(internal/pgdb/pgdb_query_builder.go) skips a column of an index when that index lowers it, so alower(x)index adds no plain-column safe operators (Eq/Gt/Lt/IsNotEmpty, ...) forx. Other columns of the same index, such astenant_id, still get operators as before. The existing logic grants operators per column with no btree-prefix ordering, so this is a per-column skip. Lowered columns are carried on the generator-internalindexContext.LoweredColumns. The runtimepgdb_v1.Indexstruct is unchanged.The example adds
PastaIngredient.label, which only alower_columnsindex covers. The builder has no safeLabel()method, butUnsafe().Label()is still there.pasta_id, which plain indexes also cover, keeps its safe operators, and its generated code is unchanged.Tests
internal/pgdb/pgdb_index_test.go:-
TestValidateLowerColumnscovers the accept path and the not-in-columns, non-BTREE and bit_hamming_ops failures.-
TestExtraIndexesLowerColumnsbuilds a pgs AST from an in-memory descriptor set and runsextraIndexeson it. It covers a top-level column and a dotted nested column. The nested caseprofile.handleproduceslower(" + io.ColumnName("8$handle") + "). It also checks that each of these is rejected: oneof name, int64, repeated string, inet-backed string andgoogle.protobuf.StringValue.example/models/food/v1/lower_columns_test.go:-
TestLowerColumnsIndexchecksColumns,OverrideExpressionandWherePredicatefor V13 and V17, the nested prefix, and the exactIndexSchemaDDL.-
TestLowerColumnsIndexPostgresappliesCreateSchemato a real Postgres and checks that all threelower()indexes exist.-
TestLowerColumnsSafeOperatorschecks that there is no safeLabel(), thatUnsafe().Label()exists, and thatPastaIdkeeps Eq/Gt/Gte/Lt/Lte/IsNotEmpty.TestSchemaFoodPasta: the partial-index count forPastaIngredientgoes from 1 to 2.Commands run:
make generateandmake example: regeneratedpgdb/v1/pgdb.pb.goand the food example. The only example changes are infood, and running both again produces no further diff.make lint(buf lint): pass.LANG=C.UTF-8 make test: everything passes exceptinternal/pgtest TestPostgreSQLWithConfig("did not find PostgreSQL executables installed"). That failure comes from the local environment: the test looks for Postgres at fixed install paths. This change doesn't touch it.Notes for reviewers
dropped: trueskiplower_columnsvalidation, because a drop only needs the index name.google.protobuf.StringValuefields are rejected. Only plainstringfields are supported.lower(col) = lower(?)predicate.Motivation: FDE-443 (case-insensitive exact username lookup on a large table without a backfill).
🤖 Generated with Claude Code