Skip to content

Commit 11a3a4e

Browse files
committed
modify MemoExt interface
1 parent 36b93b9 commit 11a3a4e

File tree

4 files changed

+41
-27
lines changed

4 files changed

+41
-27
lines changed

optd-cost-model/src/cost/join/hash_join.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ impl<S: CostModelStorageManager> CostModelImpl<S> {
2828
right_keys: ListPred,
2929
) -> CostModelResult<EstimatedStatistic> {
3030
let selectivity = {
31-
let output_attr_refs = self.memo.get_attribute_ref(group_id);
32-
let left_attr_refs = self.memo.get_attribute_ref(left_group_id);
33-
let right_attr_refs = self.memo.get_attribute_ref(right_group_id);
31+
let output_attr_refs = self.memo.get_attribute_refs(group_id);
32+
let left_attr_refs = self.memo.get_attribute_refs(left_group_id);
33+
let right_attr_refs = self.memo.get_attribute_refs(right_group_id);
3434
let left_attr_cnt = left_attr_refs.attr_refs().len();
3535
// there may be more than one expression tree in a group.
3636
// see comment in PredicateType::PhysicalFilter(_) for more information

optd-cost-model/src/cost/join/nested_loop_join.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ impl<S: CostModelStorageManager> CostModelImpl<S> {
2525
join_cond: ArcPredicateNode,
2626
) -> CostModelResult<EstimatedStatistic> {
2727
let selectivity = {
28-
let output_attr_refs = self.memo.get_attribute_ref(group_id);
29-
let left_attr_refs = self.memo.get_attribute_ref(left_group_id);
30-
let right_attr_refs = self.memo.get_attribute_ref(right_group_id);
28+
let output_attr_refs = self.memo.get_attribute_refs(group_id);
29+
let left_attr_refs = self.memo.get_attribute_refs(left_group_id);
30+
let right_attr_refs = self.memo.get_attribute_refs(right_group_id);
3131
let input_correlation = get_input_correlation(left_attr_refs, right_attr_refs);
3232

3333
self.get_join_selectivity_from_expr_tree(

optd-cost-model/src/cost_model.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ pub mod tests {
155155

156156
use super::*;
157157

158-
const TEST_TABLE1_ID: TableId = TableId(0);
159-
const TEST_TABLE2_ID: TableId = TableId(1);
160-
const TEST_TABLE3_ID: TableId = TableId(2);
161-
const TEST_TABLE4_ID: TableId = TableId(3);
158+
pub const TEST_TABLE1_ID: TableId = TableId(0);
159+
pub const TEST_TABLE2_ID: TableId = TableId(1);
160+
pub const TEST_TABLE3_ID: TableId = TableId(2);
161+
pub const TEST_TABLE4_ID: TableId = TableId(3);
162162

163-
const TEST_GROUP1_ID: GroupId = GroupId(0);
164-
const TEST_GROUP2_ID: GroupId = GroupId(1);
165-
const TEST_GROUP3_ID: GroupId = GroupId(2);
166-
const TEST_GROUP4_ID: GroupId = GroupId(3);
163+
pub const TEST_GROUP1_ID: GroupId = GroupId(0);
164+
pub const TEST_GROUP2_ID: GroupId = GroupId(1);
165+
pub const TEST_GROUP3_ID: GroupId = GroupId(2);
166+
pub const TEST_GROUP4_ID: GroupId = GroupId(3);
167167

168168
pub type TestPerAttributeStats = AttributeCombValueStats;
169169
// TODO: add tests for non-mock storage manager
@@ -495,7 +495,7 @@ pub mod tests {
495495
}
496496

497497
pub fn get_attr_refs(&self, group_id: GroupId) -> GroupAttrRefs {
498-
self.memo.get_attribute_ref(group_id)
498+
self.memo.get_attribute_refs(group_id)
499499
}
500500
}
501501

optd-cost-model/src/memo_ext.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
use crate::common::{
2-
properties::{attr_ref::GroupAttrRefs, schema::Schema, Attribute},
2+
properties::{
3+
attr_ref::{AttrRef, GroupAttrRefs},
4+
schema::Schema,
5+
Attribute,
6+
},
37
types::GroupId,
48
};
59

@@ -13,10 +17,12 @@ use crate::common::{
1317
pub trait MemoExt: Send + Sync + 'static {
1418
/// Get the schema of a group in the memo.
1519
fn get_schema(&self, group_id: GroupId) -> Schema;
16-
/// Get the attribute reference of a group in the memo.
17-
fn get_attribute_ref(&self, group_id: GroupId) -> GroupAttrRefs;
18-
/// Get the attribute information of a given attribute in a group in the memo.
20+
/// Get the attribute info of a given attribute in a group in the memo.
1921
fn get_attribute_info(&self, group_id: GroupId, attr_ref_idx: u64) -> Attribute;
22+
/// Get the attribute reference of a group in the memo.
23+
fn get_attribute_refs(&self, group_id: GroupId) -> GroupAttrRefs;
24+
/// Get the attribute reference of a given attribute in a group in the memo.
25+
fn get_attribute_ref(&self, group_id: GroupId, attr_ref_idx: u64) -> AttrRef;
2026

2127
// TODO: Figure out what other information is needed to compute the cost...
2228
}
@@ -26,18 +32,22 @@ pub mod tests {
2632
use std::collections::HashMap;
2733

2834
use crate::common::{
29-
properties::{attr_ref::GroupAttrRefs, schema::Schema, Attribute},
35+
properties::{
36+
attr_ref::{AttrRef, GroupAttrRefs},
37+
schema::Schema,
38+
Attribute,
39+
},
3040
types::GroupId,
3141
};
3242

3343
pub struct MemoGroupInfo {
3444
pub schema: Schema,
35-
pub attr_ref: GroupAttrRefs,
45+
pub attr_refs: GroupAttrRefs,
3646
}
3747

3848
impl MemoGroupInfo {
39-
pub fn new(schema: Schema, attr_ref: GroupAttrRefs) -> Self {
40-
Self { schema, attr_ref }
49+
pub fn new(schema: Schema, attr_refs: GroupAttrRefs) -> Self {
50+
Self { schema, attr_refs }
4151
}
4252
}
4353

@@ -63,13 +73,17 @@ pub mod tests {
6373
self.memo.get(&group_id).unwrap().schema.clone()
6474
}
6575

66-
fn get_attribute_ref(&self, group_id: GroupId) -> GroupAttrRefs {
67-
self.memo.get(&group_id).unwrap().attr_ref.clone()
68-
}
69-
7076
fn get_attribute_info(&self, group_id: GroupId, attr_ref_idx: u64) -> Attribute {
7177
self.memo.get(&group_id).unwrap().schema.attributes[attr_ref_idx as usize].clone()
7278
}
79+
80+
fn get_attribute_refs(&self, group_id: GroupId) -> GroupAttrRefs {
81+
self.memo.get(&group_id).unwrap().attr_refs.clone()
82+
}
83+
84+
fn get_attribute_ref(&self, group_id: GroupId, attr_ref_idx: u64) -> AttrRef {
85+
self.memo.get(&group_id).unwrap().attr_refs.attr_refs()[attr_ref_idx as usize].clone()
86+
}
7387
}
7488

7589
impl From<HashMap<GroupId, MemoGroupInfo>> for MockMemoExtImpl {

0 commit comments

Comments
 (0)