diff --git a/dbms/tests/queries/0_stateless/01009_insert_select_nicelulu.reference b/dbms/tests/queries/0_stateless/01009_insert_select_nicelulu.reference new file mode 100644 index 00000000000..ccdf6eb3297 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01009_insert_select_nicelulu.reference @@ -0,0 +1 @@ +1189 diff --git a/dbms/tests/queries/0_stateless/01009_insert_select_nicelulu.sql b/dbms/tests/queries/0_stateless/01009_insert_select_nicelulu.sql new file mode 100644 index 00000000000..90a902c352d --- /dev/null +++ b/dbms/tests/queries/0_stateless/01009_insert_select_nicelulu.sql @@ -0,0 +1,24 @@ +Set any_join_distinct_right_table_keys=1; +DROP TABLE IF EXISTS test_insert_t1; +DROP TABLE IF EXISTS test_insert_t2; +DROP TABLE IF EXISTS test_insert_t3; + +CREATE TABLE test_insert_t1 (`dt` Date, `uid` String, `name` String, `city` String) ENGINE = MergeTree PARTITION BY toYYYYMMDD(dt) ORDER BY name SETTINGS index_granularity = 8192; +CREATE TABLE test_insert_t2 (`dt` Date, `uid` String) ENGINE = MergeTree PARTITION BY toYYYYMMDD(dt) ORDER BY uid SETTINGS index_granularity = 8192; +CREATE TABLE test_insert_t3 (`dt` Date, `uid` String, `name` String, `city` String) ENGINE = MergeTree PARTITION BY toYYYYMMDD(dt) ORDER BY name SETTINGS index_granularity = 8192; + +INSERT INTO test_insert_t1 SELECT '2019-09-01',toString(number),toString(rand()),toString(rand()) FROM system.numbers WHERE number > 10 limit 1000000; +INSERT INTO test_insert_t2 SELECT '2019-09-01',toString(number) FROM system.numbers WHERE number >=0 limit 200; +INSERT INTO test_insert_t2 SELECT '2019-09-01',toString(number) FROM system.numbers WHERE number >=100000 limit 200; +INSERT INTO test_insert_t2 SELECT '2019-09-01',toString(number) FROM system.numbers WHERE number >=300000 limit 200; +INSERT INTO test_insert_t2 SELECT '2019-09-01',toString(number) FROM system.numbers WHERE number >=500000 limit 200; +INSERT INTO test_insert_t2 SELECT '2019-09-01',toString(number) FROM system.numbers WHERE number >=700000 limit 200; +INSERT INTO test_insert_t2 SELECT '2019-09-01',toString(number) FROM system.numbers WHERE number >=900000 limit 200; + +INSERT INTO test_insert_t3 SELECT '2019-09-01', uid, name, city FROM ( SELECT dt, uid, name, city FROM test_insert_t1 WHERE dt = '2019-09-01') t1 GLOBAL ANY INNER JOIN (SELECT uid FROM test_insert_t2 WHERE dt = '2019-09-01') t2 ON t1.uid=t2.uid; + +SELECT count(*) FROM test_insert_t3; + +DROP TABLE test_insert_t1; +DROP TABLE test_insert_t2; +DROP TABLE test_insert_t3; diff --git a/docs/en/operations/settings/permissions_for_queries.md b/docs/en/operations/settings/permissions_for_queries.md index ee080edbae1..892e1cdd9ea 100644 --- a/docs/en/operations/settings/permissions_for_queries.md +++ b/docs/en/operations/settings/permissions_for_queries.md @@ -21,7 +21,7 @@ Restricts permissions for read data, write data and change settings queries. See how the queries are divided into types [above](#permissions_for_queries). -**Possible values** +Possible values: - 0 — All queries are allowed. - 1 — Only read data queries are allowed. @@ -34,25 +34,21 @@ When using the `GET` method in the [HTTP interface](../../interfaces/http.md), ` Setting `readonly = 1` prohibit the user from changing all the settings. There is a way to prohibit the user from changing only specific settings, for details see [constraints on settings](constraints_on_settings.md). -**Default value** - -0 +Default value: 0 ## allow_ddl {#settings_allow_ddl} -Allows/denies [DDL](https://en.wikipedia.org/wiki/Data_definition_language) queries. +Allows or denies [DDL](https://en.wikipedia.org/wiki/Data_definition_language) queries. See how the queries are divided into types [above](#permissions_for_queries). -**Possible values** +Possible values: - 0 — DDL queries are not allowed. - 1 — DDL queries are allowed. -You cannot execute `SET allow_ddl = 1` if `allow_ddl = 0` for the current session. +You can't execute `SET allow_ddl = 1` if `allow_ddl = 0` for the current session. -**Default value** - -1 +Default value: 1 [Original article](https://clickhouse.yandex/docs/en/operations/settings/permissions_for_queries/) diff --git a/docs/en/query_language/create.md b/docs/en/query_language/create.md index 7133b125ae2..20790ffb834 100644 --- a/docs/en/query_language/create.md +++ b/docs/en/query_language/create.md @@ -1,3 +1,5 @@ +# CREATE Queries + ## CREATE DATABASE {#query_language-create-database} Creates database. @@ -56,7 +58,7 @@ Creates a table with the same structure as another table. You can specify a diff CREATE TABLE [IF NOT EXISTS] [db.]table_name AS table_fucntion() ``` -Creates a table with the same structure and data as the value returned by table function. +Creates a table with the structure and data returned by a [table function](table_functions/index.md). ``` sql CREATE TABLE [IF NOT EXISTS] [db.]table_name ENGINE = engine AS SELECT ... @@ -151,8 +153,8 @@ If a codec is specified, the default codec doesn't apply. Codecs can be combined Compression is supported for the table engines: -- [*MergeTree](../operations/table_engines/mergetree.md) family -- [*Log](../operations/table_engines/log_family.md) family +- [MergeTree](../operations/table_engines/mergetree.md) family +- [Log](../operations/table_engines/log_family.md) family - [Set](../operations/table_engines/set.md) - [Join](../operations/table_engines/join.md) diff --git a/docs/en/query_language/select.md b/docs/en/query_language/select.md index 657467c7937..afa2df73c3d 100644 --- a/docs/en/query_language/select.md +++ b/docs/en/query_language/select.md @@ -92,23 +92,26 @@ FROM ``` -### FROM Clause +### FROM Clause {#select-from} If the FROM clause is omitted, data will be read from the `system.one` table. -The 'system.one' table contains exactly one row (this table fulfills the same purpose as the DUAL table found in other DBMSs). +The `system.one` table contains exactly one row (this table fulfills the same purpose as the DUAL table found in other DBMSs). -The FROM clause specifies the table to read data from, or a subquery, or a table function; ARRAY JOIN and the regular JOIN may also be included (see below). +The `FROM` clause specifies the source to read data from: -Instead of a table, the SELECT subquery may be specified in brackets. -In this case, the subquery processing pipeline will be built into the processing pipeline of an external query. -In contrast to standard SQL, a synonym does not need to be specified after a subquery. For compatibility, it is possible to write 'AS name' after a subquery, but the specified name isn't used anywhere. +- Table +- Subquery +- [Table function](table_functions/index.md) -A table function may be specified instead of a table. For more information, see the section "Table functions". +`ARRAY JOIN` and the regular `JOIN` may also be included (see below). + +Instead of a table, the `SELECT` subquery may be specified in parenthesis. +In contrast to standard SQL, a synonym does not need to be specified after a subquery. For compatibility, it is possible to write `AS name` after a subquery, but the specified name isn't used anywhere. To execute a query, all the columns listed in the query are extracted from the appropriate table. Any columns not needed for the external query are thrown out of the subqueries. -If a query does not list any columns (for example, SELECT count() FROM t), some column is extracted from the table anyway (the smallest one is preferred), in order to calculate the number of rows. +If a query does not list any columns (for example, `SELECT count() FROM t`), some column is extracted from the table anyway (the smallest one is preferred), in order to calculate the number of rows. -The FINAL modifier can be used only for a SELECT from ReplacingMergeTree, SummingMergeTree, AggregatingMergeTree, CollapsingMergeTree and VersionedCollapsingMergeTree tables. When you specify FINAL, data is selected fully "merged". Keep in mind that using FINAL leads to a selection that includes columns related to the primary key, in addition to the columns specified in the SELECT. Additionally, the query will be executed in a single stream, and data will be merged during query execution. This means that when using FINAL, the query is processed more slowly. In most cases, you should avoid using FINAL. +The `FINAL` modifier can be used in the `SELECT` select query for aggregating engines from the [MergeTree](../operations/table_engines/mergetree.md) family. When you specify `FINAL`, data is selected fully "merged". Keep in mind that using `FINAL` leads to a selection that includes columns related to the primary key, in addition to the columns specified in the `SELECT`. Additionally, the query will be executed in a single stream, and data will be merged during query execution. This means that when using `FINAL`, the query is processed slowly. In the most cases, avoid using `FINAL`. ### SAMPLE Clause {#select-sample-clause} diff --git a/docs/en/query_language/table_functions/index.md b/docs/en/query_language/table_functions/index.md index f694c5e3518..dc2665ce7a5 100644 --- a/docs/en/query_language/table_functions/index.md +++ b/docs/en/query_language/table_functions/index.md @@ -1,8 +1,30 @@ -# Table functions +# Table Functions -Table functions can be specified in the FROM clause instead of the database and table names. -Table functions can only be used if 'readonly' is not set. -Table functions aren't related to other functions. +Table function is a method of constructing a table. +You can use table functions in: + +* [CREATE TABLE AS ](../create.md#create-table-query) query. + + It's one of the methods of creating a table. + +* [FROM](../select.md#select-from) clause of the `SELECT` query. + + The method of creating a temporary table, that is available only in current query. The table is deleted after the query finishes. + +!!! warning "Warning" + You can't use table functions if the [allow_ddl](../../operations/settings/permissions_for_queries.md#settings_allow_ddl) setting is disabled. + +Function | Description +---------|------------ +[file](file.md) | Creates a [File](../../operations/table_engines/file.md)-engine table. +[merge](merge.md) | Creates a [Merge](../../operations/table_engines/merge.md)-engine table. +[numbers](numbers.md) | Creates a table with the single column filled with integer numbers. +[remote](remote.md) | Allows you to access remote servers without creating a [Distributed](../../operations/table_engines/distributed.md)-engine table. +[url](url.md) | Creates a [Url](../../operations/table_engines/url.md)-engine table. +[mysql](mysql.md) | Creates a [MySQL](../../operations/table_engines/mysql.md)-engine table. +[jdbc](jdbc.md) | Creates a [JDBC](../../operations/table_engines/jdbc.md)-engine table. +[odbc](odbc.md) | Creates a [ODBC](../../operations/table_engines/odbc.md)-engine table. +[hdfs](hdfs.md) | Creates a [HDFS](../../operations/table_engines/hdfs.md)-engine table. [Original article](https://clickhouse.yandex/docs/en/query_language/table_functions/) diff --git a/docs/fa/operations/table_engines/hdfs.md b/docs/fa/operations/table_engines/hdfs.md new file mode 120000 index 00000000000..d4dbfa46e68 --- /dev/null +++ b/docs/fa/operations/table_engines/hdfs.md @@ -0,0 +1 @@ +../../../en/operations/table_engines/hdfs.md \ No newline at end of file diff --git a/docs/fa/query_language/table_functions/hdfs.md b/docs/fa/query_language/table_functions/hdfs.md new file mode 120000 index 00000000000..2616e737eb6 --- /dev/null +++ b/docs/fa/query_language/table_functions/hdfs.md @@ -0,0 +1 @@ +../../../en/query_language/table_functions/hdfs.md \ No newline at end of file diff --git a/docs/fa/query_language/table_functions/input.md b/docs/fa/query_language/table_functions/input.md new file mode 120000 index 00000000000..f23cc8ee673 --- /dev/null +++ b/docs/fa/query_language/table_functions/input.md @@ -0,0 +1 @@ +../../../en/query_language/table_functions/input.md \ No newline at end of file diff --git a/docs/toc_fa.yml b/docs/toc_fa.yml index 1799093df24..b35ead655f7 100644 --- a/docs/toc_fa.yml +++ b/docs/toc_fa.yml @@ -87,6 +87,7 @@ nav: - 'MySQL': 'operations/table_engines/mysql.md' - 'JDBC': 'operations/table_engines/jdbc.md' - 'ODBC': 'operations/table_engines/odbc.md' + - 'HDFS': 'operations/table_engines/hdfs.md' - 'Special': - 'Distributed': 'operations/table_engines/distributed.md' - 'External data': 'operations/table_engines/external_data.md' @@ -158,6 +159,8 @@ nav: - 'mysql': 'query_language/table_functions/mysql.md' - 'jdbc': 'query_language/table_functions/jdbc.md' - 'odbc': 'query_language/table_functions/odbc.md' + - 'hdfs': 'query_language/table_functions/hdfs.md' + - 'input': 'query_language/table_functions/input.md' - 'Dictionaries': - 'Introduction': 'query_language/dicts/index.md' - 'External Dictionaries': diff --git a/docs/toc_zh.yml b/docs/toc_zh.yml index d140ec88d64..d0d73cea636 100644 --- a/docs/toc_zh.yml +++ b/docs/toc_zh.yml @@ -86,6 +86,7 @@ nav: - 'MySQL': 'operations/table_engines/mysql.md' - 'JDBC': 'operations/table_engines/jdbc.md' - 'ODBC': 'operations/table_engines/odbc.md' + - 'HDFS': 'operations/table_engines/hdfs.md' - '其他表引擎': - 'Distributed': 'operations/table_engines/distributed.md' - 'External data': 'operations/table_engines/external_data.md' @@ -157,6 +158,8 @@ nav: - 'mysql': 'query_language/table_functions/mysql.md' - 'jdbc': 'query_language/table_functions/jdbc.md' - 'odbc': 'query_language/table_functions/odbc.md' + - 'hdfs': 'query_language/table_functions/hdfs.md' + - 'input': 'query_language/table_functions/input.md' - '字典': - '介绍': 'query_language/dicts/index.md' - '外部字典': diff --git a/docs/zh/operations/table_engines/hdfs.md b/docs/zh/operations/table_engines/hdfs.md new file mode 120000 index 00000000000..d4dbfa46e68 --- /dev/null +++ b/docs/zh/operations/table_engines/hdfs.md @@ -0,0 +1 @@ +../../../en/operations/table_engines/hdfs.md \ No newline at end of file diff --git a/docs/zh/query_language/select.md b/docs/zh/query_language/select.md index 4c819db1507..589215ea545 100644 --- a/docs/zh/query_language/select.md +++ b/docs/zh/query_language/select.md @@ -26,7 +26,7 @@ SELECT [DISTINCT] expr_list 如果查询中不包含`DISTINCT`,`GROUP BY`,`ORDER BY`子句以及`IN`和`JOIN`子查询,那么它将仅使用O(1)数量的内存来完全流式的处理查询 否则,这个查询将消耗大量的内存,除非你指定了这些系统配置:`max_memory_usage`, `max_rows_to_group_by`, `max_rows_to_sort`, `max_rows_in_distinct`, `max_bytes_in_distinct`, `max_rows_in_set`, `max_bytes_in_set`, `max_rows_in_join`, `max_bytes_in_join`, `max_bytes_before_external_sort`, `max_bytes_before_external_group_by`。它们规定了可以使用外部排序(将临时表存储到磁盘中)以及外部聚合,`目前系统不存在关于Join的配置`,更多关于它们的信息,可以参见“配置”部分。 -### FROM 子句 +### FROM 子句 {#select-from} 如果查询中不包含FROM子句,那么将读取`system.one`。 `system.one`中仅包含一行数据(此表实现了与其他数据库管理系统中的DUAL相同的功能)。 diff --git a/docs/zh/query_language/table_functions/hdfs.md b/docs/zh/query_language/table_functions/hdfs.md new file mode 120000 index 00000000000..2616e737eb6 --- /dev/null +++ b/docs/zh/query_language/table_functions/hdfs.md @@ -0,0 +1 @@ +../../../en/query_language/table_functions/hdfs.md \ No newline at end of file diff --git a/docs/zh/query_language/table_functions/input.md b/docs/zh/query_language/table_functions/input.md new file mode 120000 index 00000000000..f23cc8ee673 --- /dev/null +++ b/docs/zh/query_language/table_functions/input.md @@ -0,0 +1 @@ +../../../en/query_language/table_functions/input.md \ No newline at end of file