Skip to content

Conversation

@samuelstroschein
Copy link
Member

@samuelstroschein samuelstroschein commented Nov 12, 2025

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.

  • State VTable:
    • Add source_tag column and on-demand inference; include in VTAB schema and getters.
    • Introduce cached version lookups via withRuntimeCache.
    • Optimize CSE cleanup by deduplicating targets and joining against a literal target_entities table.
  • Validation:
    • Refactor validateStateMutation (new ValidateStateMutationArgs); accept cached versions.
    • PK/unique checks now consider transaction rows (tombstones) and still ignore inherited rows.
  • Runtime/API:
    • Export validateStateMutation args from state/vtable/index.ts.
  • Tests/Benchmarks:
    • Update tests (reject duplicate inserts in one transaction; ignore inherited entities for uniqueness).
    • Add vtable.insert.bench.ts and multiple *.explain.txt artifacts; remove repro files.
  • Chore:
    • Lockfile/type bumps and incidental file updates.

Written by Cursor Bugbot for commit 7787f4c. This will update automatically on new commits. Configure here.

@changeset-bot
Copy link

changeset-bot bot commented Nov 12, 2025

⚠️ No Changeset found

Latest commit: 71e4488

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@samuelstroschein samuelstroschein temporarily deployed to verify-indeces - lix-docs PR #3739 November 12, 2025 23:19 — with Render Destroyed
@nx-cloud
Copy link

nx-cloud bot commented Nov 12, 2025

View your CI Pipeline Execution ↗ for commit 71e4488

Command Status Duration Result
nx run-many --nx-bail --target=build --parallel ✅ Succeeded 1m 30s View ↗
nx run-many --target=test --parallel ✅ Succeeded 3m 46s View ↗
nx run-many --target=lint --parallel ✅ Succeeded 10s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-12 23:58:11 UTC

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

Comment on lines 526 to 603
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);
}

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 12, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

@samuelstroschein samuelstroschein temporarily deployed to verify-indeces - lix-docs PR #3739 November 12, 2025 23:51 — with Render Destroyed
@samuelstroschein samuelstroschein merged commit 2caacad into main Nov 13, 2025
3 checks passed
@samuelstroschein samuelstroschein deleted the verify-indeces branch November 13, 2025 00:29
@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants