Standard join type syntax position (#12520)

This commit is contained in:
Artem Zuikov 2020-07-16 11:56:45 +03:00 committed by GitHub
parent f7792d0145
commit ff372ec0f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 117 additions and 79 deletions

View File

@ -24,7 +24,7 @@ See the detailed description of the [CREATE TABLE](../../../sql-reference/statem
**Engine Parameters**
- `join_strictness` [JOIN strictness](../../../sql-reference/statements/select/join.md#select-join-strictness).
- `join_strictness` [JOIN strictness](../../../sql-reference/statements/select/join.md#select-join-types).
- `join_type` [JOIN type](../../../sql-reference/statements/select/join.md#select-join-types).
- `k1[, k2, ...]` Key columns from the `USING` clause that the `JOIN` operation is made with.

View File

@ -471,7 +471,7 @@ Default value: 0.
See also:
- [JOIN strictness](../../sql-reference/statements/select/join.md#select-join-strictness)
- [JOIN strictness](../../sql-reference/statements/select/join.md#join-settings)
## temporary\_files\_codec {#temporary_files_codec}

View File

@ -11,7 +11,7 @@ Syntax:
``` sql
SELECT <expr_list>
FROM <left_table>
[GLOBAL] [ANY|ALL|ASOF] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI] JOIN <right_table>
[GLOBAL] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI|ANY|ASOF] JOIN <right_table>
(ON <expr_list>)|(USING <column_list>) ...
```
@ -33,17 +33,13 @@ Additional join types available in ClickHouse:
- `LEFT SEMI JOIN` and `RIGHT SEMI JOIN`, a whitelist on “join keys”, without producing a cartesian product.
- `LEFT ANTI JOIN` and `RIGHT ANTI JOIN`, a blacklist on “join keys”, without producing a cartesian product.
- `LEFT ANY JOIN`, `RIGHT ANY JOIN` and `INNER ANY JOIN`, partially (for opposite side of `LEFT` and `RIGHT`) or completely (for `INNER` and `FULL`) disables the cartesian product for standard `JOIN` types.
- `ASOF JOIN` and `LEFT ASOF JOIN`, joining sequences with a non-exact match. `ASOF JOIN` usage is described below.
## Strictness {#select-join-strictness}
Modifies how matching by “join keys” is performed
- `ALL` — The standard `JOIN` behavior in SQL as described above. The default.
- `ANY` — Partially (for opposite side of `LEFT` and `RIGHT`) or completely (for `INNER` and `FULL`) disables the cartesian product for standard `JOIN` types.
- `ASOF` — For joining sequences with a non-exact match. `ASOF JOIN` usage is described below.
## Setting {#join-settings}
!!! note "Note"
The default strictness value can be overriden using [join\_default\_strictness](../../../operations/settings/settings.md#settings-join_default_strictness) setting.
The default join type can be overriden using [join\_default\_strictness](../../../operations/settings/settings.md#settings-join_default_strictness) setting.
Also the behavior of ClickHouse server for `ANY JOIN` operations depends on the [any_join_distinct_right_table_keys](../../../operations/settings/settings.md#any_join_distinct_right_table_keys) setting.

View File

@ -23,7 +23,7 @@ Vea la descripción detallada del [CREATE TABLE](../../../sql-reference/statemen
**Parámetros del motor**
- `join_strictness` [ÚNETE a la rigurosidad](../../../sql-reference/statements/select/join.md#select-join-strictness).
- `join_strictness` [ÚNETE a la rigurosidad](../../../sql-reference/statements/select/join.md#select-join-types).
- `join_type` [Tipo de unión](../../../sql-reference/statements/select/join.md#select-join-types).
- `k1[, k2, ...]` Key columns from the `USING` cláusula que el `JOIN` operación se hace con.

View File

@ -12,7 +12,7 @@ Sintaxis:
``` sql
SELECT <expr_list>
FROM <left_table>
[GLOBAL] [ANY|ALL|ASOF] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI] JOIN <right_table>
[GLOBAL] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI|ANY|ASOF] JOIN <right_table>
(ON <expr_list>)|(USING <column_list>) ...
```
@ -34,14 +34,10 @@ Tipos de unión adicionales disponibles en ClickHouse:
- `LEFT SEMI JOIN` y `RIGHT SEMI JOIN`, una lista blanca en “join keys”, sin producir un producto cartesiano.
- `LEFT ANTI JOIN` y `RIGHT ANTI JOIN`, una lista negra sobre “join keys”, sin producir un producto cartesiano.
- `LEFT ANY JOIN`, `RIGHT ANY JOIN` and `INNER ANY JOIN`, partially (for opposite side of `LEFT` and `RIGHT`) or completely (for `INNER` and `FULL`) disables the cartesian product for standard `JOIN` types.
- `ASOF JOIN` and `LEFT ASOF JOIN`, joining sequences with a non-exact match. `ASOF JOIN` usage is described below.
## Rigor {#select-join-strictness}
Modifica cómo coincidir por “join keys” se realiza
- `ALL` — The standard `JOIN` comportamiento en SQL como se describió anteriormente. Predeterminado.
- `ANY` — Partially (for opposite side of `LEFT` y `RIGHT`) o completamente (para `INNER` y `FULL`) deshabilita el producto cartesiano para `JOIN` tipo.
- `ASOF` — For joining sequences with a non-exact match. `ASOF JOIN` el uso se describe a continuación.
## Setting {#join-settings}
!!! note "Nota"
El valor de rigor predeterminado se puede anular usando [Por favor, introduzca su dirección de correo electrónico](../../../operations/settings/settings.md#settings-join_default_strictness) configuración.

View File

@ -23,7 +23,7 @@ CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
**پارامترهای موتور**
- `join_strictness` [پیوستن به سختی](../../../sql-reference/statements/select/join.md#select-join-strictness).
- `join_strictness` [پیوستن به سختی](../../../sql-reference/statements/select/join.md#select-join-types).
- `join_type` [پیوستن به نوع](../../../sql-reference/statements/select/join.md#select-join-types).
- `k1[, k2, ...]` Key columns from the `USING` بند که `JOIN` عملیات با ساخته شده.

View File

@ -12,7 +12,7 @@ machine_translated_rev: 72537a2d527c63c07aa5d2361a8829f3895cf2bd
``` sql
SELECT <expr_list>
FROM <left_table>
[GLOBAL] [ANY|ALL|ASOF] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI] JOIN <right_table>
[GLOBAL] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI|ANY|ASOF] JOIN <right_table>
(ON <expr_list>)|(USING <column_list>) ...
```
@ -34,15 +34,12 @@ FROM <left_table>
- `LEFT SEMI JOIN` و `RIGHT SEMI JOIN`, یک لیست سفید در “join keys”, بدون تولید محصول دکارتی.
- `LEFT ANTI JOIN` و `RIGHT ANTI JOIN`, لیست سیاه در “join keys”, بدون تولید محصول دکارتی.
- `LEFT ANY JOIN`, `RIGHT ANY JOIN` و `INNER ANY JOIN`, partially (for opposite side of `LEFT` and `RIGHT`) or completely (for `INNER` and `FULL`) disables the cartesian product for standard `JOIN` types.
- `ASOF JOIN` و `LEFT ASOF JOIN`, joining sequences with a non-exact match. `ASOF JOIN` usage is described below.
## سختی {#select-join-strictness}
## Setting {#join-settings}
تغییر چگونگی تطبیق توسط “join keys” انجام شده است
- `ALL` — The standard `JOIN` رفتار در گذاشتن همانطور که در بالا توضیح. به طور پیش فرض.
- `ANY` — Partially (for opposite side of `LEFT` و `RIGHT`) یا به طور کامل (برای `INNER` و `FULL`) غیر فعال محصول دکارتی برای استاندارد `JOIN` انواع.
- `ASOF` — For joining sequences with a non-exact match. `ASOF JOIN` استفاده در زیر توضیح داده شده است.
!!! note "یادداشت"
مقدار سختگیرانه پیش فرض را می توان با استفاده از لغو [بررسی اجمالی](../../../operations/settings/settings.md#settings-join_default_strictness) تنظیمات.

View File

@ -23,7 +23,7 @@ Voir la description détaillée de la [CREATE TABLE](../../../sql-reference/stat
**Les Paramètres Du Moteur**
- `join_strictness` [ADHÉRER à la rigueur](../../../sql-reference/statements/select/join.md#select-join-strictness).
- `join_strictness` [ADHÉRER à la rigueur](../../../sql-reference/statements/select/join.md#select-join-types).
- `join_type` [Type de jointure](../../../sql-reference/statements/select/join.md#select-join-types).
- `k1[, k2, ...]` Key columns from the `USING` la clause que l' `JOIN` l'opération est faite avec de la.

View File

@ -12,7 +12,7 @@ Syntaxe:
``` sql
SELECT <expr_list>
FROM <left_table>
[GLOBAL] [ANY|ALL|ASOF] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI] JOIN <right_table>
[GLOBAL] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI|ANY|ASOF] JOIN <right_table>
(ON <expr_list>)|(USING <column_list>) ...
```
@ -34,14 +34,10 @@ Autres types de jointure disponibles dans ClickHouse:
- `LEFT SEMI JOIN` et `RIGHT SEMI JOIN` une liste blanche sur “join keys”, sans produire un produit cartésien.
- `LEFT ANTI JOIN` et `RIGHT ANTI JOIN` une liste noire sur “join keys”, sans produire un produit cartésien.
- `LEFT ANY JOIN`, `RIGHT ANY JOIN` et `INNER ANY JOIN`, partially (for opposite side of `LEFT` and `RIGHT`) or completely (for `INNER` and `FULL`) disables the cartesian product for standard `JOIN` types.
- `ASOF JOIN` et `LEFT ASOF JOIN`, joining sequences with a non-exact match. `ASOF JOIN` usage is described below.
## Rigueur {#select-join-strictness}
Modifie la façon dont la correspondance par “join keys” est effectué
- `ALL` — The standard `JOIN` comportement en SQL comme décrit ci-dessus. Défaut.
- `ANY` — Partially (for opposite side of `LEFT` et `RIGHT`) ou complètement (pour `INNER` et `FULL`) désactive le produit cartésien de la norme `JOIN` type.
- `ASOF` — For joining sequences with a non-exact match. `ASOF JOIN` l'utilisation est décrite ci-dessous.
## Setting {#join-settings}
!!! note "Note"
La valeur de rigueur par défaut peut être remplacée à l'aide [join\_default\_strictness](../../../operations/settings/settings.md#settings-join_default_strictness) paramètre.

View File

@ -23,7 +23,7 @@ CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
**エンジン変数**
- `join_strictness` [厳密に結合する](../../../sql-reference/statements/select/join.md#select-join-strictness).
- `join_strictness` [厳密に結合する](../../../sql-reference/statements/select/join.md#select-join-types).
- `join_type` [結合タイプ](../../../sql-reference/statements/select/join.md#select-join-types).
- `k1[, k2, ...]` Key columns from the `USING` 句は、 `JOIN` 操作はでなされる。

View File

@ -16,7 +16,7 @@ CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
**Параметры движка**
- `join_strictness` [строгость JOIN](../../../engines/table-engines/special/join.md#select-join-strictness).
- `join_strictness` [строгость JOIN](../../../engines/table-engines/special/join.md#select-join-types).
- `join_type` [тип JOIN](../../../engines/table-engines/special/join.md#select-join-types).
- `k1[, k2, ...]` ключевые столбцы секции `USING` с которыми выполняется операция `JOIN`.

View File

@ -7,7 +7,7 @@ Join создаёт новую таблицу путем объединения
``` sql
SELECT <expr_list>
FROM <left_table>
[GLOBAL] [ANY|ALL|ASOF] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI] JOIN <right_table>
[GLOBAL] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI|ANY|ASOF] JOIN <right_table>
(ON <expr_list>)|(USING <column_list>) ...
```
@ -29,18 +29,14 @@ FROM <left_table>
- `LEFT SEMI JOIN` и `RIGHT SEMI JOIN`, белый список по ключам соединения, не производит декартово произведение.
- `LEFT ANTI JOIN` и `RIGHT ANTI JOIN`, черный список по ключам соединения, не производит декартово произведение.
- `LEFT ANY JOIN`, `RIGHT ANY JOIN` и `INNER ANY JOIN`, Частично (для противоположных сторон `LEFT` и `RIGHT`) или полностью (для `INNER` и `FULL`) отключает декартово произведение для стандартых видов `JOIN`.
- `ASOF JOIN` и `LEFT ASOF JOIN`, Для соединения последовательностей по нечеткому совпадению. Использование `ASOF JOIN` описано ниже.
## Строгость {#select-join-strictness}
Изменяет способ сопоставления по ключам соединения:
- `ALL` — стандартное поведение `JOIN` в SQL, как описано выше. По умолчанию.
- `ANY` — Частично (для противоположных сторон `LEFT` и `RIGHT`) или полностью (для `INNER` и `FULL`) отключает декартово произведение для стандартых видов `JOIN`.
- `ASOF` — Для соединения последовательностей по нечеткому совпадению. Использование `ASOF JOIN` описано ниже.
## Настройки {#join-settings}
!!! note "Примечание"
Значение строгости по умолчанию может быть переопределено с помощью настройки [join\_default\_strictness](../../../operations/settings/settings.md#settings-join_default_strictness).
### Использование ASOF JOIN {#asof-join-usage}
`ASOF JOIN` применим в том случае, когда необходимо объединять записи, которые не имеют точного совпадения.

View File

@ -23,7 +23,7 @@ Ayrıntılııklamasına bakın [CREATE TABLE](../../../sql-reference/statem
**Motor Parametreleri**
- `join_strictness` [Katılık katılın](../../../sql-reference/statements/select/join.md#select-join-strictness).
- `join_strictness` [Katılık katılın](../../../sql-reference/statements/select/join.md#select-join-types).
- `join_type` [Birleştirme türü](../../../sql-reference/statements/select/join.md#select-join-types).
- `k1[, k2, ...]` Key columns from the `USING` fık thera: `JOIN` işlemi yapılmamaktadır.

View File

@ -24,7 +24,7 @@ CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
**引擎参数**
- `join_strictness` [JOIN 限制](../../../sql-reference/statements/select/join.md#select-join-strictness).
- `join_strictness` [JOIN 限制](../../../sql-reference/statements/select/join.md#select-join-types).
- `join_type` [JOIN 类型](../../../sql-reference/statements/select/join.md#select-join-types).
- `k1[, k2, ...]` 进行`JOIN` 操作时 `USING`语句用到的key列

View File

@ -13,7 +13,7 @@ Join通过使用一个或多个表的公共值合并来自一个或多个表的
``` sql
SELECT <expr_list>
FROM <left_table>
[GLOBAL] [ANY|ALL|ASOF] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI] JOIN <right_table>
[GLOBAL] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI|ANY|ASOF] JOIN <right_table>
(ON <expr_list>)|(USING <column_list>) ...
```
@ -35,14 +35,10 @@ ClickHouse中提供的其他联接类型:
- `LEFT SEMI JOIN``RIGHT SEMI JOIN`,白名单 “join keys”而不产生笛卡尔积。
- `LEFT ANTI JOIN``RIGHT ANTI JOIN`,黑名单 “join keys”而不产生笛卡尔积。
- `LEFT ANY JOIN`, `RIGHT ANY JOIN` and `INNER ANY JOIN`, partially (for opposite side of `LEFT` and `RIGHT`) or completely (for `INNER` and `FULL`) disables the cartesian product for standard `JOIN` types.
- `ASOF JOIN` and `LEFT ASOF JOIN`, joining sequences with a non-exact match. `ASOF JOIN` usage is described below.
## 严格 {#select-join-strictness}
修改如何匹配 “join keys” 执行
- `ALL` — The standard `JOIN` sql中的行为如上所述。 默认值。
- `ANY` — Partially (for opposite side of `LEFT``RIGHT`)或完全(为 `INNER``FULL`)禁用笛卡尔积为标准 `JOIN` 类型。
- `ASOF` — For joining sequences with a non-exact match. `ASOF JOIN` 用法描述如下。
## 严格 {#join-settings}
!!! note "注"
可以使用以下方式复盖默认的严格性值 [join\_default\_strictness](../../../operations/settings/settings.md#settings-join_default_strictness) 设置。

View File

@ -39,6 +39,7 @@ namespace ErrorCodes
extern const int INCOMPATIBLE_TYPE_OF_JOIN;
extern const int UNSUPPORTED_JOIN_KEYS;
extern const int LOGICAL_ERROR;
extern const int SYNTAX_ERROR;
extern const int SET_SIZE_LIMIT_EXCEEDED;
extern const int TYPE_MISMATCH;
}
@ -174,7 +175,7 @@ HashJoin::HashJoin(std::shared_ptr<TableJoin> table_join_, const Block & right_s
key_columns.pop_back();
if (key_columns.empty())
throw Exception("ASOF join cannot be done without a joining column", ErrorCodes::LOGICAL_ERROR);
throw Exception("ASOF join cannot be done without a joining column", ErrorCodes::SYNTAX_ERROR);
/// this is going to set up the appropriate hash table for the direct lookup part of the join
/// However, this does not depend on the size of the asof join key (as that goes into the BST)

View File

@ -103,6 +103,20 @@ bool ParserArrayJoin::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
}
void ParserTablesInSelectQueryElement::parseJoinStrictness(Pos & pos, ASTTableJoin & table_join)
{
if (ParserKeyword("ANY").ignore(pos))
table_join.strictness = ASTTableJoin::Strictness::Any;
else if (ParserKeyword("ALL").ignore(pos))
table_join.strictness = ASTTableJoin::Strictness::All;
else if (ParserKeyword("ASOF").ignore(pos))
table_join.strictness = ASTTableJoin::Strictness::Asof;
else if (ParserKeyword("SEMI").ignore(pos))
table_join.strictness = ASTTableJoin::Strictness::Semi;
else if (ParserKeyword("ANTI").ignore(pos) || ParserKeyword("ONLY").ignore(pos))
table_join.strictness = ASTTableJoin::Strictness::Anti;
}
bool ParserTablesInSelectQueryElement::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
auto res = std::make_shared<ASTTablesInSelectQueryElement>();
@ -131,19 +145,12 @@ bool ParserTablesInSelectQueryElement::parseImpl(Pos & pos, ASTPtr & node, Expec
else if (ParserKeyword("LOCAL").ignore(pos))
table_join->locality = ASTTableJoin::Locality::Local;
if (ParserKeyword("ANY").ignore(pos))
table_join->strictness = ASTTableJoin::Strictness::Any;
else if (ParserKeyword("ALL").ignore(pos))
table_join->strictness = ASTTableJoin::Strictness::All;
else if (ParserKeyword("ASOF").ignore(pos))
table_join->strictness = ASTTableJoin::Strictness::Asof;
else if (ParserKeyword("SEMI").ignore(pos))
table_join->strictness = ASTTableJoin::Strictness::Semi;
else if (ParserKeyword("ANTI").ignore(pos) || ParserKeyword("ONLY").ignore(pos))
table_join->strictness = ASTTableJoin::Strictness::Anti;
else
table_join->strictness = ASTTableJoin::Strictness::Unspecified;
table_join->strictness = ASTTableJoin::Strictness::Unspecified;
/// Legacy: allow JOIN type before JOIN kind
parseJoinStrictness(pos, *table_join);
bool no_kind = false;
if (ParserKeyword("INNER").ignore(pos))
table_join->kind = ASTTableJoin::Kind::Inner;
else if (ParserKeyword("LEFT").ignore(pos))
@ -155,6 +162,20 @@ bool ParserTablesInSelectQueryElement::parseImpl(Pos & pos, ASTPtr & node, Expec
else if (ParserKeyword("CROSS").ignore(pos))
table_join->kind = ASTTableJoin::Kind::Cross;
else
no_kind = true;
/// Standard position: JOIN type after JOIN kind
parseJoinStrictness(pos, *table_join);
/// Optional OUTER keyword for outer joins.
if (table_join->kind == ASTTableJoin::Kind::Left
|| table_join->kind == ASTTableJoin::Kind::Right
|| table_join->kind == ASTTableJoin::Kind::Full)
{
ParserKeyword("OUTER").ignore(pos);
}
if (no_kind)
{
/// Use INNER by default as in another DBMS.
if (table_join->strictness == ASTTableJoin::Strictness::Semi ||
@ -172,14 +193,6 @@ bool ParserTablesInSelectQueryElement::parseImpl(Pos & pos, ASTPtr & node, Expec
(table_join->kind != ASTTableJoin::Kind::Left && table_join->kind != ASTTableJoin::Kind::Right))
throw Exception("SEMI|ANTI JOIN should be LEFT or RIGHT.", ErrorCodes::SYNTAX_ERROR);
/// Optional OUTER keyword for outer joins.
if (table_join->kind == ASTTableJoin::Kind::Left
|| table_join->kind == ASTTableJoin::Kind::Right
|| table_join->kind == ASTTableJoin::Kind::Full)
{
ParserKeyword("OUTER").ignore(pos);
}
if (!ParserKeyword("JOIN").ignore(pos, expected))
return false;
}

View File

@ -6,6 +6,8 @@
namespace DB
{
struct ASTTableJoin;
/** List of single or multiple JOIN-ed tables or subqueries in SELECT query, with ARRAY JOINs and SAMPLE, FINAL modifiers.
*/
class ParserTablesInSelectQuery : public IParserBase
@ -27,6 +29,8 @@ protected:
private:
bool is_first;
static void parseJoinStrictness(Pos & pos, ASTTableJoin & table_join);
};

View File

@ -0,0 +1,12 @@
0
0
0
0
0
0
0
0
0
0
0
0

View File

@ -0,0 +1,31 @@
select * from numbers(1) t1 left outer join numbers(1) t2 using number;
select * from numbers(1) t1 right outer join numbers(1) t2 using number;
select * from numbers(1) t1 left any join numbers(1) t2 using number;
select * from numbers(1) t1 right any join numbers(1) t2 using number;
select * from numbers(1) t1 left semi join numbers(1) t2 using number;
select * from numbers(1) t1 right semi join numbers(1) t2 using number;
select * from numbers(1) t1 left anti join numbers(1) t2 using number;
select * from numbers(1) t1 right anti join numbers(1) t2 using number;
select * from numbers(1) t1 asof join numbers(1) t2 using number; -- { serverError 62 }
select * from numbers(1) t1 left asof join numbers(1) t2 using number; -- { serverError 62 }
-- legacy
select * from numbers(1) t1 all left join numbers(1) t2 using number;
select * from numbers(1) t1 all right join numbers(1) t2 using number;
select * from numbers(1) t1 any left join numbers(1) t2 using number;
select * from numbers(1) t1 any right join numbers(1) t2 using number;
select * from numbers(1) t1 semi left join numbers(1) t2 using number;
select * from numbers(1) t1 semi right join numbers(1) t2 using number;
select * from numbers(1) t1 anti left join numbers(1) t2 using number;
select * from numbers(1) t1 anti right join numbers(1) t2 using number;
select * from numbers(1) t1 asof join numbers(1) t2 using number; -- { serverError 62 }
select * from numbers(1) t1 asof left join numbers(1) t2 using number; -- { serverError 62 }