Skip to content

Commit

Permalink
Merge pull request #58660 from ClickHouse/backport/23.12/58608
Browse files Browse the repository at this point in the history
Backport #58608 to 23.12: Remove order by requierement in PASTE JOIN
  • Loading branch information
alexey-milovidov committed Jan 10, 2024
2 parents 56527c7 + e298838 commit e502a3f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
28 changes: 28 additions & 0 deletions docs/en/sql-reference/statements/select/join.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,34 @@ PASTE JOIN
10
└───┴──────┘
```
Note: In this case result can be nondeterministic if the reading is parallel. Example:
```SQL
SELECT *
FROM
(
SELECT number AS a
FROM numbers_mt(5)
) AS t1
PASTE JOIN
(
SELECT number AS a
FROM numbers(10)
ORDER BY a DESC
) AS t2
SETTINGS max_block_size = 2;

┌─a─┬─t2.a─┐
29
38
└───┴──────┘
┌─a─┬─t2.a─┐
07
16
└───┴──────┘
┌─a─┬─t2.a─┐
45
└───┴──────┘
```

## Distributed JOIN

Expand Down
6 changes: 4 additions & 2 deletions src/QueryPipeline/QueryPipelineBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
extern const int NOT_IMPLEMENTED;
extern const int BAD_ARGUMENTS;
}

void QueryPipelineBuilder::checkInitialized()
Expand Down Expand Up @@ -357,7 +356,10 @@ std::unique_ptr<QueryPipelineBuilder> QueryPipelineBuilder::joinPipelinesYShaped
left->pipe.dropExtremes();
right->pipe.dropExtremes();
if ((left->getNumStreams() != 1 || right->getNumStreams() != 1) && join->getTableJoin().kind() == JoinKind::Paste)
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Paste JOIN requires sorted tables only");
{
left->pipe.resize(1, true);
right->pipe.resize(1, true);
}
else if (left->getNumStreams() != 1 || right->getNumStreams() != 1)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Join is supported only for pipelines with one output port");

Expand Down
10 changes: 10 additions & 0 deletions tests/queries/0_stateless/02933_paste_join.reference
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,13 @@ UInt64
UInt64
UInt64
UInt64
0 9
1 8
2 7
3 6
4 5
5 4
6 3
7 2
8 1
9 0
2 changes: 1 addition & 1 deletion tests/queries/0_stateless/02933_paste_join.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ INSERT INTO t2 SELECT number, number FROM numbers(15, 15);
SELECT * FROM ( SELECT * from t1 ) t1 PASTE JOIN ( SELECT * from t2 ) t2 SETTINGS max_threads = 1;
SELECT toTypeName(a) FROM (SELECT number as a FROM numbers(11)) t1 PASTE JOIN (select number as a from numbers(10)) t2 SETTINGS join_use_nulls = 1;
SET max_threads = 2;
select * from (SELECT number as a FROM numbers_mt(10)) t1 PASTE JOIN (select number as a from numbers(10) ORDER BY a DESC) t2 SETTINGS max_block_size=10;
select * from (SELECT number as a FROM numbers(10)) t1 ANY PASTE JOIN (select number as a from numbers(10)) t2; -- { clientError SYNTAX_ERROR }
select * from (SELECT number as a FROM numbers(10)) t1 ALL PASTE JOIN (select number as a from numbers(10)) t2; -- { clientError SYNTAX_ERROR }
select * from (SELECT number as a FROM numbers_mt(10)) t1 PASTE JOIN (select number as a from numbers(10) ORDER BY a DESC) t2 SETTINGS max_block_size=3; -- { serverError BAD_ARGUMENTS }

0 comments on commit e502a3f

Please sign in to comment.