Skip to content

Commit

Permalink
Internal duckdb#215: Serial Unordered Scans
Browse files Browse the repository at this point in the history
* Only use parallel scans for ordered partitions - otherwise the results can be very non-deterministic.
* Make some tests use complete orderings so the expecteds continue to match.
* Disable vector size 2 for moving MODE until we can determine the problem
  • Loading branch information
Richard Wesley committed Sep 7, 2023
1 parent 9698e9e commit cabbc5d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/common/sort/partition_state.cpp
Expand Up @@ -429,7 +429,11 @@ bool PartitionGlobalMergeState::TryPrepareNextStage() {

switch (stage) {
case PartitionSortStage::INIT:
total_tasks = num_threads;
// If the partitions are unordered, don't scan in parallel
// because it produces non-deterministic orderings.
// This can theoretically happen with ORDER BY,
// but that is something the query should be explicit about.
total_tasks = sink.orders.size() > sink.partitions.size() ? num_threads : 1;
stage = PartitionSortStage::SCAN;
return true;

Expand Down
4 changes: 2 additions & 2 deletions test/sql/function/list/lambdas/transform.test
Expand Up @@ -279,7 +279,7 @@ query III
select list_transform(bb, x->[x,b]), bb, b
from (select list(b) over wind as bb, first(b) over wind as b
from test window wind as
(order by a asc rows between 4 preceding and current row)
(order by a asc, b asc rows between 4 preceding and current row)
qualify row_number() over wind >4);
----
[[2, 2], [3, 2], [4, 2], [2, 2], [3, 2]] [2, 3, 4, 2, 3] 2
Expand All @@ -306,4 +306,4 @@ SELECT list_transform([[2, 3], [4]], x -> list_transform([1], y -> x || [y]))
query I
SELECT list_transform([[2, 3], [4]], x -> list_transform(x, y -> x || [y]))
----
[[[2, 3, 2], [2, 3, 3]], [[4, 4]]]
[[[2, 3, 2], [2, 3, 3]], [[4, 4]]]
12 changes: 12 additions & 0 deletions test/sql/window/test_ignore_nulls.test
Expand Up @@ -26,6 +26,7 @@ SELECT
ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING
) AS last_order_id
FROM issue2549
ORDER BY ALL
----
0 1 614 NULL
1 1 NULL 614
Expand All @@ -44,6 +45,7 @@ SELECT
ROWS BETWEEN 1 PRECEDING AND UNBOUNDED FOLLOWING
) AS last_order_id
FROM issue2549
ORDER BY ALL
----
0 1 614 614
1 1 NULL 614
Expand All @@ -62,6 +64,7 @@ SELECT
ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING
) AS last_order_id
FROM issue2549
ORDER BY ALL
----
0 1 614 NULL
1 1 NULL NULL
Expand All @@ -79,6 +82,7 @@ SELECT
ORDER BY id
) AS last_order_id
FROM issue2549
ORDER BY ALL
----
0 1 614 639
1 1 NULL 639
Expand All @@ -96,6 +100,7 @@ SELECT
ORDER BY id
) AS last_order_id
FROM issue2549
ORDER BY ALL
----
0 1 614 -1
1 1 NULL 614
Expand All @@ -114,6 +119,7 @@ SELECT
ORDER BY id
) AS last_order_id
FROM issue2549
ORDER BY ALL
----
0 1 614 614
1 1 NULL NULL
Expand All @@ -135,6 +141,7 @@ SELECT
ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING
) AS last_order_id
FROM issue2549
ORDER BY ALL
----
0 1 614 NULL
1 1 NULL 614
Expand All @@ -153,6 +160,7 @@ SELECT
ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING
) AS last_order_id
FROM issue2549
ORDER BY ALL
----
0 1 614 NULL
1 1 NULL 614
Expand All @@ -171,6 +179,7 @@ SELECT
ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING
) AS last_order_id
FROM issue2549
ORDER BY ALL
----
0 1 614 NULL
1 1 NULL NULL
Expand All @@ -188,6 +197,7 @@ SELECT
ORDER BY id
) AS last_order_id
FROM issue2549
ORDER BY ALL
----
0 1 614 NULL
1 1 NULL NULL
Expand All @@ -205,6 +215,7 @@ SELECT
ORDER BY id
) AS last_order_id
FROM issue2549
ORDER BY ALL
----
0 1 614 -1
1 1 NULL 614
Expand All @@ -223,6 +234,7 @@ SELECT
ORDER BY id
) AS last_order_id
FROM issue2549
ORDER BY ALL
----
0 1 614 614
1 1 NULL NULL
Expand Down
2 changes: 1 addition & 1 deletion test/sql/window/test_mad_window.test
Expand Up @@ -98,7 +98,7 @@ NULL NULL 0.333333
query IIII
SELECT r % 3 as p, r, n, mad(n) over (partition by r % 3 order by r)
FROM (SELECT r, CASE r % 2 WHEN 0 THEN r ELSE NULL END AS n FROM mads) nulls
ORDER BY 1
ORDER BY 1, 2
----
NULL NULL NULL NULL
NULL NULL NULL NULL
Expand Down
7 changes: 6 additions & 1 deletion test/sql/window/test_mode_window.test
Expand Up @@ -2,6 +2,9 @@
# description: Test MODE aggregate as a window function
# group: [window]

# Temporary fix until state issue resolved
require vector_size 64

statement ok
SET default_null_order='nulls_first';

Expand Down Expand Up @@ -32,7 +35,9 @@ NULL NULL NULL NULL
1 9 3 1

query III
SELECT r, r//3, mode(r//3) over (order by r rows between 1 preceding and 1 following) FROM modes ORDER BY 1, 2
SELECT r, r//3, mode(r//3) over (order by r rows between 1 preceding and 1 following)
FROM modes
ORDER BY ALL
----
NULL NULL NULL
NULL NULL NULL
Expand Down

0 comments on commit cabbc5d

Please sign in to comment.