no_mistakes_postgres_engine/catalog/
table_scope.rs1use super::{CatalogTable, RelationKind, SchemaCatalog};
3use std::collections::BTreeSet;
4
5impl SchemaCatalog {
6 pub fn logical_tables(&self) -> impl Iterator<Item = &CatalogTable> {
7 self.tables().filter(|table| is_logical(table))
8 }
9
10 pub fn logical_partition_tables<'a>(
11 &'a self,
12 relation: &str,
13 ) -> impl Iterator<Item = &'a CatalogTable> + 'a {
14 let mut seen = BTreeSet::new();
15 std::iter::successors(self.relation(relation), move |table| {
16 self.relation(table.partition_of.as_deref()?)
17 })
18 .map_while(move |table| seen.insert(table.name.as_str()).then_some(table))
19 .filter(|table| is_logical(table))
20 }
21}
22
23fn is_logical(table: &CatalogTable) -> bool {
24 table.partition_of.is_none() || table.relation_kind == RelationKind::PartitionedTable
25}