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
//
// Unified Query Algebra
//
// Copyright (c) 2023-2026 Cognica, Inc.
//
//! Immutable SQL metadata for rows retained by an execution scope.
use super::InternalRelationId;
use crate::{RowSchema, SQLError};
/// An executor-owned, SQL-invisible row source. The syntax and plan retain only its identity and complete type descriptor; the execution owner supplies repeatable readers and enforces its memory allowance.
///
/// This descriptor cannot be serialized into a stored statement. Cloning it preserves the source identity and shares the immutable schema, without copying any row values.
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc(hidden)]
pub struct RetainedRowSource {
relation: InternalRelationId,
schema: RowSchema,
rows: usize,
}
impl RetainedRowSource {
pub fn new(
relation: InternalRelationId,
schema: RowSchema,
rows: usize,
) -> Result<Self, SQLError> {
let attributes = schema.internal_columns_with_types();
if schema.has_sql_bindings()
|| attributes.len() != schema.physical_width()
|| attributes
.iter()
.enumerate()
.any(|(position, (column, slot, _))| {
*column != relation.column(position) || *slot != Some(position)
})
{
return Err(SQLError::Internal(
"retained row source must expose only its own internal physical attributes".into(),
));
}
Ok(Self {
relation,
schema,
rows,
})
}
pub fn relation(&self) -> InternalRelationId {
self.relation
}
pub fn schema(&self) -> &RowSchema {
&self.schema
}
pub fn rows(&self) -> usize {
self.rows
}
}