-
Notifications
You must be signed in to change notification settings - Fork 169
Verify-indeces #3739
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
Verify-indeces #3739
Conversation
…ding inherited_from_version_id checks
makes sql queries faster by avoiding where _pk LIKE queries
using joins allows sqlite to optimize the query better. the benched time went from 20ms down to 6ms
|
|
View your CI Pipeline Execution ↗ for commit 71e4488
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| function pruneUnusedLeftJoins( | ||
| select: SelectStatementNode | ||
| ): SelectStatementNode { | ||
| if (select.from_clauses.length === 0) { | ||
| return select; | ||
| } | ||
| let changed = false; | ||
| const rewrittenFrom = select.from_clauses.map((clause, clauseIndex) => { | ||
| if (clause.joins.length === 0) { | ||
| return clause; | ||
| } | ||
| const filteredJoins = clause.joins.filter((join, joinIndex) => { | ||
| if (join.join_type !== "left") { | ||
| return true; | ||
| } | ||
| if (join.relation.node_kind === "raw_fragment") { | ||
| return true; | ||
| } | ||
| const alias = resolveRelationAlias(join.relation); | ||
| if (!alias) { | ||
| return true; | ||
| } | ||
| if (aliasReferencedOutsideJoin(select, clauseIndex, joinIndex, alias)) { | ||
| return true; | ||
| } | ||
| changed = true; | ||
| return false; | ||
| }); | ||
| if (filteredJoins.length === clause.joins.length) { | ||
| return clause; | ||
| } | ||
| return { | ||
| ...clause, | ||
| joins: filteredJoins, | ||
| }; | ||
| }); | ||
| if (!changed) { | ||
| return select; | ||
| } | ||
| return { | ||
| ...select, | ||
| from_clauses: rewrittenFrom, | ||
| }; | ||
| } | ||
|
|
||
| function aliasReferencedOutsideJoin( | ||
| select: SelectStatementNode, | ||
| clauseIndex: number, | ||
| joinIndex: number, | ||
| alias: string | ||
| ): boolean { | ||
| const strippedSelect: SelectStatementNode = { | ||
| ...select, | ||
| from_clauses: select.from_clauses.map((clause, currentClauseIndex) => { | ||
| if (currentClauseIndex !== clauseIndex) { | ||
| return clause; | ||
| } | ||
| return { | ||
| ...clause, | ||
| joins: clause.joins.map((join, currentJoinIndex) => { | ||
| if (currentJoinIndex !== joinIndex) { | ||
| return join; | ||
| } | ||
| if (!join.on_expression) { | ||
| return join; | ||
| } | ||
| return { | ||
| ...join, | ||
| on_expression: null, | ||
| }; | ||
| }), | ||
| }; | ||
| }), | ||
| }; | ||
| const usage = collectTableColumnUsage(strippedSelect); | ||
| const summary = usage.get(alias); | ||
| return !!summary && (summary.requiresAllColumns || summary.columns.size > 0); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid pruning left joins that can affect result cardinality
The new pruneUnusedLeftJoins logic drops any LEFT JOIN whose alias is not referenced elsewhere by clearing its on_expression before calling collectTableColumnUsage. This treats a join as removable even when it influences row count (for example SELECT COUNT(*) FROM t LEFT JOIN u ON u.t_id = t.id or a join where the ON clause references only the left table). Removing such joins changes the number of rows emitted even though none of the joined columns are projected, which breaks aggregates and downstream semantics. The optimizer needs additional guarantees (e.g., uniqueness of the joined relation or an EXISTS semantics) before eliminating a join; otherwise these joins must be retained.
Useful? React with 👍 / 👎.
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
flashtype | 7787f4c | Commit Preview URL Branch Preview URL |
Nov 12 2025, 11:42 PM |
Note
Enhances the state vtable and validation: adds
source_tag, caches version lookups, optimizes working change set cleanup, and updates PK/unique checks to consider transaction state while ignoring inherited rows.source_tagcolumn and on-demand inference; include in VTAB schema and getters.withRuntimeCache.target_entitiestable.validateStateMutation(newValidateStateMutationArgs); accept cached versions.validateStateMutationargs fromstate/vtable/index.ts.vtable.insert.bench.tsand multiple*.explain.txtartifacts; remove repro files.Written by Cursor Bugbot for commit 7787f4c. This will update automatically on new commits. Configure here.