Skip to content

Commit 6ff463e

Browse files
committed
sql/planner/optimizer/cost/mod.rs -> sql/planner/optimizer/cost/cost.rs
1 parent 2108f85 commit 6ff463e

File tree

2 files changed

+58
-39
lines changed

2 files changed

+58
-39
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2022 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use std::ops::Add;
16+
17+
use common_exception::Result;
18+
use common_planner::IndexType;
19+
20+
use crate::sql::optimizer::MExpr;
21+
use crate::sql::optimizer::Memo;
22+
23+
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
24+
pub struct Cost(pub f64);
25+
26+
impl<T> From<T> for Cost
27+
where T: Into<f64>
28+
{
29+
fn from(t: T) -> Self {
30+
Cost(t.into())
31+
}
32+
}
33+
34+
impl Add for Cost {
35+
type Output = Self;
36+
37+
fn add(self, rhs: Self) -> Self::Output {
38+
Cost(self.0 + rhs.0)
39+
}
40+
}
41+
42+
pub trait CostModel {
43+
/// Compute cost of given `MExpr`(children are not encapsulated).
44+
fn compute_cost(&self, memo: &Memo, m_expr: &MExpr) -> Result<Cost>;
45+
}
46+
47+
/// Context of best cost within a group.
48+
#[derive(Debug, Clone)]
49+
pub struct CostContext {
50+
pub group_index: IndexType,
51+
pub expr_index: IndexType,
52+
pub cost: Cost,
53+
}

src/query/service/src/sql/planner/optimizer/cost/mod.rs

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#[allow(clippy::module_inception)]
16+
mod cost;
1517
mod cost_model;
1618

17-
use std::ops::Add;
18-
19-
use common_exception::Result;
20-
use common_planner::IndexType;
19+
pub use cost::Cost;
20+
pub use cost::CostContext;
21+
pub use cost::CostModel;
2122
pub use cost_model::DefaultCostModel;
22-
23-
use super::MExpr;
24-
use super::Memo;
25-
26-
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
27-
pub struct Cost(pub f64);
28-
29-
impl<T> From<T> for Cost
30-
where T: Into<f64>
31-
{
32-
fn from(t: T) -> Self {
33-
Cost(t.into())
34-
}
35-
}
36-
37-
impl Add for Cost {
38-
type Output = Self;
39-
40-
fn add(self, rhs: Self) -> Self::Output {
41-
Cost(self.0 + rhs.0)
42-
}
43-
}
44-
45-
pub trait CostModel {
46-
/// Compute cost of given `MExpr`(children are not encapsulated).
47-
fn compute_cost(&self, memo: &Memo, m_expr: &MExpr) -> Result<Cost>;
48-
}
49-
50-
/// Context of best cost within a group.
51-
#[derive(Debug, Clone)]
52-
pub struct CostContext {
53-
pub group_index: IndexType,
54-
pub expr_index: IndexType,
55-
pub cost: Cost,
56-
}

0 commit comments

Comments
 (0)