diff --git a/query-algebrizer/src/clauses/ground.rs b/query-algebrizer/src/clauses/ground.rs index c70bcefe..d7ad7557 100644 --- a/query-algebrizer/src/clauses/ground.rs +++ b/query-algebrizer/src/clauses/ground.rs @@ -36,10 +36,8 @@ use errors::{ }; use types::{ - ColumnConstraint, ComputedTable, EmptyBecause, - QualifiedAlias, SourceAlias, ValueTypeSet, VariableColumn, @@ -112,23 +110,6 @@ impl ConjoiningClauses { self.bind_value(&var, value.clone()); } - let vt = value.value_type(); - - // Check to see whether this variable is already associated to a column. - // If so, we want to add an equality filter (or, in the future, redo the existing patterns). - if let Some(QualifiedAlias(table, column)) = self.column_bindings - .get(&var) - .and_then(|vec| vec.get(0).cloned()) { - self.constrain_column_to_constant(table, column, value); - } - - // Are we also trying to figure out the type of the value when the query runs? - // If so, constrain that! - if let Some(table) = self.extracted_types.get(&var) - .map(|qa| qa.0.clone()) { - self.wheres.add_intersection(ColumnConstraint::HasType(table, vt)); - } - Ok(()) } diff --git a/query-algebrizer/src/clauses/mod.rs b/query-algebrizer/src/clauses/mod.rs index 9eb22809..22d7b455 100644 --- a/query-algebrizer/src/clauses/mod.rs +++ b/query-algebrizer/src/clauses/mod.rs @@ -338,7 +338,25 @@ impl ConjoiningClauses { impl ConjoiningClauses { /// Be careful with this. It'll overwrite existing bindings. pub fn bind_value(&mut self, var: &Variable, value: TypedValue) { - self.constrain_var_to_type(var.clone(), value.value_type()); + let vt = value.value_type(); + self.constrain_var_to_type(var.clone(), vt); + + // Are there any existing column bindings for this variable? + // If so, generate a constraint against the primary column. + if let Some(vec) = self.column_bindings.get(var) { + if let Some(col) = vec.first() { + self.wheres.add_intersection(ColumnConstraint::Equals(col.clone(), QueryValue::TypedValue(value.clone()))); + } + } + + // Are we also trying to figure out the type of the value when the query runs? + // If so, constrain that! + if let Some(table) = self.extracted_types.get(&var) + .map(|qa| qa.0.clone()) { + self.wheres.add_intersection(ColumnConstraint::HasType(table, value.value_type())); + } + + // Finally, store the binding for future use. self.value_bindings.insert(var.clone(), value); }