Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c4fcfc05
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看板
提交
c4fcfc05
编写于
7月 30, 2022
作者:
C
cpwu
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' into cpwu/3.0
上级
2164a374
582d7447
变更
31
展开全部
隐藏空白更改
内联
并排
Showing
31 changed file
with
624 addition
and
294 deletion
+624
-294
.gitignore
.gitignore
+4
-0
include/common/tglobal.h
include/common/tglobal.h
+1
-0
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+0
-2
include/libs/scalar/filter.h
include/libs/scalar/filter.h
+4
-0
include/libs/scalar/scalar.h
include/libs/scalar/scalar.h
+3
-3
include/os/osString.h
include/os/osString.h
+2
-0
source/client/src/clientEnv.c
source/client/src/clientEnv.c
+2
-0
source/client/src/clientHb.c
source/client/src/clientHb.c
+1
-0
source/client/src/clientMain.c
source/client/src/clientMain.c
+2
-0
source/common/src/tglobal.c
source/common/src/tglobal.c
+18
-4
source/dnode/mgmt/exe/dmMain.c
source/dnode/mgmt/exe/dmMain.c
+2
-0
source/dnode/mgmt/node_mgmt/src/dmMgmt.c
source/dnode/mgmt/node_mgmt/src/dmMgmt.c
+1
-0
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+3
-0
source/dnode/vnode/src/tsdb/tsdbCommit.c
source/dnode/vnode/src/tsdb/tsdbCommit.c
+2
-0
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+102
-74
source/dnode/vnode/src/tsdb/tsdbUtil.c
source/dnode/vnode/src/tsdb/tsdbUtil.c
+98
-0
source/libs/command/src/command.c
source/libs/command/src/command.c
+7
-0
source/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+7
-0
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+1
-185
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+25
-12
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+51
-4
source/libs/parser/test/parSelectTest.cpp
source/libs/parser/test/parSelectTest.cpp
+2
-0
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+1
-1
source/libs/planner/src/planSpliter.c
source/libs/planner/src/planSpliter.c
+2
-0
source/libs/planner/test/planOrderByTest.cpp
source/libs/planner/test/planOrderByTest.cpp
+2
-0
source/libs/planner/test/planSubqueryTest.cpp
source/libs/planner/test/planSubqueryTest.cpp
+6
-0
source/libs/scalar/src/filter.c
source/libs/scalar/src/filter.c
+192
-0
source/libs/scheduler/src/schJob.c
source/libs/scheduler/src/schJob.c
+1
-1
source/os/src/osString.c
source/os/src/osString.c
+78
-4
tests/script/tsim/parser/condition_query.sim
tests/script/tsim/parser/condition_query.sim
+3
-3
tools/CMakeLists.txt
tools/CMakeLists.txt
+1
-1
未找到文件。
.gitignore
浏览文件 @
c4fcfc05
...
...
@@ -50,6 +50,10 @@ pysim/
tests/script/api/batchprepare
taosadapter
taosadapter-debug
tools/taos-tools/*
tools/taosws-rs/*
tools/taosadapter/*
tools/upx*
# Doxygen Generated files
html/
...
...
include/common/tglobal.h
浏览文件 @
c4fcfc05
...
...
@@ -146,6 +146,7 @@ struct SConfig *taosGetCfg();
void
taosSetAllDebugFlag
(
int32_t
flag
);
void
taosSetDebugFlag
(
int32_t
*
pFlagPtr
,
const
char
*
flagName
,
int32_t
flagVal
);
int32_t
taosSetCfg
(
SConfig
*
pCfg
,
char
*
name
);
void
taosLocalCfgForbiddenToChange
(
char
*
name
,
bool
*
forbidden
);
#ifdef __cplusplus
}
...
...
include/libs/nodes/querynodes.h
浏览文件 @
c4fcfc05
...
...
@@ -418,8 +418,6 @@ void nodesValueNodeToVariant(const SValueNode* pNode, SVariant* pVal);
char
*
nodesGetFillModeString
(
EFillMode
mode
);
int32_t
nodesMergeConds
(
SNode
**
pDst
,
SNodeList
**
pSrc
);
int32_t
nodesPartitionCond
(
SNode
**
pCondition
,
SNode
**
pPrimaryKeyCond
,
SNode
**
pTagIndexCond
,
SNode
**
pTagCond
,
SNode
**
pOtherCond
);
#ifdef __cplusplus
}
...
...
include/libs/scalar/filter.h
浏览文件 @
c4fcfc05
...
...
@@ -46,6 +46,10 @@ extern int32_t filterFreeNcharColumns(SFilterInfo *pFilterInfo);
extern
void
filterFreeInfo
(
SFilterInfo
*
info
);
extern
bool
filterRangeExecute
(
SFilterInfo
*
info
,
SColumnDataAgg
*
pDataStatis
,
int32_t
numOfCols
,
int32_t
numOfRows
);
/* condition split interface */
int32_t
filterPartitionCond
(
SNode
**
pCondition
,
SNode
**
pPrimaryKeyCond
,
SNode
**
pTagIndexCond
,
SNode
**
pTagCond
,
SNode
**
pOtherCond
);
#ifdef __cplusplus
}
#endif
...
...
include/libs/scalar/scalar.h
浏览文件 @
c4fcfc05
...
...
@@ -25,7 +25,7 @@ extern "C" {
typedef
struct
SFilterInfo
SFilterInfo
;
int32_t
scalarGetOperatorResultType
(
SOperatorNode
*
pOp
);
int32_t
scalarGetOperatorResultType
(
SOperatorNode
*
pOp
);
/*
pNode will be freed in API;
...
...
@@ -43,7 +43,7 @@ int32_t scalarGetOperatorParamNum(EOperatorType type);
int32_t
scalarGenerateSetFromList
(
void
**
data
,
void
*
pNode
,
uint32_t
type
);
int32_t
vectorGetConvertType
(
int32_t
type1
,
int32_t
type2
);
int32_t
vectorConvertImpl
(
const
SScalarParam
*
pIn
,
SScalarParam
*
pOut
,
int32_t
*
overflow
);
int32_t
vectorConvertImpl
(
const
SScalarParam
*
pIn
,
SScalarParam
*
pOut
,
int32_t
*
overflow
);
/* Math functions */
int32_t
absFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
...
...
@@ -86,7 +86,7 @@ int32_t nowFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu
int32_t
todayFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
timezoneFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
bool
getTimePseudoFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
getTimePseudoFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
int32_t
winStartTsFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
winEndTsFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
...
...
include/os/osString.h
浏览文件 @
c4fcfc05
...
...
@@ -62,6 +62,8 @@ typedef int32_t TdUcs4;
int32_t
taosUcs4len
(
TdUcs4
*
ucs4
);
int64_t
taosStr2int64
(
const
char
*
str
);
void
taosConvInit
(
void
);
void
taosConvDestroy
();
int32_t
taosUcs4ToMbs
(
TdUcs4
*
ucs4
,
int32_t
ucs4_max_len
,
char
*
mbs
);
bool
taosMbsToUcs4
(
const
char
*
mbs
,
size_t
mbs_len
,
TdUcs4
*
ucs4
,
int32_t
ucs4_max_len
,
int32_t
*
len
);
int32_t
tasoUcs4Compare
(
TdUcs4
*
f1_ucs4
,
TdUcs4
*
f2_ucs4
,
int32_t
bytes
);
...
...
source/client/src/clientEnv.c
浏览文件 @
c4fcfc05
...
...
@@ -361,6 +361,8 @@ void taos_init_imp(void) {
initQueryModuleMsgHandle
();
taosConvInit
();
rpcInit
();
SCatalogCfg
cfg
=
{.
maxDBCacheNum
=
100
,
.
maxTblCacheNum
=
100
};
...
...
source/client/src/clientHb.c
浏览文件 @
c4fcfc05
...
...
@@ -353,6 +353,7 @@ int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) {
desc
.
subDesc
=
NULL
;
desc
.
subPlanNum
=
0
;
}
desc
.
subPlanNum
=
taosArrayGetSize
(
desc
.
subDesc
);
ASSERT
(
desc
.
subPlanNum
==
taosArrayGetSize
(
desc
.
subDesc
));
}
else
{
desc
.
subDesc
=
NULL
;
...
...
source/client/src/clientMain.c
浏览文件 @
c4fcfc05
...
...
@@ -75,6 +75,8 @@ void taos_cleanup(void) {
cleanupTaskQueue
();
taosConvDestroy
();
tscInfo
(
"all local resources released"
);
taosCleanupCfg
();
taosCloseLog
();
...
...
source/common/src/tglobal.c
浏览文件 @
c4fcfc05
...
...
@@ -49,7 +49,7 @@ int32_t tsNumOfShmThreads = 1;
// queue & threads
int32_t
tsNumOfRpcThreads
=
1
;
int32_t
tsNumOfCommitThreads
=
2
;
int32_t
tsNumOfTaskQueueThreads
=
1
;
int32_t
tsNumOfTaskQueueThreads
=
4
;
int32_t
tsNumOfMnodeQueryThreads
=
4
;
int32_t
tsNumOfMnodeFetchThreads
=
1
;
int32_t
tsNumOfMnodeReadThreads
=
1
;
...
...
@@ -317,9 +317,9 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
if
(
cfgAddString
(
pCfg
,
"smlTagName"
,
tsSmlTagName
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddBool
(
pCfg
,
"smlDataFormat"
,
tsSmlDataFormat
,
1
)
!=
0
)
return
-
1
;
tsNumOfTaskQueueThreads
=
tsNumOfCores
/
4
;
tsNumOfTaskQueueThreads
=
T
RANGE
(
tsNumOfTaskQueueThreads
,
1
,
2
);
if
(
cfgAddInt32
(
pCfg
,
"numOfTaskQueueThreads"
,
tsNumOfTaskQueueThreads
,
1
,
1024
,
0
)
!=
0
)
return
-
1
;
tsNumOfTaskQueueThreads
=
tsNumOfCores
/
2
;
tsNumOfTaskQueueThreads
=
T
MAX
(
tsNumOfTaskQueueThreads
,
4
);
if
(
cfgAddInt32
(
pCfg
,
"numOfTaskQueueThreads"
,
tsNumOfTaskQueueThreads
,
4
,
1024
,
0
)
!=
0
)
return
-
1
;
return
0
;
}
...
...
@@ -594,6 +594,20 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
return
0
;
}
void
taosLocalCfgForbiddenToChange
(
char
*
name
,
bool
*
forbidden
)
{
int32_t
len
=
strlen
(
name
);
char
lowcaseName
[
CFG_NAME_MAX_LEN
+
1
]
=
{
0
};
strntolower
(
lowcaseName
,
name
,
TMIN
(
CFG_NAME_MAX_LEN
,
len
));
if
(
strcasecmp
(
"charset"
,
name
)
==
0
)
{
*
forbidden
=
true
;
return
;
}
*
forbidden
=
false
;
}
int32_t
taosSetCfg
(
SConfig
*
pCfg
,
char
*
name
)
{
int32_t
len
=
strlen
(
name
);
char
lowcaseName
[
CFG_NAME_MAX_LEN
+
1
]
=
{
0
};
...
...
source/dnode/mgmt/exe/dmMain.c
浏览文件 @
c4fcfc05
...
...
@@ -218,6 +218,8 @@ int mainWindows(int argc,char** argv) {
taosCleanupArgs
();
return
-
1
;
}
taosConvInit
();
if
(
global
.
dumpConfig
)
{
dmDumpCfg
();
...
...
source/dnode/mgmt/node_mgmt/src/dmMgmt.c
浏览文件 @
c4fcfc05
...
...
@@ -215,6 +215,7 @@ void dmCleanupDnode(SDnode *pDnode) {
dmClearVars
(
pDnode
);
rpcCleanup
();
indexCleanup
();
taosConvDestroy
();
dDebug
(
"dnode is closed, ptr:%p"
,
pDnode
);
}
...
...
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
c4fcfc05
...
...
@@ -90,6 +90,9 @@ int32_t tsdbRowCmprFn(const void *p1, const void *p2);
void
tRowIterInit
(
SRowIter
*
pIter
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
);
SColVal
*
tRowIterNext
(
SRowIter
*
pIter
);
// SRowMerger
int32_t
tRowMergerInit2
(
SRowMerger
*
pMerger
,
STSchema
*
pResTSchema
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
);
int32_t
tRowMergerAdd
(
SRowMerger
*
pMerger
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
);
int32_t
tRowMergerInit
(
SRowMerger
*
pMerger
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
);
void
tRowMergerClear
(
SRowMerger
*
pMerger
);
int32_t
tRowMerge
(
SRowMerger
*
pMerger
,
TSDBROW
*
pRow
);
...
...
source/dnode/vnode/src/tsdb/tsdbCommit.c
浏览文件 @
c4fcfc05
...
...
@@ -311,6 +311,8 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) {
tfsAllocDisk
(
pTsdb
->
pVnode
->
pTfs
,
0
,
&
did
);
tfsMkdirRecurAt
(
pTsdb
->
pVnode
->
pTfs
,
pTsdb
->
path
,
did
);
wSet
.
diskId
=
did
;
wSet
.
fid
=
pCommitter
->
commitFid
;
fHead
=
(
SHeadFile
){.
commitID
=
pCommitter
->
commitID
,
.
offset
=
0
,
.
size
=
0
};
...
...
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
c4fcfc05
此差异已折叠。
点击以展开。
source/dnode/vnode/src/tsdb/tsdbUtil.c
浏览文件 @
c4fcfc05
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tdataformat.h"
#include "tsdb.h"
// SMapData =======================================================================
...
...
@@ -548,6 +549,103 @@ SColVal *tRowIterNext(SRowIter *pIter) {
}
// SRowMerger ======================================================
int32_t
tRowMergerInit2
(
SRowMerger
*
pMerger
,
STSchema
*
pResTSchema
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
)
{
int32_t
code
=
0
;
TSDBKEY
key
=
TSDBROW_KEY
(
pRow
);
SColVal
*
pColVal
=
&
(
SColVal
){
0
};
STColumn
*
pTColumn
;
int32_t
iCol
,
jCol
=
0
;
pMerger
->
pTSchema
=
pResTSchema
;
pMerger
->
version
=
key
.
version
;
pMerger
->
pArray
=
taosArrayInit
(
pResTSchema
->
numOfCols
,
sizeof
(
SColVal
));
if
(
pMerger
->
pArray
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
// ts
pTColumn
=
&
pTSchema
->
columns
[
jCol
++
];
ASSERT
(
pTColumn
->
type
==
TSDB_DATA_TYPE_TIMESTAMP
);
*
pColVal
=
COL_VAL_VALUE
(
pTColumn
->
colId
,
pTColumn
->
type
,
(
SValue
){.
ts
=
key
.
ts
});
if
(
taosArrayPush
(
pMerger
->
pArray
,
pColVal
)
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
// other
for
(
iCol
=
1
;
jCol
<
pTSchema
->
numOfCols
&&
iCol
<
pResTSchema
->
numOfCols
;
++
iCol
)
{
pTColumn
=
&
pResTSchema
->
columns
[
iCol
];
if
(
pTSchema
->
columns
[
jCol
].
colId
<
pTColumn
->
colId
)
{
++
jCol
;
--
iCol
;
continue
;
}
else
if
(
pTSchema
->
columns
[
jCol
].
colId
>
pTColumn
->
colId
)
{
taosArrayPush
(
pMerger
->
pArray
,
&
COL_VAL_NONE
(
pTColumn
->
colId
,
pTColumn
->
type
));
continue
;
}
tsdbRowGetColVal
(
pRow
,
pTSchema
,
jCol
++
,
pColVal
);
if
(
taosArrayPush
(
pMerger
->
pArray
,
pColVal
)
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
}
for
(;
iCol
<
pResTSchema
->
numOfCols
;
++
iCol
)
{
pTColumn
=
&
pResTSchema
->
columns
[
iCol
];
taosArrayPush
(
pMerger
->
pArray
,
&
COL_VAL_NONE
(
pTColumn
->
colId
,
pTColumn
->
type
));
}
_exit:
return
code
;
}
int32_t
tRowMergerAdd
(
SRowMerger
*
pMerger
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
)
{
int32_t
code
=
0
;
TSDBKEY
key
=
TSDBROW_KEY
(
pRow
);
SColVal
*
pColVal
=
&
(
SColVal
){
0
};
STColumn
*
pTColumn
;
int32_t
iCol
,
jCol
=
1
;
ASSERT
(((
SColVal
*
)
pMerger
->
pArray
->
pData
)
->
value
.
ts
==
key
.
ts
);
for
(
iCol
=
1
;
iCol
<
pMerger
->
pTSchema
->
numOfCols
&&
jCol
<
pTSchema
->
numOfCols
;
++
iCol
)
{
pTColumn
=
&
pMerger
->
pTSchema
->
columns
[
iCol
];
if
(
pTSchema
->
columns
[
jCol
].
colId
<
pTColumn
->
colId
)
{
++
jCol
;
--
iCol
;
continue
;
}
else
if
(
pTSchema
->
columns
[
jCol
].
colId
>
pTColumn
->
colId
)
{
continue
;
}
tsdbRowGetColVal
(
pRow
,
pTSchema
,
jCol
++
,
pColVal
);
if
(
key
.
version
>
pMerger
->
version
)
{
if
(
!
pColVal
->
isNone
)
{
taosArraySet
(
pMerger
->
pArray
,
iCol
,
pColVal
);
}
}
else
if
(
key
.
version
<
pMerger
->
version
)
{
SColVal
*
tColVal
=
(
SColVal
*
)
taosArrayGet
(
pMerger
->
pArray
,
iCol
);
if
(
tColVal
->
isNone
&&
!
pColVal
->
isNone
)
{
taosArraySet
(
pMerger
->
pArray
,
iCol
,
pColVal
);
}
}
else
{
ASSERT
(
0
);
}
}
pMerger
->
version
=
key
.
version
;
_exit:
return
code
;
}
int32_t
tRowMergerInit
(
SRowMerger
*
pMerger
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
)
{
int32_t
code
=
0
;
TSDBKEY
key
=
TSDBROW_KEY
(
pRow
);
...
...
source/libs/command/src/command.c
浏览文件 @
c4fcfc05
...
...
@@ -517,6 +517,13 @@ static int32_t execAlterLocal(SAlterLocalStmt* pStmt) {
goto
_return
;
}
bool
forbidden
=
false
;
taosLocalCfgForbiddenToChange
(
pStmt
->
config
,
&
forbidden
);
if
(
forbidden
)
{
terrno
=
TSDB_CODE_OPS_NOT_SUPPORT
;
return
terrno
;
}
if
(
cfgSetItem
(
tsCfg
,
pStmt
->
config
,
pStmt
->
value
,
CFG_STYPE_ALTER_CMD
))
{
return
terrno
;
}
...
...
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
c4fcfc05
...
...
@@ -2684,6 +2684,7 @@ static int32_t jsonToDataType(const SJson* pJson, void* pObj) {
static
const
char
*
jkExprDataType
=
"DataType"
;
static
const
char
*
jkExprAliasName
=
"AliasName"
;
static
const
char
*
jkExprUserAlias
=
"UserAlias"
;
static
int32_t
exprNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SExprNode
*
pNode
=
(
const
SExprNode
*
)
pObj
;
...
...
@@ -2692,6 +2693,9 @@ static int32_t exprNodeToJson(const void* pObj, SJson* pJson) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddStringToObject
(
pJson
,
jkExprAliasName
,
pNode
->
aliasName
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddStringToObject
(
pJson
,
jkExprUserAlias
,
pNode
->
userAlias
);
}
return
code
;
}
...
...
@@ -2703,6 +2707,9 @@ static int32_t jsonToExprNode(const SJson* pJson, void* pObj) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetStringValue
(
pJson
,
jkExprAliasName
,
pNode
->
aliasName
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetStringValue
(
pJson
,
jkExprUserAlias
,
pNode
->
userAlias
);
}
return
code
;
}
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
c4fcfc05
...
...
@@ -1502,7 +1502,7 @@ static EDealRes collectColumns(SNode* pNode, void* pContext) {
SCollectColumnsCxt
*
pCxt
=
(
SCollectColumnsCxt
*
)
pContext
;
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pNode
;
if
(
isCollectType
(
pCxt
->
collectType
,
pCol
->
colType
)
&&
if
(
isCollectType
(
pCxt
->
collectType
,
pCol
->
colType
)
&&
0
!=
strcmp
(
pCol
->
colName
,
"*"
)
&&
(
NULL
==
pCxt
->
pTableAlias
||
0
==
strcmp
(
pCxt
->
pTableAlias
,
pCol
->
tableAlias
)))
{
return
doCollect
(
pCxt
,
pCol
,
pNode
);
}
...
...
@@ -1816,187 +1816,3 @@ int32_t nodesMergeConds(SNode** pDst, SNodeList** pSrc) {
return
TSDB_CODE_SUCCESS
;
}
typedef
struct
SClassifyConditionCxt
{
bool
hasPrimaryKey
;
bool
hasTagIndexCol
;
bool
hasTagCol
;
bool
hasOtherCol
;
}
SClassifyConditionCxt
;
static
EDealRes
classifyConditionImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
SClassifyConditionCxt
*
pCxt
=
(
SClassifyConditionCxt
*
)
pContext
;
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pNode
;
if
(
PRIMARYKEY_TIMESTAMP_COL_ID
==
pCol
->
colId
&&
TSDB_SYSTEM_TABLE
!=
pCol
->
tableType
)
{
pCxt
->
hasPrimaryKey
=
true
;
}
else
if
(
pCol
->
hasIndex
)
{
pCxt
->
hasTagIndexCol
=
true
;
pCxt
->
hasTagCol
=
true
;
}
else
if
(
COLUMN_TYPE_TAG
==
pCol
->
colType
||
COLUMN_TYPE_TBNAME
==
pCol
->
colType
)
{
pCxt
->
hasTagCol
=
true
;
}
else
{
pCxt
->
hasOtherCol
=
true
;
}
}
return
DEAL_RES_CONTINUE
;
}
typedef
enum
EConditionType
{
COND_TYPE_PRIMARY_KEY
=
1
,
COND_TYPE_TAG_INDEX
,
COND_TYPE_TAG
,
COND_TYPE_NORMAL
}
EConditionType
;
static
EConditionType
classifyCondition
(
SNode
*
pNode
)
{
SClassifyConditionCxt
cxt
=
{.
hasPrimaryKey
=
false
,
.
hasTagIndexCol
=
false
,
.
hasOtherCol
=
false
};
nodesWalkExpr
(
pNode
,
classifyConditionImpl
,
&
cxt
);
return
cxt
.
hasOtherCol
?
COND_TYPE_NORMAL
:
(
cxt
.
hasPrimaryKey
&&
cxt
.
hasTagCol
?
COND_TYPE_NORMAL
:
(
cxt
.
hasPrimaryKey
?
COND_TYPE_PRIMARY_KEY
:
(
cxt
.
hasTagIndexCol
?
COND_TYPE_TAG_INDEX
:
COND_TYPE_TAG
)));
}
static
int32_t
partitionLogicCond
(
SNode
**
pCondition
,
SNode
**
pPrimaryKeyCond
,
SNode
**
pTagIndexCond
,
SNode
**
pTagCond
,
SNode
**
pOtherCond
)
{
SLogicConditionNode
*
pLogicCond
=
(
SLogicConditionNode
*
)(
*
pCondition
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
SNodeList
*
pPrimaryKeyConds
=
NULL
;
SNodeList
*
pTagIndexConds
=
NULL
;
SNodeList
*
pTagConds
=
NULL
;
SNodeList
*
pOtherConds
=
NULL
;
SNode
*
pCond
=
NULL
;
FOREACH
(
pCond
,
pLogicCond
->
pParameterList
)
{
switch
(
classifyCondition
(
pCond
))
{
case
COND_TYPE_PRIMARY_KEY
:
if
(
NULL
!=
pPrimaryKeyCond
)
{
code
=
nodesListMakeAppend
(
&
pPrimaryKeyConds
,
nodesCloneNode
(
pCond
));
}
break
;
case
COND_TYPE_TAG_INDEX
:
if
(
NULL
!=
pTagIndexCond
)
{
code
=
nodesListMakeAppend
(
&
pTagIndexConds
,
nodesCloneNode
(
pCond
));
}
if
(
NULL
!=
pTagCond
)
{
code
=
nodesListMakeAppend
(
&
pTagConds
,
nodesCloneNode
(
pCond
));
}
break
;
case
COND_TYPE_TAG
:
if
(
NULL
!=
pTagCond
)
{
code
=
nodesListMakeAppend
(
&
pTagConds
,
nodesCloneNode
(
pCond
));
}
break
;
case
COND_TYPE_NORMAL
:
default:
if
(
NULL
!=
pOtherCond
)
{
code
=
nodesListMakeAppend
(
&
pOtherConds
,
nodesCloneNode
(
pCond
));
}
break
;
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
break
;
}
}
SNode
*
pTempPrimaryKeyCond
=
NULL
;
SNode
*
pTempTagIndexCond
=
NULL
;
SNode
*
pTempTagCond
=
NULL
;
SNode
*
pTempOtherCond
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesMergeConds
(
&
pTempPrimaryKeyCond
,
&
pPrimaryKeyConds
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesMergeConds
(
&
pTempTagIndexCond
,
&
pTagIndexConds
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesMergeConds
(
&
pTempTagCond
,
&
pTagConds
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesMergeConds
(
&
pTempOtherCond
,
&
pOtherConds
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
NULL
!=
pPrimaryKeyCond
)
{
*
pPrimaryKeyCond
=
pTempPrimaryKeyCond
;
}
if
(
NULL
!=
pTagIndexCond
)
{
*
pTagIndexCond
=
pTempTagIndexCond
;
}
if
(
NULL
!=
pTagCond
)
{
*
pTagCond
=
pTempTagCond
;
}
if
(
NULL
!=
pOtherCond
)
{
*
pOtherCond
=
pTempOtherCond
;
}
nodesDestroyNode
(
*
pCondition
);
*
pCondition
=
NULL
;
}
else
{
nodesDestroyList
(
pPrimaryKeyConds
);
nodesDestroyList
(
pTagIndexConds
);
nodesDestroyList
(
pTagConds
);
nodesDestroyList
(
pOtherConds
);
nodesDestroyNode
(
pTempPrimaryKeyCond
);
nodesDestroyNode
(
pTempTagIndexCond
);
nodesDestroyNode
(
pTempTagCond
);
nodesDestroyNode
(
pTempOtherCond
);
}
return
code
;
}
int32_t
nodesPartitionCond
(
SNode
**
pCondition
,
SNode
**
pPrimaryKeyCond
,
SNode
**
pTagIndexCond
,
SNode
**
pTagCond
,
SNode
**
pOtherCond
)
{
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
*
pCondition
)
&&
LOGIC_COND_TYPE_AND
==
((
SLogicConditionNode
*
)
*
pCondition
)
->
condType
)
{
return
partitionLogicCond
(
pCondition
,
pPrimaryKeyCond
,
pTagIndexCond
,
pTagCond
,
pOtherCond
);
}
bool
needOutput
=
false
;
switch
(
classifyCondition
(
*
pCondition
))
{
case
COND_TYPE_PRIMARY_KEY
:
if
(
NULL
!=
pPrimaryKeyCond
)
{
*
pPrimaryKeyCond
=
*
pCondition
;
needOutput
=
true
;
}
break
;
case
COND_TYPE_TAG_INDEX
:
if
(
NULL
!=
pTagIndexCond
)
{
*
pTagIndexCond
=
*
pCondition
;
needOutput
=
true
;
}
if
(
NULL
!=
pTagCond
)
{
SNode
*
pTempCond
=
*
pCondition
;
if
(
NULL
!=
pTagIndexCond
)
{
pTempCond
=
nodesCloneNode
(
*
pCondition
);
if
(
NULL
==
pTempCond
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
*
pTagCond
=
pTempCond
;
needOutput
=
true
;
}
break
;
case
COND_TYPE_TAG
:
if
(
NULL
!=
pTagCond
)
{
*
pTagCond
=
*
pCondition
;
needOutput
=
true
;
}
break
;
case
COND_TYPE_NORMAL
:
default:
if
(
NULL
!=
pOtherCond
)
{
*
pOtherCond
=
*
pCondition
;
needOutput
=
true
;
}
break
;
}
if
(
needOutput
)
{
*
pCondition
=
NULL
;
}
return
TSDB_CODE_SUCCESS
;
}
source/libs/parser/src/parAstCreater.c
浏览文件 @
c4fcfc05
...
...
@@ -233,18 +233,22 @@ SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const
SNode
*
releaseRawExprNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
)
{
CHECK_PARSER_STATUS
(
pCxt
);
SRawExprNode
*
pRawExpr
=
(
SRawExprNode
*
)
pNode
;
SNode
*
pExpr
=
pRawExpr
->
pNode
;
if
(
nodesIsExprNode
(
pExpr
))
{
SNode
*
pRealizedExpr
=
pRawExpr
->
pNode
;
if
(
nodesIsExprNode
(
pRealizedExpr
))
{
SExprNode
*
pExpr
=
(
SExprNode
*
)
pRealizedExpr
;
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pExpr
))
{
strcpy
(((
SExprNode
*
)
pExpr
)
->
aliasName
,
((
SColumnNode
*
)
pExpr
)
->
colName
);
strcpy
(
pExpr
->
aliasName
,
((
SColumnNode
*
)
pExpr
)
->
colName
);
strcpy
(
pExpr
->
userAlias
,
((
SColumnNode
*
)
pExpr
)
->
colName
);
}
else
{
int32_t
len
=
TMIN
(
sizeof
(((
SExprNode
*
)
pExpr
)
->
aliasName
)
-
1
,
pRawExpr
->
n
);
strncpy
(((
SExprNode
*
)
pExpr
)
->
aliasName
,
pRawExpr
->
p
,
len
);
((
SExprNode
*
)
pExpr
)
->
aliasName
[
len
]
=
'\0'
;
int32_t
len
=
TMIN
(
sizeof
(
pExpr
->
aliasName
)
-
1
,
pRawExpr
->
n
);
strncpy
(
pExpr
->
aliasName
,
pRawExpr
->
p
,
len
);
pExpr
->
aliasName
[
len
]
=
'\0'
;
strncpy
(
pExpr
->
userAlias
,
pRawExpr
->
p
,
len
);
pExpr
->
userAlias
[
len
]
=
'\0'
;
}
}
taosMemoryFreeClear
(
pNode
);
return
pExpr
;
return
p
Realized
Expr
;
}
SToken
getTokenFromRawExprNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
)
{
...
...
@@ -641,11 +645,12 @@ SNode* createInterpTimeRange(SAstCreateContext* pCxt, SNode* pStart, SNode* pEnd
SNode
*
setProjectionAlias
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
,
SToken
*
pAlias
)
{
CHECK_PARSER_STATUS
(
pCxt
);
trimEscape
(
pAlias
);
int32_t
len
=
TMIN
(
sizeof
(((
SExprNode
*
)
pNode
)
->
aliasName
)
-
1
,
pAlias
->
n
);
strncpy
(((
SExprNode
*
)
pNode
)
->
aliasName
,
pAlias
->
z
,
len
);
((
SExprNode
*
)
pNode
)
->
aliasName
[
len
]
=
'\0'
;
strncpy
(((
SExprNode
*
)
pNode
)
->
userAlias
,
pAlias
->
z
,
len
);
((
SExprNode
*
)
pNode
)
->
userAlias
[
len
]
=
'\0'
;
SExprNode
*
pExpr
=
(
SExprNode
*
)
pNode
;
int32_t
len
=
TMIN
(
sizeof
(
pExpr
->
aliasName
)
-
1
,
pAlias
->
n
);
strncpy
(
pExpr
->
aliasName
,
pAlias
->
z
,
len
);
pExpr
->
aliasName
[
len
]
=
'\0'
;
strncpy
(
pExpr
->
userAlias
,
pAlias
->
z
,
len
);
pExpr
->
userAlias
[
len
]
=
'\0'
;
return
pNode
;
}
...
...
@@ -766,13 +771,21 @@ SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pPr
return
(
SNode
*
)
select
;
}
static
void
setSubquery
(
SNode
*
pStmt
)
{
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
((
SSelectStmt
*
)
pStmt
)
->
isSubquery
=
true
;
}
}
SNode
*
createSetOperator
(
SAstCreateContext
*
pCxt
,
ESetOperatorType
type
,
SNode
*
pLeft
,
SNode
*
pRight
)
{
CHECK_PARSER_STATUS
(
pCxt
);
SSetOperator
*
setOp
=
(
SSetOperator
*
)
nodesMakeNode
(
QUERY_NODE_SET_OPERATOR
);
CHECK_OUT_OF_MEM
(
setOp
);
setOp
->
opType
=
type
;
setOp
->
pLeft
=
pLeft
;
setSubquery
(
setOp
->
pLeft
);
setOp
->
pRight
=
pRight
;
setSubquery
(
setOp
->
pRight
);
sprintf
(
setOp
->
stmtName
,
"%p"
,
setOp
);
return
(
SNode
*
)
setOp
;
}
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
c4fcfc05
...
...
@@ -523,6 +523,9 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p
if
(
'\0'
==
pCol
->
node
.
aliasName
[
0
])
{
strcpy
(
pCol
->
node
.
aliasName
,
pColSchema
->
name
);
}
if
(
'\0'
==
pCol
->
node
.
userAlias
[
0
])
{
strcpy
(
pCol
->
node
.
userAlias
,
pColSchema
->
name
);
}
pCol
->
tableId
=
pTable
->
pMeta
->
uid
;
pCol
->
tableType
=
pTable
->
pMeta
->
tableType
;
pCol
->
colId
=
pColSchema
->
colId
;
...
...
@@ -549,6 +552,9 @@ static void setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SColum
if
(
'\0'
==
pCol
->
node
.
aliasName
[
0
])
{
strcpy
(
pCol
->
node
.
aliasName
,
pCol
->
colName
);
}
if
(
'\0'
==
pCol
->
node
.
userAlias
[
0
])
{
strcpy
(
pCol
->
node
.
userAlias
,
pCol
->
colName
);
}
pCol
->
node
.
resType
=
pExpr
->
resType
;
}
...
...
@@ -691,7 +697,7 @@ static EDealRes translateColumnUseAlias(STranslateContext* pCxt, SColumnNode** p
SNode
*
pNode
;
FOREACH
(
pNode
,
pProjectionList
)
{
SExprNode
*
pExpr
=
(
SExprNode
*
)
pNode
;
if
(
0
==
strcmp
((
*
pCol
)
->
colName
,
pExpr
->
aliasName
))
{
if
(
0
==
strcmp
((
*
pCol
)
->
colName
,
pExpr
->
userAlias
))
{
SColumnRefNode
*
pColRef
=
(
SColumnRefNode
*
)
nodesMakeNode
(
QUERY_NODE_COLUMN_REF
);
if
(
NULL
==
pColRef
)
{
pCxt
->
errCode
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -1535,6 +1541,7 @@ static EDealRes rewriteColToSelectValFunc(STranslateContext* pCxt, SNode** pNode
}
strcpy
(
pFunc
->
functionName
,
"_select_value"
);
strcpy
(
pFunc
->
node
.
aliasName
,
((
SExprNode
*
)
*
pNode
)
->
aliasName
);
strcpy
(
pFunc
->
node
.
userAlias
,
((
SExprNode
*
)
*
pNode
)
->
userAlias
);
pCxt
->
errCode
=
nodesListMakeAppend
(
&
pFunc
->
pParameterList
,
*
pNode
);
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
)
{
pCxt
->
errCode
=
getFuncInfo
(
pCxt
,
pFunc
);
...
...
@@ -2171,12 +2178,51 @@ static int32_t translateFillValues(STranslateContext* pCxt, SSelectStmt* pSelect
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
rewriteProjectAlias
(
SNodeList
*
pProjectionList
)
{
int32_t
no
=
1
;
SNode
*
pProject
=
NULL
;
FOREACH
(
pProject
,
pProjectionList
)
{
SExprNode
*
pExpr
=
(
SExprNode
*
)
pProject
;
if
(
'\0'
==
pExpr
->
userAlias
[
0
])
{
strcpy
(
pExpr
->
userAlias
,
pExpr
->
aliasName
);
}
sprintf
(
pExpr
->
aliasName
,
"#expr_%d"
,
no
++
);
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
checkProjectAlias
(
STranslateContext
*
pCxt
,
SNodeList
*
pProjectionList
)
{
SHashObj
*
pUserAliasSet
=
taosHashInit
(
LIST_LENGTH
(
pProjectionList
),
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
SNode
*
pProject
=
NULL
;
FOREACH
(
pProject
,
pProjectionList
)
{
SExprNode
*
pExpr
=
(
SExprNode
*
)
pProject
;
if
(
NULL
!=
taosHashGet
(
pUserAliasSet
,
pExpr
->
userAlias
,
strlen
(
pExpr
->
userAlias
)))
{
taosHashCleanup
(
pUserAliasSet
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_AMBIGUOUS_COLUMN
,
pExpr
->
userAlias
);
}
taosHashPut
(
pUserAliasSet
,
pExpr
->
userAlias
,
strlen
(
pExpr
->
userAlias
),
&
pExpr
,
POINTER_BYTES
);
}
taosHashCleanup
(
pUserAliasSet
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateProjectionList
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
if
(
pSelect
->
isSubquery
)
{
return
checkProjectAlias
(
pCxt
,
pSelect
->
pProjectionList
);
}
return
rewriteProjectAlias
(
pSelect
->
pProjectionList
);
}
static
int32_t
translateSelectList
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
pCxt
->
currClause
=
SQL_CLAUSE_SELECT
;
int32_t
code
=
translateExprList
(
pCxt
,
pSelect
->
pProjectionList
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
translateStar
(
pCxt
,
pSelect
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
translateProjectionList
(
pCxt
,
pSelect
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkExprListForGroupBy
(
pCxt
,
pSelect
,
pSelect
->
pProjectionList
);
}
...
...
@@ -2232,7 +2278,7 @@ static int32_t getQueryTimeRange(STranslateContext* pCxt, SNode* pWhere, STimeWi
}
SNode
*
pPrimaryKeyCond
=
NULL
;
nodes
PartitionCond
(
&
pCond
,
&
pPrimaryKeyCond
,
NULL
,
NULL
,
NULL
);
filter
PartitionCond
(
&
pCond
,
&
pPrimaryKeyCond
,
NULL
,
NULL
,
NULL
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
NULL
!=
pPrimaryKeyCond
)
{
...
...
@@ -2699,6 +2745,7 @@ static SNode* createSetOperProject(const char* pTableAlias, SNode* pNode) {
strcpy
(
pCol
->
tableAlias
,
pTableAlias
);
strcpy
(
pCol
->
colName
,
((
SExprNode
*
)
pNode
)
->
aliasName
);
strcpy
(
pCol
->
node
.
aliasName
,
pCol
->
colName
);
strcpy
(
pCol
->
node
.
userAlias
,
((
SExprNode
*
)
pNode
)
->
userAlias
);
return
(
SNode
*
)
pCol
;
}
...
...
@@ -2810,7 +2857,7 @@ static int32_t partitionDeleteWhere(STranslateContext* pCxt, SDeleteStmt* pDelet
SNode
*
pPrimaryKeyCond
=
NULL
;
SNode
*
pOtherCond
=
NULL
;
int32_t
code
=
nodes
PartitionCond
(
&
pDelete
->
pWhere
,
&
pPrimaryKeyCond
,
NULL
,
&
pDelete
->
pTagCond
,
&
pOtherCond
);
int32_t
code
=
filter
PartitionCond
(
&
pDelete
->
pWhere
,
&
pPrimaryKeyCond
,
NULL
,
&
pDelete
->
pTagCond
,
&
pOtherCond
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pOtherCond
)
{
code
=
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_DELETE_WHERE
);
}
...
...
@@ -4983,7 +5030,7 @@ static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) {
SNode
*
pCurrStmt
=
pCxt
->
pCurrStmt
;
int32_t
currLevel
=
pCxt
->
currLevel
;
pCxt
->
currLevel
=
++
(
pCxt
->
levelNo
);
int32_t
code
=
translateQuery
(
pCxt
,
pNode
);
int32_t
code
=
translateQuery
(
pCxt
,
pNode
);
pCxt
->
currClause
=
currClause
;
pCxt
->
pCurrStmt
=
pCurrStmt
;
pCxt
->
currLevel
=
currLevel
;
...
...
source/libs/parser/test/parSelectTest.cpp
浏览文件 @
c4fcfc05
...
...
@@ -70,6 +70,8 @@ TEST_F(ParserSelectTest, condition) {
run
(
"SELECT c1 FROM t1 WHERE NOT ts in (true, false)"
);
run
(
"SELECT * FROM t1 WHERE c1 > 10 and c1 is not null"
);
run
(
"SELECT * FROM t1 WHERE TBNAME like 'fda%' or TS > '2021-05-05 18:19:01.000'"
);
}
TEST_F
(
ParserSelectTest
,
pseudoColumn
)
{
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
c4fcfc05
...
...
@@ -436,7 +436,7 @@ static int32_t pushDownCondOptDealScan(SOptimizeContext* pCxt, SScanLogicNode* p
SNode
*
pPrimaryKeyCond
=
NULL
;
SNode
*
pOtherCond
=
NULL
;
int32_t
code
=
nodes
PartitionCond
(
&
pScan
->
node
.
pConditions
,
&
pPrimaryKeyCond
,
&
pScan
->
pTagIndexCond
,
&
pScan
->
pTagCond
,
int32_t
code
=
filter
PartitionCond
(
&
pScan
->
node
.
pConditions
,
&
pPrimaryKeyCond
,
&
pScan
->
pTagIndexCond
,
&
pScan
->
pTagCond
,
&
pOtherCond
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pScan
->
pTagCond
)
{
code
=
pushDownCondOptRebuildTbanme
(
&
pScan
->
pTagCond
);
...
...
source/libs/planner/src/planSpliter.c
浏览文件 @
c4fcfc05
...
...
@@ -763,6 +763,8 @@ static SNode* stbSplCreateColumnNode(SExprNode* pExpr) {
return
NULL
;
}
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pExpr
))
{
strcpy
(
pCol
->
dbName
,
((
SColumnNode
*
)
pExpr
)
->
dbName
);
strcpy
(
pCol
->
tableName
,
((
SColumnNode
*
)
pExpr
)
->
tableName
);
strcpy
(
pCol
->
tableAlias
,
((
SColumnNode
*
)
pExpr
)
->
tableAlias
);
}
strcpy
(
pCol
->
colName
,
pExpr
->
aliasName
);
...
...
source/libs/planner/test/planOrderByTest.cpp
浏览文件 @
c4fcfc05
...
...
@@ -39,6 +39,8 @@ TEST_F(PlanOrderByTest, expr) {
useDb
(
"root"
,
"test"
);
run
(
"SELECT * FROM t1 ORDER BY c1 + 10, c2"
);
run
(
"SELECT c1 FROM st1 ORDER BY ts, _C0"
);
}
TEST_F
(
PlanOrderByTest
,
nullsOrder
)
{
...
...
source/libs/planner/test/planSubqueryTest.cpp
浏览文件 @
c4fcfc05
...
...
@@ -73,3 +73,9 @@ TEST_F(PlanSubqeuryTest, outerInterval) {
run
(
"SELECT COUNT(*) FROM (SELECT ts, TOP(c1, 10) FROM st1s1) INTERVAL(5s)"
);
}
TEST_F
(
PlanSubqeuryTest
,
outerPartition
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT c1, COUNT(*) FROM (SELECT ts, c1 FROM st1) PARTITION BY c1"
);
}
source/libs/scalar/src/filter.c
浏览文件 @
c4fcfc05
...
...
@@ -22,6 +22,7 @@
#include "tcompare.h"
#include "tdatablock.h"
#include "ttime.h"
#include "functionMgt.h"
OptrStr
gOptrStr
[]
=
{
{
0
,
"invalid"
},
...
...
@@ -3877,4 +3878,195 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnData
}
typedef
struct
SClassifyConditionCxt
{
bool
hasPrimaryKey
;
bool
hasTagIndexCol
;
bool
hasTagCol
;
bool
hasOtherCol
;
}
SClassifyConditionCxt
;
static
EDealRes
classifyConditionImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
SClassifyConditionCxt
*
pCxt
=
(
SClassifyConditionCxt
*
)
pContext
;
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pNode
;
if
(
PRIMARYKEY_TIMESTAMP_COL_ID
==
pCol
->
colId
&&
TSDB_SYSTEM_TABLE
!=
pCol
->
tableType
)
{
pCxt
->
hasPrimaryKey
=
true
;
}
else
if
(
pCol
->
hasIndex
)
{
pCxt
->
hasTagIndexCol
=
true
;
pCxt
->
hasTagCol
=
true
;
}
else
if
(
COLUMN_TYPE_TAG
==
pCol
->
colType
||
COLUMN_TYPE_TBNAME
==
pCol
->
colType
)
{
pCxt
->
hasTagCol
=
true
;
}
else
{
pCxt
->
hasOtherCol
=
true
;
}
}
else
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
))
{
SFunctionNode
*
pFunc
=
(
SFunctionNode
*
)
pNode
;
if
(
fmIsPseudoColumnFunc
(
pFunc
->
funcId
))
{
if
(
FUNCTION_TYPE_TBNAME
==
pFunc
->
funcType
)
{
pCxt
->
hasTagCol
=
true
;
}
else
{
pCxt
->
hasOtherCol
=
true
;
}
}
}
return
DEAL_RES_CONTINUE
;
}
typedef
enum
EConditionType
{
COND_TYPE_PRIMARY_KEY
=
1
,
COND_TYPE_TAG_INDEX
,
COND_TYPE_TAG
,
COND_TYPE_NORMAL
}
EConditionType
;
static
EConditionType
classifyCondition
(
SNode
*
pNode
)
{
SClassifyConditionCxt
cxt
=
{.
hasPrimaryKey
=
false
,
.
hasTagIndexCol
=
false
,
.
hasOtherCol
=
false
};
nodesWalkExpr
(
pNode
,
classifyConditionImpl
,
&
cxt
);
return
cxt
.
hasOtherCol
?
COND_TYPE_NORMAL
:
(
cxt
.
hasPrimaryKey
&&
cxt
.
hasTagCol
?
COND_TYPE_NORMAL
:
(
cxt
.
hasPrimaryKey
?
COND_TYPE_PRIMARY_KEY
:
(
cxt
.
hasTagIndexCol
?
COND_TYPE_TAG_INDEX
:
COND_TYPE_TAG
)));
}
static
int32_t
partitionLogicCond
(
SNode
**
pCondition
,
SNode
**
pPrimaryKeyCond
,
SNode
**
pTagIndexCond
,
SNode
**
pTagCond
,
SNode
**
pOtherCond
)
{
SLogicConditionNode
*
pLogicCond
=
(
SLogicConditionNode
*
)(
*
pCondition
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
SNodeList
*
pPrimaryKeyConds
=
NULL
;
SNodeList
*
pTagIndexConds
=
NULL
;
SNodeList
*
pTagConds
=
NULL
;
SNodeList
*
pOtherConds
=
NULL
;
SNode
*
pCond
=
NULL
;
FOREACH
(
pCond
,
pLogicCond
->
pParameterList
)
{
switch
(
classifyCondition
(
pCond
))
{
case
COND_TYPE_PRIMARY_KEY
:
if
(
NULL
!=
pPrimaryKeyCond
)
{
code
=
nodesListMakeAppend
(
&
pPrimaryKeyConds
,
nodesCloneNode
(
pCond
));
}
break
;
case
COND_TYPE_TAG_INDEX
:
if
(
NULL
!=
pTagIndexCond
)
{
code
=
nodesListMakeAppend
(
&
pTagIndexConds
,
nodesCloneNode
(
pCond
));
}
if
(
NULL
!=
pTagCond
)
{
code
=
nodesListMakeAppend
(
&
pTagConds
,
nodesCloneNode
(
pCond
));
}
break
;
case
COND_TYPE_TAG
:
if
(
NULL
!=
pTagCond
)
{
code
=
nodesListMakeAppend
(
&
pTagConds
,
nodesCloneNode
(
pCond
));
}
break
;
case
COND_TYPE_NORMAL
:
default:
if
(
NULL
!=
pOtherCond
)
{
code
=
nodesListMakeAppend
(
&
pOtherConds
,
nodesCloneNode
(
pCond
));
}
break
;
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
break
;
}
}
SNode
*
pTempPrimaryKeyCond
=
NULL
;
SNode
*
pTempTagIndexCond
=
NULL
;
SNode
*
pTempTagCond
=
NULL
;
SNode
*
pTempOtherCond
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesMergeConds
(
&
pTempPrimaryKeyCond
,
&
pPrimaryKeyConds
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesMergeConds
(
&
pTempTagIndexCond
,
&
pTagIndexConds
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesMergeConds
(
&
pTempTagCond
,
&
pTagConds
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesMergeConds
(
&
pTempOtherCond
,
&
pOtherConds
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
NULL
!=
pPrimaryKeyCond
)
{
*
pPrimaryKeyCond
=
pTempPrimaryKeyCond
;
}
if
(
NULL
!=
pTagIndexCond
)
{
*
pTagIndexCond
=
pTempTagIndexCond
;
}
if
(
NULL
!=
pTagCond
)
{
*
pTagCond
=
pTempTagCond
;
}
if
(
NULL
!=
pOtherCond
)
{
*
pOtherCond
=
pTempOtherCond
;
}
nodesDestroyNode
(
*
pCondition
);
*
pCondition
=
NULL
;
}
else
{
nodesDestroyList
(
pPrimaryKeyConds
);
nodesDestroyList
(
pTagIndexConds
);
nodesDestroyList
(
pTagConds
);
nodesDestroyList
(
pOtherConds
);
nodesDestroyNode
(
pTempPrimaryKeyCond
);
nodesDestroyNode
(
pTempTagIndexCond
);
nodesDestroyNode
(
pTempTagCond
);
nodesDestroyNode
(
pTempOtherCond
);
}
return
code
;
}
int32_t
filterPartitionCond
(
SNode
**
pCondition
,
SNode
**
pPrimaryKeyCond
,
SNode
**
pTagIndexCond
,
SNode
**
pTagCond
,
SNode
**
pOtherCond
)
{
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
*
pCondition
)
&&
LOGIC_COND_TYPE_AND
==
((
SLogicConditionNode
*
)
*
pCondition
)
->
condType
)
{
return
partitionLogicCond
(
pCondition
,
pPrimaryKeyCond
,
pTagIndexCond
,
pTagCond
,
pOtherCond
);
}
bool
needOutput
=
false
;
switch
(
classifyCondition
(
*
pCondition
))
{
case
COND_TYPE_PRIMARY_KEY
:
if
(
NULL
!=
pPrimaryKeyCond
)
{
*
pPrimaryKeyCond
=
*
pCondition
;
needOutput
=
true
;
}
break
;
case
COND_TYPE_TAG_INDEX
:
if
(
NULL
!=
pTagIndexCond
)
{
*
pTagIndexCond
=
*
pCondition
;
needOutput
=
true
;
}
if
(
NULL
!=
pTagCond
)
{
SNode
*
pTempCond
=
*
pCondition
;
if
(
NULL
!=
pTagIndexCond
)
{
pTempCond
=
nodesCloneNode
(
*
pCondition
);
if
(
NULL
==
pTempCond
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
*
pTagCond
=
pTempCond
;
needOutput
=
true
;
}
break
;
case
COND_TYPE_TAG
:
if
(
NULL
!=
pTagCond
)
{
*
pTagCond
=
*
pCondition
;
needOutput
=
true
;
}
break
;
case
COND_TYPE_NORMAL
:
default:
if
(
NULL
!=
pOtherCond
)
{
*
pOtherCond
=
*
pCondition
;
needOutput
=
true
;
}
break
;
}
if
(
needOutput
)
{
*
pCondition
=
NULL
;
}
return
TSDB_CODE_SUCCESS
;
}
source/libs/scheduler/src/schJob.c
浏览文件 @
c4fcfc05
...
...
@@ -278,7 +278,7 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) {
}
SHashObj
*
planToTask
=
taosHashInit
(
SCHEDULE_DEFAULT_MAX_TASK_NUM
,
pDag
->
numOfSubplans
,
taosGetDefaultHashFunction
(
POINTER_BYTES
==
sizeof
(
int64_t
)
?
TSDB_DATA_TYPE_BIGINT
:
TSDB_DATA_TYPE_INT
),
false
,
HASH_NO_LOCK
);
if
(
NULL
==
planToTask
)
{
...
...
source/os/src/osString.c
浏览文件 @
c4fcfc05
...
...
@@ -134,21 +134,95 @@ int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs) {
#endif
}
typedef
struct
{
iconv_t
conv
;
int8_t
inUse
;
}
SConv
;
SConv
*
gConv
=
NULL
;
int32_t
convUsed
=
0
;
int32_t
gConvMaxNum
=
0
;
void
taosConvInit
(
void
)
{
gConvMaxNum
=
512
;
gConv
=
taosMemoryCalloc
(
gConvMaxNum
,
sizeof
(
SConv
));
for
(
int32_t
i
=
0
;
i
<
gConvMaxNum
;
++
i
)
{
gConv
[
i
].
conv
=
iconv_open
(
DEFAULT_UNICODE_ENCODEC
,
tsCharset
);
if
((
iconv_t
)
-
1
==
gConv
[
i
].
conv
||
(
iconv_t
)
0
==
gConv
[
i
].
conv
)
{
ASSERT
(
0
);
}
}
}
void
taosConvDestroy
()
{
for
(
int32_t
i
=
0
;
i
<
gConvMaxNum
;
++
i
)
{
iconv_close
(
gConv
[
i
].
conv
);
}
taosMemoryFreeClear
(
gConv
);
gConvMaxNum
=
-
1
;
}
iconv_t
taosAcquireConv
(
int32_t
*
idx
)
{
if
(
gConvMaxNum
<=
0
)
{
*
idx
=
-
1
;
return
iconv_open
(
DEFAULT_UNICODE_ENCODEC
,
tsCharset
);
}
while
(
true
)
{
int32_t
used
=
atomic_add_fetch_32
(
&
convUsed
,
1
);
if
(
used
>
gConvMaxNum
)
{
used
=
atomic_sub_fetch_32
(
&
convUsed
,
1
);
sched_yield
();
continue
;
}
break
;
}
int32_t
startId
=
taosGetSelfPthreadId
()
%
gConvMaxNum
;
while
(
true
)
{
if
(
gConv
[
startId
].
inUse
)
{
startId
=
(
startId
+
1
)
%
gConvMaxNum
;
continue
;
}
int8_t
old
=
atomic_val_compare_exchange_8
(
&
gConv
[
startId
].
inUse
,
0
,
1
);
if
(
0
==
old
)
{
break
;
}
}
*
idx
=
startId
;
return
gConv
[
startId
].
conv
;
}
void
taosReleaseConv
(
int32_t
idx
,
iconv_t
conv
)
{
if
(
idx
<
0
)
{
iconv_close
(
conv
);
return
;
}
atomic_store_8
(
&
gConv
[
idx
].
inUse
,
0
);
atomic_sub_fetch_32
(
&
convUsed
,
1
);
}
bool
taosMbsToUcs4
(
const
char
*
mbs
,
size_t
mbsLength
,
TdUcs4
*
ucs4
,
int32_t
ucs4_max_len
,
int32_t
*
len
)
{
#ifdef DISALLOW_NCHAR_WITHOUT_ICONV
printf
(
"Nchar cannot be read and written without iconv, please install iconv library and recompile TDengine.
\n
"
);
return
-
1
;
#else
memset
(
ucs4
,
0
,
ucs4_max_len
);
iconv_t
cd
=
iconv_open
(
DEFAULT_UNICODE_ENCODEC
,
tsCharset
);
int32_t
idx
=
-
1
;
iconv_t
conv
=
taosAcquireConv
(
&
idx
);
size_t
ucs4_input_len
=
mbsLength
;
size_t
outLeft
=
ucs4_max_len
;
if
(
iconv
(
c
d
,
(
char
**
)
&
mbs
,
&
ucs4_input_len
,
(
char
**
)
&
ucs4
,
&
outLeft
)
==
-
1
)
{
iconv_close
(
cd
);
if
(
iconv
(
c
onv
,
(
char
**
)
&
mbs
,
&
ucs4_input_len
,
(
char
**
)
&
ucs4
,
&
outLeft
)
==
-
1
)
{
taosReleaseConv
(
idx
,
conv
);
return
false
;
}
iconv_close
(
cd
);
taosReleaseConv
(
idx
,
conv
);
if
(
len
!=
NULL
)
{
*
len
=
(
int32_t
)(
ucs4_max_len
-
outLeft
);
if
(
*
len
<
0
)
{
...
...
tests/script/tsim/parser/condition_query.sim
浏览文件 @
c4fcfc05
...
...
@@ -2631,7 +2631,7 @@ sql_error select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts or
print "ts&tbname test"
sql
_error
select count(*) from stb1 where ts > 0 or tbname like 'tb%';
sql select count(*) from stb1 where ts > 0 or tbname like 'tb%';
print "ts&tag test"
sql select count(*) from stb1 where ts > 0 or t1 > 0;
...
...
@@ -2717,9 +2717,9 @@ print "tbname&tag&join test"
print "column&ts&tbname&tag test"
sql
_error
select * from stb1 where (tbname like 'tb%' or ts > '2021-05-05 18:19:01.000') and (t1 > 5 or t1 < 4) and c1 > 0;
sql select * from stb1 where (tbname like 'tb%' or ts > '2021-05-05 18:19:01.000') and (t1 > 5 or t1 < 4) and c1 > 0;
sql select * from stb1 where (ts > '2021-05-05 18:19:01.000') and (ts > '2021-05-05 18:19:02.000' or t1 > 3) and (t1 > 5 or t1 < 4) and c1 > 0;
sql
_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:20.000' and col
> 0 and t1 > 0;
sql
select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:20.000' and c1
> 0 and t1 > 0;
print "column&ts&tbname&join test"
...
...
tools/CMakeLists.txt
浏览文件 @
c4fcfc05
...
...
@@ -112,7 +112,7 @@ ELSE ()
COMMAND CGO_CFLAGS=-I
${
CMAKE_CURRENT_SOURCE_DIR
}
/../include/client CGO_LDFLAGS=-L
${
CMAKE_BINARY_DIR
}
/build/lib go build -a -ldflags
"-s -w -X github.com/taosdata/taosadapter/version.Version=
${
taos_version
}
-X github.com/taosdata/taosadapter/version.CommitID=
${
taosadapter_commit_sha1
}
"
COMMAND CGO_CFLAGS=-I
${
CMAKE_CURRENT_SOURCE_DIR
}
/../include/client CGO_LDFLAGS=-L
${
CMAKE_BINARY_DIR
}
/build/lib go build -a -o taosadapter-debug -ldflags
"-X github.com/taosdata/taosadapter/version.Version=
${
taos_version
}
-X github.com/taosdata/taosadapter/version.CommitID=
${
taosadapter_commit_sha1
}
"
INSTALL_COMMAND
COMMAND wget -c https://github.com/upx/upx/releases/download/v3.96/upx-3.96-
${
PLATFORM_ARCH_STR
}
_linux.tar.xz -O
$
{
CMAKE_CURRENT_SOURCE_DIR
}
/upx.tar.xz && tar -xvJf
${
CMAKE_CURRENT_SOURCE_DIR
}
/upx.tar.xz -C
${
CMAKE_CURRENT_SOURCE_DIR
}
--strip-components 1 > /dev/null &&
${
CMAKE_CURRENT_SOURCE_DIR
}
/upx taosadapter || :
COMMAND wget -c https://github.com/upx/upx/releases/download/v3.96/upx-3.96-
${
PLATFORM_ARCH_STR
}
_linux.tar.xz -O $
ENV{HOME}/upx.tar.xz && tar -xvJf $ENV{HOME}/upx.tar.xz -C $ENV{HOME}/ --strip-components 1 > /dev/null && $ENV{HOME
}/upx taosadapter || :
COMMAND cmake -E copy taosadapter
${
CMAKE_BINARY_DIR
}
/build/bin
COMMAND cmake -E make_directory
${
CMAKE_BINARY_DIR
}
/test/cfg/
COMMAND cmake -E copy ./example/config/taosadapter.toml
${
CMAKE_BINARY_DIR
}
/test/cfg/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录