Repository navigation
Support OR in WHERE - #11
Merged
Merged
Conversation
An OR becomes one predicate, {:or, branches}, each branch an AND-ed list
of predicates, so AND binds tighter and nesting is kept. It is checked on
the rows read, with SQL NULL semantics per branch, while the conditions
AND-ed with it still narrow the read. NOT over AND now works too, as the
OR it means.
An OR of equalities and INs on one field is rewritten to an IN, so an
index or the primary key serves it as one lookup per value. IN lists are
now deduplicated, since each value is read on its own and a repeated one
returned its rows twice.
Predicate.fields/1 gives every field a predicate reads, for the planner's
residual columns, the primary-key check and _tenant. In a query across
tenants an OR on _tenant alone picks the tenants; mixing _tenant with
other fields is refused, as each tenant's rows are filtered before they
get _tenant.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PFBZUrerge6bbWVCHpS5Ko
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ORis now supported inWHERE, and so isNOToverAND(not (a and b)isnot a or not b).{:or, branches}. Each branch is an AND-ed list of predicates, so AND binds tighter than OR and nesting is kept.Efsql.Parserflattens chains of ORs into a single predicate.pushdownis:filter). The conditions AND-ed with it still narrow the read.statusis NULL still matchesstatus = 'paid' or total > 100when its total is over 100.Efsql.Rewritepass turns an OR of equalities and INs on one field into an IN. An index, or the primary key_, then serves it with one lookup per value.pass_in_singletonnow deduplicates IN and NOT IN values usingTypes.equality_key. Before this, each value was read on its own, soa in (1, 1)returned its rows twice. OR made this easier to hit (a = 1 or a in (1, 2)).Predicate.fields/1: returns every field a predicate reads. It is used for the planner's residual columns, the check on the primary key_, and the_tenantchecks._tenantalone picks the tenants. An OR that mixes_tenantwith other fields is refused with a clear message, because each tenant's rows are filtered before they get_tenant._: only an OR of equalities or INs is supported. The error says to use the key's field name for anything else.or.Tests
test/or_test.exs(FoundationDB):_inside an OR.test/cross_tenant_test.exs: an OR on_tenantpicks the tenants; mixing_tenantwith other fields is refused.🤖 Generated with Claude Code
https://claude.ai/code/session_01PFBZUrerge6bbWVCHpS5Ko
Generated by Claude Code