11use std:: collections:: HashSet ;
22
3- use crate :: utils:: DisjointSets ;
3+ use crate :: { common :: types :: TableId , utils:: DisjointSets } ;
44
5- pub type BaseTableAttrRefs = Vec < AttrRef > ;
5+ pub type AttrRefs = Vec < AttrRef > ;
66
7+ /// [`BaseTableAttrRef`] represents a reference to an attribute in a base table,
8+ /// i.e. a table existing in the catalog.
79#[ derive( Clone , Debug , Default , Eq , Hash , PartialEq ) ]
810pub struct BaseTableAttrRef {
9- pub table : String ,
10- pub attr_idx : usize ,
11+ pub table_id : TableId ,
12+ pub attr_idx : u64 ,
1113}
1214
15+ /// [`AttrRef`] represents a reference to an attribute in a query.
1316#[ derive( Clone , Debug ) ]
1417pub enum AttrRef {
18+ /// Reference to a base table attribute.
1519 BaseTableAttrRef ( BaseTableAttrRef ) ,
16- /// TODO: Better representation of derived attributes (e.g. t.v1 + t.v2).
20+ /// Reference to a derived attribute (e.g. t.v1 + t.v2).
21+ /// TODO: Better representation of derived attributes.
1722 Derived ,
1823}
1924
2025impl AttrRef {
21- pub fn base_table_attr_ref ( table : String , attr_idx : usize ) -> Self {
22- AttrRef :: BaseTableAttrRef ( BaseTableAttrRef { table , attr_idx } )
26+ pub fn base_table_attr_ref ( table_id : TableId , attr_idx : u64 ) -> Self {
27+ AttrRef :: BaseTableAttrRef ( BaseTableAttrRef { table_id , attr_idx } )
2328 }
2429}
2530
@@ -29,6 +34,7 @@ impl From<BaseTableAttrRef> for AttrRef {
2934 }
3035}
3136
37+ /// [`EqPredicate`] represents an equality predicate between two attributes.
3238#[ derive( Clone , Debug , Eq , Hash , PartialEq ) ]
3339pub struct EqPredicate {
3440 pub left : BaseTableAttrRef ,
@@ -41,13 +47,12 @@ impl EqPredicate {
4147 }
4248}
4349
44- /// `SemanticCorrelation` represents the semantic correlation between attributes in a
50+ /// [ `SemanticCorrelation`] represents the semantic correlation between attributes in a
4551/// query. "Semantic" means that the attributes are correlated based on the
4652/// semantics of the query, not the statistics.
4753///
48- /// `SemanticCorrelation` contains equal attributes denoted by disjoint sets of base
54+ /// [ `SemanticCorrelation`] contains equal attributes denoted by disjoint sets of base
4955/// table attributes, e.g. {{ t1.c1 = t2.c1 = t3.c1 }, { t1.c2 = t2.c2 }}.
50-
5156#[ derive( Clone , Debug , Default ) ]
5257pub struct SemanticCorrelation {
5358 /// A disjoint set of base table attributes with equal values in the same row.
@@ -155,25 +160,23 @@ impl SemanticCorrelation {
155160 }
156161}
157162
163+ /// [`GroupAttrRefs`] represents the attributes of a group in a query.
158164#[ derive( Clone , Debug ) ]
159165pub struct GroupAttrRefs {
160- attribute_refs : BaseTableAttrRefs ,
166+ attribute_refs : AttrRefs ,
161167 /// Correlation of the output attributes of the group.
162168 output_correlation : Option < SemanticCorrelation > ,
163169}
164170
165171impl GroupAttrRefs {
166- pub fn new (
167- attribute_refs : BaseTableAttrRefs ,
168- output_correlation : Option < SemanticCorrelation > ,
169- ) -> Self {
172+ pub fn new ( attribute_refs : AttrRefs , output_correlation : Option < SemanticCorrelation > ) -> Self {
170173 Self {
171174 attribute_refs,
172175 output_correlation,
173176 }
174177 }
175178
176- pub fn base_table_attribute_refs ( & self ) -> & BaseTableAttrRefs {
179+ pub fn base_table_attribute_refs ( & self ) -> & AttrRefs {
177180 & self . attribute_refs
178181 }
179182
@@ -189,19 +192,19 @@ mod tests {
189192 #[ test]
190193 fn test_eq_base_table_attribute_sets ( ) {
191194 let attr1 = BaseTableAttrRef {
192- table : "t1" . to_string ( ) ,
195+ table_id : TableId ( 1 ) ,
193196 attr_idx : 1 ,
194197 } ;
195198 let attr2 = BaseTableAttrRef {
196- table : "t2" . to_string ( ) ,
199+ table_id : TableId ( 2 ) ,
197200 attr_idx : 2 ,
198201 } ;
199202 let attr3 = BaseTableAttrRef {
200- table : "t3" . to_string ( ) ,
203+ table_id : TableId ( 3 ) ,
201204 attr_idx : 3 ,
202205 } ;
203206 let attr4 = BaseTableAttrRef {
204- table : "t4" . to_string ( ) ,
207+ table_id : TableId ( 4 ) ,
205208 attr_idx : 4 ,
206209 } ;
207210 let pred1 = EqPredicate :: new ( attr1. clone ( ) , attr2. clone ( ) ) ;
0 commit comments