Skip to content

Commit f9b6ccc

Browse files
committed
prefer set of matching functions instead of std::function
1 parent eb7d6be commit f9b6ccc

File tree

5 files changed

+41
-37
lines changed

5 files changed

+41
-37
lines changed

src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,13 @@ bool MergeTreeIndexConditionBloomFilter::alwaysUnknownOrTrue() const
212212
{
213213
return rpnEvaluatesAlwaysUnknownOrTrue(
214214
rpn,
215-
[](RPNElement::Function function)
216-
{
217-
return (
218-
function == RPNElement::FUNCTION_EQUALS || function == RPNElement::FUNCTION_NOT_EQUALS
219-
|| function == RPNElement::FUNCTION_HAS || function == RPNElement::FUNCTION_HAS_ANY
220-
|| function == RPNElement::FUNCTION_HAS_ALL || function == RPNElement::FUNCTION_IN
221-
|| function == RPNElement::FUNCTION_NOT_IN);
222-
});
215+
{RPNElement::FUNCTION_EQUALS,
216+
RPNElement::FUNCTION_NOT_EQUALS,
217+
RPNElement::FUNCTION_HAS,
218+
RPNElement::FUNCTION_HAS_ANY,
219+
RPNElement::FUNCTION_HAS_ALL,
220+
RPNElement::FUNCTION_IN,
221+
RPNElement::FUNCTION_NOT_IN});
223222
}
224223

225224
bool MergeTreeIndexConditionBloomFilter::mayBeTrueOnGranule(const MergeTreeIndexGranuleBloomFilter * granule) const

src/Storages/MergeTree/MergeTreeIndexBloomFilterText.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,16 @@ bool MergeTreeConditionBloomFilterText::alwaysUnknownOrTrue() const
178178
{
179179
return rpnEvaluatesAlwaysUnknownOrTrue(
180180
rpn,
181-
[](RPNElement::Function function)
182-
{
183-
return (
184-
function == RPNElement::FUNCTION_EQUALS || function == RPNElement::FUNCTION_NOT_EQUALS
185-
|| function == RPNElement::FUNCTION_HAS || function == RPNElement::FUNCTION_IN || function == RPNElement::FUNCTION_NOT_IN
186-
|| function == RPNElement::FUNCTION_MULTI_SEARCH || function == RPNElement::FUNCTION_MATCH
187-
|| function == RPNElement::FUNCTION_HAS_ANY || function == RPNElement::FUNCTION_HAS_ALL
188-
|| function == RPNElement::ALWAYS_FALSE);
189-
});
181+
{RPNElement::FUNCTION_EQUALS,
182+
RPNElement::FUNCTION_NOT_EQUALS,
183+
RPNElement::FUNCTION_HAS,
184+
RPNElement::FUNCTION_IN,
185+
RPNElement::FUNCTION_NOT_IN,
186+
RPNElement::FUNCTION_MULTI_SEARCH,
187+
RPNElement::FUNCTION_MATCH,
188+
RPNElement::FUNCTION_HAS_ANY,
189+
RPNElement::FUNCTION_HAS_ALL,
190+
RPNElement::ALWAYS_FALSE});
190191
}
191192

192193
/// Keep in-sync with MergeTreeIndexConditionGin::mayBeTrueOnTranuleInPart

src/Storages/MergeTree/MergeTreeIndexGin.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ bool MergeTreeIndexConditionGin::alwaysUnknownOrTrue() const
223223
{
224224
return rpnEvaluatesAlwaysUnknownOrTrue(
225225
rpn,
226-
[](RPNElement::Function function)
227-
{
228-
return (
229-
function == RPNElement::FUNCTION_EQUALS || function == RPNElement::FUNCTION_NOT_EQUALS
230-
|| function == RPNElement::FUNCTION_HAS || function == RPNElement::FUNCTION_IN || function == RPNElement::FUNCTION_NOT_IN
231-
|| function == RPNElement::FUNCTION_MULTI_SEARCH || function == RPNElement::FUNCTION_MATCH);
232-
});
226+
{RPNElement::FUNCTION_EQUALS,
227+
RPNElement::FUNCTION_NOT_EQUALS,
228+
RPNElement::FUNCTION_HAS,
229+
RPNElement::FUNCTION_IN,
230+
RPNElement::FUNCTION_NOT_IN,
231+
RPNElement::FUNCTION_MULTI_SEARCH,
232+
RPNElement::FUNCTION_MATCH});
233233
}
234234

235235
bool MergeTreeIndexConditionGin::mayBeTrueOnGranuleInPart(MergeTreeIndexGranulePtr idx_granule,[[maybe_unused]] PostingsCacheForStore & cache_store) const

src/Storages/MergeTree/MergeTreeIndexMinMax.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ bool MergeTreeIndexConditionMinMax::alwaysUnknownOrTrue() const
179179
{
180180
return rpnEvaluatesAlwaysUnknownOrTrue(
181181
condition.getRPN(),
182-
[](KeyCondition::RPNElement::Function function)
183-
{
184-
return (
185-
function == KeyCondition::RPNElement::FUNCTION_NOT_IN_RANGE || function == KeyCondition::RPNElement::FUNCTION_IN_RANGE
186-
|| function == KeyCondition::RPNElement::FUNCTION_IN_SET || function == KeyCondition::RPNElement::FUNCTION_NOT_IN_SET
187-
|| function == KeyCondition::RPNElement::FUNCTION_ARGS_IN_HYPERRECTANGLE
188-
|| function == KeyCondition::RPNElement::FUNCTION_POINT_IN_POLYGON || function == KeyCondition::RPNElement::FUNCTION_IS_NULL
189-
|| function == KeyCondition::RPNElement::FUNCTION_IS_NOT_NULL || function == KeyCondition::RPNElement::ALWAYS_FALSE);
190-
});
182+
{KeyCondition::RPNElement::FUNCTION_NOT_IN_RANGE,
183+
KeyCondition::RPNElement::FUNCTION_IN_RANGE,
184+
KeyCondition::RPNElement::FUNCTION_IN_SET,
185+
KeyCondition::RPNElement::FUNCTION_NOT_IN_SET,
186+
KeyCondition::RPNElement::FUNCTION_ARGS_IN_HYPERRECTANGLE,
187+
KeyCondition::RPNElement::FUNCTION_POINT_IN_POLYGON,
188+
KeyCondition::RPNElement::FUNCTION_IS_NULL,
189+
KeyCondition::RPNElement::FUNCTION_IS_NOT_NULL,
190+
KeyCondition::RPNElement::ALWAYS_FALSE});
191191
}
192192

193193
bool MergeTreeIndexConditionMinMax::mayBeTrueOnGranule(MergeTreeIndexGranulePtr idx_granule) const

src/Storages/MergeTree/MergeTreeIndices.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)