Skip to content

Support scoped scalar and tuple IN subqueries - #45

Merged
asmyasnikov merged 4 commits into
mainfrom
codex/in-subqueries
Sep 23, 2026
Merged

asmyasnikov merged 4 commits into
mainfrom
codex/in-subqueries

Conversation

@asmyasnikov

Copy link
Copy Markdown
Member

Noncorrelated IN (SELECT ...) queries previously resolved inner columns and parameters against the outer relation, producing misleading missing-column or List-operand diagnostics. This implements the first scalar and tuple-key stages of #32 using the existing SELECT analyzer with independent scopes. WHERE predicates support one scalar or tuple-valued output column, nullable keys, shared parameters, nested membership, and applicable DML; correlated queries and unsupported contexts fail explicitly.

The jOOQ DSL renders scalar subqueries with typed query parts and scoped table mappings. Tuple subqueries retain their original YQL through the existing explicit-DECLARE JDBC path; the DSL rejects them because its row constructor changes the required YQL projection. Booktest adds read and mutation examples, generated for all 18 runtime profiles and included in the shared build checks.

Validation: make check, published Java/jOOQ and Kotlin SDK builds, and sequential generated native Go, database/sql and jOOQ execution against local YDB 26.3.1.16. The live tests cover empty and nullable inputs, composite keys, alias shadowing, numeric types, mutations and table mappings; stable/nightly CI now includes the suite and its integration coverage. The checked-in Booktest queries also execute through both Go profiles.

The pinned server exhibited false-positive filtering for a tuple mixing primary-key and non-key columns. The exact observation and reproducer are documented in .agents/yql-evidence.md; the generator does not rewrite SQL to mask it. Full composite keys and the all-non-key tuple example were verified separately.

Part of #32; keep the issue open for derived FROM/JOIN sources, named SELECT bindings and collection aggregation. Independent scope metadata is necessary to distinguish aliases reused by different SELECTs; this reuses direct parser contexts and the existing semantic core without adding an intermediate AST or a runtime execution layer.

@codecov-commenter

codecov-commenter commented Sep 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.23824% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.78%. Comparing base (8229abc) to head (a65eddf).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/analyzer/in_subquery.go 94.96% 4 Missing and 4 partials ⚠️
internal/codegen/java/jooq.go 94.20% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #45      +/-   ##
==========================================
+ Coverage   89.47%   89.78%   +0.30%     
==========================================
  Files          63       64       +1     
  Lines       10480    10729     +249     
==========================================
+ Hits         9377     9633     +256     
+ Misses        631      626       -5     
+ Partials      472      470       -2     
Flag Coverage Δ
integration 40.78% <66.14%> (+0.77%) ⬆️
unit 89.68% <96.23%> (+0.31%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/analyzer/expression.go 86.06% <100.00%> (+0.09%) ⬆️
internal/analyzer/insert_select.go 98.62% <100.00%> (+0.09%) ⬆️
internal/analyzer/order_by.go 100.00% <100.00%> (ø)
internal/analyzer/predicate.go 93.19% <100.00%> (+0.44%) ⬆️
internal/analyzer/select_semantic.go 88.64% <100.00%> (+0.86%) ⬆️
internal/analyzer/semantic.go 91.56% <100.00%> (+0.21%) ⬆️
internal/model/model.go 94.59% <ø> (ø)
internal/codegen/java/jooq.go 84.77% <94.20%> (+3.86%) ⬆️
internal/analyzer/in_subquery.go 94.96% <94.96%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21c97f3...a65eddf. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread internal/analyzer/predicate.go Outdated
Comment thread internal/analyzer/in_subquery.go
Comment thread internal/analyzer/in_subquery.go
@robot-vibe-db

robot-vibe-db Bot commented Sep 23, 2026

Copy link
Copy Markdown

AI Review Summary

Verdict: ✅ No critical issues found

Critical issues

No critical issues found.

Other findings

  • Minor | High: a JOIN ON IN (SELECT ...) yields a second, vague invalid predicate: IN subquery could not be resolved diagnostic alongside the specific JOIN diagnostic, because the declined subquery is not recorded in scope.inSubqueriesinternal/analyzer/predicate.go:97
  • Minor | Medium: when the inner SELECT fails, any unbound inner column ref that resolves against the outer scope replaces all inner diagnostics with the "correlated IN subqueries are unsupported" message, masking unrelated inner errors — internal/analyzer/in_subquery.go:99
  • Minor | Medium: IN subqueries in unsupported contexts (projections, HAVING, CASE/IF) are fully analyzed and their scopes/parameter inferences recorded before the context-specific rejection is raised during expression resolution — internal/analyzer/in_subquery.go:56

This review was generated automatically. Critical issues require attention; other findings are advisory.
If this comment was useful, please give it a 👍 — it helps us improve the review bot.

@robot-vibe-db

robot-vibe-db Bot commented Sep 23, 2026

Copy link
Copy Markdown

Full analysis log

Analysis performed by claude, z-ai/glm-5.3-flash.

@asmyasnikov
asmyasnikov merged commit 2682eb2 into main Sep 23, 2026
9 checks passed
@asmyasnikov
asmyasnikov deleted the codex/in-subqueries branch September 23, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants