Skip to content

Commit 7011528

Browse files
committed
[refactor](predicates) Simplify predicates and profile
1 parent 59bd274 commit 7011528

File tree

9 files changed

+331
-536
lines changed

9 files changed

+331
-536
lines changed

be/src/exec/olap_common.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,19 @@ class ColumnValueRange {
212212

213213
int scale() const { return _scale; }
214214

215-
static void add_fixed_value_range(ColumnValueRange<primitive_type>& range,
215+
static void add_fixed_value_range(ColumnValueRange<primitive_type>& range, SQLFilterOp op,
216216
const CppType* value) {
217217
static_cast<void>(range.add_fixed_value(*value));
218218
}
219219

220-
static void remove_fixed_value_range(ColumnValueRange<primitive_type>& range,
220+
static void remove_fixed_value_range(ColumnValueRange<primitive_type>& range, SQLFilterOp op,
221221
const CppType* value) {
222222
range.remove_fixed_value(*value);
223223
}
224224

225+
static void empty_function(ColumnValueRange<primitive_type>& range, SQLFilterOp op,
226+
const CppType* value) {}
227+
225228
static void add_value_range(ColumnValueRange<primitive_type>& range, SQLFilterOp op,
226229
const CppType* value) {
227230
static_cast<void>(range.add_range(op, *value));

be/src/exec/olap_utils.h

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -67,43 +67,14 @@ enum SQLFilterOp {
6767
FILTER_LESS = 2,
6868
FILTER_LESS_OR_EQUAL = 3,
6969
FILTER_IN = 4,
70-
FILTER_NOT_IN = 5
70+
FILTER_NOT_IN = 5,
71+
FILTER_EQ = 6,
72+
FILTER_NE = 7
7173
};
7274

7375
template <PrimitiveType>
7476
constexpr bool always_false_v = false;
7577

76-
inline SQLFilterOp to_olap_filter_type(TExprOpcode::type type, bool opposite) {
77-
switch (type) {
78-
case TExprOpcode::LT:
79-
return opposite ? FILTER_LARGER : FILTER_LESS;
80-
81-
case TExprOpcode::LE:
82-
return opposite ? FILTER_LARGER_OR_EQUAL : FILTER_LESS_OR_EQUAL;
83-
84-
case TExprOpcode::GT:
85-
return opposite ? FILTER_LESS : FILTER_LARGER;
86-
87-
case TExprOpcode::GE:
88-
return opposite ? FILTER_LESS_OR_EQUAL : FILTER_LARGER_OR_EQUAL;
89-
90-
case TExprOpcode::EQ:
91-
return opposite ? FILTER_NOT_IN : FILTER_IN;
92-
93-
case TExprOpcode::NE:
94-
return opposite ? FILTER_IN : FILTER_NOT_IN;
95-
96-
case TExprOpcode::EQ_FOR_NULL:
97-
return FILTER_IN;
98-
99-
default:
100-
VLOG_CRITICAL << "TExprOpcode: " << type;
101-
DCHECK(false);
102-
}
103-
104-
return FILTER_IN;
105-
}
106-
10778
inline SQLFilterOp to_olap_filter_type(const std::string& function_name) {
10879
if (function_name == "lt") {
10980
return FILTER_LESS;
@@ -114,9 +85,9 @@ inline SQLFilterOp to_olap_filter_type(const std::string& function_name) {
11485
} else if (function_name == "ge") {
11586
return FILTER_LARGER_OR_EQUAL;
11687
} else if (function_name == "eq") {
117-
return FILTER_IN;
88+
return FILTER_EQ;
11889
} else if (function_name == "ne") {
119-
return FILTER_NOT_IN;
90+
return FILTER_NE;
12091
} else if (function_name == "in") {
12192
return FILTER_IN;
12293
} else if (function_name == "not_in") {

be/src/pipeline/exec/file_scan_operator.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -55,50 +55,6 @@ PushDownType FileScanLocalState::_should_push_down_binary_predicate(
5555
}
5656
}
5757

58-
bool FileScanLocalState::_should_push_down_or_predicate_recursively(
59-
const vectorized::VExprSPtr& expr) const {
60-
if (expr->node_type() == TExprNodeType::COMPOUND_PRED &&
61-
expr->op() == TExprOpcode::COMPOUND_OR) {
62-
return std::ranges::all_of(expr->children(), [this](const vectorized::VExprSPtr& it) {
63-
return _should_push_down_or_predicate_recursively(it);
64-
});
65-
} else if (expr->node_type() == TExprNodeType::COMPOUND_PRED &&
66-
expr->op() == TExprOpcode::COMPOUND_AND) {
67-
return std::ranges::any_of(expr->children(), [this](const vectorized::VExprSPtr& it) {
68-
return _should_push_down_or_predicate_recursively(it);
69-
});
70-
} else {
71-
auto children = expr->children();
72-
if (children.empty() || children[0]->node_type() != TExprNodeType::SLOT_REF) {
73-
// not a slot ref(column)
74-
return false;
75-
}
76-
std::shared_ptr<vectorized::VSlotRef> slot_ref =
77-
std::dynamic_pointer_cast<vectorized::VSlotRef>(children[0]);
78-
auto entry = _slot_id_to_predicates.find(slot_ref->slot_id());
79-
if (_slot_id_to_predicates.end() == entry) {
80-
return false;
81-
}
82-
if (is_complex_type(slot_ref->data_type()->get_primitive_type())) {
83-
return false;
84-
}
85-
return true;
86-
}
87-
}
88-
89-
PushDownType FileScanLocalState::_should_push_down_or_predicate(
90-
const vectorized::VExprContext* expr_ctx) const {
91-
// TODO(gabriel): Do not push down OR predicate for the time being.
92-
// auto expr = expr_ctx->root()->get_impl() ? expr_ctx->root()->get_impl() : expr_ctx->root();
93-
// if (expr->node_type() == TExprNodeType::COMPOUND_PRED &&
94-
// expr->op() == TExprOpcode::COMPOUND_OR) {
95-
// if (_should_push_down_or_predicate_recursively(expr)) {
96-
// return PushDownType::PARTIAL_ACCEPTABLE;
97-
// }
98-
// }
99-
return PushDownType::UNACCEPTABLE;
100-
}
101-
10258
int FileScanLocalState::max_scanners_concurrency(RuntimeState* state) const {
10359
// For select * from table limit 10; should just use one thread.
10460
if (should_run_serial()) {

be/src/pipeline/exec/file_scan_operator.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ class FileScanLocalState final : public ScanLocalState<FileScanLocalState> {
8282
PushDownType _should_push_down_binary_predicate(
8383
vectorized::VectorizedFnCall* fn_call, vectorized::VExprContext* expr_ctx,
8484
StringRef* constant_val, const std::set<std::string> fn_name) const override;
85-
PushDownType _should_push_down_or_predicate(
86-
const vectorized::VExprContext* expr_ctx) const override;
87-
bool _should_push_down_or_predicate_recursively(const vectorized::VExprSPtr& expr) const;
8885
std::shared_ptr<vectorized::SplitSourceConnector> _split_source = nullptr;
8986
int _max_scanners;
9087
// A in memory cache to save some common components

be/src/pipeline/exec/olap_scan_operator.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -450,19 +450,6 @@ Status OlapScanLocalState::_init_scanners(std::list<vectorized::ScannerSPtr>* sc
450450
return Status::OK();
451451
}
452452
SCOPED_TIMER(_scanner_init_timer);
453-
454-
if (!_conjuncts.empty() && _state->enable_profile()) {
455-
std::string message;
456-
for (auto& conjunct : _conjuncts) {
457-
if (conjunct->root()) {
458-
if (!message.empty()) {
459-
message += ", ";
460-
}
461-
message += conjunct->root()->debug_string();
462-
}
463-
}
464-
custom_profile()->add_info_string("RemainedDownPredicates", message);
465-
}
466453
auto& p = _parent->cast<OlapScanOperatorX>();
467454

468455
for (auto uid : p._olap_scan_node.output_column_unique_ids) {
@@ -834,23 +821,6 @@ void OlapScanLocalState::set_scan_ranges(RuntimeState* state,
834821
}
835822
}
836823

837-
static std::string predicates_to_string(
838-
const phmap::flat_hash_map<int, std::vector<std::shared_ptr<ColumnPredicate>>>&
839-
slot_id_to_predicates) {
840-
fmt::memory_buffer debug_string_buffer;
841-
for (const auto& [slot_id, predicates] : slot_id_to_predicates) {
842-
if (predicates.empty()) {
843-
continue;
844-
}
845-
fmt::format_to(debug_string_buffer, "Slot ID: {}: [", slot_id);
846-
for (const auto& predicate : predicates) {
847-
fmt::format_to(debug_string_buffer, "{{{}}}, ", predicate->debug_string());
848-
}
849-
fmt::format_to(debug_string_buffer, "] ");
850-
}
851-
return fmt::to_string(debug_string_buffer);
852-
}
853-
854824
static std::string tablets_id_to_string(
855825
const std::vector<std::unique_ptr<TPaloScanRange>>& scan_ranges) {
856826
if (scan_ranges.empty()) {
@@ -960,8 +930,6 @@ Status OlapScanLocalState::_build_key_ranges_and_filters() {
960930
}
961931

962932
if (state()->enable_profile()) {
963-
custom_profile()->add_info_string("PushDownPredicates",
964-
predicates_to_string(_slot_id_to_predicates));
965933
custom_profile()->add_info_string("KeyRanges", _scan_keys.debug_string());
966934
custom_profile()->add_info_string("TabletIds", tablets_id_to_string(_scan_ranges));
967935
}

0 commit comments

Comments
 (0)