-
Notifications
You must be signed in to change notification settings - Fork 978
feat(postgresql): add accurate analyzer mode for database-only analysis #4237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kyleconroy
wants to merge
10
commits into
main
Choose a base branch
from
claude/accurate-analyzer-mode-UeNm6
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Add an optional `analyzer.accurate: true` mode for PostgreSQL that bypasses
the internal catalog and uses only database-backed analysis.
Key features:
- Uses database PREPARE for all type resolution (columns, parameters)
- Uses expander package for SELECT * and RETURNING * expansion
- Queries pg_catalog to build catalog structures for code generation
- Skips internal catalog building from schema files
Configuration:
```yaml
sql:
- engine: postgresql
database:
uri: "postgres://..." # or managed: true
analyzer:
accurate: true
```
This mode requires a database connection and the schema must exist in the
database. It provides more accurate type information for complex queries.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add three end-to-end test cases for the accurate analyzer mode: 1. accurate_star_expansion - Tests SELECT *, INSERT RETURNING *, UPDATE RETURNING *, DELETE RETURNING * 2. accurate_enum - Tests enum type introspection from pg_catalog 3. accurate_cte - Tests CTE (Common Table Expression) with star expansion All tests use the managed-db context which requires Docker to run PostgreSQL containers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Update expected output files to match actual sqlc generate output: - Fix parameter naming (Column1, Column2, dollar_1) - Fix nullability types (sql.NullString, sql.NullInt32) - Fix CTE formatting (single line) - Fix query semicolons 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Tests CTE using VALUES clause with column aliasing to verify accurate analyzer handles inline table expressions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The VALUES clause was incorrectly formatting multiple rows as a single
row with multiple columns. For example:
VALUES ('A'), ('B'), ('C')
was being formatted as:
VALUES ('A', 'B', 'C')
This caused the star expander to think the VALUES table had 3 columns
instead of 1, resulting in incorrect SELECT * expansion.
The fix properly iterates over each row in ValuesLists and wraps each
in parentheses.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
…o claude/accurate-analyzer-mode-UeNm6
… experiment This change refactors the "accurate analyzer mode" feature: 1. Rename config option from `analyzer.accurate: true` to `analyzer.database: only` - a third option in addition to true/false 2. Gate the feature behind the `analyzerv2` experiment flag. The feature is only enabled when: - `analyzer.database: only` is set in the config - `SQLCEXPERIMENT=analyzerv2` environment variable is set 3. Update JSON schemas to support boolean or "only" for analyzer.database 4. Add experiment tests for analyzerv2 flag 5. Update end-to-end test configs and expected outputs The database-only mode skips building the internal catalog from schema files and instead relies entirely on the database for type resolution and star expansion. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…nly) This extends the database-only analyzer mode to support SQLite in addition to PostgreSQL: 1. Add EnsureConn, GetColumnNames, and IntrospectSchema methods to the SQLite analyzer for database-only mode functionality 2. Update compiler to handle SQLite database-only mode: - Add sqliteAnalyzer field to Compiler struct - Initialize SQLite analyzer when database-only mode is enabled - Build catalog from SQLite database via PRAGMA table_info 3. Add SQLite end-to-end test case for database-only mode The SQLite database-only mode uses PRAGMA table_info to introspect tables and columns, and prepares queries to get column names for star expansion. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add EnsureConn and GetColumnNames methods to Analyzer interface - Remove engine-specific pgAnalyzer and sqliteAnalyzer fields from compiler - Use unified analyzer interface for database connection initialization - Keep parsing schema files to build catalog, only use database for star expansion 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
In database-only mode, parse the schema migrations to validate syntax and collect them for the database connection, but skip updating the catalog. The database will be the source of truth for schema information. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
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.
Add an optional
analyzer.accurate: truemode for PostgreSQL that bypassesthe internal catalog and uses only database-backed analysis.
Key features:
Configuration:
This mode requires a database connection and the schema must exist in the
database. It provides more accurate type information for complex queries.
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com