Skip to content

Commit

Permalink
Resolve the optional comb stats, remove table id in filter
Browse files Browse the repository at this point in the history
  • Loading branch information
lanlou1554 committed Nov 15, 2024
1 parent d87c2b3 commit 4090d0e
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 111 deletions.
1 change: 1 addition & 0 deletions optd-cost-model/src/common/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub enum PredicateType {
Constant(ConstantType),
AttributeRef,
ExternAttributeRef,
// TODO(lanlou): Id -> Id(IdType)
Id,
UnOp(UnOpType),
BinOp(BinOpType),
Expand Down
13 changes: 10 additions & 3 deletions optd-cost-model/src/common/predicates/attr_ref_pred.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::common::nodes::{ArcPredicateNode, PredicateNode, PredicateType, ReprPredicateNode};
use crate::common::{
nodes::{ArcPredicateNode, PredicateNode, PredicateType, ReprPredicateNode},
types::TableId,
};

use super::id_pred::IdPred;

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

Expand All @@ -32,11 +38,12 @@ impl AttributeRefPred {
}

/// Gets the table id.
pub fn table_id(&self) -> usize {
self.0.child(0).data.as_ref().unwrap().as_u64() as usize
pub fn table_id(&self) -> TableId {
TableId(self.0.child(0).data.as_ref().unwrap().as_u64() as usize)
}

/// Gets the attribute index.
/// Note: The attribute index is the **base** index, which is table specific.
pub fn attr_index(&self) -> usize {
self.0.child(1).data.as_ref().unwrap().as_u64() as usize
}
Expand Down
2 changes: 1 addition & 1 deletion optd-cost-model/src/cost/agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<S: CostModelStorageLayer> CostModelImpl<S> {
let table_id = attr_ref.table_id();
let attr_idx = attr_ref.attr_index();
let stats_option =
self.get_attribute_comb_stats(TableId(table_id), &[attr_idx])?;
self.get_attribute_comb_stats(table_id, &[attr_idx])?;

let ndistinct = match stats_option {
Some(stats) => stats.ndistinct,
Expand Down
Loading

0 comments on commit 4090d0e

Please sign in to comment.