Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
~笨蛋陪你哭
TDengine
提交
dfd365f0
T
TDengine
项目概览
~笨蛋陪你哭
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
dfd365f0
编写于
4月 01, 2021
作者:
H
haojun Liao
提交者:
GitHub
4月 01, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5643 from taosdata/feature/qrefactor
[td-225]fix a invalid read.
上级
f167bd6c
b74d5b72
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
465 addition
and
368 deletion
+465
-368
src/client/src/tscAsync.c
src/client/src/tscAsync.c
+3
-6
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+50
-19
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+1
-1
src/query/inc/sql.y
src/query/inc/sql.y
+1
-0
src/query/src/qSqlParser.c
src/query/src/qSqlParser.c
+11
-2
src/query/src/queryMain.c
src/query/src/queryMain.c
+1
-0
src/query/src/sql.c
src/query/src/sql.c
+344
-338
src/vnode/src/vnodeRead.c
src/vnode/src/vnodeRead.c
+2
-2
tests/script/general/parser/topbot.sim
tests/script/general/parser/topbot.sim
+52
-0
未找到文件。
src/client/src/tscAsync.c
浏览文件 @
dfd365f0
...
...
@@ -301,7 +301,7 @@ static void tscAsyncResultCallback(SSchedMsg *pMsg) {
taosReleaseRef
(
tscObjRef
,
pSql
->
self
);
}
void
tscAsyncResultOnError
(
SSqlObj
*
pSql
)
{
void
tscAsyncResultOnError
(
SSqlObj
*
pSql
)
{
SSchedMsg
schedMsg
=
{
0
};
schedMsg
.
fp
=
tscAsyncResultCallback
;
schedMsg
.
ahandle
=
(
void
*
)
pSql
->
self
;
...
...
@@ -505,10 +505,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
return
;
_error:
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
pSql
->
res
.
code
=
code
;
tscAsyncResultOnError
(
pSql
);
}
pRes
->
code
=
code
;
tscAsyncResultOnError
(
pSql
);
taosReleaseRef
(
tscObjRef
,
pSql
->
self
);
}
src/client/src/tscSQLParser.c
浏览文件 @
dfd365f0
...
...
@@ -3293,7 +3293,8 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC
}
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_BOOL
)
{
if
(
pExpr
->
tokenId
!=
TK_EQ
&&
pExpr
->
tokenId
!=
TK_NE
)
{
int32_t
t
=
pExpr
->
tokenId
;
if
(
t
!=
TK_EQ
&&
t
!=
TK_NE
&&
t
!=
TK_NOTNULL
&&
t
!=
TK_ISNULL
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
}
...
...
@@ -3493,7 +3494,8 @@ static int32_t validateSQLExpr(SSqlCmd* pCmd, tSqlExpr* pExpr, SQueryInfo* pQuer
}
pList
->
ids
[
pList
->
num
++
]
=
index
;
}
else
if
(
pExpr
->
tokenId
==
TK_FLOAT
&&
(
isnan
(
pExpr
->
value
.
dKey
)
||
isinf
(
pExpr
->
value
.
dKey
)))
{
}
else
if
((
pExpr
->
tokenId
==
TK_FLOAT
&&
(
isnan
(
pExpr
->
value
.
dKey
)
||
isinf
(
pExpr
->
value
.
dKey
)))
||
pExpr
->
tokenId
==
TK_NULL
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
else
if
(
pExpr
->
type
==
SQL_NODE_SQLFUNCTION
)
{
if
(
*
type
==
NON_ARITHMEIC_EXPR
)
{
...
...
@@ -3727,6 +3729,39 @@ static int32_t setExprToCond(tSqlExpr** parent, tSqlExpr* pExpr, const char* msg
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
validateNullExpr
(
tSqlExpr
*
pExpr
,
char
*
msgBuf
)
{
const
char
*
msg
=
"only support is [not] null"
;
tSqlExpr
*
pRight
=
pExpr
->
pRight
;
if
(
pRight
->
tokenId
==
TK_NULL
&&
(
!
(
pExpr
->
tokenId
==
TK_ISNULL
||
pExpr
->
tokenId
==
TK_NOTNULL
)))
{
return
invalidSqlErrMsg
(
msgBuf
,
msg
);
}
return
TSDB_CODE_SUCCESS
;
}
// check for like expression
static
int32_t
validateLikeExpr
(
tSqlExpr
*
pExpr
,
STableMeta
*
pTableMeta
,
int32_t
index
,
char
*
msgBuf
)
{
const
char
*
msg1
=
"wildcard string should be less than 20 characters"
;
const
char
*
msg2
=
"illegal column name"
;
tSqlExpr
*
pLeft
=
pExpr
->
pLeft
;
tSqlExpr
*
pRight
=
pExpr
->
pRight
;
if
(
pExpr
->
tokenId
==
TK_LIKE
)
{
if
(
pRight
->
value
.
nLen
>
TSDB_PATTERN_STRING_MAX_LEN
)
{
return
invalidSqlErrMsg
(
msgBuf
,
msg1
);
}
SSchema
*
pSchema
=
tscGetTableSchema
(
pTableMeta
);
if
((
!
isTablenameToken
(
&
pLeft
->
colInfo
))
&&
!
IS_VAR_DATA_TYPE
(
pSchema
[
index
].
type
))
{
return
invalidSqlErrMsg
(
msgBuf
,
msg2
);
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
handleExprInQueryCond
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExpr
**
pExpr
,
SCondExpr
*
pCondExpr
,
int32_t
*
type
,
int32_t
parentOptr
)
{
const
char
*
msg1
=
"table query cannot use tags filter"
;
...
...
@@ -3736,8 +3771,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql
const
char
*
msg5
=
"not support ordinary column join"
;
const
char
*
msg6
=
"only one query condition on tbname allowed"
;
const
char
*
msg7
=
"only in/like allowed in filter table name"
;
const
char
*
msg8
=
"wildcard string should be less than 20 characters"
;
tSqlExpr
*
pLeft
=
(
*
pExpr
)
->
pLeft
;
tSqlExpr
*
pRight
=
(
*
pExpr
)
->
pRight
;
...
...
@@ -3753,6 +3787,18 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
// validate the null expression
int32_t
code
=
validateNullExpr
(
*
pExpr
,
tscGetErrorMsgPayload
(
pCmd
));
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
// validate the like expression
code
=
validateLikeExpr
(
*
pExpr
,
pTableMeta
,
index
.
columnIndex
,
tscGetErrorMsgPayload
(
pCmd
));
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
if
(
index
.
columnIndex
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
// query on time range
if
(
!
validateJoinExprNode
(
pCmd
,
pQueryInfo
,
*
pExpr
,
&
index
))
{
return
TSDB_CODE_TSC_INVALID_SQL
;
...
...
@@ -3774,7 +3820,6 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql
int16_t
leftIdx
=
index
.
tableIndex
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
pCmd
,
&
pRight
->
colInfo
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -3821,20 +3866,6 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
// check for like expression
if
((
*
pExpr
)
->
tokenId
==
TK_LIKE
)
{
if
(
pRight
->
value
.
nLen
>
TSDB_PATTERN_STRING_MAX_LEN
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg8
);
}
SSchema
*
pSchema
=
tscGetTableSchema
(
pTableMetaInfo
->
pTableMeta
);
if
((
!
isTablenameToken
(
&
pLeft
->
colInfo
))
&&
pSchema
[
index
.
columnIndex
].
type
!=
TSDB_DATA_TYPE_BINARY
&&
pSchema
[
index
.
columnIndex
].
type
!=
TSDB_DATA_TYPE_NCHAR
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
}
// in case of in operator, keep it in a seprate attribute
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
if
(
!
validTableNameOptr
(
*
pExpr
))
{
...
...
src/client/src/tscUtil.c
浏览文件 @
dfd365f0
...
...
@@ -309,7 +309,7 @@ void tscSetResRawPtr(SSqlRes* pRes, SQueryInfo* pQueryInfo) {
int32_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
p
Res
->
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutput
;
++
i
)
{
SInternalField
*
pInfo
=
(
SInternalField
*
)
TARRAY_GET_ELEM
(
pQueryInfo
->
fieldsInfo
.
internalField
,
i
);
pRes
->
urow
[
i
]
=
pRes
->
data
+
offset
*
pRes
->
numOfRows
;
...
...
src/query/inc/sql.y
浏览文件 @
dfd365f0
...
...
@@ -675,6 +675,7 @@ expr(A) ::= STRING(X). { A = tSqlExprCreateIdValue(&X, TK_STRING);}
expr(A) ::= NOW(X). { A = tSqlExprCreateIdValue(&X, TK_NOW); }
expr(A) ::= VARIABLE(X). { A = tSqlExprCreateIdValue(&X, TK_VARIABLE);}
expr(A) ::= BOOL(X). { A = tSqlExprCreateIdValue(&X, TK_BOOL);}
expr(A) ::= NULL(X). { A = tSqlExprCreateIdValue(&X, TK_NULL);}
// ordinary functions: min(x), max(x), top(k, 20)
expr(A) ::= ID(X) LP exprlist(Y) RP(E). { A = tSqlExprCreateFunction(Y, &X, &E, X.type); }
...
...
src/query/src/qSqlParser.c
浏览文件 @
dfd365f0
...
...
@@ -127,7 +127,12 @@ tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType) {
pSqlExpr
->
token
=
*
pToken
;
}
if
(
optrType
==
TK_INTEGER
||
optrType
==
TK_STRING
||
optrType
==
TK_FLOAT
||
optrType
==
TK_BOOL
)
{
if
(
optrType
==
TK_NULL
)
{
pToken
->
type
=
TSDB_DATA_TYPE_NULL
;
tVariantCreate
(
&
pSqlExpr
->
value
,
pToken
);
pSqlExpr
->
tokenId
=
optrType
;
pSqlExpr
->
type
=
SQL_NODE_VALUE
;
}
else
if
(
optrType
==
TK_INTEGER
||
optrType
==
TK_STRING
||
optrType
==
TK_FLOAT
||
optrType
==
TK_BOOL
)
{
toTSDBType
(
pToken
->
type
);
tVariantCreate
(
&
pSqlExpr
->
value
,
pToken
);
...
...
@@ -356,7 +361,11 @@ void tSqlExprCompact(tSqlExpr** pExpr) {
bool
tSqlExprIsLeaf
(
tSqlExpr
*
pExpr
)
{
return
(
pExpr
->
pRight
==
NULL
&&
pExpr
->
pLeft
==
NULL
)
&&
(
pExpr
->
tokenId
==
0
||
pExpr
->
tokenId
==
TK_ID
||
(
pExpr
->
tokenId
>=
TK_BOOL
&&
pExpr
->
tokenId
<=
TK_NCHAR
)
||
pExpr
->
tokenId
==
TK_SET
);
(
pExpr
->
tokenId
==
0
||
(
pExpr
->
tokenId
==
TK_ID
)
||
(
pExpr
->
tokenId
>=
TK_BOOL
&&
pExpr
->
tokenId
<=
TK_NCHAR
)
||
(
pExpr
->
tokenId
==
TK_NULL
)
||
(
pExpr
->
tokenId
==
TK_SET
));
}
bool
tSqlExprIsParentOfLeaf
(
tSqlExpr
*
pExpr
)
{
...
...
src/query/src/queryMain.c
浏览文件 @
dfd365f0
...
...
@@ -372,6 +372,7 @@ int32_t qKillQuery(qinfo_t qinfo) {
return
TSDB_CODE_QRY_INVALID_QHANDLE
;
}
qDebug
(
"QInfo:%"
PRIu64
" query killed"
,
pQInfo
->
qId
);
setQueryKilled
(
pQInfo
);
// Wait for the query executing thread being stopped/
...
...
src/query/src/sql.c
浏览文件 @
dfd365f0
此差异已折叠。
点击以展开。
src/vnode/src/vnodeRead.c
浏览文件 @
dfd365f0
...
...
@@ -364,7 +364,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SVReadMsg *pRead) {
// register the qhandle to connect to quit query immediate if connection is broken
if
(
vnodeNotifyCurrentQhandle
(
pRead
->
rpcHandle
,
pRetrieve
->
qId
,
*
handle
,
pVnode
->
vgId
)
!=
TSDB_CODE_SUCCESS
)
{
vError
(
"vgId:%d, QInfo:%"
PRIu64
"-%p, retrieve discarded since link is broken, %p"
,
pVnode
->
vgId
,
pRetrieve
->
qhandle
,
*
handle
,
pRead
->
rpcHandle
);
vError
(
"vgId:%d, QInfo:%"
PRIu64
"-%p, retrieve discarded since link is broken,
conn:
%p"
,
pVnode
->
vgId
,
pRetrieve
->
qhandle
,
*
handle
,
pRead
->
rpcHandle
);
code
=
TSDB_CODE_RPC_NETWORK_UNAVAIL
;
qKillQuery
(
*
handle
);
qReleaseQInfo
(
pVnode
->
qMgmt
,
(
void
**
)
&
handle
,
true
);
...
...
@@ -409,7 +409,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SVReadMsg *pRead) {
// client is broken, the query needs to be killed immediately.
int32_t
vnodeNotifyCurrentQhandle
(
void
*
handle
,
uint64_t
qId
,
void
*
qhandle
,
int32_t
vgId
)
{
SRetrieveTableMsg
*
pMsg
=
rpcMallocCont
(
sizeof
(
SRetrieveTableMsg
));
pMsg
->
q
handle
=
htobe64
((
uint64_t
)
qhandle
);
pMsg
->
q
Id
=
htobe64
(
qId
);
pMsg
->
header
.
vgId
=
htonl
(
vgId
);
pMsg
->
header
.
contLen
=
htonl
(
sizeof
(
SRetrieveTableMsg
));
...
...
tests/script/general/parser/topbot.sim
浏览文件 @
dfd365f0
...
...
@@ -325,4 +325,56 @@ if $row != 0 then
return -1
endi
print ===============================>td-3621
sql create table ttm2(ts timestamp, k bool);
sql insert into ttm2 values('2021-1-1 1:1:1', true)
sql insert into ttm2 values('2021-1-1 1:1:2', NULL)
sql insert into ttm2 values('2021-1-1 1:1:3', false)
sql select * from ttm2 where k is not null
if $row != 2 then
return -1
endi
if $data00 != @21-01-01 01:01:01.000@ then
print expect 21-01-01 01:01:01.000, actual $data00
return -1
endi
sql select * from ttm2 where k is null
if $row != 1 then
return -1
endi
if $data00 != @21-01-01 01:01:02.000@ then
return -1
endi
sql select * from ttm2 where k=true
if $row != 1 then
return -1
endi
if $data00 != @21-01-01 01:01:01.000@ then
return -1
endi
sql select * from ttm2 where k=false
if $row != 1 then
return -1
endi
if $data00 != @21-01-01 01:01:03.000@ then
return -1
endi
sql select * from ttm2 where k<>false
if $row != 1 then
return -1
endi
sql_error select * from ttm2 where k=null
sql_error select * from ttm2 where k<>null
sql_error select * from ttm2 where k like null
sql_error select * from ttm2 where k<null
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录