Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
56a9115e
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
56a9115e
编写于
10月 27, 2021
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize json length
上级
c2f3328e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
13 deletion
+51
-13
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+27
-3
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+24
-10
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
56a9115e
...
...
@@ -3999,8 +3999,17 @@ static int32_t checkAndSetJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tS
return
checkAndSetJoinCondInfo
(
pCmd
,
pQueryInfo
,
pExpr
->
pRight
);
}
tSqlExpr
*
pLeft
=
pExpr
->
pLeft
;
tSqlExpr
*
pRight
=
pExpr
->
pRight
;
if
(
pLeft
->
tokenId
==
TK_ARROW
){
pLeft
=
pLeft
->
pLeft
;
}
if
(
pRight
->
tokenId
==
TK_ARROW
){
pRight
=
pRight
->
pLeft
;
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
p
Expr
->
p
Left
->
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pLeft
->
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
...
...
@@ -4034,7 +4043,7 @@ static int32_t checkAndSetJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tS
int16_t
leftIdx
=
index
.
tableIndex
;
index
=
(
SColumnIndex
)
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
p
Expr
->
p
Right
->
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pRight
->
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
...
...
@@ -4293,8 +4302,23 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr
const
char
*
msg3
=
"join column must have same type"
;
const
char
*
msg4
=
"self join is not allowed"
;
const
char
*
msg5
=
"join table must be the same type(table to table, super table to super table)"
;
const
char
*
msg6
=
"tag json key must be string"
;
const
char
*
msg7
=
"tag json key in json must be same"
;
tSqlExpr
*
pRight
=
pExpr
->
pRight
;
if
(
pRight
->
tokenId
==
TK_ARROW
){
if
(
!
IS_VAR_DATA_TYPE
(
pExpr
->
pLeft
->
pRight
->
value
.
nType
)
||
pExpr
->
pLeft
->
pRight
->
value
.
nType
!=
pExpr
->
pRight
->
pRight
->
value
.
nType
){
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
return
false
;
}
if
(
pExpr
->
pLeft
->
pRight
->
value
.
nLen
!=
pExpr
->
pRight
->
pRight
->
value
.
nLen
||
strncmp
(
pExpr
->
pLeft
->
pRight
->
value
.
pz
,
pExpr
->
pRight
->
pRight
->
value
.
pz
,
pExpr
->
pRight
->
pRight
->
value
.
nLen
)
!=
0
){
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
return
false
;
}
pRight
=
pExpr
->
pRight
->
pLeft
;
}
if
(
pRight
->
tokenId
!=
TK_ID
)
{
return
true
;
...
...
@@ -4648,7 +4672,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql
}
}
if
(
pRight
!=
NULL
&&
pRight
->
tokenId
==
TK_ID
)
{
// join on tag columns for stable query
if
(
pRight
!=
NULL
&&
(
pRight
->
tokenId
==
TK_ID
||
pRight
->
tokenId
==
TK_ARROW
)
)
{
// join on tag columns for stable query
if
(
!
validateJoinExprNode
(
pCmd
,
pQueryInfo
,
*
pExpr
,
&
index
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
src/query/src/qExecutor.c
浏览文件 @
56a9115e
...
...
@@ -137,6 +137,14 @@ do { \
} \
} while (0)
#define GET_JSON_KEY(exprInfo) \
char* param = NULL; \
int32_t paramLen = 0; \
if(exprInfo->base.numOfParams > 0){ \
param = exprInfo->base.param[0].pz; \
paramLen = exprInfo->base.param[0].nLen; \
}
uint64_t
queryHandleId
=
0
;
int32_t
getMaximumIdleDurationSec
()
{
...
...
@@ -3047,7 +3055,7 @@ void filterColRowsInDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SSDataBlock* pBlock
static
SColumnInfo
*
doGetTagColumnInfoById
(
SColumnInfo
*
pTagColList
,
int32_t
numOfTags
,
int16_t
colId
);
static
void
doSetTagValueInParam
(
void
*
pTable
,
int32_t
tagColId
,
tVariant
*
tag
,
int16_t
type
,
int16_t
bytes
);
static
void
doSetTagValueInParam
(
void
*
pTable
,
char
*
param
,
int32_t
paraLen
,
int32_t
tagColId
,
tVariant
*
tag
,
int16_t
type
,
int16_t
bytes
);
static
uint32_t
doFilterByBlockTimeWindow
(
STableScanInfo
*
pTableScanInfo
,
SSDataBlock
*
pBlock
)
{
SQLFunctionCtx
*
pCtx
=
pTableScanInfo
->
pCtx
;
...
...
@@ -3129,7 +3137,8 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
// compare tag first
tVariant
t
=
{
0
};
doSetTagValueInParam
(
pRuntimeEnv
->
current
->
pTable
,
tagId
,
&
t
,
pColInfo
->
type
,
pColInfo
->
bytes
);
GET_JSON_KEY
(
pExprInfo
)
doSetTagValueInParam
(
pRuntimeEnv
->
current
->
pTable
,
param
,
paramLen
,
tagId
,
&
t
,
pColInfo
->
type
,
pColInfo
->
bytes
);
setTimestampListJoinInfo
(
pRuntimeEnv
,
&
t
,
pRuntimeEnv
->
current
);
STSElem
elem
=
tsBufGetElem
(
pRuntimeEnv
->
pTsBuf
);
...
...
@@ -3336,7 +3345,7 @@ int32_t binarySearchForKey(char *pValue, int num, TSKEY key, int order) {
* set tag value in SQLFunctionCtx
* e.g.,tag information into input buffer
*/
static
void
doSetTagValueInParam
(
void
*
pTable
,
int32_t
tagColId
,
tVariant
*
tag
,
int16_t
type
,
int16_t
bytes
)
{
static
void
doSetTagValueInParam
(
void
*
pTable
,
char
*
param
,
int32_t
paramLen
,
int32_t
tagColId
,
tVariant
*
tag
,
int16_t
type
,
int16_t
bytes
)
{
tVariantDestroy
(
tag
);
char
*
val
=
NULL
;
...
...
@@ -3359,10 +3368,13 @@ static void doSetTagValueInParam(void* pTable, int32_t tagColId, tVariant *tag,
//tVariantCreateFromBinary(tag, varDataVal(val), varDataLen(val), type);
}
else
if
(
type
==
TSDB_DATA_TYPE_JSON
){
char
jsonVal
[
TSDB_MAX_JSON_TAGS_LEN
]
=
{
0
};
getJsonTagValueAll
(
val
,
jsonVal
,
TSDB_MAX_JSON_TAGS_LEN
);
if
(
param
&&
paramLen
>
0
){
getJsonTagValueElment
(
pTable
,
param
,
paramLen
,
jsonVal
,
bytes
);
}
else
{
getJsonTagValueAll
(
val
,
jsonVal
,
TSDB_MAX_JSON_TAGS_LEN
);
}
tVariantCreateFromBinary
(
tag
,
jsonVal
,
varDataTLen
(
jsonVal
),
type
);
}
else
{
}
else
{
tVariantCreateFromBinary
(
tag
,
val
,
bytes
,
type
);
}
}
...
...
@@ -3391,8 +3403,8 @@ void setTagValue(SOperatorInfo* pOperatorInfo, void *pTable, SQLFunctionCtx* pCt
int16_t
tagColId
=
(
int16_t
)
pExprInfo
->
base
.
param
[
0
].
i64
;
SColumnInfo
*
pColInfo
=
doGetTagColumnInfoById
(
pQueryAttr
->
tagColList
,
pQueryAttr
->
numOfTags
,
tagColId
);
doSetTagValueInParam
(
pTable
,
tagColId
,
&
pCtx
[
0
].
tag
,
pColInfo
->
type
,
pColInfo
->
bytes
);
GET_JSON_KEY
(
pExprInfo
)
doSetTagValueInParam
(
pTable
,
param
,
paramLen
,
tagColId
,
&
pCtx
[
0
].
tag
,
pColInfo
->
type
,
pColInfo
->
bytes
);
return
;
}
else
{
// set tag value, by which the results are aggregated.
...
...
@@ -3408,7 +3420,8 @@ void setTagValue(SOperatorInfo* pOperatorInfo, void *pTable, SQLFunctionCtx* pCt
}
// todo use tag column index to optimize performance
doSetTagValueInParam
(
pTable
,
pLocalExprInfo
->
base
.
colInfo
.
colId
,
&
pCtx
[
idx
].
tag
,
pLocalExprInfo
->
base
.
resType
,
GET_JSON_KEY
(
pLocalExprInfo
)
doSetTagValueInParam
(
pTable
,
param
,
paramLen
,
pLocalExprInfo
->
base
.
colInfo
.
colId
,
&
pCtx
[
idx
].
tag
,
pLocalExprInfo
->
base
.
resType
,
pLocalExprInfo
->
base
.
resBytes
);
if
(
IS_NUMERIC_TYPE
(
pLocalExprInfo
->
base
.
resType
)
...
...
@@ -4011,7 +4024,8 @@ void setCtxTagForJoin(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx, SExpr
int16_t
tagColId
=
(
int16_t
)
pExprInfo
->
base
.
param
[
0
].
i64
;
SColumnInfo
*
pColInfo
=
doGetTagColumnInfoById
(
pQueryAttr
->
tagColList
,
pQueryAttr
->
numOfTags
,
tagColId
);
doSetTagValueInParam
(
pTable
,
tagColId
,
&
pCtx
->
tag
,
pColInfo
->
type
,
pColInfo
->
bytes
);
GET_JSON_KEY
(
pExprInfo
)
doSetTagValueInParam
(
pTable
,
param
,
paramLen
,
tagColId
,
&
pCtx
->
tag
,
pColInfo
->
type
,
pColInfo
->
bytes
);
int16_t
tagType
=
pCtx
[
0
].
tag
.
nType
;
if
(
tagType
==
TSDB_DATA_TYPE_BINARY
||
tagType
==
TSDB_DATA_TYPE_NCHAR
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录