Skip to content
Snippets Groups Projects
Verified Commit e4e2cbd2 authored by Denis Smirnov's avatar Denis Smirnov
Browse files

perf: remove redundant clons while merging tuples

parent 426d49bf
No related branches found
No related tags found
1 merge request!1414sbroad import
...@@ -89,6 +89,14 @@ impl Chain { ...@@ -89,6 +89,14 @@ impl Chain {
} }
} }
fn reserve(&mut self, additional: usize) {
self.nodes.reserve(additional);
}
fn length(&self) -> usize {
self.nodes.len()
}
/// Append a new node to the chain. Keep AND and OR nodes in the back, /// Append a new node to the chain. Keep AND and OR nodes in the back,
/// while other nodes in the front of the chain double-ended queue. /// while other nodes in the front of the chain double-ended queue.
fn push(&mut self, expr_id: usize, plan: &Plan) -> Result<(), QueryPlannerError> { fn push(&mut self, expr_id: usize, plan: &Plan) -> Result<(), QueryPlannerError> {
...@@ -196,6 +204,7 @@ impl Plan { ...@@ -196,6 +204,7 @@ impl Plan {
} }
Bool::Or => { Bool::Or => {
let mut new_chain = chain.clone(); let mut new_chain = chain.clone();
new_chain.reserve(capacity - new_chain.length());
new_chain.push(*right, self)?; new_chain.push(*right, self)?;
stack.push(new_chain); stack.push(new_chain);
chain.push(*left, self)?; chain.push(*left, self)?;
......
...@@ -93,8 +93,8 @@ impl Chain { ...@@ -93,8 +93,8 @@ impl Chain {
match self.grouped.entry(group_op) { match self.grouped.entry(group_op) {
Entry::Occupied(mut entry) => { Entry::Occupied(mut entry) => {
let (left, right) = entry.get_mut(); let (left, right) = entry.get_mut();
let new_left_id = plan.expr_clone(left_id)?; let new_left_id = left_id;
let new_right_id = plan.expr_clone(right_id)?; let new_right_id = right_id;
plan.get_columns_or_self(new_left_id)? plan.get_columns_or_self(new_left_id)?
.iter() .iter()
.for_each(|id| { .for_each(|id| {
...@@ -107,8 +107,8 @@ impl Chain { ...@@ -107,8 +107,8 @@ impl Chain {
}); });
} }
Entry::Vacant(entry) => { Entry::Vacant(entry) => {
let new_left_id = plan.expr_clone(left_id)?; let new_left_id = left_id;
let new_right_id = plan.expr_clone(right_id)?; let new_right_id = right_id;
entry.insert(( entry.insert((
plan.get_columns_or_self(new_left_id)?, plan.get_columns_or_self(new_left_id)?,
plan.get_columns_or_self(new_right_id)?, plan.get_columns_or_self(new_right_id)?,
...@@ -119,8 +119,7 @@ impl Chain { ...@@ -119,8 +119,7 @@ impl Chain {
} }
} }
let new_expr_id = plan.expr_clone(expr_id)?; self.other.push(expr_id);
self.other.push(new_expr_id);
Ok(()) Ok(())
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment