| 89 | } |
| 90 | |
| 91 | int TupleRowLexicalComparator::CompareInterpreted( |
| 92 | const TupleRow* lhs, const TupleRow* rhs) const { |
| 93 | DCHECK_EQ(ordering_exprs_.size(), ordering_expr_evals_lhs_.size()); |
| 94 | DCHECK_EQ(ordering_expr_evals_lhs_.size(), ordering_expr_evals_rhs_.size()); |
| 95 | for (int i = 0; i < ordering_expr_evals_lhs_.size(); ++i) { |
| 96 | void* lhs_value = ordering_expr_evals_lhs_[i]->GetValue(lhs); |
| 97 | void* rhs_value = ordering_expr_evals_rhs_[i]->GetValue(rhs); |
| 98 | |
| 99 | // The sort order of NULLs is independent of asc/desc. |
| 100 | if (lhs_value == NULL && rhs_value == NULL) continue; |
| 101 | if (lhs_value == NULL && rhs_value != NULL) return nulls_first_[i]; |
| 102 | if (lhs_value != NULL && rhs_value == NULL) return -nulls_first_[i]; |
| 103 | |
| 104 | int result = RawValue::Compare(lhs_value, rhs_value, ordering_exprs_[i]->type()); |
| 105 | if (!is_asc_[i]) result = -result; |
| 106 | if (result != 0) return result; |
| 107 | // Otherwise, try the next Expr |
| 108 | } |
| 109 | return 0; // fully equivalent key |
| 110 | } |
| 111 | |
| 112 | // Codegens an unrolled version of TupleRowLexicalComparator::Compare(). Uses codegen'd |
| 113 | // key exprs and injects nulls_first_ and is_asc_ values. |