inillucent_sql/bind/derived_note.rs
1//! Where a derived table came from.
2//!
3//! Invariant: **the note describes the FROM term as it was written, and the
4//! binder fills it once, when the term is bound.** The planner reads it to
5//! decide what SQLite would decide: whether to flatten the derived table, run
6//! it as a co-routine or fill a table with it, and what to call it in
7//! `EXPLAIN QUERY PLAN`.
8
9/// Where a derived table came from.
10///
11/// SQLite plans a derived table by where it came from as much as by what it
12/// holds. A CTE written `MATERIALIZED` is never flattened, and a CTE used more
13/// than once is materialized once rather than run as a co-routine for each
14/// use. A derived table that has no name is shown as `(subquery-N)`.
15#[derive(Clone, Debug, Default, PartialEq, Eq)]
16pub struct DerivedNote {
17 /// Whether the FROM term was a subquery written with no alias.
18 pub anonymous: bool,
19 /// Whether the FROM term named a view.
20 pub view: bool,
21 /// Whether the FROM term named a common table expression.
22 pub cte: bool,
23 /// `Some(true)` for `MATERIALIZED`, `Some(false)` for `NOT MATERIALIZED`.
24 pub materialized: Option<bool>,
25 /// How many FROM terms of the statement name the CTE.
26 pub uses: u32,
27 /// The CTE's or view's name as written, which a `CO-ROUTINE` or
28 /// `MATERIALIZE` node shows in place of the alias.
29 pub name: Vec<u8>,
30 /// Whether something outside the query reads this term's columns by its
31 /// number, so it has to stay a term rather than be flattened.
32 ///
33 /// The view an `INSTEAD OF UPDATE` or `DELETE` writes through is one: the
34 /// trigger's `OLD` and the new values are read from its columns after the
35 /// query has found the rows.
36 pub pinned: bool,
37}