Skip to content

feat(vnext): add dialect-aware statement index#174

Merged
Light2Dark merged 1 commit into
dev-refactorfrom
codex/vnext-statement-index
Jul 24, 2026
Merged

feat(vnext): add dialect-aware statement index#174
Light2Dark merged 1 commit into
dev-refactorfrom
codex/vnext-statement-index

Conversation

@Light2Dark

@Light2Dark Light2Dark commented Jul 24, 2026

Copy link
Copy Markdown
Member

Summary

  • add an internal synchronous parser-free statement partition and binary-search cursor lookup
  • preserve explicit half-open ownership for trivia, terminators, empty slots, EOF, and left/right affinity
  • add bounded PostgreSQL, DuckDB, BigQuery, and Dremio lexical profiles with opaque fail-closed suffixes
  • keep incremental reuse, session attachment, parser semantics, and public APIs out of this slice

Safety and performance

  • cap materialized slots at 10,000 and collapse the remainder into one opaque slot
  • bound dollar delimiters and retain no statement substrings
  • conservatively handle Unicode dollar tags and prefix boundaries
  • fail closed for BigQuery procedural bodies, custom delimiters, and PostgreSQL BEGIN ATOMIC bodies
  • 16 MiB scans under a 128 MiB heap: about 44 ms ASCII, 61 ms Latin, 47 ms astral

Evidence

  • exact head: 56b57ea
  • focused statement-index tests: 82 passed
  • full suite: 795 passed, 1 governed expected failure
  • changed coverage: 98.76% statements, 96.97% branches, 100% functions, 98.75% lines
  • strict typecheck, non-mutating lint, test integrity, demo build, packed-package smoke, and Chromium passed
  • lexical/correctness reviewer: APPROVE exact head, no blocker/high/medium findings
  • performance/API reviewer: APPROVE exact head, no blocker/high/medium findings

Public API

No vNext public exports or generated root declarations are added. The full scanner remains the correctness oracle for a later independently reviewed incremental slice.


Summary by cubic

Adds an internal, dialect-aware SQL statement index for vNext. It partitions analysisText into exact half-open slots with binary-search cursor lookup and bounded resources, with no public API changes.

  • New Features
    • Exact slot partitioning and ownership: terminators associate left; trailing trivia moves to the next slot; explicit empty slots are preserved.
    • Dialect profiles for PostgreSQL, DuckDB, BigQuery, and Dremio; protects strings/comments (e.g., dollar-quoting, E-strings, triple/raw/backtick, nested comments) and fails closed for custom delimiters, BigQuery procedural blocks, and PostgreSQL BEGIN ATOMIC.
    • Left/right-affinity lookup via binary search with explicit EOF behavior for terminated vs open statements.
    • Bounded resources: up to 10,000 materialized slots; bounded dollar-quote tag length; no statement substring copies; frozen partition data.
    • Reports unterminated strings/comments without exposing internal semicolons; operates on analysisText so UTF-16 offsets match the original text under the current masking transform; dialect behavior is keyed by internal profile identity, not a caller-controlled ID.

Written for commit 2ca3c25. Summary will update on new commits.

Review in cubic

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 98.76% (🎯 91%) 321 / 325
🔵 Statements 98.77% (🎯 91%) 322 / 326
🔵 Functions 100% (🎯 90%) 35 / 35
🔵 Branches 97.02% (🎯 85%) 294 / 303
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/vnext/statement-index.ts 98.77% 97.02% 100% 98.76% 197, 268, 473, 922
Generated in workflow #680 for commit 2ca3c25 by the Vitest Coverage Report Action

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an internal vNext “statement index” that partitions analysisText into dialect-aware, half-open statement slots (with explicit terminator/trivia ownership) and supports fast cursor-to-slot lookup via binary search, without introducing any new public vNext exports.

Changes:

  • Introduces a bounded, parser-free SQL statement partitioner with per-dialect lexical profiles (PostgreSQL, DuckDB, BigQuery, Dremio) plus opaque fail-closed suffix behavior.
  • Adds comprehensive Vitest coverage for partition semantics, cursor affinity, dialect-specific quoting/comment rules, resource caps, and deterministic properties.
  • Documents slot semantics, cursor-affinity behavior, dialect profile intent, and source-coordinate rationale in vNext docs/ADR.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/vnext/statement-index.ts New internal statement index builder + cursor lookup with dialect-aware lexical scanning and bounded opaque fallback.
src/vnext/tests/statement-index.test.ts New focused tests covering partition correctness, affinity rules, dialect behaviors, and resource limits.
docs/vnext/statement-index.md New documentation describing slot model, affinity semantics, profiles, and complexity guarantees.
docs/vnext/source-coordinates.md Adds a brief cross-reference noting statement index scans analysisText offsets.
docs/adr/0001-language-service-and-session.md Updates ADR with the statement-index oracle design and constraints for vNext sequencing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/vnext/statement-index.ts
@Light2Dark
Light2Dark force-pushed the codex/vnext-statement-index branch from 56b57ea to 2ca3c25 Compare July 24, 2026 14:55
@Light2Dark
Light2Dark merged commit aa846cf into dev-refactor Jul 24, 2026
9 checks passed
@Light2Dark
Light2Dark deleted the codex/vnext-statement-index branch July 24, 2026 14:57
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.

2 participants