-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[fix](be) Finish pending scanners after shared limit #65814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mryange
wants to merge
2
commits into
apache:master
Choose a base branch
from
Mryange:fix-shared-scan-limit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+188
−6
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
regression-test/data/correctness_p0/test_shared_scan_limit_pending_tasks.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| -- This file is automatically generated. You should know what you did if you want to edit this | ||
| -- !shared_scan_limit_parallel_2 -- | ||
|
|
||
| -- !shared_scan_limit_parallel_6 -- | ||
|
|
||
| -- !shared_scan_limit_parallel_8 -- | ||
|
|
175 changes: 175 additions & 0 deletions
175
regression-test/suites/correctness_p0/test_shared_scan_limit_pending_tasks.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| // 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. | ||
|
|
||
| suite("test_shared_scan_limit_pending_tasks") { | ||
| sql "DROP TABLE IF EXISTS shared_scan_limit_t1" | ||
| sql "DROP TABLE IF EXISTS shared_scan_limit_t3" | ||
| sql "DROP TABLE IF EXISTS shared_scan_limit_t4" | ||
| sql "DROP TABLE IF EXISTS shared_scan_limit_t5" | ||
|
|
||
| sql """ | ||
| CREATE TABLE shared_scan_limit_t1 ( | ||
| pk INT, | ||
| v1 BIGINT, | ||
| v2 BIGINT | ||
| ) ENGINE=OLAP | ||
| DUPLICATE KEY(pk) | ||
| DISTRIBUTED BY HASH(pk) BUCKETS 10 | ||
| PROPERTIES ("replication_num" = "1") | ||
| """ | ||
| sql """ | ||
| CREATE TABLE shared_scan_limit_t3 ( | ||
| pk INT, | ||
| v1 BIGINT, | ||
| v2 BIGINT | ||
| ) ENGINE=OLAP | ||
| DUPLICATE KEY(pk) | ||
| DISTRIBUTED BY HASH(pk) BUCKETS 10 | ||
| PROPERTIES ("replication_num" = "1") | ||
| """ | ||
| sql """ | ||
| CREATE TABLE shared_scan_limit_t4 ( | ||
| pk INT, | ||
| v1 BIGINT, | ||
| v2 BIGINT | ||
| ) ENGINE=OLAP | ||
| DUPLICATE KEY(pk) | ||
| DISTRIBUTED BY HASH(pk) BUCKETS 10 | ||
| PROPERTIES ("replication_num" = "1") | ||
| """ | ||
| sql """ | ||
| CREATE TABLE shared_scan_limit_t5 ( | ||
| pk INT, | ||
| v1 BIGINT, | ||
| v2 BIGINT | ||
| ) ENGINE=OLAP | ||
| DUPLICATE KEY(pk) | ||
| DISTRIBUTED BY HASH(pk) BUCKETS 10 | ||
| PROPERTIES ("replication_num" = "1") | ||
| """ | ||
|
|
||
| sql """ | ||
| INSERT INTO shared_scan_limit_t1 VALUES | ||
| (0,70,32163), (1,-71,NULL), (2,-85,-222125), (3,26,22867), | ||
| (4,17,NULL), (5,NULL,6236439), (6,-16907,-24720), (7,26877,1893), | ||
| (8,30405,9), (9,5873343,66), (10,-17,-47), (11,NULL,20987), | ||
| (12,NULL,-4672), (13,NULL,3551614), (14,28521,-1372), (15,NULL,NULL), | ||
| (16,38,NULL), (17,NULL,-54), (18,NULL,-4686447), (19,NULL,-8420) | ||
| """ | ||
| sql """ | ||
| INSERT INTO shared_scan_limit_t3 VALUES | ||
| (0,28862,-25225), (1,5516858,-4609390), (2,-7815300,NULL), | ||
| (3,NULL,-7685824), (4,22293,26373), (5,NULL,NULL), (6,1237,-31), | ||
| (7,1606,3318374), (8,NULL,-21355), (9,NULL,-20127), (10,5413995,-3), | ||
| (11,-4718995,NULL), (12,3179854,3733421), (13,18867,76), | ||
| (14,15517,-4932405), (15,-30778,NULL), (16,NULL,-7258), | ||
| (17,NULL,7520313), (18,6936629,NULL), (19,-45,6231596) | ||
| """ | ||
| sql """ | ||
| INSERT INTO shared_scan_limit_t4 VALUES | ||
| (0,5649134,4812327), (1,8249417,4670054), (2,106,6714155), | ||
| (3,NULL,NULL), (4,-52850,-5113499), (5,-23911,-9637), (6,-26168,9), | ||
| (7,-47,-28398), (8,-29518,-2365317), (9,20685,22956), (10,97,25099), | ||
| (11,-32617,6143808), (12,NULL,NULL), (13,-52,NULL), (14,7680925,NULL), | ||
| (15,10848,NULL), (16,64,-3394), (17,113,-12488), (18,-87,-12093), | ||
| (19,NULL,22) | ||
| """ | ||
| sql """ | ||
| INSERT INTO shared_scan_limit_t5 VALUES | ||
| (0,-3018453,-5763927), (1,-60,-6233027), (2,78,-5304), (3,63,NULL), | ||
| (4,23287,NULL), (5,98,7989209), (6,-61,-30493), (7,-6781665,-22321), | ||
| (8,-5165806,-75), (9,NULL,31290), (10,1311226,7754904), (11,-72,54), | ||
| (12,114,3741372), (13,NULL,NULL), (14,-40,2014555), (15,69,-4555977), | ||
| (16,118,-8708), (17,NULL,NULL), (18,-123,NULL), (19,NULL,19843) | ||
| """ | ||
| sql "sync" | ||
|
|
||
| sql "SET enable_sql_cache = false" | ||
| sql "SET experimental_enable_local_shuffle = false" | ||
| sql "SET query_timeout = 60" | ||
|
|
||
| // A shared LIMIT can be exhausted while another ScannerContext still owns pending tasks. | ||
| // Every context must still reach EOS instead of leaving its pipeline task blocked forever. | ||
| sql "SET parallel_pipeline_task_num = 2" | ||
| qt_shared_scan_limit_parallel_2 """ | ||
| SELECT v1, pk | ||
| FROM shared_scan_limit_t1 AS t1 | ||
| WHERE v2 > ( | ||
| SELECT SUM(v1) | ||
| FROM shared_scan_limit_t5 AS t3 | ||
| WHERE EXISTS ( | ||
| SELECT pk | ||
| FROM shared_scan_limit_t3 AS t4 | ||
| WHERE NOT EXISTS ( | ||
| SELECT pk, v1, v1, v2, v1 | ||
| FROM shared_scan_limit_t4 AS t5 | ||
| WHERE v2 NOT IN ( | ||
| SELECT pk FROM shared_scan_limit_t1 AS t6 ORDER BY pk | ||
| ) | ||
| ) AND v1 < 7 | ||
| ) | ||
| ) | ||
| ORDER BY v1, pk DESC | ||
| LIMIT 6 | ||
| """ | ||
|
|
||
| sql "SET parallel_pipeline_task_num = 6" | ||
| qt_shared_scan_limit_parallel_6 """ | ||
| SELECT v1, pk | ||
| FROM shared_scan_limit_t1 AS t1 | ||
| WHERE v2 > ( | ||
| SELECT SUM(v1) | ||
| FROM shared_scan_limit_t5 AS t3 | ||
| WHERE EXISTS ( | ||
| SELECT pk | ||
| FROM shared_scan_limit_t3 AS t4 | ||
| WHERE NOT EXISTS ( | ||
| SELECT pk, v1, v1, v2, v1 | ||
| FROM shared_scan_limit_t4 AS t5 | ||
| WHERE v2 NOT IN ( | ||
| SELECT pk FROM shared_scan_limit_t1 AS t6 ORDER BY pk | ||
| ) | ||
| ) AND v1 < 7 | ||
| ) | ||
| ) | ||
| ORDER BY v1, pk DESC | ||
| LIMIT 6 | ||
| """ | ||
|
|
||
| sql "SET parallel_pipeline_task_num = 8" | ||
| qt_shared_scan_limit_parallel_8 """ | ||
| SELECT v1, pk | ||
| FROM shared_scan_limit_t1 AS t1 | ||
| WHERE v2 > ( | ||
| SELECT SUM(v1) | ||
| FROM shared_scan_limit_t5 AS t3 | ||
| WHERE EXISTS ( | ||
| SELECT pk | ||
| FROM shared_scan_limit_t3 AS t4 | ||
| WHERE NOT EXISTS ( | ||
| SELECT pk, v1, v1, v2, v1 | ||
| FROM shared_scan_limit_t4 AS t5 | ||
| WHERE v2 NOT IN ( | ||
| SELECT pk FROM shared_scan_limit_t1 AS t6 ORDER BY pk | ||
| ) | ||
| ) AND v1 < 7 | ||
| ) | ||
| ) | ||
| ORDER BY v1, pk DESC | ||
| LIMIT 6 | ||
| """ | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Avoid opening pending scanners after the LIMIT is satisfied
After this deletion, a context that did not produce the limiting row repeatedly schedules its remaining tasks: every consumed EOS calls
schedule_scan_task()before the local finish check, and_scanner_scan()runsprepare()/open()beforeScanner::get_block()sees the shared counter<= 0. With many tablet/file ranges this does O(remaining scanners) initialization/eager-read work; worse, an otherwise-unneeded submit/prepare/open error is propagated through_process_status, so a LIMIT query that already has enough rows can now fail.The old guard can strand a late context whose first schedule already sees zero because its dependency starts blocked; a separate zero-to-negative window exists after EOS. Please keep a no-I/O finite-exhausted path (
limit >= 0 && shared_remaining <= 0), but have the scheduling path itself finish/wake the context when it will submit no task and no completed/in-flight work remains (or synthesize a cheap EOS). If work remains in flight, let its callbacks return without starting new pending readers. Do not rely only on a later consumer check, which can be unreachable.