Skip to content

Commit cafd01c

Browse files
committed
Resolve the optional comb stats, remove table id in filter
1 parent 64f4a10 commit cafd01c

File tree

4 files changed

+123
-111
lines changed

4 files changed

+123
-111
lines changed

optd-cost-model/src/common/nodes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub enum PredicateType {
5151
Constant(ConstantType),
5252
AttributeRef,
5353
ExternAttributeRef,
54+
// TODO(lanlou): Id -> Id(IdType)
5455
Id,
5556
UnOp(UnOpType),
5657
BinOp(BinOpType),

optd-cost-model/src/common/predicates/attr_ref_pred.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::common::nodes::{ArcPredicateNode, PredicateNode, PredicateType, ReprPredicateNode};
1+
use crate::common::{
2+
nodes::{ArcPredicateNode, PredicateNode, PredicateType, ReprPredicateNode},
3+
types::TableId,
4+
};
25

36
use super::id_pred::IdPred;
47

@@ -8,11 +11,14 @@ use super::id_pred::IdPred;
811
/// 1. The table id, represented by an [`IdPred`].
912
/// 2. The index of the column, represented by an [`IdPred`].
1013
///
14+
/// **TODO**: Now we assume any IdPred is as same as the ones in the ORM layer.
15+
///
1116
/// Currently, [`AttributeRefPred`] only holds base table attributes, i.e. attributes
1217
/// that already exist in the table. More complex structures may be introduced in the
1318
/// future to represent derived attributes (e.g. t.v1 + t.v2).
1419
///
1520
/// TODO: Support derived column in `AttributeRefPred`.
21+
/// Proposal: Data field can store the column type (base or derived).
1622
#[derive(Clone, Debug)]
1723
pub struct AttributeRefPred(pub ArcPredicateNode);
1824

@@ -32,11 +38,12 @@ impl AttributeRefPred {
3238
}
3339

3440
/// Gets the table id.
35-
pub fn table_id(&self) -> usize {
36-
self.0.child(0).data.as_ref().unwrap().as_u64() as usize
41+
pub fn table_id(&self) -> TableId {
42+
TableId(self.0.child(0).data.as_ref().unwrap().as_u64() as usize)
3743
}
3844

3945
/// Gets the attribute index.
46+
/// Note: The attribute index is the **base** index, which is table specific.
4047
pub fn attr_index(&self) -> usize {
4148
self.0.child(1).data.as_ref().unwrap().as_u64() as usize
4249
}

optd-cost-model/src/cost/agg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<S: CostModelStorageLayer> CostModelImpl<S> {
3737
let table_id = attr_ref.table_id();
3838
let attr_idx = attr_ref.attr_index();
3939
let stats_option =
40-
self.get_attribute_comb_stats(TableId(table_id), &[attr_idx])?;
40+
self.get_attribute_comb_stats(table_id, &[attr_idx])?;
4141

4242
let ndistinct = match stats_option {
4343
Some(stats) => stats.ndistinct,

0 commit comments

Comments
 (0)