Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
eeab56e3
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
eeab56e3
编写于
6月 22, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: sql command 'select constant'
上级
45a806f7
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
617 addition
and
548 deletion
+617
-548
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+1
-1
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+6
-5
source/libs/parser/src/parCalcConst.c
source/libs/parser/src/parCalcConst.c
+13
-1
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+15
-1
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+530
-527
source/libs/parser/test/parSelectTest.cpp
source/libs/parser/test/parSelectTest.cpp
+6
-0
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+14
-1
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+16
-10
source/libs/planner/src/planPhysiCreater.c
source/libs/planner/src/planPhysiCreater.c
+10
-2
source/libs/planner/test/planBasicTest.cpp
source/libs/planner/test/planBasicTest.cpp
+6
-0
未找到文件。
source/libs/function/src/builtins.c
浏览文件 @
eeab56e3
...
...
@@ -1799,7 +1799,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"last_row"
,
.
type
=
FUNCTION_TYPE_LAST_ROW
,
.
classification
=
FUNC_MGT_MULTI_RES_FUNC
,
.
classification
=
FUNC_MGT_
AGG_FUNC
|
FUNC_MGT_
MULTI_RES_FUNC
,
.
translateFunc
=
translateLastRow
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
initFunc
=
minmaxFunctionSetup
,
...
...
source/libs/parser/inc/sql.y
浏览文件 @
eeab56e3
...
...
@@ -757,8 +757,9 @@ boolean_primary(A) ::= NK_LP(C) boolean_value_expression(B) NK_RP(D).
common_expression(A) ::= expression(B). { A = B; }
common_expression(A) ::= boolean_value_expression(B). { A = B; }
/************************************************ from_clause *********************************************************/
from_clause(A) ::= FROM table_reference_list(B). { A = B; }
/************************************************ from_clause_opt *********************************************************/
from_clause_opt(A) ::= . { A = NULL; }
from_clause_opt(A) ::= FROM table_reference_list(B). { A = B; }
table_reference_list(A) ::= table_reference(B). { A = B; }
table_reference_list(A) ::= table_reference_list(B) NK_COMMA table_reference(C). { A = createJoinTableNode(pCxt, JOIN_TYPE_INNER, B, C, NULL); }
...
...
@@ -792,9 +793,9 @@ join_type(A) ::= INNER.
/************************************************ query_specification *************************************************/
query_specification(A) ::=
SELECT set_quantifier_opt(B) select_list(C) from_clause
(D) where_clause_opt(E
)
partition_by_clause_opt(F) range_opt(J) every_opt(K) fill_opt(L) twindow_clause_opt(G)
group_by_clause_opt(H) having_clause_opt(I).
{
SELECT set_quantifier_opt(B) select_list(C) from_clause
_opt(D
)
where_clause_opt(E) partition_by_clause_opt(F) range_opt(J) every_opt(K)
fill_opt(L) twindow_clause_opt(G) group_by_clause_opt(H) having_clause_opt(I).
{
A = createSelectStmt(pCxt, B, C, D);
A = addWhereClause(pCxt, A, E);
A = addPartitionByClause(pCxt, A, F);
...
...
source/libs/parser/src/parCalcConst.c
浏览文件 @
eeab56e3
...
...
@@ -232,7 +232,11 @@ static int32_t calcConstGroupBy(SCalcConstContext* pCxt, SSelectStmt* pSelect) {
return
code
;
}
static
int32_t
calcConstSelect
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
,
bool
subquery
)
{
static
int32_t
calcConstSelectWithoutFrom
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
,
bool
subquery
)
{
return
calcConstProjections
(
pCxt
,
pSelect
,
subquery
);
}
static
int32_t
calcConstSelectFrom
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
,
bool
subquery
)
{
int32_t
code
=
calcConstFromTable
(
pCxt
,
pSelect
->
pFromTable
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
calcConstProjections
(
pCxt
,
pSelect
,
subquery
);
...
...
@@ -258,6 +262,14 @@ static int32_t calcConstSelect(SCalcConstContext* pCxt, SSelectStmt* pSelect, bo
return
code
;
}
static
int32_t
calcConstSelect
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
,
bool
subquery
)
{
if
(
NULL
==
pSelect
->
pFromTable
)
{
return
calcConstSelectWithoutFrom
(
pCxt
,
pSelect
,
subquery
);
}
else
{
return
calcConstSelectFrom
(
pCxt
,
pSelect
,
subquery
);
}
}
static
int32_t
calcConstDelete
(
SCalcConstContext
*
pCxt
,
SDeleteStmt
*
pDelete
)
{
int32_t
code
=
calcConstFromTable
(
pCxt
,
pDelete
->
pFromTable
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
eeab56e3
...
...
@@ -2466,7 +2466,13 @@ static int32_t replaceOrderByAlias(STranslateContext* pCxt, SNodeList* pProjecti
return
pCxt
->
errCode
;
}
static
int32_t
translateSelect
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
static
int32_t
translateSelectWithoutFrom
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
pCxt
->
pCurrSelectStmt
=
pSelect
;
pCxt
->
currClause
=
SQL_CLAUSE_SELECT
;
return
translateExprList
(
pCxt
,
pSelect
->
pProjectionList
);
}
static
int32_t
translateSelectFrom
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
pCxt
->
pCurrSelectStmt
=
pSelect
;
int32_t
code
=
translateFrom
(
pCxt
,
pSelect
->
pFromTable
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
@@ -2515,6 +2521,14 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) {
return
code
;
}
static
int32_t
translateSelect
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
if
(
NULL
==
pSelect
->
pFromTable
)
{
return
translateSelectWithoutFrom
(
pCxt
,
pSelect
);
}
else
{
return
translateSelectFrom
(
pCxt
,
pSelect
);
}
}
static
SNode
*
createSetOperProject
(
const
char
*
pTableAlias
,
SNode
*
pNode
)
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
nodesMakeNode
(
QUERY_NODE_COLUMN
);
if
(
NULL
==
pCol
)
{
...
...
source/libs/parser/src/sql.c
浏览文件 @
eeab56e3
此差异已折叠。
点击以展开。
source/libs/parser/test/parSelectTest.cpp
浏览文件 @
eeab56e3
...
...
@@ -388,4 +388,10 @@ TEST_F(ParserSelectTest, informationSchema) {
run
(
"SELECT * FROM information_schema.user_databases WHERE name = 'information_schema'"
);
}
TEST_F
(
ParserSelectTest
,
withoutFrom
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT 1"
);
}
}
// namespace ParserTest
source/libs/planner/src/planLogicCreater.c
浏览文件 @
eeab56e3
...
...
@@ -901,7 +901,12 @@ static int32_t createDistinctLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSe
return
code
;
}
static
int32_t
createSelectLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SLogicNode
**
pLogicNode
)
{
static
int32_t
createSelectWithoutFromLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SLogicNode
**
pLogicNode
)
{
return
createProjectLogicNode
(
pCxt
,
pSelect
,
pLogicNode
);
}
static
int32_t
createSelectFromLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SLogicNode
**
pLogicNode
)
{
SLogicNode
*
pRoot
=
NULL
;
int32_t
code
=
createLogicNodeByTable
(
pCxt
,
pSelect
,
pSelect
->
pFromTable
,
&
pRoot
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
@@ -941,6 +946,14 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele
return
code
;
}
static
int32_t
createSelectLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SLogicNode
**
pLogicNode
)
{
if
(
NULL
==
pSelect
->
pFromTable
)
{
return
createSelectWithoutFromLogicNode
(
pCxt
,
pSelect
,
pLogicNode
);
}
else
{
return
createSelectFromLogicNode
(
pCxt
,
pSelect
,
pLogicNode
);
}
}
static
int32_t
createSetOpRootLogicNode
(
SLogicPlanContext
*
pCxt
,
SSetOperator
*
pSetOperator
,
FCreateSetOpLogicNode
func
,
SLogicNode
**
pRoot
)
{
return
createRootLogicNode
(
pCxt
,
pSetOperator
,
pSetOperator
->
precision
,
(
FCreateLogicNode
)
func
,
pRoot
);
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
eeab56e3
...
...
@@ -293,16 +293,22 @@ static int32_t cpdCondAppend(SNode** pCond, SNode** pAdditionalCond) {
return
code
;
}
static
int32_t
cpdCalcTimeRange
(
SScanLogicNode
*
pScan
,
SNode
**
pPrimaryKeyCond
,
SNode
**
pOtherCond
)
{
bool
isStrict
=
false
;
int32_t
code
=
filterGetTimeRange
(
*
pPrimaryKeyCond
,
&
pScan
->
scanRange
,
&
isStrict
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
isStrict
)
{
nodesDestroyNode
(
*
pPrimaryKeyCond
);
}
else
{
code
=
cpdCondAppend
(
pOtherCond
,
pPrimaryKeyCond
);
static
int32_t
cpdCalcTimeRange
(
SOptimizeContext
*
pCxt
,
SScanLogicNode
*
pScan
,
SNode
**
pPrimaryKeyCond
,
SNode
**
pOtherCond
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
pCxt
->
pPlanCxt
->
topicQuery
||
pCxt
->
pPlanCxt
->
streamQuery
)
{
code
=
cpdCondAppend
(
pOtherCond
,
pPrimaryKeyCond
);
}
else
{
bool
isStrict
=
false
;
code
=
filterGetTimeRange
(
*
pPrimaryKeyCond
,
&
pScan
->
scanRange
,
&
isStrict
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
isStrict
)
{
nodesDestroyNode
(
*
pPrimaryKeyCond
);
}
else
{
code
=
cpdCondAppend
(
pOtherCond
,
pPrimaryKeyCond
);
}
*
pPrimaryKeyCond
=
NULL
;
}
*
pPrimaryKeyCond
=
NULL
;
}
return
code
;
}
...
...
@@ -344,7 +350,7 @@ static int32_t cpdOptimizeScanCondition(SOptimizeContext* pCxt, SScanLogicNode*
SNode
*
pOtherCond
=
NULL
;
int32_t
code
=
nodesPartitionCond
(
&
pScan
->
node
.
pConditions
,
&
pPrimaryKeyCond
,
&
pTagCond
,
&
pOtherCond
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pPrimaryKeyCond
)
{
code
=
cpdCalcTimeRange
(
pScan
,
&
pPrimaryKeyCond
,
&
pOtherCond
);
code
=
cpdCalcTimeRange
(
p
Cxt
,
p
Scan
,
&
pPrimaryKeyCond
,
&
pOtherCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pTagCond
)
{
code
=
cpdApplyTagIndex
(
pScan
,
&
pTagCond
,
&
pOtherCond
);
...
...
source/libs/planner/src/planPhysiCreater.c
浏览文件 @
eeab56e3
...
...
@@ -917,8 +917,16 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild
pProject
->
slimit
=
pProjectLogicNode
->
slimit
;
pProject
->
soffset
=
pProjectLogicNode
->
soffset
;
int32_t
code
=
setListSlotId
(
pCxt
,
((
SPhysiNode
*
)
nodesListGetNode
(
pChildren
,
0
))
->
pOutputDataBlockDesc
->
dataBlockId
,
-
1
,
pProjectLogicNode
->
pProjections
,
&
pProject
->
pProjections
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
0
==
LIST_LENGTH
(
pChildren
))
{
pProject
->
pProjections
=
nodesCloneList
(
pProjectLogicNode
->
pProjections
);
if
(
NULL
==
pProject
->
pProjections
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
}
else
{
code
=
setListSlotId
(
pCxt
,
((
SPhysiNode
*
)
nodesListGetNode
(
pChildren
,
0
))
->
pOutputDataBlockDesc
->
dataBlockId
,
-
1
,
pProjectLogicNode
->
pProjections
,
&
pProject
->
pProjections
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
addDataBlockSlotsForProject
(
pCxt
,
pProjectLogicNode
->
stmtName
,
pProject
->
pProjections
,
pProject
->
node
.
pOutputDataBlockDesc
);
...
...
source/libs/planner/test/planBasicTest.cpp
浏览文件 @
eeab56e3
...
...
@@ -95,3 +95,9 @@ TEST_F(PlanBasicTest, lastRowFunc) {
run
(
"SELECT LAST_ROW(c1) FROM st1"
);
}
TEST_F
(
PlanBasicTest
,
withoutFrom
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT 1"
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录