Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小楼昨夜-听风雨
TDengine
提交
75029e98
T
TDengine
项目概览
小楼昨夜-听风雨
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
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,发现更多精彩内容 >>
提交
75029e98
编写于
5月 09, 2020
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-225] 1. fix bugs for first/last query in super table; 2. add STableIdTag info function
上级
5476ccaa
变更
10
展开全部
显示空白变更内容
内联
并排
Showing
10 changed file
with
901 addition
and
815 deletion
+901
-815
cmake/platform.inc
cmake/platform.inc
+1
-1
src/client/src/tscFunctionImpl.c
src/client/src/tscFunctionImpl.c
+4
-3
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+61
-4
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+49
-19
src/inc/ttokendef.h
src/inc/ttokendef.h
+14
-13
src/query/inc/sql.y
src/query/inc/sql.y
+1
-1
src/query/inc/tsqlfunction.h
src/query/inc/tsqlfunction.h
+0
-14
src/query/src/qtokenizer.c
src/query/src/qtokenizer.c
+1
-0
src/query/src/queryExecutor.c
src/query/src/queryExecutor.c
+95
-87
src/query/src/sql.c
src/query/src/sql.c
+675
-673
未找到文件。
cmake/platform.inc
浏览文件 @
75029e98
...
@@ -62,7 +62,7 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
...
@@ -62,7 +62,7 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
IF
(
$
{
CMAKE_SIZEOF_VOID_P
}
MATCHES
8
)
IF
(
$
{
CMAKE_SIZEOF_VOID_P
}
MATCHES
8
)
SET
(
TD_LINUX_64
TRUE
)
SET
(
TD_LINUX_64
TRUE
)
SET
(
TD_OS_DIR
$
{
TD_COMMUNITY_DIR
}
/
src
/
os
/
linux
)
SET
(
TD_OS_DIR
$
{
TD_COMMUNITY_DIR
}
/
src
/
os
/
linux
)
ADD_DEFINITIONS
(
-
D_M_X64
)
ADD_DEFINITIONS
(
-
D_M_X64
-
D_DEBUG_VIEW
)
MESSAGE
(
STATUS
"The current platform is Linux 64-bit"
)
MESSAGE
(
STATUS
"The current platform is Linux 64-bit"
)
ELSEIF
(
$
{
CMAKE_SIZEOF_VOID_P
}
MATCHES
4
)
ELSEIF
(
$
{
CMAKE_SIZEOF_VOID_P
}
MATCHES
4
)
IF
(
TD_ARM
)
IF
(
TD_ARM
)
...
...
src/client/src/tscFunctionImpl.c
浏览文件 @
75029e98
...
@@ -168,9 +168,10 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
...
@@ -168,9 +168,10 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
// (uid, tid) + VGID + TAGSIZE + VARSTR_HEADER_SIZE
if
(
functionId
==
TSDB_FUNC_TID_TAG
)
{
// todo use struct
if
(
functionId
==
TSDB_FUNC_TID_TAG
)
{
// todo use struct
*
type
=
TSDB_DATA_TYPE_BINARY
;
*
type
=
TSDB_DATA_TYPE_BINARY
;
*
bytes
=
dataBytes
+
sizeof
(
int64_t
)
+
sizeof
(
int32_t
)
+
sizeof
(
int32_t
)
;
// (uid, tid) + VGID + TAGSIZE
*
bytes
=
dataBytes
+
sizeof
(
int64_t
)
+
sizeof
(
int32_t
)
+
sizeof
(
int32_t
)
+
VARSTR_HEADER_SIZE
;
*
interBytes
=
*
bytes
;
*
interBytes
=
*
bytes
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -5285,10 +5286,10 @@ SQLAggFuncElem aAggs[] = {{
...
@@ -5285,10 +5286,10 @@ SQLAggFuncElem aAggs[] = {{
},
},
{
{
// 34
// 34
"tid_tag"
,
// return table id and the corresponding tags for join match
"tid_tag"
,
// return table id and the corresponding tags for join match
and subscribe
TSDB_FUNC_TID_TAG
,
TSDB_FUNC_TID_TAG
,
TSDB_FUNC_TID_TAG
,
TSDB_FUNC_TID_TAG
,
TSDB_FUNCSTATE_MO
,
TSDB_FUNCSTATE_MO
|
TSDB_FUNCSTATE_STABLE
,
function_setup
,
function_setup
,
noop1
,
noop1
,
noop2
,
noop2
,
...
...
src/client/src/tscSQLParser.c
浏览文件 @
75029e98
...
@@ -1123,7 +1123,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
...
@@ -1123,7 +1123,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
if
(
addProjectionExprAndResultField
(
pQueryInfo
,
pItem
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
addProjectionExprAndResultField
(
pQueryInfo
,
pItem
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_INVALID_SQL
;
return
TSDB_CODE_INVALID_SQL
;
}
}
}
else
if
(
pItem
->
pNode
->
nSQLOptr
>=
TK_COUNT
&&
pItem
->
pNode
->
nSQLOptr
<=
TK_
AVG_IRATE
)
{
}
else
if
(
pItem
->
pNode
->
nSQLOptr
>=
TK_COUNT
&&
pItem
->
pNode
->
nSQLOptr
<=
TK_
TBID
)
{
// sql function in selection clause, append sql function info in pSqlCmd structure sequentially
// sql function in selection clause, append sql function info in pSqlCmd structure sequentially
if
(
addExprAndResultField
(
pQueryInfo
,
outputIndex
,
pItem
,
true
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
addExprAndResultField
(
pQueryInfo
,
outputIndex
,
pItem
,
true
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_INVALID_SQL
;
return
TSDB_CODE_INVALID_SQL
;
...
@@ -1468,6 +1468,7 @@ static int32_t setExprInfoForFunctions(SQueryInfo* pQueryInfo, SSchema* pSchema,
...
@@ -1468,6 +1468,7 @@ static int32_t setExprInfoForFunctions(SQueryInfo* pQueryInfo, SSchema* pSchema,
int32_t
addExprAndResultField
(
SQueryInfo
*
pQueryInfo
,
int32_t
colIndex
,
tSQLExprItem
*
pItem
,
bool
finalResult
)
{
int32_t
addExprAndResultField
(
SQueryInfo
*
pQueryInfo
,
int32_t
colIndex
,
tSQLExprItem
*
pItem
,
bool
finalResult
)
{
STableMetaInfo
*
pTableMetaInfo
=
NULL
;
STableMetaInfo
*
pTableMetaInfo
=
NULL
;
int32_t
optr
=
pItem
->
pNode
->
nSQLOptr
;
int32_t
optr
=
pItem
->
pNode
->
nSQLOptr
;
const
char
*
msg1
=
"not support column types"
;
const
char
*
msg1
=
"not support column types"
;
...
@@ -1476,6 +1477,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
...
@@ -1476,6 +1477,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
const
char
*
msg4
=
"invalid table name"
;
const
char
*
msg4
=
"invalid table name"
;
const
char
*
msg5
=
"parameter is out of range [0, 100]"
;
const
char
*
msg5
=
"parameter is out of range [0, 100]"
;
const
char
*
msg6
=
"function applied to tags not allowed"
;
const
char
*
msg6
=
"function applied to tags not allowed"
;
const
char
*
msg7
=
"normal table can not apply this function"
;
switch
(
optr
)
{
switch
(
optr
)
{
case
TK_COUNT
:
{
case
TK_COUNT
:
{
...
@@ -1858,13 +1860,68 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
...
@@ -1858,13 +1860,68 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
}
}
}
}
return
TSDB_CODE_SUCCESS
;
};
case
TK_TBID
:
{
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
if
(
UTIL_TABLE_IS_NOMRAL_TABLE
(
pTableMetaInfo
))
{
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg7
);
}
// no parameters or more than one parameter for function
if
(
pItem
->
pNode
->
pParam
==
NULL
||
pItem
->
pNode
->
pParam
->
nExpr
!=
1
)
{
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg2
);
}
tSQLExpr
*
pParam
=
pItem
->
pNode
->
pParam
->
a
[
0
].
pNode
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pParam
->
colInfo
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg3
);
}
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
SSchema
*
pSchema
=
tscGetTableTagSchema
(
pTableMetaInfo
->
pTableMeta
);
// functions can not be applied to normal columns
int32_t
numOfCols
=
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
if
(
index
.
columnIndex
<
numOfCols
)
{
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg6
);
}
index
.
columnIndex
-=
numOfCols
;
// 2. valid the column type
int16_t
colType
=
pSchema
[
index
.
columnIndex
].
type
;
if
(
colType
==
TSDB_DATA_TYPE_BOOL
||
colType
>=
TSDB_DATA_TYPE_BINARY
)
{
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg1
);
}
tscColumnListInsert
(
pTableMetaInfo
->
tagColList
,
&
index
);
SSchema
*
pTagSchema
=
tscGetTableTagSchema
(
pTableMetaInfo
->
pTableMeta
);
SSchema
s
=
pTagSchema
[
index
.
columnIndex
];
int16_t
bytes
=
0
;
int16_t
type
=
0
;
int16_t
inter
=
0
;
int32_t
ret
=
getResultDataInfo
(
s
.
type
,
s
.
bytes
,
TSDB_FUNC_TID_TAG
,
0
,
&
type
,
&
bytes
,
&
inter
,
0
,
0
);
assert
(
ret
==
TSDB_CODE_SUCCESS
);
s
.
type
=
type
;
s
.
bytes
=
bytes
;
TSDB_QUERY_SET_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_TAG_FILTER_QUERY
);
tscAddSpecialColumnForSelect
(
pQueryInfo
,
0
,
TSDB_FUNC_TID_TAG
,
&
index
,
&
s
,
TSDB_COL_TAG
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
default:
default:
return
TSDB_CODE_INVALID_SQL
;
return
TSDB_CODE_INVALID_SQL
;
}
}
}
}
// todo refactor
// todo refactor
...
...
src/client/src/tscSubquery.c
浏览文件 @
75029e98
...
@@ -412,10 +412,6 @@ static void updateQueryTimeRange(SQueryInfo* pQueryInfo, int64_t st, int64_t et)
...
@@ -412,10 +412,6 @@ static void updateQueryTimeRange(SQueryInfo* pQueryInfo, int64_t st, int64_t et)
static
void
tSIntersectionAndLaunchSecQuery
(
SJoinSupporter
*
pSupporter
,
SSqlObj
*
pSql
)
{
static
void
tSIntersectionAndLaunchSecQuery
(
SJoinSupporter
*
pSupporter
,
SSqlObj
*
pSql
)
{
SSqlObj
*
pParentSql
=
pSupporter
->
pObj
;
SSqlObj
*
pParentSql
=
pSupporter
->
pObj
;
// SSqlCmd* pCmd = &pSql->cmd;
// SSqlRes* pRes = &pSql->res;
// SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
SQueryInfo
*
pParentQueryInfo
=
tscGetQueryInfoDetail
(
&
pParentSql
->
cmd
,
pParentSql
->
cmd
.
clauseIndex
);
SQueryInfo
*
pParentQueryInfo
=
tscGetQueryInfoDetail
(
&
pParentSql
->
cmd
,
pParentSql
->
cmd
.
clauseIndex
);
// if (tscNonOrderedProjectionQueryOnSTable(pParentQueryInfo, 0)) {
// if (tscNonOrderedProjectionQueryOnSTable(pParentQueryInfo, 0)) {
...
@@ -602,21 +598,6 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
...
@@ -602,21 +598,6 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
// if (pSupporter->pState->code != TSDB_CODE_SUCCESS) {
// tscError("%p abort query due to other subquery failure. code:%d, global code:%s", pSql, numOfRows,
// tstrerror(pSupporter->pState->code));
//
// quitAllSubquery(pParentSql, pSupporter);
// return;
// }
//
// if (numOfRows < 0) {
// tscError("%p sub query failed, code:%s, index:%d", pSql, tstrerror(numOfRows), pSupporter->subqueryIndex);
// pSupporter->pState->code = numOfRows;
// quitAllSubquery(pParentSql, pSupporter);
// return;
// }
// response of tag retrieve
// response of tag retrieve
if
(
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_TAG_FILTER_QUERY
))
{
if
(
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_TAG_FILTER_QUERY
))
{
if
(
numOfRows
==
0
||
pSql
->
res
.
completed
)
{
if
(
numOfRows
==
0
||
pSql
->
res
.
completed
)
{
...
@@ -1051,6 +1032,55 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
...
@@ -1051,6 +1032,55 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
static
void
tscRetrieveDataRes
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
);
static
void
tscRetrieveDataRes
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
);
//static void ddx(TAOS* taos) {
//
// SSqlCmd* pCmd = &pSql->cmd;
//
// tscPartiallyFreeSqlObj(pSql);
//// tscTrace("continue parse sql: %s", pSql->cmd.curSql);
//
// SQueryInfo* pQueryInfo = NULL;
// int32_t code = tscGetQueryInfoDetailSafely(pCmd, pCmd->clauseIndex, &pQueryInfo);
// assert(code == TSDB_CODE_SUCCESS);
//
// STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
//
// if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) { // return the tableId & tag
// SSchema s = {0};
// SColumnIndex index = {0};
//
// size_t numOfTags = taosArrayGetSize(pTableMetaInfo->tagColList);
// for (int32_t i = 0; i < numOfTags; ++i) {
// SColumn* c = taosArrayGetP(pTableMetaInfo->tagColList, i);
// index = (SColumnIndex){.tableIndex = 0, .columnIndex = c->colIndex.columnIndex};
//
// SSchema* pTagSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta);
// s = pTagSchema[c->colIndex.columnIndex];
//
// int16_t bytes = 0;
// int16_t type = 0;
// int16_t inter = 0;
//
// getResultDataInfo(s.type, s.bytes, TSDB_FUNC_TID_TAG, 0, &type, &bytes, &inter, 0, 0);
//
// s.type = type;
// s.bytes = bytes;
//// pSupporter->tagSize = s.bytes;
// }
//
// // set get tags query type
// TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY);
//
// tscAddSpecialColumnForSelect(pQueryInfo, 0, TSDB_FUNC_TID_TAG, &index, &s, TSDB_COL_TAG);
// size_t numOfCols = taosArrayGetSize(pQueryInfo->colList);
//
// tscTrace( "%p vgroupIndex:%d, type:%d, tid_tag query to retrieve (tableId, tags), "
// "exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s",
// pSql, pTableMetaInfo->vgroupIndex, pQueryInfo->type, tscSqlExprNumOfExprs(pQueryInfo),
// numOfCols, pQueryInfo->fieldsInfo.numOfOutput, pQueryInfo->pTableMetaInfo[0]->name);
// }
//}
static
SSqlObj
*
tscCreateSqlObjForSubquery
(
SSqlObj
*
pSql
,
SRetrieveSupport
*
trsupport
,
SSqlObj
*
prevSqlObj
);
static
SSqlObj
*
tscCreateSqlObjForSubquery
(
SSqlObj
*
pSql
,
SRetrieveSupport
*
trsupport
,
SSqlObj
*
prevSqlObj
);
// todo merge with callback
// todo merge with callback
...
...
src/inc/ttokendef.h
浏览文件 @
75029e98
...
@@ -206,19 +206,20 @@
...
@@ -206,19 +206,20 @@
#define TK_SUM_IRATE 188
#define TK_SUM_IRATE 188
#define TK_AVG_RATE 189
#define TK_AVG_RATE 189
#define TK_AVG_IRATE 190
#define TK_AVG_IRATE 190
#define TK_SEMI 191
#define TK_TBID 191
#define TK_NONE 192
#define TK_SEMI 192
#define TK_PREV 193
#define TK_NONE 193
#define TK_LINEAR 194
#define TK_PREV 194
#define TK_IMPORT 195
#define TK_LINEAR 195
#define TK_METRIC 196
#define TK_IMPORT 196
#define TK_TBNAME 197
#define TK_METRIC 197
#define TK_JOIN 198
#define TK_TBNAME 198
#define TK_METRICS 199
#define TK_JOIN 199
#define TK_STABLE 200
#define TK_METRICS 200
#define TK_INSERT 201
#define TK_STABLE 201
#define TK_INTO 202
#define TK_INSERT 202
#define TK_VALUES 203
#define TK_INTO 203
#define TK_VALUES 204
#endif
#endif
...
...
src/query/inc/sql.y
浏览文件 @
75029e98
...
@@ -655,5 +655,5 @@ cmd ::= KILL QUERY IPTOKEN(X) COLON(Z) INTEGER(Y) COLON(K) INTEGER(F). {X
...
@@ -655,5 +655,5 @@ cmd ::= KILL QUERY IPTOKEN(X) COLON(Z) INTEGER(Y) COLON(K) INTEGER(F). {X
DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR GLOB IGNORE IMMEDIATE INITIALLY INSTEAD
DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR GLOB IGNORE IMMEDIATE INITIALLY INSTEAD
LIKE MATCH KEY OF OFFSET RAISE REPLACE RESTRICT ROW STATEMENT TRIGGER VIEW ALL
LIKE MATCH KEY OF OFFSET RAISE REPLACE RESTRICT ROW STATEMENT TRIGGER VIEW ALL
COUNT SUM AVG MIN MAX FIRST LAST TOP BOTTOM STDDEV PERCENTILE APERCENTILE LEASTSQUARES HISTOGRAM DIFF
COUNT SUM AVG MIN MAX FIRST LAST TOP BOTTOM STDDEV PERCENTILE APERCENTILE LEASTSQUARES HISTOGRAM DIFF
SPREAD TWA INTERP LAST_ROW RATE IRATE SUM_RATE SUM_IRATE AVG_RATE AVG_IRATE NOW IPTOKEN SEMI NONE PREV LINEAR IMPORT
SPREAD TWA INTERP LAST_ROW RATE IRATE SUM_RATE SUM_IRATE AVG_RATE AVG_IRATE
TBID
NOW IPTOKEN SEMI NONE PREV LINEAR IMPORT
METRIC TBNAME JOIN METRICS STABLE NULL INSERT INTO VALUES.
METRIC TBNAME JOIN METRICS STABLE NULL INSERT INTO VALUES.
src/query/inc/tsqlfunction.h
浏览文件 @
75029e98
...
@@ -245,21 +245,8 @@ enum {
...
@@ -245,21 +245,8 @@ enum {
BLK_DATA_ALL_NEEDED
=
0x3
,
BLK_DATA_ALL_NEEDED
=
0x3
,
};
};
#define IS_FILE_BLOCK(x) (((x)&BLK_FILE_BLOCK) != 0)
#define SET_FILE_BLOCK_FLAG(x) \
do { \
(x) &= (~BLK_CACHE_BLOCK); \
(x) |= BLK_FILE_BLOCK; \
} while (0);
#define SET_CACHE_BLOCK_FLAG(x) ((x) = BLK_CACHE_BLOCK | BLK_BLOCK_LOADED);
#define SET_DATA_BLOCK_NOT_LOADED(x) ((x) &= (~BLK_BLOCK_LOADED));
#define SET_DATA_BLOCK_NOT_LOADED(x) ((x) &= (~BLK_BLOCK_LOADED));
#define SET_DATA_BLOCK_LOADED(x) ((x) |= BLK_BLOCK_LOADED);
#define IS_DATA_BLOCK_LOADED(x) (((x)&BLK_BLOCK_LOADED) != 0)
typedef
struct
STwaInfo
{
typedef
struct
STwaInfo
{
TSKEY
lastKey
;
TSKEY
lastKey
;
int8_t
hasResult
;
// flag to denote has value
int8_t
hasResult
;
// flag to denote has value
...
@@ -291,7 +278,6 @@ bool top_bot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, char *mi
...
@@ -291,7 +278,6 @@ bool top_bot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, char *mi
bool
stableQueryFunctChanged
(
int32_t
funcId
);
bool
stableQueryFunctChanged
(
int32_t
funcId
);
void
resetResultInfo
(
SResultInfo
*
pResInfo
);
void
resetResultInfo
(
SResultInfo
*
pResInfo
);
void
initResultInfo
(
SResultInfo
*
pResInfo
);
void
initResultInfo
(
SResultInfo
*
pResInfo
);
void
setResultInfoBuf
(
SResultInfo
*
pResInfo
,
int32_t
size
,
bool
superTable
);
void
setResultInfoBuf
(
SResultInfo
*
pResInfo
,
int32_t
size
,
bool
superTable
);
...
...
src/query/src/qtokenizer.c
浏览文件 @
75029e98
...
@@ -225,6 +225,7 @@ static SKeyword keywordTable[] = {
...
@@ -225,6 +225,7 @@ static SKeyword keywordTable[] = {
{
"TBNAME"
,
TK_TBNAME
},
{
"TBNAME"
,
TK_TBNAME
},
{
"JOIN"
,
TK_JOIN
},
{
"JOIN"
,
TK_JOIN
},
{
"METRICS"
,
TK_METRICS
},
{
"METRICS"
,
TK_METRICS
},
{
"TBID"
,
TK_TBID
},
{
"STABLE"
,
TK_STABLE
},
{
"STABLE"
,
TK_STABLE
},
{
"FILE"
,
TK_FILE
},
{
"FILE"
,
TK_FILE
},
{
"VNODES"
,
TK_VNODES
},
{
"VNODES"
,
TK_VNODES
},
...
...
src/query/src/queryExecutor.c
浏览文件 @
75029e98
...
@@ -39,10 +39,10 @@
...
@@ -39,10 +39,10 @@
#define TSDB_COL_IS_TAG(f) (((f)&TSDB_COL_TAG) != 0)
#define TSDB_COL_IS_TAG(f) (((f)&TSDB_COL_TAG) != 0)
#define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP)
#define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP)
#define IS_MASTER_SCAN(runtime) (((runtime)->scanFlag & 1u) == MASTER_SCAN)
#define IS_MASTER_SCAN(runtime) ((runtime)->scanFlag == MASTER_SCAN)
#define IS_SUPPLEMENT_SCAN(runtime) ((runtime)->scanFlag == SUPPLEMENTARY_SCAN)
#define IS_REVERSE_SCAN(runtime) ((runtime)->scanFlag == SUPPLEMENTARY_SCAN)
#define SET_SUPPLEMENT_SCAN_FLAG(runtime) ((runtime)->scanFlag = SUPPLEMENTARY_SCAN)
#define SET_MASTER_SCAN_FLAG(runtime) ((runtime)->scanFlag = MASTER_SCAN)
#define SET_MASTER_SCAN_FLAG(runtime) ((runtime)->scanFlag = MASTER_SCAN)
#define SET_REVERSE_SCAN_FLAG(runtime) ((runtime)->scanFlag = SUPPLEMENTARY_SCAN)
#define GET_QINFO_ADDR(x) ((void *)((char *)(x)-offsetof(SQInfo, runtimeEnv)))
#define GET_QINFO_ADDR(x) ((void *)((char *)(x)-offsetof(SQInfo, runtimeEnv)))
...
@@ -1101,7 +1101,7 @@ static bool functionNeedToExecute(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx
...
@@ -1101,7 +1101,7 @@ static bool functionNeedToExecute(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx
}
}
// in the supplementary scan, only the following functions need to be executed
// in the supplementary scan, only the following functions need to be executed
if
(
IS_
SUPPLEMENT
_SCAN
(
pRuntimeEnv
)
&&
if
(
IS_
REVERSE
_SCAN
(
pRuntimeEnv
)
&&
!
(
functionId
==
TSDB_FUNC_LAST_DST
||
functionId
==
TSDB_FUNC_FIRST_DST
||
functionId
==
TSDB_FUNC_FIRST
||
!
(
functionId
==
TSDB_FUNC_LAST_DST
||
functionId
==
TSDB_FUNC_FIRST_DST
||
functionId
==
TSDB_FUNC_FIRST
||
functionId
==
TSDB_FUNC_LAST
||
functionId
==
TSDB_FUNC_TAG
||
functionId
==
TSDB_FUNC_TS
))
{
functionId
==
TSDB_FUNC_LAST
||
functionId
==
TSDB_FUNC_TAG
||
functionId
==
TSDB_FUNC_TS
))
{
return
false
;
return
false
;
...
@@ -2450,8 +2450,7 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -2450,8 +2450,7 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
qTrace
(
"QInfo:%p query start, qrange:%"
PRId64
"-%"
PRId64
", lastkey:%"
PRId64
", order:%d"
,
qTrace
(
"QInfo:%p query start, qrange:%"
PRId64
"-%"
PRId64
", lastkey:%"
PRId64
", order:%d"
,
GET_QINFO_ADDR
(
pRuntimeEnv
),
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
lastKey
,
pQuery
->
order
.
order
);
GET_QINFO_ADDR
(
pRuntimeEnv
),
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
lastKey
,
pQuery
->
order
.
order
);
TsdbQueryHandleT
pQueryHandle
=
TsdbQueryHandleT
pQueryHandle
=
IS_MASTER_SCAN
(
pRuntimeEnv
)
?
pRuntimeEnv
->
pQueryHandle
:
pRuntimeEnv
->
pSecQueryHandle
;
pRuntimeEnv
->
scanFlag
==
MASTER_SCAN
?
pRuntimeEnv
->
pQueryHandle
:
pRuntimeEnv
->
pSecQueryHandle
;
while
(
tsdbNextDataBlock
(
pQueryHandle
))
{
while
(
tsdbNextDataBlock
(
pQueryHandle
))
{
if
(
isQueryKilled
(
GET_QINFO_ADDR
(
pRuntimeEnv
)))
{
if
(
isQueryKilled
(
GET_QINFO_ADDR
(
pRuntimeEnv
)))
{
return
0
;
return
0
;
...
@@ -2835,11 +2834,12 @@ void copyResToQueryResultBuf(SQInfo *pQInfo, SQuery *pQuery) {
...
@@ -2835,11 +2834,12 @@ void copyResToQueryResultBuf(SQInfo *pQInfo, SQuery *pQuery) {
return
;
// failed to save data in the disk
return
;
// failed to save data in the disk
}
}
// set current query completed
// check if all results has been sent to client
// if (pQInfo->numOfGroupResultPages == 0 && pQInfo->groupIndex == pQInfo->pSidSet->numOfSubSet) {
int32_t
numOfGroup
=
taosArrayGetSize
(
pQInfo
->
groupInfo
.
pGroupList
);
// pQInfo->tableIndex = pQInfo->pSidSet->numOfTables;
if
(
pQInfo
->
numOfGroupResultPages
==
0
&&
pQInfo
->
groupIndex
==
numOfGroup
)
{
// return;
pQInfo
->
tableIndex
=
pQInfo
->
groupInfo
.
numOfTables
;
// set query completed
// }
return
;
}
}
}
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
...
@@ -3087,7 +3087,31 @@ void setTableDataInfo(STableQueryInfo *pTableQueryInfo, int32_t tableIndex, int3
...
@@ -3087,7 +3087,31 @@ void setTableDataInfo(STableQueryInfo *pTableQueryInfo, int32_t tableIndex, int3
pTableQueryInfo
->
tableIndex
=
tableIndex
;
pTableQueryInfo
->
tableIndex
=
tableIndex
;
}
}
static
void
doDisableFunctsForSupplementaryScan
(
SQuery
*
pQuery
,
SWindowResInfo
*
pWindowResInfo
,
int32_t
order
)
{
static
void
updateTableQueryInfoForReverseScan
(
SQuery
*
pQuery
,
STableQueryInfo
*
pTableQueryInfo
)
{
if
(
pTableQueryInfo
==
NULL
)
{
return
;
}
// order has change already!
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pQuery
->
order
.
order
);
if
(
!
QUERY_IS_ASC_QUERY
(
pQuery
))
{
assert
(
pTableQueryInfo
->
win
.
ekey
>=
pTableQueryInfo
->
lastKey
+
step
);
}
else
{
assert
(
pTableQueryInfo
->
win
.
ekey
<=
pTableQueryInfo
->
lastKey
+
step
);
}
pTableQueryInfo
->
win
.
ekey
=
pTableQueryInfo
->
lastKey
+
step
;
SWAP
(
pTableQueryInfo
->
win
.
skey
,
pTableQueryInfo
->
win
.
ekey
,
TSKEY
);
pTableQueryInfo
->
lastKey
=
pTableQueryInfo
->
win
.
skey
;
SWITCH_ORDER
(
pTableQueryInfo
->
cur
.
order
);
pTableQueryInfo
->
cur
.
vgroupIndex
=
-
1
;
}
static
void
disableFuncInReverseScanImpl
(
SQInfo
*
pQInfo
,
SWindowResInfo
*
pWindowResInfo
,
int32_t
order
)
{
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
for
(
int32_t
i
=
0
;
i
<
pWindowResInfo
->
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pWindowResInfo
->
size
;
++
i
)
{
SWindowStatus
*
pStatus
=
getTimeWindowResStatus
(
pWindowResInfo
,
i
);
SWindowStatus
*
pStatus
=
getTimeWindowResStatus
(
pWindowResInfo
,
i
);
if
(
!
pStatus
->
closed
)
{
if
(
!
pStatus
->
closed
)
{
...
@@ -3108,18 +3132,32 @@ static void doDisableFunctsForSupplementaryScan(SQuery *pQuery, SWindowResInfo *
...
@@ -3108,18 +3132,32 @@ static void doDisableFunctsForSupplementaryScan(SQuery *pQuery, SWindowResInfo *
}
}
}
}
}
}
int32_t
numOfGroups
=
taosArrayGetSize
(
pQInfo
->
groupInfo
.
pGroupList
);
for
(
int32_t
i
=
0
;
i
<
numOfGroups
;
++
i
)
{
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
groupInfo
.
pGroupList
,
i
);
qTrace
(
"QInfo:%p no result in group %d, continue"
,
pQInfo
,
pQInfo
->
groupIndex
-
1
);
size_t
t
=
taosArrayGetSize
(
group
);
for
(
int32_t
j
=
0
;
j
<
t
;
++
j
)
{
SGroupItem
*
item
=
taosArrayGet
(
group
,
j
);
updateTableQueryInfoForReverseScan
(
pQuery
,
item
->
info
);
}
}
}
}
void
disableFuncInReverseScan
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
void
disableFuncInReverseScan
(
SQInfo
*
pQInfo
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
int32_t
order
=
pQuery
->
order
.
order
;
int32_t
order
=
pQuery
->
order
.
order
;
// group by normal columns and interval query on normal table
// group by normal columns and interval query on normal table
SWindowResInfo
*
pWindowResInfo
=
&
pRuntimeEnv
->
windowResInfo
;
SWindowResInfo
*
pWindowResInfo
=
&
pRuntimeEnv
->
windowResInfo
;
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
)
||
isIntervalQuery
(
pQuery
))
{
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
)
||
isIntervalQuery
(
pQuery
))
{
d
oDisableFunctsForSupplementaryScan
(
pQuery
,
pWindowResInfo
,
order
);
d
isableFuncInReverseScanImpl
(
pQInfo
,
pWindowResInfo
,
order
);
}
else
{
// for simple result of table query,
}
else
{
// for simple result of table query,
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutput
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutput
;
++
j
)
{
// todo refactor
int32_t
functId
=
pQuery
->
pSelectExpr
[
j
].
base
.
functionId
;
int32_t
functId
=
pQuery
->
pSelectExpr
[
j
].
base
.
functionId
;
SQLFunctionCtx
*
pCtx
=
&
pRuntimeEnv
->
pCtx
[
j
];
SQLFunctionCtx
*
pCtx
=
&
pRuntimeEnv
->
pCtx
[
j
];
...
@@ -3134,34 +3172,10 @@ void disableFuncInReverseScan(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -3134,34 +3172,10 @@ void disableFuncInReverseScan(SQueryRuntimeEnv *pRuntimeEnv) {
}
}
}
}
void
disableFuncForReverseScan
(
SQInfo
*
pQInfo
,
int32_t
order
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
pRuntimeEnv
->
pCtx
[
i
].
order
=
(
pRuntimeEnv
->
pCtx
[
i
].
order
)
^
1u
;
}
if
(
isIntervalQuery
(
pQuery
))
{
// for (int32_t i = 0; i < pQInfo->groupInfo.numOfTables; ++i) {
// STableQueryInfo *pTableQueryInfo = pQInfo->pTableQueryInfo[i].pTableQInfo;
// SWindowResInfo * pWindowResInfo = &pTableQueryInfo->windowResInfo;
//
// doDisableFunctsForSupplementaryScan(pQuery, pWindowResInfo, order);
// }
}
else
{
SWindowResInfo
*
pWindowResInfo
=
&
pRuntimeEnv
->
windowResInfo
;
doDisableFunctsForSupplementaryScan
(
pQuery
,
pWindowResInfo
,
order
);
}
pQuery
->
order
.
order
=
(
pQuery
->
order
.
order
)
^
1u
;
}
void
switchCtxOrder
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
void
switchCtxOrder
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
SWITCH_ORDER
(
pRuntimeEnv
->
pCtx
[
i
]
SWITCH_ORDER
(
pRuntimeEnv
->
pCtx
[
i
]
.
order
);
.
order
);
// = (pRuntimeEnv->pCtx[i].order == TSDB_ORDER_ASC)? TSDB_ORDER_DESC:TSDB_ORDER_ASC;
}
}
}
}
...
@@ -3358,7 +3372,7 @@ static void setEnvBeforeReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusI
...
@@ -3358,7 +3372,7 @@ static void setEnvBeforeReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusI
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
SWITCH_ORDER
(
pQuery
->
order
.
order
);
SWITCH_ORDER
(
pQuery
->
order
.
order
);
SET_
SUPPLEMENT
_SCAN_FLAG
(
pRuntimeEnv
);
SET_
REVERSE
_SCAN_FLAG
(
pRuntimeEnv
);
STsdbQueryCond
cond
=
{
STsdbQueryCond
cond
=
{
.
twindow
=
pQuery
->
window
,
.
twindow
=
pQuery
->
window
,
...
@@ -3376,7 +3390,7 @@ static void setEnvBeforeReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusI
...
@@ -3376,7 +3390,7 @@ static void setEnvBeforeReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusI
setQueryStatus
(
pQuery
,
QUERY_NOT_COMPLETED
);
setQueryStatus
(
pQuery
,
QUERY_NOT_COMPLETED
);
switchCtxOrder
(
pRuntimeEnv
);
switchCtxOrder
(
pRuntimeEnv
);
disableFuncInReverseScan
(
p
RuntimeEnv
);
disableFuncInReverseScan
(
p
QInfo
);
}
}
static
void
clearEnvAfterReverseScan
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SQueryStatusInfo
*
pStatus
)
{
static
void
clearEnvAfterReverseScan
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SQueryStatusInfo
*
pStatus
)
{
...
@@ -3533,28 +3547,6 @@ void destroyTableQueryInfo(STableQueryInfo *pTableQueryInfo, int32_t numOfCols)
...
@@ -3533,28 +3547,6 @@ void destroyTableQueryInfo(STableQueryInfo *pTableQueryInfo, int32_t numOfCols)
free
(
pTableQueryInfo
);
free
(
pTableQueryInfo
);
}
}
void
changeMeterQueryInfoForSuppleQuery
(
SQuery
*
pQuery
,
STableQueryInfo
*
pTableQueryInfo
)
{
if
(
pTableQueryInfo
==
NULL
)
{
return
;
}
// order has change already!
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pQuery
->
order
.
order
);
if
(
!
QUERY_IS_ASC_QUERY
(
pQuery
))
{
assert
(
pTableQueryInfo
->
win
.
ekey
>=
pTableQueryInfo
->
lastKey
+
step
);
}
else
{
assert
(
pTableQueryInfo
->
win
.
ekey
<=
pTableQueryInfo
->
lastKey
+
step
);
}
pTableQueryInfo
->
win
.
ekey
=
pTableQueryInfo
->
lastKey
+
step
;
SWAP
(
pTableQueryInfo
->
win
.
skey
,
pTableQueryInfo
->
win
.
ekey
,
TSKEY
);
pTableQueryInfo
->
lastKey
=
pTableQueryInfo
->
win
.
skey
;
pTableQueryInfo
->
cur
.
order
=
pTableQueryInfo
->
cur
.
order
^
1u
;
pTableQueryInfo
->
cur
.
vgroupIndex
=
-
1
;
}
void
restoreIntervalQueryRange
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
STableQueryInfo
*
pTableQueryInfo
)
{
void
restoreIntervalQueryRange
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
STableQueryInfo
*
pTableQueryInfo
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
...
@@ -3943,10 +3935,17 @@ static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char *data
...
@@ -3943,10 +3935,17 @@ static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char *data
data
+=
bytes
*
numOfRows
;
data
+=
bytes
*
numOfRows
;
}
}
// all data returned, set query over
// all data returned, set query over
if
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
if
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
if
(
pQInfo
->
runtimeEnv
.
stableQuery
&&
isIntervalQuery
(
pQuery
))
{
if
(
pQInfo
->
tableIndex
>=
pQInfo
->
groupInfo
.
numOfTables
)
{
setQueryStatus
(
pQuery
,
QUERY_OVER
);
setQueryStatus
(
pQuery
,
QUERY_OVER
);
}
}
}
else
{
setQueryStatus
(
pQuery
,
QUERY_OVER
);
}
}
}
}
int32_t
vnodeQueryResultInterpolate
(
SQInfo
*
pQInfo
,
tFilePage
**
pDst
,
tFilePage
**
pDataSrc
,
int32_t
numOfRows
,
int32_t
vnodeQueryResultInterpolate
(
SQInfo
*
pQInfo
,
tFilePage
**
pDst
,
tFilePage
**
pDataSrc
,
int32_t
numOfRows
,
...
@@ -4368,7 +4367,8 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) {
...
@@ -4368,7 +4367,8 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) {
int64_t
st
=
taosGetTimestampMs
();
int64_t
st
=
taosGetTimestampMs
();
TsdbQueryHandleT
*
pQueryHandle
=
pRuntimeEnv
->
pQueryHandle
;
TsdbQueryHandleT
pQueryHandle
=
IS_MASTER_SCAN
(
pRuntimeEnv
)
?
pRuntimeEnv
->
pQueryHandle
:
pRuntimeEnv
->
pSecQueryHandle
;
while
(
tsdbNextDataBlock
(
pQueryHandle
))
{
while
(
tsdbNextDataBlock
(
pQueryHandle
))
{
if
(
isQueryKilled
(
pQInfo
))
{
if
(
isQueryKilled
(
pQInfo
))
{
break
;
break
;
...
@@ -4400,7 +4400,7 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) {
...
@@ -4400,7 +4400,7 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) {
}
}
}
}
assert
(
pTableQueryInfo
!=
NULL
&&
pTableQueryInfo
!=
NULL
);
assert
(
pTableQueryInfo
!=
NULL
);
restoreIntervalQueryRange
(
pRuntimeEnv
,
pTableQueryInfo
);
restoreIntervalQueryRange
(
pRuntimeEnv
,
pTableQueryInfo
);
SDataStatis
*
pStatis
=
NULL
;
SDataStatis
*
pStatis
=
NULL
;
...
@@ -4759,28 +4759,35 @@ static void createTableQueryInfo(SQInfo *pQInfo) {
...
@@ -4759,28 +4759,35 @@ static void createTableQueryInfo(SQInfo *pQInfo) {
}
}
}
}
static
void
prepareQueryInfoForReverseScan
(
SQInfo
*
pQInfo
)
{
// SQuery *pQuery = pQInfo->runtimeEnv.pQuery;
// for (int32_t i = 0; i < pQInfo->groupInfo.numOfTables; ++i) {
// STableQueryInfo *pTableQueryInfo = pQInfo->pTableQueryInfo[i].pTableQInfo;
// changeMeterQueryInfoForSuppleQuery(pQuery, pTableQueryInfo);
// }
}
static
void
doSaveContext
(
SQInfo
*
pQInfo
)
{
static
void
doSaveContext
(
SQInfo
*
pQInfo
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SET_SUPPLEMENT_SCAN_FLAG
(
pRuntimeEnv
);
SET_REVERSE_SCAN_FLAG
(
pRuntimeEnv
);
disableFuncForReverseScan
(
pQInfo
,
pQuery
->
order
.
order
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
SWITCH_ORDER
(
pQuery
->
order
.
order
);
if
(
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
if
(
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
pRuntimeEnv
->
pTSBuf
->
cur
.
order
=
p
RuntimeEnv
->
pTSBuf
->
cur
.
order
^
1u
;
pRuntimeEnv
->
pTSBuf
->
cur
.
order
=
p
Query
->
order
.
order
;
}
}
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
STsdbQueryCond
cond
=
{
prepareQueryInfoForReverseScan
(
pQInfo
);
.
twindow
=
pQuery
->
window
,
.
order
=
pQuery
->
order
.
order
,
.
colList
=
pQuery
->
colList
,
.
numOfCols
=
pQuery
->
numOfCols
,
};
// clean unused handle
if
(
pRuntimeEnv
->
pSecQueryHandle
!=
NULL
)
{
tsdbCleanupQueryHandle
(
pRuntimeEnv
->
pSecQueryHandle
);
}
pRuntimeEnv
->
pSecQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
pQInfo
->
tableIdGroupInfo
);
setQueryStatus
(
pQuery
,
QUERY_NOT_COMPLETED
);
switchCtxOrder
(
pRuntimeEnv
);
disableFuncInReverseScan
(
pQInfo
);
}
}
static
void
doRestoreContext
(
SQInfo
*
pQInfo
)
{
static
void
doRestoreContext
(
SQInfo
*
pQInfo
)
{
...
@@ -4835,8 +4842,6 @@ static void multiTableQueryProcess(SQInfo *pQInfo) {
...
@@ -4835,8 +4842,6 @@ static void multiTableQueryProcess(SQInfo *pQInfo) {
copyFromWindowResToSData
(
pQInfo
,
pRuntimeEnv
->
windowResInfo
.
pResult
);
copyFromWindowResToSData
(
pQInfo
,
pRuntimeEnv
->
windowResInfo
.
pResult
);
}
}
pQuery
->
rec
.
rows
+=
pQuery
->
rec
.
rows
;
if
(
pQuery
->
rec
.
rows
==
0
)
{
if
(
pQuery
->
rec
.
rows
==
0
)
{
// vnodePrintQueryStatistics(pSupporter);
// vnodePrintQueryStatistics(pSupporter);
}
}
...
@@ -6287,7 +6292,10 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
...
@@ -6287,7 +6292,10 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
SGroupItem
*
item
=
taosArrayGet
(
pa
,
i
);
SGroupItem
*
item
=
taosArrayGet
(
pa
,
i
);
char
*
output
=
pQuery
->
sdata
[
0
]
->
data
+
i
*
rsize
;
char
*
output
=
pQuery
->
sdata
[
0
]
->
data
+
i
*
rsize
;
*
(
int64_t
*
)
output
=
item
->
id
.
uid
;
// memory align problem
varDataSetLen
(
output
,
rsize
-
VARSTR_HEADER_SIZE
);
output
=
varDataVal
(
output
);
*
(
int64_t
*
)
output
=
item
->
id
.
uid
;
// memory align problem, todo serialize
output
+=
sizeof
(
item
->
id
.
uid
);
output
+=
sizeof
(
item
->
id
.
uid
);
*
(
int32_t
*
)
output
=
item
->
id
.
tid
;
*
(
int32_t
*
)
output
=
item
->
id
.
tid
;
...
...
src/query/src/sql.c
浏览文件 @
75029e98
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录