hello-stephen commented on code in PR #71073:
URL: https://github.com/apache/doris/pull/71073#discussion_r4809023247
##########
be/src/exec/pipeline/pipeline_task.cpp:
##########
@@ -350,12 +386,22 @@ bool PipelineTask::_is_blocked() {
});
}
-void PipelineTask::unblock_all_dependencies() {
+void PipelineTask::unblock_all_dependencies(std::optional<PipelineId>
downstream_pipeline) {
// Keep dependency pointers and task-owned operator/shared state stable
because set_ready() may
// synchronously call wake_up() and submit this task.
std::unique_lock<std::mutex> lock(_dependency_lifecycle_lock);
auto fragment = _fragment_context.lock();
if (!is_finalized() && fragment) {
+ if (downstream_pipeline) {
+ // A hash join can finish probing an empty partition while its
build task is still
+ // synchronizing RF sizes. Keep the build's normal close and
publication path alive.
+ if (std::ranges::any_of(_finish_dependencies, [](const Dependency*
dep) {
Review Comment:
[P2] Keep an exit for ignored size-sync failures
An EOS hash build with a distributed runtime-sized Bloom filter can latch
its finish dependency, then have its empty local probe finish while it waits.
Its `SendFilterSize` RPC can already have returned OK when the merge node’s
separate `SyncFilterSize` RPC fails. With `ignore_runtime_filter_error=true`,
that failure only logs, so the producer never releases the latch. This return
also skips the previous downstream unblock, which can delay fragment completion
until cancellation or query timeout. Please bound this retained wait or arrange
for the ignored failure to release the latch.
##########
be/test/exec/operator/exchange_source_operator_test.cpp:
##########
@@ -181,4 +190,426 @@ TEST_F(ExchangeSourceOperatorXTest, test_no_merge) {
EXPECT_TRUE(local_state->close(state.get()));
}
}
-} // namespace doris
\ No newline at end of file
+class ExchangeRuntimeFilterTest : public RuntimeFilterTest {
+protected:
+ void SetUp() override {
+ RuntimeFilterTest::SetUp();
+ _context = std::make_shared<PipelineFragmentContext>(TUniqueId(),
TPipelineFragmentParams(),
+ _query_ctx,
ExecEnv::GetInstance(),
+ nullptr);
+ _context->set_rec_cte_stage(3);
Review Comment:
[P1] Use stage 0 for the bitmap tests
This fixture puts every consumer in recursive CTE stage 3.
`RuntimeFilterConsumer::_apply_ready_expr` only enables block dedup at stage 0,
so all four `RepeatFilterSkipsOnlyCertifiedBlocks` variants reach the bitmap
assertion with the bit unset. `IgnoresBitmapWithoutPlannerCertification` also
passes regardless of planner certification at stage 3. Please set stage 3 only
in the test that checks stage propagation and run the bitmap tests at stage 0.
##########
regression-test/suites/nereids_rules_p0/runtime_filter/test_runtime_filter_on_exchange.groovy:
##########
@@ -0,0 +1,117 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+import org.apache.doris.regression.action.ProfileAction
+
+suite("test_runtime_filter_on_exchange", "p0") {
+ sql "set disable_join_reorder = true"
+ sql "set enable_runtime_filter_prune = false"
+ sql "set enable_runtime_filter_partition_prune = false"
+ sql "set enable_runtime_filter_bucket_prune = false"
+ sql "set runtime_filter_wait_time_ms = 0"
+ sql "set runtime_filter_wait_infinitely = false"
+ sql "set parallel_pipeline_task_num = 3"
+ sql "set enable_sql_cache = false"
+ sql "set enable_query_cache = false"
+ sql "set enable_condition_cache = false"
+
+ sql "drop table if exists rf_exchange_fact"
+ sql """create table rf_exchange_fact (id int not null, k bigint null, v
bigint not null)
+ duplicate key(id) distributed by hash(id) buckets 3
+ properties("replication_num" = "1")"""
+ sql """insert into rf_exchange_fact
+ select cast(number as int), if(number % 17 = 0, null, number %
1024), number * 3
+ from numbers("number" = "32768")"""
+ sql "drop table if exists rf_exchange_dim"
+ sql """create table rf_exchange_dim (k bigint not null)
+ duplicate key(k) distributed by hash(k) buckets 1
+ properties("replication_num" = "1")"""
+ sql "insert into rf_exchange_dim values (7)"
+
+ for (boolean enabled : [false, true]) {
+ sql "set enable_runtime_filter_on_exchange = ${enabled}"
+ for (String type : ['IN', 'BLOOM_FILTER', 'MIN_MAX',
'IN_OR_BLOOM_FILTER']) {
+ sql "set runtime_filter_type = '${type}'"
+ order_qt_direct """select count(*), sum(f.id), sum(f.v)
+ from rf_exchange_fact f join [shuffle]
rf_exchange_dim d on f.k = d.k"""
+ order_qt_alias """select count(*), sum(p.id), sum(p.v)
+ from (select id, k + 1 as x, v from
rf_exchange_fact) p
+ join [shuffle] (select k + 1 as x from
rf_exchange_dim) d on p.x = d.x"""
+ order_qt_union """select count(*), sum(p.id), sum(p.v)
+ from (select id, k as x, v from rf_exchange_fact
where id < 16384
+ union all
+ select id, k as x, v from rf_exchange_fact
where id >= 16384) p
+ join [shuffle] rf_exchange_dim d on p.x = d.k"""
+ order_qt_cte """with p as (select id, k, v from rf_exchange_fact)
+ select count(*), sum(a.id), sum(a.v)
+ from p a join [shuffle] p b on a.id = b.id
+ join [shuffle] rf_exchange_dim d on a.k = d.k"""
+ order_qt_grouped """select count(*), sum(p.total)
+ from (select k, sum(v) as total from
rf_exchange_fact group by k) p
+ join [shuffle] rf_exchange_dim d on p.k =
d.k"""
+ order_qt_empty """select count(*) from rf_exchange_fact f
+ join [shuffle] (select k from rf_exchange_dim
where k < 0) d on f.k = d.k"""
+ order_qt_outer """select count(*), count(d.k), sum(f.id)
+ from rf_exchange_fact f left join [shuffle]
rf_exchange_dim d on f.k = d.k"""
+ order_qt_limit """select count(*), sum(p.id), sum(p.v)
+ from (select id, k, v from rf_exchange_fact
order by id limit 20 offset 5) p
+ join [shuffle] rf_exchange_dim d on p.k = d.k"""
+ }
+ }
+
+ // Delay the one-row build input while the probe scan fills the exchange
queues.
+ // Scan RFs remain enabled: positive receiver counters prove that rows
which escaped
+ // scan filtering are pruned at the exchange, rather than only checking
the final join.
+ String delayedBuildQuery = """select count(*), sum(f.id), sum(f.v)
+ from rf_exchange_fact f join [shuffle]
+ (select k + cast(sleep(2) as bigint) as k from
rf_exchange_dim) d on f.k = d.k"""
+ sql "set enable_profile = true"
+ sql "set profile_level = 2"
+ sql "set runtime_filter_type = 'IN'"
+ for (boolean enabled : [false, true]) {
+ sql "set enable_runtime_filter_on_exchange = ${enabled}"
+ String token = "rf_exchange_${enabled}_${UUID.randomUUID()}"
+ order_qt_delayed "/* ${token} */ ${delayedBuildQuery}"
+ String profile = new ProfileAction(context).getProfileBySql(token,
['EXCHANGE_OPERATOR'])
+ boolean receiver = false
+ List<BigDecimal> inputRows = []
+ List<BigDecimal> filteredRows = []
+ profile.eachLine { String line ->
+ String text = line.trim()
+ if (text ==~ /^[A-Z][A-Z0-9_]*_OPERATOR\b.*/) {
+ receiver = text.startsWith('EXCHANGE_OPERATOR')
+ }
+ if (receiver) {
+ def input = (text =~ /^- RF[0-9]+ InputRows:\s*([0-9,.]+)/)
+ def filtered = (text =~ /^- RF[0-9]+ FilterRows:\s*([0-9,.]+)/)
+ if (input.find()) {
+ inputRows.add(new BigDecimal(input.group(1).replace(',',
'')))
+ }
+ if (filtered.find()) {
+ filteredRows.add(new
BigDecimal(filtered.group(1).replace(',', '')))
+ }
+ }
+ }
+ if (enabled) {
+ if (!inputRows.any { it > 0 } || !filteredRows.any { it > 0 }) {
Review Comment:
[P2] Synchronize filter delivery in the profile test
The build-side `sleep(2)` lets probe rows accumulate. Receiver waiting is
disabled and the budget is zero. On a shuffle join,
`HashJoinBuildSinkOperatorX::sink_impl` releases the probe on EOS before
`close()` sends the asynchronous RF. The exchange can drain the queued rows
before the filter arrives, yielding a correct result and zero receiver
`FilterRows`. Please ensure the probe rows are queued before publication and
synchronize receiver consumption with filter delivery before asserting a
positive count.
##########
be/src/exec/exchange/vdata_stream_sender.cpp:
##########
@@ -344,6 +344,13 @@ Status BlockSerializer::serialize_block(const Block* src,
PBlock* dest, size_t n
RETURN_IF_ERROR(src->serialize(_parent->_state->be_exec_version(), dest,
&uncompressed_bytes,
&compressed_bytes, &compress_time,
_parent->compression_type(),
_parent->transfer_large_data_by_brpc()));
+ const auto& filters = src->applied_runtime_filters();
Review Comment:
[P2] Preserve the proof in multi-block broadcast
`add_borrowed_broadcast_block` in `exchange_sink_buffer.cpp` reconstructs
the `PBlock` field by field and omits both bitmap words. The cached and
uncached multi-block broadcast paths use that helper. For example, a parent
join’s RF on `b.k` can be certified for `Scan b` and the broadcast receiver
feeding the build side of a lower inner join. The receiver then sees a zero
bitmap and evaluates that RF again. Please copy both optional fields in the
helper and cover the multi-block broadcast path.
##########
be/src/exec/pipeline/pipeline_task.cpp:
##########
@@ -153,11 +153,47 @@ Status PipelineTask::prepare(const
std::vector<TScanRangeParams>& scan_range, co
parent_profile =
_state->get_local_state(op->operator_id())->operator_profile();
}
{
- const auto& deps =
-
_state->get_local_state(_source->operator_id())->execution_dependencies();
+ auto* source_state = _state->get_local_state(_source->operator_id());
+ const auto deps = source_state->execution_dependencies();
+ auto* scan_state = dynamic_cast<ScanLocalStateBase*>(source_state);
+ auto* exchange_state =
_state->query_options().enable_runtime_filter_wait_on_exchange
+ ?
dynamic_cast<ExchangeLocalState*>(source_state)
+ : nullptr;
+ const bool wait_for_scan_rf = scan_state &&
scan_state->has_runtime_filters();
+ const bool wait_for_exchange_rf =
+ exchange_state && exchange_state->waits_for_runtime_filters();
+ const std::vector<DependencySPtr>* rf_dependencies = nullptr;
+ if (wait_for_scan_rf || wait_for_exchange_rf) {
+ std::vector<std::weak_ptr<Dependency>> prerequisites;
+ prerequisites.emplace_back(
+
_state->get_query_ctx()->get_execution_dependency()->shared_from_this());
+ for (auto* dep : deps) {
+ prerequisites.emplace_back(dep->shared_from_this());
+ }
+ // A probe can wait for a sibling pipeline's hash table before
spending its RF
+ // budget. A source's own data dependency is checked after open().
+ for (size_t i = 1; i < _operators.size(); ++i) {
+ auto* local_state =
_state->get_local_state(_operators[i]->operator_id());
+ for (auto* dep : local_state->dependencies()) {
Review Comment:
[P2] Let zero-wait filters preserve the empty-build short circuit
Consider a probe pipeline with an upper inner hash join whose build is
empty, a lower hash join whose build is slow, and a scan with an unpublished
zero-wait RF from another fragment. The new timer waits for the lower join’s
read dependency before it can expire. `_wait_to_start()` therefore parks the
task before `_is_blocked()` can see that the upper join needs no child input
and end the pipeline. This also affects scans with exchange filtering disabled.
Please make zero-wait consumers ready independently of the prerequisites and
keep skippable operator dependencies out of the startup gate.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java:
##########
@@ -403,7 +403,7 @@ protected LogicalPlan preprocess(LogicalPlan logicalPlan) {
private void configRuntimeFilterWaitTime() {
if (ConnectContext.get() != null &&
ConnectContext.get().getSessionVariable() != null
&&
ConnectContext.get().getSessionVariable().getRuntimeFilterWaitTimeMs()
- ==
VariableMgr.getDefaultSessionVariable().getRuntimeFilterWaitTimeMs()) {
+ ==
Integer.parseInt(VariableMgr.getDefaultValue(SessionVariable.RUNTIME_FILTER_WAIT_TIME_MS)))
{
Review Comment:
[P2] Keep an explicit session wait of 1000 ms
After `SET GLOBAL runtime_filter_wait_time_ms = 5000` and `SET SESSION
runtime_filter_wait_time_ms = 1000`, the previous condition kept the explicit
one-second setting. The new comparison sees the built-in default of 1000 and
can overwrite it with 5000 ms for an external scan or at least the query
timeout in cloud mode. This happens with exchange filtering disabled as well.
Please preserve the explicit session override while honoring a custom inherited
global value.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]