Skip to main content

inillucent_sql/plan/
queue.rs

1//! What a recursive CTE's own `ORDER BY`, `LIMIT` and `OFFSET` mean to the loop
2//! that fills it.
3//!
4//! Invariant: **the `ORDER BY` decides which queued row is taken next and the
5//! `LIMIT` stops the recursion.** A CTE with neither is first in, first out and
6//! runs until a pass produces nothing. It is here rather than in [`super`]
7//! because `plan.rs` is at its recorded size.
8
9use crate::bind::{BoundExpr, BoundOrderTerm};
10
11/// What a recursive CTE's own `ORDER BY`, `LIMIT` and `OFFSET` mean to the loop
12/// that fills it.
13///
14/// The `ORDER BY` decides which queued row is taken next, so `ORDER BY depth
15/// DESC` walks depth first, and the `LIMIT` stops the recursion once that many
16/// rows have been produced after the `OFFSET`.
17#[derive(Clone, Debug, PartialEq)]
18pub struct RecursiveQueue {
19    /// The terms that order the queue; empty for first in, first out.
20    pub order_by: Vec<BoundOrderTerm>,
21    /// The `LIMIT`.
22    pub limit: Option<BoundExpr>,
23    /// The `OFFSET`.
24    pub offset: Option<BoundExpr>,
25}