Skip to main content

no_mistakes_postgres_sql/statement_facts/
keyed_lookups.rs

1/// One duplicate keyed lookup of the same relation within a single statement scope.
2#[derive(Debug, Clone, PartialEq, Eq)]
3pub struct SqlDuplicateKeyedLookupFact {
4    /// Canonical target relation name (e.g. `people` or `public.people`).
5    pub relation: String,
6    /// Human-readable normalized key summary (e.g. `id = n.owner_id`).
7    pub key_display: String,
8    /// 1-based line of the first lookup (rebased to physical source line for embedded SQL).
9    pub first_line: usize,
10    /// 1-based SQL column of the first lookup.
11    pub first_column: usize,
12    /// 1-based line of the duplicate lookup (rebased to physical source line for embedded SQL).
13    pub line: usize,
14    /// 1-based SQL column of the duplicate lookup.
15    pub column: usize,
16}
17
18/// A relation read from a join or a scalar subquery, before catalog classification.
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct SqlViewUseFact {
21    /// Canonical relation identity.
22    pub relation: String,
23    /// Whole-row embedding is the only use of the view and the lookup uses its ID.
24    pub whole_row_on_id: bool,
25    /// The only key is a bare ID with a possible outer column of that name.
26    pub correlated_bare_id: bool,
27    /// Positional aliases applied to the relation columns at this reference.
28    pub column_aliases: Vec<String>,
29    /// Unqualified columns whose binding needs catalog evidence.
30    pub unqualified_columns: Vec<String>,
31    /// A join output aliases a read column at an unknown source position.
32    pub unresolved_column_ownership: bool,
33    /// An explicit qualified row argument proves an embedding.
34    pub qualified_embedding: bool,
35    /// Bare JSON arguments whose column ownership must be resolved.
36    pub row_arguments: Vec<SqlBareViewRowRead>,
37    /// Additional bare references that can resolve to a sibling column instead of the view row.
38    pub bare_row_reads: Vec<SqlBareViewRowRead>,
39    /// Column references that can bind to this view in an enclosing query.
40    pub correlated_columns: Vec<SqlBareViewRowRead>,
41    /// Output columns on the other side of an implicit NATURAL join.
42    pub natural_join_peers: Vec<SqlNaturalJoinPeers>,
43    /// One-based source line.
44    pub line: usize,
45    /// One-based SQL column.
46    pub column: usize,
47}
48
49#[derive(Debug, Clone, PartialEq, Eq, Default)]
50pub struct SqlNaturalJoinPeers {
51    pub known_columns: Vec<String>,
52    pub relations: Vec<String>,
53    pub opaque: bool,
54}
55
56/// A bare reference sharing a name with a view's whole-row alias.
57#[derive(Debug, Clone, PartialEq, Eq)]
58pub struct SqlBareViewRowRead {
59    /// The ambiguous bare name.
60    pub name: String,
61    /// Name-resolution scopes, from the innermost query outward.
62    pub scopes: Vec<SqlBareViewRowScope>,
63}
64
65/// Inputs whose columns can bind a bare name at a single lexical scope.
66#[derive(Debug, Clone, PartialEq, Eq)]
67pub struct SqlBareViewRowScope {
68    /// This scope contains the view whose row alias was referenced.
69    pub view_input: bool,
70    /// A peer has a matching column proven directly from its SQL projection.
71    pub known_peer_column: bool,
72    /// Physical peers whose catalog columns can claim this name.
73    pub peers: Vec<String>,
74    /// At least one peer has unknown output names.
75    pub opaque_peer: bool,
76}