Akanksha-kedia opened a new pull request, #18516:
URL: https://github.com/apache/pinot/pull/18516

   ## Description
   
   When the multi-stage engine's broker-side segment pruning eliminates all 
segments for a query (i.e., no real servers remain in the dispatch plan), the 
broker currently still acquires a query-throttler slot and dispatches to 
servers needlessly. This PR adds a fast-path that detects this condition and 
returns an empty `BrokerResponseNativeV2` with the correct result schema 
immediately, skipping dispatch entirely.
   
   ## Problem
   
   In the current flow, even when all segments are pruned at the broker:
   1. The query throttler semaphore is acquired (blocking other queries)
   2. The query is dispatched over the network to servers
   3. Servers process an empty plan and return empty results
   4. The broker reduces the empty results
   
   This wastes query-throttler capacity, network round-trips, and server-side 
resources for queries that are already known to produce no results.
   
   ## Solution
   
   After `planQuery()` produces the `DispatchableSubPlan`, check if 
`servers.size() <= 1` (i.e., only the broker itself is present in the plan with 
no real servers to dispatch to). When this condition holds, call the new 
`buildEmptyBrokerResponse()` method that:
   
   - Constructs the correct `DataSchema` from the plan's root stage and result 
fields
   - Returns an empty `ResultTable` with zero rows
   - Reports `numServersQueried = 0` and `numServersResponded = 0`
   - Populates the broker-pruned segment count in stats
   - Logs the query completion and updates metrics as normal
   
   ## Performance Impact
   
   - Eliminates network round-trips for fully-pruned queries
   - Eliminates query-throttler slot acquisition (reduces head-of-line blocking 
for other queries)
   - Reduces server-side thread/memory allocation for no-op dispatches
   - Latency for pruned queries drops from network-RTT-bounded to 
sub-millisecond
   
   ## Testing Done
   
   - [x] Unit test added: `testBuildEmptyBrokerResponseWhenAllSegmentsPruned` 
verifies correct schema, zero rows, zero servers queried/responded, and that 
the query throttler is never called
   - [x] Verified the optimization is placed after QPS quota validation (so 
quota is still enforced)
   - [x] Verified backward compatibility: queries with actual segments are 
unaffected
   
   ## Checklist
   - [x] Code follows project style guidelines
   - [x] Self-review completed
   - [x] No new warnings introduced
   - [x] Unit test covers the new fast-path behavior


-- 
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]

Reply via email to