Skip to content

Commit c0411b9

Browse files
authored
Merge pull request #330 from noahisaksen/fix-limit-during-parallel-execution
Fix #328 - Dont do limit pushdown during parallel execution
2 parents a9b4caf + b055cd1 commit c0411b9

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/storage/postgres_optimizer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ static void OptimizePostgresScanLimitPushdown(unique_ptr<LogicalOperator> &op) {
5353
}
5454

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

5762
string generated_limit_clause = "";
5863
if (limit.limit_val.Type() != LimitNodeType::UNSET) {

test/sql/storage/limit.test

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,35 @@ query II
3939
EXPLAIN FROM s.large_tbl LIMIT 5;
4040
----
4141
logical_opt <!REGEX>:.*LIMIT.*
42+
43+
44+
statement ok
45+
set pg_pages_per_task=1
46+
47+
query I
48+
FROM s.large_tbl LIMIT 5
49+
----
50+
0
51+
1
52+
2
53+
3
54+
4
55+
56+
query I
57+
FROM s.large_tbl LIMIT 5 OFFSET 5
58+
----
59+
5
60+
6
61+
7
62+
8
63+
9
64+
65+
statement ok
66+
set explain_output='optimized_only'
67+
68+
# limit is still in plan as we were not able to push down due to parallel execution
69+
70+
query II
71+
EXPLAIN FROM s.large_tbl LIMIT 5;
72+
----
73+
logical_opt <REGEX>:.*LIMIT.*

0 commit comments

Comments
 (0)