Checks if a logical operator (`AND`/`OR`) can short-circuit evaluation based on the left-hand side (lhs) result. Short-circuiting occurs under these circumstances: - For `AND`: - if LHS is all false => short-circuit → return LHS - if LHS is all true => short-circuit → return RHS - if LHS is mixed and true_count/sum_count <= [`PRE_SELECTION_THRESHOLD`] -> pre-selection - For `OR`: - if LHS is all
(
lhs: &'a ColumnarValue,
op: &Operator,
)
| 758 | /// 2. Handles both scalar values and array values |
| 759 | /// 3. For arrays, uses optimized bit counting techniques for boolean arrays |
| 760 | fn check_short_circuit<'a>( |
| 761 | lhs: &'a ColumnarValue, |
| 762 | op: &Operator, |
| 763 | ) -> ShortCircuitStrategy<'a> { |
| 764 | // Quick reject for non-logical operators,and quick judgment when op is and |
| 765 | let is_and = match op { |
| 766 | Operator::And => true, |
| 767 | Operator::Or => false, |
| 768 | _ => return ShortCircuitStrategy::None, |
| 769 | }; |
| 770 | |
| 771 | // Non-boolean types can't be short-circuited |
| 772 | if lhs.data_type() != DataType::Boolean { |
| 773 | return ShortCircuitStrategy::None; |
| 774 | } |
| 775 | |
| 776 | match lhs { |
| 777 | ColumnarValue::Array(array) => { |
| 778 | // Fast path for arrays - try to downcast to boolean array |
| 779 | if let Ok(bool_array) = as_boolean_array(array) { |
| 780 | // Arrays with nulls can't be short-circuited |
| 781 | if bool_array.null_count() > 0 { |
| 782 | return ShortCircuitStrategy::None; |
| 783 | } |
| 784 | |
| 785 | let len = bool_array.len(); |
| 786 | if len == 0 { |
| 787 | return ShortCircuitStrategy::None; |
| 788 | } |
| 789 | |
| 790 | let true_count = bool_array.values().count_set_bits(); |
| 791 | if is_and { |
| 792 | // For AND, prioritize checking for all-false (short circuit case) |
| 793 | // Uses optimized false_count() method provided by Arrow |
| 794 | |
| 795 | // Short circuit if all values are false |
| 796 | if true_count == 0 { |
| 797 | return ShortCircuitStrategy::ReturnLeft; |
| 798 | } |
| 799 | |
| 800 | // If no false values, then all must be true |
| 801 | if true_count == len { |
| 802 | return ShortCircuitStrategy::ReturnRight; |
| 803 | } |
| 804 | |
| 805 | // determine if we can pre-selection |
| 806 | if true_count as f32 / len as f32 <= PRE_SELECTION_THRESHOLD { |
| 807 | return ShortCircuitStrategy::PreSelection(bool_array); |
| 808 | } |
| 809 | } else { |
| 810 | // For OR, prioritize checking for all-true (short circuit case) |
| 811 | // Uses optimized true_count() method provided by Arrow |
| 812 | |
| 813 | // Short circuit if all values are true |
| 814 | if true_count == len { |
| 815 | return ShortCircuitStrategy::ReturnLeft; |
| 816 | } |
| 817 |
searching dependent graphs…