1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! The terminal batch consumer (ADR-0682): the final `RETURN` of a
//! streaming statement hands each bounded batch of result rows to a
//! caller-supplied consumer instead of appending to the part's `Vec<Row>`.
//! The pull itself is the back-pressure: the terminal pulls the next batch
//! only after the consumer returns from the previous one, and a consumer
//! answering [`BatchFlow::Stop`] ends the walk and cancels the statement.
use Result;
/// Rows per result batch (ADR-0555's batch bound): the terminal's consumer
/// deliveries and the materialized path's replay chunking share the one
/// bound the inter-clause stream already batches by.
pub const BATCH_ROWS: usize = 1024;
/// What the consumer wants after a batch: the next one, or the end of the
/// walk. `Stop` is `RowStream::stop` for the statement: the terminal stops
/// its input stream and the statement fails with `Error::Cancelled`
/// (`"query cancelled"`), exactly as a cancelled token ends it.
/// The caller-supplied sink for a streaming statement's result (ADR-0682).
/// The engine calls [`RowConsumer::columns`] exactly once, before the first
/// batch (a `RETURN *` learns its columns only at its first batch, so the
/// columns may arrive together with it), then [`RowConsumer::batch`] once
/// per bounded batch of result rows, in row order. The consumer runs on the
/// statement's own thread — the connection's query worker, or the caller's
/// thread where the statement itself runs inline — never concurrently with
/// the pull that produced the batch.
///
/// `Send`: the statement runs on the connection's worker thread, so the
/// consumer crosses to it.
/// The engine-side handle a statement carries for its consumer: wraps the
/// caller's [`RowConsumer`] with whether it has been engaged (columns were
/// announced), so the boundary can tell a statement whose rows streamed
/// from one whose result still sits in its `QueryResult` — the materialized
/// forms (writes, `EXPLAIN`, catalog commands, `UNION` folds, breakers)
/// replay their rows through the same sink after the run.