diff --git a/query-algebrizer/src/clauses/mod.rs b/query-algebrizer/src/clauses/mod.rs index e51c36bf..24ee5389 100644 --- a/query-algebrizer/src/clauses/mod.rs +++ b/query-algebrizer/src/clauses/mod.rs @@ -512,9 +512,6 @@ impl ConjoiningClauses { // to get its type, record that we can get it from this table. let needs_type_extraction = !late_binding && // Never need to extract for bound vars. - // Never need to extract types for refs, and var columns are handled elsewhere: - // a subquery will be projecting a type tag. - column == Column::Fixed(DatomsColumn::Value) && self.known_type(&var).is_none() && // Don't need to extract if we know a single type. !self.extracted_types.contains_key(&var); // We're already extracting the type. @@ -523,8 +520,11 @@ impl ConjoiningClauses { // If we subsequently find out its type, we'll remove this later -- see // the removal in `constrain_var_to_type`. if needs_type_extraction { - self.extracted_types.insert(var.clone(), alias.for_type_tag()); + if let Some(tag_alias) = alias.for_associated_type_tag() { + self.extracted_types.insert(var.clone(), tag_alias); + } } + self.column_bindings.entry(var).or_insert(vec![]).push(alias); } diff --git a/query-algebrizer/src/types.rs b/query-algebrizer/src/types.rs index be3b253a..27e42ac1 100644 --- a/query-algebrizer/src/types.rs +++ b/query-algebrizer/src/types.rs @@ -127,6 +127,16 @@ impl DatomsColumn { ValueTypeTag => "value_type_tag", } } + + /// The type of the `v` column is determined by the `value_type_tag` column. Return the + /// associated column determining the type of this column, if there is one. + pub fn associated_type_tag_column(&self) -> Option { + use self::DatomsColumn::*; + match *self { + Value => Some(ValueTypeTag), + _ => None, + } + } } impl ColumnName for DatomsColumn { @@ -220,9 +230,12 @@ impl QualifiedAlias { QualifiedAlias(table, column.into()) } - pub fn for_type_tag(&self) -> QualifiedAlias { - // TODO: this only makes sense for `DatomsColumn` tables. - QualifiedAlias(self.0.clone(), Column::Fixed(DatomsColumn::ValueTypeTag)) + pub fn for_associated_type_tag(&self) -> Option { + match self.1 { + Column::Fixed(ref c) => c.associated_type_tag_column().map(Column::Fixed), + Column::Fulltext(_) => None, + Column::Variable(_) => None, + }.map(|d| QualifiedAlias(self.0.clone(), d)) } } diff --git a/query-translator/src/translate.rs b/query-translator/src/translate.rs index c5bd4a0f..71f97418 100644 --- a/query-translator/src/translate.rs +++ b/query-translator/src/translate.rs @@ -170,7 +170,7 @@ impl ToConstraint for ColumnConstraint { Constraint::equal(left.to_column(), right.to_column()), Equals(qa, QueryValue::PrimitiveLong(value)) => { - let tag_column = qa.for_type_tag().to_column(); + let tag_column = qa.for_associated_type_tag().expect("an associated type tag alias").to_column(); let value_column = qa.to_column(); // A bare long in a query might match a ref, an instant, a long (obviously), or a