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
/// One duplicate keyed lookup of the same relation within a single statement scope.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SqlDuplicateKeyedLookupFact {
/// Canonical target relation name (e.g. `people` or `public.people`).
pub relation: String,
/// Human-readable normalized key summary (e.g. `id = n.owner_id`).
pub key_display: String,
/// 1-based line of the first lookup (rebased to physical source line for embedded SQL).
pub first_line: usize,
/// 1-based SQL column of the first lookup.
pub first_column: usize,
/// 1-based line of the duplicate lookup (rebased to physical source line for embedded SQL).
pub line: usize,
/// 1-based SQL column of the duplicate lookup.
pub column: usize,
}
/// A relation read from a join or a scalar subquery, before catalog classification.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SqlViewUseFact {
/// Canonical relation identity.
pub relation: String,
/// Whole-row embedding is the only use of the view and the lookup uses its ID.
pub whole_row_on_id: bool,
/// The only key is a bare ID with a possible outer column of that name.
pub correlated_bare_id: bool,
/// Positional aliases applied to the relation columns at this reference.
pub column_aliases: Vec<String>,
/// Unqualified columns whose binding needs catalog evidence.
pub unqualified_columns: Vec<String>,
/// A join output aliases a read column at an unknown source position.
pub unresolved_column_ownership: bool,
/// An explicit qualified row argument proves an embedding.
pub qualified_embedding: bool,
/// Bare JSON arguments whose column ownership must be resolved.
pub row_arguments: Vec<SqlBareViewRowRead>,
/// Additional bare references that can resolve to a sibling column instead of the view row.
pub bare_row_reads: Vec<SqlBareViewRowRead>,
/// Column references that can bind to this view in an enclosing query.
pub correlated_columns: Vec<SqlBareViewRowRead>,
/// Output columns on the other side of an implicit NATURAL join.
pub natural_join_peers: Vec<SqlNaturalJoinPeers>,
/// One-based source line.
pub line: usize,
/// One-based SQL column.
pub column: usize,
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct SqlNaturalJoinPeers {
pub known_columns: Vec<String>,
pub relations: Vec<String>,
pub opaque: bool,
}
/// A bare reference sharing a name with a view's whole-row alias.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SqlBareViewRowRead {
/// The ambiguous bare name.
pub name: String,
/// Name-resolution scopes, from the innermost query outward.
pub scopes: Vec<SqlBareViewRowScope>,
}
/// Inputs whose columns can bind a bare name at a single lexical scope.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SqlBareViewRowScope {
/// This scope contains the view whose row alias was referenced.
pub view_input: bool,
/// A peer has a matching column proven directly from its SQL projection.
pub known_peer_column: bool,
/// Physical peers whose catalog columns can claim this name.
pub peers: Vec<String>,
/// At least one peer has unknown output names.
pub opaque_peer: bool,
}