Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
7978ae63
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
7978ae63
编写于
11月 03, 2020
作者:
A
alexey-milovidov
提交者:
GitHub
11月 03, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16619 from ClickHouse/settings-early-apply
Apply SETTINGS clause earlier
上级
268c8052
878fd466
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
79 addition
and
13 deletion
+79
-13
src/Interpreters/executeQuery.cpp
src/Interpreters/executeQuery.cpp
+28
-13
tests/queries/0_stateless/01553_settings_early_apply.reference
.../queries/0_stateless/01553_settings_early_apply.reference
+43
-0
tests/queries/0_stateless/01553_settings_early_apply.sql
tests/queries/0_stateless/01553_settings_early_apply.sql
+8
-0
未找到文件。
src/Interpreters/executeQuery.cpp
浏览文件 @
7978ae63
...
...
@@ -17,6 +17,7 @@
#include <Parsers/ASTInsertQuery.h>
#include <Parsers/ASTSelectQuery.h>
#include <Parsers/ASTSelectWithUnionQuery.h>
#include <Parsers/ASTShowProcesslistQuery.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTLiteral.h>
...
...
@@ -337,6 +338,27 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
/// TODO Parser should fail early when max_query_size limit is reached.
ast
=
parseQuery
(
parser
,
begin
,
end
,
""
,
max_query_size
,
settings
.
max_parser_depth
);
/// Interpret SETTINGS clauses as early as possible (before invoking the corresponding interpreter),
/// to allow settings to take effect.
if
(
const
auto
*
select_query
=
ast
->
as
<
ASTSelectQuery
>
())
{
if
(
auto
new_settings
=
select_query
->
settings
())
InterpreterSetQuery
(
new_settings
,
context
).
executeForCurrentContext
();
}
else
if
(
const
auto
*
select_with_union_query
=
ast
->
as
<
ASTSelectWithUnionQuery
>
())
{
if
(
!
select_with_union_query
->
list_of_selects
->
children
.
empty
())
{
if
(
auto
new_settings
=
select_with_union_query
->
list_of_selects
->
children
.
back
()
->
as
<
ASTSelectQuery
>
()
->
settings
())
InterpreterSetQuery
(
new_settings
,
context
).
executeForCurrentContext
();
}
}
else
if
(
const
auto
*
query_with_output
=
dynamic_cast
<
const
ASTQueryWithOutput
*>
(
ast
.
get
()))
{
if
(
query_with_output
->
settings_ast
)
InterpreterSetQuery
(
query_with_output
->
settings_ast
,
context
).
executeForCurrentContext
();
}
auto
*
insert_query
=
ast
->
as
<
ASTInsertQuery
>
();
if
(
insert_query
&&
insert_query
->
settings_ast
)
...
...
@@ -802,12 +824,12 @@ BlockIO executeQuery(
}
BlockIO
executeQuery
(
const
String
&
query
,
Context
&
context
,
bool
internal
,
QueryProcessingStage
::
Enum
stage
,
bool
may_have_embedded_data
,
bool
allow_processors
)
const
String
&
query
,
Context
&
context
,
bool
internal
,
QueryProcessingStage
::
Enum
stage
,
bool
may_have_embedded_data
,
bool
allow_processors
)
{
BlockIO
res
=
executeQuery
(
query
,
context
,
internal
,
stage
,
may_have_embedded_data
);
...
...
@@ -876,7 +898,6 @@ void executeQuery(
}
else
if
(
streams
.
in
)
{
/// FIXME: try to prettify this cast using `as<>()`
const
auto
*
ast_query_with_output
=
dynamic_cast
<
const
ASTQueryWithOutput
*>
(
ast
.
get
());
WriteBuffer
*
out_buf
=
&
ostr
;
...
...
@@ -895,9 +916,6 @@ void executeQuery(
?
getIdentifierName
(
ast_query_with_output
->
format
)
:
context
.
getDefaultFormat
();
if
(
ast_query_with_output
&&
ast_query_with_output
->
settings_ast
)
InterpreterSetQuery
(
ast_query_with_output
->
settings_ast
,
context
).
executeForCurrentContext
();
BlockOutputStreamPtr
out
=
context
.
getOutputFormat
(
format_name
,
*
out_buf
,
streams
.
in
->
getHeader
());
/// Save previous progress callback if any. TODO Do it more conveniently.
...
...
@@ -936,9 +954,6 @@ void executeQuery(
?
getIdentifierName
(
ast_query_with_output
->
format
)
:
context
.
getDefaultFormat
();
if
(
ast_query_with_output
&&
ast_query_with_output
->
settings_ast
)
InterpreterSetQuery
(
ast_query_with_output
->
settings_ast
,
context
).
executeForCurrentContext
();
if
(
!
pipeline
.
isCompleted
())
{
pipeline
.
addSimpleTransform
([](
const
Block
&
header
)
...
...
tests/queries/0_stateless/01553_settings_early_apply.reference
0 → 100644
浏览文件 @
7978ae63
number
0
number
1
0
1
2
3
4
5
6
7
8
9
{
"meta":
[
{
"name": "number",
"type": "UInt64"
}
],
"data":
[
["0"],
["1"],
["2"],
["3"],
["4"],
["5"],
["6"],
["7"],
["8"],
["9"]
],
"rows": 10,
"rows_before_limit_at_least": 10
}
tests/queries/0_stateless/01553_settings_early_apply.sql
0 → 100644
浏览文件 @
7978ae63
select
*
from
numbers
(
100
)
settings
max_result_rows
=
1
;
-- { serverError 396 }
select
*
from
numbers
(
100
)
FORMAT
JSON
settings
max_result_rows
=
1
;
-- { serverError 396 }
SET
max_result_rows
=
1
;
select
*
from
numbers
(
10
);
-- { serverError 396 }
select
*
from
numbers
(
10
)
SETTINGS
result_overflow_mode
=
'break'
,
max_block_size
=
1
FORMAT
PrettySpaceNoEscapes
;
select
*
from
numbers
(
10
)
settings
max_result_rows
=
10
;
select
*
from
numbers
(
10
)
FORMAT
JSONCompact
settings
max_result_rows
=
10
,
output_format_write_statistics
=
0
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录