Skip to content

Use proper result set when evaluating parameters - #782

Open
simolus3 wants to merge 8 commits into
mainfrom
update-evaluator
Open

Use proper result set when evaluating parameters#782
simolus3 wants to merge 8 commits into
mainfrom
update-evaluator

Conversation

@simolus3

@simolus3 simolus3 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

When querying buckets for Sync Streams, we generally try to resolve parameters independently to form a cartesian product in the end. This is correct for most streams, but goes wrong when a parameter index has more than one column. For example, in SELECT a.* FROM a, b WHERE a.c1 = b.c1 AND a.c2 = b.c2 AND b.u = auth.user_id(), the two parameters are b.c1 and b.c2. If we encounter multiple rows of b through a lookup result, we can't assume those to be independent parameters though! We can only pair parameters that originate from the same row.

This is currently implemented by tracking provenance for each parameter value back to the lookup this originally came from. When we build the cartesian product in the end, we ignore values with incompatible provenance from different rows. Unfortunately, tracking provenance is both kind of expensive and very tricky to get right.

Semantically, evaluating bucket parameters involves:

  1. Forming a result set by adding lookups through joins or a cartesian product.
  2. Once we have the full result set, bucket parameters are a projection.

This replaces the previous querier logic with an actual result set implementation: We start out with a unit set of one row without columns, then go through added lookups that are cross-joined (table-valued functions) or inner-joined (parameter lookups). If we end up with an empty intermediate result set at any point, we know there won't be any buckets and bail out early.

Intersection parameters require special consideration now, but can be implemented by going through the result set and deleting rows where the columns don't match.

AI use: The approach is manual, most tests and some implementation details are generated with Claude Code.

@changeset-bot

changeset-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: dade362

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

}

for (let i = 0; i < this.lookupStages.length; i++) {
// Within a stage, we can resolve lookups concurrently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

With the implementation from this PR, joins are no longer processed concurrently. It's possible to add that back with minor added complexity, but:

  • this is only relevant for complex sync streams
  • we already evaluate other users / queriers concurrently, to the point where bucket storage is likely the bottleneck and not JS

So I don't think this is necessarily something worth doing, but I can change this here / in a follow-up PR if needed.

@simolus3

simolus3 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68a4c2dc8b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/sync-rules/src/sync_plan/evaluator/parameter_evaluator.ts Outdated
Comment thread packages/sync-rules/src/sync_plan/evaluator/result_set.ts
@simolus3
simolus3 marked this pull request as ready for review September 2, 2026 08:41

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: af866d1014

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/sync-rules/src/sync_plan/evaluator/parameter_evaluator.ts Outdated
@simolus3
simolus3 requested a review from rkistner September 2, 2026 09:11
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.

1 participant