BiteTheDDDDt opened a new pull request, #62222:
URL: https://github.com/apache/doris/pull/62222

   This pull request refactors and improves the scan limit handling logic 
across the scanner and storage layers, making the enforcement of SQL LIMITs 
more robust and efficient. The main changes include centralizing the shared 
scan limit logic in the scanner, ensuring correct behavior for both general 
LIMIT and Top-N (ORDER BY ... LIMIT) queries, and simplifying or removing 
redundant limit checks in the context and scheduler layers.
   
   **Scan limit handling improvements:**
   
   - Added a new virtual method `shared_scan_limit_ptr()` to 
`ScanLocalStateBase` and its implementation in `ScanLocalState`, allowing 
scanners to access a shared atomic scan limit pointer for enforcing SQL LIMIT 
across parallel scanners. 
[[1]](diffhunk://#diff-a45108106b12759815ac5991d56a9d6ead7ffb9c915fb0cf7b6f0b8123b30262R72)
 
[[2]](diffhunk://#diff-a45108106b12759815ac5991d56a9d6ead7ffb9c915fb0cf7b6f0b8123b30262R240)
 
[[3]](diffhunk://#diff-3c4794a864169735a628d8fcb1de986523a9516aad318aa0a893913f4ce031d4R1047-R1054)
   - In `Scanner`, now caches the shared scan limit pointer during 
initialization and uses it to perform early exits and decrement the limit as 
rows are produced, ensuring all scanners stop promptly when the LIMIT is 
reached. This logic is bypassed for Top-N queries, where each scanner must 
independently produce its local candidates. 
[[1]](diffhunk://#diff-7fe2376680f9ab835053a0a93c7f9458e6d526acfc180318be0ad936e0c2dedeR50-R55)
 
[[2]](diffhunk://#diff-7fe2376680f9ab835053a0a93c7f9458e6d526acfc180318be0ad936e0c2dedeR132-R142)
 
[[3]](diffhunk://#diff-7fe2376680f9ab835053a0a93c7f9458e6d526acfc180318be0ad936e0c2dedeR176-R183)
 
[[4]](diffhunk://#diff-7fe2376680f9ab835053a0a93c7f9458e6d526acfc180318be0ad936e0c2dedeR196-R197)
 
[[5]](diffhunk://#diff-9c777f60e1d076777f042a0b702967bd5864bcfe9ee1eee9b456bb67c6fdf817R266-R270)
   
   **Top-N and storage layer limit propagation:**
   
   - Refactored `VCollectIterator` to unify and clarify local read limit 
handling for both general and Top-N queries, using a new `_local_read_limit` 
and `_limit_mode` to control limit enforcement and propagation to the storage 
layer. This ensures correct block truncation and limit application in both code 
paths. 
[[1]](diffhunk://#diff-88c1391d53c67a5ab8475c103bb743a2a80cc282e0c752e8fc52b7aaeb2e0e35L87-L108)
 
[[2]](diffhunk://#diff-88c1391d53c67a5ab8475c103bb743a2a80cc282e0c752e8fc52b7aaeb2e0e35L259-R263)
 
[[3]](diffhunk://#diff-88c1391d53c67a5ab8475c103bb743a2a80cc282e0c752e8fc52b7aaeb2e0e35L270-L272)
 
[[4]](diffhunk://#diff-88c1391d53c67a5ab8475c103bb743a2a80cc282e0c752e8fc52b7aaeb2e0e35L282-R293)
 
[[5]](diffhunk://#diff-88c1391d53c67a5ab8475c103bb743a2a80cc282e0c752e8fc52b7aaeb2e0e35L350-R356)
 
[[6]](diffhunk://#diff-88c1391d53c67a5ab8475c103bb743a2a80cc282e0c752e8fc52b7aaeb2e0e35L379-R382)
 
[[7]](diffhunk://#diff-88c1391d53c67a5ab8475c103bb743a2a80cc282e0c752e8fc52b7aaeb2e0e35L388-R391
 )
   - In `OlapScanner`, disables the shared scan limit pointer for Top-N 
queries, ensuring each scanner independently enforces its local limit, and 
clarifies when storage-level optimizations are valid. 
[[1]](diffhunk://#diff-4d3f2b2a64e1dac3bc076994d3cd9a6c569f7a8c6ad5bc69425188ffccb4266bL511-R516)
 
[[2]](diffhunk://#diff-4d3f2b2a64e1dac3bc076994d3cd9a6c569f7a8c6ad5bc69425188ffccb4266bR536-R548)
   
   **Context and scheduler simplification:**
   
   - Removed redundant or now-unnecessary limit enforcement logic from 
`ScannerContext` and `ScannerScheduler`, centralizing all shared scan limit 
checks in the scanner itself. This reduces complexity and avoids 
double-counting or race conditions. 
[[1]](diffhunk://#diff-0c9a817d45d8130ea3211189e1321d1275e22fd4a9a3fac2bd707b1cfeefa5e5L116-L136)
 
[[2]](diffhunk://#diff-0c9a817d45d8130ea3211189e1321d1275e22fd4a9a3fac2bd707b1cfeefa5e5L425-R404)
 
[[3]](diffhunk://#diff-0c9a817d45d8130ea3211189e1321d1275e22fd4a9a3fac2bd707b1cfeefa5e5L746-L750)
 
[[4]](diffhunk://#diff-3049f42cade971254aae07ced700d9a10b2505b03da743efea3270e63bd88dceL291-L293)
 
[[5]](diffhunk://#diff-ecdf52f3fb33b9018cc1aff92085e470087071b25d79efed8a849a289215d05fL215-R216)
 
[[6]](diffhunk://#diff-ecdf52f3fb33b9018cc1aff92085e470087071b25d79efed8a849a289215d05fL252-L267)


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