From e95c2f12e68d8644c9a2a3e06ef10ffde6cfc4d2 Mon Sep 17 00:00:00 2001 From: Denis Smirnov <sd@picodata.io> Date: Fri, 17 Dec 2021 16:35:30 +0700 Subject: [PATCH] refactoring: move nxt node ID from Plan to Nodes --- src/ir.rs | 12 ++++++------ src/ir/operator.rs | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ir.rs b/src/ir.rs index 4ca51c957e..60a8c43b99 100644 --- a/src/ir.rs +++ b/src/ir.rs @@ -55,6 +55,12 @@ impl Nodes { self.arena.push(node); position } + + /// Returns the next node position + #[must_use] + pub fn next_id(&self) -> usize { + self.arena.len() + } } /// Logical plan tree structure. @@ -154,12 +160,6 @@ impl Plan { Ok(plan) } - /// Returns the next node position - #[must_use] - pub fn next_node_id(&self) -> usize { - self.nodes.arena.len() - } - /// Build {logical id: position} map for relational nodes #[must_use] pub fn relational_id_map(&self) -> HashMap<usize, usize> { diff --git a/src/ir/operator.rs b/src/ir/operator.rs index 59aaaddbfe..4f1578b030 100644 --- a/src/ir/operator.rs +++ b/src/ir/operator.rs @@ -206,7 +206,7 @@ impl Relational { child: usize, col_names: &[&str], ) -> Result<Self, QueryPlannerError> { - let id = plan.next_node_id(); + let id = plan.nodes.next_id(); let children: Vec<usize> = vec![child]; let output = plan.add_output_row(id, &children, &[0], col_names)?; @@ -234,7 +234,7 @@ impl Relational { return Err(QueryPlannerError::InvalidBool); } - let id = plan.next_node_id(); + let id = plan.nodes.next_id(); let children: Vec<usize> = vec![child]; let output = plan.add_output_row(id, &children, &[0], &[])?; @@ -273,7 +273,7 @@ impl Relational { return Err(QueryPlannerError::NotEqualRows); } - let id = plan.next_node_id(); + let id = plan.nodes.next_id(); let children: Vec<usize> = vec![left, right]; let output = plan.add_output_row(id, &children, &[0, 1], &[])?; @@ -299,7 +299,7 @@ impl Relational { if alias.is_empty() { return Err(QueryPlannerError::InvalidName); } - let id = plan.next_node_id(); + let id = plan.nodes.next_id(); let children: Vec<usize> = vec![child]; let output = plan.add_output_row(id, &children, &[0], &[])?; @@ -318,7 +318,7 @@ impl Plan { /// # Errors /// Returns `QueryPlannerError` when when relation is invalid. pub fn add_scan(&mut self, table: &str) -> Result<usize, QueryPlannerError> { - let logical_id = self.next_node_id(); + let logical_id = self.nodes.next_id(); let nodes = &mut self.nodes; if let Some(relations) = &self.relations { -- GitLab