From 2a7713e0bf13720722cd86bba049b5772fb5f0b6 Mon Sep 17 00:00:00 2001 From: Denis Smirnov <sd@picodata.io> Date: Mon, 20 Dec 2021 16:01:31 +0700 Subject: [PATCH] fix: pass logical id to selection node Previously, we didn't pass logaicl ID, that was incorrect we have to generate ID first for the filter boolean expression, and then pass it to the selection node as well. --- src/ir/operator.rs | 8 ++++++-- src/ir/operator/tests.rs | 9 +++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ir/operator.rs b/src/ir/operator.rs index 33ed546f66..c79f62c743 100644 --- a/src/ir/operator.rs +++ b/src/ir/operator.rs @@ -260,13 +260,17 @@ impl Plan { /// - filter expression is not boolean /// - child node is not relational /// - child output tuple is not valid - pub fn add_select(&mut self, child: usize, filter: usize) -> Result<usize, QueryPlannerError> { + pub fn add_select( + &mut self, + child: usize, + filter: usize, + id: usize, + ) -> Result<usize, QueryPlannerError> { if let Node::Expression(Expression::Bool { .. }) = self.get_node(filter)? { } else { return Err(QueryPlannerError::InvalidBool); } - let id = self.nodes.next_id(); let children: Vec<usize> = vec![child]; let output = self.add_output_row(id, &children, &[0], &[])?; diff --git a/src/ir/operator/tests.rs b/src/ir/operator/tests.rs index a59ed8cae2..7d3a388bb3 100644 --- a/src/ir/operator/tests.rs +++ b/src/ir/operator/tests.rs @@ -152,24 +152,25 @@ fn selection() { let scan_id = plan.add_scan("t").unwrap(); - let ref_a_id = plan.nodes.add_ref(scan_id + 1, Some(vec![0]), 0); + let logical_id = plan.nodes.next_id(); + let ref_a_id = plan.nodes.add_ref(logical_id, Some(vec![0]), 0); let a_id = plan.nodes.add_alias("a", ref_a_id).unwrap(); let const_id = plan.nodes.add_const(Value::number_from_str("10").unwrap()); let gt_id = plan.nodes.add_bool(a_id, Bool::Gt, const_id).unwrap(); // Correct Selection operator - plan.add_select(scan_id, gt_id).unwrap(); + plan.add_select(scan_id, gt_id, logical_id).unwrap(); // Non-boolean filter assert_eq!( QueryPlannerError::InvalidBool, - plan.add_select(scan_id, const_id).unwrap_err() + plan.add_select(scan_id, const_id, logical_id).unwrap_err() ); // Non-relational child assert_eq!( QueryPlannerError::InvalidNode, - plan.add_select(const_id, gt_id).unwrap_err() + plan.add_select(const_id, gt_id, logical_id).unwrap_err() ); } -- GitLab