← Back to Pull requests

feat: functional/expression indexes via override_expression #153

Open
arreyder opened this pull request with 162 lines diff across 10 files
View on GitHub
arreyder arreyder commented on Jul 14, 2026 23:11 UTC
Author

What & why

Adds an override_expression field to the pgdb.v1.MessageOptions.Index option so proto authors can declare functional/expression indexes — e.g. a btree over a JSONB path. Today the only way to index a value derived from a JSONB/proto-map field is to denormalize it into a real column (proto field + write-path + backfill migration + Dynamo re-mirror). This exposes a capability the DDL layer already has.

Motivating case: SearchUserOwnership filters (role_to_entitlement_id ->> 'primary') IN (...) with no serving index (the only index on that column is GIN/containment). With this, the fix is one index declaration:

option (pgdb.v1.msg).indexes = {
  name: "primary_owner"
  method: INDEX_METHOD_BTREE
  partial_deleted_at_is_null: true
  override_expression: "tenant_id, ((\"pb$role_to_entitlement_id\" ->> 'primary'))"
};

How

  • index2sql already renders Index.OverrideExpression verbatim (HNSW vector indexes use it). This just threads the new proto field through extraIndexes into that existing path. When set, columns is ignored for DDL (matching the vector precedent); partial_deleted_at_is_null still applies.

  • Bug fix: the descriptor template interpolated OverrideExpression unescaped ("{{ .DB.OverrideExpression }}"). Any expression containing a quoted identifier produced invalid Go (missing ',' in composite literal). Now emitted via %q. Vector overrides never tripped this (no quotes); expression indexes do.
  • Author contract

    The override body is emitted verbatim, so it carries physical column tokens: proto fields are pb$-prefixed and quoted, system columns are bare — same convention the vector overrides already use.

    Validation

  • New DB-free regression test (TestIndexOverrideExpression) asserts the rendered CREATE INDEX (verbatim body + preserved partial predicate).

  • Existing TestSchemaPet now exercises the new Pet functional index against a real Postgres.

  • Manually verified the generated DDL executes on Postgres 16 and the planner uses the index (Index Scan).
  • Diff shape

    Core change is ~16 lines (proto field + one passthrough + template escape). The rest is regenerated .pb.go / example output.

    🤖 Generated with Claude Code

    Diff: 162 lines (+151 / -11) across 10 files Reviewer: None requested Review duration: 207821m
    All Vouch review confidence checks passed
    Residual risk 0.40 = Change Risk (0.66) × (1 − Review Confidence (0.38)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.66 · 162 lines diff across 10 files
    0.66
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 10%
    38%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.305
    No Reviewer Assigned no_reviewer_assigned
    0.120
    Real PR Conversation Timeline
    1 comments
    "Review active on #153"
    general weight: 0.35
    Reviewers
    None requested
    Assignees
    arreyder arreyder
    Labels
    risk: medium confidence: 38.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 65.7% (HIGH) · Higher = larger blast radius
    65.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 38.5% · Lower = rushed or shallow review
    38.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 40.4% · Moderate risk
    40.4%