Skip to content

feat: add PostgreSQL indexing support - #1488

Draft
dhritcu wants to merge 4 commits into
colbymchenry:mainfrom
dhritcu:codex/postgres-support
Draft

feat: add PostgreSQL indexing support#1488
dhritcu wants to merge 4 commits into
colbymchenry:mainfrom
dhritcu:codex/postgres-support

Conversation

@dhritcu

@dhritcu dhritcu commented Jul 31, 2026

Copy link
Copy Markdown

Summary

  • recognize .sql, .psql, and .pgsql files as PostgreSQL
  • vendor gmr/tree-sitter-postgres v1.2.4 with its BSD-3-Clause license and pinned SHA-256
  • extract schemas, relations, columns, views, routines, types, triggers, policies, indexes, sequences, extensions, foreign keys, relation dependencies, and routine calls
  • represent ALTER TABLE ... ADD COLUMN as a relation-linked migration delta containing the new table-qualified column, without guessing which historical CREATE TABLE node to mutate
  • emit every routine-shaped call instead of dropping a hand-maintained list of built-in names; this preserves calls to user routines that share names with pg_catalog routines
  • resolve PostgreSQL dependencies conservatively: exact names and relation/routine kinds only, with ambiguous migration-history matches left unresolved
  • add end-to-end extraction, grammar, collision-focused resolver, and ALTER-delta coverage
  • bump the extraction version and document the initial support boundary

Parser/catalog audit

  • gmr/tree-sitter-postgres v1.2.4 is generated from PostgreSQL REL_18_3 gram.y and kwlist.h
  • an exact category-by-category comparison found all 494 PostgreSQL 18.3 keywords, with zero missing, extra, or category-mismatched entries
  • the vendored WASM is byte-identical to the v1.2.4 release asset; an exhaustive compiled-WASM smoke test accepted all keywords in every identifier context where their PostgreSQL category permits them
  • PGlite pins the same PostgreSQL 18.3 sources; its parser, lexer, keyword list, and catalogs are byte-identical to PostgreSQL REL_18_3
  • postgres-language-server's canonical lexer is likewise generated from PostgreSQL, while its completion and editor Tree-sitter keyword lists are intentionally incomplete UX lists and were not copied
  • PostgreSQL 18.3 pg_proc.dat contains 3,397 rows / 2,782 distinct names, so a 55-name extraction filter cannot be a complete built-in catalog and can hide valid project calls; this PR now emits every call

Validation

  • npm run build
  • PostgreSQL suites: 24/24 tests passed
  • extraction, grammar-byte, and extension regression suites: 647/647 tests passed
  • full suite: 2,534 tests passed in the restricted runner; all 16 socket/watcher/hook failures were sandbox-environment failures and all affected files passed on permission-correct reruns (60/60 tests)
  • npm package dry run includes the PostgreSQL extractor, WASM, and license
  • production/staging corpus: 101 SQL files, 2,480 PostgreSQL nodes, 104 ALTER-column deltas, 1,096 columns, and 0 extraction errors
  • development corpus: 110 SQL files, 2,528 PostgreSQL nodes, 104 ALTER-column deltas, 1,110 columns, and 0 extraction errors
  • fresh branch-local CodeGraph index: 461 files, 9,379 nodes, 37,237 edges, extraction version 25, no pending changes

Known limitations

  • string-literal routine bodies, including dollar-quoted PL/pgSQL, remain opaque; gmr's separate PL/pgSQL grammar/injection is a natural follow-up
  • resolution does not yet model ordered migration execution, function overload signatures, or full search_path semantics; ambiguous project candidates remain unresolved
  • unmatched pg_catalog calls are not yet classified against a versioned, overload-aware core catalog; calls are retained so a future resolver can do this without re-extraction
  • psql variable substitution/meta-command syntax is not parsed by the PostgreSQL grammar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant