Skip to content

Fix #328 - Dont do limit pushdown during parallel execution #330

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/storage/postgres_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ static void OptimizePostgresScanLimitPushdown(unique_ptr<LogicalOperator> &op) {
}

auto &bind_data = get.bind_data->Cast<PostgresBindData>();
if (bind_data.max_threads != 1 || !bind_data.can_use_main_thread) {
// cannot push down limit/offset if we are not using the main thread
OptimizePostgresScanLimitPushdown(op->children[0]);
return;
}

string generated_limit_clause = "";
if (limit.limit_val.Type() != LimitNodeType::UNSET) {
Expand Down
32 changes: 32 additions & 0 deletions test/sql/storage/limit.test
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,35 @@ query II
EXPLAIN FROM s.large_tbl LIMIT 5;
----
logical_opt <!REGEX>:.*LIMIT.*


statement ok
set pg_pages_per_task=1

query I
FROM s.large_tbl LIMIT 5
----
0
1
2
3
4

query I
FROM s.large_tbl LIMIT 5 OFFSET 5
----
5
6
7
8
9

statement ok
set explain_output='optimized_only'

# limit is still in plan as we were not able to push down due to parallel execution

query II
EXPLAIN FROM s.large_tbl LIMIT 5;
----
logical_opt <REGEX>:.*LIMIT.*
Loading