@@ -27,7 +27,7 @@ enum class RPNEvaluationIndexUsefulnessState : uint8_t
2727};
2828
2929[[nodiscard]] inline RPNEvaluationIndexUsefulnessState
30- evalAndRpnIndexStates (const RPNEvaluationIndexUsefulnessState & lhs, const RPNEvaluationIndexUsefulnessState & rhs)
30+ evalAndRpnIndexStates (RPNEvaluationIndexUsefulnessState lhs, RPNEvaluationIndexUsefulnessState rhs)
3131{
3232 if (lhs == RPNEvaluationIndexUsefulnessState::ALWAYS_FALSE || rhs == RPNEvaluationIndexUsefulnessState::ALWAYS_FALSE)
3333 {
@@ -47,7 +47,7 @@ evalAndRpnIndexStates(const RPNEvaluationIndexUsefulnessState & lhs, const RPNEv
4747}
4848
4949[[nodiscard]] inline RPNEvaluationIndexUsefulnessState
50- evalOrRpnIndexStates (const RPNEvaluationIndexUsefulnessState & lhs, const RPNEvaluationIndexUsefulnessState & rhs)
50+ evalOrRpnIndexStates (RPNEvaluationIndexUsefulnessState lhs, RPNEvaluationIndexUsefulnessState rhs)
5151{
5252 if (lhs == RPNEvaluationIndexUsefulnessState::ALWAYS_TRUE || rhs == RPNEvaluationIndexUsefulnessState::ALWAYS_TRUE)
5353 {
@@ -190,7 +190,7 @@ class IMergeTreeIndexCondition
190190
191191 template <typename RPNElement>
192192 bool rpnEvaluatesAlwaysUnknownOrTrue (
193- const std::vector<RPNElement> & rpn, std::function< bool ( typename RPNElement::Function)> isMatchingRPNFunction ) const
193+ const std::vector<RPNElement> & rpn, const std::unordered_set< typename RPNElement::Function> & matchingFunctions ) const
194194 {
195195 std::vector<Internal::RPNEvaluationIndexUsefulnessState> rpn_stack;
196196 rpn_stack.reserve (rpn.size () - 1 );
@@ -209,7 +209,7 @@ class IMergeTreeIndexCondition
209209 {
210210 rpn_stack.emplace_back (Internal::RPNEvaluationIndexUsefulnessState::FALSE );
211211 }
212- else if (isMatchingRPNFunction (element.function ))
212+ else if (matchingFunctions. contains (element.function ))
213213 {
214214 rpn_stack.push_back (Internal::RPNEvaluationIndexUsefulnessState::TRUE );
215215 }
@@ -236,6 +236,10 @@ class IMergeTreeIndexCondition
236236 }
237237
238238 chassert (rpn_stack.size () == 1 );
239+ /*
240+ * In case the result is `ALWAYS_TRUE`, it means we don't need any indices at all, it might be a constant result.
241+ * Thus, we only check against the `TRUE` to determine the usefulness of the index condition.
242+ */
239243 return rpn_stack.front () != Internal::RPNEvaluationIndexUsefulnessState::TRUE ;
240244 }
241245};
0 commit comments