pub struct ConjoiningClauses {
pub empty_because: Option<EmptyBecause>,
pub from: Vec<SourceAlias>,
pub computed_tables: Vec<ComputedTable>,
pub wheres: ColumnIntersection,
pub column_bindings: BTreeMap<Variable, Vec<QualifiedAlias>>,
pub input_variables: BTreeSet<Variable>,
pub known_types: BTreeMap<Variable, ValueTypeSet>,
pub extracted_types: BTreeMap<Variable, QualifiedAlias>,
// some fields omitted
}
A ConjoiningClauses
(CC) is a collection of clauses that are combined with JOIN
.
The topmost form in a query is a ConjoiningClauses
.
- Ordinary pattern clauses turn into
FROM
parts and WHERE
parts using =
.
- Predicate clauses turn into the same, but with other functions.
- Function clauses turn into
WHERE
parts using function-specific comparisons.
not
turns into NOT EXISTS
with WHERE
clauses inside the subquery to
bind it to the outer variables, or adds simple WHERE
clauses to the outer
clause.
not-join
is similar, but with explicit binding.
or
turns into a collection of UNION
s inside a subquery, or a simple
alternation.
or
's documentation states that all clauses must include the same vars,
but that's an over-simplification: all clauses must refer to the external
unification vars.
The entire UNION
-set is JOIN
ed to any surrounding expressions per the rule-vars
clause, or the intersection of the vars in the two sides of the JOIN
.
Not yet done:
- Function clauses with bindings turn into:
- Subqueries. Perhaps less efficient? Certainly clearer.
- Projection expressions, if only used for output.
- Inline expressions?
Some
if this set of clauses cannot yield results in the context of the current schema.
A vector of source/alias pairs used to construct a SQL FROM
list.
A vector of computed tables (typically subqueries). The index into this vector is used as
an identifier in a DatomsTable::Computed(c)
table reference.
A list of fragments that can be joined by AND
.
column_bindings: BTreeMap<Variable, Vec<QualifiedAlias>>
A map from var to qualified columns. Used to project.
A list of variables mentioned in the enclosing query's :in clause. These must all be bound
before the query can be executed. TODO: clarify what this means for nested CCs.
A map from var to type. Whenever a var maps unambiguously to two different types, it cannot
yield results, so we don't represent that case here. If a var isn't present in the map, it
means that its type is not known in advance.
Usually that state should be represented by ValueTypeSet::Any
.
A mapping, similar to column_bindings
, but used to pull type tags out of the store at runtime.
If a var isn't unit in known_types
, it should be present here.
Be careful with this. It'll overwrite existing bindings.
Return an iterator over the variables externally bound to values.
Return a set of the variables externally bound to values.
Return a single ValueType
if the given variable is known to have a precise type.
Returns None
if the type of the variable is unknown.
Returns None
if the type of the variable is known but not precise -- "double
or integer" isn't good enough.
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Formats the value using the given formatter. Read more
Returns the "default value" for a type. Read more