transpiler: three-tier intercept to minimize transpilation#192
Draft
transpiler: three-tier intercept to minimize transpilation#192
Conversation
Most queries (plain SELECT/INSERT/UPDATE/DELETE) need zero transforms — DuckDB handles them natively. The parse/transform/deparse cycle was wasted work for these queries. This adds a pre-parse classifier (Tier 0) that does fast case-insensitive substring matching. If no PG-specific patterns are found, the query goes straight to DuckDB without any parsing — 25x faster than the full pipeline (1.6μs vs 41μs, 2 allocs vs 48). When patterns are detected, only the relevant transforms run (Tier 1) via bitmask-based selective execution, skipping unneeded transforms. Architecture: - Tier 0: Classify() does string scan, returns Direct for plain queries - Tier 1: transpileWithFlags() parses and runs only flagged transforms - Tier 2: Error-driven retry (unchanged, handled by conn.go) All changes encapsulated in transpiler package. The 4 call sites in conn.go remain unchanged — they still call tr.Transpile(query). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…, FlagAll sentinel - Fix hasAnyPrefix to skip line comments (-- ...) in addition to block comments, preventing false negatives like "-- comment\nSET ..." - Replace brittle FlagAll magic number with flagSentinel pattern - Add explanatory comments to classifier for known false-positive patterns: ~ operator, CTID substring, writable CTE, UNIQUE/REFERENCES in DDL - Document FallbackToNative behavioral change for Tier 0 queries - Add test cases for line comment handling in SET/SHOW classification Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…NT ON, REFRESH The DDL transform marks these as no-ops (IsNoOp=true) but the classifier was missing them, causing Tier 0 to send them directly to DuckDB where they would fail instead of being silently acknowledged in DuckLake mode. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
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.
Summary
server/conn.go— all 4 call sites still calltr.Transpile(query)which now internally classifiesBenchmark results
SELECT)Architecture
Classify()string scan → return original SQLClassifier patterns
Conservative rule: false positives (unnecessary transform runs) are fine. False negatives would be bugs.
Detects:
SET/SHOW/RESET,pg_catalog.*,information_schema,public.,version(), PG types (JSONB,BYTEA,INET, etc.), type casts (::regtype,::regclass), PG functions (array_agg,regexp_matches, etc.), operators (->,~),FOR UPDATE,ctid,_pg_expandarray,ON CONFLICT, DDL patterns (DuckLake only), writable CTEs,$Nplaceholders.Test plan
TestClassify_Direct— plain queries returnDirect=trueTestClassify_NeedsTransform— PG-specific queries return correct flagsTestClassify_DuckLakeMode— DDL patterns flagged only in DuckLake modeTestTier0MatchesTier1— Direct queries produce equivalent results to full pipelineBenchmarkTranspile_DirectvsBenchmarkTranspile_OldAllTransforms🤖 Generated with Claude Code