Skip to content

Commit 8e44b53

Browse files
committed
improve agg index rewrite matching
1 parent 3732e64 commit 8e44b53

File tree

5 files changed

+1118
-640
lines changed

5 files changed

+1118
-640
lines changed

src/query/sql/src/planner/binder/ddl/index.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use derive_visitor::Drive;
4747
use derive_visitor::DriveMut;
4848
use itertools::Itertools;
4949

50+
use crate::AggIndexPlan;
5051
use crate::AggregatingIndexChecker;
5152
use crate::AggregatingIndexRewriter;
5253
use crate::BindContext;
@@ -179,7 +180,11 @@ impl Binder {
179180
new_bind_context.planning_agg_index = true;
180181
if let Statement::Query(query) = &stmt {
181182
let (s_expr, _) = self.bind_query(&mut new_bind_context, query)?;
182-
s_exprs.push((index_id, index_meta.query.clone(), s_expr));
183+
s_exprs.push(AggIndexPlan {
184+
index_id,
185+
sql: index_meta.query.clone(),
186+
s_expr,
187+
});
183188
}
184189
}
185190
agg_indexes.extend(s_exprs);

src/query/sql/src/planner/metadata/metadata.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub struct Metadata {
7575
non_lazy_columns: ColumnSet,
7676
/// Mappings from table index to _row_id column index.
7777
table_row_id_index: HashMap<IndexType, Symbol>,
78-
agg_indices: HashMap<String, Vec<(u64, String, SExpr)>>,
78+
agg_indices: HashMap<String, Vec<AggIndexPlan>>,
7979
max_column_position: usize, // for CSV
8080

8181
/// Scan id of each scan operator.
@@ -86,6 +86,13 @@ pub struct Metadata {
8686
next_logical_recursive_cte_id: u32,
8787
}
8888

89+
#[derive(Clone, Debug)]
90+
pub struct AggIndexPlan {
91+
pub index_id: u64,
92+
pub sql: String,
93+
pub s_expr: SExpr,
94+
}
95+
8996
impl Metadata {
9097
fn next_column_index(&self) -> Symbol {
9198
Symbol::new(self.columns.len())
@@ -333,7 +340,7 @@ impl Metadata {
333340
column_index
334341
}
335342

336-
pub fn add_agg_indices(&mut self, table: String, agg_indices: Vec<(u64, String, SExpr)>) {
343+
pub fn add_agg_indices(&mut self, table: String, agg_indices: Vec<AggIndexPlan>) {
337344
match self.agg_indices.entry(table) {
338345
Entry::Occupied(occupied) => occupied.into_mut().extend(agg_indices),
339346
Entry::Vacant(vacant) => {
@@ -342,15 +349,15 @@ impl Metadata {
342349
}
343350
}
344351

345-
pub fn agg_indices(&self) -> &HashMap<String, Vec<(u64, String, SExpr)>> {
352+
pub fn agg_indices(&self) -> &HashMap<String, Vec<AggIndexPlan>> {
346353
&self.agg_indices
347354
}
348355

349-
pub fn replace_agg_indices(&mut self, agg_indices: HashMap<String, Vec<(u64, String, SExpr)>>) {
356+
pub fn replace_agg_indices(&mut self, agg_indices: HashMap<String, Vec<AggIndexPlan>>) {
350357
self.agg_indices = agg_indices
351358
}
352359

353-
pub fn get_agg_indices(&self, table: &str) -> Option<&[(u64, String, SExpr)]> {
360+
pub fn get_agg_indices(&self, table: &str) -> Option<&[AggIndexPlan]> {
354361
self.agg_indices.get(table).map(|v| v.as_slice())
355362
}
356363

0 commit comments

Comments
 (0)