Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
e15aa9b1
T
TDengine
项目概览
慢慢CG
/
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看板
提交
e15aa9b1
编写于
12月 31, 2019
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add the union support in sql parser. #1032. [TBASE-1140]
上级
c18b6b1b
变更
20
显示空白变更内容
内联
并排
Showing
20 changed file
with
2593 addition
and
2302 deletion
+2593
-2302
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+39
-34
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+14
-10
src/client/src/sql.c
src/client/src/sql.c
+522
-515
src/client/src/tscAsync.c
src/client/src/tscAsync.c
+41
-23
src/client/src/tscJoinProcess.c
src/client/src/tscJoinProcess.c
+92
-65
src/client/src/tscLocal.c
src/client/src/tscLocal.c
+72
-52
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+18
-18
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+2
-2
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+882
-857
src/client/src/tscSecondaryMerge.c
src/client/src/tscSecondaryMerge.c
+196
-169
src/client/src/tscServer.c
src/client/src/tscServer.c
+281
-211
src/client/src/tscSql.c
src/client/src/tscSql.c
+49
-38
src/client/src/tscStream.c
src/client/src/tscStream.c
+63
-53
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+253
-190
src/inc/sql.y
src/inc/sql.y
+2
-1
src/inc/tsdb.h
src/inc/tsdb.h
+1
-0
src/inc/tsqldef.h
src/inc/tsqldef.h
+60
-60
src/inc/tutil.h
src/inc/tutil.h
+2
-2
src/util/src/hash.c
src/util/src/hash.c
+2
-0
src/util/src/tutil.c
src/util/src/tutil.c
+2
-2
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
e15aa9b1
...
@@ -29,9 +29,9 @@ extern "C" {
...
@@ -29,9 +29,9 @@ extern "C" {
#include "tsclient.h"
#include "tsclient.h"
#include "tsdb.h"
#include "tsdb.h"
#define UTIL_METER_IS_
METRIC
(metaInfo) \
#define UTIL_METER_IS_
SUPERTABLE
(metaInfo) \
(((metaInfo)->pMeterMeta != NULL) && ((metaInfo)->pMeterMeta->meterType == TSDB_METER_METRIC))
(((metaInfo)->pMeterMeta != NULL) && ((metaInfo)->pMeterMeta->meterType == TSDB_METER_METRIC))
#define UTIL_METER_IS_NOMRAL_METER(metaInfo) (!(UTIL_METER_IS_
METRIC
(metaInfo)))
#define UTIL_METER_IS_NOMRAL_METER(metaInfo) (!(UTIL_METER_IS_
SUPERTABLE
(metaInfo)))
#define UTIL_METER_IS_CREATE_FROM_METRIC(metaInfo) \
#define UTIL_METER_IS_CREATE_FROM_METRIC(metaInfo) \
(((metaInfo)->pMeterMeta != NULL) && ((metaInfo)->pMeterMeta->meterType == TSDB_METER_MTABLE))
(((metaInfo)->pMeterMeta != NULL) && ((metaInfo)->pMeterMeta->meterType == TSDB_METER_MTABLE))
...
@@ -95,23 +95,23 @@ SMeterSidExtInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx);
...
@@ -95,23 +95,23 @@ SMeterSidExtInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx);
* @param pSql sql object
* @param pSql sql object
* @return
* @return
*/
*/
bool
tscIsPointInterpQuery
(
S
SqlCmd
*
pCmd
);
bool
tscIsPointInterpQuery
(
S
QueryInfo
*
pQueryInfo
);
bool
tscIsTWAQuery
(
S
SqlCmd
*
pCmd
);
bool
tscIsTWAQuery
(
S
QueryInfo
*
pQueryInfo
);
bool
tscProjectionQueryOnMetric
(
SSqlCmd
*
pCmd
);
bool
tscProjectionQueryOnMetric
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
);
bool
tscProjectionQueryOnTable
(
S
SqlCmd
*
pCmd
);
bool
tscProjectionQueryOnTable
(
S
QueryInfo
*
pQueryInfo
);
bool
tscIsTwoStageMergeMetricQuery
(
SSqlCmd
*
pCmd
);
bool
tscIsTwoStageMergeMetricQuery
(
SSqlCmd
*
pCmd
);
bool
tscQueryOnMetric
(
SSqlCmd
*
pCmd
);
bool
tscQueryOnMetric
(
SSqlCmd
*
pCmd
);
bool
tscQueryMetricTags
(
S
SqlCmd
*
pCmd
);
bool
tscQueryMetricTags
(
S
QueryInfo
*
pQueryInfo
);
bool
tscIsSelectivityWithTagQuery
(
SSqlCmd
*
pCmd
);
bool
tscIsSelectivityWithTagQuery
(
SSqlCmd
*
pCmd
);
void
tscAddSpecialColumnForSelect
(
S
SqlCmd
*
pCmd
,
int32_t
outputColIndex
,
int16_t
functionId
,
SColumnIndex
*
pIndex
,
void
tscAddSpecialColumnForSelect
(
S
QueryInfo
*
pQueryInfo
,
int32_t
outputColIndex
,
int16_t
functionId
,
SColumnIndex
*
pIndex
,
SSchema
*
pColSchema
,
int16_t
isTag
);
SSchema
*
pColSchema
,
int16_t
isTag
);
void
addRequiredTagColumn
(
S
SqlCmd
*
pCmd
,
int32_t
tagColIndex
,
int32_t
tableIndex
);
void
addRequiredTagColumn
(
S
QueryInfo
*
pQueryInfo
,
int32_t
tagColIndex
,
int32_t
tableIndex
);
int32_t
setMeterID
(
SSqlObj
*
pSql
,
SSQLToken
*
pzTableName
,
int32_t
tableIndex
);
int32_t
setMeterID
(
SSqlObj
*
pSql
,
int32_t
subClauseIndex
,
SSQLToken
*
pzTableName
,
int32_t
tableIndex
);
void
tscClearInterpInfo
(
S
SqlCmd
*
pCmd
);
void
tscClearInterpInfo
(
S
QueryInfo
*
pQueryInfo
);
bool
tscIsInsertOrImportData
(
char
*
sqlstr
);
bool
tscIsInsertOrImportData
(
char
*
sqlstr
);
...
@@ -125,30 +125,30 @@ void tscFieldInfoSetValFromField(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIE
...
@@ -125,30 +125,30 @@ void tscFieldInfoSetValFromField(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIE
void
tscFieldInfoSetValue
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
int8_t
type
,
const
char
*
name
,
int16_t
bytes
);
void
tscFieldInfoSetValue
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
int8_t
type
,
const
char
*
name
,
int16_t
bytes
);
void
tscFieldInfoUpdateVisible
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
bool
visible
);
void
tscFieldInfoUpdateVisible
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
bool
visible
);
void
tscFieldInfoCalOffset
(
S
SqlCmd
*
pCmd
);
void
tscFieldInfoCalOffset
(
S
QueryInfo
*
pQueryInfo
);
void
tscFieldInfoUpdateOffset
(
S
SqlCmd
*
pCmd
);
void
tscFieldInfoUpdateOffset
(
S
QueryInfo
*
pQueryInfo
);
void
tscFieldInfoCopy
(
SFieldInfo
*
src
,
SFieldInfo
*
dst
,
const
int32_t
*
indexList
,
int32_t
size
);
void
tscFieldInfoCopy
(
SFieldInfo
*
src
,
SFieldInfo
*
dst
,
const
int32_t
*
indexList
,
int32_t
size
);
void
tscFieldInfoCopyAll
(
SFieldInfo
*
src
,
SFieldInfo
*
dst
);
void
tscFieldInfoCopyAll
(
SFieldInfo
*
src
,
SFieldInfo
*
dst
);
TAOS_FIELD
*
tscFieldInfoGetField
(
S
SqlCmd
*
pCmd
,
int32_t
index
);
TAOS_FIELD
*
tscFieldInfoGetField
(
S
QueryInfo
*
pQueryInfo
,
int32_t
index
);
int16_t
tscFieldInfoGetOffset
(
S
SqlCmd
*
pCmd
,
int32_t
index
);
int16_t
tscFieldInfoGetOffset
(
S
QueryInfo
*
pQueryInfo
,
int32_t
index
);
int32_t
tscGetResRowLength
(
S
SqlCmd
*
pCmd
);
int32_t
tscGetResRowLength
(
S
QueryInfo
*
pQueryInfo
);
void
tscClearFieldInfo
(
SFieldInfo
*
pFieldInfo
);
void
tscClearFieldInfo
(
SFieldInfo
*
pFieldInfo
);
int32_t
tscNumOfFields
(
S
SqlCmd
*
pCmd
);
int32_t
tscNumOfFields
(
S
QueryInfo
*
pQueryInfo
);
void
addExprParams
(
SSqlExpr
*
pExpr
,
char
*
argument
,
int32_t
type
,
int32_t
bytes
,
int16_t
tableIndex
);
void
addExprParams
(
SSqlExpr
*
pExpr
,
char
*
argument
,
int32_t
type
,
int32_t
bytes
,
int16_t
tableIndex
);
SSqlExpr
*
tscSqlExprInsert
(
S
SqlCmd
*
pCmd
,
int32_t
index
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
int16_t
type
,
SSqlExpr
*
tscSqlExprInsert
(
S
QueryInfo
*
pQueryInfo
,
int32_t
index
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
int16_t
type
,
int16_t
size
,
int16_t
interSize
);
int16_t
size
,
int16_t
interSize
);
SSqlExpr
*
tscSqlExprInsertEmpty
(
S
SqlCmd
*
pCmd
,
int32_t
index
,
int16_t
functionId
);
SSqlExpr
*
tscSqlExprInsertEmpty
(
S
QueryInfo
*
pQueryInfo
,
int32_t
index
,
int16_t
functionId
);
SSqlExpr
*
tscSqlExprUpdate
(
S
SqlCmd
*
pCmd
,
int32_t
index
,
int16_t
functionId
,
int16_t
srcColumnIndex
,
int16_t
type
,
SSqlExpr
*
tscSqlExprUpdate
(
S
QueryInfo
*
pQueryInfo
,
int32_t
index
,
int16_t
functionId
,
int16_t
srcColumnIndex
,
int16_t
type
,
int16_t
size
);
int16_t
size
);
SSqlExpr
*
tscSqlExprGet
(
S
SqlCmd
*
pCmd
,
int32_t
index
);
SSqlExpr
*
tscSqlExprGet
(
S
QueryInfo
*
pQueryInfo
,
int32_t
index
);
void
tscSqlExprCopy
(
SSqlExprInfo
*
dst
,
const
SSqlExprInfo
*
src
,
uint64_t
uid
);
void
tscSqlExprCopy
(
SSqlExprInfo
*
dst
,
const
SSqlExprInfo
*
src
,
uint64_t
uid
);
SColumnBase
*
tscColumnBaseInfoInsert
(
S
SqlCmd
*
pCmd
,
SColumnIndex
*
colIndex
);
SColumnBase
*
tscColumnBaseInfoInsert
(
S
QueryInfo
*
pQueryInfo
,
SColumnIndex
*
colIndex
);
void
tscColumnFilterInfoCopy
(
SColumnFilterInfo
*
dst
,
const
SColumnFilterInfo
*
src
);
void
tscColumnFilterInfoCopy
(
SColumnFilterInfo
*
dst
,
const
SColumnFilterInfo
*
src
);
void
tscColumnBaseCopy
(
SColumnBase
*
dst
,
const
SColumnBase
*
src
);
void
tscColumnBaseCopy
(
SColumnBase
*
dst
,
const
SColumnBase
*
src
);
...
@@ -172,31 +172,36 @@ void tsSetMetricQueryCond(STagCond* pTagCond, uint64_t uid, const char* str);
...
@@ -172,31 +172,36 @@ void tsSetMetricQueryCond(STagCond* pTagCond, uint64_t uid, const char* str);
void
tscTagCondCopy
(
STagCond
*
dest
,
const
STagCond
*
src
);
void
tscTagCondCopy
(
STagCond
*
dest
,
const
STagCond
*
src
);
void
tscTagCondRelease
(
STagCond
*
pCond
);
void
tscTagCondRelease
(
STagCond
*
pCond
);
void
tscGetSrcColumnInfo
(
SSrcColumnInfo
*
pColInfo
,
S
SqlCmd
*
pCmd
);
void
tscGetSrcColumnInfo
(
SSrcColumnInfo
*
pColInfo
,
S
QueryInfo
*
pQueryInfo
);
void
tscSetFreeHeatBeat
(
STscObj
*
pObj
);
void
tscSetFreeHeatBeat
(
STscObj
*
pObj
);
bool
tscShouldFreeHeatBeat
(
SSqlObj
*
pHb
);
bool
tscShouldFreeHeatBeat
(
SSqlObj
*
pHb
);
void
tscCleanSqlCmd
(
SSqlCmd
*
pCmd
);
void
tscCleanSqlCmd
(
SSqlCmd
*
pCmd
);
bool
tscShouldFreeAsyncSqlObj
(
SSqlObj
*
pSql
);
bool
tscShouldFreeAsyncSqlObj
(
SSqlObj
*
pSql
);
void
tscRemoveAllMeterMetaInfo
(
SSqlCmd
*
pCmd
,
bool
removeFromCache
);
void
tscRemoveAllMeterMetaInfo
(
SQueryInfo
*
pQueryInfo
,
const
char
*
address
,
bool
removeFromCache
);
SMeterMetaInfo
*
tscGetMeterMetaInfo
(
SSqlCmd
*
pCmd
,
int32_t
index
);
SMeterMetaInfo
*
tscGetMeterMetaInfo
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
,
int32_t
tableIndex
);
SMeterMetaInfo
*
tscGetMeterMetaInfoByUid
(
SSqlCmd
*
pCmd
,
uint64_t
uid
,
int32_t
*
index
);
SMeterMetaInfo
*
tscGetMeterMetaInfoFromQueryInfo
(
SQueryInfo
*
pQueryInfo
,
int32_t
tableIndex
);
SQueryInfo
*
tscGetQueryInfoDetail
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
);
SMeterMetaInfo
*
tscGetMeterMetaInfoByUid
(
SQueryInfo
*
pQueryInfo
,
int32_t
subClauseIndex
,
uint64_t
uid
,
int32_t
*
index
);
void
tscClearMeterMetaInfo
(
SMeterMetaInfo
*
pMeterMetaInfo
,
bool
removeFromCache
);
void
tscClearMeterMetaInfo
(
SMeterMetaInfo
*
pMeterMetaInfo
,
bool
removeFromCache
);
SMeterMetaInfo
*
tscAddMeterMetaInfo
(
SSqlCmd
*
pCmd
,
const
char
*
name
,
SMeterMeta
*
pMeterMeta
,
SMetricMeta
*
pMetricMeta
,
SMeterMetaInfo
*
tscAddMeterMetaInfo
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
,
const
char
*
name
,
SMeterMeta
*
pMeterMeta
,
SMetricMeta
*
pMetricMeta
,
int16_t
numOfTags
,
int16_t
*
tags
);
int16_t
numOfTags
,
int16_t
*
tags
);
SMeterMetaInfo
*
tscAddEmptyMeterMetaInfo
(
SSqlCmd
*
pCmd
);
SMeterMetaInfo
*
tscAddEmptyMeterMetaInfo
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
);
int32_t
tscAddQueryInfo
(
SSqlCmd
*
pCmd
);
int32_t
tscAddSubqueryInfo
(
SSqlCmd
*
pCmd
);
void
tscFreeSubqueryInfo
(
SSqlCmd
*
pCmd
);
void
tscGetMetricMetaCacheKey
(
SSqlCmd
*
pCmd
,
char
*
keyStr
,
uint64_t
uid
);
void
tscGetMetricMetaCacheKey
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
,
char
*
keyStr
,
uint64_t
uid
);
int
tscGetMetricMeta
(
SSqlObj
*
pSql
);
int
tscGetMetricMeta
(
SSqlObj
*
pSql
);
int
tscGetMeterMeta
(
SSqlObj
*
pSql
,
char
*
meterId
,
int32_t
tableIndex
);
int
tscGetMeterMeta
(
SSqlObj
*
pSql
,
char
*
meterId
,
int32_t
tableIndex
);
int
tscGetMeterMetaEx
(
SSqlObj
*
pSql
,
char
*
meterId
,
bool
createIfNotExists
);
int
tscGetMeterMetaEx
(
SSqlObj
*
pSql
,
char
*
meterId
,
bool
createIfNotExists
);
void
tscResetForNextRetrieve
(
SSqlRes
*
pRes
);
void
tscResetForNextRetrieve
(
SSqlRes
*
pRes
);
void
tscAddTimestampColumn
(
S
SqlCmd
*
pCmd
,
int16_t
functionId
,
int16_t
tableIndex
);
void
tscAddTimestampColumn
(
S
QueryInfo
*
pQueryInfo
,
int16_t
functionId
,
int16_t
tableIndex
);
void
tscDoQuery
(
SSqlObj
*
pSql
);
void
tscDoQuery
(
SSqlObj
*
pSql
);
/**
/**
...
@@ -217,9 +222,9 @@ void tscDoQuery(SSqlObj* pSql);
...
@@ -217,9 +222,9 @@ void tscDoQuery(SSqlObj* pSql);
* @return
* @return
*/
*/
SSqlObj
*
createSubqueryObj
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
void
(
*
fp
)(),
void
*
param
,
SSqlObj
*
pPrevSql
);
SSqlObj
*
createSubqueryObj
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
void
(
*
fp
)(),
void
*
param
,
SSqlObj
*
pPrevSql
);
void
addGroupInfoForSubquery
(
SSqlObj
*
pParentObj
,
SSqlObj
*
pSql
,
int32_t
tableIndex
);
void
addGroupInfoForSubquery
(
SSqlObj
*
pParentObj
,
SSqlObj
*
pSql
,
int32_t
subClauseIndex
,
int32_t
tableIndex
);
void
doAddGroupColumnForSubquery
(
S
SqlCmd
*
pCmd
,
int32_t
tagIndex
);
void
doAddGroupColumnForSubquery
(
S
QueryInfo
*
pQueryInfo
,
int32_t
tagIndex
);
int16_t
tscGetJoinTagColIndexByUid
(
STagCond
*
pTagCond
,
uint64_t
uid
);
int16_t
tscGetJoinTagColIndexByUid
(
STagCond
*
pTagCond
,
uint64_t
uid
);
...
@@ -228,7 +233,7 @@ TAOS* taos_connect_a(char* ip, char* user, char* pass, char* db, uint16_t port,
...
@@ -228,7 +233,7 @@ TAOS* taos_connect_a(char* ip, char* user, char* pass, char* db, uint16_t port,
void
sortRemoveDuplicates
(
STableDataBlocks
*
dataBuf
);
void
sortRemoveDuplicates
(
STableDataBlocks
*
dataBuf
);
void
tscPrintSelectClause
(
SSqlCmd
*
pCmd
);
void
tscPrintSelectClause
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/client/inc/tsclient.h
浏览文件 @
e15aa9b1
...
@@ -39,9 +39,9 @@ extern "C" {
...
@@ -39,9 +39,9 @@ extern "C" {
#include "tsqlfunction.h"
#include "tsqlfunction.h"
#include "tutil.h"
#include "tutil.h"
#define TSC_GET_RESPTR_BASE(res,
cmd
, col, ord) \
#define TSC_GET_RESPTR_BASE(res,
_queryinfo
, col, ord) \
((res->data + tscFieldInfoGetOffset(
cmd
, col) * res->numOfRows) + \
((res->data + tscFieldInfoGetOffset(
_queryinfo
, col) * res->numOfRows) + \
(1 - ord.order) * (res->numOfRows - 1) * tscFieldInfoGetField(
cmd
, col)->bytes)
(1 - ord.order) * (res->numOfRows - 1) * tscFieldInfoGetField(
_queryinfo
, col)->bytes)
// forward declaration
// forward declaration
struct
SSqlInfo
;
struct
SSqlInfo
;
...
@@ -208,6 +208,7 @@ typedef struct SDataBlockList {
...
@@ -208,6 +208,7 @@ typedef struct SDataBlockList {
}
SDataBlockList
;
}
SDataBlockList
;
typedef
struct
SQueryInfo
{
typedef
struct
SQueryInfo
{
uint16_t
type
;
// query type
char
intervalTimeUnit
;
char
intervalTimeUnit
;
int64_t
etime
,
stime
;
int64_t
etime
,
stime
;
...
@@ -221,16 +222,18 @@ typedef struct SQueryInfo {
...
@@ -221,16 +222,18 @@ typedef struct SQueryInfo {
SLimitVal
limit
;
SLimitVal
limit
;
SLimitVal
slimit
;
SLimitVal
slimit
;
STagCond
tagCond
;
STagCond
tagCond
;
SOrderVal
order
;
int16_t
interpoType
;
// interpolate type
int16_t
interpoType
;
// interpolate type
int16_t
numOfTables
;
int16_t
numOfTables
;
SMeterMetaInfo
**
pMeterInfo
;
SMeterMetaInfo
**
pMeterInfo
;
struct
STSBuf
*
tsBuf
;
struct
STSBuf
*
tsBuf
;
// todo use dynamic allocated memory for defaultVal
// todo use dynamic allocated memory for defaultVal
int64_t
defaultVal
[
TSDB_MAX_COLUMNS
];
// default value for interpolation
int64_t
defaultVal
[
TSDB_MAX_COLUMNS
];
// default value for interpolation
char
*
msg
;
// pointer to the pCmd->payload to keep error message temporarily
}
SQueryInfo
;
}
SQueryInfo
;
typedef
struct
{
typedef
struct
{
SOrderVal
order
;
//
SOrderVal order;
int
command
;
int
command
;
int
count
;
// TODO refactor
int
count
;
// TODO refactor
...
@@ -241,7 +244,6 @@ typedef struct {
...
@@ -241,7 +244,6 @@ typedef struct {
int8_t
isInsertFromFile
;
// load data from file or not
int8_t
isInsertFromFile
;
// load data from file or not
uint8_t
msgType
;
uint8_t
msgType
;
uint16_t
type
;
// query type
/*
/*
* use to keep short request msg and error msg, in such case, SSqlCmd->payload == SSqlCmd->ext;
* use to keep short request msg and error msg, in such case, SSqlCmd->payload == SSqlCmd->ext;
...
@@ -255,8 +257,8 @@ typedef struct {
...
@@ -255,8 +257,8 @@ typedef struct {
short
numOfCols
;
short
numOfCols
;
int64_t
globalLimit
;
int64_t
globalLimit
;
SQueryInfo
*
pQueryInfo
;
SQueryInfo
*
*
pQueryInfo
;
int32_t
numOf
Queries
;
int32_t
numOf
Clause
;
// char intervalTimeUnit;
// char intervalTimeUnit;
// int64_t etime, stime;
// int64_t etime, stime;
...
@@ -421,12 +423,12 @@ int taos_retrieve(TAOS_RES *res);
...
@@ -421,12 +423,12 @@ int taos_retrieve(TAOS_RES *res);
* transfer function for metric query in stream computing, the function need to be change
* transfer function for metric query in stream computing, the function need to be change
* before send query message to vnode
* before send query message to vnode
*/
*/
int32_t
tscTansformSQLFunctionForMetricQuery
(
S
SqlCmd
*
pCmd
);
int32_t
tscTansformSQLFunctionForMetricQuery
(
S
QueryInfo
*
pQueryInfo
);
void
tscRestoreSQLFunctionForMetricQuery
(
S
SqlCmd
*
pCmd
);
void
tscRestoreSQLFunctionForMetricQuery
(
S
QueryInfo
*
pQueryInfo
);
void
tscClearSqlMetaInfoForce
(
SSqlCmd
*
pCmd
);
void
tscClearSqlMetaInfoForce
(
SSqlCmd
*
pCmd
);
int32_t
tscCreateResPointerInfo
(
S
SqlCmd
*
pCmd
,
SSqlRes
*
pRes
);
int32_t
tscCreateResPointerInfo
(
S
QueryInfo
*
pQueryInfo
,
SSqlRes
*
pRes
);
void
tscDestroyResPointerInfo
(
SSqlRes
*
pRes
);
void
tscDestroyResPointerInfo
(
SSqlRes
*
pRes
);
void
tscFreeSqlCmdData
(
SSqlCmd
*
pCmd
);
void
tscFreeSqlCmdData
(
SSqlCmd
*
pCmd
);
...
@@ -454,6 +456,8 @@ void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowL
...
@@ -454,6 +456,8 @@ void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowL
bool
tscIsUpdateQuery
(
STscObj
*
pObj
);
bool
tscIsUpdateQuery
(
STscObj
*
pObj
);
bool
tscHasReachLimitation
(
SSqlObj
*
pSql
);
bool
tscHasReachLimitation
(
SSqlObj
*
pSql
);
char
*
tscGetErrorMsgPayload
(
SSqlCmd
*
pCmd
);
int32_t
tscInvalidSQLErrMsg
(
char
*
msg
,
const
char
*
additionalInfo
,
const
char
*
sql
);
int32_t
tscInvalidSQLErrMsg
(
char
*
msg
,
const
char
*
additionalInfo
,
const
char
*
sql
);
// transfer SSqlInfo to SqlCmd struct
// transfer SSqlInfo to SqlCmd struct
...
...
src/client/src/sql.c
浏览文件 @
e15aa9b1
...
@@ -122,17 +122,17 @@ typedef union {
...
@@ -122,17 +122,17 @@ typedef union {
#define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo
#define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo
#define ParseARG_STORE yypParser->pInfo = pInfo
#define ParseARG_STORE yypParser->pInfo = pInfo
#define YYFALLBACK 1
#define YYFALLBACK 1
#define YYNSTATE 24
1
#define YYNSTATE 24
6
#define YYNRULE 21
3
#define YYNRULE 21
5
#define YYNTOKEN 197
#define YYNTOKEN 197
#define YY_MAX_SHIFT 24
0
#define YY_MAX_SHIFT 24
5
#define YY_MIN_SHIFTREDUCE 39
1
#define YY_MIN_SHIFTREDUCE 39
8
#define YY_MAX_SHIFTREDUCE 6
03
#define YY_MAX_SHIFTREDUCE 6
12
#define YY_ERROR_ACTION 6
04
#define YY_ERROR_ACTION 6
13
#define YY_ACCEPT_ACTION 6
05
#define YY_ACCEPT_ACTION 6
14
#define YY_NO_ACTION 6
06
#define YY_NO_ACTION 6
15
#define YY_MIN_REDUCE 6
07
#define YY_MIN_REDUCE 6
16
#define YY_MAX_REDUCE 8
19
#define YY_MAX_REDUCE 8
30
/************* End control #defines *******************************************/
/************* End control #defines *******************************************/
/* Define the yytestcase() macro to be a no-op if is not already defined
/* Define the yytestcase() macro to be a no-op if is not already defined
...
@@ -198,115 +198,116 @@ typedef union {
...
@@ -198,115 +198,116 @@ typedef union {
** yy_default[] Default action for each state.
** yy_default[] Default action for each state.
**
**
*********** Begin parsing tables **********************************************/
*********** Begin parsing tables **********************************************/
#define YY_ACTTAB_COUNT (5
16
)
#define YY_ACTTAB_COUNT (5
28
)
static
const
YYACTIONTYPE
yy_action
[]
=
{
static
const
YYACTIONTYPE
yy_action
[]
=
{
/* 0 */
738
,
431
,
129
,
147
,
238
,
10
,
605
,
240
,
129
,
432
,
/* 0 */
749
,
438
,
131
,
149
,
243
,
10
,
614
,
245
,
131
,
439
,
/* 10 */
129
,
151
,
807
,
40
,
42
,
19
,
34
,
35
,
806
,
150
,
/* 10 */
131
,
154
,
818
,
41
,
43
,
20
,
35
,
36
,
817
,
153
,
/* 20 */
807
,
28
,
128
,
431
,
194
,
38
,
36
,
39
,
37
,
133
,
/* 20 */
818
,
29
,
738
,
438
,
199
,
39
,
37
,
40
,
38
,
130
,
/* 30 */
490
,
432
,
93
,
33
,
32
,
97
,
803
,
31
,
30
,
29
,
/* 30 */
497
,
439
,
95
,
34
,
33
,
99
,
150
,
32
,
31
,
30
,
/* 40 */
40
,
42
,
729
,
34
,
35
,
148
,
802
,
159
,
28
,
715
,
/* 40 */
41
,
43
,
738
,
35
,
36
,
151
,
135
,
162
,
29
,
724
,
/* 50 */
735
,
194
,
38
,
36
,
39
,
37
,
181
,
97
,
219
,
218
,
/* 50 */
746
,
199
,
39
,
37
,
40
,
38
,
184
,
99
,
224
,
223
,
/* 60 */
33
,
32
,
158
,
718
,
31
,
30
,
29
,
392
,
393
,
394
,
/* 60 */
34
,
33
,
161
,
727
,
32
,
31
,
30
,
399
,
400
,
401
,
/* 70 */
395
,
396
,
397
,
398
,
399
,
400
,
401
,
402
,
403
,
239
,
/* 70 */
402
,
403
,
404
,
405
,
406
,
407
,
408
,
409
,
410
,
244
,
/* 80 */
718
,
40
,
42
,
182
,
34
,
35
,
209
,
230
,
191
,
28
,
/* 80 */
727
,
41
,
43
,
187
,
35
,
36
,
214
,
814
,
196
,
29
,
/* 90 */
56
,
19
,
194
,
38
,
36
,
39
,
37
,
31
,
30
,
29
,
/* 90 */
58
,
20
,
199
,
39
,
37
,
40
,
38
,
32
,
31
,
30
,
/* 100 */
54
,
33
,
32
,
801
,
718
,
31
,
30
,
29
,
42
,
517
,
/* 100 */
56
,
34
,
33
,
75
,
727
,
32
,
31
,
30
,
43
,
235
,
/* 110 */
34
,
35
,
762
,
16
,
189
,
28
,
19
,
19
,
194
,
38
,
/* 110 */
35
,
36
,
773
,
235
,
194
,
29
,
20
,
20
,
199
,
39
,
/* 120 */
36
,
39
,
37
,
160
,
559
,
715
,
221
,
33
,
32
,
145
,
/* 120 */
37
,
40
,
38
,
163
,
568
,
724
,
226
,
34
,
33
,
438
,
/* 130 */
170
,
31
,
30
,
29
,
232
,
34
,
35
,
178
,
7
,
175
,
/* 130 */
166
,
32
,
31
,
30
,
237
,
35
,
36
,
439
,
7
,
813
,
/* 140 */
28
,
59
,
107
,
194
,
38
,
36
,
39
,
37
,
217
,
222
,
/* 140 */
29
,
61
,
109
,
199
,
39
,
37
,
40
,
38
,
222
,
227
,
/* 150 */
715
,
715
,
33
,
32
,
146
,
716
,
31
,
30
,
29
,
15
,
/* 150 */
724
,
724
,
34
,
33
,
50
,
725
,
32
,
31
,
30
,
15
,
/* 160 */
208
,
231
,
207
,
206
,
205
,
204
,
203
,
202
,
201
,
200
,
/* 160 */
213
,
236
,
212
,
211
,
210
,
209
,
208
,
207
,
206
,
205
,
/* 170 */
700
,
19
,
689
,
690
,
691
,
692
,
693
,
694
,
695
,
696
,
/* 170 */
709
,
51
,
698
,
699
,
700
,
701
,
702
,
703
,
704
,
705
,
/* 180 */
697
,
698
,
699
,
155
,
572
,
431
,
703
,
563
,
702
,
566
,
/* 180 */
706
,
707
,
708
,
158
,
581
,
11
,
812
,
572
,
99
,
575
,
/* 190 */
565
,
569
,
568
,
432
,
38
,
36
,
39
,
37
,
237
,
236
,
/* 190 */
99
,
578
,
167
,
158
,
581
,
221
,
220
,
572
,
16
,
575
,
/* 200 */
414
,
11
,
33
,
32
,
232
,
714
,
31
,
30
,
29
,
110
,
/* 200 */
20
,
578
,
34
,
33
,
144
,
26
,
32
,
31
,
30
,
237
,
/* 210 */
111
,
213
,
62
,
65
,
134
,
152
,
153
,
155
,
572
,
193
,
/* 210 */
86
,
85
,
138
,
173
,
654
,
155
,
156
,
122
,
143
,
198
,
/* 220 */
142
,
563
,
97
,
566
,
58
,
569
,
84
,
83
,
136
,
163
,
/* 220 */
181
,
712
,
178
,
711
,
147
,
155
,
156
,
158
,
581
,
529
,
/* 230 */
506
,
231
,
97
,
503
,
141
,
504
,
26
,
505
,
71
,
75
,
/* 230 */
60
,
572
,
148
,
575
,
723
,
578
,
236
,
16
,
39
,
37
,
/* 240 */
233
,
82
,
74
,
124
,
122
,
234
,
86
,
85
,
77
,
152
,
/* 240 */
40
,
38
,
27
,
772
,
26
,
59
,
34
,
33
,
549
,
550
,
/* 250 */
153
,
155
,
572
,
520
,
564
,
563
,
567
,
566
,
709
,
569
,
/* 250 */
32
,
31
,
30
,
136
,
112
,
113
,
218
,
64
,
67
,
155
,
/* 260 */
25
,
161
,
162
,
46
,
33
,
32
,
73
,
154
,
31
,
30
,
/* 260 */
156
,
94
,
513
,
663
,
183
,
510
,
122
,
511
,
26
,
512
,
/* 270 */
29
,
645
,
230
,
561
,
120
,
540
,
541
,
761
,
41
,
180
,
/* 270 */
521
,
146
,
126
,
124
,
239
,
88
,
87
,
186
,
42
,
157
,
/* 280 */
135
,
47
,
654
,
152
,
153
,
120
,
144
,
57
,
571
,
646
,
/* 280 */
73
,
77
,
238
,
84
,
76
,
570
,
526
,
137
,
42
,
580
,
/* 290 */
164
,
49
,
120
,
216
,
215
,
531
,
532
,
589
,
573
,
44
,
/* 290 */
79
,
17
,
655
,
164
,
165
,
122
,
242
,
241
,
421
,
580
,
/* 300 */
13
,
12
,
12
,
570
,
2
,
137
,
496
,
50
,
138
,
562
,
/* 300 */
47
,
540
,
541
,
598
,
579
,
45
,
13
,
12
,
582
,
574
,
/* 310 */
44
,
495
,
41
,
139
,
198
,
20
,
717
,
510
,
20
,
511
,
/* 310 */
783
,
577
,
12
,
573
,
579
,
576
,
2
,
72
,
71
,
48
,
/* 320 */
140
,
508
,
571
,
509
,
81
,
80
,
131
,
70
,
69
,
127
,
/* 320 */
503
,
571
,
42
,
139
,
45
,
502
,
203
,
9
,
8
,
21
,
/* 330 */
507
,
9
,
8
,
132
,
816
,
130
,
772
,
570
,
771
,
156
,
/* 330 */
21
,
140
,
517
,
580
,
518
,
515
,
141
,
516
,
83
,
82
,
/* 340 */
768
,
767
,
157
,
220
,
737
,
754
,
41
,
94
,
753
,
108
,
/* 340 */
142
,
133
,
129
,
134
,
726
,
132
,
827
,
782
,
579
,
159
,
/* 350 */
109
,
106
,
656
,
199
,
125
,
23
,
571
,
212
,
25
,
214
,
/* 350 */
108
,
779
,
778
,
160
,
748
,
718
,
225
,
96
,
740
,
110
,
/* 360 */
815
,
67
,
814
,
730
,
88
,
812
,
112
,
527
,
674
,
24
,
/* 360 */
765
,
764
,
514
,
111
,
665
,
204
,
26
,
127
,
24
,
217
,
/* 370 */
183
,
570
,
21
,
126
,
643
,
187
,
76
,
641
,
78
,
639
,
/* 370 */
185
,
219
,
826
,
69
,
90
,
825
,
823
,
114
,
683
,
25
,
/* 380 */
51
,
638
,
165
,
728
,
121
,
48
,
98
,
636
,
635
,
634
,
/* 380 */
22
,
128
,
652
,
536
,
78
,
650
,
188
,
80
,
648
,
647
,
/* 390 */
632
,
43
,
625
,
123
,
629
,
99
,
627
,
192
,
741
,
742
,
/* 390 */
168
,
192
,
52
,
737
,
123
,
645
,
644
,
643
,
641
,
634
,
/* 400 */
190
,
188
,
186
,
184
,
27
,
755
,
211
,
72
,
223
,
224
,
/* 400 */
49
,
125
,
44
,
638
,
636
,
100
,
101
,
197
,
195
,
752
,
/* 410 */
225
,
226
,
227
,
228
,
100
,
196
,
229
,
52
,
235
,
603
,
/* 410 */
193
,
753
,
766
,
28
,
191
,
189
,
216
,
74
,
228
,
229
,
/* 420 */
166
,
167
,
143
,
169
,
60
,
63
,
168
,
637
,
602
,
171
,
/* 420 */
230
,
231
,
232
,
201
,
233
,
234
,
53
,
240
,
612
,
169
,
/* 430 */
87
,
172
,
173
,
174
,
115
,
631
,
114
,
675
,
113
,
116
,
/* 430 */
170
,
62
,
145
,
65
,
171
,
172
,
611
,
646
,
174
,
175
,
/* 440 */
117
,
119
,
118
,
89
,
1
,
713
,
103
,
101
,
22
,
102
,
/* 440 */
177
,
176
,
610
,
89
,
117
,
640
,
116
,
684
,
115
,
119
,
/* 450 */
104
,
105
,
601
,
176
,
177
,
594
,
179
,
92
,
55
,
528
,
/* 450 */
118
,
120
,
722
,
121
,
91
,
106
,
102
,
103
,
23
,
104
,
/* 460 */
95
,
149
,
185
,
4
,
533
,
5
,
96
,
61
,
3
,
17
,
/* 460 */
105
,
107
,
1
,
179
,
180
,
603
,
182
,
186
,
523
,
55
,
/* 470 */
574
,
471
,
18
,
14
,
195
,
6
,
197
,
470
,
469
,
468
,
/* 470 */
537
,
97
,
152
,
57
,
190
,
18
,
63
,
542
,
4
,
98
,
/* 480 */
467
,
466
,
465
,
464
,
462
,
44
,
435
,
64
,
437
,
66
,
/* 480 */
5
,
583
,
19
,
3
,
14
,
478
,
6
,
200
,
477
,
202
,
/* 490 */
20
,
210
,
492
,
491
,
489
,
53
,
456
,
45
,
454
,
446
,
/* 490 */
476
,
475
,
474
,
473
,
472
,
471
,
469
,
45
,
442
,
215
,
/* 500 */
68
,
452
,
448
,
450
,
444
,
442
,
463
,
461
,
79
,
417
,
/* 500 */
66
,
444
,
21
,
68
,
46
,
499
,
498
,
496
,
54
,
463
,
/* 510 */
433
,
90
,
407
,
91
,
405
,
607
,
/* 510 */
461
,
453
,
70
,
459
,
455
,
457
,
451
,
449
,
470
,
468
,
/* 520 */
81
,
424
,
440
,
92
,
93
,
414
,
412
,
616
,
};
};
static
const
YYCODETYPE
yy_lookahead
[]
=
{
static
const
YYCODETYPE
yy_lookahead
[]
=
{
/* 0 */
201
,
1
,
250
,
200
,
201
,
250
,
198
,
199
,
250
,
9
,
/* 0 */
201
,
1
,
250
,
200
,
201
,
250
,
198
,
199
,
250
,
9
,
/* 10 */
250
,
259
,
260
,
13
,
14
,
201
,
16
,
17
,
260
,
259
,
/* 10 */
250
,
259
,
260
,
13
,
14
,
201
,
16
,
17
,
260
,
259
,
/* 20 */
260
,
21
,
2
50
,
1
,
24
,
25
,
26
,
27
,
28
,
250
,
/* 20 */
260
,
21
,
2
34
,
1
,
24
,
25
,
26
,
27
,
28
,
250
,
/* 30 */
5
,
9
,
201
,
33
,
34
,
201
,
2
50
,
37
,
38
,
39
,
/* 30 */
5
,
9
,
201
,
33
,
34
,
201
,
2
48
,
37
,
38
,
39
,
/* 40 */
13
,
14
,
234
,
16
,
17
,
218
,
250
,
233
,
21
,
235
,
/* 40 */
13
,
14
,
234
,
16
,
17
,
218
,
250
,
233
,
21
,
235
,
/* 50 */
251
,
24
,
25
,
26
,
27
,
28
,
248
,
201
,
33
,
34
,
/* 50 */
251
,
24
,
25
,
26
,
27
,
28
,
248
,
201
,
33
,
34
,
/* 60 */
33
,
34
,
218
,
236
,
37
,
38
,
39
,
45
,
46
,
47
,
/* 60 */
33
,
34
,
218
,
236
,
37
,
38
,
39
,
45
,
46
,
47
,
/* 70 */
48
,
49
,
50
,
51
,
52
,
53
,
54
,
55
,
56
,
57
,
/* 70 */
48
,
49
,
50
,
51
,
52
,
53
,
54
,
55
,
56
,
57
,
/* 80 */
236
,
13
,
14
,
252
,
16
,
17
,
218
,
78
,
254
,
21
,
/* 80 */
236
,
13
,
14
,
252
,
16
,
17
,
218
,
250
,
254
,
21
,
/* 90 */
256
,
201
,
24
,
25
,
26
,
27
,
28
,
37
,
38
,
39
,
/* 90 */
256
,
201
,
24
,
25
,
26
,
27
,
28
,
37
,
38
,
39
,
/* 100 */
100
,
33
,
34
,
250
,
236
,
37
,
38
,
39
,
14
,
101
,
/* 100 */
100
,
33
,
34
,
72
,
236
,
37
,
38
,
39
,
14
,
78
,
/* 110 */
16
,
17
,
256
,
105
,
258
,
21
,
201
,
201
,
24
,
25
,
/* 110 */
16
,
17
,
256
,
78
,
258
,
21
,
201
,
201
,
24
,
25
,
/* 120 */
26
,
27
,
28
,
233
,
97
,
235
,
201
,
33
,
34
,
250
,
/* 120 */
26
,
27
,
28
,
233
,
97
,
235
,
201
,
33
,
34
,
1
,
/* 130 */
123
,
37
,
38
,
39
,
60
,
16
,
17
,
130
,
96
,
132
,
/* 130 */
63
,
37
,
38
,
39
,
60
,
16
,
17
,
9
,
96
,
250
,
/* 140 */
21
,
99
,
100
,
24
,
25
,
26
,
27
,
28
,
233
,
233
,
/* 140 */
21
,
99
,
100
,
24
,
25
,
26
,
27
,
28
,
233
,
233
,
/* 150 */
235
,
235
,
33
,
34
,
250
,
230
,
37
,
38
,
39
,
85
,
/* 150 */
235
,
235
,
33
,
34
,
101
,
230
,
37
,
38
,
39
,
85
,
/* 160 */
86
,
87
,
88
,
89
,
90
,
91
,
92
,
93
,
94
,
95
,
/* 160 */
86
,
87
,
88
,
89
,
90
,
91
,
92
,
93
,
94
,
95
,
/* 170 */
217
,
201
,
219
,
220
,
221
,
222
,
223
,
224
,
225
,
226
,
/* 170 */
217
,
118
,
219
,
220
,
221
,
222
,
223
,
224
,
225
,
226
,
/* 180 */
227
,
228
,
229
,
1
,
2
,
1
,
219
,
5
,
22
1
,
7
,
/* 180 */
227
,
228
,
229
,
1
,
2
,
44
,
250
,
5
,
20
1
,
7
,
/* 190 */
5
,
9
,
7
,
9
,
25
,
26
,
27
,
28
,
60
,
61
,
/* 190 */
201
,
9
,
125
,
1
,
2
,
128
,
129
,
5
,
96
,
7
,
/* 200 */
62
,
44
,
33
,
34
,
60
,
235
,
37
,
38
,
39
,
64
,
/* 200 */
201
,
9
,
33
,
34
,
63
,
103
,
37
,
38
,
39
,
60
,
/* 210 */
6
5
,
66
,
67
,
68
,
250
,
33
,
34
,
1
,
2
,
37
,
/* 210 */
6
9
,
70
,
71
,
124
,
205
,
33
,
34
,
208
,
77
,
37
,
/* 220 */
63
,
5
,
201
,
7
,
237
,
9
,
69
,
70
,
71
,
63
,
/* 220 */
131
,
219
,
133
,
221
,
250
,
33
,
34
,
1
,
2
,
37
,
/* 230 */
2
,
87
,
201
,
5
,
77
,
7
,
249
,
9
,
64
,
65
,
/* 230 */
237
,
5
,
250
,
7
,
235
,
9
,
87
,
96
,
25
,
26
,
/* 240 */
66
,
67
,
68
,
64
,
65
,
66
,
67
,
68
,
74
,
33
,
/* 240 */
27
,
28
,
249
,
256
,
103
,
256
,
33
,
34
,
113
,
114
,
/* 250 */
3
4
,
1
,
2
,
37
,
5
,
5
,
7
,
7
,
232
,
9
,
/* 250 */
3
7
,
38
,
39
,
250
,
64
,
65
,
66
,
67
,
68
,
33
,
/* 260 */
103
,
33
,
34
,
101
,
33
,
34
,
72
,
59
,
37
,
38
,
/* 260 */
34
,
96
,
2
,
205
,
123
,
5
,
208
,
7
,
103
,
9
,
/* 270 */
39
,
205
,
78
,
1
,
208
,
112
,
113
,
256
,
96
,
122
,
/* 270 */
97
,
130
,
64
,
65
,
66
,
67
,
68
,
104
,
96
,
59
,
/* 280 */
250
,
119
,
205
,
33
,
34
,
208
,
129
,
256
,
106
,
205
,
/* 280 */
64
,
65
,
66
,
67
,
68
,
1
,
101
,
250
,
96
,
107
,
/* 290 */
124
,
101
,
208
,
127
,
128
,
97
,
97
,
97
,
97
,
101
,
/* 290 */
74
,
106
,
205
,
33
,
34
,
208
,
60
,
61
,
62
,
107
,
/* 300 */
101
,
101
,
101
,
121
,
96
,
250
,
97
,
117
,
250
,
37
,
/* 300 */
101
,
97
,
97
,
97
,
122
,
101
,
101
,
101
,
97
,
5
,
/* 310 */
101
,
97
,
96
,
250
,
97
,
101
,
236
,
5
,
101
,
7
,
/* 310 */
231
,
7
,
101
,
5
,
122
,
7
,
96
,
126
,
127
,
120
,
/* 320 */
250
,
5
,
106
,
7
,
72
,
73
,
250
,
125
,
126
,
250
,
/* 320 */
97
,
37
,
96
,
250
,
101
,
97
,
97
,
126
,
127
,
101
,
/* 330 */
10
2
,
125
,
126
,
250
,
236
,
250
,
231
,
121
,
231
,
231
,
/* 330 */
10
1
,
250
,
5
,
107
,
7
,
5
,
250
,
7
,
72
,
73
,
/* 340 */
2
31
,
231
,
231
,
231
,
201
,
257
,
96
,
201
,
257
,
20
1
,
/* 340 */
2
50
,
250
,
250
,
250
,
236
,
250
,
236
,
231
,
122
,
23
1
,
/* 350 */
2
01
,
238
,
201
,
201
,
201
,
201
,
106
,
201
,
103
,
201
,
/* 350 */
2
38
,
231
,
231
,
231
,
201
,
232
,
231
,
201
,
234
,
201
,
/* 360 */
2
01
,
201
,
201
,
234
,
59
,
201
,
201
,
106
,
201
,
201
,
/* 360 */
2
57
,
257
,
102
,
201
,
201
,
201
,
103
,
201
,
201
,
201
,
/* 370 */
2
53
,
121
,
201
,
201
,
201
,
253
,
201
,
201
,
201
,
201
,
/* 370 */
2
34
,
201
,
201
,
201
,
59
,
201
,
201
,
201
,
201
,
201
,
/* 380 */
116
,
201
,
201
,
247
,
201
,
118
,
246
,
201
,
201
,
201
,
/* 380 */
201
,
201
,
201
,
107
,
201
,
201
,
253
,
201
,
201
,
201
,
/* 390 */
201
,
115
,
201
,
201
,
201
,
245
,
201
,
110
,
202
,
202
,
/* 390 */
201
,
253
,
117
,
247
,
201
,
201
,
201
,
201
,
201
,
201
,
/* 400 */
11
4
,
109
,
108
,
107
,
120
,
202
,
75
,
84
,
83
,
49
,
/* 400 */
11
9
,
201
,
116
,
201
,
201
,
246
,
245
,
111
,
115
,
202
,
/* 410 */
80
,
82
,
53
,
81
,
244
,
202
,
79
,
202
,
75
,
5
,
/* 410 */
110
,
202
,
202
,
121
,
109
,
108
,
75
,
84
,
83
,
49
,
/* 420 */
131
,
5
,
202
,
58
,
206
,
206
,
131
,
202
,
5
,
131
,
/* 420 */
80
,
82
,
53
,
202
,
81
,
79
,
202
,
75
,
5
,
132
,
/* 430 */
203
,
5
,
131
,
58
,
210
,
202
,
214
,
216
,
215
,
213
,
/* 430 */
5
,
206
,
202
,
206
,
132
,
58
,
5
,
202
,
132
,
5
,
/* 440 */
211
,
209
,
212
,
203
,
207
,
234
,
241
,
243
,
204
,
242
,
/* 440 */
58
,
132
,
5
,
203
,
210
,
202
,
214
,
216
,
215
,
211
,
/* 450 */
2
40
,
239
,
5
,
131
,
58
,
86
,
123
,
104
,
101
,
97
,
/* 450 */
2
13
,
212
,
234
,
209
,
203
,
240
,
244
,
243
,
204
,
242
,
/* 460 */
96
,
1
,
96
,
111
,
97
,
111
,
96
,
72
,
96
,
101
,
/* 460 */
241
,
239
,
207
,
132
,
58
,
86
,
124
,
104
,
97
,
105
,
/* 470 */
97
,
9
,
101
,
96
,
98
,
96
,
98
,
5
,
5
,
5
,
/* 470 */
97
,
96
,
1
,
101
,
96
,
101
,
72
,
97
,
112
,
96
,
/* 480 */
5
,
1
,
5
,
5
,
5
,
101
,
76
,
72
,
58
,
126
,
/* 480 */
112
,
97
,
101
,
96
,
96
,
9
,
96
,
98
,
5
,
98
,
/* 490 */
101
,
15
,
5
,
5
,
97
,
96
,
5
,
16
,
5
,
5
,
/* 490 */
5
,
5
,
5
,
1
,
5
,
5
,
5
,
101
,
76
,
1
5
,
/* 500 */
126
,
5
,
5
,
5
,
5
,
5
,
5
,
5
,
58
,
58
,
/* 500 */
72
,
58
,
101
,
127
,
16
,
5
,
5
,
97
,
96
,
5
,
/* 510 */
76
,
21
,
59
,
21
,
58
,
0
,
261
,
261
,
261
,
261
,
/* 510 */
5
,
5
,
127
,
5
,
5
,
5
,
5
,
5
,
5
,
5
,
/* 520 */
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
/* 520 */
58
,
58
,
76
,
21
,
21
,
59
,
58
,
0
,
261
,
261
,
/* 530 */
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
/* 530 */
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
/* 540 */
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
/* 540 */
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
/* 550 */
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
/* 550 */
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
...
@@ -325,82 +326,83 @@ static const YYCODETYPE yy_lookahead[] = {
...
@@ -325,82 +326,83 @@ static const YYCODETYPE yy_lookahead[] = {
/* 680 */
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
/* 680 */
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
/* 690 */
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
/* 690 */
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
/* 700 */
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
/* 700 */
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
/* 710 */
261
,
261
,
261
,
/* 710 */
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
261
,
/* 720 */
261
,
261
,
261
,
261
,
261
,
};
};
#define YY_SHIFT_COUNT (24
0
)
#define YY_SHIFT_COUNT (24
5
)
#define YY_SHIFT_MIN (0)
#define YY_SHIFT_MIN (0)
#define YY_SHIFT_MAX (5
15
)
#define YY_SHIFT_MAX (5
27
)
static
const
unsigned
short
int
yy_shift_ofst
[]
=
{
static
const
unsigned
short
int
yy_shift_ofst
[]
=
{
/* 0 */
1
57
,
74
,
182
,
250
,
184
,
184
,
184
,
184
,
184
,
184
,
/* 0 */
1
41
,
74
,
182
,
226
,
128
,
128
,
128
,
128
,
128
,
128
,
/* 10 */
0
,
22
,
2
50
,
228
,
228
,
228
,
184
,
184
,
184
,
184
,
/* 10 */
0
,
22
,
2
26
,
260
,
260
,
260
,
102
,
128
,
128
,
128
,
/* 20 */
1
84
,
194
,
144
,
9
,
9
,
516
,
216
,
250
,
250
,
250
,
/* 20 */
1
28
,
128
,
31
,
149
,
35
,
35
,
528
,
192
,
226
,
226
,
/* 30 */
2
50
,
250
,
250
,
250
,
250
,
250
,
250
,
250
,
250
,
250
,
/* 30 */
2
26
,
226
,
226
,
226
,
226
,
226
,
226
,
226
,
226
,
226
,
/* 40 */
2
50
,
250
,
250
,
250
,
228
,
228
,
25
,
25
,
25
,
25
,
/* 40 */
2
26
,
226
,
226
,
226
,
226
,
260
,
260
,
25
,
25
,
25
,
/* 50 */
25
,
25
,
42
,
25
,
184
,
184
,
163
,
163
,
8
,
184
,
/* 50 */
25
,
25
,
25
,
42
,
25
,
165
,
128
,
128
,
135
,
135
,
/* 60 */
18
4
,
184
,
184
,
184
,
184
,
184
,
184
,
184
,
184
,
184
,
/* 60 */
18
5
,
128
,
128
,
128
,
128
,
128
,
128
,
128
,
128
,
128
,
/* 70 */
1
84
,
184
,
184
,
184
,
184
,
184
,
184
,
184
,
184
,
184
,
/* 70 */
1
28
,
128
,
128
,
128
,
128
,
128
,
128
,
128
,
128
,
128
,
/* 80 */
1
84
,
184
,
184
,
184
,
184
,
184
,
184
,
184
,
184
,
184
,
/* 80 */
1
28
,
128
,
128
,
128
,
128
,
128
,
128
,
128
,
128
,
128
,
/* 90 */
1
84
,
184
,
255
,
305
,
305
,
261
,
261
,
305
,
264
,
267
,
/* 90 */
1
28
,
128
,
128
,
128
,
263
,
315
,
315
,
276
,
276
,
315
,
/* 100 */
27
6
,
287
,
286
,
292
,
294
,
296
,
284
,
255
,
305
,
305
,
/* 100 */
27
5
,
281
,
286
,
296
,
293
,
300
,
305
,
307
,
292
,
263
,
/* 110 */
3
31
,
331
,
305
,
323
,
325
,
360
,
330
,
329
,
359
,
332
,
/* 110 */
3
15
,
315
,
341
,
341
,
315
,
333
,
335
,
370
,
340
,
339
,
/* 120 */
3
37
,
305
,
343
,
305
,
343
,
516
,
516
,
27
,
68
,
68
,
/* 120 */
3
69
,
343
,
346
,
315
,
352
,
315
,
352
,
528
,
528
,
27
,
/* 130 */
68
,
94
,
119
,
169
,
169
,
169
,
174
,
231
,
231
,
231
,
/* 130 */
68
,
68
,
68
,
94
,
119
,
213
,
213
,
213
,
216
,
169
,
/* 140 */
231
,
145
,
179
,
166
,
7
,
60
,
60
,
138
,
198
,
199
,
/* 140 */
169
,
169
,
169
,
190
,
208
,
67
,
89
,
60
,
60
,
236
,
/* 150 */
200
,
201
,
185
,
249
,
272
,
208
,
162
,
190
,
209
,
214
,
/* 150 */
173
,
204
,
205
,
206
,
211
,
304
,
308
,
284
,
220
,
199
,
/* 160 */
217
,
312
,
316
,
202
,
206
,
252
,
414
,
289
,
416
,
295
,
/* 160 */
53
,
223
,
228
,
229
,
327
,
330
,
191
,
201
,
266
,
423
,
/* 170 */
365
,
423
,
298
,
426
,
301
,
375
,
447
,
322
,
396
,
369
,
/* 170 */
297
,
425
,
302
,
377
,
431
,
306
,
434
,
309
,
382
,
437
,
/* 180 */
33
3
,
353
,
357
,
362
,
364
,
460
,
366
,
367
,
370
,
368
,
/* 180 */
33
1
,
406
,
379
,
342
,
363
,
371
,
364
,
372
,
373
,
375
,
/* 190 */
352
,
371
,
354
,
373
,
372
,
377
,
376
,
379
,
378
,
395
,
/* 190 */
471
,
378
,
380
,
383
,
374
,
366
,
381
,
368
,
384
,
387
,
/* 200 */
462
,
472
,
473
,
474
,
475
,
480
,
477
,
478
,
479
,
384
,
/* 200 */
388
,
389
,
390
,
391
,
404
,
476
,
483
,
485
,
486
,
487
,
/* 210 */
4
10
,
476
,
415
,
430
,
481
,
363
,
374
,
389
,
487
,
488
,
/* 210 */
4
92
,
489
,
490
,
491
,
396
,
422
,
484
,
428
,
443
,
488
,
/* 220 */
3
97
,
399
,
389
,
491
,
493
,
494
,
496
,
497
,
498
,
499
,
/* 220 */
3
76
,
385
,
401
,
500
,
501
,
410
,
412
,
401
,
504
,
505
,
/* 230 */
50
0
,
501
,
502
,
450
,
451
,
434
,
490
,
492
,
453
,
456
,
/* 230 */
50
6
,
508
,
509
,
510
,
511
,
512
,
513
,
514
,
462
,
463
,
/* 240 */
515
,
/* 240 */
446
,
502
,
503
,
466
,
468
,
527
,
};
};
#define YY_REDUCE_COUNT (12
6
)
#define YY_REDUCE_COUNT (12
8
)
#define YY_REDUCE_MIN (-248)
#define YY_REDUCE_MIN (-248)
#define YY_REDUCE_MAX (2
44
)
#define YY_REDUCE_MAX (2
55
)
static
const
short
yy_reduce_ofst
[]
=
{
static
const
short
yy_reduce_ofst
[]
=
{
/* 0 */
-
192
,
-
47
,
-
248
,
-
240
,
-
144
,
-
166
,
-
186
,
-
110
,
-
85
,
-
84
,
/* 0 */
-
192
,
-
47
,
-
248
,
-
240
,
-
144
,
-
166
,
-
186
,
-
110
,
-
85
,
-
84
,
/* 10 */
-
201
,
-
197
,
-
242
,
-
173
,
-
156
,
-
132
,
-
169
,
21
,
31
,
-
75
,
/* 10 */
-
201
,
-
197
,
-
242
,
-
173
,
-
156
,
-
132
,
-
212
,
-
169
,
-
13
,
-
11
,
/* 20 */
-
30
,
66
,
-
33
,
77
,
84
,
-
13
,
-
245
,
-
228
,
-
221
,
-
21
4
,
/* 20 */
-
75
,
-
1
,
9
,
2
,
58
,
87
,
-
7
,
-
245
,
-
221
,
-
20
4
,
/* 30 */
-
204
,
-
147
,
-
121
,
-
96
,
-
36
,
30
,
55
,
58
,
63
,
70
,
/* 30 */
-
163
,
-
111
,
-
64
,
-
26
,
-
18
,
3
,
37
,
73
,
81
,
86
,
/* 40 */
76
,
79
,
83
,
85
,
80
,
98
,
105
,
107
,
108
,
109
,
/* 40 */
90
,
91
,
92
,
93
,
95
,
108
,
110
,
79
,
116
,
118
,
/* 50 */
1
10
,
111
,
26
,
112
,
143
,
146
,
88
,
91
,
113
,
148
,
/* 50 */
1
20
,
121
,
122
,
123
,
125
,
124
,
153
,
156
,
103
,
104
,
/* 60 */
1
49
,
151
,
152
,
153
,
154
,
156
,
158
,
159
,
160
,
16
1
,
/* 60 */
1
12
,
158
,
162
,
163
,
164
,
166
,
167
,
168
,
170
,
17
1
,
/* 70 */
1
64
,
165
,
167
,
168
,
171
,
172
,
173
,
175
,
176
,
177
,
/* 70 */
1
72
,
174
,
175
,
176
,
177
,
178
,
179
,
180
,
181
,
183
,
/* 80 */
1
78
,
180
,
181
,
183
,
186
,
187
,
188
,
189
,
191
,
192
,
/* 80 */
1
84
,
186
,
187
,
188
,
189
,
193
,
194
,
195
,
196
,
197
,
/* 90 */
19
3
,
195
,
129
,
196
,
197
,
117
,
122
,
203
,
136
,
14
0
,
/* 90 */
19
8
,
200
,
202
,
203
,
136
,
207
,
209
,
133
,
138
,
21
0
,
/* 100 */
1
50
,
170
,
204
,
207
,
205
,
210
,
212
,
211
,
213
,
215
,
/* 100 */
1
46
,
159
,
161
,
212
,
214
,
217
,
219
,
215
,
222
,
218
,
/* 110 */
2
18
,
219
,
220
,
221
,
223
,
222
,
224
,
226
,
229
,
230
,
/* 110 */
2
21
,
224
,
225
,
227
,
230
,
231
,
233
,
232
,
234
,
237
,
/* 120 */
23
2
,
225
,
227
,
233
,
240
,
237
,
24
4
,
/* 120 */
23
8
,
239
,
244
,
235
,
240
,
243
,
251
,
255
,
25
4
,
};
};
static
const
YYACTIONTYPE
yy_default
[]
=
{
static
const
YYACTIONTYPE
yy_default
[]
=
{
/* 0 */
6
04
,
655
,
809
,
809
,
604
,
604
,
604
,
604
,
604
,
604
,
/* 0 */
6
13
,
664
,
820
,
820
,
613
,
613
,
613
,
613
,
613
,
613
,
/* 10 */
7
39
,
622
,
809
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
/* 10 */
7
50
,
631
,
820
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
/* 20 */
6
04
,
657
,
644
,
657
,
657
,
734
,
604
,
604
,
604
,
604
,
/* 20 */
6
13
,
613
,
666
,
653
,
666
,
666
,
745
,
613
,
613
,
613
,
/* 30 */
6
04
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
/* 30 */
6
13
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
/* 40 */
6
04
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
/* 40 */
6
13
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
/* 50 */
6
04
,
604
,
604
,
604
,
604
,
604
,
758
,
758
,
732
,
604
,
/* 50 */
6
13
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
769
,
769
,
/* 60 */
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
/* 60 */
743
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
/* 70 */
6
04
,
604
,
604
,
604
,
604
,
604
,
642
,
604
,
640
,
604
,
/* 70 */
6
13
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
651
,
613
,
/* 80 */
6
04
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
/* 80 */
6
49
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
/* 90 */
6
04
,
604
,
604
,
624
,
624
,
604
,
604
,
624
,
765
,
769
,
/* 90 */
6
13
,
613
,
613
,
613
,
613
,
633
,
633
,
613
,
613
,
633
,
/* 100 */
7
63
,
751
,
759
,
750
,
746
,
745
,
773
,
604
,
624
,
624
,
/* 100 */
7
76
,
780
,
774
,
762
,
770
,
761
,
757
,
756
,
784
,
613
,
/* 110 */
6
52
,
652
,
624
,
673
,
671
,
669
,
661
,
667
,
663
,
665
,
/* 110 */
6
33
,
633
,
661
,
661
,
633
,
682
,
680
,
678
,
670
,
676
,
/* 120 */
6
59
,
624
,
650
,
624
,
650
,
688
,
701
,
604
,
774
,
808
,
/* 120 */
6
72
,
674
,
668
,
633
,
659
,
633
,
659
,
697
,
710
,
613
,
/* 130 */
7
64
,
792
,
791
,
804
,
798
,
797
,
604
,
796
,
795
,
794
,
/* 130 */
7
85
,
819
,
775
,
803
,
802
,
815
,
809
,
808
,
613
,
807
,
/* 140 */
793
,
604
,
604
,
604
,
604
,
800
,
799
,
604
,
604
,
604
,
/* 140 */
806
,
805
,
804
,
613
,
613
,
613
,
613
,
811
,
810
,
613
,
/* 150 */
6
04
,
604
,
604
,
604
,
604
,
776
,
770
,
766
,
604
,
604
,
/* 150 */
6
13
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
787
,
781
,
/* 160 */
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
/* 160 */
777
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
/* 170 */
6
04
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
/* 170 */
6
13
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
/* 180 */
6
04
,
731
,
740
,
604
,
604
,
604
,
604
,
604
,
604
,
760
,
/* 180 */
6
13
,
613
,
613
,
613
,
742
,
613
,
613
,
751
,
613
,
613
,
/* 190 */
6
04
,
752
,
604
,
604
,
604
,
604
,
604
,
604
,
710
,
604
,
/* 190 */
6
13
,
613
,
613
,
613
,
771
,
613
,
763
,
613
,
613
,
613
,
/* 200 */
6
04
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
676
,
/* 200 */
6
13
,
613
,
613
,
719
,
613
,
613
,
613
,
613
,
613
,
613
,
/* 210 */
6
04
,
604
,
604
,
604
,
604
,
604
,
604
,
813
,
604
,
604
,
/* 210 */
6
13
,
613
,
613
,
613
,
685
,
613
,
613
,
613
,
613
,
613
,
/* 220 */
6
04
,
704
,
811
,
604
,
604
,
604
,
604
,
604
,
604
,
604
,
/* 220 */
6
13
,
613
,
824
,
613
,
613
,
613
,
713
,
822
,
613
,
613
,
/* 230 */
6
04
,
604
,
604
,
604
,
604
,
604
,
628
,
626
,
604
,
620
,
/* 230 */
6
13
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
613
,
/* 240 */
6
04
,
/* 240 */
6
13
,
637
,
635
,
613
,
629
,
613
,
};
};
/********** End of lemon-generated parsing tables *****************************/
/********** End of lemon-generated parsing tables *****************************/
...
@@ -525,6 +527,7 @@ static const YYCODETYPE yyFallback[] = {
...
@@ -525,6 +527,7 @@ static const YYCODETYPE yyFallback[] = {
1
,
/* NULL => ID */
1
,
/* NULL => ID */
0
,
/* SELECT => nothing */
0
,
/* SELECT => nothing */
0
,
/* UNION => nothing */
0
,
/* UNION => nothing */
1
,
/* ALL => ID */
0
,
/* FROM => nothing */
0
,
/* FROM => nothing */
0
,
/* VARIABLE => nothing */
0
,
/* VARIABLE => nothing */
0
,
/* INTERVAL => nothing */
0
,
/* INTERVAL => nothing */
...
@@ -584,7 +587,6 @@ static const YYCODETYPE yyFallback[] = {
...
@@ -584,7 +587,6 @@ static const YYCODETYPE yyFallback[] = {
1
,
/* STATEMENT => ID */
1
,
/* STATEMENT => ID */
1
,
/* TRIGGER => ID */
1
,
/* TRIGGER => ID */
1
,
/* VIEW => ID */
1
,
/* VIEW => ID */
1
,
/* ALL => ID */
1
,
/* COUNT => ID */
1
,
/* COUNT => ID */
1
,
/* SUM => ID */
1
,
/* SUM => ID */
1
,
/* AVG => ID */
1
,
/* AVG => ID */
...
@@ -808,66 +810,66 @@ static const char *const yyTokenName[] = {
...
@@ -808,66 +810,66 @@ static const char *const yyTokenName[] = {
/* 102 */
"NULL"
,
/* 102 */
"NULL"
,
/* 103 */
"SELECT"
,
/* 103 */
"SELECT"
,
/* 104 */
"UNION"
,
/* 104 */
"UNION"
,
/* 105 */
"
FROM
"
,
/* 105 */
"
ALL
"
,
/* 106 */
"
VARIABLE
"
,
/* 106 */
"
FROM
"
,
/* 107 */
"
INTERVAL
"
,
/* 107 */
"
VARIABLE
"
,
/* 108 */
"
FIL
L"
,
/* 108 */
"
INTERVA
L"
,
/* 109 */
"
SLIDING
"
,
/* 109 */
"
FILL
"
,
/* 110 */
"
ORDER
"
,
/* 110 */
"
SLIDING
"
,
/* 111 */
"
BY
"
,
/* 111 */
"
ORDER
"
,
/* 112 */
"
ASC
"
,
/* 112 */
"
BY
"
,
/* 113 */
"
DE
SC"
,
/* 113 */
"
A
SC"
,
/* 114 */
"
GROUP
"
,
/* 114 */
"
DESC
"
,
/* 115 */
"
HAVING
"
,
/* 115 */
"
GROUP
"
,
/* 116 */
"
LIMIT
"
,
/* 116 */
"
HAVING
"
,
/* 117 */
"
OFFSE
T"
,
/* 117 */
"
LIMI
T"
,
/* 118 */
"
SLIMI
T"
,
/* 118 */
"
OFFSE
T"
,
/* 119 */
"S
OFFSE
T"
,
/* 119 */
"S
LIMI
T"
,
/* 120 */
"
WHERE
"
,
/* 120 */
"
SOFFSET
"
,
/* 121 */
"
NOW
"
,
/* 121 */
"
WHERE
"
,
/* 122 */
"
RESET
"
,
/* 122 */
"
NOW
"
,
/* 123 */
"
QUERY
"
,
/* 123 */
"
RESET
"
,
/* 124 */
"
ADD
"
,
/* 124 */
"
QUERY
"
,
/* 125 */
"
COLUMN
"
,
/* 125 */
"
ADD
"
,
/* 126 */
"
TAG
"
,
/* 126 */
"
COLUMN
"
,
/* 127 */
"
CHANGE
"
,
/* 127 */
"
TAG
"
,
/* 128 */
"
SET
"
,
/* 128 */
"
CHANGE
"
,
/* 129 */
"
KILL
"
,
/* 129 */
"
SET
"
,
/* 130 */
"
CONNECTION
"
,
/* 130 */
"
KILL
"
,
/* 131 */
"CO
L
ON"
,
/* 131 */
"CO
NNECTI
ON"
,
/* 132 */
"
STREAM
"
,
/* 132 */
"
COLON
"
,
/* 133 */
"
ABORT
"
,
/* 133 */
"
STREAM
"
,
/* 134 */
"A
FTER
"
,
/* 134 */
"A
BORT
"
,
/* 135 */
"A
TTACH
"
,
/* 135 */
"A
FTER
"
,
/* 136 */
"
BEFORE
"
,
/* 136 */
"
ATTACH
"
,
/* 137 */
"BE
GIN
"
,
/* 137 */
"BE
FORE
"
,
/* 138 */
"
CASCADE
"
,
/* 138 */
"
BEGIN
"
,
/* 139 */
"C
LUSTER
"
,
/* 139 */
"C
ASCADE
"
,
/* 140 */
"C
ONFLICT
"
,
/* 140 */
"C
LUSTER
"
,
/* 141 */
"CO
PY
"
,
/* 141 */
"CO
NFLICT
"
,
/* 142 */
"
DEFERRED
"
,
/* 142 */
"
COPY
"
,
/* 143 */
"DE
LIMITERS
"
,
/* 143 */
"DE
FERRED
"
,
/* 144 */
"DE
TACH
"
,
/* 144 */
"DE
LIMITERS
"
,
/* 145 */
"
E
ACH"
,
/* 145 */
"
DET
ACH"
,
/* 146 */
"E
ND
"
,
/* 146 */
"E
ACH
"
,
/* 147 */
"E
XPLAIN
"
,
/* 147 */
"E
ND
"
,
/* 148 */
"
FAIL
"
,
/* 148 */
"
EXPLAIN
"
,
/* 149 */
"F
OR
"
,
/* 149 */
"F
AIL
"
,
/* 150 */
"
IGNORE
"
,
/* 150 */
"
FOR
"
,
/* 151 */
"I
MMEDIAT
E"
,
/* 151 */
"I
GNOR
E"
,
/* 152 */
"I
NITIALLY
"
,
/* 152 */
"I
MMEDIATE
"
,
/* 153 */
"IN
STEAD
"
,
/* 153 */
"IN
ITIALLY
"
,
/* 154 */
"
MATCH
"
,
/* 154 */
"
INSTEAD
"
,
/* 155 */
"
KEY
"
,
/* 155 */
"
MATCH
"
,
/* 156 */
"
OF
"
,
/* 156 */
"
KEY
"
,
/* 157 */
"
RAISE
"
,
/* 157 */
"
OF
"
,
/* 158 */
"R
EPLAC
E"
,
/* 158 */
"R
AIS
E"
,
/* 159 */
"RE
STRICT
"
,
/* 159 */
"RE
PLACE
"
,
/* 160 */
"R
OW
"
,
/* 160 */
"R
ESTRICT
"
,
/* 161 */
"
STATEMENT
"
,
/* 161 */
"
ROW
"
,
/* 162 */
"
TRIGGER
"
,
/* 162 */
"
STATEMENT
"
,
/* 163 */
"
VIEW
"
,
/* 163 */
"
TRIGGER
"
,
/* 164 */
"
ALL
"
,
/* 164 */
"
VIEW
"
,
/* 165 */
"COUNT"
,
/* 165 */
"COUNT"
,
/* 166 */
"SUM"
,
/* 166 */
"SUM"
,
/* 167 */
"AVG"
,
/* 167 */
"AVG"
,
...
@@ -1094,96 +1096,98 @@ static const char *const yyRuleName[] = {
...
@@ -1094,96 +1096,98 @@ static const char *const yyRuleName[] = {
/* 120 */
"tagitem ::= PLUS FLOAT"
,
/* 120 */
"tagitem ::= PLUS FLOAT"
,
/* 121 */
"select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt"
,
/* 121 */
"select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt"
,
/* 122 */
"union ::= select"
,
/* 122 */
"union ::= select"
,
/* 123 */
"union ::= union UNION select"
,
/* 123 */
"union ::= LP union RP"
,
/* 124 */
"cmd ::= union"
,
/* 124 */
"union ::= union UNION ALL select"
,
/* 125 */
"select ::= SELECT selcollist"
,
/* 125 */
"union ::= union UNION ALL LP select RP"
,
/* 126 */
"sclp ::= selcollist COMMA"
,
/* 126 */
"cmd ::= union"
,
/* 127 */
"sclp ::="
,
/* 127 */
"select ::= SELECT selcollist"
,
/* 128 */
"selcollist ::= sclp expr as"
,
/* 128 */
"sclp ::= selcollist COMMA"
,
/* 129 */
"selcollist ::= sclp STAR"
,
/* 129 */
"sclp ::="
,
/* 130 */
"as ::= AS ids"
,
/* 130 */
"selcollist ::= sclp expr as"
,
/* 131 */
"as ::= ids"
,
/* 131 */
"selcollist ::= sclp STAR"
,
/* 132 */
"as ::="
,
/* 132 */
"as ::= AS ids"
,
/* 133 */
"from ::= FROM tablelist"
,
/* 133 */
"as ::= ids"
,
/* 134 */
"tablelist ::= ids cpxName"
,
/* 134 */
"as ::="
,
/* 135 */
"tablelist ::= tablelist COMMA ids cpxName"
,
/* 135 */
"from ::= FROM tablelist"
,
/* 136 */
"tmvar ::= VARIABLE"
,
/* 136 */
"tablelist ::= ids cpxName"
,
/* 137 */
"interval_opt ::= INTERVAL LP tmvar RP"
,
/* 137 */
"tablelist ::= tablelist COMMA ids cpxName"
,
/* 138 */
"interval_opt ::="
,
/* 138 */
"tmvar ::= VARIABLE"
,
/* 139 */
"fill_opt ::="
,
/* 139 */
"interval_opt ::= INTERVAL LP tmvar RP"
,
/* 140 */
"fill_opt ::= FILL LP ID COMMA tagitemlist RP"
,
/* 140 */
"interval_opt ::="
,
/* 141 */
"fill_opt ::= FILL LP ID RP"
,
/* 141 */
"fill_opt ::="
,
/* 142 */
"sliding_opt ::= SLIDING LP tmvar RP"
,
/* 142 */
"fill_opt ::= FILL LP ID COMMA tagitemlist RP"
,
/* 143 */
"sliding_opt ::="
,
/* 143 */
"fill_opt ::= FILL LP ID RP"
,
/* 144 */
"orderby_opt ::="
,
/* 144 */
"sliding_opt ::= SLIDING LP tmvar RP"
,
/* 145 */
"orderby_opt ::= ORDER BY sortlist"
,
/* 145 */
"sliding_opt ::="
,
/* 146 */
"sortlist ::= sortlist COMMA item sortorder"
,
/* 146 */
"orderby_opt ::="
,
/* 147 */
"sortlist ::= item sortorder"
,
/* 147 */
"orderby_opt ::= ORDER BY sortlist"
,
/* 148 */
"item ::= ids cpxName"
,
/* 148 */
"sortlist ::= sortlist COMMA item sortorder"
,
/* 149 */
"sortorder ::= ASC"
,
/* 149 */
"sortlist ::= item sortorder"
,
/* 150 */
"sortorder ::= DESC"
,
/* 150 */
"item ::= ids cpxName"
,
/* 151 */
"sortorder ::="
,
/* 151 */
"sortorder ::= ASC"
,
/* 152 */
"groupby_opt ::="
,
/* 152 */
"sortorder ::= DESC"
,
/* 153 */
"groupby_opt ::= GROUP BY grouplist"
,
/* 153 */
"sortorder ::="
,
/* 154 */
"grouplist ::= grouplist COMMA item"
,
/* 154 */
"groupby_opt ::="
,
/* 155 */
"grouplist ::= item"
,
/* 155 */
"groupby_opt ::= GROUP BY grouplist"
,
/* 156 */
"having_opt ::="
,
/* 156 */
"grouplist ::= grouplist COMMA item"
,
/* 157 */
"having_opt ::= HAVING expr"
,
/* 157 */
"grouplist ::= item"
,
/* 158 */
"limit_opt ::="
,
/* 158 */
"having_opt ::="
,
/* 159 */
"limit_opt ::= LIMIT signed"
,
/* 159 */
"having_opt ::= HAVING expr"
,
/* 160 */
"limit_opt ::= LIMIT signed OFFSET signed"
,
/* 160 */
"limit_opt ::="
,
/* 161 */
"limit_opt ::= LIMIT signed COMMA signed"
,
/* 161 */
"limit_opt ::= LIMIT signed"
,
/* 162 */
"slimit_opt ::="
,
/* 162 */
"limit_opt ::= LIMIT signed OFFSET signed"
,
/* 163 */
"slimit_opt ::= SLIMIT signed"
,
/* 163 */
"limit_opt ::= LIMIT signed COMMA signed"
,
/* 164 */
"slimit_opt ::= SLIMIT signed SOFFSET signed"
,
/* 164 */
"slimit_opt ::="
,
/* 165 */
"slimit_opt ::= SLIMIT signed COMMA signed"
,
/* 165 */
"slimit_opt ::= SLIMIT signed"
,
/* 166 */
"where_opt ::="
,
/* 166 */
"slimit_opt ::= SLIMIT signed SOFFSET signed"
,
/* 167 */
"where_opt ::= WHERE expr"
,
/* 167 */
"slimit_opt ::= SLIMIT signed COMMA signed"
,
/* 168 */
"expr ::= LP expr RP"
,
/* 168 */
"where_opt ::="
,
/* 169 */
"expr ::= ID"
,
/* 169 */
"where_opt ::= WHERE expr"
,
/* 170 */
"expr ::= ID DOT ID"
,
/* 170 */
"expr ::= LP expr RP"
,
/* 171 */
"expr ::= ID DOT STAR"
,
/* 171 */
"expr ::= ID"
,
/* 172 */
"expr ::= INTEGER"
,
/* 172 */
"expr ::= ID DOT ID"
,
/* 173 */
"expr ::= MINUS INTEGER"
,
/* 173 */
"expr ::= ID DOT STAR"
,
/* 174 */
"expr ::= PLUS INTEGER"
,
/* 174 */
"expr ::= INTEGER"
,
/* 175 */
"expr ::= FLOAT"
,
/* 175 */
"expr ::= MINUS INTEGER"
,
/* 176 */
"expr ::= MINUS FLOAT"
,
/* 176 */
"expr ::= PLUS INTEGER"
,
/* 177 */
"expr ::= PLUS FLOAT"
,
/* 177 */
"expr ::= FLOAT"
,
/* 178 */
"expr ::= STRING"
,
/* 178 */
"expr ::= MINUS FLOAT"
,
/* 179 */
"expr ::= NOW"
,
/* 179 */
"expr ::= PLUS FLOAT"
,
/* 180 */
"expr ::= VARIABLE"
,
/* 180 */
"expr ::= STRING"
,
/* 181 */
"expr ::= BOOL"
,
/* 181 */
"expr ::= NOW"
,
/* 182 */
"expr ::= ID LP exprlist RP"
,
/* 182 */
"expr ::= VARIABLE"
,
/* 183 */
"expr ::= ID LP STAR RP"
,
/* 183 */
"expr ::= BOOL"
,
/* 184 */
"expr ::= expr AND expr"
,
/* 184 */
"expr ::= ID LP exprlist RP"
,
/* 185 */
"expr ::= expr OR expr"
,
/* 185 */
"expr ::= ID LP STAR RP"
,
/* 186 */
"expr ::= expr LT expr"
,
/* 186 */
"expr ::= expr AND expr"
,
/* 187 */
"expr ::= expr GT expr"
,
/* 187 */
"expr ::= expr OR expr"
,
/* 188 */
"expr ::= expr LE expr"
,
/* 188 */
"expr ::= expr LT expr"
,
/* 189 */
"expr ::= expr GE expr"
,
/* 189 */
"expr ::= expr GT expr"
,
/* 190 */
"expr ::= expr NE expr"
,
/* 190 */
"expr ::= expr LE expr"
,
/* 191 */
"expr ::= expr EQ expr"
,
/* 191 */
"expr ::= expr GE expr"
,
/* 192 */
"expr ::= expr PLUS expr"
,
/* 192 */
"expr ::= expr NE expr"
,
/* 193 */
"expr ::= expr MINUS expr"
,
/* 193 */
"expr ::= expr EQ expr"
,
/* 194 */
"expr ::= expr STAR expr"
,
/* 194 */
"expr ::= expr PLUS expr"
,
/* 195 */
"expr ::= expr SLASH expr"
,
/* 195 */
"expr ::= expr MINUS expr"
,
/* 196 */
"expr ::= expr REM expr"
,
/* 196 */
"expr ::= expr STAR expr"
,
/* 197 */
"expr ::= expr LIKE expr"
,
/* 197 */
"expr ::= expr SLASH expr"
,
/* 198 */
"expr ::= expr IN LP exprlist RP"
,
/* 198 */
"expr ::= expr REM expr"
,
/* 199 */
"exprlist ::= exprlist COMMA expritem"
,
/* 199 */
"expr ::= expr LIKE expr"
,
/* 200 */
"exprlist ::= expritem"
,
/* 200 */
"expr ::= expr IN LP exprlist RP"
,
/* 201 */
"expritem ::= expr"
,
/* 201 */
"exprlist ::= exprlist COMMA expritem"
,
/* 202 */
"expritem ::="
,
/* 202 */
"exprlist ::= expritem"
,
/* 203 */
"cmd ::= RESET QUERY CACHE"
,
/* 203 */
"expritem ::= expr"
,
/* 204 */
"cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist"
,
/* 204 */
"expritem ::="
,
/* 205 */
"cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids"
,
/* 205 */
"cmd ::= RESET QUERY CACHE"
,
/* 206 */
"cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist"
,
/* 206 */
"cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist"
,
/* 207 */
"cmd ::= ALTER TABLE ids cpxName DROP TAG ids"
,
/* 207 */
"cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids"
,
/* 208 */
"cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids"
,
/* 208 */
"cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist"
,
/* 209 */
"cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem"
,
/* 209 */
"cmd ::= ALTER TABLE ids cpxName DROP TAG ids"
,
/* 210 */
"cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER"
,
/* 210 */
"cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids"
,
/* 211 */
"cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER"
,
/* 211 */
"cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem"
,
/* 212 */
"cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER"
,
/* 212 */
"cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER"
,
/* 213 */
"cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER"
,
/* 214 */
"cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER"
,
};
};
#endif
/* NDEBUG */
#endif
/* NDEBUG */
...
@@ -1764,96 +1768,98 @@ static const struct {
...
@@ -1764,96 +1768,98 @@ static const struct {
{
236
,
-
2
},
/* (120) tagitem ::= PLUS FLOAT */
{
236
,
-
2
},
/* (120) tagitem ::= PLUS FLOAT */
{
234
,
-
12
},
/* (121) select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */
{
234
,
-
12
},
/* (121) select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */
{
248
,
-
1
},
/* (122) union ::= select */
{
248
,
-
1
},
/* (122) union ::= select */
{
248
,
-
3
},
/* (123) union ::= union UNION select */
{
248
,
-
3
},
/* (123) union ::= LP union RP */
{
199
,
-
1
},
/* (124) cmd ::= union */
{
248
,
-
4
},
/* (124) union ::= union UNION ALL select */
{
234
,
-
2
},
/* (125) select ::= SELECT selcollist */
{
248
,
-
6
},
/* (125) union ::= union UNION ALL LP select RP */
{
249
,
-
2
},
/* (126) sclp ::= selcollist COMMA */
{
199
,
-
1
},
/* (126) cmd ::= union */
{
249
,
0
},
/* (127) sclp ::= */
{
234
,
-
2
},
/* (127) select ::= SELECT selcollist */
{
237
,
-
3
},
/* (128) selcollist ::= sclp expr as */
{
249
,
-
2
},
/* (128) sclp ::= selcollist COMMA */
{
237
,
-
2
},
/* (129) selcollist ::= sclp STAR */
{
249
,
0
},
/* (129) sclp ::= */
{
251
,
-
2
},
/* (130) as ::= AS ids */
{
237
,
-
3
},
/* (130) selcollist ::= sclp expr as */
{
251
,
-
1
},
/* (131) as ::= ids */
{
237
,
-
2
},
/* (131) selcollist ::= sclp STAR */
{
251
,
0
},
/* (132) as ::= */
{
251
,
-
2
},
/* (132) as ::= AS ids */
{
238
,
-
2
},
/* (133) from ::= FROM tablelist */
{
251
,
-
1
},
/* (133) as ::= ids */
{
252
,
-
2
},
/* (134) tablelist ::= ids cpxName */
{
251
,
0
},
/* (134) as ::= */
{
252
,
-
4
},
/* (135) tablelist ::= tablelist COMMA ids cpxName */
{
238
,
-
2
},
/* (135) from ::= FROM tablelist */
{
253
,
-
1
},
/* (136) tmvar ::= VARIABLE */
{
252
,
-
2
},
/* (136) tablelist ::= ids cpxName */
{
240
,
-
4
},
/* (137) interval_opt ::= INTERVAL LP tmvar RP */
{
252
,
-
4
},
/* (137) tablelist ::= tablelist COMMA ids cpxName */
{
240
,
0
},
/* (138) interval_opt ::= */
{
253
,
-
1
},
/* (138) tmvar ::= VARIABLE */
{
241
,
0
},
/* (139) fill_opt ::= */
{
240
,
-
4
},
/* (139) interval_opt ::= INTERVAL LP tmvar RP */
{
241
,
-
6
},
/* (140) fill_opt ::= FILL LP ID COMMA tagitemlist RP */
{
240
,
0
},
/* (140) interval_opt ::= */
{
241
,
-
4
},
/* (141) fill_opt ::= FILL LP ID RP */
{
241
,
0
},
/* (141) fill_opt ::= */
{
242
,
-
4
},
/* (142) sliding_opt ::= SLIDING LP tmvar RP */
{
241
,
-
6
},
/* (142) fill_opt ::= FILL LP ID COMMA tagitemlist RP */
{
242
,
0
},
/* (143) sliding_opt ::= */
{
241
,
-
4
},
/* (143) fill_opt ::= FILL LP ID RP */
{
244
,
0
},
/* (144) orderby_opt ::= */
{
242
,
-
4
},
/* (144) sliding_opt ::= SLIDING LP tmvar RP */
{
244
,
-
3
},
/* (145) orderby_opt ::= ORDER BY sortlist */
{
242
,
0
},
/* (145) sliding_opt ::= */
{
254
,
-
4
},
/* (146) sortlist ::= sortlist COMMA item sortorder */
{
244
,
0
},
/* (146) orderby_opt ::= */
{
254
,
-
2
},
/* (147) sortlist ::= item sortorder */
{
244
,
-
3
},
/* (147) orderby_opt ::= ORDER BY sortlist */
{
256
,
-
2
},
/* (148) item ::= ids cpxName */
{
254
,
-
4
},
/* (148) sortlist ::= sortlist COMMA item sortorder */
{
257
,
-
1
},
/* (149) sortorder ::= ASC */
{
254
,
-
2
},
/* (149) sortlist ::= item sortorder */
{
257
,
-
1
},
/* (150) sortorder ::= DESC */
{
256
,
-
2
},
/* (150) item ::= ids cpxName */
{
257
,
0
},
/* (151) sortorder ::= */
{
257
,
-
1
},
/* (151) sortorder ::= ASC */
{
243
,
0
},
/* (152) groupby_opt ::= */
{
257
,
-
1
},
/* (152) sortorder ::= DESC */
{
243
,
-
3
},
/* (153) groupby_opt ::= GROUP BY grouplist */
{
257
,
0
},
/* (153) sortorder ::= */
{
258
,
-
3
},
/* (154) grouplist ::= grouplist COMMA item */
{
243
,
0
},
/* (154) groupby_opt ::= */
{
258
,
-
1
},
/* (155) grouplist ::= item */
{
243
,
-
3
},
/* (155) groupby_opt ::= GROUP BY grouplist */
{
245
,
0
},
/* (156) having_opt ::= */
{
258
,
-
3
},
/* (156) grouplist ::= grouplist COMMA item */
{
245
,
-
2
},
/* (157) having_opt ::= HAVING expr */
{
258
,
-
1
},
/* (157) grouplist ::= item */
{
247
,
0
},
/* (158) limit_opt ::= */
{
245
,
0
},
/* (158) having_opt ::= */
{
247
,
-
2
},
/* (159) limit_opt ::= LIMIT signed */
{
245
,
-
2
},
/* (159) having_opt ::= HAVING expr */
{
247
,
-
4
},
/* (160) limit_opt ::= LIMIT signed OFFSET signed */
{
247
,
0
},
/* (160) limit_opt ::= */
{
247
,
-
4
},
/* (161) limit_opt ::= LIMIT signed COMMA signed */
{
247
,
-
2
},
/* (161) limit_opt ::= LIMIT signed */
{
246
,
0
},
/* (162) slimit_opt ::= */
{
247
,
-
4
},
/* (162) limit_opt ::= LIMIT signed OFFSET signed */
{
246
,
-
2
},
/* (163) slimit_opt ::= SLIMIT signed */
{
247
,
-
4
},
/* (163) limit_opt ::= LIMIT signed COMMA signed */
{
246
,
-
4
},
/* (164) slimit_opt ::= SLIMIT signed SOFFSET signed */
{
246
,
0
},
/* (164) slimit_opt ::= */
{
246
,
-
4
},
/* (165) slimit_opt ::= SLIMIT signed COMMA signed */
{
246
,
-
2
},
/* (165) slimit_opt ::= SLIMIT signed */
{
239
,
0
},
/* (166) where_opt ::= */
{
246
,
-
4
},
/* (166) slimit_opt ::= SLIMIT signed SOFFSET signed */
{
239
,
-
2
},
/* (167) where_opt ::= WHERE expr */
{
246
,
-
4
},
/* (167) slimit_opt ::= SLIMIT signed COMMA signed */
{
250
,
-
3
},
/* (168) expr ::= LP expr RP */
{
239
,
0
},
/* (168) where_opt ::= */
{
250
,
-
1
},
/* (169) expr ::= ID */
{
239
,
-
2
},
/* (169) where_opt ::= WHERE expr */
{
250
,
-
3
},
/* (170) expr ::= ID DOT ID */
{
250
,
-
3
},
/* (170) expr ::= LP expr RP */
{
250
,
-
3
},
/* (171) expr ::= ID DOT STAR */
{
250
,
-
1
},
/* (171) expr ::= ID */
{
250
,
-
1
},
/* (172) expr ::= INTEGER */
{
250
,
-
3
},
/* (172) expr ::= ID DOT ID */
{
250
,
-
2
},
/* (173) expr ::= MINUS INTEGER */
{
250
,
-
3
},
/* (173) expr ::= ID DOT STAR */
{
250
,
-
2
},
/* (174) expr ::= PLUS INTEGER */
{
250
,
-
1
},
/* (174) expr ::= INTEGER */
{
250
,
-
1
},
/* (175) expr ::= FLOAT */
{
250
,
-
2
},
/* (175) expr ::= MINUS INTEGER */
{
250
,
-
2
},
/* (176) expr ::= MINUS FLOAT */
{
250
,
-
2
},
/* (176) expr ::= PLUS INTEGER */
{
250
,
-
2
},
/* (177) expr ::= PLUS FLOAT */
{
250
,
-
1
},
/* (177) expr ::= FLOAT */
{
250
,
-
1
},
/* (178) expr ::= STRING */
{
250
,
-
2
},
/* (178) expr ::= MINUS FLOAT */
{
250
,
-
1
},
/* (179) expr ::= NOW */
{
250
,
-
2
},
/* (179) expr ::= PLUS FLOAT */
{
250
,
-
1
},
/* (180) expr ::= VARIABLE */
{
250
,
-
1
},
/* (180) expr ::= STRING */
{
250
,
-
1
},
/* (181) expr ::= BOOL */
{
250
,
-
1
},
/* (181) expr ::= NOW */
{
250
,
-
4
},
/* (182) expr ::= ID LP exprlist RP */
{
250
,
-
1
},
/* (182) expr ::= VARIABLE */
{
250
,
-
4
},
/* (183) expr ::= ID LP STAR RP */
{
250
,
-
1
},
/* (183) expr ::= BOOL */
{
250
,
-
3
},
/* (184) expr ::= expr AND expr */
{
250
,
-
4
},
/* (184) expr ::= ID LP exprlist RP */
{
250
,
-
3
},
/* (185) expr ::= expr OR expr */
{
250
,
-
4
},
/* (185) expr ::= ID LP STAR RP */
{
250
,
-
3
},
/* (186) expr ::= expr LT expr */
{
250
,
-
3
},
/* (186) expr ::= expr AND expr */
{
250
,
-
3
},
/* (187) expr ::= expr GT expr */
{
250
,
-
3
},
/* (187) expr ::= expr OR expr */
{
250
,
-
3
},
/* (188) expr ::= expr LE expr */
{
250
,
-
3
},
/* (188) expr ::= expr LT expr */
{
250
,
-
3
},
/* (189) expr ::= expr GE expr */
{
250
,
-
3
},
/* (189) expr ::= expr GT expr */
{
250
,
-
3
},
/* (190) expr ::= expr NE expr */
{
250
,
-
3
},
/* (190) expr ::= expr LE expr */
{
250
,
-
3
},
/* (191) expr ::= expr EQ expr */
{
250
,
-
3
},
/* (191) expr ::= expr GE expr */
{
250
,
-
3
},
/* (192) expr ::= expr PLUS expr */
{
250
,
-
3
},
/* (192) expr ::= expr NE expr */
{
250
,
-
3
},
/* (193) expr ::= expr MINUS expr */
{
250
,
-
3
},
/* (193) expr ::= expr EQ expr */
{
250
,
-
3
},
/* (194) expr ::= expr STAR expr */
{
250
,
-
3
},
/* (194) expr ::= expr PLUS expr */
{
250
,
-
3
},
/* (195) expr ::= expr SLASH expr */
{
250
,
-
3
},
/* (195) expr ::= expr MINUS expr */
{
250
,
-
3
},
/* (196) expr ::= expr REM expr */
{
250
,
-
3
},
/* (196) expr ::= expr STAR expr */
{
250
,
-
3
},
/* (197) expr ::= expr LIKE expr */
{
250
,
-
3
},
/* (197) expr ::= expr SLASH expr */
{
250
,
-
5
},
/* (198) expr ::= expr IN LP exprlist RP */
{
250
,
-
3
},
/* (198) expr ::= expr REM expr */
{
259
,
-
3
},
/* (199) exprlist ::= exprlist COMMA expritem */
{
250
,
-
3
},
/* (199) expr ::= expr LIKE expr */
{
259
,
-
1
},
/* (200) exprlist ::= expritem */
{
250
,
-
5
},
/* (200) expr ::= expr IN LP exprlist RP */
{
260
,
-
1
},
/* (201) expritem ::= expr */
{
259
,
-
3
},
/* (201) exprlist ::= exprlist COMMA expritem */
{
260
,
0
},
/* (202) expritem ::= */
{
259
,
-
1
},
/* (202) exprlist ::= expritem */
{
199
,
-
3
},
/* (203) cmd ::= RESET QUERY CACHE */
{
260
,
-
1
},
/* (203) expritem ::= expr */
{
199
,
-
7
},
/* (204) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */
{
260
,
0
},
/* (204) expritem ::= */
{
199
,
-
7
},
/* (205) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */
{
199
,
-
3
},
/* (205) cmd ::= RESET QUERY CACHE */
{
199
,
-
7
},
/* (206) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */
{
199
,
-
7
},
/* (206) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */
{
199
,
-
7
},
/* (207) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */
{
199
,
-
7
},
/* (207) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */
{
199
,
-
8
},
/* (208) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */
{
199
,
-
7
},
/* (208) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */
{
199
,
-
9
},
/* (209) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */
{
199
,
-
7
},
/* (209) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */
{
199
,
-
5
},
/* (210) cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */
{
199
,
-
8
},
/* (210) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */
{
199
,
-
7
},
/* (211) cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */
{
199
,
-
9
},
/* (211) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */
{
199
,
-
7
},
/* (212) cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */
{
199
,
-
5
},
/* (212) cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */
{
199
,
-
7
},
/* (213) cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */
{
199
,
-
7
},
/* (214) cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */
};
};
static
void
yy_accept
(
yyParser
*
);
/* Forward Declaration */
static
void
yy_accept
(
yyParser
*
);
/* Forward Declaration */
...
@@ -2313,85 +2319,86 @@ static void yy_reduce(
...
@@ -2313,85 +2319,86 @@ static void yy_reduce(
yymsp
[
-
11
].
minor
.
yy138
=
yylhsminor
.
yy138
;
yymsp
[
-
11
].
minor
.
yy138
=
yylhsminor
.
yy138
;
break
;
break
;
case
122
:
/* union ::= select */
case
122
:
/* union ::= select */
{
{
yylhsminor
.
yy117
=
setSubclause
(
NULL
,
yymsp
[
0
].
minor
.
yy138
);
}
yylhsminor
.
yy117
=
setSubclause
(
NULL
,
yymsp
[
0
].
minor
.
yy138
);
}
yymsp
[
0
].
minor
.
yy117
=
yylhsminor
.
yy117
;
yymsp
[
0
].
minor
.
yy117
=
yylhsminor
.
yy117
;
break
;
break
;
case
123
:
/* union ::= union UNION select */
case
123
:
/* union ::= LP union RP */
{
{
yymsp
[
-
2
].
minor
.
yy117
=
yymsp
[
-
1
].
minor
.
yy117
;
}
yylhsminor
.
yy117
=
appendSelectClause
(
yymsp
[
-
2
].
minor
.
yy117
,
yymsp
[
0
].
minor
.
yy138
);
}
yymsp
[
-
2
].
minor
.
yy117
=
yylhsminor
.
yy117
;
break
;
break
;
case
124
:
/* cmd ::= union */
case
124
:
/* union ::= union UNION ALL select */
{
{
yylhsminor
.
yy117
=
appendSelectClause
(
yymsp
[
-
3
].
minor
.
yy117
,
yymsp
[
0
].
minor
.
yy138
);
}
setSQLInfo
(
pInfo
,
yymsp
[
0
].
minor
.
yy117
,
NULL
,
TSDB_SQL_SELECT
);
yymsp
[
-
3
].
minor
.
yy117
=
yylhsminor
.
yy117
;
}
break
;
case
125
:
/* union ::= union UNION ALL LP select RP */
{
yylhsminor
.
yy117
=
appendSelectClause
(
yymsp
[
-
5
].
minor
.
yy117
,
yymsp
[
-
1
].
minor
.
yy138
);
}
yymsp
[
-
5
].
minor
.
yy117
=
yylhsminor
.
yy117
;
break
;
case
126
:
/* cmd ::= union */
{
setSQLInfo
(
pInfo
,
yymsp
[
0
].
minor
.
yy117
,
NULL
,
TSDB_SQL_SELECT
);
}
break
;
break
;
case
12
5
:
/* select ::= SELECT selcollist */
case
12
7
:
/* select ::= SELECT selcollist */
{
{
yylhsminor
.
yy138
=
tSetQuerySQLElems
(
&
yymsp
[
-
1
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy284
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
yylhsminor
.
yy138
=
tSetQuerySQLElems
(
&
yymsp
[
-
1
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy284
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
}
}
yymsp
[
-
1
].
minor
.
yy138
=
yylhsminor
.
yy138
;
yymsp
[
-
1
].
minor
.
yy138
=
yylhsminor
.
yy138
;
break
;
break
;
case
12
6
:
/* sclp ::= selcollist COMMA */
case
12
8
:
/* sclp ::= selcollist COMMA */
{
yylhsminor
.
yy284
=
yymsp
[
-
1
].
minor
.
yy284
;}
{
yylhsminor
.
yy284
=
yymsp
[
-
1
].
minor
.
yy284
;}
yymsp
[
-
1
].
minor
.
yy284
=
yylhsminor
.
yy284
;
yymsp
[
-
1
].
minor
.
yy284
=
yylhsminor
.
yy284
;
break
;
break
;
case
12
7
:
/* sclp ::= */
case
12
9
:
/* sclp ::= */
{
yymsp
[
1
].
minor
.
yy284
=
0
;}
{
yymsp
[
1
].
minor
.
yy284
=
0
;}
break
;
break
;
case
1
28
:
/* selcollist ::= sclp expr as */
case
1
30
:
/* selcollist ::= sclp expr as */
{
{
yylhsminor
.
yy284
=
tSQLExprListAppend
(
yymsp
[
-
2
].
minor
.
yy284
,
yymsp
[
-
1
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy0
.
n
?&
yymsp
[
0
].
minor
.
yy0
:
0
);
yylhsminor
.
yy284
=
tSQLExprListAppend
(
yymsp
[
-
2
].
minor
.
yy284
,
yymsp
[
-
1
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy0
.
n
?&
yymsp
[
0
].
minor
.
yy0
:
0
);
}
}
yymsp
[
-
2
].
minor
.
yy284
=
yylhsminor
.
yy284
;
yymsp
[
-
2
].
minor
.
yy284
=
yylhsminor
.
yy284
;
break
;
break
;
case
1
29
:
/* selcollist ::= sclp STAR */
case
1
31
:
/* selcollist ::= sclp STAR */
{
{
tSQLExpr
*
pNode
=
tSQLExprIdValueCreate
(
NULL
,
TK_ALL
);
tSQLExpr
*
pNode
=
tSQLExprIdValueCreate
(
NULL
,
TK_ALL
);
yylhsminor
.
yy284
=
tSQLExprListAppend
(
yymsp
[
-
1
].
minor
.
yy284
,
pNode
,
0
);
yylhsminor
.
yy284
=
tSQLExprListAppend
(
yymsp
[
-
1
].
minor
.
yy284
,
pNode
,
0
);
}
}
yymsp
[
-
1
].
minor
.
yy284
=
yylhsminor
.
yy284
;
yymsp
[
-
1
].
minor
.
yy284
=
yylhsminor
.
yy284
;
break
;
break
;
case
13
0
:
/* as ::= AS ids */
case
13
2
:
/* as ::= AS ids */
{
yymsp
[
-
1
].
minor
.
yy0
=
yymsp
[
0
].
minor
.
yy0
;
}
{
yymsp
[
-
1
].
minor
.
yy0
=
yymsp
[
0
].
minor
.
yy0
;
}
break
;
break
;
case
13
1
:
/* as ::= ids */
case
13
3
:
/* as ::= ids */
{
yylhsminor
.
yy0
=
yymsp
[
0
].
minor
.
yy0
;
}
{
yylhsminor
.
yy0
=
yymsp
[
0
].
minor
.
yy0
;
}
yymsp
[
0
].
minor
.
yy0
=
yylhsminor
.
yy0
;
yymsp
[
0
].
minor
.
yy0
=
yylhsminor
.
yy0
;
break
;
break
;
case
13
2
:
/* as ::= */
case
13
4
:
/* as ::= */
{
yymsp
[
1
].
minor
.
yy0
.
n
=
0
;
}
{
yymsp
[
1
].
minor
.
yy0
.
n
=
0
;
}
break
;
break
;
case
13
3
:
/* from ::= FROM tablelist */
case
13
5
:
/* from ::= FROM tablelist */
{
yymsp
[
-
1
].
minor
.
yy480
=
yymsp
[
0
].
minor
.
yy480
;}
{
yymsp
[
-
1
].
minor
.
yy480
=
yymsp
[
0
].
minor
.
yy480
;}
break
;
break
;
case
13
4
:
/* tablelist ::= ids cpxName */
case
13
6
:
/* tablelist ::= ids cpxName */
{
toTSDBType
(
yymsp
[
-
1
].
minor
.
yy0
.
type
);
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yylhsminor
.
yy480
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);}
{
toTSDBType
(
yymsp
[
-
1
].
minor
.
yy0
.
type
);
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yylhsminor
.
yy480
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);}
yymsp
[
-
1
].
minor
.
yy480
=
yylhsminor
.
yy480
;
yymsp
[
-
1
].
minor
.
yy480
=
yylhsminor
.
yy480
;
break
;
break
;
case
13
5
:
/* tablelist ::= tablelist COMMA ids cpxName */
case
13
7
:
/* tablelist ::= tablelist COMMA ids cpxName */
{
toTSDBType
(
yymsp
[
-
1
].
minor
.
yy0
.
type
);
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yylhsminor
.
yy480
=
tVariantListAppendToken
(
yymsp
[
-
3
].
minor
.
yy480
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
}
{
toTSDBType
(
yymsp
[
-
1
].
minor
.
yy0
.
type
);
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yylhsminor
.
yy480
=
tVariantListAppendToken
(
yymsp
[
-
3
].
minor
.
yy480
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
}
yymsp
[
-
3
].
minor
.
yy480
=
yylhsminor
.
yy480
;
yymsp
[
-
3
].
minor
.
yy480
=
yylhsminor
.
yy480
;
break
;
break
;
case
13
6
:
/* tmvar ::= VARIABLE */
case
13
8
:
/* tmvar ::= VARIABLE */
{
yylhsminor
.
yy0
=
yymsp
[
0
].
minor
.
yy0
;}
{
yylhsminor
.
yy0
=
yymsp
[
0
].
minor
.
yy0
;}
yymsp
[
0
].
minor
.
yy0
=
yylhsminor
.
yy0
;
yymsp
[
0
].
minor
.
yy0
=
yylhsminor
.
yy0
;
break
;
break
;
case
13
7
:
/* interval_opt ::= INTERVAL LP tmvar RP */
case
13
9
:
/* interval_opt ::= INTERVAL LP tmvar RP */
case
14
2
:
/* sliding_opt ::= SLIDING LP tmvar RP */
yytestcase
(
yyruleno
==
142
);
case
14
4
:
/* sliding_opt ::= SLIDING LP tmvar RP */
yytestcase
(
yyruleno
==
144
);
{
yymsp
[
-
3
].
minor
.
yy0
=
yymsp
[
-
1
].
minor
.
yy0
;
}
{
yymsp
[
-
3
].
minor
.
yy0
=
yymsp
[
-
1
].
minor
.
yy0
;
}
break
;
break
;
case
1
38
:
/* interval_opt ::= */
case
1
40
:
/* interval_opt ::= */
case
14
3
:
/* sliding_opt ::= */
yytestcase
(
yyruleno
==
143
);
case
14
5
:
/* sliding_opt ::= */
yytestcase
(
yyruleno
==
145
);
{
yymsp
[
1
].
minor
.
yy0
.
n
=
0
;
yymsp
[
1
].
minor
.
yy0
.
z
=
NULL
;
yymsp
[
1
].
minor
.
yy0
.
type
=
0
;
}
{
yymsp
[
1
].
minor
.
yy0
.
n
=
0
;
yymsp
[
1
].
minor
.
yy0
.
z
=
NULL
;
yymsp
[
1
].
minor
.
yy0
.
type
=
0
;
}
break
;
break
;
case
1
39
:
/* fill_opt ::= */
case
1
41
:
/* fill_opt ::= */
{
yymsp
[
1
].
minor
.
yy480
=
0
;
}
{
yymsp
[
1
].
minor
.
yy480
=
0
;
}
break
;
break
;
case
14
0
:
/* fill_opt ::= FILL LP ID COMMA tagitemlist RP */
case
14
2
:
/* fill_opt ::= FILL LP ID COMMA tagitemlist RP */
{
{
tVariant
A
=
{
0
};
tVariant
A
=
{
0
};
toTSDBType
(
yymsp
[
-
3
].
minor
.
yy0
.
type
);
toTSDBType
(
yymsp
[
-
3
].
minor
.
yy0
.
type
);
...
@@ -2401,33 +2408,33 @@ static void yy_reduce(
...
@@ -2401,33 +2408,33 @@ static void yy_reduce(
yymsp
[
-
5
].
minor
.
yy480
=
yymsp
[
-
1
].
minor
.
yy480
;
yymsp
[
-
5
].
minor
.
yy480
=
yymsp
[
-
1
].
minor
.
yy480
;
}
}
break
;
break
;
case
14
1
:
/* fill_opt ::= FILL LP ID RP */
case
14
3
:
/* fill_opt ::= FILL LP ID RP */
{
{
toTSDBType
(
yymsp
[
-
1
].
minor
.
yy0
.
type
);
toTSDBType
(
yymsp
[
-
1
].
minor
.
yy0
.
type
);
yymsp
[
-
3
].
minor
.
yy480
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
yymsp
[
-
3
].
minor
.
yy480
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
}
}
break
;
break
;
case
14
4
:
/* orderby_opt ::= */
case
14
6
:
/* orderby_opt ::= */
case
15
2
:
/* groupby_opt ::= */
yytestcase
(
yyruleno
==
152
);
case
15
4
:
/* groupby_opt ::= */
yytestcase
(
yyruleno
==
154
);
{
yymsp
[
1
].
minor
.
yy480
=
0
;}
{
yymsp
[
1
].
minor
.
yy480
=
0
;}
break
;
break
;
case
14
5
:
/* orderby_opt ::= ORDER BY sortlist */
case
14
7
:
/* orderby_opt ::= ORDER BY sortlist */
case
15
3
:
/* groupby_opt ::= GROUP BY grouplist */
yytestcase
(
yyruleno
==
153
);
case
15
5
:
/* groupby_opt ::= GROUP BY grouplist */
yytestcase
(
yyruleno
==
155
);
{
yymsp
[
-
2
].
minor
.
yy480
=
yymsp
[
0
].
minor
.
yy480
;}
{
yymsp
[
-
2
].
minor
.
yy480
=
yymsp
[
0
].
minor
.
yy480
;}
break
;
break
;
case
14
6
:
/* sortlist ::= sortlist COMMA item sortorder */
case
14
8
:
/* sortlist ::= sortlist COMMA item sortorder */
{
{
yylhsminor
.
yy480
=
tVariantListAppend
(
yymsp
[
-
3
].
minor
.
yy480
,
&
yymsp
[
-
1
].
minor
.
yy236
,
yymsp
[
0
].
minor
.
yy220
);
yylhsminor
.
yy480
=
tVariantListAppend
(
yymsp
[
-
3
].
minor
.
yy480
,
&
yymsp
[
-
1
].
minor
.
yy236
,
yymsp
[
0
].
minor
.
yy220
);
}
}
yymsp
[
-
3
].
minor
.
yy480
=
yylhsminor
.
yy480
;
yymsp
[
-
3
].
minor
.
yy480
=
yylhsminor
.
yy480
;
break
;
break
;
case
14
7
:
/* sortlist ::= item sortorder */
case
14
9
:
/* sortlist ::= item sortorder */
{
{
yylhsminor
.
yy480
=
tVariantListAppend
(
NULL
,
&
yymsp
[
-
1
].
minor
.
yy236
,
yymsp
[
0
].
minor
.
yy220
);
yylhsminor
.
yy480
=
tVariantListAppend
(
NULL
,
&
yymsp
[
-
1
].
minor
.
yy236
,
yymsp
[
0
].
minor
.
yy220
);
}
}
yymsp
[
-
1
].
minor
.
yy480
=
yylhsminor
.
yy480
;
yymsp
[
-
1
].
minor
.
yy480
=
yylhsminor
.
yy480
;
break
;
break
;
case
1
48
:
/* item ::= ids cpxName */
case
1
50
:
/* item ::= ids cpxName */
{
{
toTSDBType
(
yymsp
[
-
1
].
minor
.
yy0
.
type
);
toTSDBType
(
yymsp
[
-
1
].
minor
.
yy0
.
type
);
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
...
@@ -2436,196 +2443,196 @@ static void yy_reduce(
...
@@ -2436,196 +2443,196 @@ static void yy_reduce(
}
}
yymsp
[
-
1
].
minor
.
yy236
=
yylhsminor
.
yy236
;
yymsp
[
-
1
].
minor
.
yy236
=
yylhsminor
.
yy236
;
break
;
break
;
case
1
49
:
/* sortorder ::= ASC */
case
1
51
:
/* sortorder ::= ASC */
{
yymsp
[
0
].
minor
.
yy220
=
TSQL_SO_ASC
;
}
{
yymsp
[
0
].
minor
.
yy220
=
TSQL_SO_ASC
;
}
break
;
break
;
case
15
0
:
/* sortorder ::= DESC */
case
15
2
:
/* sortorder ::= DESC */
{
yymsp
[
0
].
minor
.
yy220
=
TSQL_SO_DESC
;}
{
yymsp
[
0
].
minor
.
yy220
=
TSQL_SO_DESC
;}
break
;
break
;
case
15
1
:
/* sortorder ::= */
case
15
3
:
/* sortorder ::= */
{
yymsp
[
1
].
minor
.
yy220
=
TSQL_SO_ASC
;}
{
yymsp
[
1
].
minor
.
yy220
=
TSQL_SO_ASC
;}
break
;
break
;
case
15
4
:
/* grouplist ::= grouplist COMMA item */
case
15
6
:
/* grouplist ::= grouplist COMMA item */
{
{
yylhsminor
.
yy480
=
tVariantListAppend
(
yymsp
[
-
2
].
minor
.
yy480
,
&
yymsp
[
0
].
minor
.
yy236
,
-
1
);
yylhsminor
.
yy480
=
tVariantListAppend
(
yymsp
[
-
2
].
minor
.
yy480
,
&
yymsp
[
0
].
minor
.
yy236
,
-
1
);
}
}
yymsp
[
-
2
].
minor
.
yy480
=
yylhsminor
.
yy480
;
yymsp
[
-
2
].
minor
.
yy480
=
yylhsminor
.
yy480
;
break
;
break
;
case
15
5
:
/* grouplist ::= item */
case
15
7
:
/* grouplist ::= item */
{
{
yylhsminor
.
yy480
=
tVariantListAppend
(
NULL
,
&
yymsp
[
0
].
minor
.
yy236
,
-
1
);
yylhsminor
.
yy480
=
tVariantListAppend
(
NULL
,
&
yymsp
[
0
].
minor
.
yy236
,
-
1
);
}
}
yymsp
[
0
].
minor
.
yy480
=
yylhsminor
.
yy480
;
yymsp
[
0
].
minor
.
yy480
=
yylhsminor
.
yy480
;
break
;
break
;
case
15
6
:
/* having_opt ::= */
case
15
8
:
/* having_opt ::= */
case
16
6
:
/* where_opt ::= */
yytestcase
(
yyruleno
==
166
);
case
16
8
:
/* where_opt ::= */
yytestcase
(
yyruleno
==
168
);
case
20
2
:
/* expritem ::= */
yytestcase
(
yyruleno
==
202
);
case
20
4
:
/* expritem ::= */
yytestcase
(
yyruleno
==
204
);
{
yymsp
[
1
].
minor
.
yy244
=
0
;}
{
yymsp
[
1
].
minor
.
yy244
=
0
;}
break
;
break
;
case
15
7
:
/* having_opt ::= HAVING expr */
case
15
9
:
/* having_opt ::= HAVING expr */
case
16
7
:
/* where_opt ::= WHERE expr */
yytestcase
(
yyruleno
==
167
);
case
16
9
:
/* where_opt ::= WHERE expr */
yytestcase
(
yyruleno
==
169
);
{
yymsp
[
-
1
].
minor
.
yy244
=
yymsp
[
0
].
minor
.
yy244
;}
{
yymsp
[
-
1
].
minor
.
yy244
=
yymsp
[
0
].
minor
.
yy244
;}
break
;
break
;
case
1
58
:
/* limit_opt ::= */
case
1
60
:
/* limit_opt ::= */
case
16
2
:
/* slimit_opt ::= */
yytestcase
(
yyruleno
==
162
);
case
16
4
:
/* slimit_opt ::= */
yytestcase
(
yyruleno
==
164
);
{
yymsp
[
1
].
minor
.
yy162
.
limit
=
-
1
;
yymsp
[
1
].
minor
.
yy162
.
offset
=
0
;}
{
yymsp
[
1
].
minor
.
yy162
.
limit
=
-
1
;
yymsp
[
1
].
minor
.
yy162
.
offset
=
0
;}
break
;
break
;
case
1
59
:
/* limit_opt ::= LIMIT signed */
case
1
61
:
/* limit_opt ::= LIMIT signed */
case
16
3
:
/* slimit_opt ::= SLIMIT signed */
yytestcase
(
yyruleno
==
163
);
case
16
5
:
/* slimit_opt ::= SLIMIT signed */
yytestcase
(
yyruleno
==
165
);
{
yymsp
[
-
1
].
minor
.
yy162
.
limit
=
yymsp
[
0
].
minor
.
yy369
;
yymsp
[
-
1
].
minor
.
yy162
.
offset
=
0
;}
{
yymsp
[
-
1
].
minor
.
yy162
.
limit
=
yymsp
[
0
].
minor
.
yy369
;
yymsp
[
-
1
].
minor
.
yy162
.
offset
=
0
;}
break
;
break
;
case
16
0
:
/* limit_opt ::= LIMIT signed OFFSET signed */
case
16
2
:
/* limit_opt ::= LIMIT signed OFFSET signed */
case
16
4
:
/* slimit_opt ::= SLIMIT signed SOFFSET signed */
yytestcase
(
yyruleno
==
164
);
case
16
6
:
/* slimit_opt ::= SLIMIT signed SOFFSET signed */
yytestcase
(
yyruleno
==
166
);
{
yymsp
[
-
3
].
minor
.
yy162
.
limit
=
yymsp
[
-
2
].
minor
.
yy369
;
yymsp
[
-
3
].
minor
.
yy162
.
offset
=
yymsp
[
0
].
minor
.
yy369
;}
{
yymsp
[
-
3
].
minor
.
yy162
.
limit
=
yymsp
[
-
2
].
minor
.
yy369
;
yymsp
[
-
3
].
minor
.
yy162
.
offset
=
yymsp
[
0
].
minor
.
yy369
;}
break
;
break
;
case
16
1
:
/* limit_opt ::= LIMIT signed COMMA signed */
case
16
3
:
/* limit_opt ::= LIMIT signed COMMA signed */
case
16
5
:
/* slimit_opt ::= SLIMIT signed COMMA signed */
yytestcase
(
yyruleno
==
165
);
case
16
7
:
/* slimit_opt ::= SLIMIT signed COMMA signed */
yytestcase
(
yyruleno
==
167
);
{
yymsp
[
-
3
].
minor
.
yy162
.
limit
=
yymsp
[
0
].
minor
.
yy369
;
yymsp
[
-
3
].
minor
.
yy162
.
offset
=
yymsp
[
-
2
].
minor
.
yy369
;}
{
yymsp
[
-
3
].
minor
.
yy162
.
limit
=
yymsp
[
0
].
minor
.
yy369
;
yymsp
[
-
3
].
minor
.
yy162
.
offset
=
yymsp
[
-
2
].
minor
.
yy369
;}
break
;
break
;
case
1
68
:
/* expr ::= LP expr RP */
case
1
70
:
/* expr ::= LP expr RP */
{
yymsp
[
-
2
].
minor
.
yy244
=
yymsp
[
-
1
].
minor
.
yy244
;
}
{
yymsp
[
-
2
].
minor
.
yy244
=
yymsp
[
-
1
].
minor
.
yy244
;
}
break
;
break
;
case
1
69
:
/* expr ::= ID */
case
1
71
:
/* expr ::= ID */
{
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_ID
);}
{
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_ID
);}
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
17
0
:
/* expr ::= ID DOT ID */
case
17
2
:
/* expr ::= ID DOT ID */
{
yymsp
[
-
2
].
minor
.
yy0
.
n
+=
(
1
+
yymsp
[
0
].
minor
.
yy0
.
n
);
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
-
2
].
minor
.
yy0
,
TK_ID
);}
{
yymsp
[
-
2
].
minor
.
yy0
.
n
+=
(
1
+
yymsp
[
0
].
minor
.
yy0
.
n
);
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
-
2
].
minor
.
yy0
,
TK_ID
);}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
17
1
:
/* expr ::= ID DOT STAR */
case
17
3
:
/* expr ::= ID DOT STAR */
{
yymsp
[
-
2
].
minor
.
yy0
.
n
+=
(
1
+
yymsp
[
0
].
minor
.
yy0
.
n
);
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
-
2
].
minor
.
yy0
,
TK_ALL
);}
{
yymsp
[
-
2
].
minor
.
yy0
.
n
+=
(
1
+
yymsp
[
0
].
minor
.
yy0
.
n
);
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
-
2
].
minor
.
yy0
,
TK_ALL
);}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
17
2
:
/* expr ::= INTEGER */
case
17
4
:
/* expr ::= INTEGER */
{
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_INTEGER
);}
{
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_INTEGER
);}
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
17
3
:
/* expr ::= MINUS INTEGER */
case
17
5
:
/* expr ::= MINUS INTEGER */
case
17
4
:
/* expr ::= PLUS INTEGER */
yytestcase
(
yyruleno
==
174
);
case
17
6
:
/* expr ::= PLUS INTEGER */
yytestcase
(
yyruleno
==
176
);
{
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yymsp
[
-
1
].
minor
.
yy0
.
type
=
TK_INTEGER
;
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
-
1
].
minor
.
yy0
,
TK_INTEGER
);}
{
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yymsp
[
-
1
].
minor
.
yy0
.
type
=
TK_INTEGER
;
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
-
1
].
minor
.
yy0
,
TK_INTEGER
);}
yymsp
[
-
1
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
1
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
17
5
:
/* expr ::= FLOAT */
case
17
7
:
/* expr ::= FLOAT */
{
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_FLOAT
);}
{
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_FLOAT
);}
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
17
6
:
/* expr ::= MINUS FLOAT */
case
17
8
:
/* expr ::= MINUS FLOAT */
case
17
7
:
/* expr ::= PLUS FLOAT */
yytestcase
(
yyruleno
==
177
);
case
17
9
:
/* expr ::= PLUS FLOAT */
yytestcase
(
yyruleno
==
179
);
{
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yymsp
[
-
1
].
minor
.
yy0
.
type
=
TK_FLOAT
;
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
-
1
].
minor
.
yy0
,
TK_FLOAT
);}
{
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yymsp
[
-
1
].
minor
.
yy0
.
type
=
TK_FLOAT
;
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
-
1
].
minor
.
yy0
,
TK_FLOAT
);}
yymsp
[
-
1
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
1
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
1
78
:
/* expr ::= STRING */
case
1
80
:
/* expr ::= STRING */
{
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_STRING
);}
{
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_STRING
);}
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
1
79
:
/* expr ::= NOW */
case
1
81
:
/* expr ::= NOW */
{
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_NOW
);
}
{
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_NOW
);
}
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
18
0
:
/* expr ::= VARIABLE */
case
18
2
:
/* expr ::= VARIABLE */
{
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_VARIABLE
);}
{
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_VARIABLE
);}
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
18
1
:
/* expr ::= BOOL */
case
18
3
:
/* expr ::= BOOL */
{
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_BOOL
);}
{
yylhsminor
.
yy244
=
tSQLExprIdValueCreate
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_BOOL
);}
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
18
2
:
/* expr ::= ID LP exprlist RP */
case
18
4
:
/* expr ::= ID LP exprlist RP */
{
{
yylhsminor
.
yy244
=
tSQLExprCreateFunction
(
yymsp
[
-
1
].
minor
.
yy284
,
&
yymsp
[
-
3
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy0
,
yymsp
[
-
3
].
minor
.
yy0
.
type
);
yylhsminor
.
yy244
=
tSQLExprCreateFunction
(
yymsp
[
-
1
].
minor
.
yy284
,
&
yymsp
[
-
3
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy0
,
yymsp
[
-
3
].
minor
.
yy0
.
type
);
}
}
yymsp
[
-
3
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
3
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
18
3
:
/* expr ::= ID LP STAR RP */
case
18
5
:
/* expr ::= ID LP STAR RP */
{
{
yylhsminor
.
yy244
=
tSQLExprCreateFunction
(
NULL
,
&
yymsp
[
-
3
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy0
,
yymsp
[
-
3
].
minor
.
yy0
.
type
);
yylhsminor
.
yy244
=
tSQLExprCreateFunction
(
NULL
,
&
yymsp
[
-
3
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy0
,
yymsp
[
-
3
].
minor
.
yy0
.
type
);
}
}
yymsp
[
-
3
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
3
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
18
4
:
/* expr ::= expr AND expr */
case
18
6
:
/* expr ::= expr AND expr */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_AND
);}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_AND
);}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
18
5
:
/* expr ::= expr OR expr */
case
18
7
:
/* expr ::= expr OR expr */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_OR
);
}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_OR
);
}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
18
6
:
/* expr ::= expr LT expr */
case
18
8
:
/* expr ::= expr LT expr */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_LT
);}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_LT
);}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
18
7
:
/* expr ::= expr GT expr */
case
18
9
:
/* expr ::= expr GT expr */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_GT
);}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_GT
);}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
1
88
:
/* expr ::= expr LE expr */
case
1
90
:
/* expr ::= expr LE expr */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_LE
);}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_LE
);}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
1
89
:
/* expr ::= expr GE expr */
case
1
91
:
/* expr ::= expr GE expr */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_GE
);}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_GE
);}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
19
0
:
/* expr ::= expr NE expr */
case
19
2
:
/* expr ::= expr NE expr */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_NE
);}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_NE
);}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
19
1
:
/* expr ::= expr EQ expr */
case
19
3
:
/* expr ::= expr EQ expr */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_EQ
);}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_EQ
);}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
19
2
:
/* expr ::= expr PLUS expr */
case
19
4
:
/* expr ::= expr PLUS expr */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_PLUS
);
}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_PLUS
);
}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
19
3
:
/* expr ::= expr MINUS expr */
case
19
5
:
/* expr ::= expr MINUS expr */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_MINUS
);
}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_MINUS
);
}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
19
4
:
/* expr ::= expr STAR expr */
case
19
6
:
/* expr ::= expr STAR expr */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_STAR
);
}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_STAR
);
}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
19
5
:
/* expr ::= expr SLASH expr */
case
19
7
:
/* expr ::= expr SLASH expr */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_DIVIDE
);}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_DIVIDE
);}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
19
6
:
/* expr ::= expr REM expr */
case
19
8
:
/* expr ::= expr REM expr */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_REM
);
}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_REM
);
}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
19
7
:
/* expr ::= expr LIKE expr */
case
19
9
:
/* expr ::= expr LIKE expr */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_LIKE
);
}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
2
].
minor
.
yy244
,
yymsp
[
0
].
minor
.
yy244
,
TK_LIKE
);
}
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
2
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
198
:
/* expr ::= expr IN LP exprlist RP */
case
200
:
/* expr ::= expr IN LP exprlist RP */
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
4
].
minor
.
yy244
,
(
tSQLExpr
*
)
yymsp
[
-
1
].
minor
.
yy284
,
TK_IN
);
}
{
yylhsminor
.
yy244
=
tSQLExprCreate
(
yymsp
[
-
4
].
minor
.
yy244
,
(
tSQLExpr
*
)
yymsp
[
-
1
].
minor
.
yy284
,
TK_IN
);
}
yymsp
[
-
4
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
-
4
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
199
:
/* exprlist ::= exprlist COMMA expritem */
case
201
:
/* exprlist ::= exprlist COMMA expritem */
{
yylhsminor
.
yy284
=
tSQLExprListAppend
(
yymsp
[
-
2
].
minor
.
yy284
,
yymsp
[
0
].
minor
.
yy244
,
0
);}
{
yylhsminor
.
yy284
=
tSQLExprListAppend
(
yymsp
[
-
2
].
minor
.
yy284
,
yymsp
[
0
].
minor
.
yy244
,
0
);}
yymsp
[
-
2
].
minor
.
yy284
=
yylhsminor
.
yy284
;
yymsp
[
-
2
].
minor
.
yy284
=
yylhsminor
.
yy284
;
break
;
break
;
case
20
0
:
/* exprlist ::= expritem */
case
20
2
:
/* exprlist ::= expritem */
{
yylhsminor
.
yy284
=
tSQLExprListAppend
(
0
,
yymsp
[
0
].
minor
.
yy244
,
0
);}
{
yylhsminor
.
yy284
=
tSQLExprListAppend
(
0
,
yymsp
[
0
].
minor
.
yy244
,
0
);}
yymsp
[
0
].
minor
.
yy284
=
yylhsminor
.
yy284
;
yymsp
[
0
].
minor
.
yy284
=
yylhsminor
.
yy284
;
break
;
break
;
case
20
1
:
/* expritem ::= expr */
case
20
3
:
/* expritem ::= expr */
{
yylhsminor
.
yy244
=
yymsp
[
0
].
minor
.
yy244
;}
{
yylhsminor
.
yy244
=
yymsp
[
0
].
minor
.
yy244
;}
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
yymsp
[
0
].
minor
.
yy244
=
yylhsminor
.
yy244
;
break
;
break
;
case
20
3
:
/* cmd ::= RESET QUERY CACHE */
case
20
5
:
/* cmd ::= RESET QUERY CACHE */
{
setDCLSQLElems
(
pInfo
,
TSDB_SQL_RESET_CACHE
,
0
);}
{
setDCLSQLElems
(
pInfo
,
TSDB_SQL_RESET_CACHE
,
0
);}
break
;
break
;
case
20
4
:
/* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */
case
20
6
:
/* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */
{
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
SAlterTableSQL
*
pAlterTable
=
tAlterTableSQLElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy421
,
NULL
,
TSDB_ALTER_TABLE_ADD_COLUMN
);
SAlterTableSQL
*
pAlterTable
=
tAlterTableSQLElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy421
,
NULL
,
TSDB_ALTER_TABLE_ADD_COLUMN
);
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
}
break
;
break
;
case
20
5
:
/* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */
case
20
7
:
/* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */
{
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
...
@@ -2636,14 +2643,14 @@ static void yy_reduce(
...
@@ -2636,14 +2643,14 @@ static void yy_reduce(
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
}
break
;
break
;
case
20
6
:
/* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */
case
20
8
:
/* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */
{
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
SAlterTableSQL
*
pAlterTable
=
tAlterTableSQLElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy421
,
NULL
,
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
);
SAlterTableSQL
*
pAlterTable
=
tAlterTableSQLElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy421
,
NULL
,
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
);
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
}
break
;
break
;
case
20
7
:
/* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */
case
20
9
:
/* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */
{
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
...
@@ -2654,7 +2661,7 @@ static void yy_reduce(
...
@@ -2654,7 +2661,7 @@ static void yy_reduce(
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
}
break
;
break
;
case
2
08
:
/* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */
case
2
10
:
/* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */
{
{
yymsp
[
-
5
].
minor
.
yy0
.
n
+=
yymsp
[
-
4
].
minor
.
yy0
.
n
;
yymsp
[
-
5
].
minor
.
yy0
.
n
+=
yymsp
[
-
4
].
minor
.
yy0
.
n
;
...
@@ -2668,7 +2675,7 @@ static void yy_reduce(
...
@@ -2668,7 +2675,7 @@ static void yy_reduce(
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
}
break
;
break
;
case
2
09
:
/* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */
case
2
11
:
/* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */
{
{
yymsp
[
-
6
].
minor
.
yy0
.
n
+=
yymsp
[
-
5
].
minor
.
yy0
.
n
;
yymsp
[
-
6
].
minor
.
yy0
.
n
+=
yymsp
[
-
5
].
minor
.
yy0
.
n
;
...
@@ -2680,13 +2687,13 @@ static void yy_reduce(
...
@@ -2680,13 +2687,13 @@ static void yy_reduce(
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
}
break
;
break
;
case
21
0
:
/* cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */
case
21
2
:
/* cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */
{
yymsp
[
-
2
].
minor
.
yy0
.
n
+=
(
yymsp
[
-
1
].
minor
.
yy0
.
n
+
yymsp
[
0
].
minor
.
yy0
.
n
);
setKillSQL
(
pInfo
,
TSDB_SQL_KILL_CONNECTION
,
&
yymsp
[
-
2
].
minor
.
yy0
);}
{
yymsp
[
-
2
].
minor
.
yy0
.
n
+=
(
yymsp
[
-
1
].
minor
.
yy0
.
n
+
yymsp
[
0
].
minor
.
yy0
.
n
);
setKillSQL
(
pInfo
,
TSDB_SQL_KILL_CONNECTION
,
&
yymsp
[
-
2
].
minor
.
yy0
);}
break
;
break
;
case
21
1
:
/* cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */
case
21
3
:
/* cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
(
yymsp
[
-
3
].
minor
.
yy0
.
n
+
yymsp
[
-
2
].
minor
.
yy0
.
n
+
yymsp
[
-
1
].
minor
.
yy0
.
n
+
yymsp
[
0
].
minor
.
yy0
.
n
);
setKillSQL
(
pInfo
,
TSDB_SQL_KILL_STREAM
,
&
yymsp
[
-
4
].
minor
.
yy0
);}
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
(
yymsp
[
-
3
].
minor
.
yy0
.
n
+
yymsp
[
-
2
].
minor
.
yy0
.
n
+
yymsp
[
-
1
].
minor
.
yy0
.
n
+
yymsp
[
0
].
minor
.
yy0
.
n
);
setKillSQL
(
pInfo
,
TSDB_SQL_KILL_STREAM
,
&
yymsp
[
-
4
].
minor
.
yy0
);}
break
;
break
;
case
21
2
:
/* cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */
case
21
4
:
/* cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
(
yymsp
[
-
3
].
minor
.
yy0
.
n
+
yymsp
[
-
2
].
minor
.
yy0
.
n
+
yymsp
[
-
1
].
minor
.
yy0
.
n
+
yymsp
[
0
].
minor
.
yy0
.
n
);
setKillSQL
(
pInfo
,
TSDB_SQL_KILL_QUERY
,
&
yymsp
[
-
4
].
minor
.
yy0
);}
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
(
yymsp
[
-
3
].
minor
.
yy0
.
n
+
yymsp
[
-
2
].
minor
.
yy0
.
n
+
yymsp
[
-
1
].
minor
.
yy0
.
n
+
yymsp
[
0
].
minor
.
yy0
.
n
);
setKillSQL
(
pInfo
,
TSDB_SQL_KILL_QUERY
,
&
yymsp
[
-
4
].
minor
.
yy0
);}
break
;
break
;
default:
default:
...
...
src/client/src/tscAsync.c
浏览文件 @
e15aa9b1
...
@@ -118,10 +118,12 @@ static void tscProcessAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOf
...
@@ -118,10 +118,12 @@ static void tscProcessAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOf
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
// sequentially retrieve data from remain vnodes first, query vnode specified by vnodeIdx
// sequentially retrieve data from remain vnodes first, query vnode specified by vnodeIdx
if
(
numOfRows
==
0
&&
tscProjectionQueryOnMetric
(
pCmd
))
{
if
(
numOfRows
==
0
&&
tscProjectionQueryOnMetric
(
pCmd
,
0
))
{
// vnode is denoted by vnodeIdx, continue to query vnode specified by vnodeIdx
// vnode is denoted by vnodeIdx, continue to query vnode specified by vnodeIdx
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
0
);
assert
(
pMeterMetaInfo
->
vnodeIndex
>=
0
);
assert
(
pMeterMetaInfo
->
vnodeIndex
>=
0
);
/* reach the maximum number of output rows, abort */
/* reach the maximum number of output rows, abort */
...
@@ -131,8 +133,9 @@ static void tscProcessAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOf
...
@@ -131,8 +133,9 @@ static void tscProcessAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOf
}
}
/* update the limit value according to current retrieval results */
/* update the limit value according to current retrieval results */
pCmd
->
pQueryInfo
->
limit
.
limit
=
pCmd
->
globalLimit
-
pRes
->
numOfTotal
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
pCmd
->
pQueryInfo
->
limit
.
offset
=
pRes
->
offset
;
pQueryInfo
->
limit
.
limit
=
pCmd
->
globalLimit
-
pRes
->
numOfTotal
;
pQueryInfo
->
limit
.
offset
=
pRes
->
offset
;
if
((
++
(
pMeterMetaInfo
->
vnodeIndex
))
<
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
)
{
if
((
++
(
pMeterMetaInfo
->
vnodeIndex
))
<
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
)
{
tscTrace
(
"%p retrieve data from next vnode:%d"
,
pSql
,
pMeterMetaInfo
->
vnodeIndex
);
tscTrace
(
"%p retrieve data from next vnode:%d"
,
pSql
,
pMeterMetaInfo
->
vnodeIndex
);
...
@@ -266,13 +269,14 @@ void tscProcessAsyncRetrieve(void *param, TAOS_RES *tres, int numOfRows) {
...
@@ -266,13 +269,14 @@ void tscProcessAsyncRetrieve(void *param, TAOS_RES *tres, int numOfRows) {
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
if
(
numOfRows
==
0
)
{
if
(
numOfRows
==
0
)
{
// sequentially retrieve data from remain vnodes.
// sequentially retrieve data from remain vnodes.
if
(
tscProjectionQueryOnMetric
(
pCmd
))
{
if
(
tscProjectionQueryOnMetric
(
pCmd
,
0
))
{
/*
/*
* vnode is denoted by vnodeIdx, continue to query vnode specified by vnodeIdx till all vnode have been retrieved
* vnode is denoted by vnodeIdx, continue to query vnode specified by vnodeIdx till all vnode have been retrieved
*/
*/
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
assert
(
pMeterMetaInfo
->
vnodeIndex
>=
0
);
assert
(
pMeterMetaInfo
->
vnodeIndex
>=
0
);
/* reach the maximum number of output rows, abort */
/* reach the maximum number of output rows, abort */
...
@@ -282,7 +286,8 @@ void tscProcessAsyncRetrieve(void *param, TAOS_RES *tres, int numOfRows) {
...
@@ -282,7 +286,8 @@ void tscProcessAsyncRetrieve(void *param, TAOS_RES *tres, int numOfRows) {
}
}
/* update the limit value according to current retrieval results */
/* update the limit value according to current retrieval results */
pCmd
->
pQueryInfo
->
limit
.
limit
=
pCmd
->
globalLimit
-
pRes
->
numOfTotal
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
pQueryInfo
->
limit
.
limit
=
pCmd
->
globalLimit
-
pRes
->
numOfTotal
;
if
((
++
pMeterMetaInfo
->
vnodeIndex
)
<=
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
)
{
if
((
++
pMeterMetaInfo
->
vnodeIndex
)
<=
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
)
{
pSql
->
cmd
.
command
=
TSDB_SQL_SELECT
;
// reset flag to launch query first.
pSql
->
cmd
.
command
=
TSDB_SQL_SELECT
;
// reset flag to launch query first.
...
@@ -297,7 +302,7 @@ void tscProcessAsyncRetrieve(void *param, TAOS_RES *tres, int numOfRows) {
...
@@ -297,7 +302,7 @@ void tscProcessAsyncRetrieve(void *param, TAOS_RES *tres, int numOfRows) {
}
}
}
else
{
}
else
{
for
(
int
i
=
0
;
i
<
pCmd
->
numOfCols
;
++
i
)
for
(
int
i
=
0
;
i
<
pCmd
->
numOfCols
;
++
i
)
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
p
Cmd
,
i
,
pCmd
->
order
)
+
pRes
->
bytes
[
i
]
*
pRes
->
row
;
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
p
QueryInfo
,
i
,
pQueryInfo
->
order
)
+
pRes
->
bytes
[
i
]
*
pRes
->
row
;
pRes
->
row
++
;
pRes
->
row
++
;
(
*
pSql
->
fetchFp
)(
pSql
->
param
,
pSql
,
pSql
->
res
.
tsrow
);
(
*
pSql
->
fetchFp
)(
pSql
->
param
,
pSql
,
pSql
->
res
.
tsrow
);
...
@@ -308,9 +313,13 @@ void tscProcessFetchRow(SSchedMsg *pMsg) {
...
@@ -308,9 +313,13 @@ void tscProcessFetchRow(SSchedMsg *pMsg) {
SSqlObj
*
pSql
=
(
SSqlObj
*
)
pMsg
->
ahandle
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
pMsg
->
ahandle
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
assert
(
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
assert
(
pCmd
->
numOfCols
==
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
);
for
(
int
i
=
0
;
i
<
pCmd
->
numOfCols
;
++
i
)
for
(
int
i
=
0
;
i
<
pCmd
->
numOfCols
;
++
i
)
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
p
Cmd
,
i
,
pCmd
->
order
)
+
pRes
->
bytes
[
i
]
*
pRes
->
row
;
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
p
QueryInfo
,
i
,
pQueryInfo
->
order
)
+
pRes
->
bytes
[
i
]
*
pRes
->
row
;
pRes
->
row
++
;
pRes
->
row
++
;
(
*
pSql
->
fetchFp
)(
pSql
->
param
,
pSql
,
pRes
->
tsrow
);
(
*
pSql
->
fetchFp
)(
pSql
->
param
,
pSql
,
pRes
->
tsrow
);
...
@@ -406,8 +415,11 @@ void tscAsyncInsertMultiVnodesProxy(void *param, TAOS_RES *tres, int numOfRows)
...
@@ -406,8 +415,11 @@ void tscAsyncInsertMultiVnodesProxy(void *param, TAOS_RES *tres, int numOfRows)
assert
(
!
pCmd
->
isInsertFromFile
&&
pSql
->
signature
==
pSql
);
assert
(
!
pCmd
->
isInsertFromFile
&&
pSql
->
signature
==
pSql
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
int32_t
index
=
0
;
assert
(
pCmd
->
pQueryInfo
->
numOfTables
==
1
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
index
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
index
,
0
);
assert
(
pQueryInfo
->
numOfTables
==
1
);
SDataBlockList
*
pDataBlocks
=
pCmd
->
pDataBlocks
;
SDataBlockList
*
pDataBlocks
=
pCmd
->
pDataBlocks
;
if
(
pDataBlocks
==
NULL
||
pMeterMetaInfo
->
vnodeIndex
>=
pDataBlocks
->
nSize
)
{
if
(
pDataBlocks
==
NULL
||
pMeterMetaInfo
->
vnodeIndex
>=
pDataBlocks
->
nSize
)
{
...
@@ -465,9 +477,10 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
...
@@ -465,9 +477,10 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
tscTrace
(
"%p renew meterMeta successfully, command:%d, code:%d, thandle:%p, retry:%d"
,
tscTrace
(
"%p renew meterMeta successfully, command:%d, code:%d, thandle:%p, retry:%d"
,
pSql
,
pSql
->
cmd
.
command
,
pSql
->
res
.
code
,
pSql
->
thandle
,
pSql
->
retry
);
pSql
,
pSql
->
cmd
.
command
,
pSql
->
res
.
code
,
pSql
->
thandle
,
pSql
->
retry
);
assert
(
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
)
->
pMeterMeta
==
NULL
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
tscGetMeterMeta
(
pSql
,
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
)
->
name
,
0
);
assert
(
pMeterMetaInfo
->
pMeterMeta
==
NULL
);
tscGetMeterMeta
(
pSql
,
pMeterMetaInfo
->
name
,
0
);
code
=
tscSendMsgToServer
(
pSql
);
code
=
tscSendMsgToServer
(
pSql
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
pRes
->
code
=
code
;
pRes
->
code
=
code
;
...
@@ -486,18 +499,21 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
...
@@ -486,18 +499,21 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
if
(
pSql
->
pStream
==
NULL
)
{
if
(
pSql
->
pStream
==
NULL
)
{
// check if it is a sub-query of metric query first, if true, enter another routine
// check if it is a sub-query of metric query first, if true, enter another routine
if
((
pSql
->
cmd
.
type
&
TSDB_QUERY_TYPE_STABLE_SUBQUERY
)
==
TSDB_QUERY_TYPE_STABLE_SUBQUERY
)
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
if
((
pQueryInfo
->
type
&
TSDB_QUERY_TYPE_STABLE_SUBQUERY
)
==
TSDB_QUERY_TYPE_STABLE_SUBQUERY
)
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
assert
(
pMeterMetaInfo
->
pMeterMeta
->
numOfTags
!=
0
&&
pMeterMetaInfo
->
vnodeIndex
>=
0
&&
pSql
->
param
!=
NULL
);
assert
(
pMeterMetaInfo
->
pMeterMeta
->
numOfTags
!=
0
&&
pMeterMetaInfo
->
vnodeIndex
>=
0
&&
pSql
->
param
!=
NULL
);
SRetrieveSupport
*
trs
=
(
SRetrieveSupport
*
)
pSql
->
param
;
SRetrieveSupport
*
trs
=
(
SRetrieveSupport
*
)
pSql
->
param
;
SSqlObj
*
pParObj
=
trs
->
pParentSqlObj
;
SSqlObj
*
pParObj
=
trs
->
pParentSqlObj
;
assert
(
pParObj
->
signature
==
pParObj
&&
trs
->
subqueryIndex
==
pMeterMetaInfo
->
vnodeIndex
&&
assert
(
pParObj
->
signature
==
pParObj
&&
trs
->
subqueryIndex
==
pMeterMetaInfo
->
vnodeIndex
&&
pMeterMetaInfo
->
pMeterMeta
->
numOfTags
!=
0
);
pMeterMetaInfo
->
pMeterMeta
->
numOfTags
!=
0
);
tscTrace
(
"%p get metricMeta during metric query successfully"
,
pSql
);
tscTrace
(
"%p get metricMeta during metric query successfully"
,
pSql
);
code
=
tscGetMeterMeta
(
pSql
,
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
)
->
name
,
0
);
code
=
tscGetMeterMeta
(
pSql
,
pMeterMetaInfo
->
name
,
0
);
pRes
->
code
=
code
;
pRes
->
code
=
code
;
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
return
;
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
return
;
...
@@ -512,14 +528,14 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
...
@@ -512,14 +528,14 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
}
}
}
else
{
// stream computing
}
else
{
// stream computing
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
code
=
tscGetMeterMeta
(
pSql
,
pMeterMetaInfo
->
name
,
0
);
code
=
tscGetMeterMeta
(
pSql
,
pMeterMetaInfo
->
name
,
0
);
pRes
->
code
=
code
;
pRes
->
code
=
code
;
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
return
;
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
return
;
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
if
(
code
==
TSDB_CODE_SUCCESS
&&
UTIL_METER_IS_
METRIC
(
pMeterMetaInfo
))
{
if
(
code
==
TSDB_CODE_SUCCESS
&&
UTIL_METER_IS_
SUPERTABLE
(
pMeterMetaInfo
))
{
code
=
tscGetMetricMeta
(
pSql
);
code
=
tscGetMetricMeta
(
pSql
);
pRes
->
code
=
code
;
pRes
->
code
=
code
;
...
@@ -539,7 +555,9 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
...
@@ -539,7 +555,9 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
* transfer the sql function for metric query before get meter/metric meta,
* transfer the sql function for metric query before get meter/metric meta,
* since in callback functions, only tscProcessSql(pStream->pSql) is executed!
* since in callback functions, only tscProcessSql(pStream->pSql) is executed!
*/
*/
tscTansformSQLFunctionForMetricQuery
(
&
pSql
->
cmd
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
tscTansformSQLFunctionForMetricQuery
(
pQueryInfo
);
tscIncStreamExecutionCount
(
pSql
->
pStream
);
tscIncStreamExecutionCount
(
pSql
->
pStream
);
}
else
{
}
else
{
tscTrace
(
"%p get meterMeta/metricMeta successfully"
,
pSql
);
tscTrace
(
"%p get meterMeta/metricMeta successfully"
,
pSql
);
...
...
src/client/src/tscJoinProcess.c
浏览文件 @
e15aa9b1
...
@@ -53,11 +53,16 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor
...
@@ -53,11 +53,16 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor
*
st
=
INT64_MAX
;
*
st
=
INT64_MAX
;
*
et
=
INT64_MIN
;
*
et
=
INT64_MIN
;
SLimitVal
*
pLimit
=
&
pSql
->
cmd
.
pQueryInfo
->
limit
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
int32_t
order
=
pSql
->
cmd
.
order
.
order
;
pSql
->
pSubs
[
0
]
->
cmd
.
pQueryInfo
->
tsBuf
=
output1
;
SLimitVal
*
pLimit
=
&
pQueryInfo
->
limit
;
pSql
->
pSubs
[
1
]
->
cmd
.
pQueryInfo
->
tsBuf
=
output2
;
int32_t
order
=
pQueryInfo
->
order
.
order
;
SQueryInfo
*
pSubQueryInfo1
=
tscGetQueryInfoDetail
(
&
pSql
->
pSubs
[
0
]
->
cmd
,
0
);
SQueryInfo
*
pSubQueryInfo2
=
tscGetQueryInfoDetail
(
&
pSql
->
pSubs
[
1
]
->
cmd
,
0
);
pSubQueryInfo1
->
tsBuf
=
output1
;
pSubQueryInfo2
->
tsBuf
=
output2
;
tsBufResetPos
(
pSupporter1
->
pTSBuf
);
tsBufResetPos
(
pSupporter1
->
pTSBuf
);
tsBufResetPos
(
pSupporter2
->
pTSBuf
);
tsBufResetPos
(
pSupporter2
->
pTSBuf
);
...
@@ -113,7 +118,9 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor
...
@@ -113,7 +118,9 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor
}
}
// in case of stable query, limit/offset is not applied here
// in case of stable query, limit/offset is not applied here
if
(
pLimit
->
offset
==
0
||
pSql
->
cmd
.
pQueryInfo
->
nAggTimeInterval
>
0
||
QUERY_IS_STABLE_QUERY
(
pSql
->
cmd
.
type
))
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
if
(
pLimit
->
offset
==
0
||
pQueryInfo
->
nAggTimeInterval
>
0
||
QUERY_IS_STABLE_QUERY
(
pQueryInfo
->
type
))
{
tsBufAppend
(
output1
,
elem1
.
vnode
,
elem1
.
tag
,
(
const
char
*
)
&
elem1
.
ts
,
sizeof
(
elem1
.
ts
));
tsBufAppend
(
output1
,
elem1
.
vnode
,
elem1
.
tag
,
(
const
char
*
)
&
elem1
.
ts
,
sizeof
(
elem1
.
ts
));
tsBufAppend
(
output2
,
elem2
.
vnode
,
elem2
.
tag
,
(
const
char
*
)
&
elem2
.
ts
,
sizeof
(
elem2
.
ts
));
tsBufAppend
(
output2
,
elem2
.
vnode
,
elem2
.
tag
,
(
const
char
*
)
&
elem2
.
ts
,
sizeof
(
elem2
.
ts
));
}
else
{
}
else
{
...
@@ -168,10 +175,12 @@ SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pS
...
@@ -168,10 +175,12 @@ SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pS
pSupporter
->
pState
=
pState
;
pSupporter
->
pState
=
pState
;
pSupporter
->
subqueryIndex
=
index
;
pSupporter
->
subqueryIndex
=
index
;
pSupporter
->
interval
=
pSql
->
cmd
.
pQueryInfo
->
nAggTimeInterval
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
pSupporter
->
limit
=
pSql
->
cmd
.
pQueryInfo
->
limit
;
pSupporter
->
interval
=
pQueryInfo
->
nAggTimeInterval
;
pSupporter
->
limit
=
pQueryInfo
->
limit
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
index
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
index
);
pSupporter
->
uid
=
pMeterMetaInfo
->
pMeterMeta
->
uid
;
pSupporter
->
uid
=
pMeterMetaInfo
->
pMeterMeta
->
uid
;
getTmpfilePath
(
"join-"
,
pSupporter
->
path
);
getTmpfilePath
(
"join-"
,
pSupporter
->
path
);
...
@@ -209,10 +218,9 @@ void tscDestroyJoinSupporter(SJoinSubquerySupporter* pSupporter) {
...
@@ -209,10 +218,9 @@ void tscDestroyJoinSupporter(SJoinSubquerySupporter* pSupporter) {
* primary timestamp column , the secondary query is not necessary
* primary timestamp column , the secondary query is not necessary
*
*
*/
*/
bool
needSecondaryQuery
(
SSqlObj
*
pSql
)
{
bool
needSecondaryQuery
(
SQueryInfo
*
pQueryInfo
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
colList
.
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pCmd
->
pQueryInfo
->
colList
.
numOfCols
;
++
i
)
{
SColumnBase
*
pBase
=
tscColumnBaseInfoGet
(
&
pQueryInfo
->
colList
,
i
);
SColumnBase
*
pBase
=
tscColumnBaseInfoGet
(
&
pCmd
->
pQueryInfo
->
colList
,
i
);
if
(
pBase
->
colIndex
.
columnIndex
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
if
(
pBase
->
colIndex
.
columnIndex
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
return
true
;
return
true
;
}
}
...
@@ -272,53 +280,58 @@ int32_t tscLaunchSecondSubquery(SSqlObj* pSql) {
...
@@ -272,53 +280,58 @@ int32_t tscLaunchSecondSubquery(SSqlObj* pSql) {
tscFreeSqlCmdData
(
&
pNew
->
cmd
);
tscFreeSqlCmdData
(
&
pNew
->
cmd
);
pSql
->
pSubs
[
j
++
]
=
pNew
;
pSql
->
pSubs
[
j
++
]
=
pNew
;
pNew
->
cmd
.
pQueryInfo
->
tsBuf
=
pSub
->
cmd
.
pQueryInfo
->
tsBuf
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pNew
->
cmd
,
0
);
pSub
->
cmd
.
pQueryInfo
->
tsBuf
=
NULL
;
SQueryInfo
*
pSubQueryInfo
=
tscGetQueryInfoDetail
(
&
pSub
->
cmd
,
0
);
pQueryInfo
->
tsBuf
=
pSubQueryInfo
->
tsBuf
;
pSubQueryInfo
->
tsBuf
=
NULL
;
taos_free_result
(
pSub
);
taos_free_result
(
pSub
);
// set the second stage sub query for join process
// set the second stage sub query for join process
p
New
->
cmd
.
type
|=
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
;
p
QueryInfo
->
type
|=
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
;
p
New
->
cmd
.
p
QueryInfo
->
nAggTimeInterval
=
pSupporter
->
interval
;
pQueryInfo
->
nAggTimeInterval
=
pSupporter
->
interval
;
p
New
->
cmd
.
p
QueryInfo
->
groupbyExpr
=
pSupporter
->
groupbyExpr
;
pQueryInfo
->
groupbyExpr
=
pSupporter
->
groupbyExpr
;
tscColumnBaseInfoCopy
(
&
p
New
->
cmd
.
p
QueryInfo
->
colList
,
&
pSupporter
->
colList
,
0
);
tscColumnBaseInfoCopy
(
&
pQueryInfo
->
colList
,
&
pSupporter
->
colList
,
0
);
tscTagCondCopy
(
&
p
New
->
cmd
.
p
QueryInfo
->
tagCond
,
&
pSupporter
->
tagCond
);
tscTagCondCopy
(
&
pQueryInfo
->
tagCond
,
&
pSupporter
->
tagCond
);
tscSqlExprCopy
(
&
p
New
->
cmd
.
p
QueryInfo
->
exprsInfo
,
&
pSupporter
->
exprsInfo
,
pSupporter
->
uid
);
tscSqlExprCopy
(
&
pQueryInfo
->
exprsInfo
,
&
pSupporter
->
exprsInfo
,
pSupporter
->
uid
);
tscFieldInfoCopyAll
(
&
pSupporter
->
fieldsInfo
,
&
p
New
->
cmd
.
p
QueryInfo
->
fieldsInfo
);
tscFieldInfoCopyAll
(
&
pSupporter
->
fieldsInfo
,
&
pQueryInfo
->
fieldsInfo
);
// add the ts function for interval query if it is missing
// add the ts function for interval query if it is missing
if
(
pSupporter
->
exprsInfo
.
pExprs
[
0
].
functionId
!=
TSDB_FUNC_TS
&&
p
New
->
cmd
.
p
QueryInfo
->
nAggTimeInterval
>
0
)
{
if
(
pSupporter
->
exprsInfo
.
pExprs
[
0
].
functionId
!=
TSDB_FUNC_TS
&&
pQueryInfo
->
nAggTimeInterval
>
0
)
{
tscAddTimestampColumn
(
&
pNew
->
cmd
,
TSDB_FUNC_TS
,
0
);
tscAddTimestampColumn
(
pQueryInfo
,
TSDB_FUNC_TS
,
0
);
}
}
// todo refactor function name
// todo refactor function name
tscAddTimestampColumn
(
&
pNew
->
cmd
,
TSDB_FUNC_TS
,
0
);
SQueryInfo
*
pNewQueryInfo
=
tscGetQueryInfoDetail
(
&
pNew
->
cmd
,
0
);
tscFieldInfoCalOffset
(
&
pNew
->
cmd
);
tscAddTimestampColumn
(
pQueryInfo
,
TSDB_FUNC_TS
,
0
);
tscFieldInfoCalOffset
(
pNewQueryInfo
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pNew
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pNewQueryInfo
,
0
);
/*
/*
* When handling the projection query, the offset value will be modified for table-table join, which is changed
* When handling the projection query, the offset value will be modified for table-table join, which is changed
* during the timestamp intersection.
* during the timestamp intersection.
*/
*/
pSupporter
->
limit
=
p
Sql
->
cmd
.
p
QueryInfo
->
limit
;
pSupporter
->
limit
=
pQueryInfo
->
limit
;
pNew
->
cmd
.
p
QueryInfo
->
limit
=
pSupporter
->
limit
;
pNewQueryInfo
->
limit
=
pSupporter
->
limit
;
// fetch the join tag column
// fetch the join tag column
if
(
UTIL_METER_IS_
METRIC
(
pMeterMetaInfo
))
{
if
(
UTIL_METER_IS_
SUPERTABLE
(
pMeterMetaInfo
))
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
&
pNew
->
cmd
,
0
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pNewQueryInfo
,
0
);
assert
(
p
New
->
cmd
.
p
QueryInfo
->
tagCond
.
joinInfo
.
hasJoin
);
assert
(
pQueryInfo
->
tagCond
.
joinInfo
.
hasJoin
);
int16_t
tagColIndex
=
tscGetJoinTagColIndexByUid
(
&
p
New
->
cmd
.
p
QueryInfo
->
tagCond
,
pMeterMetaInfo
->
pMeterMeta
->
uid
);
int16_t
tagColIndex
=
tscGetJoinTagColIndexByUid
(
&
pQueryInfo
->
tagCond
,
pMeterMetaInfo
->
pMeterMeta
->
uid
);
pExpr
->
param
[
0
].
i64Key
=
tagColIndex
;
pExpr
->
param
[
0
].
i64Key
=
tagColIndex
;
pExpr
->
numOfParams
=
1
;
pExpr
->
numOfParams
=
1
;
}
}
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
tscPrintSelectClause
(
&
pNew
->
cmd
);
tscPrintSelectClause
(
&
pNew
->
cmd
,
0
);
#endif
#endif
tscProcessSql
(
pNew
);
tscProcessSql
(
pNew
);
...
@@ -370,10 +383,12 @@ static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSubquerySupporter* pSupporter
...
@@ -370,10 +383,12 @@ static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSubquerySupporter* pSupporter
// update the query time range according to the join results on timestamp
// update the query time range according to the join results on timestamp
static
void
updateQueryTimeRange
(
SSqlObj
*
pSql
,
int64_t
st
,
int64_t
et
)
{
static
void
updateQueryTimeRange
(
SSqlObj
*
pSql
,
int64_t
st
,
int64_t
et
)
{
assert
(
pSql
->
cmd
.
pQueryInfo
->
stime
<=
st
&&
pSql
->
cmd
.
pQueryInfo
->
etime
>=
et
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
pSql
->
cmd
.
pQueryInfo
->
stime
=
st
;
assert
(
pQueryInfo
->
stime
<=
st
&&
pQueryInfo
->
etime
>=
et
);
pSql
->
cmd
.
pQueryInfo
->
etime
=
et
;
pQueryInfo
->
stime
=
st
;
pQueryInfo
->
etime
=
et
;
}
}
static
void
joinRetrieveCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
static
void
joinRetrieveCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
...
@@ -381,8 +396,9 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
...
@@ -381,8 +396,9 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
SSqlObj
*
pParentSql
=
pSupporter
->
pObj
;
SSqlObj
*
pParentSql
=
pSupporter
->
pObj
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
if
((
p
Sql
->
cmd
.
type
&
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)
==
0
)
{
if
((
p
QueryInfo
->
type
&
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)
==
0
)
{
if
(
pSupporter
->
pState
->
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
pSupporter
->
pState
->
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"%p abort query due to other subquery failure. code:%d, global code:%d"
,
pSql
,
numOfRows
,
tscError
(
"%p abort query due to other subquery failure. code:%d, global code:%d"
,
pSql
,
numOfRows
,
pSupporter
->
pState
->
code
);
pSupporter
->
pState
->
code
);
...
@@ -408,8 +424,8 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
...
@@ -408,8 +424,8 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
tscTrace
(
"%p create tmp file for ts block:%s"
,
pSql
,
pBuf
->
path
);
tscTrace
(
"%p create tmp file for ts block:%s"
,
pSql
,
pBuf
->
path
);
pSupporter
->
pTSBuf
=
pBuf
;
pSupporter
->
pTSBuf
=
pBuf
;
}
else
{
}
else
{
assert
(
p
Sql
->
cmd
.
p
QueryInfo
->
numOfTables
==
1
);
// for subquery, only one metermetaInfo
assert
(
pQueryInfo
->
numOfTables
==
1
);
// for subquery, only one metermetaInfo
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
0
);
tsBufMerge
(
pSupporter
->
pTSBuf
,
pBuf
,
pMeterMetaInfo
->
vnodeIndex
);
tsBufMerge
(
pSupporter
->
pTSBuf
,
pBuf
,
pMeterMetaInfo
->
vnodeIndex
);
tsBufDestory
(
pBuf
);
tsBufDestory
(
pBuf
);
...
@@ -422,9 +438,11 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
...
@@ -422,9 +438,11 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
taos_fetch_rows_a
(
tres
,
joinRetrieveCallback
,
param
);
taos_fetch_rows_a
(
tres
,
joinRetrieveCallback
,
param
);
}
else
if
(
numOfRows
==
0
)
{
// no data from this vnode anymore
}
else
if
(
numOfRows
==
0
)
{
// no data from this vnode anymore
if
(
tscProjectionQueryOnMetric
(
&
pParentSql
->
cmd
))
{
if
(
tscProjectionQueryOnMetric
(
&
pSql
->
cmd
,
0
))
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
assert
(
pSql
->
cmd
.
pQueryInfo
->
numOfTables
==
1
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
assert
(
pQueryInfo
->
numOfTables
==
1
);
// for projection query, need to try next vnode
// for projection query, need to try next vnode
if
((
++
pMeterMetaInfo
->
vnodeIndex
)
<
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
)
{
if
((
++
pMeterMetaInfo
->
vnodeIndex
)
<
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
)
{
...
@@ -478,9 +496,11 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
...
@@ -478,9 +496,11 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
pSql
->
res
.
numOfTotal
+=
pSql
->
res
.
numOfRows
;
pSql
->
res
.
numOfTotal
+=
pSql
->
res
.
numOfRows
;
}
}
if
(
tscProjectionQueryOnMetric
(
&
pSql
->
cmd
)
&&
numOfRows
==
0
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
assert
(
pSql
->
cmd
.
pQueryInfo
->
numOfTables
==
1
);
if
(
tscProjectionQueryOnMetric
(
pCmd
,
0
)
&&
numOfRows
==
0
)
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
assert
(
pQueryInfo
->
numOfTables
==
1
);
// for projection query, need to try next vnode if current vnode is exhausted
// for projection query, need to try next vnode if current vnode is exhausted
if
((
++
pMeterMetaInfo
->
vnodeIndex
)
<
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
)
{
if
((
++
pMeterMetaInfo
->
vnodeIndex
)
<
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
)
{
...
@@ -516,13 +536,14 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) {
...
@@ -516,13 +536,14 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) {
assert
(
pSql
->
numOfSubs
>=
1
);
assert
(
pSql
->
numOfSubs
>=
1
);
for
(
int32_t
i
=
0
;
i
<
pSql
->
numOfSubs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pSql
->
numOfSubs
;
++
i
)
{
SSqlRes
*
pRes
=
&
pSql
->
pSubs
[
i
]
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
pSubs
[
i
]
->
res
;
S
SqlCmd
*
pCmd
=
&
pSql
->
pSubs
[
i
]
->
cmd
;
S
QueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
pSubs
[
i
]
->
cmd
,
0
)
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
0
);
if
(
tscProjectionQueryOnMetric
(
pCmd
))
{
if
(
tscProjectionQueryOnMetric
(
&
pSql
->
cmd
,
0
))
{
if
(
pRes
->
row
>=
pRes
->
numOfRows
&&
pMeterMetaInfo
->
vnodeIndex
<
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
&&
if
(
pRes
->
row
>=
pRes
->
numOfRows
&&
pMeterMetaInfo
->
vnodeIndex
<
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
&&
(
!
tscHasReachLimitation
(
pSql
->
pSubs
[
i
])))
{
(
!
tscHasReachLimitation
(
pSql
->
pSubs
[
i
])))
{
numOfFetch
++
;
numOfFetch
++
;
...
@@ -555,9 +576,11 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) {
...
@@ -555,9 +576,11 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) {
// wait for all subqueries completed
// wait for all subqueries completed
pSupporter
->
pState
->
numOfTotal
=
numOfFetch
;
pSupporter
->
pState
->
numOfTotal
=
numOfFetch
;
assert
(
pRes1
->
numOfRows
>=
0
&&
pCmd1
->
pQueryInfo
->
numOfTables
==
1
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd1
,
0
);
assert
(
pRes1
->
numOfRows
>=
0
&&
pQueryInfo
->
numOfTables
==
1
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd1
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
0
);
if
(
pRes1
->
row
>=
pRes1
->
numOfRows
)
{
if
(
pRes1
->
row
>=
pRes1
->
numOfRows
)
{
tscTrace
(
"%p subquery:%p retrieve data from vnode, subquery:%d, vnodeIndex:%d"
,
pSql
,
pSql1
,
tscTrace
(
"%p subquery:%p retrieve data from vnode, subquery:%d, vnodeIndex:%d"
,
pSql
,
pSql1
,
...
@@ -589,16 +612,17 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
...
@@ -589,16 +612,17 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
return
;
// the column transfer support struct has been built
return
;
// the column transfer support struct has been built
}
}
pRes
->
pColumnIndex
=
calloc
(
1
,
sizeof
(
SColumnIndex
)
*
pCmd
->
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
pRes
->
pColumnIndex
=
calloc
(
1
,
sizeof
(
SColumnIndex
)
*
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
);
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
i
);
int32_t
tableIndexOfSub
=
-
1
;
int32_t
tableIndexOfSub
=
-
1
;
for
(
int32_t
j
=
0
;
j
<
p
Cmd
->
p
QueryInfo
->
numOfTables
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pQueryInfo
->
numOfTables
;
++
j
)
{
SSqlObj
*
pSub
=
pSql
->
pSubs
[
j
];
SSqlObj
*
pSub
=
pSql
->
pSubs
[
j
];
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSub
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSub
->
cmd
,
0
,
0
);
if
(
pMeterMetaInfo
->
pMeterMeta
->
uid
==
pExpr
->
uid
)
{
if
(
pMeterMetaInfo
->
pMeterMeta
->
uid
==
pExpr
->
uid
)
{
tableIndexOfSub
=
j
;
tableIndexOfSub
=
j
;
break
;
break
;
...
@@ -606,9 +630,10 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
...
@@ -606,9 +630,10 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
}
}
SSqlCmd
*
pSubCmd
=
&
pSql
->
pSubs
[
tableIndexOfSub
]
->
cmd
;
SSqlCmd
*
pSubCmd
=
&
pSql
->
pSubs
[
tableIndexOfSub
]
->
cmd
;
SQueryInfo
*
pSubQueryInfo
=
tscGetQueryInfoDetail
(
pSubCmd
,
0
);
for
(
int32_t
k
=
0
;
k
<
pSub
Cmd
->
p
QueryInfo
->
exprsInfo
.
numOfExprs
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pSubQueryInfo
->
exprsInfo
.
numOfExprs
;
++
k
)
{
SSqlExpr
*
pSubExpr
=
tscSqlExprGet
(
pSub
Cmd
,
k
);
SSqlExpr
*
pSubExpr
=
tscSqlExprGet
(
pSub
QueryInfo
,
k
);
if
(
pExpr
->
functionId
==
pSubExpr
->
functionId
&&
pExpr
->
colInfo
.
colId
==
pSubExpr
->
colInfo
.
colId
)
{
if
(
pExpr
->
functionId
==
pSubExpr
->
functionId
&&
pExpr
->
colInfo
.
colId
==
pSubExpr
->
colInfo
.
colId
)
{
pRes
->
pColumnIndex
[
i
]
=
(
SColumnIndex
){.
tableIndex
=
tableIndexOfSub
,
.
columnIndex
=
k
};
pRes
->
pColumnIndex
[
i
]
=
(
SColumnIndex
){.
tableIndex
=
tableIndexOfSub
,
.
columnIndex
=
k
};
break
;
break
;
...
@@ -619,7 +644,7 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
...
@@ -619,7 +644,7 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
void
tscJoinQueryCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
)
{
void
tscJoinQueryCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
)
{
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
// SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0);
// SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0
, 0
);
// int32_t idx = pSql->cmd.vnodeIdx;
// int32_t idx = pSql->cmd.vnodeIdx;
...
@@ -648,7 +673,8 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
...
@@ -648,7 +673,8 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
// }
// }
// } else {
// } else {
if
((
pSql
->
cmd
.
type
&
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)
!=
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
if
((
pQueryInfo
->
type
&
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)
!=
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
// direct call joinRetrieveCallback and set the error code
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
// direct call joinRetrieveCallback and set the error code
joinRetrieveCallback
(
param
,
pSql
,
code
);
joinRetrieveCallback
(
param
,
pSql
,
code
);
}
else
{
// first stage query, continue to retrieve data
}
else
{
// first stage query, continue to retrieve data
...
@@ -678,13 +704,14 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
...
@@ -678,13 +704,14 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
if
(
atomic_add_fetch_32
(
&
pSupporter
->
pState
->
numOfCompleted
,
1
)
>=
pSupporter
->
pState
->
numOfTotal
)
{
if
(
atomic_add_fetch_32
(
&
pSupporter
->
pState
->
numOfCompleted
,
1
)
>=
pSupporter
->
pState
->
numOfTotal
)
{
tscSetupOutputColumnIndex
(
pParentSql
);
tscSetupOutputColumnIndex
(
pParentSql
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
/**
/**
* if the query is a continue query (vnodeIndex > 0 for projection query) for next vnode, do the retrieval of
* if the query is a continue query (vnodeIndex > 0 for projection query) for next vnode, do the retrieval of
* data instead of returning to its invoker
* data instead of returning to its invoker
*/
*/
if
(
pMeterMetaInfo
->
vnodeIndex
>
0
&&
tscProjectionQueryOnMetric
(
&
pSql
->
cmd
))
{
if
(
pMeterMetaInfo
->
vnodeIndex
>
0
&&
tscProjectionQueryOnMetric
(
&
pSql
->
cmd
,
0
))
{
assert
(
pMeterMetaInfo
->
vnodeIndex
<
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
);
assert
(
pMeterMetaInfo
->
vnodeIndex
<
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
);
pSupporter
->
pState
->
numOfCompleted
=
0
;
// reset the record value
pSupporter
->
pState
->
numOfCompleted
=
0
;
// reset the record value
...
...
src/client/src/tscLocal.c
浏览文件 @
e15aa9b1
...
@@ -85,7 +85,7 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type
...
@@ -85,7 +85,7 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type
* length((uint64_t) 123456789011) > 12, greater than sizsof(uint64_t)
* length((uint64_t) 123456789011) > 12, greater than sizsof(uint64_t)
*/
*/
static
int32_t
tscMaxLengthOfTagsFields
(
SSqlObj
*
pSql
)
{
static
int32_t
tscMaxLengthOfTagsFields
(
SSqlObj
*
pSql
)
{
SMeterMeta
*
pMeta
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
)
->
pMeterMeta
;
SMeterMeta
*
pMeta
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
)
->
pMeterMeta
;
if
(
pMeta
->
meterType
==
TSDB_METER_METRIC
||
pMeta
->
meterType
==
TSDB_METER_OTABLE
||
if
(
pMeta
->
meterType
==
TSDB_METER_METRIC
||
pMeta
->
meterType
==
TSDB_METER_OTABLE
||
pMeta
->
meterType
==
TSDB_METER_STABLE
)
{
pMeta
->
meterType
==
TSDB_METER_STABLE
)
{
...
@@ -114,8 +114,9 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
...
@@ -114,8 +114,9 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
// one column for each row
// one column for each row
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
SMeterMeta
*
pMeta
=
pMeterMetaInfo
->
pMeterMeta
;
SMeterMeta
*
pMeta
=
pMeterMetaInfo
->
pMeterMeta
;
/*
/*
...
@@ -127,7 +128,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
...
@@ -127,7 +128,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
int32_t
numOfRows
=
pMeta
->
numOfColumns
;
int32_t
numOfRows
=
pMeta
->
numOfColumns
;
int32_t
totalNumOfRows
=
numOfRows
+
pMeta
->
numOfTags
;
int32_t
totalNumOfRows
=
numOfRows
+
pMeta
->
numOfTags
;
if
(
UTIL_METER_IS_
METRIC
(
pMeterMetaInfo
))
{
if
(
UTIL_METER_IS_
SUPERTABLE
(
pMeterMetaInfo
))
{
numOfRows
=
pMeta
->
numOfColumns
+
pMeta
->
numOfTags
;
numOfRows
=
pMeta
->
numOfColumns
+
pMeta
->
numOfTags
;
}
}
...
@@ -135,31 +136,31 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
...
@@ -135,31 +136,31 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
SSchema
*
pSchema
=
tsGetSchema
(
pMeta
);
SSchema
*
pSchema
=
tsGetSchema
(
pMeta
);
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
0
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
0
);
strncpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
Cmd
,
0
)
*
totalNumOfRows
+
pField
->
bytes
*
i
,
pSchema
[
i
].
name
,
strncpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
QueryInfo
,
0
)
*
totalNumOfRows
+
pField
->
bytes
*
i
,
pSchema
[
i
].
name
,
TSDB_COL_NAME_LEN
);
TSDB_COL_NAME_LEN
);
char
*
type
=
tDataTypeDesc
[
pSchema
[
i
].
type
].
aName
;
char
*
type
=
tDataTypeDesc
[
pSchema
[
i
].
type
].
aName
;
pField
=
tscFieldInfoGetField
(
p
Cmd
,
1
);
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
1
);
strncpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
Cmd
,
1
)
*
totalNumOfRows
+
pField
->
bytes
*
i
,
type
,
pField
->
bytes
);
strncpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
QueryInfo
,
1
)
*
totalNumOfRows
+
pField
->
bytes
*
i
,
type
,
pField
->
bytes
);
int32_t
bytes
=
pSchema
[
i
].
bytes
;
int32_t
bytes
=
pSchema
[
i
].
bytes
;
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
bytes
=
bytes
/
TSDB_NCHAR_SIZE
;
bytes
=
bytes
/
TSDB_NCHAR_SIZE
;
}
}
pField
=
tscFieldInfoGetField
(
p
Cmd
,
2
);
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
2
);
*
(
int32_t
*
)(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
Cmd
,
2
)
*
totalNumOfRows
+
pField
->
bytes
*
i
)
=
bytes
;
*
(
int32_t
*
)(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
QueryInfo
,
2
)
*
totalNumOfRows
+
pField
->
bytes
*
i
)
=
bytes
;
pField
=
tscFieldInfoGetField
(
p
Cmd
,
3
);
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
3
);
if
(
i
>=
pMeta
->
numOfColumns
&&
pMeta
->
numOfTags
!=
0
)
{
if
(
i
>=
pMeta
->
numOfColumns
&&
pMeta
->
numOfTags
!=
0
)
{
strncpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
Cmd
,
3
)
*
totalNumOfRows
+
pField
->
bytes
*
i
,
"tag"
,
strncpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
QueryInfo
,
3
)
*
totalNumOfRows
+
pField
->
bytes
*
i
,
"tag"
,
strlen
(
"tag"
)
+
1
);
strlen
(
"tag"
)
+
1
);
}
}
}
}
if
(
UTIL_METER_IS_
METRIC
(
pMeterMetaInfo
))
{
if
(
UTIL_METER_IS_
SUPERTABLE
(
pMeterMetaInfo
))
{
return
0
;
return
0
;
}
}
...
@@ -167,27 +168,27 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
...
@@ -167,27 +168,27 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
char
*
pTagValue
=
tsGetTagsValue
(
pMeta
);
char
*
pTagValue
=
tsGetTagsValue
(
pMeta
);
for
(
int32_t
i
=
numOfRows
;
i
<
totalNumOfRows
;
++
i
)
{
for
(
int32_t
i
=
numOfRows
;
i
<
totalNumOfRows
;
++
i
)
{
// field name
// field name
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
0
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
0
);
strncpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
Cmd
,
0
)
*
totalNumOfRows
+
pField
->
bytes
*
i
,
pSchema
[
i
].
name
,
strncpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
QueryInfo
,
0
)
*
totalNumOfRows
+
pField
->
bytes
*
i
,
pSchema
[
i
].
name
,
TSDB_COL_NAME_LEN
);
TSDB_COL_NAME_LEN
);
// type name
// type name
pField
=
tscFieldInfoGetField
(
p
Cmd
,
1
);
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
1
);
char
*
type
=
tDataTypeDesc
[
pSchema
[
i
].
type
].
aName
;
char
*
type
=
tDataTypeDesc
[
pSchema
[
i
].
type
].
aName
;
strncpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
Cmd
,
1
)
*
totalNumOfRows
+
pField
->
bytes
*
i
,
type
,
pField
->
bytes
);
strncpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
QueryInfo
,
1
)
*
totalNumOfRows
+
pField
->
bytes
*
i
,
type
,
pField
->
bytes
);
// type length
// type length
int32_t
bytes
=
pSchema
[
i
].
bytes
;
int32_t
bytes
=
pSchema
[
i
].
bytes
;
pField
=
tscFieldInfoGetField
(
p
Cmd
,
2
);
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
2
);
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
bytes
=
bytes
/
TSDB_NCHAR_SIZE
;
bytes
=
bytes
/
TSDB_NCHAR_SIZE
;
}
}
*
(
int32_t
*
)(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
Cmd
,
2
)
*
totalNumOfRows
+
pField
->
bytes
*
i
)
=
bytes
;
*
(
int32_t
*
)(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
QueryInfo
,
2
)
*
totalNumOfRows
+
pField
->
bytes
*
i
)
=
bytes
;
// tag value
// tag value
pField
=
tscFieldInfoGetField
(
p
Cmd
,
3
);
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
3
);
char
*
target
=
pRes
->
data
+
tscFieldInfoGetOffset
(
p
Cmd
,
3
)
*
totalNumOfRows
+
pField
->
bytes
*
i
;
char
*
target
=
pRes
->
data
+
tscFieldInfoGetOffset
(
p
QueryInfo
,
3
)
*
totalNumOfRows
+
pField
->
bytes
*
i
;
if
(
isNull
(
pTagValue
,
pSchema
[
i
].
type
))
{
if
(
isNull
(
pTagValue
,
pSchema
[
i
].
type
))
{
sprintf
(
target
,
"%s"
,
TSDB_DATA_NULL_STR
);
sprintf
(
target
,
"%s"
,
TSDB_DATA_NULL_STR
);
...
@@ -252,25 +253,28 @@ static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
...
@@ -252,25 +253,28 @@ static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
pCmd
->
numOfCols
=
numOfCols
;
pCmd
->
numOfCols
=
numOfCols
;
pCmd
->
order
.
order
=
TSQL_SO_ASC
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
pQueryInfo
->
order
.
order
=
TSQL_SO_ASC
;
tscFieldInfoSetValue
(
&
p
Cmd
->
p
QueryInfo
->
fieldsInfo
,
0
,
TSDB_DATA_TYPE_BINARY
,
"Field"
,
TSDB_COL_NAME_LEN
);
tscFieldInfoSetValue
(
&
pQueryInfo
->
fieldsInfo
,
0
,
TSDB_DATA_TYPE_BINARY
,
"Field"
,
TSDB_COL_NAME_LEN
);
rowLen
+=
TSDB_COL_NAME_LEN
;
rowLen
+=
TSDB_COL_NAME_LEN
;
tscFieldInfoSetValue
(
&
p
Cmd
->
p
QueryInfo
->
fieldsInfo
,
1
,
TSDB_DATA_TYPE_BINARY
,
"Type"
,
typeColLength
);
tscFieldInfoSetValue
(
&
pQueryInfo
->
fieldsInfo
,
1
,
TSDB_DATA_TYPE_BINARY
,
"Type"
,
typeColLength
);
rowLen
+=
typeColLength
;
rowLen
+=
typeColLength
;
tscFieldInfoSetValue
(
&
p
Cmd
->
p
QueryInfo
->
fieldsInfo
,
2
,
TSDB_DATA_TYPE_INT
,
"Length"
,
sizeof
(
int32_t
));
tscFieldInfoSetValue
(
&
pQueryInfo
->
fieldsInfo
,
2
,
TSDB_DATA_TYPE_INT
,
"Length"
,
sizeof
(
int32_t
));
rowLen
+=
sizeof
(
int32_t
);
rowLen
+=
sizeof
(
int32_t
);
tscFieldInfoSetValue
(
&
p
Cmd
->
p
QueryInfo
->
fieldsInfo
,
3
,
TSDB_DATA_TYPE_BINARY
,
"Note"
,
noteColLength
);
tscFieldInfoSetValue
(
&
pQueryInfo
->
fieldsInfo
,
3
,
TSDB_DATA_TYPE_BINARY
,
"Note"
,
noteColLength
);
rowLen
+=
noteColLength
;
rowLen
+=
noteColLength
;
return
rowLen
;
return
rowLen
;
}
}
static
int32_t
tscProcessDescribeTable
(
SSqlObj
*
pSql
)
{
static
int32_t
tscProcessDescribeTable
(
SSqlObj
*
pSql
)
{
assert
(
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
)
->
pMeterMeta
!=
NULL
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
assert
(
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
)
->
pMeterMeta
!=
NULL
);
const
int32_t
NUM_OF_DESCRIBE_TABLE_COLUMNS
=
4
;
const
int32_t
NUM_OF_DESCRIBE_TABLE_COLUMNS
=
4
;
const
int32_t
TYPE_COLUMN_LENGTH
=
16
;
const
int32_t
TYPE_COLUMN_LENGTH
=
16
;
...
@@ -283,7 +287,7 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
...
@@ -283,7 +287,7 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
int32_t
rowLen
=
int32_t
rowLen
=
tscBuildMeterSchemaResultFields
(
pSql
,
NUM_OF_DESCRIBE_TABLE_COLUMNS
,
TYPE_COLUMN_LENGTH
,
note_field_length
);
tscBuildMeterSchemaResultFields
(
pSql
,
NUM_OF_DESCRIBE_TABLE_COLUMNS
,
TYPE_COLUMN_LENGTH
,
note_field_length
);
tscFieldInfoCalOffset
(
&
pSql
->
cmd
);
tscFieldInfoCalOffset
(
pQueryInfo
);
return
tscSetValueToResObj
(
pSql
,
rowLen
);
return
tscSetValueToResObj
(
pSql
,
rowLen
);
}
}
...
@@ -293,7 +297,9 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
...
@@ -293,7 +297,9 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
// only need to reorganize the results in the column format
// only need to reorganize the results in the column format
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
SMetricMeta
*
pMetricMeta
=
pMeterMetaInfo
->
pMetricMeta
;
SMetricMeta
*
pMetricMeta
=
pMeterMetaInfo
->
pMetricMeta
;
SSchema
*
pSchema
=
tsGetTagSchema
(
pMeterMetaInfo
->
pMeterMeta
);
SSchema
*
pSchema
=
tsGetTagSchema
(
pMeterMetaInfo
->
pMeterMeta
);
...
@@ -310,7 +316,7 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
...
@@ -310,7 +316,7 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
}
}
int32_t
totalNumOfResults
=
pMetricMeta
->
numOfMeters
;
int32_t
totalNumOfResults
=
pMetricMeta
->
numOfMeters
;
int32_t
rowLen
=
tscGetResRowLength
(
p
Cmd
);
int32_t
rowLen
=
tscGetResRowLength
(
p
QueryInfo
);
tscInitResObjForLocalQuery
(
pSql
,
totalNumOfResults
,
rowLen
);
tscInitResObjForLocalQuery
(
pSql
,
totalNumOfResults
,
rowLen
);
...
@@ -321,16 +327,16 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
...
@@ -321,16 +327,16 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
for
(
int32_t
j
=
0
;
j
<
pSidList
->
numOfSids
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pSidList
->
numOfSids
;
++
j
)
{
SMeterSidExtInfo
*
pSidExt
=
tscGetMeterSidInfo
(
pSidList
,
j
);
SMeterSidExtInfo
*
pSidExt
=
tscGetMeterSidInfo
(
pSidList
,
j
);
for
(
int32_t
k
=
0
;
k
<
p
Cmd
->
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
k
)
{
SColIndexEx
*
pColIndex
=
&
tscSqlExprGet
(
p
Cmd
,
k
)
->
colInfo
;
SColIndexEx
*
pColIndex
=
&
tscSqlExprGet
(
p
QueryInfo
,
k
)
->
colInfo
;
int16_t
offsetId
=
pColIndex
->
colIdx
;
int16_t
offsetId
=
pColIndex
->
colIdx
;
assert
((
pColIndex
->
flag
&
TSDB_COL_TAG
)
!=
0
);
assert
((
pColIndex
->
flag
&
TSDB_COL_TAG
)
!=
0
);
char
*
val
=
pSidExt
->
tags
+
vOffset
[
offsetId
];
char
*
val
=
pSidExt
->
tags
+
vOffset
[
offsetId
];
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
k
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
k
);
memcpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
Cmd
,
k
)
*
totalNumOfResults
+
pField
->
bytes
*
rowIdx
,
val
,
memcpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
QueryInfo
,
k
)
*
totalNumOfResults
+
pField
->
bytes
*
rowIdx
,
val
,
(
size_t
)
pField
->
bytes
);
(
size_t
)
pField
->
bytes
);
}
}
rowIdx
++
;
rowIdx
++
;
...
@@ -344,21 +350,23 @@ static int tscBuildMetricTagSqlFunctionResult(SSqlObj *pSql) {
...
@@ -344,21 +350,23 @@ static int tscBuildMetricTagSqlFunctionResult(SSqlObj *pSql) {
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SMetricMeta
*
pMetricMeta
=
tscGetMeterMetaInfo
(
pCmd
,
0
)
->
pMetricMeta
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMetricMeta
*
pMetricMeta
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
)
->
pMetricMeta
;
int32_t
totalNumOfResults
=
1
;
// count function only produce one result
int32_t
totalNumOfResults
=
1
;
// count function only produce one result
int32_t
rowLen
=
tscGetResRowLength
(
p
Cmd
);
int32_t
rowLen
=
tscGetResRowLength
(
p
QueryInfo
);
tscInitResObjForLocalQuery
(
pSql
,
totalNumOfResults
,
rowLen
);
tscInitResObjForLocalQuery
(
pSql
,
totalNumOfResults
,
rowLen
);
int32_t
rowIdx
=
0
;
int32_t
rowIdx
=
0
;
for
(
int32_t
i
=
0
;
i
<
totalNumOfResults
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
totalNumOfResults
;
++
i
)
{
for
(
int32_t
k
=
0
;
k
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
k
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
i
);
if
(
pExpr
->
colInfo
.
colIdx
==
-
1
&&
pExpr
->
functionId
==
TSDB_FUNC_COUNT
)
{
if
(
pExpr
->
colInfo
.
colIdx
==
-
1
&&
pExpr
->
functionId
==
TSDB_FUNC_COUNT
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
k
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
k
);
memcpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
Cmd
,
i
)
*
totalNumOfResults
+
pField
->
bytes
*
rowIdx
,
memcpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
p
QueryInfo
,
i
)
*
totalNumOfResults
+
pField
->
bytes
*
rowIdx
,
&
pMetricMeta
->
numOfMeters
,
sizeof
(
pMetricMeta
->
numOfMeters
));
&
pMetricMeta
->
numOfMeters
,
sizeof
(
pMetricMeta
->
numOfMeters
));
}
else
{
}
else
{
tscError
(
"not support operations"
);
tscError
(
"not support operations"
);
...
@@ -374,14 +382,16 @@ static int tscBuildMetricTagSqlFunctionResult(SSqlObj *pSql) {
...
@@ -374,14 +382,16 @@ static int tscBuildMetricTagSqlFunctionResult(SSqlObj *pSql) {
static
int
tscProcessQueryTags
(
SSqlObj
*
pSql
)
{
static
int
tscProcessQueryTags
(
SSqlObj
*
pSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMeta
*
pMeterMeta
=
tscGetMeterMetaInfo
(
pCmd
,
0
)
->
pMeterMeta
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMeterMeta
*
pMeterMeta
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
)
->
pMeterMeta
;
if
(
pMeterMeta
==
NULL
||
pMeterMeta
->
numOfTags
==
0
||
pMeterMeta
->
numOfColumns
==
0
)
{
if
(
pMeterMeta
==
NULL
||
pMeterMeta
->
numOfTags
==
0
||
pMeterMeta
->
numOfColumns
==
0
)
{
strcpy
(
pCmd
->
payload
,
"invalid table"
);
strcpy
(
pCmd
->
payload
,
"invalid table"
);
pSql
->
res
.
code
=
TSDB_CODE_INVALID_TABLE
;
pSql
->
res
.
code
=
TSDB_CODE_INVALID_TABLE
;
return
pSql
->
res
.
code
;
return
pSql
->
res
.
code
;
}
}
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
0
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
0
);
if
(
pExpr
->
functionId
==
TSDB_FUNC_COUNT
)
{
if
(
pExpr
->
functionId
==
TSDB_FUNC_COUNT
)
{
return
tscBuildMetricTagSqlFunctionResult
(
pSql
);
return
tscBuildMetricTagSqlFunctionResult
(
pSql
);
}
else
{
}
else
{
...
@@ -390,7 +400,9 @@ static int tscProcessQueryTags(SSqlObj *pSql) {
...
@@ -390,7 +400,9 @@ static int tscProcessQueryTags(SSqlObj *pSql) {
}
}
static
void
tscProcessCurrentUser
(
SSqlObj
*
pSql
)
{
static
void
tscProcessCurrentUser
(
SSqlObj
*
pSql
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
&
pSql
->
cmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
0
);
tscSetLocalQueryResult
(
pSql
,
pSql
->
pTscObj
->
user
,
pExpr
->
aliasName
,
TSDB_USER_LEN
);
tscSetLocalQueryResult
(
pSql
,
pSql
->
pTscObj
->
user
,
pExpr
->
aliasName
,
TSDB_USER_LEN
);
}
}
...
@@ -403,19 +415,24 @@ static void tscProcessCurrentDB(SSqlObj *pSql) {
...
@@ -403,19 +415,24 @@ static void tscProcessCurrentDB(SSqlObj *pSql) {
setNull
(
db
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
);
setNull
(
db
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
);
}
}
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
&
pSql
->
cmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
0
);
tscSetLocalQueryResult
(
pSql
,
db
,
pExpr
->
aliasName
,
TSDB_DB_NAME_LEN
);
tscSetLocalQueryResult
(
pSql
,
db
,
pExpr
->
aliasName
,
TSDB_DB_NAME_LEN
);
}
}
static
void
tscProcessServerVer
(
SSqlObj
*
pSql
)
{
static
void
tscProcessServerVer
(
SSqlObj
*
pSql
)
{
const
char
*
v
=
pSql
->
pTscObj
->
sversion
;
const
char
*
v
=
pSql
->
pTscObj
->
sversion
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
&
pSql
->
cmd
,
0
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
0
);
tscSetLocalQueryResult
(
pSql
,
v
,
pExpr
->
aliasName
,
tListLen
(
pSql
->
pTscObj
->
sversion
));
tscSetLocalQueryResult
(
pSql
,
v
,
pExpr
->
aliasName
,
tListLen
(
pSql
->
pTscObj
->
sversion
));
}
}
static
void
tscProcessClientVer
(
SSqlObj
*
pSql
)
{
static
void
tscProcessClientVer
(
SSqlObj
*
pSql
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
&
pSql
->
cmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
0
);
tscSetLocalQueryResult
(
pSql
,
version
,
pExpr
->
aliasName
,
strlen
(
version
));
tscSetLocalQueryResult
(
pSql
,
version
,
pExpr
->
aliasName
,
strlen
(
version
));
}
}
...
@@ -433,7 +450,9 @@ static void tscProcessServStatus(SSqlObj *pSql) {
...
@@ -433,7 +450,9 @@ static void tscProcessServStatus(SSqlObj *pSql) {
}
}
}
}
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
&
pSql
->
cmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
0
);
tscSetLocalQueryResult
(
pSql
,
"1"
,
pExpr
->
aliasName
,
2
);
tscSetLocalQueryResult
(
pSql
,
"1"
,
pExpr
->
aliasName
,
2
);
}
}
...
@@ -442,12 +461,13 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
...
@@ -442,12 +461,13 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
pCmd
->
numOfCols
=
1
;
pCmd
->
numOfCols
=
1
;
pCmd
->
order
.
order
=
TSQL_SO_ASC
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
pQueryInfo
->
order
.
order
=
TSQL_SO_ASC
;
tscFieldInfoSetValue
(
&
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
,
0
,
TSDB_DATA_TYPE_BINARY
,
columnName
,
valueLength
);
tscFieldInfoSetValue
(
&
p
QueryInfo
->
fieldsInfo
,
0
,
TSDB_DATA_TYPE_BINARY
,
columnName
,
valueLength
);
tscInitResObjForLocalQuery
(
pSql
,
1
,
valueLength
);
tscInitResObjForLocalQuery
(
pSql
,
1
,
valueLength
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
0
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
0
);
strncpy
(
pRes
->
data
,
val
,
pField
->
bytes
);
strncpy
(
pRes
->
data
,
val
,
pField
->
bytes
);
}
}
...
...
src/client/src/tscParseInsert.c
浏览文件 @
e15aa9b1
...
@@ -651,7 +651,7 @@ void sortRemoveDuplicates(STableDataBlocks *dataBuf) {
...
@@ -651,7 +651,7 @@ void sortRemoveDuplicates(STableDataBlocks *dataBuf) {
static
int32_t
doParseInsertStatement
(
SSqlObj
*
pSql
,
void
*
pTableHashList
,
char
**
str
,
SParsedDataColInfo
*
spd
,
static
int32_t
doParseInsertStatement
(
SSqlObj
*
pSql
,
void
*
pTableHashList
,
char
**
str
,
SParsedDataColInfo
*
spd
,
int32_t
*
totalNum
)
{
int32_t
*
totalNum
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
SMeterMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
SMeterMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
STableDataBlocks
*
dataBuf
=
NULL
;
STableDataBlocks
*
dataBuf
=
NULL
;
...
@@ -707,7 +707,7 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
...
@@ -707,7 +707,7 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
char
*
sql
=
*
sqlstr
;
char
*
sql
=
*
sqlstr
;
// get the token of specified table
// get the token of specified table
...
@@ -754,7 +754,7 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
...
@@ -754,7 +754,7 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
STagData
*
pTag
=
(
STagData
*
)
pCmd
->
payload
;
STagData
*
pTag
=
(
STagData
*
)
pCmd
->
payload
;
memset
(
pTag
,
0
,
sizeof
(
STagData
));
memset
(
pTag
,
0
,
sizeof
(
STagData
));
setMeterID
(
pSql
,
&
sToken
,
0
);
setMeterID
(
pSql
,
0
,
&
sToken
,
0
);
strncpy
(
pTag
->
name
,
pMeterMetaInfo
->
name
,
TSDB_METER_ID_LEN
);
strncpy
(
pTag
->
name
,
pMeterMetaInfo
->
name
,
TSDB_METER_ID_LEN
);
code
=
tscGetMeterMeta
(
pSql
,
pTag
->
name
,
0
);
code
=
tscGetMeterMeta
(
pSql
,
pTag
->
name
,
0
);
...
@@ -762,7 +762,7 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
...
@@ -762,7 +762,7 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
return
code
;
return
code
;
}
}
if
(
!
UTIL_METER_IS_
METRIC
(
pMeterMetaInfo
))
{
if
(
!
UTIL_METER_IS_
SUPERTABLE
(
pMeterMetaInfo
))
{
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"create table only from super table is allowed"
,
sToken
.
z
);
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"create table only from super table is allowed"
,
sToken
.
z
);
}
}
...
@@ -894,7 +894,7 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
...
@@ -894,7 +894,7 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"invalid table name"
,
*
sqlstr
);
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"invalid table name"
,
*
sqlstr
);
}
}
int32_t
ret
=
setMeterID
(
pSql
,
&
tableToken
,
0
);
int32_t
ret
=
setMeterID
(
pSql
,
0
,
&
tableToken
,
0
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
return
ret
;
}
}
...
@@ -941,13 +941,13 @@ int validateTableName(char *tblName, int len) {
...
@@ -941,13 +941,13 @@ int validateTableName(char *tblName, int len) {
* @param pSql
* @param pSql
* @return
* @return
*/
*/
int
doParse
r
InsertSql
(
SSqlObj
*
pSql
,
char
*
str
)
{
int
doParseInsertSql
(
SSqlObj
*
pSql
,
char
*
str
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
int32_t
code
=
TSDB_CODE_INVALID_SQL
;
int32_t
code
=
TSDB_CODE_INVALID_SQL
;
int32_t
totalNum
=
0
;
int32_t
totalNum
=
0
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscAddEmptyMeterMetaInfo
(
pCmd
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscAddEmptyMeterMetaInfo
(
pCmd
,
0
);
if
((
code
=
tscAllocPayload
(
pCmd
,
TSDB_PAYLOAD_SIZE
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
tscAllocPayload
(
pCmd
,
TSDB_PAYLOAD_SIZE
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
...
@@ -992,7 +992,7 @@ int doParserInsertSql(SSqlObj *pSql, char *str) {
...
@@ -992,7 +992,7 @@ int doParserInsertSql(SSqlObj *pSql, char *str) {
}
}
//TODO refactor
//TODO refactor
if
((
code
=
setMeterID
(
pSql
,
&
sToken
,
0
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
setMeterID
(
pSql
,
0
,
&
sToken
,
0
))
!=
TSDB_CODE_SUCCESS
)
{
goto
_error_clean
;
goto
_error_clean
;
}
}
...
@@ -1011,7 +1011,7 @@ int doParserInsertSql(SSqlObj *pSql, char *str) {
...
@@ -1011,7 +1011,7 @@ int doParserInsertSql(SSqlObj *pSql, char *str) {
}
}
}
}
if
(
UTIL_METER_IS_
METRIC
(
pMeterMetaInfo
))
{
if
(
UTIL_METER_IS_
SUPERTABLE
(
pMeterMetaInfo
))
{
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"insert data into super table is not supported"
,
NULL
);
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"insert data into super table is not supported"
,
NULL
);
goto
_error_clean
;
goto
_error_clean
;
}
}
...
@@ -1088,7 +1088,7 @@ int doParserInsertSql(SSqlObj *pSql, char *str) {
...
@@ -1088,7 +1088,7 @@ int doParserInsertSql(SSqlObj *pSql, char *str) {
strcpy
(
pDataBlock
->
filename
,
fname
);
strcpy
(
pDataBlock
->
filename
,
fname
);
}
else
if
(
sToken
.
type
==
TK_LP
)
{
}
else
if
(
sToken
.
type
==
TK_LP
)
{
/* insert into tablename(col1, col2,..., coln) values(v1, v2,... vn); */
/* insert into tablename(col1, col2,..., coln) values(v1, v2,... vn); */
SMeterMeta
*
pMeterMeta
=
tscGetMeterMetaInfo
(
pCmd
,
0
)
->
pMeterMeta
;
SMeterMeta
*
pMeterMeta
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
)
->
pMeterMeta
;
SSchema
*
pSchema
=
tsGetSchema
(
pMeterMeta
);
SSchema
*
pSchema
=
tsGetSchema
(
pMeterMeta
);
if
(
pCmd
->
isInsertFromFile
==
-
1
)
{
if
(
pCmd
->
isInsertFromFile
==
-
1
)
{
...
@@ -1188,7 +1188,7 @@ int doParserInsertSql(SSqlObj *pSql, char *str) {
...
@@ -1188,7 +1188,7 @@ int doParserInsertSql(SSqlObj *pSql, char *str) {
goto
_error_clean
;
goto
_error_clean
;
}
}
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
// set the next sent data vnode index in data block arraylist
// set the next sent data vnode index in data block arraylist
pMeterMetaInfo
->
vnodeIndex
=
1
;
pMeterMetaInfo
->
vnodeIndex
=
1
;
...
@@ -1203,7 +1203,7 @@ _error_clean:
...
@@ -1203,7 +1203,7 @@ _error_clean:
pCmd
->
pDataBlocks
=
tscDestroyBlockArrayList
(
pCmd
->
pDataBlocks
);
pCmd
->
pDataBlocks
=
tscDestroyBlockArrayList
(
pCmd
->
pDataBlocks
);
_clean:
_clean:
taosCleanUp
IntHash
(
pSql
->
pTableHashList
);
taosCleanUp
HashTable
(
pSql
->
pTableHashList
);
pSql
->
pTableHashList
=
NULL
;
pSql
->
pTableHashList
=
NULL
;
return
code
;
return
code
;
}
}
...
@@ -1231,14 +1231,14 @@ int tsParseInsertSql(SSqlObj *pSql, char *sql, char *acct, char *db) {
...
@@ -1231,14 +1231,14 @@ int tsParseInsertSql(SSqlObj *pSql, char *sql, char *acct, char *db) {
pCmd
->
isInsertFromFile
=
-
1
;
pCmd
->
isInsertFromFile
=
-
1
;
pSql
->
res
.
numOfRows
=
0
;
pSql
->
res
.
numOfRows
=
0
;
return
doParse
r
InsertSql
(
pSql
,
sql
+
index
);
return
doParseInsertSql
(
pSql
,
sql
+
index
);
}
}
int
tsParseSql
(
SSqlObj
*
pSql
,
char
*
acct
,
char
*
db
,
bool
multiVnodeInsertion
)
{
int
tsParseSql
(
SSqlObj
*
pSql
,
char
*
acct
,
char
*
db
,
bool
multiVnodeInsertion
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
// must before clean the sqlcmd object
// must before clean the sqlcmd object
tscRemoveAll
MeterMetaInfo
(
&
pSql
->
cmd
,
false
);
// tscRemove
MeterMetaInfo(&pSql->cmd, false);
if
(
NULL
==
pSql
->
asyncTblPos
)
{
if
(
NULL
==
pSql
->
asyncTblPos
)
{
tscCleanSqlCmd
(
&
pSql
->
cmd
);
tscCleanSqlCmd
(
&
pSql
->
cmd
);
...
@@ -1287,7 +1287,7 @@ static int doPackSendDataBlock(SSqlObj *pSql, int32_t numOfRows, STableDataBlock
...
@@ -1287,7 +1287,7 @@ static int doPackSendDataBlock(SSqlObj *pSql, int32_t numOfRows, STableDataBlock
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMeta
*
pMeterMeta
=
tscGetMeterMetaInfo
(
pCmd
,
0
)
->
pMeterMeta
;
SMeterMeta
*
pMeterMeta
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
)
->
pMeterMeta
;
SShellSubmitBlock
*
pBlocks
=
(
SShellSubmitBlock
*
)(
pTableDataBlocks
->
pData
);
SShellSubmitBlock
*
pBlocks
=
(
SShellSubmitBlock
*
)(
pTableDataBlocks
->
pData
);
tsSetBlockInfo
(
pBlocks
,
pMeterMeta
,
numOfRows
);
tsSetBlockInfo
(
pBlocks
,
pMeterMeta
,
numOfRows
);
...
@@ -1319,7 +1319,7 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) {
...
@@ -1319,7 +1319,7 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) {
int
numOfRows
=
0
;
int
numOfRows
=
0
;
int32_t
code
=
0
;
int32_t
code
=
0
;
int
nrows
=
0
;
int
nrows
=
0
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
SMeterMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
SMeterMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
int32_t
rowSize
=
pMeterMeta
->
rowSize
;
int32_t
rowSize
=
pMeterMeta
->
rowSize
;
...
@@ -1415,7 +1415,7 @@ void tscProcessMultiVnodesInsert(SSqlObj *pSql) {
...
@@ -1415,7 +1415,7 @@ void tscProcessMultiVnodesInsert(SSqlObj *pSql) {
}
}
STableDataBlocks
*
pDataBlock
=
NULL
;
STableDataBlocks
*
pDataBlock
=
NULL
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
/* the first block has been sent to server in processSQL function */
/* the first block has been sent to server in processSQL function */
...
@@ -1450,7 +1450,7 @@ void tscProcessMultiVnodesInsertForFile(SSqlObj *pSql) {
...
@@ -1450,7 +1450,7 @@ void tscProcessMultiVnodesInsertForFile(SSqlObj *pSql) {
return
;
return
;
}
}
SMeterMetaInfo
*
pInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
STableDataBlocks
*
pDataBlock
=
NULL
;
STableDataBlocks
*
pDataBlock
=
NULL
;
int32_t
affected_rows
=
0
;
int32_t
affected_rows
=
0
;
...
...
src/client/src/tscPrepare.c
浏览文件 @
e15aa9b1
...
@@ -409,7 +409,7 @@ static int insertStmtReset(STscStmt* pStmt) {
...
@@ -409,7 +409,7 @@ static int insertStmtReset(STscStmt* pStmt) {
}
}
pCmd
->
batchSize
=
0
;
pCmd
->
batchSize
=
0
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
pMeterMetaInfo
->
vnodeIndex
=
0
;
pMeterMetaInfo
->
vnodeIndex
=
0
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -423,7 +423,7 @@ static int insertStmtExecute(STscStmt* stmt) {
...
@@ -423,7 +423,7 @@ static int insertStmtExecute(STscStmt* stmt) {
++
pCmd
->
batchSize
;
++
pCmd
->
batchSize
;
}
}
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
if
(
pCmd
->
pDataBlocks
->
nSize
>
0
)
{
if
(
pCmd
->
pDataBlocks
->
nSize
>
0
)
{
// merge according to vgid
// merge according to vgid
...
...
src/client/src/tscSQLParser.c
浏览文件 @
e15aa9b1
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
src/client/src/tscSecondaryMerge.c
浏览文件 @
e15aa9b1
...
@@ -58,12 +58,13 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu
...
@@ -58,12 +58,13 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu
* the fields and offset attributes in pCmd and pModel may be different due to
* the fields and offset attributes in pCmd and pModel may be different due to
* merge requirement. So, the final result in pRes structure is formatted in accordance with the pCmd object.
* merge requirement. So, the final result in pRes structure is formatted in accordance with the pCmd object.
*/
*/
for
(
int32_t
i
=
0
;
i
<
pCmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
SQLFunctionCtx
*
pCtx
=
&
pReducer
->
pCtx
[
i
];
SQLFunctionCtx
*
pCtx
=
&
pReducer
->
pCtx
[
i
];
pCtx
->
aOutputBuf
=
pReducer
->
pResultBuf
->
data
+
tscFieldInfoGetOffset
(
p
Cmd
,
i
)
*
pReducer
->
resColModel
->
maxCapacity
;
pCtx
->
aOutputBuf
=
pReducer
->
pResultBuf
->
data
+
tscFieldInfoGetOffset
(
p
QueryInfo
,
i
)
*
pReducer
->
resColModel
->
maxCapacity
;
pCtx
->
order
=
p
Cmd
->
order
.
order
;
pCtx
->
order
=
p
QueryInfo
->
order
.
order
;
pCtx
->
functionId
=
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
.
pExprs
[
i
].
functionId
;
pCtx
->
functionId
=
p
QueryInfo
->
exprsInfo
.
pExprs
[
i
].
functionId
;
// input buffer hold only one point data
// input buffer hold only one point data
pCtx
->
aInputElemBuf
=
pReducer
->
pTempBuffer
->
data
+
pDesc
->
pSchema
->
colOffset
[
i
];
pCtx
->
aInputElemBuf
=
pReducer
->
pTempBuffer
->
data
+
pDesc
->
pSchema
->
colOffset
[
i
];
...
@@ -72,7 +73,7 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu
...
@@ -72,7 +73,7 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu
pCtx
->
inputType
=
pDesc
->
pSchema
->
pFields
[
i
].
type
;
pCtx
->
inputType
=
pDesc
->
pSchema
->
pFields
[
i
].
type
;
pCtx
->
inputBytes
=
pDesc
->
pSchema
->
pFields
[
i
].
bytes
;
pCtx
->
inputBytes
=
pDesc
->
pSchema
->
pFields
[
i
].
bytes
;
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
i
);
// output data format yet comes from pCmd.
// output data format yet comes from pCmd.
pCtx
->
outputBytes
=
pField
->
bytes
;
pCtx
->
outputBytes
=
pField
->
bytes
;
pCtx
->
outputType
=
pField
->
type
;
pCtx
->
outputType
=
pField
->
type
;
...
@@ -84,15 +85,15 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu
...
@@ -84,15 +85,15 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu
pRes
->
bytes
[
i
]
=
pField
->
bytes
;
pRes
->
bytes
[
i
]
=
pField
->
bytes
;
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
i
);
// for top/bottom function, the output of timestamp is the first column
// for top/bottom function, the output of timestamp is the first column
int32_t
functionId
=
pExpr
->
functionId
;
int32_t
functionId
=
pExpr
->
functionId
;
if
(
functionId
==
TSDB_FUNC_TOP
||
functionId
==
TSDB_FUNC_BOTTOM
)
{
if
(
functionId
==
TSDB_FUNC_TOP
||
functionId
==
TSDB_FUNC_BOTTOM
)
{
pCtx
->
ptsOutputBuf
=
pReducer
->
pCtx
[
0
].
aOutputBuf
;
pCtx
->
ptsOutputBuf
=
pReducer
->
pCtx
[
0
].
aOutputBuf
;
pCtx
->
param
[
2
].
i64Key
=
p
Cmd
->
order
.
order
;
pCtx
->
param
[
2
].
i64Key
=
p
QueryInfo
->
order
.
order
;
pCtx
->
param
[
2
].
nType
=
TSDB_DATA_TYPE_BIGINT
;
pCtx
->
param
[
2
].
nType
=
TSDB_DATA_TYPE_BIGINT
;
pCtx
->
param
[
1
].
i64Key
=
p
Cmd
->
order
.
orderColId
;
pCtx
->
param
[
1
].
i64Key
=
p
QueryInfo
->
order
.
orderColId
;
}
}
SResultInfo
*
pResInfo
=
&
pReducer
->
pResInfo
[
i
];
SResultInfo
*
pResInfo
=
&
pReducer
->
pResInfo
[
i
];
...
@@ -105,11 +106,11 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu
...
@@ -105,11 +106,11 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu
int16_t
n
=
0
;
int16_t
n
=
0
;
int16_t
tagLen
=
0
;
int16_t
tagLen
=
0
;
SQLFunctionCtx
**
pTagCtx
=
calloc
(
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
,
POINTER_BYTES
);
SQLFunctionCtx
**
pTagCtx
=
calloc
(
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
,
POINTER_BYTES
);
SQLFunctionCtx
*
pCtx
=
NULL
;
SQLFunctionCtx
*
pCtx
=
NULL
;
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
i
);
if
(
pExpr
->
functionId
==
TSDB_FUNC_TAG_DUMMY
||
pExpr
->
functionId
==
TSDB_FUNC_TS_DUMMY
)
{
if
(
pExpr
->
functionId
==
TSDB_FUNC_TAG_DUMMY
||
pExpr
->
functionId
==
TSDB_FUNC_TS_DUMMY
)
{
tagLen
+=
pExpr
->
resBytes
;
tagLen
+=
pExpr
->
resBytes
;
pTagCtx
[
n
++
]
=
&
pReducer
->
pCtx
[
i
];
pTagCtx
[
n
++
]
=
&
pReducer
->
pCtx
[
i
];
...
@@ -214,7 +215,9 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
...
@@ -214,7 +215,9 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
printf
(
"load data page into mem for build loser tree: %ld rows
\n
"
,
pDS
->
filePage
.
numOfElems
);
printf
(
"load data page into mem for build loser tree: %ld rows
\n
"
,
pDS
->
filePage
.
numOfElems
);
SSrcColumnInfo
colInfo
[
256
]
=
{
0
};
SSrcColumnInfo
colInfo
[
256
]
=
{
0
};
tscGetSrcColumnInfo
(
colInfo
,
pCmd
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
tscGetSrcColumnInfo
(
colInfo
,
pQueryInfo
);
tColModelDisplayEx
(
pDesc
->
pSchema
,
pDS
->
filePage
.
data
,
pDS
->
filePage
.
numOfElems
,
pMemBuffer
[
0
]
->
numOfElemsPerPage
,
tColModelDisplayEx
(
pDesc
->
pSchema
,
pDS
->
filePage
.
data
,
pDS
->
filePage
.
numOfElems
,
pMemBuffer
[
0
]
->
numOfElemsPerPage
,
colInfo
);
colInfo
);
...
@@ -238,7 +241,9 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
...
@@ -238,7 +241,9 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
param
->
pLocalData
=
pReducer
->
pLocalDataSrc
;
param
->
pLocalData
=
pReducer
->
pLocalDataSrc
;
param
->
pDesc
=
pReducer
->
pDesc
;
param
->
pDesc
=
pReducer
->
pDesc
;
param
->
numOfElems
=
pReducer
->
pLocalDataSrc
[
0
]
->
pMemBuffer
->
numOfElemsPerPage
;
param
->
numOfElems
=
pReducer
->
pLocalDataSrc
[
0
]
->
pMemBuffer
->
numOfElemsPerPage
;
param
->
groupOrderType
=
pCmd
->
pQueryInfo
[
0
].
groupbyExpr
.
orderType
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
param
->
groupOrderType
=
pQueryInfo
->
groupbyExpr
.
orderType
;
pRes
->
code
=
tLoserTreeCreate
(
&
pReducer
->
pLoserTree
,
pReducer
->
numOfBuffer
,
param
,
treeComparator
);
pRes
->
code
=
tLoserTreeCreate
(
&
pReducer
->
pLoserTree
,
pReducer
->
numOfBuffer
,
param
,
treeComparator
);
if
(
pReducer
->
pLoserTree
==
NULL
||
pRes
->
code
!=
0
)
{
if
(
pReducer
->
pLoserTree
==
NULL
||
pRes
->
code
!=
0
)
{
...
@@ -247,12 +252,12 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
...
@@ -247,12 +252,12 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
// the input data format follows the old format, but output in a new format.
// the input data format follows the old format, but output in a new format.
// so, all the input must be parsed as old format
// so, all the input must be parsed as old format
pReducer
->
pCtx
=
(
SQLFunctionCtx
*
)
calloc
(
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
,
sizeof
(
SQLFunctionCtx
));
pReducer
->
pCtx
=
(
SQLFunctionCtx
*
)
calloc
(
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
,
sizeof
(
SQLFunctionCtx
));
pReducer
->
rowSize
=
pMemBuffer
[
0
]
->
nElemSize
;
pReducer
->
rowSize
=
pMemBuffer
[
0
]
->
nElemSize
;
tscRestoreSQLFunctionForMetricQuery
(
p
Cmd
);
tscRestoreSQLFunctionForMetricQuery
(
p
QueryInfo
);
tscFieldInfoCalOffset
(
p
Cmd
);
tscFieldInfoCalOffset
(
p
QueryInfo
);
if
(
pReducer
->
rowSize
>
pMemBuffer
[
0
]
->
nPageSize
)
{
if
(
pReducer
->
rowSize
>
pMemBuffer
[
0
]
->
nPageSize
)
{
assert
(
false
);
// todo fixed row size is larger than the minimum page size;
assert
(
false
);
// todo fixed row size is larger than the minimum page size;
...
@@ -272,7 +277,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
...
@@ -272,7 +277,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
pReducer
->
nResultBufSize
=
pMemBuffer
[
0
]
->
nPageSize
*
16
;
pReducer
->
nResultBufSize
=
pMemBuffer
[
0
]
->
nPageSize
*
16
;
pReducer
->
pResultBuf
=
(
tFilePage
*
)
calloc
(
1
,
pReducer
->
nResultBufSize
+
sizeof
(
tFilePage
));
pReducer
->
pResultBuf
=
(
tFilePage
*
)
calloc
(
1
,
pReducer
->
nResultBufSize
+
sizeof
(
tFilePage
));
int32_t
finalRowLength
=
tscGetResRowLength
(
p
Cmd
);
int32_t
finalRowLength
=
tscGetResRowLength
(
p
QueryInfo
);
pReducer
->
resColModel
=
finalmodel
;
pReducer
->
resColModel
=
finalmodel
;
pReducer
->
resColModel
->
maxCapacity
=
pReducer
->
nResultBufSize
/
finalRowLength
;
pReducer
->
resColModel
->
maxCapacity
=
pReducer
->
nResultBufSize
/
finalRowLength
;
assert
(
finalRowLength
<=
pReducer
->
rowSize
);
assert
(
finalRowLength
<=
pReducer
->
rowSize
);
...
@@ -294,33 +299,33 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
...
@@ -294,33 +299,33 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
}
}
pReducer
->
pTempBuffer
->
numOfElems
=
0
;
pReducer
->
pTempBuffer
->
numOfElems
=
0
;
pReducer
->
pResInfo
=
calloc
((
size_t
)
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
,
sizeof
(
SResultInfo
));
pReducer
->
pResInfo
=
calloc
((
size_t
)
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
,
sizeof
(
SResultInfo
));
tscCreateResPointerInfo
(
p
Cmd
,
pRes
);
tscCreateResPointerInfo
(
p
QueryInfo
,
pRes
);
tscInitSqlContext
(
pCmd
,
pRes
,
pReducer
,
pDesc
);
tscInitSqlContext
(
pCmd
,
pRes
,
pReducer
,
pDesc
);
// we change the maxCapacity of schema to denote that there is only one row in temp buffer
// we change the maxCapacity of schema to denote that there is only one row in temp buffer
pReducer
->
pDesc
->
pSchema
->
maxCapacity
=
1
;
pReducer
->
pDesc
->
pSchema
->
maxCapacity
=
1
;
pReducer
->
offset
=
p
Cmd
->
p
QueryInfo
->
limit
.
offset
;
pReducer
->
offset
=
pQueryInfo
->
limit
.
offset
;
pRes
->
pLocalReducer
=
pReducer
;
pRes
->
pLocalReducer
=
pReducer
;
pRes
->
numOfGroups
=
0
;
pRes
->
numOfGroups
=
0
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
int16_t
prec
=
pMeterMetaInfo
->
pMeterMeta
->
precision
;
int16_t
prec
=
pMeterMetaInfo
->
pMeterMeta
->
precision
;
int64_t
stime
=
(
p
Cmd
->
pQueryInfo
[
0
].
stime
<
pCmd
->
pQueryInfo
[
0
].
etime
)
?
pCmd
->
pQueryInfo
[
0
].
stime
:
pCmd
->
pQueryInfo
[
0
].
etime
;
int64_t
stime
=
(
p
QueryInfo
->
stime
<
pQueryInfo
->
etime
)
?
pQueryInfo
->
stime
:
pQueryInfo
->
etime
;
int64_t
revisedSTime
=
taosGetIntervalStartTimestamp
(
stime
,
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
,
pCmd
->
pQueryInfo
[
0
].
intervalTimeUnit
,
prec
);
int64_t
revisedSTime
=
taosGetIntervalStartTimestamp
(
stime
,
p
QueryInfo
->
nAggTimeInterval
,
pQueryInfo
->
intervalTimeUnit
,
prec
);
SInterpolationInfo
*
pInterpoInfo
=
&
pReducer
->
interpolationInfo
;
SInterpolationInfo
*
pInterpoInfo
=
&
pReducer
->
interpolationInfo
;
taosInitInterpoInfo
(
pInterpoInfo
,
p
Cmd
->
order
.
order
,
revisedSTime
,
pCmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
,
taosInitInterpoInfo
(
pInterpoInfo
,
p
QueryInfo
->
order
.
order
,
revisedSTime
,
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
,
pReducer
->
rowSize
);
pReducer
->
rowSize
);
int32_t
startIndex
=
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
-
pCmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
;
int32_t
startIndex
=
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
-
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
;
if
(
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
>
0
)
{
if
(
p
QueryInfo
->
groupbyExpr
.
numOfGroupCols
>
0
)
{
pInterpoInfo
->
pTags
[
0
]
=
(
char
*
)
pInterpoInfo
->
pTags
+
POINTER_BYTES
*
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
;
pInterpoInfo
->
pTags
[
0
]
=
(
char
*
)
pInterpoInfo
->
pTags
+
POINTER_BYTES
*
p
QueryInfo
->
groupbyExpr
.
numOfGroupCols
;
for
(
int32_t
i
=
1
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
;
++
i
)
{
for
(
int32_t
i
=
1
;
i
<
p
QueryInfo
->
groupbyExpr
.
numOfGroupCols
;
++
i
)
{
pInterpoInfo
->
pTags
[
i
]
=
pReducer
->
resColModel
->
pFields
[
startIndex
+
i
-
1
].
bytes
+
pInterpoInfo
->
pTags
[
i
-
1
];
pInterpoInfo
->
pTags
[
i
]
=
pReducer
->
resColModel
->
pFields
[
startIndex
+
i
-
1
].
bytes
+
pInterpoInfo
->
pTags
[
i
-
1
];
}
}
}
else
{
}
else
{
...
@@ -429,6 +434,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
...
@@ -429,6 +434,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
}
}
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
// there is no more result, so we release all allocated resource
// there is no more result, so we release all allocated resource
SLocalReducer
*
pLocalReducer
=
(
SLocalReducer
*
)
atomic_exchange_ptr
(
&
pRes
->
pLocalReducer
,
NULL
);
SLocalReducer
*
pLocalReducer
=
(
SLocalReducer
*
)
atomic_exchange_ptr
(
&
pRes
->
pLocalReducer
,
NULL
);
...
@@ -444,7 +450,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
...
@@ -444,7 +450,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
tfree
(
pLocalReducer
->
interpolationInfo
.
pTags
);
tfree
(
pLocalReducer
->
interpolationInfo
.
pTags
);
if
(
pLocalReducer
->
pCtx
!=
NULL
)
{
if
(
pLocalReducer
->
pCtx
!=
NULL
)
{
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
SQLFunctionCtx
*
pCtx
=
&
pLocalReducer
->
pCtx
[
i
];
SQLFunctionCtx
*
pCtx
=
&
pLocalReducer
->
pCtx
[
i
];
tVariantDestroy
(
&
pCtx
->
tag
);
tVariantDestroy
(
&
pCtx
->
tag
);
}
}
...
@@ -459,7 +465,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
...
@@ -459,7 +465,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
tfree
(
pLocalReducer
->
pResultBuf
);
tfree
(
pLocalReducer
->
pResultBuf
);
if
(
pLocalReducer
->
pResInfo
!=
NULL
)
{
if
(
pLocalReducer
->
pResInfo
!=
NULL
)
{
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
tfree
(
pLocalReducer
->
pResInfo
[
i
].
interResultBuf
);
tfree
(
pLocalReducer
->
pResInfo
[
i
].
interResultBuf
);
}
}
...
@@ -494,12 +500,14 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
...
@@ -494,12 +500,14 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
static
int32_t
createOrderDescriptor
(
tOrderDescriptor
**
pOrderDesc
,
SSqlCmd
*
pCmd
,
tColModel
*
pModel
)
{
static
int32_t
createOrderDescriptor
(
tOrderDescriptor
**
pOrderDesc
,
SSqlCmd
*
pCmd
,
tColModel
*
pModel
)
{
int32_t
numOfGroupByCols
=
0
;
int32_t
numOfGroupByCols
=
0
;
if
(
pCmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
>
0
)
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
numOfGroupByCols
=
pCmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
;
if
(
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
>
0
)
{
numOfGroupByCols
=
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
;
}
}
// primary timestamp column is involved in final result
// primary timestamp column is involved in final result
if
(
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
!=
0
)
{
if
(
p
QueryInfo
->
nAggTimeInterval
!=
0
)
{
numOfGroupByCols
++
;
numOfGroupByCols
++
;
}
}
...
@@ -509,20 +517,20 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
...
@@ -509,20 +517,20 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
}
}
if
(
numOfGroupByCols
>
0
)
{
if
(
numOfGroupByCols
>
0
)
{
int32_t
startCols
=
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
-
pCmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
;
int32_t
startCols
=
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
-
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
;
// tags value locate at the last columns
// tags value locate at the last columns
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
groupbyExpr
.
numOfGroupCols
;
++
i
)
{
orderIdx
[
i
]
=
startCols
++
;
orderIdx
[
i
]
=
startCols
++
;
}
}
if
(
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
!=
0
)
{
if
(
p
QueryInfo
->
nAggTimeInterval
!=
0
)
{
// the first column is the timestamp, handles queries like "interval(10m) group by tags"
// the first column is the timestamp, handles queries like "interval(10m) group by tags"
orderIdx
[
numOfGroupByCols
-
1
]
=
PRIMARYKEY_TIMESTAMP_COL_INDEX
;
orderIdx
[
numOfGroupByCols
-
1
]
=
PRIMARYKEY_TIMESTAMP_COL_INDEX
;
}
}
}
}
*
pOrderDesc
=
tOrderDesCreate
(
orderIdx
,
numOfGroupByCols
,
pModel
,
p
Cmd
->
order
.
order
);
*
pOrderDesc
=
tOrderDesCreate
(
orderIdx
,
numOfGroupByCols
,
pModel
,
p
QueryInfo
->
order
.
order
);
tfree
(
orderIdx
);
tfree
(
orderIdx
);
if
(
*
pOrderDesc
==
NULL
)
{
if
(
*
pOrderDesc
==
NULL
)
{
...
@@ -533,7 +541,9 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
...
@@ -533,7 +541,9 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
}
}
bool
isSameGroup
(
SSqlCmd
*
pCmd
,
SLocalReducer
*
pReducer
,
char
*
pPrev
,
tFilePage
*
tmpBuffer
)
{
bool
isSameGroup
(
SSqlCmd
*
pCmd
,
SLocalReducer
*
pReducer
,
char
*
pPrev
,
tFilePage
*
tmpBuffer
)
{
int16_t
functionId
=
tscSqlExprGet
(
pCmd
,
0
)
->
functionId
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
int16_t
functionId
=
tscSqlExprGet
(
pQueryInfo
,
0
)
->
functionId
;
// disable merge procedure for column projection query
// disable merge procedure for column projection query
if
(
functionId
==
TSDB_FUNC_PRJ
||
functionId
==
TSDB_FUNC_ARITHM
)
{
if
(
functionId
==
TSDB_FUNC_PRJ
||
functionId
==
TSDB_FUNC_ARITHM
)
{
...
@@ -550,10 +560,10 @@ bool isSameGroup(SSqlCmd *pCmd, SLocalReducer *pReducer, char *pPrev, tFilePage
...
@@ -550,10 +560,10 @@ bool isSameGroup(SSqlCmd *pCmd, SLocalReducer *pReducer, char *pPrev, tFilePage
if
(
pOrderDesc
->
orderIdx
.
pData
[
numOfCols
-
1
]
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
//<= 0
if
(
pOrderDesc
->
orderIdx
.
pData
[
numOfCols
-
1
]
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
//<= 0
// super table interval query
// super table interval query
assert
(
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
>
0
);
assert
(
p
QueryInfo
->
nAggTimeInterval
>
0
);
pOrderDesc
->
orderIdx
.
numOfOrderedCols
-=
1
;
pOrderDesc
->
orderIdx
.
numOfOrderedCols
-=
1
;
}
else
{
// simple group by query
}
else
{
// simple group by query
assert
(
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
==
0
);
assert
(
p
QueryInfo
->
nAggTimeInterval
==
0
);
}
}
// only one row exists
// only one row exists
...
@@ -572,7 +582,8 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
...
@@ -572,7 +582,8 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
tColModel
*
pModel
=
NULL
;
tColModel
*
pModel
=
NULL
;
*
pFinalModel
=
NULL
;
*
pFinalModel
=
NULL
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
(
*
pMemBuffer
)
=
(
tExtMemBuffer
**
)
malloc
(
POINTER_BYTES
*
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
);
(
*
pMemBuffer
)
=
(
tExtMemBuffer
**
)
malloc
(
POINTER_BYTES
*
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
);
if
(
*
pMemBuffer
==
NULL
)
{
if
(
*
pMemBuffer
==
NULL
)
{
...
@@ -581,7 +592,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
...
@@ -581,7 +592,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
return
pRes
->
code
;
return
pRes
->
code
;
}
}
pSchema
=
(
SSchema
*
)
calloc
(
1
,
sizeof
(
SSchema
)
*
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
);
pSchema
=
(
SSchema
*
)
calloc
(
1
,
sizeof
(
SSchema
)
*
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
);
if
(
pSchema
==
NULL
)
{
if
(
pSchema
==
NULL
)
{
tscError
(
"%p failed to allocate memory"
,
pSql
);
tscError
(
"%p failed to allocate memory"
,
pSql
);
pRes
->
code
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
pRes
->
code
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
...
@@ -589,8 +600,8 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
...
@@ -589,8 +600,8 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
}
}
int32_t
rlen
=
0
;
int32_t
rlen
=
0
;
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
i
);
pSchema
[
i
].
bytes
=
pExpr
->
resBytes
;
pSchema
[
i
].
bytes
=
pExpr
->
resBytes
;
pSchema
[
i
].
type
=
pExpr
->
resType
;
pSchema
[
i
].
type
=
pExpr
->
resType
;
...
@@ -599,7 +610,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
...
@@ -599,7 +610,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
}
}
int32_t
capacity
=
nBufferSizes
/
rlen
;
int32_t
capacity
=
nBufferSizes
/
rlen
;
pModel
=
tColModelCreate
(
pSchema
,
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
,
capacity
);
pModel
=
tColModelCreate
(
pSchema
,
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
,
capacity
);
for
(
int32_t
i
=
0
;
i
<
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
;
++
i
)
{
char
tmpPath
[
512
]
=
{
0
};
char
tmpPath
[
512
]
=
{
0
};
...
@@ -615,16 +626,16 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
...
@@ -615,16 +626,16 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
return
pRes
->
code
;
return
pRes
->
code
;
}
}
memset
(
pSchema
,
0
,
sizeof
(
SSchema
)
*
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
);
memset
(
pSchema
,
0
,
sizeof
(
SSchema
)
*
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
);
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
i
);
pSchema
[
i
].
type
=
pField
->
type
;
pSchema
[
i
].
type
=
pField
->
type
;
pSchema
[
i
].
bytes
=
pField
->
bytes
;
pSchema
[
i
].
bytes
=
pField
->
bytes
;
strcpy
(
pSchema
[
i
].
name
,
pField
->
name
);
strcpy
(
pSchema
[
i
].
name
,
pField
->
name
);
}
}
*
pFinalModel
=
tColModelCreate
(
pSchema
,
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
,
capacity
);
*
pFinalModel
=
tColModelCreate
(
pSchema
,
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
,
capacity
);
tfree
(
pSchema
);
tfree
(
pSchema
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -714,15 +725,15 @@ void adjustLoserTreeFromNewData(SLocalReducer *pLocalReducer, SLocalDataSource *
...
@@ -714,15 +725,15 @@ void adjustLoserTreeFromNewData(SLocalReducer *pLocalReducer, SLocalDataSource *
}
}
}
}
void
savePrevRecordAndSetupInterpoInfo
(
SLocalReducer
*
pLocalReducer
,
S
SqlCmd
*
pCmd
,
SInterpolationInfo
*
pInterpoInfo
)
{
void
savePrevRecordAndSetupInterpoInfo
(
SLocalReducer
*
pLocalReducer
,
S
QueryInfo
*
pQueryInfo
,
SInterpolationInfo
*
pInterpoInfo
)
{
// discard following dataset in the same group and reset the interpolation information
// discard following dataset in the same group and reset the interpolation information
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
0
);
int16_t
prec
=
pMeterMetaInfo
->
pMeterMeta
->
precision
;
int16_t
prec
=
pMeterMetaInfo
->
pMeterMeta
->
precision
;
int64_t
stime
=
(
p
Cmd
->
pQueryInfo
[
0
].
stime
<
pCmd
->
pQueryInfo
[
0
].
etime
)
?
pCmd
->
pQueryInfo
[
0
].
stime
:
pCmd
->
pQueryInfo
[
0
].
etime
;
int64_t
stime
=
(
p
QueryInfo
->
stime
<
pQueryInfo
->
etime
)
?
pQueryInfo
->
stime
:
pQueryInfo
->
etime
;
int64_t
revisedSTime
=
taosGetIntervalStartTimestamp
(
stime
,
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
,
pCmd
->
pQueryInfo
[
0
].
intervalTimeUnit
,
prec
);
int64_t
revisedSTime
=
taosGetIntervalStartTimestamp
(
stime
,
p
QueryInfo
->
nAggTimeInterval
,
pQueryInfo
->
intervalTimeUnit
,
prec
);
taosInitInterpoInfo
(
pInterpoInfo
,
p
Cmd
->
order
.
order
,
revisedSTime
,
pCmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
,
taosInitInterpoInfo
(
pInterpoInfo
,
p
QueryInfo
->
order
.
order
,
revisedSTime
,
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
,
pLocalReducer
->
rowSize
);
pLocalReducer
->
rowSize
);
pLocalReducer
->
discard
=
true
;
pLocalReducer
->
discard
=
true
;
...
@@ -733,11 +744,12 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SSqlCmd *pC
...
@@ -733,11 +744,12 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SSqlCmd *pC
}
}
// todo merge with following function
// todo merge with following function
static
void
reversedCopyResultToDstBuf
(
SSqlCmd
*
pCmd
,
SSqlRes
*
pRes
,
tFilePage
*
pFinalDataPage
)
{
static
void
reversedCopyResultToDstBuf
(
SQueryInfo
*
pQueryInfo
,
SSqlRes
*
pRes
,
tFilePage
*
pFinalDataPage
)
{
for
(
int32_t
i
=
0
;
i
<
pCmd
->
pQueryInfo
[
0
].
exprsInfo
.
numOfExprs
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
pCmd
,
i
);
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
pQueryInfo
,
i
);
int32_t
offset
=
tscFieldInfoGetOffset
(
p
Cmd
,
i
);
int32_t
offset
=
tscFieldInfoGetOffset
(
p
QueryInfo
,
i
);
char
*
src
=
pFinalDataPage
->
data
+
(
pRes
->
numOfRows
-
1
)
*
pField
->
bytes
+
pRes
->
numOfRows
*
offset
;
char
*
src
=
pFinalDataPage
->
data
+
(
pRes
->
numOfRows
-
1
)
*
pField
->
bytes
+
pRes
->
numOfRows
*
offset
;
char
*
dst
=
pRes
->
data
+
pRes
->
numOfRows
*
offset
;
char
*
dst
=
pRes
->
data
+
pRes
->
numOfRows
*
offset
;
...
@@ -749,12 +761,11 @@ static void reversedCopyResultToDstBuf(SSqlCmd *pCmd, SSqlRes *pRes, tFilePage *
...
@@ -749,12 +761,11 @@ static void reversedCopyResultToDstBuf(SSqlCmd *pCmd, SSqlRes *pRes, tFilePage *
}
}
}
}
static
void
reversedCopyFromInterpolationToDstBuf
(
SSqlCmd
*
pCmd
,
SSqlRes
*
pRes
,
tFilePage
**
pResPages
,
static
void
reversedCopyFromInterpolationToDstBuf
(
SQueryInfo
*
pQueryInfo
,
SSqlRes
*
pRes
,
tFilePage
**
pResPages
,
SLocalReducer
*
pLocalReducer
)
{
SLocalReducer
*
pLocalReducer
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pCmd
->
pQueryInfo
[
0
].
exprsInfo
.
numOfExprs
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
pQueryInfo
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
pCmd
,
i
);
int32_t
offset
=
tscFieldInfoGetOffset
(
p
Cmd
,
i
);
int32_t
offset
=
tscFieldInfoGetOffset
(
p
QueryInfo
,
i
);
assert
(
offset
==
pLocalReducer
->
resColModel
->
colOffset
[
i
]);
assert
(
offset
==
pLocalReducer
->
resColModel
->
colOffset
[
i
]);
char
*
src
=
pResPages
[
i
]
->
data
+
(
pRes
->
numOfRows
-
1
)
*
pField
->
bytes
;
char
*
src
=
pResPages
[
i
]
->
data
+
(
pRes
->
numOfRows
-
1
)
*
pField
->
bytes
;
...
@@ -776,6 +787,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
...
@@ -776,6 +787,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
tFilePage
*
pFinalDataPage
=
pLocalReducer
->
pResultBuf
;
tFilePage
*
pFinalDataPage
=
pLocalReducer
->
pResultBuf
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
if
(
pRes
->
pLocalReducer
!=
pLocalReducer
)
{
if
(
pRes
->
pLocalReducer
!=
pLocalReducer
)
{
/*
/*
...
@@ -786,100 +798,101 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
...
@@ -786,100 +798,101 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
assert
(
pRes
->
pLocalReducer
==
NULL
);
assert
(
pRes
->
pLocalReducer
==
NULL
);
}
}
if
(
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
==
0
||
pCmd
->
pQueryInfo
[
0
].
interpoType
==
TSDB_INTERPO_NONE
)
{
if
(
p
QueryInfo
->
nAggTimeInterval
==
0
||
pQueryInfo
->
interpoType
==
TSDB_INTERPO_NONE
)
{
// no interval query, no interpolation
// no interval query, no interpolation
pRes
->
data
=
pLocalReducer
->
pFinalRes
;
pRes
->
data
=
pLocalReducer
->
pFinalRes
;
pRes
->
numOfRows
=
pFinalDataPage
->
numOfElems
;
pRes
->
numOfRows
=
pFinalDataPage
->
numOfElems
;
pRes
->
numOfTotal
+=
pRes
->
numOfRows
;
pRes
->
numOfTotal
+=
pRes
->
numOfRows
;
if
(
p
Cmd
->
p
QueryInfo
->
limit
.
offset
>
0
)
{
if
(
pQueryInfo
->
limit
.
offset
>
0
)
{
if
(
p
Cmd
->
p
QueryInfo
->
limit
.
offset
<
pRes
->
numOfRows
)
{
if
(
pQueryInfo
->
limit
.
offset
<
pRes
->
numOfRows
)
{
int32_t
prevSize
=
pFinalDataPage
->
numOfElems
;
int32_t
prevSize
=
pFinalDataPage
->
numOfElems
;
tColModelErase
(
pLocalReducer
->
resColModel
,
pFinalDataPage
,
prevSize
,
0
,
p
Cmd
->
p
QueryInfo
->
limit
.
offset
-
1
);
tColModelErase
(
pLocalReducer
->
resColModel
,
pFinalDataPage
,
prevSize
,
0
,
pQueryInfo
->
limit
.
offset
-
1
);
/* remove the hole in column model */
/* remove the hole in column model */
tColModelCompact
(
pLocalReducer
->
resColModel
,
pFinalDataPage
,
prevSize
);
tColModelCompact
(
pLocalReducer
->
resColModel
,
pFinalDataPage
,
prevSize
);
pRes
->
numOfRows
-=
p
Cmd
->
p
QueryInfo
->
limit
.
offset
;
pRes
->
numOfRows
-=
pQueryInfo
->
limit
.
offset
;
pRes
->
numOfTotal
-=
p
Cmd
->
p
QueryInfo
->
limit
.
offset
;
pRes
->
numOfTotal
-=
pQueryInfo
->
limit
.
offset
;
p
Cmd
->
p
QueryInfo
->
limit
.
offset
=
0
;
pQueryInfo
->
limit
.
offset
=
0
;
}
else
{
}
else
{
p
Cmd
->
p
QueryInfo
->
limit
.
offset
-=
pRes
->
numOfRows
;
pQueryInfo
->
limit
.
offset
-=
pRes
->
numOfRows
;
pRes
->
numOfRows
=
0
;
pRes
->
numOfRows
=
0
;
pRes
->
numOfTotal
=
0
;
pRes
->
numOfTotal
=
0
;
}
}
}
}
if
(
p
Cmd
->
pQueryInfo
->
limit
.
limit
>=
0
&&
pRes
->
numOfTotal
>
pCmd
->
pQueryInfo
->
limit
.
limit
)
{
if
(
p
QueryInfo
->
limit
.
limit
>=
0
&&
pRes
->
numOfTotal
>
pQueryInfo
->
limit
.
limit
)
{
/* impose the limitation of output rows on the final result */
/* impose the limitation of output rows on the final result */
int32_t
prevSize
=
pFinalDataPage
->
numOfElems
;
int32_t
prevSize
=
pFinalDataPage
->
numOfElems
;
int32_t
overFlow
=
pRes
->
numOfTotal
-
p
Cmd
->
p
QueryInfo
->
limit
.
limit
;
int32_t
overFlow
=
pRes
->
numOfTotal
-
pQueryInfo
->
limit
.
limit
;
assert
(
overFlow
<
pRes
->
numOfRows
);
assert
(
overFlow
<
pRes
->
numOfRows
);
pRes
->
numOfTotal
=
p
Cmd
->
p
QueryInfo
->
limit
.
limit
;
pRes
->
numOfTotal
=
pQueryInfo
->
limit
.
limit
;
pRes
->
numOfRows
-=
overFlow
;
pRes
->
numOfRows
-=
overFlow
;
pFinalDataPage
->
numOfElems
-=
overFlow
;
pFinalDataPage
->
numOfElems
-=
overFlow
;
tColModelCompact
(
pLocalReducer
->
resColModel
,
pFinalDataPage
,
prevSize
);
tColModelCompact
(
pLocalReducer
->
resColModel
,
pFinalDataPage
,
prevSize
);
/* set remain data to be discarded, and reset the interpolation information */
/* set remain data to be discarded, and reset the interpolation information */
savePrevRecordAndSetupInterpoInfo
(
pLocalReducer
,
p
Cmd
,
&
pLocalReducer
->
interpolationInfo
);
savePrevRecordAndSetupInterpoInfo
(
pLocalReducer
,
p
QueryInfo
,
&
pLocalReducer
->
interpolationInfo
);
}
}
int32_t
rowSize
=
tscGetResRowLength
(
p
Cmd
);
int32_t
rowSize
=
tscGetResRowLength
(
p
QueryInfo
);
// handle the descend order output
// handle the descend order output
if
(
p
Cmd
->
order
.
order
==
TSQL_SO_ASC
)
{
if
(
p
QueryInfo
->
order
.
order
==
TSQL_SO_ASC
)
{
memcpy
(
pRes
->
data
,
pFinalDataPage
->
data
,
pRes
->
numOfRows
*
rowSize
);
memcpy
(
pRes
->
data
,
pFinalDataPage
->
data
,
pRes
->
numOfRows
*
rowSize
);
}
else
{
}
else
{
reversedCopyResultToDstBuf
(
p
Cmd
,
pRes
,
pFinalDataPage
);
reversedCopyResultToDstBuf
(
p
QueryInfo
,
pRes
,
pFinalDataPage
);
}
}
pFinalDataPage
->
numOfElems
=
0
;
pFinalDataPage
->
numOfElems
=
0
;
return
;
return
;
}
}
int64_t
*
pPrimaryKeys
=
(
int64_t
*
)
pLocalReducer
->
pBufForInterpo
;
int64_t
*
pPrimaryKeys
=
(
int64_t
*
)
pLocalReducer
->
pBufForInterpo
;
SInterpolationInfo
*
pInterpoInfo
=
&
pLocalReducer
->
interpolationInfo
;
SInterpolationInfo
*
pInterpoInfo
=
&
pLocalReducer
->
interpolationInfo
;
int64_t
actualETime
=
(
p
Cmd
->
pQueryInfo
[
0
].
stime
<
pCmd
->
pQueryInfo
[
0
].
etime
)
?
pCmd
->
pQueryInfo
[
0
].
etime
:
pCmd
->
pQueryInfo
[
0
].
stime
;
int64_t
actualETime
=
(
p
QueryInfo
->
stime
<
pQueryInfo
->
etime
)
?
pQueryInfo
->
etime
:
pQueryInfo
->
stime
;
tFilePage
**
pResPages
=
malloc
(
POINTER_BYTES
*
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
);
tFilePage
**
pResPages
=
malloc
(
POINTER_BYTES
*
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
);
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
i
);
pResPages
[
i
]
=
calloc
(
1
,
sizeof
(
tFilePage
)
+
pField
->
bytes
*
pLocalReducer
->
resColModel
->
maxCapacity
);
pResPages
[
i
]
=
calloc
(
1
,
sizeof
(
tFilePage
)
+
pField
->
bytes
*
pLocalReducer
->
resColModel
->
maxCapacity
);
}
}
char
**
srcData
=
(
char
**
)
malloc
((
POINTER_BYTES
+
sizeof
(
int32_t
))
*
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
);
char
**
srcData
=
(
char
**
)
malloc
((
POINTER_BYTES
+
sizeof
(
int32_t
))
*
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
);
int32_t
*
functions
=
(
int32_t
*
)((
char
*
)
srcData
+
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
*
sizeof
(
void
*
));
int32_t
*
functions
=
(
int32_t
*
)((
char
*
)
srcData
+
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
*
sizeof
(
void
*
));
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
srcData
[
i
]
=
pLocalReducer
->
pBufForInterpo
+
tscFieldInfoGetOffset
(
p
Cmd
,
i
)
*
pInterpoInfo
->
numOfRawDataInRows
;
srcData
[
i
]
=
pLocalReducer
->
pBufForInterpo
+
tscFieldInfoGetOffset
(
p
QueryInfo
,
i
)
*
pInterpoInfo
->
numOfRawDataInRows
;
functions
[
i
]
=
tscSqlExprGet
(
p
Cmd
,
i
)
->
functionId
;
functions
[
i
]
=
tscSqlExprGet
(
p
QueryInfo
,
i
)
->
functionId
;
}
}
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
int8_t
precision
=
pMeterMetaInfo
->
pMeterMeta
->
precision
;
int8_t
precision
=
pMeterMetaInfo
->
pMeterMeta
->
precision
;
while
(
1
)
{
while
(
1
)
{
int32_t
remains
=
taosNumOfRemainPoints
(
pInterpoInfo
);
int32_t
remains
=
taosNumOfRemainPoints
(
pInterpoInfo
);
TSKEY
etime
=
taosGetRevisedEndKey
(
actualETime
,
p
Cmd
->
order
.
order
,
pCmd
->
pQueryInfo
[
0
].
nAggTimeInterval
,
pCmd
->
pQueryInfo
[
0
].
intervalTimeUnit
,
TSKEY
etime
=
taosGetRevisedEndKey
(
actualETime
,
p
QueryInfo
->
order
.
order
,
pQueryInfo
->
nAggTimeInterval
,
pQueryInfo
->
intervalTimeUnit
,
precision
);
precision
);
int32_t
nrows
=
taosGetNumOfResultWithInterpo
(
pInterpoInfo
,
pPrimaryKeys
,
remains
,
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
,
etime
,
int32_t
nrows
=
taosGetNumOfResultWithInterpo
(
pInterpoInfo
,
pPrimaryKeys
,
remains
,
p
QueryInfo
->
nAggTimeInterval
,
etime
,
pLocalReducer
->
resColModel
->
maxCapacity
);
pLocalReducer
->
resColModel
->
maxCapacity
);
int32_t
newRows
=
taosDoInterpoResult
(
pInterpoInfo
,
p
Cmd
->
pQueryInfo
[
0
].
interpoType
,
pResPages
,
remains
,
nrows
,
int32_t
newRows
=
taosDoInterpoResult
(
pInterpoInfo
,
p
QueryInfo
->
interpoType
,
pResPages
,
remains
,
nrows
,
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
,
pPrimaryKeys
,
pLocalReducer
->
resColModel
,
srcData
,
p
QueryInfo
->
nAggTimeInterval
,
pPrimaryKeys
,
pLocalReducer
->
resColModel
,
srcData
,
p
Cmd
->
pQueryInfo
[
0
].
defaultVal
,
functions
,
pLocalReducer
->
resColModel
->
maxCapacity
);
p
QueryInfo
->
defaultVal
,
functions
,
pLocalReducer
->
resColModel
->
maxCapacity
);
assert
(
newRows
<=
nrows
);
assert
(
newRows
<=
nrows
);
if
(
p
Cmd
->
p
QueryInfo
->
limit
.
offset
<
newRows
)
{
if
(
pQueryInfo
->
limit
.
offset
<
newRows
)
{
newRows
-=
p
Cmd
->
p
QueryInfo
->
limit
.
offset
;
newRows
-=
pQueryInfo
->
limit
.
offset
;
if
(
p
Cmd
->
p
QueryInfo
->
limit
.
offset
>
0
)
{
if
(
pQueryInfo
->
limit
.
offset
>
0
)
{
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
i
);
memmove
(
pResPages
[
i
]
->
data
,
pResPages
[
i
]
->
data
+
pField
->
bytes
*
p
Cmd
->
p
QueryInfo
->
limit
.
offset
,
newRows
*
pField
->
bytes
);
memmove
(
pResPages
[
i
]
->
data
,
pResPages
[
i
]
->
data
+
pField
->
bytes
*
pQueryInfo
->
limit
.
offset
,
newRows
*
pField
->
bytes
);
}
}
}
}
...
@@ -887,10 +900,10 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
...
@@ -887,10 +900,10 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
pRes
->
numOfRows
=
newRows
;
pRes
->
numOfRows
=
newRows
;
pRes
->
numOfTotal
+=
newRows
;
pRes
->
numOfTotal
+=
newRows
;
p
Cmd
->
p
QueryInfo
->
limit
.
offset
=
0
;
pQueryInfo
->
limit
.
offset
=
0
;
break
;
break
;
}
else
{
}
else
{
p
Cmd
->
p
QueryInfo
->
limit
.
offset
-=
newRows
;
pQueryInfo
->
limit
.
offset
-=
newRows
;
pRes
->
numOfRows
=
0
;
pRes
->
numOfRows
=
0
;
int32_t
rpoints
=
taosNumOfRemainPoints
(
pInterpoInfo
);
int32_t
rpoints
=
taosNumOfRemainPoints
(
pInterpoInfo
);
...
@@ -902,7 +915,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
...
@@ -902,7 +915,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
/* all output for current group are completed */
/* all output for current group are completed */
int32_t
totalRemainRows
=
int32_t
totalRemainRows
=
taosGetNumOfResWithoutLimit
(
pInterpoInfo
,
pPrimaryKeys
,
rpoints
,
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
,
actualETime
);
taosGetNumOfResWithoutLimit
(
pInterpoInfo
,
pPrimaryKeys
,
rpoints
,
p
QueryInfo
->
nAggTimeInterval
,
actualETime
);
if
(
totalRemainRows
<=
0
)
{
if
(
totalRemainRows
<=
0
)
{
break
;
break
;
}
}
...
@@ -911,33 +924,33 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
...
@@ -911,33 +924,33 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
}
}
if
(
pRes
->
numOfRows
>
0
)
{
if
(
pRes
->
numOfRows
>
0
)
{
if
(
p
Cmd
->
pQueryInfo
->
limit
.
limit
>=
0
&&
pRes
->
numOfTotal
>
pCmd
->
pQueryInfo
->
limit
.
limit
)
{
if
(
p
QueryInfo
->
limit
.
limit
>=
0
&&
pRes
->
numOfTotal
>
pQueryInfo
->
limit
.
limit
)
{
int32_t
overFlow
=
pRes
->
numOfTotal
-
p
Cmd
->
p
QueryInfo
->
limit
.
limit
;
int32_t
overFlow
=
pRes
->
numOfTotal
-
pQueryInfo
->
limit
.
limit
;
pRes
->
numOfRows
-=
overFlow
;
pRes
->
numOfRows
-=
overFlow
;
assert
(
pRes
->
numOfRows
>=
0
);
assert
(
pRes
->
numOfRows
>=
0
);
pRes
->
numOfTotal
=
p
Cmd
->
p
QueryInfo
->
limit
.
limit
;
pRes
->
numOfTotal
=
pQueryInfo
->
limit
.
limit
;
pFinalDataPage
->
numOfElems
-=
overFlow
;
pFinalDataPage
->
numOfElems
-=
overFlow
;
/* set remain data to be discarded, and reset the interpolation information */
/* set remain data to be discarded, and reset the interpolation information */
savePrevRecordAndSetupInterpoInfo
(
pLocalReducer
,
p
Cmd
,
pInterpoInfo
);
savePrevRecordAndSetupInterpoInfo
(
pLocalReducer
,
p
QueryInfo
,
pInterpoInfo
);
}
}
if
(
p
Cmd
->
order
.
order
==
TSQL_SO_ASC
)
{
if
(
p
QueryInfo
->
order
.
order
==
TSQL_SO_ASC
)
{
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
i
);
memcpy
(
pRes
->
data
+
pLocalReducer
->
resColModel
->
colOffset
[
i
]
*
pRes
->
numOfRows
,
pResPages
[
i
]
->
data
,
memcpy
(
pRes
->
data
+
pLocalReducer
->
resColModel
->
colOffset
[
i
]
*
pRes
->
numOfRows
,
pResPages
[
i
]
->
data
,
pField
->
bytes
*
pRes
->
numOfRows
);
pField
->
bytes
*
pRes
->
numOfRows
);
}
}
}
else
{
}
else
{
reversedCopyFromInterpolationToDstBuf
(
p
Cmd
,
pRes
,
pResPages
,
pLocalReducer
);
reversedCopyFromInterpolationToDstBuf
(
p
QueryInfo
,
pRes
,
pResPages
,
pLocalReducer
);
}
}
}
}
pFinalDataPage
->
numOfElems
=
0
;
pFinalDataPage
->
numOfElems
=
0
;
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
tfree
(
pResPages
[
i
]);
tfree
(
pResPages
[
i
]);
}
}
tfree
(
pResPages
);
tfree
(
pResPages
);
...
@@ -961,8 +974,10 @@ static void savePreviousRow(SLocalReducer *pLocalReducer, tFilePage *tmpBuffer)
...
@@ -961,8 +974,10 @@ static void savePreviousRow(SLocalReducer *pLocalReducer, tFilePage *tmpBuffer)
static
void
doExecuteSecondaryMerge
(
SSqlCmd
*
pCmd
,
SLocalReducer
*
pLocalReducer
,
bool
needInit
)
{
static
void
doExecuteSecondaryMerge
(
SSqlCmd
*
pCmd
,
SLocalReducer
*
pLocalReducer
,
bool
needInit
)
{
// the tag columns need to be set before all functions execution
// the tag columns need to be set before all functions execution
for
(
int32_t
j
=
0
;
j
<
pCmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
j
)
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pCmd
,
j
);
for
(
int32_t
j
=
0
;
j
<
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
j
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
j
);
SQLFunctionCtx
*
pCtx
=
&
pLocalReducer
->
pCtx
[
j
];
SQLFunctionCtx
*
pCtx
=
&
pLocalReducer
->
pCtx
[
j
];
tVariantAssign
(
&
pCtx
->
param
[
0
],
&
pExpr
->
param
[
0
]);
tVariantAssign
(
&
pCtx
->
param
[
0
],
&
pExpr
->
param
[
0
]);
...
@@ -981,8 +996,8 @@ static void doExecuteSecondaryMerge(SSqlCmd* pCmd, SLocalReducer *pLocalReducer,
...
@@ -981,8 +996,8 @@ static void doExecuteSecondaryMerge(SSqlCmd* pCmd, SLocalReducer *pLocalReducer,
}
}
}
}
for
(
int32_t
j
=
0
;
j
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
j
)
{
int32_t
functionId
=
tscSqlExprGet
(
p
Cmd
,
j
)
->
functionId
;
int32_t
functionId
=
tscSqlExprGet
(
p
QueryInfo
,
j
)
->
functionId
;
if
(
functionId
==
TSDB_FUNC_TAG_DUMMY
||
functionId
==
TSDB_FUNC_TS_DUMMY
)
{
if
(
functionId
==
TSDB_FUNC_TAG_DUMMY
||
functionId
==
TSDB_FUNC_TS_DUMMY
)
{
continue
;
continue
;
}
}
...
@@ -999,11 +1014,11 @@ static void handleUnprocessedRow(SSqlCmd* pCmd, SLocalReducer *pLocalReducer, tF
...
@@ -999,11 +1014,11 @@ static void handleUnprocessedRow(SSqlCmd* pCmd, SLocalReducer *pLocalReducer, tF
}
}
}
}
static
int64_t
getNumOfResultLocal
(
S
SqlCmd
*
pCmd
,
SQLFunctionCtx
*
pCtx
)
{
static
int64_t
getNumOfResultLocal
(
S
QueryInfo
*
pQueryInfo
,
SQLFunctionCtx
*
pCtx
)
{
int64_t
maxOutput
=
0
;
int64_t
maxOutput
=
0
;
for
(
int32_t
j
=
0
;
j
<
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
.
numOfExprs
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
p
QueryInfo
->
exprsInfo
.
numOfExprs
;
++
j
)
{
int32_t
functionId
=
tscSqlExprGet
(
p
Cmd
,
j
)
->
functionId
;
int32_t
functionId
=
tscSqlExprGet
(
p
QueryInfo
,
j
)
->
functionId
;
/*
/*
* ts, tag, tagprj function can not decide the output number of current query
* ts, tag, tagprj function can not decide the output number of current query
...
@@ -1026,10 +1041,10 @@ static int64_t getNumOfResultLocal(SSqlCmd *pCmd, SQLFunctionCtx *pCtx) {
...
@@ -1026,10 +1041,10 @@ static int64_t getNumOfResultLocal(SSqlCmd *pCmd, SQLFunctionCtx *pCtx) {
* filled with the same result, which is the tags, specified in group by clause
* filled with the same result, which is the tags, specified in group by clause
*
*
*/
*/
static
void
fillMultiRowsOfTagsVal
(
S
SqlCmd
*
pCmd
,
int32_t
numOfRes
,
SLocalReducer
*
pLocalReducer
)
{
static
void
fillMultiRowsOfTagsVal
(
S
QueryInfo
*
pQueryInfo
,
int32_t
numOfRes
,
SLocalReducer
*
pLocalReducer
)
{
int32_t
maxBufSize
=
0
;
// find the max tags column length to prepare the buffer
int32_t
maxBufSize
=
0
;
// find the max tags column length to prepare the buffer
for
(
int32_t
k
=
0
;
k
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
k
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
k
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
k
);
if
(
maxBufSize
<
pExpr
->
resBytes
&&
pExpr
->
functionId
==
TSDB_FUNC_TAG
)
{
if
(
maxBufSize
<
pExpr
->
resBytes
&&
pExpr
->
functionId
==
TSDB_FUNC_TAG
)
{
maxBufSize
=
pExpr
->
resBytes
;
maxBufSize
=
pExpr
->
resBytes
;
}
}
...
@@ -1038,8 +1053,8 @@ static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReduce
...
@@ -1038,8 +1053,8 @@ static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReduce
assert
(
maxBufSize
>=
0
);
assert
(
maxBufSize
>=
0
);
char
*
buf
=
malloc
((
size_t
)
maxBufSize
);
char
*
buf
=
malloc
((
size_t
)
maxBufSize
);
for
(
int32_t
k
=
0
;
k
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
k
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
k
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
k
);
if
(
pExpr
->
functionId
!=
TSDB_FUNC_TAG
)
{
if
(
pExpr
->
functionId
!=
TSDB_FUNC_TAG
)
{
continue
;
continue
;
}
}
...
@@ -1059,9 +1074,9 @@ static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReduce
...
@@ -1059,9 +1074,9 @@ static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReduce
free
(
buf
);
free
(
buf
);
}
}
int32_t
finalizeRes
(
S
SqlCmd
*
pCmd
,
SLocalReducer
*
pLocalReducer
)
{
int32_t
finalizeRes
(
S
QueryInfo
*
pQueryInfo
,
SLocalReducer
*
pLocalReducer
)
{
for
(
int32_t
k
=
0
;
k
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
k
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
k
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
k
);
aAggs
[
pExpr
->
functionId
].
xFinalize
(
&
pLocalReducer
->
pCtx
[
k
]);
aAggs
[
pExpr
->
functionId
].
xFinalize
(
&
pLocalReducer
->
pCtx
[
k
]);
// allow to re-initialize for the next round
// allow to re-initialize for the next round
...
@@ -1070,10 +1085,10 @@ int32_t finalizeRes(SSqlCmd *pCmd, SLocalReducer *pLocalReducer) {
...
@@ -1070,10 +1085,10 @@ int32_t finalizeRes(SSqlCmd *pCmd, SLocalReducer *pLocalReducer) {
pLocalReducer
->
hasPrevRow
=
false
;
pLocalReducer
->
hasPrevRow
=
false
;
int32_t
numOfRes
=
(
int32_t
)
getNumOfResultLocal
(
p
Cmd
,
pLocalReducer
->
pCtx
);
int32_t
numOfRes
=
(
int32_t
)
getNumOfResultLocal
(
p
QueryInfo
,
pLocalReducer
->
pCtx
);
pLocalReducer
->
pResultBuf
->
numOfElems
+=
numOfRes
;
pLocalReducer
->
pResultBuf
->
numOfElems
+=
numOfRes
;
fillMultiRowsOfTagsVal
(
p
Cmd
,
numOfRes
,
pLocalReducer
);
fillMultiRowsOfTagsVal
(
p
QueryInfo
,
numOfRes
,
pLocalReducer
);
return
numOfRes
;
return
numOfRes
;
}
}
...
@@ -1084,9 +1099,9 @@ int32_t finalizeRes(SSqlCmd *pCmd, SLocalReducer *pLocalReducer) {
...
@@ -1084,9 +1099,9 @@ int32_t finalizeRes(SSqlCmd *pCmd, SLocalReducer *pLocalReducer) {
* results generated by simple aggregation function, we merge them all into one points
* results generated by simple aggregation function, we merge them all into one points
* *Exception*: column projection query, required no merge procedure
* *Exception*: column projection query, required no merge procedure
*/
*/
bool
needToMerge
(
S
SqlCmd
*
pCmd
,
SLocalReducer
*
pLocalReducer
,
tFilePage
*
tmpBuffer
)
{
bool
needToMerge
(
S
QueryInfo
*
pQueryInfo
,
SLocalReducer
*
pLocalReducer
,
tFilePage
*
tmpBuffer
)
{
int32_t
ret
=
0
;
// merge all result by default
int32_t
ret
=
0
;
// merge all result by default
int16_t
functionId
=
tscSqlExprGet
(
p
Cmd
,
0
)
->
functionId
;
int16_t
functionId
=
tscSqlExprGet
(
p
QueryInfo
,
0
)
->
functionId
;
if
(
functionId
==
TSDB_FUNC_PRJ
||
functionId
==
TSDB_FUNC_ARITHM
)
{
// column projection query
if
(
functionId
==
TSDB_FUNC_PRJ
||
functionId
==
TSDB_FUNC_ARITHM
)
{
// column projection query
ret
=
1
;
// disable merge procedure
ret
=
1
;
// disable merge procedure
...
@@ -1106,18 +1121,19 @@ bool needToMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer, tFilePage *tmpBuff
...
@@ -1106,18 +1121,19 @@ bool needToMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer, tFilePage *tmpBuff
return
(
ret
==
0
);
return
(
ret
==
0
);
}
}
static
bool
reachGroupResultLimit
(
S
SqlCmd
*
pCmd
,
SSqlRes
*
pRes
)
{
static
bool
reachGroupResultLimit
(
S
QueryInfo
*
pQueryInfo
,
SSqlRes
*
pRes
)
{
return
(
pRes
->
numOfGroups
>=
p
Cmd
->
pQueryInfo
[
0
].
slimit
.
limit
&&
pCmd
->
pQueryInfo
[
0
].
slimit
.
limit
>=
0
);
return
(
pRes
->
numOfGroups
>=
p
QueryInfo
->
slimit
.
limit
&&
pQueryInfo
->
slimit
.
limit
>=
0
);
}
}
static
bool
saveGroupResultInfo
(
SSqlObj
*
pSql
)
{
static
bool
saveGroupResultInfo
(
SSqlObj
*
pSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
pRes
->
numOfGroups
+=
1
;
pRes
->
numOfGroups
+=
1
;
// the output group is limited by the slimit clause
// the output group is limited by the slimit clause
if
(
reachGroupResultLimit
(
p
Cmd
,
pRes
))
{
if
(
reachGroupResultLimit
(
p
QueryInfo
,
pRes
))
{
return
true
;
return
true
;
}
}
...
@@ -1138,6 +1154,8 @@ static bool saveGroupResultInfo(SSqlObj *pSql) {
...
@@ -1138,6 +1154,8 @@ static bool saveGroupResultInfo(SSqlObj *pSql) {
bool
doGenerateFinalResults
(
SSqlObj
*
pSql
,
SLocalReducer
*
pLocalReducer
,
bool
noMoreCurrentGroupRes
)
{
bool
doGenerateFinalResults
(
SSqlObj
*
pSql
,
SLocalReducer
*
pLocalReducer
,
bool
noMoreCurrentGroupRes
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
tFilePage
*
pResBuf
=
pLocalReducer
->
pResultBuf
;
tFilePage
*
pResBuf
=
pLocalReducer
->
pResultBuf
;
tColModel
*
pModel
=
pLocalReducer
->
resColModel
;
tColModel
*
pModel
=
pLocalReducer
->
resColModel
;
...
@@ -1147,9 +1165,9 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no
...
@@ -1147,9 +1165,9 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no
* ignore the output of the current group since this group is skipped by user
* ignore the output of the current group since this group is skipped by user
* We set the numOfRows to be 0 and discard the possible remain results.
* We set the numOfRows to be 0 and discard the possible remain results.
*/
*/
if
(
p
Cmd
->
pQueryInfo
[
0
].
slimit
.
offset
>
0
)
{
if
(
p
QueryInfo
->
slimit
.
offset
>
0
)
{
pRes
->
numOfRows
=
0
;
pRes
->
numOfRows
=
0
;
p
Cmd
->
pQueryInfo
[
0
].
slimit
.
offset
-=
1
;
p
QueryInfo
->
slimit
.
offset
-=
1
;
pLocalReducer
->
discard
=
!
noMoreCurrentGroupRes
;
pLocalReducer
->
discard
=
!
noMoreCurrentGroupRes
;
return
false
;
return
false
;
}
}
...
@@ -1163,24 +1181,24 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no
...
@@ -1163,24 +1181,24 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no
#endif
#endif
SInterpolationInfo
*
pInterpoInfo
=
&
pLocalReducer
->
interpolationInfo
;
SInterpolationInfo
*
pInterpoInfo
=
&
pLocalReducer
->
interpolationInfo
;
int32_t
startIndex
=
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
-
pCmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
;
int32_t
startIndex
=
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
-
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
;
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
groupbyExpr
.
numOfGroupCols
;
++
i
)
{
memcpy
(
pInterpoInfo
->
pTags
[
i
],
memcpy
(
pInterpoInfo
->
pTags
[
i
],
pLocalReducer
->
pBufForInterpo
+
pModel
->
colOffset
[
startIndex
+
i
]
*
pResBuf
->
numOfElems
,
pLocalReducer
->
pBufForInterpo
+
pModel
->
colOffset
[
startIndex
+
i
]
*
pResBuf
->
numOfElems
,
pModel
->
pFields
[
startIndex
+
i
].
bytes
);
pModel
->
pFields
[
startIndex
+
i
].
bytes
);
}
}
taosInterpoSetStartInfo
(
&
pLocalReducer
->
interpolationInfo
,
pResBuf
->
numOfElems
,
p
Cmd
->
pQueryInfo
[
0
].
interpoType
);
taosInterpoSetStartInfo
(
&
pLocalReducer
->
interpolationInfo
,
pResBuf
->
numOfElems
,
p
QueryInfo
->
interpoType
);
doInterpolateResult
(
pSql
,
pLocalReducer
,
noMoreCurrentGroupRes
);
doInterpolateResult
(
pSql
,
pLocalReducer
,
noMoreCurrentGroupRes
);
return
true
;
return
true
;
}
}
void
resetOutputBuf
(
S
SqlCmd
*
pCmd
,
SLocalReducer
*
pLocalReducer
)
{
// reset output buffer to the beginning
void
resetOutputBuf
(
S
QueryInfo
*
pQueryInfo
,
SLocalReducer
*
pLocalReducer
)
{
// reset output buffer to the beginning
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
pLocalReducer
->
pCtx
[
i
].
aOutputBuf
=
pLocalReducer
->
pCtx
[
i
].
aOutputBuf
=
pLocalReducer
->
pResultBuf
->
data
+
tscFieldInfoGetOffset
(
p
Cmd
,
i
)
*
pLocalReducer
->
resColModel
->
maxCapacity
;
pLocalReducer
->
pResultBuf
->
data
+
tscFieldInfoGetOffset
(
p
QueryInfo
,
i
)
*
pLocalReducer
->
resColModel
->
maxCapacity
;
}
}
memset
(
pLocalReducer
->
pResultBuf
,
0
,
pLocalReducer
->
nResultBufSize
+
sizeof
(
tFilePage
));
memset
(
pLocalReducer
->
pResultBuf
,
0
,
pLocalReducer
->
nResultBufSize
+
sizeof
(
tFilePage
));
...
@@ -1190,17 +1208,19 @@ static void resetEnvForNewResultset(SSqlRes *pRes, SSqlCmd *pCmd, SLocalReducer
...
@@ -1190,17 +1208,19 @@ static void resetEnvForNewResultset(SSqlRes *pRes, SSqlCmd *pCmd, SLocalReducer
// In handling data in other groups, we need to reset the interpolation information for a new group data
// In handling data in other groups, we need to reset the interpolation information for a new group data
pRes
->
numOfRows
=
0
;
pRes
->
numOfRows
=
0
;
pRes
->
numOfTotal
=
0
;
pRes
->
numOfTotal
=
0
;
pCmd
->
pQueryInfo
->
limit
.
offset
=
pLocalReducer
->
offset
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
pQueryInfo
->
limit
.
offset
=
pLocalReducer
->
offset
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
int16_t
precision
=
pMeterMetaInfo
->
pMeterMeta
->
precision
;
int16_t
precision
=
pMeterMetaInfo
->
pMeterMeta
->
precision
;
// for group result interpolation, do not return if not data is generated
// for group result interpolation, do not return if not data is generated
if
(
p
Cmd
->
pQueryInfo
[
0
].
interpoType
!=
TSDB_INTERPO_NONE
)
{
if
(
p
QueryInfo
->
interpoType
!=
TSDB_INTERPO_NONE
)
{
int64_t
stime
=
(
p
Cmd
->
pQueryInfo
[
0
].
stime
<
pCmd
->
pQueryInfo
[
0
].
etime
)
?
pCmd
->
pQueryInfo
[
0
].
stime
:
pCmd
->
pQueryInfo
[
0
].
etime
;
int64_t
stime
=
(
p
QueryInfo
->
stime
<
pQueryInfo
->
etime
)
?
pQueryInfo
->
stime
:
pQueryInfo
->
etime
;
int64_t
newTime
=
taosGetIntervalStartTimestamp
(
stime
,
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
,
pCmd
->
pQueryInfo
[
0
].
intervalTimeUnit
,
precision
);
int64_t
newTime
=
taosGetIntervalStartTimestamp
(
stime
,
p
QueryInfo
->
nAggTimeInterval
,
pQueryInfo
->
intervalTimeUnit
,
precision
);
taosInitInterpoInfo
(
&
pLocalReducer
->
interpolationInfo
,
p
Cmd
->
order
.
order
,
newTime
,
pCmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
,
taosInitInterpoInfo
(
&
pLocalReducer
->
interpolationInfo
,
p
QueryInfo
->
order
.
order
,
newTime
,
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
,
pLocalReducer
->
rowSize
);
pLocalReducer
->
rowSize
);
}
}
}
}
...
@@ -1213,22 +1233,23 @@ static bool doInterpolationForCurrentGroup(SSqlObj *pSql) {
...
@@ -1213,22 +1233,23 @@ static bool doInterpolationForCurrentGroup(SSqlObj *pSql) {
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SLocalReducer
*
pLocalReducer
=
pRes
->
pLocalReducer
;
SLocalReducer
*
pLocalReducer
=
pRes
->
pLocalReducer
;
SInterpolationInfo
*
pInterpoInfo
=
&
pLocalReducer
->
interpolationInfo
;
SInterpolationInfo
*
pInterpoInfo
=
&
pLocalReducer
->
interpolationInfo
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
0
);
int8_t
p
=
pMeterMetaInfo
->
pMeterMeta
->
precision
;
int8_t
p
=
pMeterMetaInfo
->
pMeterMeta
->
precision
;
if
(
taosHasRemainsDataForInterpolation
(
pInterpoInfo
))
{
if
(
taosHasRemainsDataForInterpolation
(
pInterpoInfo
))
{
assert
(
p
Cmd
->
pQueryInfo
[
0
].
interpoType
!=
TSDB_INTERPO_NONE
);
assert
(
p
QueryInfo
->
interpoType
!=
TSDB_INTERPO_NONE
);
tFilePage
*
pFinalDataBuf
=
pLocalReducer
->
pResultBuf
;
tFilePage
*
pFinalDataBuf
=
pLocalReducer
->
pResultBuf
;
int64_t
etime
=
*
(
int64_t
*
)(
pFinalDataBuf
->
data
+
TSDB_KEYSIZE
*
(
pInterpoInfo
->
numOfRawDataInRows
-
1
));
int64_t
etime
=
*
(
int64_t
*
)(
pFinalDataBuf
->
data
+
TSDB_KEYSIZE
*
(
pInterpoInfo
->
numOfRawDataInRows
-
1
));
int32_t
remain
=
taosNumOfRemainPoints
(
pInterpoInfo
);
int32_t
remain
=
taosNumOfRemainPoints
(
pInterpoInfo
);
TSKEY
ekey
=
taosGetRevisedEndKey
(
etime
,
p
Cmd
->
order
.
order
,
pCmd
->
pQueryInfo
[
0
].
nAggTimeInterval
,
pCmd
->
pQueryInfo
[
0
].
intervalTimeUnit
,
p
);
TSKEY
ekey
=
taosGetRevisedEndKey
(
etime
,
p
QueryInfo
->
order
.
order
,
pQueryInfo
->
nAggTimeInterval
,
pQueryInfo
->
intervalTimeUnit
,
p
);
int32_t
rows
=
taosGetNumOfResultWithInterpo
(
pInterpoInfo
,
(
TSKEY
*
)
pLocalReducer
->
pBufForInterpo
,
remain
,
int32_t
rows
=
taosGetNumOfResultWithInterpo
(
pInterpoInfo
,
(
TSKEY
*
)
pLocalReducer
->
pBufForInterpo
,
remain
,
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
,
ekey
,
pLocalReducer
->
resColModel
->
maxCapacity
);
p
QueryInfo
->
nAggTimeInterval
,
ekey
,
pLocalReducer
->
resColModel
->
maxCapacity
);
if
(
rows
>
0
)
{
// do interpo
if
(
rows
>
0
)
{
// do interpo
doInterpolateResult
(
pSql
,
pLocalReducer
,
false
);
doInterpolateResult
(
pSql
,
pLocalReducer
,
false
);
}
}
...
@@ -1248,17 +1269,18 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
...
@@ -1248,17 +1269,18 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
bool
prevGroupCompleted
=
(
!
pLocalReducer
->
discard
)
&&
pLocalReducer
->
hasUnprocessedRow
;
bool
prevGroupCompleted
=
(
!
pLocalReducer
->
discard
)
&&
pLocalReducer
->
hasUnprocessedRow
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
int8_t
precision
=
pMeterMetaInfo
->
pMeterMeta
->
precision
;
int8_t
precision
=
pMeterMetaInfo
->
pMeterMeta
->
precision
;
if
((
isAllSourcesCompleted
(
pLocalReducer
)
&&
!
pLocalReducer
->
hasPrevRow
)
||
pLocalReducer
->
pLocalDataSrc
[
0
]
==
NULL
||
if
((
isAllSourcesCompleted
(
pLocalReducer
)
&&
!
pLocalReducer
->
hasPrevRow
)
||
pLocalReducer
->
pLocalDataSrc
[
0
]
==
NULL
||
prevGroupCompleted
)
{
prevGroupCompleted
)
{
// if interpoType == TSDB_INTERPO_NONE, return directly
// if interpoType == TSDB_INTERPO_NONE, return directly
if
(
p
Cmd
->
pQueryInfo
[
0
].
interpoType
!=
TSDB_INTERPO_NONE
)
{
if
(
p
QueryInfo
->
interpoType
!=
TSDB_INTERPO_NONE
)
{
int64_t
etime
=
(
p
Cmd
->
pQueryInfo
[
0
].
stime
<
pCmd
->
pQueryInfo
[
0
].
etime
)
?
pCmd
->
pQueryInfo
[
0
].
etime
:
pCmd
->
pQueryInfo
[
0
].
stime
;
int64_t
etime
=
(
p
QueryInfo
->
stime
<
pQueryInfo
->
etime
)
?
pQueryInfo
->
etime
:
pQueryInfo
->
stime
;
etime
=
taosGetRevisedEndKey
(
etime
,
p
Cmd
->
order
.
order
,
pCmd
->
pQueryInfo
[
0
].
nAggTimeInterval
,
pCmd
->
pQueryInfo
[
0
].
intervalTimeUnit
,
precision
);
etime
=
taosGetRevisedEndKey
(
etime
,
p
QueryInfo
->
order
.
order
,
pQueryInfo
->
nAggTimeInterval
,
pQueryInfo
->
intervalTimeUnit
,
precision
);
int32_t
rows
=
taosGetNumOfResultWithInterpo
(
pInterpoInfo
,
NULL
,
0
,
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
,
etime
,
int32_t
rows
=
taosGetNumOfResultWithInterpo
(
pInterpoInfo
,
NULL
,
0
,
p
QueryInfo
->
nAggTimeInterval
,
etime
,
pLocalReducer
->
resColModel
->
maxCapacity
);
pLocalReducer
->
resColModel
->
maxCapacity
);
if
(
rows
>
0
)
{
// do interpo
if
(
rows
>
0
)
{
// do interpo
doInterpolateResult
(
pSql
,
pLocalReducer
,
true
);
doInterpolateResult
(
pSql
,
pLocalReducer
,
true
);
...
@@ -1289,10 +1311,12 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
...
@@ -1289,10 +1311,12 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
static
void
doMergeWithPrevRows
(
SSqlObj
*
pSql
,
int32_t
numOfRes
)
{
static
void
doMergeWithPrevRows
(
SSqlObj
*
pSql
,
int32_t
numOfRes
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SLocalReducer
*
pLocalReducer
=
pRes
->
pLocalReducer
;
SLocalReducer
*
pLocalReducer
=
pRes
->
pLocalReducer
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
for
(
int32_t
k
=
0
;
k
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
k
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
k
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
k
);
SQLFunctionCtx
*
pCtx
=
&
pLocalReducer
->
pCtx
[
k
];
SQLFunctionCtx
*
pCtx
=
&
pLocalReducer
->
pCtx
[
k
];
pCtx
->
aOutputBuf
+=
pCtx
->
outputBytes
*
numOfRes
;
pCtx
->
aOutputBuf
+=
pCtx
->
outputBytes
*
numOfRes
;
...
@@ -1325,6 +1349,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
...
@@ -1325,6 +1349,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
pRes
->
numOfRows
=
0
;
pRes
->
numOfRows
=
0
;
SLocalReducer
*
pLocalReducer
=
pRes
->
pLocalReducer
;
SLocalReducer
*
pLocalReducer
=
pRes
->
pLocalReducer
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
// set the data merge in progress
// set the data merge in progress
int32_t
prevStatus
=
int32_t
prevStatus
=
...
@@ -1372,7 +1397,9 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
...
@@ -1372,7 +1397,9 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
#if defined(_DEBUG_VIEW)
#if defined(_DEBUG_VIEW)
printf
(
"chosen row:
\t
"
);
printf
(
"chosen row:
\t
"
);
SSrcColumnInfo
colInfo
[
256
]
=
{
0
};
SSrcColumnInfo
colInfo
[
256
]
=
{
0
};
tscGetSrcColumnInfo
(
colInfo
,
pCmd
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
tscGetSrcColumnInfo
(
colInfo
,
pQueryInfo
);
tColModelDisplayEx
(
pModel
,
tmpBuffer
->
data
,
tmpBuffer
->
numOfElems
,
pModel
->
maxCapacity
,
colInfo
);
tColModelDisplayEx
(
pModel
,
tmpBuffer
->
data
,
tmpBuffer
->
numOfElems
,
pModel
->
maxCapacity
,
colInfo
);
#endif
#endif
...
@@ -1408,7 +1435,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
...
@@ -1408,7 +1435,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
}
}
if
(
pLocalReducer
->
hasPrevRow
)
{
if
(
pLocalReducer
->
hasPrevRow
)
{
if
(
needToMerge
(
p
Cmd
,
pLocalReducer
,
tmpBuffer
))
{
if
(
needToMerge
(
p
QueryInfo
,
pLocalReducer
,
tmpBuffer
))
{
// belong to the group of the previous row, continue process it
// belong to the group of the previous row, continue process it
doExecuteSecondaryMerge
(
pCmd
,
pLocalReducer
,
false
);
doExecuteSecondaryMerge
(
pCmd
,
pLocalReducer
,
false
);
...
@@ -1419,7 +1446,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
...
@@ -1419,7 +1446,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
* current row does not belong to the group of previous row.
* current row does not belong to the group of previous row.
* so the processing of previous group is completed.
* so the processing of previous group is completed.
*/
*/
int32_t
numOfRes
=
finalizeRes
(
p
Cmd
,
pLocalReducer
);
int32_t
numOfRes
=
finalizeRes
(
p
QueryInfo
,
pLocalReducer
);
bool
sameGroup
=
isSameGroup
(
pCmd
,
pLocalReducer
,
pLocalReducer
->
prevRowOfInput
,
tmpBuffer
);
bool
sameGroup
=
isSameGroup
(
pCmd
,
pLocalReducer
,
pLocalReducer
->
prevRowOfInput
,
tmpBuffer
);
tFilePage
*
pResBuf
=
pLocalReducer
->
pResultBuf
;
tFilePage
*
pResBuf
=
pLocalReducer
->
pResultBuf
;
...
@@ -1442,7 +1469,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
...
@@ -1442,7 +1469,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
pLocalReducer
->
hasUnprocessedRow
=
true
;
pLocalReducer
->
hasUnprocessedRow
=
true
;
}
}
resetOutputBuf
(
p
Cmd
,
pLocalReducer
);
resetOutputBuf
(
p
QueryInfo
,
pLocalReducer
);
pOneDataSrc
->
rowIdx
+=
1
;
pOneDataSrc
->
rowIdx
+=
1
;
// here we do not check the return value
// here we do not check the return value
...
@@ -1496,7 +1523,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
...
@@ -1496,7 +1523,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
}
}
if
(
pLocalReducer
->
hasPrevRow
)
{
if
(
pLocalReducer
->
hasPrevRow
)
{
finalizeRes
(
p
Cmd
,
pLocalReducer
);
finalizeRes
(
p
QueryInfo
,
pLocalReducer
);
}
}
if
(
pLocalReducer
->
pResultBuf
->
numOfElems
)
{
if
(
pLocalReducer
->
pResultBuf
->
numOfElems
)
{
...
...
src/client/src/tscServer.c
浏览文件 @
e15aa9b1
...
@@ -138,6 +138,8 @@ void tscProcessActivityTimer(void *handle, void *tmrId) {
...
@@ -138,6 +138,8 @@ void tscProcessActivityTimer(void *handle, void *tmrId) {
pSql
->
pTscObj
=
pObj
;
pSql
->
pTscObj
=
pObj
;
pSql
->
signature
=
pSql
;
pSql
->
signature
=
pSql
;
pObj
->
pHb
=
pSql
;
pObj
->
pHb
=
pSql
;
tscAddSubqueryInfo
(
&
pObj
->
pHb
->
cmd
);
tscTrace
(
"%p pHb is allocated, pObj:%p"
,
pObj
->
pHb
,
pObj
);
tscTrace
(
"%p pHb is allocated, pObj:%p"
,
pObj
->
pHb
,
pObj
);
}
}
...
@@ -221,9 +223,9 @@ void tscGetConnToVnode(SSqlObj *pSql, uint8_t *pCode) {
...
@@ -221,9 +223,9 @@ void tscGetConnToVnode(SSqlObj *pSql, uint8_t *pCode) {
pSql
->
thandle
=
NULL
;
pSql
->
thandle
=
NULL
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
if
(
UTIL_METER_IS_
METRIC
(
pMeterMetaInfo
))
{
// multiple vnode query
if
(
UTIL_METER_IS_
SUPERTABLE
(
pMeterMetaInfo
))
{
// multiple vnode query
SVnodeSidList
*
vnodeList
=
tscGetVnodeSidList
(
pMeterMetaInfo
->
pMetricMeta
,
pMeterMetaInfo
->
vnodeIndex
);
SVnodeSidList
*
vnodeList
=
tscGetVnodeSidList
(
pMeterMetaInfo
->
pMetricMeta
,
pMeterMetaInfo
->
vnodeIndex
);
if
(
vnodeList
!=
NULL
)
{
if
(
vnodeList
!=
NULL
)
{
pVPeersDesc
=
vnodeList
->
vpeerDesc
;
pVPeersDesc
=
vnodeList
->
vpeerDesc
;
...
@@ -421,7 +423,7 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
...
@@ -421,7 +423,7 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
return
ahandle
;
return
ahandle
;
}
}
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
if
(
msg
==
NULL
)
{
if
(
msg
==
NULL
)
{
tscTrace
(
"%p no response from ip:0x%x"
,
pSql
,
pSql
->
ip
);
tscTrace
(
"%p no response from ip:0x%x"
,
pSql
,
pSql
->
ip
);
...
@@ -639,6 +641,7 @@ static int tscLaunchMetricSubQueries(SSqlObj *pSql);
...
@@ -639,6 +641,7 @@ static int tscLaunchMetricSubQueries(SSqlObj *pSql);
// todo merge with callback
// todo merge with callback
int32_t
tscLaunchJoinSubquery
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
SJoinSubquerySupporter
*
pSupporter
)
{
int32_t
tscLaunchJoinSubquery
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
SJoinSubquerySupporter
*
pSupporter
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
pSql
->
res
.
qhandle
=
0x1
;
pSql
->
res
.
qhandle
=
0x1
;
pSql
->
res
.
numOfRows
=
0
;
pSql
->
res
.
numOfRows
=
0
;
...
@@ -658,36 +661,38 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
...
@@ -658,36 +661,38 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
pSql
->
pSubs
[
pSql
->
numOfSubs
++
]
=
pNew
;
pSql
->
pSubs
[
pSql
->
numOfSubs
++
]
=
pNew
;
assert
(
pSql
->
numOfSubs
<=
pSupporter
->
pState
->
numOfTotal
);
assert
(
pSql
->
numOfSubs
<=
pSupporter
->
pState
->
numOfTotal
);
if
(
QUERY_IS_JOIN_QUERY
(
p
Cmd
->
type
))
{
if
(
QUERY_IS_JOIN_QUERY
(
p
QueryInfo
->
type
))
{
addGroupInfoForSubquery
(
pSql
,
pNew
,
tableIndex
);
addGroupInfoForSubquery
(
pSql
,
pNew
,
0
,
tableIndex
);
// refactor as one method
// refactor as one method
tscColumnBaseInfoUpdateTableIndex
(
&
pNew
->
cmd
.
pQueryInfo
[
0
].
colList
,
0
);
SQueryInfo
*
pNewQueryInfo
=
tscGetQueryInfoDetail
(
&
pNew
->
cmd
,
0
);
tscColumnBaseInfoCopy
(
&
pSupporter
->
colList
,
&
pNew
->
cmd
.
pQueryInfo
[
0
].
colList
,
0
);
tscColumnBaseInfoUpdateTableIndex
(
&
pNewQueryInfo
->
colList
,
0
);
tscColumnBaseInfoCopy
(
&
pSupporter
->
colList
,
&
pNewQueryInfo
->
colList
,
0
);
tscSqlExprCopy
(
&
pSupporter
->
exprsInfo
,
&
pNew
->
cmd
.
pQueryInfo
[
0
].
exprsInfo
,
pSupporter
->
uid
);
tscSqlExprCopy
(
&
pSupporter
->
exprsInfo
,
&
pNew
QueryInfo
->
exprsInfo
,
pSupporter
->
uid
);
tscFieldInfoCopyAll
(
&
pNew
->
cmd
.
pQueryInfo
[
0
].
fieldsInfo
,
&
pSupporter
->
fieldsInfo
);
tscFieldInfoCopyAll
(
&
pNew
QueryInfo
->
fieldsInfo
,
&
pSupporter
->
fieldsInfo
);
tscTagCondCopy
(
&
pSupporter
->
tagCond
,
&
pNew
->
cmd
.
pQueryInfo
[
0
].
tagCond
);
tscTagCondCopy
(
&
pSupporter
->
tagCond
,
&
pNew
QueryInfo
->
tagCond
);
pSupporter
->
groupbyExpr
=
pNew
->
cmd
.
pQueryInfo
[
0
].
groupbyExpr
;
pSupporter
->
groupbyExpr
=
pNew
QueryInfo
->
groupbyExpr
;
pNew
->
cmd
.
numOfCols
=
0
;
pNew
->
cmd
.
numOfCols
=
0
;
pNew
->
cmd
.
pQueryInfo
[
0
].
nAggTimeInterval
=
0
;
pNew
QueryInfo
->
nAggTimeInterval
=
0
;
memset
(
&
pNew
->
cmd
.
pQueryInfo
[
0
].
limit
,
0
,
sizeof
(
SLimitVal
));
memset
(
&
pNew
QueryInfo
->
limit
,
0
,
sizeof
(
SLimitVal
));
memset
(
&
pNew
->
cmd
.
pQueryInfo
[
0
].
groupbyExpr
,
0
,
sizeof
(
SSqlGroupbyExpr
));
memset
(
&
pNew
QueryInfo
->
groupbyExpr
,
0
,
sizeof
(
SSqlGroupbyExpr
));
// set the ts,tags that involved in join, as the output column of intermediate result
// set the ts,tags that involved in join, as the output column of intermediate result
tscFreeSqlCmdData
(
&
pNew
->
cmd
);
pCmd
->
pDataBlocks
=
tscDestroyBlockArrayList
(
pNew
->
cmd
.
pDataBlocks
);
tscFreeSubqueryInfo
(
&
pNew
->
cmd
);
SSchema
colSchema
=
{.
type
=
TSDB_DATA_TYPE_BINARY
,
.
bytes
=
1
};
SSchema
colSchema
=
{.
type
=
TSDB_DATA_TYPE_BINARY
,
.
bytes
=
1
};
SColumnIndex
index
=
{
0
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
};
SColumnIndex
index
=
{
0
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
};
tscAddSpecialColumnForSelect
(
&
pNew
->
cmd
,
0
,
TSDB_FUNC_TS_COMP
,
&
index
,
&
colSchema
,
TSDB_COL_NORMAL
);
tscAddSpecialColumnForSelect
(
pNewQueryInfo
,
0
,
TSDB_FUNC_TS_COMP
,
&
index
,
&
colSchema
,
TSDB_COL_NORMAL
);
// set the tags value for ts_comp function
// set the tags value for ts_comp function
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
&
pNew
->
cmd
,
0
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pNewQueryInfo
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pNew
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pNewQueryInfo
,
0
);
int16_t
tagColIndex
=
tscGetJoinTagColIndexByUid
(
&
pSupporter
->
tagCond
,
pMeterMetaInfo
->
pMeterMeta
->
uid
);
int16_t
tagColIndex
=
tscGetJoinTagColIndexByUid
(
&
pSupporter
->
tagCond
,
pMeterMetaInfo
->
pMeterMeta
->
uid
);
pExpr
->
param
->
i64Key
=
tagColIndex
;
pExpr
->
param
->
i64Key
=
tagColIndex
;
...
@@ -697,16 +702,17 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
...
@@ -697,16 +702,17 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
for
(
int32_t
i
=
0
;
i
<
pSupporter
->
colList
.
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pSupporter
->
colList
.
numOfCols
;
++
i
)
{
SColumnBase
*
pColBase
=
&
pSupporter
->
colList
.
pColList
[
i
];
SColumnBase
*
pColBase
=
&
pSupporter
->
colList
.
pColList
[
i
];
if
(
pColBase
->
numOfFilters
>
0
)
{
// copy to the pNew->cmd.colList if it is filtered.
if
(
pColBase
->
numOfFilters
>
0
)
{
// copy to the pNew->cmd.colList if it is filtered.
tscColumnBaseCopy
(
&
pNew
->
cmd
.
pQueryInfo
[
0
].
colList
.
pColList
[
pNew
->
cmd
.
pQueryInfo
[
0
].
colList
.
numOfCols
],
pColBase
);
tscColumnBaseCopy
(
&
pNew
QueryInfo
->
colList
.
pColList
[
pNewQueryInfo
->
colList
.
numOfCols
],
pColBase
);
pNew
->
cmd
.
pQueryInfo
[
0
].
colList
.
numOfCols
++
;
pNew
QueryInfo
->
colList
.
numOfCols
++
;
}
}
}
}
}
else
{
}
else
{
pNew
->
cmd
.
type
|=
TSDB_QUERY_TYPE_SUBQUERY
;
SQueryInfo
*
pNewQueryInfo
=
tscGetQueryInfoDetail
(
&
pNew
->
cmd
,
0
);
pNewQueryInfo
->
type
|=
TSDB_QUERY_TYPE_SUBQUERY
;
}
}
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
tscPrintSelectClause
(
&
pNew
->
cmd
);
tscPrintSelectClause
(
&
pNew
->
cmd
,
0
);
#endif
#endif
return
tscProcessSql
(
pNew
);
return
tscProcessSql
(
pNew
);
...
@@ -752,13 +758,20 @@ int tscProcessSql(SSqlObj *pSql) {
...
@@ -752,13 +758,20 @@ int tscProcessSql(SSqlObj *pSql) {
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
NULL
;
int16_t
type
=
0
;
if
(
pQueryInfo
!=
NULL
)
{
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
if
(
pMeterMetaInfo
!=
NULL
)
{
if
(
pMeterMetaInfo
!=
NULL
)
{
name
=
pMeterMetaInfo
->
name
;
name
=
pMeterMetaInfo
->
name
;
}
}
tscTrace
(
"%p SQL cmd:%d will be processed, name:%s, type:%d"
,
pSql
,
pSql
->
cmd
.
command
,
name
,
pSql
->
cmd
.
type
);
type
=
pQueryInfo
->
type
;
}
tscTrace
(
"%p SQL cmd:%d will be processed, name:%s, type:%d"
,
pSql
,
pCmd
->
command
,
name
,
type
);
pSql
->
retry
=
0
;
pSql
->
retry
=
0
;
if
(
pSql
->
cmd
.
command
<
TSDB_SQL_MGMT
)
{
if
(
pSql
->
cmd
.
command
<
TSDB_SQL_MGMT
)
{
#ifdef CLUSTER
#ifdef CLUSTER
...
@@ -767,8 +780,7 @@ int tscProcessSql(SSqlObj *pSql) {
...
@@ -767,8 +780,7 @@ int tscProcessSql(SSqlObj *pSql) {
pSql
->
maxRetry
=
2
;
pSql
->
maxRetry
=
2
;
#endif
#endif
// the pMeterMetaInfo cannot be NULL
if
(
pMeterMetaInfo
==
NULL
)
{
// the pMeterMetaInfo cannot be NULL
if
(
pMeterMetaInfo
==
NULL
)
{
pSql
->
res
.
code
=
TSDB_CODE_OTHERS
;
pSql
->
res
.
code
=
TSDB_CODE_OTHERS
;
return
pSql
->
res
.
code
;
return
pSql
->
res
.
code
;
}
}
...
@@ -776,7 +788,7 @@ int tscProcessSql(SSqlObj *pSql) {
...
@@ -776,7 +788,7 @@ int tscProcessSql(SSqlObj *pSql) {
if
(
UTIL_METER_IS_NOMRAL_METER
(
pMeterMetaInfo
))
{
if
(
UTIL_METER_IS_NOMRAL_METER
(
pMeterMetaInfo
))
{
pSql
->
index
=
pMeterMetaInfo
->
pMeterMeta
->
index
;
pSql
->
index
=
pMeterMetaInfo
->
pMeterMeta
->
index
;
}
else
{
// it must be the parent SSqlObj for super table query
}
else
{
// it must be the parent SSqlObj for super table query
if
((
p
Sql
->
cmd
.
type
&
TSDB_QUERY_TYPE_SUBQUERY
)
!=
0
)
{
if
((
p
QueryInfo
->
type
&
TSDB_QUERY_TYPE_SUBQUERY
)
!=
0
)
{
int32_t
idx
=
pMeterMetaInfo
->
vnodeIndex
;
int32_t
idx
=
pMeterMetaInfo
->
vnodeIndex
;
SVnodeSidList
*
pSidList
=
tscGetVnodeSidList
(
pMeterMetaInfo
->
pMetricMeta
,
idx
);
SVnodeSidList
*
pSidList
=
tscGetVnodeSidList
(
pMeterMetaInfo
->
pMetricMeta
,
idx
);
...
@@ -790,17 +802,18 @@ int tscProcessSql(SSqlObj *pSql) {
...
@@ -790,17 +802,18 @@ int tscProcessSql(SSqlObj *pSql) {
}
}
// todo handle async situation
// todo handle async situation
if
(
QUERY_IS_JOIN_QUERY
(
pSql
->
cmd
.
type
))
{
if
(
QUERY_IS_JOIN_QUERY
(
type
))
{
if
((
p
Sql
->
cmd
.
type
&
TSDB_QUERY_TYPE_SUBQUERY
)
==
0
)
{
if
((
p
QueryInfo
->
type
&
TSDB_QUERY_TYPE_SUBQUERY
)
==
0
)
{
SSubqueryState
*
pState
=
calloc
(
1
,
sizeof
(
SSubqueryState
));
SSubqueryState
*
pState
=
calloc
(
1
,
sizeof
(
SSubqueryState
));
pState
->
numOfTotal
=
pSql
->
cmd
.
pQueryInfo
[
0
].
numOfTables
;
for
(
int32_t
i
=
0
;
i
<
pSql
->
cmd
.
pQueryInfo
[
0
].
numOfTables
;
++
i
)
{
pState
->
numOfTotal
=
pQueryInfo
->
numOfTables
;
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
SJoinSubquerySupporter
*
pSupporter
=
tscCreateJoinSupporter
(
pSql
,
pState
,
i
);
SJoinSubquerySupporter
*
pSupporter
=
tscCreateJoinSupporter
(
pSql
,
pState
,
i
);
if
(
pSupporter
==
NULL
)
{
// failed to create support struct, abort current query
if
(
pSupporter
==
NULL
)
{
// failed to create support struct, abort current query
tscError
(
"%p tableIndex:%d, failed to allocate join support object, abort further query"
,
pSql
,
i
);
tscError
(
"%p tableIndex:%d, failed to allocate join support object, abort further query"
,
pSql
,
i
);
pState
->
numOfCompleted
=
p
Sql
->
cmd
.
pQueryInfo
[
0
].
numOfTables
-
i
-
1
;
pState
->
numOfCompleted
=
p
QueryInfo
->
numOfTables
-
i
-
1
;
pSql
->
res
.
code
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
pSql
->
res
.
code
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
return
pSql
->
res
.
code
;
return
pSql
->
res
.
code
;
...
@@ -829,7 +842,7 @@ int tscProcessSql(SSqlObj *pSql) {
...
@@ -829,7 +842,7 @@ int tscProcessSql(SSqlObj *pSql) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
else
{
}
else
{
// for first stage sub query, iterate all vnodes to get all timestamp
// for first stage sub query, iterate all vnodes to get all timestamp
if
((
p
Sql
->
cmd
.
type
&
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)
!=
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)
{
if
((
p
QueryInfo
->
type
&
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)
!=
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)
{
return
doProcessSql
(
pSql
);
return
doProcessSql
(
pSql
);
}
}
}
}
...
@@ -891,11 +904,12 @@ static void doCleanupSubqueries(SSqlObj *pSql, int32_t vnodeIndex, int32_t numOf
...
@@ -891,11 +904,12 @@ static void doCleanupSubqueries(SSqlObj *pSql, int32_t vnodeIndex, int32_t numOf
int
tscLaunchMetricSubQueries
(
SSqlObj
*
pSql
)
{
int
tscLaunchMetricSubQueries
(
SSqlObj
*
pSql
)
{
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
// pRes->code check only serves in launching metric sub-queries
// pRes->code check only serves in launching metric sub-queries
if
(
pRes
->
code
==
TSDB_CODE_QUERY_CANCELLED
)
{
if
(
pRes
->
code
==
TSDB_CODE_QUERY_CANCELLED
)
{
p
Sql
->
cmd
.
command
=
TSDB_SQL_RETRIEVE_METRIC
;
// enable the abort of kill metric function.
p
Cmd
->
command
=
TSDB_SQL_RETRIEVE_METRIC
;
// enable the abort of kill metric function.
return
p
Sql
->
res
.
code
;
return
p
Res
->
code
;
}
}
tExtMemBuffer
**
pMemoryBuf
=
NULL
;
tExtMemBuffer
**
pMemoryBuf
=
NULL
;
...
@@ -905,7 +919,9 @@ int tscLaunchMetricSubQueries(SSqlObj *pSql) {
...
@@ -905,7 +919,9 @@ int tscLaunchMetricSubQueries(SSqlObj *pSql) {
pRes
->
qhandle
=
1
;
// hack the qhandle check
pRes
->
qhandle
=
1
;
// hack the qhandle check
const
uint32_t
nBufferSize
=
(
1
<<
16
);
// 64KB
const
uint32_t
nBufferSize
=
(
1
<<
16
);
// 64KB
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
int32_t
numOfVnodes
=
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
;
int32_t
numOfVnodes
=
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
;
assert
(
numOfVnodes
>
0
);
assert
(
numOfVnodes
>
0
);
...
@@ -964,15 +980,17 @@ int tscLaunchMetricSubQueries(SSqlObj *pSql) {
...
@@ -964,15 +980,17 @@ int tscLaunchMetricSubQueries(SSqlObj *pSql) {
doCleanupSubqueries
(
pSql
,
i
,
numOfVnodes
,
trs
,
pDesc
,
pModel
,
pMemoryBuf
,
pState
);
doCleanupSubqueries
(
pSql
,
i
,
numOfVnodes
,
trs
,
pDesc
,
pModel
,
pMemoryBuf
,
pState
);
if
(
i
==
0
)
{
if
(
i
==
0
)
{
return
p
Sql
->
res
.
code
;
return
p
Res
->
code
;
}
}
break
;
break
;
}
}
// todo handle multi-vnode situation
// todo handle multi-vnode situation
if
(
pSql
->
cmd
.
pQueryInfo
[
0
].
tsBuf
)
{
if
(
pQueryInfo
->
tsBuf
)
{
pNew
->
cmd
.
pQueryInfo
[
0
].
tsBuf
=
tsBufClone
(
pSql
->
cmd
.
pQueryInfo
[
0
].
tsBuf
);
SQueryInfo
*
pNewQueryInfo
=
tscGetQueryInfoDetail
(
&
pNew
->
cmd
,
0
);
pNewQueryInfo
->
tsBuf
=
tsBufClone
(
pQueryInfo
->
tsBuf
);
}
}
tscTrace
(
"%p sub:%p launch subquery.orderOfSub:%d"
,
pSql
,
pNew
,
trs
->
subqueryIndex
);
tscTrace
(
"%p sub:%p launch subquery.orderOfSub:%d"
,
pSql
,
pNew
,
trs
->
subqueryIndex
);
...
@@ -1107,7 +1125,9 @@ static void tscHandleSubRetrievalError(SRetrieveSupport *trsupport, SSqlObj *pSq
...
@@ -1107,7 +1125,9 @@ static void tscHandleSubRetrievalError(SRetrieveSupport *trsupport, SSqlObj *pSq
pPObj
->
cmd
.
command
=
TSDB_SQL_RETRIEVE_METRIC
;
pPObj
->
cmd
.
command
=
TSDB_SQL_RETRIEVE_METRIC
;
}
else
{
}
else
{
// in case of second stage join subquery, invoke its callback function instead of regular QueueAsyncRes
// in case of second stage join subquery, invoke its callback function instead of regular QueueAsyncRes
if
((
pPObj
->
cmd
.
type
&
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)
==
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pPObj
->
cmd
,
0
);
if
((
pQueryInfo
->
type
&
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)
==
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)
{
(
*
pPObj
->
fp
)(
pPObj
->
param
,
pPObj
,
pPObj
->
res
.
code
);
(
*
pPObj
->
fp
)(
pPObj
->
param
,
pPObj
,
pPObj
->
res
.
code
);
}
else
{
// regular super table query
}
else
{
// regular super table query
if
(
pPObj
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
pPObj
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
...
@@ -1137,8 +1157,9 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
...
@@ -1137,8 +1157,9 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
}
}
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
SVnodeSidList
*
vnodeInfo
=
tscGetVnodeSidList
(
pMeterMetaInfo
->
pMetricMeta
,
idx
);
SVnodeSidList
*
vnodeInfo
=
tscGetVnodeSidList
(
pMeterMetaInfo
->
pMetricMeta
,
idx
);
SVPeerDesc
*
pSvd
=
&
vnodeInfo
->
vpeerDesc
[
vnodeInfo
->
index
];
SVPeerDesc
*
pSvd
=
&
vnodeInfo
->
vpeerDesc
[
vnodeInfo
->
index
];
...
@@ -1153,7 +1174,9 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
...
@@ -1153,7 +1174,9 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
printf
(
"received data from vnode: %d rows
\n
"
,
pRes
->
numOfRows
);
printf
(
"received data from vnode: %d rows
\n
"
,
pRes
->
numOfRows
);
SSrcColumnInfo
colInfo
[
256
]
=
{
0
};
SSrcColumnInfo
colInfo
[
256
]
=
{
0
};
tscGetSrcColumnInfo
(
colInfo
,
&
pPObj
->
cmd
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
tscGetSrcColumnInfo
(
colInfo
,
pQueryInfo
);
tColModelDisplayEx
(
pDesc
->
pSchema
,
pRes
->
data
,
pRes
->
numOfRows
,
pRes
->
numOfRows
,
colInfo
);
tColModelDisplayEx
(
pDesc
->
pSchema
,
pRes
->
data
,
pRes
->
numOfRows
,
pRes
->
numOfRows
,
colInfo
);
#endif
#endif
if
(
tsTotalTmpDirGB
!=
0
&&
tsAvailTmpDirGB
<
tsMinimalTmpDirGB
)
{
if
(
tsTotalTmpDirGB
!=
0
&&
tsAvailTmpDirGB
<
tsMinimalTmpDirGB
)
{
...
@@ -1163,7 +1186,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
...
@@ -1163,7 +1186,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
return
;
return
;
}
}
int32_t
ret
=
saveToBuffer
(
trsupport
->
pExtMemBuffer
[
idx
],
pDesc
,
trsupport
->
localBuffer
,
pRes
->
data
,
int32_t
ret
=
saveToBuffer
(
trsupport
->
pExtMemBuffer
[
idx
],
pDesc
,
trsupport
->
localBuffer
,
pRes
->
data
,
pRes
->
numOfRows
,
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
.
orderType
);
pRes
->
numOfRows
,
p
QueryInfo
->
groupbyExpr
.
orderType
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
// set no disk space error info, and abort retry
// set no disk space error info, and abort retry
tscAbortFurtherRetryRetrieval
(
trsupport
,
tres
,
TSDB_CODE_CLI_NO_DISKSPACE
);
tscAbortFurtherRetryRetrieval
(
trsupport
,
tres
,
TSDB_CODE_CLI_NO_DISKSPACE
);
...
@@ -1183,7 +1206,9 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
...
@@ -1183,7 +1206,9 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
printf
(
"%ld rows data flushed to disk:
\n
"
,
trsupport
->
localBuffer
->
numOfElems
);
printf
(
"%ld rows data flushed to disk:
\n
"
,
trsupport
->
localBuffer
->
numOfElems
);
SSrcColumnInfo
colInfo
[
256
]
=
{
0
};
SSrcColumnInfo
colInfo
[
256
]
=
{
0
};
tscGetSrcColumnInfo
(
colInfo
,
&
pPObj
->
cmd
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pPObj
->
cmd
,
0
);
tscGetSrcColumnInfo
(
colInfo
,
pQueryInfo
);
tColModelDisplayEx
(
pDesc
->
pSchema
,
trsupport
->
localBuffer
->
data
,
trsupport
->
localBuffer
->
numOfElems
,
tColModelDisplayEx
(
pDesc
->
pSchema
,
trsupport
->
localBuffer
->
data
,
trsupport
->
localBuffer
->
numOfElems
,
trsupport
->
localBuffer
->
numOfElems
,
colInfo
);
trsupport
->
localBuffer
->
numOfElems
,
colInfo
);
#endif
#endif
...
@@ -1197,7 +1222,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
...
@@ -1197,7 +1222,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
// each result for a vnode is ordered as an independant list,
// each result for a vnode is ordered as an independant list,
// then used as an input of loser tree for disk-based merge routine
// then used as an input of loser tree for disk-based merge routine
int32_t
ret
=
int32_t
ret
=
tscFlushTmpBuffer
(
trsupport
->
pExtMemBuffer
[
idx
],
pDesc
,
trsupport
->
localBuffer
,
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
.
orderType
);
tscFlushTmpBuffer
(
trsupport
->
pExtMemBuffer
[
idx
],
pDesc
,
trsupport
->
localBuffer
,
p
QueryInfo
->
groupbyExpr
.
orderType
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
/* set no disk space error info, and abort retry */
/* set no disk space error info, and abort retry */
return
tscAbortFurtherRetryRetrieval
(
trsupport
,
tres
,
TSDB_CODE_CLI_NO_DISKSPACE
);
return
tscAbortFurtherRetryRetrieval
(
trsupport
,
tres
,
TSDB_CODE_CLI_NO_DISKSPACE
);
...
@@ -1213,7 +1238,9 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
...
@@ -1213,7 +1238,9 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
tscTrace
(
"%p retrieve from %d vnodes completed.final NumOfRows:%d,start to build loser tree"
,
pPObj
,
tscTrace
(
"%p retrieve from %d vnodes completed.final NumOfRows:%d,start to build loser tree"
,
pPObj
,
trsupport
->
pState
->
numOfTotal
,
trsupport
->
pState
->
numOfCompleted
);
trsupport
->
pState
->
numOfTotal
,
trsupport
->
pState
->
numOfCompleted
);
tscClearInterpInfo
(
&
pPObj
->
cmd
);
SQueryInfo
*
pPQueryInfo
=
tscGetQueryInfoDetail
(
&
pPObj
->
cmd
,
0
);
tscClearInterpInfo
(
pPQueryInfo
);
tscCreateLocalReducer
(
trsupport
->
pExtMemBuffer
,
trsupport
->
pState
->
numOfTotal
,
pDesc
,
trsupport
->
pFinalColModel
,
tscCreateLocalReducer
(
trsupport
->
pExtMemBuffer
,
trsupport
->
pState
->
numOfTotal
,
pDesc
,
trsupport
->
pFinalColModel
,
&
pPObj
->
cmd
,
&
pPObj
->
res
);
&
pPObj
->
cmd
,
&
pPObj
->
res
);
tscTrace
(
"%p build loser tree completed"
,
pPObj
);
tscTrace
(
"%p build loser tree completed"
,
pPObj
);
...
@@ -1289,11 +1316,12 @@ static void tscRetrieveDataRes(void *param, TAOS_RES *tres, int retCode);
...
@@ -1289,11 +1316,12 @@ static void tscRetrieveDataRes(void *param, TAOS_RES *tres, int retCode);
static
SSqlObj
*
tscCreateSqlObjForSubquery
(
SSqlObj
*
pSql
,
SRetrieveSupport
*
trsupport
,
SSqlObj
*
prevSqlObj
)
{
static
SSqlObj
*
tscCreateSqlObjForSubquery
(
SSqlObj
*
pSql
,
SRetrieveSupport
*
trsupport
,
SSqlObj
*
prevSqlObj
)
{
SSqlObj
*
pNew
=
createSubqueryObj
(
pSql
,
0
,
tscRetrieveDataRes
,
trsupport
,
prevSqlObj
);
SSqlObj
*
pNew
=
createSubqueryObj
(
pSql
,
0
,
tscRetrieveDataRes
,
trsupport
,
prevSqlObj
);
if
(
pNew
!=
NULL
)
{
// the sub query of two-stage super table query
if
(
pNew
!=
NULL
)
{
// the sub query of two-stage super table query
pNew
->
cmd
.
type
|=
TSDB_QUERY_TYPE_STABLE_SUBQUERY
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pNew
->
cmd
,
0
);
assert
(
pNew
->
cmd
.
pQueryInfo
[
0
].
numOfTables
==
1
);
pQueryInfo
->
type
|=
TSDB_QUERY_TYPE_STABLE_SUBQUERY
;
assert
(
pQueryInfo
->
numOfTables
==
1
);
// launch subquery for each vnode, so the subquery index equals to the vnodeIndex.
// launch subquery for each vnode, so the subquery index equals to the vnodeIndex.
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pNew
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
0
);
pMeterMetaInfo
->
vnodeIndex
=
trsupport
->
subqueryIndex
;
pMeterMetaInfo
->
vnodeIndex
=
trsupport
->
subqueryIndex
;
pSql
->
pSubs
[
trsupport
->
subqueryIndex
]
=
pNew
;
pSql
->
pSubs
[
trsupport
->
subqueryIndex
]
=
pNew
;
...
@@ -1306,7 +1334,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
...
@@ -1306,7 +1334,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
SRetrieveSupport
*
trsupport
=
(
SRetrieveSupport
*
)
param
;
SRetrieveSupport
*
trsupport
=
(
SRetrieveSupport
*
)
param
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
int32_t
idx
=
pMeterMetaInfo
->
vnodeIndex
;
int32_t
idx
=
pMeterMetaInfo
->
vnodeIndex
;
SVnodeSidList
*
vnodeInfo
=
NULL
;
SVnodeSidList
*
vnodeInfo
=
NULL
;
...
@@ -1350,7 +1378,9 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
...
@@ -1350,7 +1378,9 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
trsupport
->
pState
->
code
=
-
TSDB_CODE_CLI_OUT_OF_MEMORY
;
trsupport
->
pState
->
code
=
-
TSDB_CODE_CLI_OUT_OF_MEMORY
;
trsupport
->
numOfRetry
=
MAX_NUM_OF_SUBQUERY_RETRY
;
trsupport
->
numOfRetry
=
MAX_NUM_OF_SUBQUERY_RETRY
;
}
else
{
}
else
{
assert
(
pNew
->
cmd
.
pQueryInfo
[
0
].
pMeterInfo
[
0
]
->
pMeterMeta
!=
NULL
&&
pNew
->
cmd
.
pQueryInfo
[
0
].
pMeterInfo
[
0
]
->
pMetricMeta
!=
NULL
);
SQueryInfo
*
pNewQueryInfo
=
tscGetQueryInfoDetail
(
&
pNew
->
cmd
,
0
);
assert
(
pNewQueryInfo
->
pMeterInfo
[
0
]
->
pMeterMeta
!=
NULL
&&
pNewQueryInfo
->
pMeterInfo
[
0
]
->
pMetricMeta
!=
NULL
);
tscProcessSql
(
pNew
);
tscProcessSql
(
pNew
);
return
;
return
;
}
}
...
@@ -1387,8 +1417,9 @@ int tscBuildRetrieveMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1387,8 +1417,9 @@ int tscBuildRetrieveMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
*
((
uint64_t
*
)
pMsg
)
=
pSql
->
res
.
qhandle
;
*
((
uint64_t
*
)
pMsg
)
=
pSql
->
res
.
qhandle
;
pMsg
+=
sizeof
(
pSql
->
res
.
qhandle
);
pMsg
+=
sizeof
(
pSql
->
res
.
qhandle
);
*
((
uint16_t
*
)
pMsg
)
=
htons
(
pSql
->
cmd
.
type
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
pMsg
+=
sizeof
(
pSql
->
cmd
.
type
);
*
((
uint16_t
*
)
pMsg
)
=
htons
(
pQueryInfo
->
type
);
pMsg
+=
sizeof
(
pQueryInfo
->
type
);
msgLen
=
pMsg
-
pStart
;
msgLen
=
pMsg
-
pStart
;
pSql
->
cmd
.
payloadLen
=
msgLen
;
pSql
->
cmd
.
payloadLen
=
msgLen
;
...
@@ -1400,7 +1431,7 @@ int tscBuildRetrieveMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1400,7 +1431,7 @@ int tscBuildRetrieveMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
void
tscUpdateVnodeInSubmitMsg
(
SSqlObj
*
pSql
,
char
*
buf
)
{
void
tscUpdateVnodeInSubmitMsg
(
SSqlObj
*
pSql
,
char
*
buf
)
{
SShellSubmitMsg
*
pShellMsg
;
SShellSubmitMsg
*
pShellMsg
;
char
*
pMsg
;
char
*
pMsg
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
SMeterMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
SMeterMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
...
@@ -1417,7 +1448,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1417,7 +1448,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
char
*
pMsg
,
*
pStart
;
char
*
pMsg
,
*
pStart
;
int
msgLen
=
0
;
int
msgLen
=
0
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
SMeterMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
SMeterMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
pStart
=
pSql
->
cmd
.
payload
+
tsRpcHeadSize
;
pStart
=
pSql
->
cmd
.
payload
+
tsRpcHeadSize
;
...
@@ -1438,7 +1469,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1438,7 +1469,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
void
tscUpdateVnodeInQueryMsg
(
SSqlObj
*
pSql
,
char
*
buf
)
{
void
tscUpdateVnodeInQueryMsg
(
SSqlObj
*
pSql
,
char
*
buf
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
char
*
pStart
=
buf
+
tsRpcHeadSize
;
char
*
pStart
=
buf
+
tsRpcHeadSize
;
SQueryMeterMsg
*
pQueryMsg
=
(
SQueryMeterMsg
*
)
pStart
;
SQueryMeterMsg
*
pQueryMsg
=
(
SQueryMeterMsg
*
)
pStart
;
...
@@ -1459,14 +1490,15 @@ void tscUpdateVnodeInQueryMsg(SSqlObj *pSql, char *buf) {
...
@@ -1459,14 +1490,15 @@ void tscUpdateVnodeInQueryMsg(SSqlObj *pSql, char *buf) {
*/
*/
static
int32_t
tscEstimateQueryMsgSize
(
SSqlCmd
*
pCmd
)
{
static
int32_t
tscEstimateQueryMsgSize
(
SSqlCmd
*
pCmd
)
{
const
static
int32_t
MIN_QUERY_MSG_PKT_SIZE
=
TSDB_MAX_BYTES_PER_ROW
*
5
;
const
static
int32_t
MIN_QUERY_MSG_PKT_SIZE
=
TSDB_MAX_BYTES_PER_ROW
*
5
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
int32_t
srcColListSize
=
p
Cmd
->
pQueryInfo
[
0
].
colList
.
numOfCols
*
sizeof
(
SColumnInfo
);
int32_t
srcColListSize
=
p
QueryInfo
->
colList
.
numOfCols
*
sizeof
(
SColumnInfo
);
int32_t
exprSize
=
sizeof
(
SSqlFuncExprMsg
)
*
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
int32_t
exprSize
=
sizeof
(
SSqlFuncExprMsg
)
*
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
// meter query without tags values
// meter query without tags values
if
(
!
UTIL_METER_IS_
METRIC
(
pMeterMetaInfo
))
{
if
(
!
UTIL_METER_IS_
SUPERTABLE
(
pMeterMetaInfo
))
{
return
MIN_QUERY_MSG_PKT_SIZE
+
minMsgSize
()
+
sizeof
(
SQueryMeterMsg
)
+
srcColListSize
+
exprSize
;
return
MIN_QUERY_MSG_PKT_SIZE
+
minMsgSize
()
+
sizeof
(
SQueryMeterMsg
)
+
srcColListSize
+
exprSize
;
}
}
...
@@ -1475,18 +1507,18 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd) {
...
@@ -1475,18 +1507,18 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd) {
SVnodeSidList
*
pVnodeSidList
=
tscGetVnodeSidList
(
pMetricMeta
,
pMeterMetaInfo
->
vnodeIndex
);
SVnodeSidList
*
pVnodeSidList
=
tscGetVnodeSidList
(
pMetricMeta
,
pMeterMetaInfo
->
vnodeIndex
);
int32_t
meterInfoSize
=
(
pMetricMeta
->
tagLen
+
sizeof
(
SMeterSidExtInfo
))
*
pVnodeSidList
->
numOfSids
;
int32_t
meterInfoSize
=
(
pMetricMeta
->
tagLen
+
sizeof
(
SMeterSidExtInfo
))
*
pVnodeSidList
->
numOfSids
;
int32_t
outputColumnSize
=
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
*
sizeof
(
SSqlFuncExprMsg
);
int32_t
outputColumnSize
=
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
*
sizeof
(
SSqlFuncExprMsg
);
int32_t
size
=
meterInfoSize
+
outputColumnSize
+
srcColListSize
+
exprSize
+
MIN_QUERY_MSG_PKT_SIZE
;
int32_t
size
=
meterInfoSize
+
outputColumnSize
+
srcColListSize
+
exprSize
+
MIN_QUERY_MSG_PKT_SIZE
;
if
(
p
Cmd
->
pQueryInfo
[
0
].
tsBuf
!=
NULL
)
{
if
(
p
QueryInfo
->
tsBuf
!=
NULL
)
{
size
+=
p
Cmd
->
pQueryInfo
[
0
].
tsBuf
->
fileSize
;
size
+=
p
QueryInfo
->
tsBuf
->
fileSize
;
}
}
return
size
;
return
size
;
}
}
static
char
*
doSerializeTableInfo
(
SSqlObj
*
pSql
,
int32_t
numOfMeters
,
int32_t
vnodeId
,
char
*
pMsg
)
{
static
char
*
doSerializeTableInfo
(
SSqlObj
*
pSql
,
int32_t
numOfMeters
,
int32_t
vnodeId
,
char
*
pMsg
)
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
SMeterMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
SMeterMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
SMetricMeta
*
pMetricMeta
=
pMeterMetaInfo
->
pMetricMeta
;
SMetricMeta
*
pMetricMeta
=
pMeterMetaInfo
->
pMetricMeta
;
...
@@ -1535,7 +1567,9 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1535,7 +1567,9 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
return
-
1
;
return
-
1
;
}
}
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
char
*
pStart
=
pCmd
->
payload
+
tsRpcHeadSize
;
char
*
pStart
=
pCmd
->
payload
+
tsRpcHeadSize
;
SMeterMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
SMeterMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
...
@@ -1577,26 +1611,26 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1577,26 +1611,26 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pQueryMsg
->
numOfSids
=
htonl
(
numOfMeters
);
pQueryMsg
->
numOfSids
=
htonl
(
numOfMeters
);
pQueryMsg
->
numOfTagsCols
=
htons
(
pMeterMetaInfo
->
numOfTags
);
pQueryMsg
->
numOfTagsCols
=
htons
(
pMeterMetaInfo
->
numOfTags
);
if
(
p
Cmd
->
order
.
order
==
TSQL_SO_ASC
)
{
if
(
p
QueryInfo
->
order
.
order
==
TSQL_SO_ASC
)
{
pQueryMsg
->
skey
=
htobe64
(
p
Cmd
->
pQueryInfo
[
0
].
stime
);
pQueryMsg
->
skey
=
htobe64
(
p
QueryInfo
->
stime
);
pQueryMsg
->
ekey
=
htobe64
(
p
Cmd
->
pQueryInfo
[
0
].
etime
);
pQueryMsg
->
ekey
=
htobe64
(
p
QueryInfo
->
etime
);
}
else
{
}
else
{
pQueryMsg
->
skey
=
htobe64
(
p
Cmd
->
pQueryInfo
[
0
].
etime
);
pQueryMsg
->
skey
=
htobe64
(
p
QueryInfo
->
etime
);
pQueryMsg
->
ekey
=
htobe64
(
p
Cmd
->
pQueryInfo
[
0
].
stime
);
pQueryMsg
->
ekey
=
htobe64
(
p
QueryInfo
->
stime
);
}
}
pQueryMsg
->
num
=
htonl
(
0
);
pQueryMsg
->
num
=
htonl
(
0
);
pQueryMsg
->
order
=
htons
(
p
Cmd
->
order
.
order
);
pQueryMsg
->
order
=
htons
(
p
QueryInfo
->
order
.
order
);
pQueryMsg
->
orderColId
=
htons
(
p
Cmd
->
order
.
orderColId
);
pQueryMsg
->
orderColId
=
htons
(
p
QueryInfo
->
order
.
orderColId
);
pQueryMsg
->
interpoType
=
htons
(
p
Cmd
->
pQueryInfo
[
0
].
interpoType
);
pQueryMsg
->
interpoType
=
htons
(
p
QueryInfo
->
interpoType
);
pQueryMsg
->
limit
=
htobe64
(
p
Cmd
->
p
QueryInfo
->
limit
.
limit
);
pQueryMsg
->
limit
=
htobe64
(
pQueryInfo
->
limit
.
limit
);
pQueryMsg
->
offset
=
htobe64
(
p
Cmd
->
p
QueryInfo
->
limit
.
offset
);
pQueryMsg
->
offset
=
htobe64
(
pQueryInfo
->
limit
.
offset
);
pQueryMsg
->
numOfCols
=
htons
(
p
Cmd
->
pQueryInfo
[
0
].
colList
.
numOfCols
);
pQueryMsg
->
numOfCols
=
htons
(
p
QueryInfo
->
colList
.
numOfCols
);
if
(
p
Cmd
->
pQueryInfo
[
0
].
colList
.
numOfCols
<=
0
)
{
if
(
p
QueryInfo
->
colList
.
numOfCols
<=
0
)
{
tscError
(
"%p illegal value of numOfCols in query msg: %d"
,
pSql
,
pMeterMeta
->
numOfColumns
);
tscError
(
"%p illegal value of numOfCols in query msg: %d"
,
pSql
,
pMeterMeta
->
numOfColumns
);
return
-
1
;
return
-
1
;
}
}
...
@@ -1606,19 +1640,19 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1606,19 +1640,19 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
return
-
1
;
return
-
1
;
}
}
pQueryMsg
->
nAggTimeInterval
=
htobe64
(
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
);
pQueryMsg
->
nAggTimeInterval
=
htobe64
(
p
QueryInfo
->
nAggTimeInterval
);
pQueryMsg
->
intervalTimeUnit
=
p
Cmd
->
pQueryInfo
[
0
].
intervalTimeUnit
;
pQueryMsg
->
intervalTimeUnit
=
p
QueryInfo
->
intervalTimeUnit
;
if
(
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
<
0
)
{
if
(
p
QueryInfo
->
nAggTimeInterval
<
0
)
{
tscError
(
"%p illegal value of aggregation time interval in query msg: %ld"
,
pSql
,
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
);
tscError
(
"%p illegal value of aggregation time interval in query msg: %ld"
,
pSql
,
p
QueryInfo
->
nAggTimeInterval
);
return
-
1
;
return
-
1
;
}
}
if
(
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
<
0
)
{
if
(
p
QueryInfo
->
groupbyExpr
.
numOfGroupCols
<
0
)
{
tscError
(
"%p illegal value of numOfGroupCols in query msg: %d"
,
pSql
,
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
);
tscError
(
"%p illegal value of numOfGroupCols in query msg: %d"
,
pSql
,
p
QueryInfo
->
groupbyExpr
.
numOfGroupCols
);
return
-
1
;
return
-
1
;
}
}
pQueryMsg
->
numOfGroupCols
=
htons
(
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
);
pQueryMsg
->
numOfGroupCols
=
htons
(
p
QueryInfo
->
groupbyExpr
.
numOfGroupCols
);
if
(
UTIL_METER_IS_NOMRAL_METER
(
pMeterMetaInfo
))
{
// query on meter
if
(
UTIL_METER_IS_NOMRAL_METER
(
pMeterMetaInfo
))
{
// query on meter
pQueryMsg
->
tagLength
=
0
;
pQueryMsg
->
tagLength
=
0
;
...
@@ -1626,20 +1660,20 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1626,20 +1660,20 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pQueryMsg
->
tagLength
=
htons
(
pMetricMeta
->
tagLen
);
pQueryMsg
->
tagLength
=
htons
(
pMetricMeta
->
tagLen
);
}
}
pQueryMsg
->
queryType
=
htons
(
p
Cmd
->
type
);
pQueryMsg
->
queryType
=
htons
(
p
QueryInfo
->
type
);
pQueryMsg
->
numOfOutputCols
=
htons
(
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
.
numOfExprs
);
pQueryMsg
->
numOfOutputCols
=
htons
(
p
QueryInfo
->
exprsInfo
.
numOfExprs
);
if
(
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
<
0
)
{
if
(
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
<
0
)
{
tscError
(
"%p illegal value of number of output columns in query msg: %d"
,
pSql
,
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
);
tscError
(
"%p illegal value of number of output columns in query msg: %d"
,
pSql
,
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
);
return
-
1
;
return
-
1
;
}
}
// set column list ids
// set column list ids
char
*
pMsg
=
(
char
*
)(
pQueryMsg
->
colList
)
+
p
Cmd
->
pQueryInfo
[
0
].
colList
.
numOfCols
*
sizeof
(
SColumnInfo
);
char
*
pMsg
=
(
char
*
)(
pQueryMsg
->
colList
)
+
p
QueryInfo
->
colList
.
numOfCols
*
sizeof
(
SColumnInfo
);
SSchema
*
pSchema
=
tsGetSchema
(
pMeterMeta
);
SSchema
*
pSchema
=
tsGetSchema
(
pMeterMeta
);
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
colList
.
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
colList
.
numOfCols
;
++
i
)
{
SColumnBase
*
pCol
=
tscColumnBaseInfoGet
(
&
p
Cmd
->
pQueryInfo
[
0
].
colList
,
i
);
SColumnBase
*
pCol
=
tscColumnBaseInfoGet
(
&
p
QueryInfo
->
colList
,
i
);
SSchema
*
pColSchema
=
&
pSchema
[
pCol
->
colIndex
.
columnIndex
];
SSchema
*
pColSchema
=
&
pSchema
[
pCol
->
colIndex
.
columnIndex
];
if
(
pCol
->
colIndex
.
columnIndex
>=
pMeterMeta
->
numOfColumns
||
pColSchema
->
type
<
TSDB_DATA_TYPE_BOOL
||
if
(
pCol
->
colIndex
.
columnIndex
>=
pMeterMeta
->
numOfColumns
||
pColSchema
->
type
<
TSDB_DATA_TYPE_BOOL
||
...
@@ -1688,8 +1722,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1688,8 +1722,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SSqlFuncExprMsg
*
pSqlFuncExpr
=
(
SSqlFuncExprMsg
*
)
pMsg
;
SSqlFuncExprMsg
*
pSqlFuncExpr
=
(
SSqlFuncExprMsg
*
)
pMsg
;
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
i
);
if
(
pExpr
->
functionId
==
TSDB_FUNC_ARITHM
)
{
if
(
pExpr
->
functionId
==
TSDB_FUNC_ARITHM
)
{
hasArithmeticFunction
=
true
;
hasArithmeticFunction
=
true
;
...
@@ -1728,8 +1762,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1728,8 +1762,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
int32_t
len
=
0
;
int32_t
len
=
0
;
if
(
hasArithmeticFunction
)
{
if
(
hasArithmeticFunction
)
{
SColumnBase
*
pColBase
=
p
Cmd
->
pQueryInfo
[
0
].
colList
.
pColList
;
SColumnBase
*
pColBase
=
p
QueryInfo
->
colList
.
pColList
;
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
colList
.
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
colList
.
numOfCols
;
++
i
)
{
char
*
name
=
pSchema
[
pColBase
[
i
].
colIndex
.
columnIndex
].
name
;
char
*
name
=
pSchema
[
pColBase
[
i
].
colIndex
.
columnIndex
].
name
;
int32_t
lenx
=
strlen
(
name
);
int32_t
lenx
=
strlen
(
name
);
memcpy
(
pMsg
,
name
,
lenx
);
memcpy
(
pMsg
,
name
,
lenx
);
...
@@ -1763,7 +1797,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1763,7 +1797,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
}
}
SSqlGroupbyExpr
*
pGroupbyExpr
=
&
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
;
SSqlGroupbyExpr
*
pGroupbyExpr
=
&
p
QueryInfo
->
groupbyExpr
;
if
(
pGroupbyExpr
->
numOfGroupCols
!=
0
)
{
if
(
pGroupbyExpr
->
numOfGroupCols
!=
0
)
{
pQueryMsg
->
orderByIdx
=
htons
(
pGroupbyExpr
->
orderIndex
);
pQueryMsg
->
orderByIdx
=
htons
(
pGroupbyExpr
->
orderIndex
);
pQueryMsg
->
orderType
=
htons
(
pGroupbyExpr
->
orderType
);
pQueryMsg
->
orderType
=
htons
(
pGroupbyExpr
->
orderType
);
...
@@ -1785,10 +1819,10 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1785,10 +1819,10 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
}
}
if
(
p
Cmd
->
pQueryInfo
[
0
].
interpoType
!=
TSDB_INTERPO_NONE
)
{
if
(
p
QueryInfo
->
interpoType
!=
TSDB_INTERPO_NONE
)
{
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
*
((
int64_t
*
)
pMsg
)
=
htobe64
(
p
Cmd
->
pQueryInfo
[
0
].
defaultVal
[
i
]);
*
((
int64_t
*
)
pMsg
)
=
htobe64
(
p
QueryInfo
->
defaultVal
[
i
]);
pMsg
+=
sizeof
(
p
Cmd
->
pQueryInfo
[
0
].
defaultVal
[
0
]);
pMsg
+=
sizeof
(
p
QueryInfo
->
defaultVal
[
0
]);
}
}
}
}
...
@@ -1797,13 +1831,13 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1797,13 +1831,13 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
int32_t
tsLen
=
0
;
int32_t
tsLen
=
0
;
int32_t
numOfBlocks
=
0
;
int32_t
numOfBlocks
=
0
;
if
(
p
Cmd
->
pQueryInfo
[
0
].
tsBuf
!=
NULL
)
{
if
(
p
QueryInfo
->
tsBuf
!=
NULL
)
{
STSVnodeBlockInfo
*
pBlockInfo
=
tsBufGetVnodeBlockInfo
(
p
Cmd
->
pQueryInfo
[
0
].
tsBuf
,
pMeterMetaInfo
->
vnodeIndex
);
STSVnodeBlockInfo
*
pBlockInfo
=
tsBufGetVnodeBlockInfo
(
p
QueryInfo
->
tsBuf
,
pMeterMetaInfo
->
vnodeIndex
);
assert
(
QUERY_IS_JOIN_QUERY
(
p
Cmd
->
type
)
&&
pBlockInfo
!=
NULL
);
// this query should not be sent
assert
(
QUERY_IS_JOIN_QUERY
(
p
QueryInfo
->
type
)
&&
pBlockInfo
!=
NULL
);
// this query should not be sent
// todo refactor
// todo refactor
fseek
(
p
Cmd
->
pQueryInfo
[
0
].
tsBuf
->
f
,
pBlockInfo
->
offset
,
SEEK_SET
);
fseek
(
p
QueryInfo
->
tsBuf
->
f
,
pBlockInfo
->
offset
,
SEEK_SET
);
fread
(
pMsg
,
pBlockInfo
->
compLen
,
1
,
p
Cmd
->
pQueryInfo
[
0
].
tsBuf
->
f
);
fread
(
pMsg
,
pBlockInfo
->
compLen
,
1
,
p
QueryInfo
->
tsBuf
->
f
);
pMsg
+=
pBlockInfo
->
compLen
;
pMsg
+=
pBlockInfo
->
compLen
;
tsLen
=
pBlockInfo
->
compLen
;
tsLen
=
pBlockInfo
->
compLen
;
...
@@ -1812,8 +1846,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1812,8 +1846,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pQueryMsg
->
tsLen
=
htonl
(
tsLen
);
pQueryMsg
->
tsLen
=
htonl
(
tsLen
);
pQueryMsg
->
tsNumOfBlocks
=
htonl
(
numOfBlocks
);
pQueryMsg
->
tsNumOfBlocks
=
htonl
(
numOfBlocks
);
if
(
p
Cmd
->
pQueryInfo
[
0
].
tsBuf
!=
NULL
)
{
if
(
p
QueryInfo
->
tsBuf
!=
NULL
)
{
pQueryMsg
->
tsOrder
=
htonl
(
p
Cmd
->
pQueryInfo
[
0
].
tsBuf
->
tsOrder
);
pQueryMsg
->
tsOrder
=
htonl
(
p
QueryInfo
->
tsBuf
->
tsOrder
);
}
}
msgLen
=
pMsg
-
pStart
;
msgLen
=
pMsg
-
pStart
;
...
@@ -1836,7 +1870,7 @@ int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1836,7 +1870,7 @@ int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg
=
doBuildMsgHeader
(
pSql
,
&
pStart
);
pMsg
=
doBuildMsgHeader
(
pSql
,
&
pStart
);
pCreateDbMsg
=
(
SCreateDbMsg
*
)
pMsg
;
pCreateDbMsg
=
(
SCreateDbMsg
*
)
pMsg
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
strncpy
(
pCreateDbMsg
->
db
,
pMeterMetaInfo
->
name
,
tListLen
(
pCreateDbMsg
->
db
));
strncpy
(
pCreateDbMsg
->
db
,
pMeterMetaInfo
->
name
,
tListLen
(
pCreateDbMsg
->
db
));
pMsg
+=
sizeof
(
SCreateDbMsg
);
pMsg
+=
sizeof
(
SCreateDbMsg
);
...
@@ -1986,7 +2020,7 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1986,7 +2020,7 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg
=
doBuildMsgHeader
(
pSql
,
&
pStart
);
pMsg
=
doBuildMsgHeader
(
pSql
,
&
pStart
);
pDropDbMsg
=
(
SDropDbMsg
*
)
pMsg
;
pDropDbMsg
=
(
SDropDbMsg
*
)
pMsg
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
strncpy
(
pDropDbMsg
->
db
,
pMeterMetaInfo
->
name
,
tListLen
(
pDropDbMsg
->
db
));
strncpy
(
pDropDbMsg
->
db
,
pMeterMetaInfo
->
name
,
tListLen
(
pDropDbMsg
->
db
));
pDropDbMsg
->
ignoreNotExists
=
pInfo
->
pDCLInfo
->
existsCheck
?
1
:
0
;
pDropDbMsg
->
ignoreNotExists
=
pInfo
->
pDCLInfo
->
existsCheck
?
1
:
0
;
...
@@ -2008,7 +2042,7 @@ int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2008,7 +2042,7 @@ int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg
=
doBuildMsgHeader
(
pSql
,
&
pStart
);
pMsg
=
doBuildMsgHeader
(
pSql
,
&
pStart
);
pDropTableMsg
=
(
SDropTableMsg
*
)
pMsg
;
pDropTableMsg
=
(
SDropTableMsg
*
)
pMsg
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
strcpy
(
pDropTableMsg
->
meterId
,
pMeterMetaInfo
->
name
);
strcpy
(
pDropTableMsg
->
meterId
,
pMeterMetaInfo
->
name
);
pDropTableMsg
->
igNotExists
=
pInfo
->
pDCLInfo
->
existsCheck
?
1
:
0
;
pDropTableMsg
->
igNotExists
=
pInfo
->
pDCLInfo
->
existsCheck
?
1
:
0
;
...
@@ -2026,7 +2060,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2026,7 +2060,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
char
*
pMsg
,
*
pStart
;
char
*
pMsg
,
*
pStart
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
pMsg
=
doBuildMsgHeader
(
pSql
,
&
pStart
);
pMsg
=
doBuildMsgHeader
(
pSql
,
&
pStart
);
pDrop
=
(
SDropDnodeMsg
*
)
pMsg
;
pDrop
=
(
SDropDnodeMsg
*
)
pMsg
;
...
@@ -2051,7 +2085,7 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2051,7 +2085,7 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg
=
doBuildMsgHeader
(
pSql
,
&
pStart
);
pMsg
=
doBuildMsgHeader
(
pSql
,
&
pStart
);
pDropMsg
=
(
SDropUserMsg
*
)
pMsg
;
pDropMsg
=
(
SDropUserMsg
*
)
pMsg
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
strcpy
(
pDropMsg
->
user
,
pMeterMetaInfo
->
name
);
strcpy
(
pDropMsg
->
user
,
pMeterMetaInfo
->
name
);
pMsg
+=
sizeof
(
SDropUserMsg
);
pMsg
+=
sizeof
(
SDropUserMsg
);
...
@@ -2071,7 +2105,7 @@ int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2071,7 +2105,7 @@ int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg
=
doBuildMsgHeader
(
pSql
,
&
pStart
);
pMsg
=
doBuildMsgHeader
(
pSql
,
&
pStart
);
pUseDbMsg
=
(
SUseDbMsg
*
)
pMsg
;
pUseDbMsg
=
(
SUseDbMsg
*
)
pMsg
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
strcpy
(
pUseDbMsg
->
db
,
pMeterMetaInfo
->
name
);
strcpy
(
pUseDbMsg
->
db
,
pMeterMetaInfo
->
name
);
pMsg
+=
sizeof
(
SUseDbMsg
);
pMsg
+=
sizeof
(
SUseDbMsg
);
...
@@ -2101,7 +2135,7 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2101,7 +2135,7 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SMgmtHead
*
pMgmt
=
(
SMgmtHead
*
)
pMsg
;
SMgmtHead
*
pMgmt
=
(
SMgmtHead
*
)
pMsg
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
size_t
nameLen
=
strlen
(
pMeterMetaInfo
->
name
);
size_t
nameLen
=
strlen
(
pMeterMetaInfo
->
name
);
if
(
nameLen
>
0
)
{
if
(
nameLen
>
0
)
{
...
@@ -2199,7 +2233,9 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2199,7 +2233,9 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
int
size
=
0
;
int
size
=
0
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
// Reallocate the payload size
// Reallocate the payload size
size
=
tscEstimateCreateTableMsgLength
(
pSql
,
pInfo
);
size
=
tscEstimateCreateTableMsgLength
(
pSql
,
pInfo
);
...
@@ -2239,7 +2275,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2239,7 +2275,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pSchema
=
pCreateTableMsg
->
schema
;
pSchema
=
pCreateTableMsg
->
schema
;
for
(
int
i
=
0
;
i
<
pCmd
->
numOfCols
+
pCmd
->
count
;
++
i
)
{
for
(
int
i
=
0
;
i
<
pCmd
->
numOfCols
+
pCmd
->
count
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
i
);
pSchema
->
type
=
pField
->
type
;
pSchema
->
type
=
pField
->
type
;
strcpy
(
pSchema
->
name
,
pField
->
name
);
strcpy
(
pSchema
->
name
,
pField
->
name
);
...
@@ -2258,7 +2294,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2258,7 +2294,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
}
}
tscClearFieldInfo
(
&
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
);
tscClearFieldInfo
(
&
p
QueryInfo
->
fieldsInfo
);
msgLen
=
pMsg
-
pStart
;
msgLen
=
pMsg
-
pStart
;
pCmd
->
payloadLen
=
msgLen
;
pCmd
->
payloadLen
=
msgLen
;
...
@@ -2269,7 +2305,8 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2269,7 +2305,8 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
int
tscEstimateAlterTableMsgLength
(
SSqlCmd
*
pCmd
)
{
int
tscEstimateAlterTableMsgLength
(
SSqlCmd
*
pCmd
)
{
return
minMsgSize
()
+
sizeof
(
SMgmtHead
)
+
sizeof
(
SAlterTableMsg
)
+
sizeof
(
SSchema
)
*
tscNumOfFields
(
pCmd
)
+
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
return
minMsgSize
()
+
sizeof
(
SMgmtHead
)
+
sizeof
(
SAlterTableMsg
)
+
sizeof
(
SSchema
)
*
tscNumOfFields
(
pQueryInfo
)
+
TSDB_EXTRA_PAYLOAD_SIZE
;
TSDB_EXTRA_PAYLOAD_SIZE
;
}
}
...
@@ -2280,7 +2317,9 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2280,7 +2317,9 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
int
size
=
0
;
int
size
=
0
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
size
=
tscEstimateAlterTableMsgLength
(
pCmd
);
size
=
tscEstimateAlterTableMsgLength
(
pCmd
);
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
pCmd
,
size
))
{
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
pCmd
,
size
))
{
...
@@ -2301,12 +2340,12 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2301,12 +2340,12 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
strcpy
(
pAlterTableMsg
->
meterId
,
pMeterMetaInfo
->
name
);
strcpy
(
pAlterTableMsg
->
meterId
,
pMeterMetaInfo
->
name
);
pAlterTableMsg
->
type
=
htons
(
pAlterInfo
->
type
);
pAlterTableMsg
->
type
=
htons
(
pAlterInfo
->
type
);
pAlterTableMsg
->
numOfCols
=
htons
(
tscNumOfFields
(
p
Cmd
));
pAlterTableMsg
->
numOfCols
=
htons
(
tscNumOfFields
(
p
QueryInfo
));
memcpy
(
pAlterTableMsg
->
tagVal
,
pAlterInfo
->
tagData
.
data
,
TSDB_MAX_TAGS_LEN
);
memcpy
(
pAlterTableMsg
->
tagVal
,
pAlterInfo
->
tagData
.
data
,
TSDB_MAX_TAGS_LEN
);
SSchema
*
pSchema
=
pAlterTableMsg
->
schema
;
SSchema
*
pSchema
=
pAlterTableMsg
->
schema
;
for
(
int
i
=
0
;
i
<
tscNumOfFields
(
p
Cmd
);
++
i
)
{
for
(
int
i
=
0
;
i
<
tscNumOfFields
(
p
QueryInfo
);
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
i
);
pSchema
->
type
=
pField
->
type
;
pSchema
->
type
=
pField
->
type
;
strcpy
(
pSchema
->
name
,
pField
->
name
);
strcpy
(
pSchema
->
name
,
pField
->
name
);
...
@@ -2332,7 +2371,7 @@ int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2332,7 +2371,7 @@ int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
STscObj
*
pObj
=
pSql
->
pTscObj
;
STscObj
*
pObj
=
pSql
->
pTscObj
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
pStart
=
pCmd
->
payload
+
tsRpcHeadSize
;
pStart
=
pCmd
->
payload
+
tsRpcHeadSize
;
pMsg
=
pStart
;
pMsg
=
pStart
;
...
@@ -2364,7 +2403,8 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2364,7 +2403,8 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SMgmtHead
*
pMgmt
=
(
SMgmtHead
*
)
pMsg
;
SMgmtHead
*
pMgmt
=
(
SMgmtHead
*
)
pMsg
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
size_t
nameLen
=
strlen
(
pMeterMetaInfo
->
name
);
size_t
nameLen
=
strlen
(
pMeterMetaInfo
->
name
);
if
(
nameLen
>
0
)
{
if
(
nameLen
>
0
)
{
...
@@ -2378,8 +2418,8 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2378,8 +2418,8 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
*
((
uint64_t
*
)
pMsg
)
=
pSql
->
res
.
qhandle
;
*
((
uint64_t
*
)
pMsg
)
=
pSql
->
res
.
qhandle
;
pMsg
+=
sizeof
(
pSql
->
res
.
qhandle
);
pMsg
+=
sizeof
(
pSql
->
res
.
qhandle
);
*
((
uint16_t
*
)
pMsg
)
=
htons
(
p
Cmd
->
type
);
*
((
uint16_t
*
)
pMsg
)
=
htons
(
p
QueryInfo
->
type
);
pMsg
+=
sizeof
(
p
Cmd
->
type
);
pMsg
+=
sizeof
(
p
QueryInfo
->
type
);
msgLen
=
pMsg
-
pStart
;
msgLen
=
pMsg
-
pStart
;
pCmd
->
payloadLen
=
msgLen
;
pCmd
->
payloadLen
=
msgLen
;
...
@@ -2388,17 +2428,17 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2388,17 +2428,17 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int
tscSetResultPointer
(
S
SqlCmd
*
pCmd
,
SSqlRes
*
pRes
)
{
static
int
tscSetResultPointer
(
S
QueryInfo
*
pQueryInfo
,
SSqlRes
*
pRes
)
{
if
(
tscCreateResPointerInfo
(
p
Cmd
,
pRes
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscCreateResPointerInfo
(
p
QueryInfo
,
pRes
)
!=
TSDB_CODE_SUCCESS
)
{
return
pRes
->
code
;
return
pRes
->
code
;
}
}
for
(
int
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
i
);
int16_t
offset
=
tscFieldInfoGetOffset
(
p
Cmd
,
i
);
int16_t
offset
=
tscFieldInfoGetOffset
(
p
QueryInfo
,
i
);
pRes
->
bytes
[
i
]
=
pField
->
bytes
;
pRes
->
bytes
[
i
]
=
pField
->
bytes
;
if
(
p
Cmd
->
order
.
order
==
TSQL_SO_DESC
)
{
if
(
p
QueryInfo
->
order
.
order
==
TSQL_SO_DESC
)
{
pRes
->
bytes
[
i
]
=
-
pRes
->
bytes
[
i
];
pRes
->
bytes
[
i
]
=
-
pRes
->
bytes
[
i
];
pRes
->
tsrow
[
i
]
=
((
pRes
->
data
+
offset
*
pRes
->
numOfRows
)
+
(
pRes
->
numOfRows
-
1
)
*
pField
->
bytes
);
pRes
->
tsrow
[
i
]
=
((
pRes
->
data
+
offset
*
pRes
->
numOfRows
)
+
(
pRes
->
numOfRows
-
1
)
*
pField
->
bytes
);
}
else
{
}
else
{
...
@@ -2419,6 +2459,8 @@ static int tscLocalResultCommonBuilder(SSqlObj *pSql, int32_t numOfRes) {
...
@@ -2419,6 +2459,8 @@ static int tscLocalResultCommonBuilder(SSqlObj *pSql, int32_t numOfRes) {
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
pRes
->
code
=
TSDB_CODE_SUCCESS
;
pRes
->
code
=
TSDB_CODE_SUCCESS
;
if
(
pRes
->
rspType
==
0
)
{
if
(
pRes
->
rspType
==
0
)
{
...
@@ -2426,7 +2468,7 @@ static int tscLocalResultCommonBuilder(SSqlObj *pSql, int32_t numOfRes) {
...
@@ -2426,7 +2468,7 @@ static int tscLocalResultCommonBuilder(SSqlObj *pSql, int32_t numOfRes) {
pRes
->
row
=
0
;
pRes
->
row
=
0
;
pRes
->
rspType
=
1
;
pRes
->
rspType
=
1
;
tscSetResultPointer
(
p
Cmd
,
pRes
);
tscSetResultPointer
(
p
QueryInfo
,
pRes
);
pRes
->
row
=
0
;
pRes
->
row
=
0
;
}
else
{
}
else
{
...
@@ -2447,7 +2489,7 @@ static int tscLocalResultCommonBuilder(SSqlObj *pSql, int32_t numOfRes) {
...
@@ -2447,7 +2489,7 @@ static int tscLocalResultCommonBuilder(SSqlObj *pSql, int32_t numOfRes) {
int
tscProcessDescribeTableRsp
(
SSqlObj
*
pSql
)
{
int
tscProcessDescribeTableRsp
(
SSqlObj
*
pSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
int32_t
numOfRes
=
pMeterMetaInfo
->
pMeterMeta
->
numOfColumns
+
pMeterMetaInfo
->
pMeterMeta
->
numOfTags
;
int32_t
numOfRes
=
pMeterMetaInfo
->
pMeterMeta
->
numOfColumns
+
pMeterMetaInfo
->
pMeterMeta
->
numOfTags
;
...
@@ -2456,10 +2498,12 @@ int tscProcessDescribeTableRsp(SSqlObj *pSql) {
...
@@ -2456,10 +2498,12 @@ int tscProcessDescribeTableRsp(SSqlObj *pSql) {
int
tscProcessTagRetrieveRsp
(
SSqlObj
*
pSql
)
{
int
tscProcessTagRetrieveRsp
(
SSqlObj
*
pSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
int32_t
numOfRes
=
0
;
int32_t
numOfRes
=
0
;
if
(
tscSqlExprGet
(
p
Cmd
,
0
)
->
functionId
==
TSDB_FUNC_TAGPRJ
)
{
if
(
tscSqlExprGet
(
p
QueryInfo
,
0
)
->
functionId
==
TSDB_FUNC_TAGPRJ
)
{
numOfRes
=
pMeterMetaInfo
->
pMetricMeta
->
numOfMeters
;
numOfRes
=
pMeterMetaInfo
->
pMetricMeta
->
numOfMeters
;
}
else
{
}
else
{
numOfRes
=
1
;
// for count function, there is only one output.
numOfRes
=
1
;
// for count function, there is only one output.
...
@@ -2472,17 +2516,18 @@ int tscProcessRetrieveMetricRsp(SSqlObj *pSql) {
...
@@ -2472,17 +2516,18 @@ int tscProcessRetrieveMetricRsp(SSqlObj *pSql) {
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
pRes
->
code
=
tscLocalDoReduce
(
pSql
);
pRes
->
code
=
tscLocalDoReduce
(
pSql
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
if
(
pRes
->
code
==
TSDB_CODE_SUCCESS
&&
pRes
->
numOfRows
>
0
)
{
if
(
pRes
->
code
==
TSDB_CODE_SUCCESS
&&
pRes
->
numOfRows
>
0
)
{
tscSetResultPointer
(
p
Cmd
,
pRes
);
tscSetResultPointer
(
p
QueryInfo
,
pRes
);
}
}
pRes
->
row
=
0
;
pRes
->
row
=
0
;
uint8_t
code
=
p
Sql
->
res
.
code
;
uint8_t
code
=
p
Res
->
code
;
if
(
pSql
->
fp
)
{
// async retrieve metric data
if
(
pSql
->
fp
)
{
// async retrieve metric data
if
(
p
Sql
->
res
.
code
==
TSDB_CODE_SUCCESS
)
{
if
(
p
Res
->
code
==
TSDB_CODE_SUCCESS
)
{
(
*
pSql
->
fp
)(
pSql
->
param
,
pSql
,
p
Sql
->
res
.
numOfRows
);
(
*
pSql
->
fp
)(
pSql
->
param
,
pSql
,
p
Res
->
numOfRows
);
}
else
{
}
else
{
tscQueueAsyncRes
(
pSql
);
tscQueueAsyncRes
(
pSql
);
}
}
...
@@ -2535,7 +2580,9 @@ int tscBuildMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2535,7 +2580,9 @@ int tscBuildMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
pMsg
=
pCmd
->
payload
+
tsRpcHeadSize
;
pMsg
=
pCmd
->
payload
+
tsRpcHeadSize
;
pStart
=
pMsg
;
pStart
=
pMsg
;
...
@@ -2547,10 +2594,10 @@ int tscBuildMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2547,10 +2594,10 @@ int tscBuildMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pInfoMsg
=
(
SMeterInfoMsg
*
)
pMsg
;
pInfoMsg
=
(
SMeterInfoMsg
*
)
pMsg
;
strcpy
(
pInfoMsg
->
meterId
,
pMeterMetaInfo
->
name
);
strcpy
(
pInfoMsg
->
meterId
,
pMeterMetaInfo
->
name
);
pInfoMsg
->
createFlag
=
htons
((
uint16_t
)
p
Cmd
->
pQueryInfo
[
0
].
defaultVal
[
0
]);
pInfoMsg
->
createFlag
=
htons
((
uint16_t
)
p
QueryInfo
->
defaultVal
[
0
]);
pMsg
+=
sizeof
(
SMeterInfoMsg
);
pMsg
+=
sizeof
(
SMeterInfoMsg
);
if
(
p
Cmd
->
pQueryInfo
[
0
].
defaultVal
[
0
]
!=
0
)
{
if
(
p
QueryInfo
->
defaultVal
[
0
]
!=
0
)
{
memcpy
(
pInfoMsg
->
tags
,
tmpData
,
sizeof
(
STagData
));
memcpy
(
pInfoMsg
->
tags
,
tmpData
,
sizeof
(
STagData
));
pMsg
+=
sizeof
(
STagData
);
pMsg
+=
sizeof
(
STagData
);
}
}
...
@@ -2608,19 +2655,20 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2608,19 +2655,20 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
static
int32_t
tscEstimateMetricMetaMsgSize
(
SSqlCmd
*
pCmd
)
{
static
int32_t
tscEstimateMetricMetaMsgSize
(
SSqlCmd
*
pCmd
)
{
const
int32_t
defaultSize
=
const
int32_t
defaultSize
=
minMsgSize
()
+
sizeof
(
SMetricMetaMsg
)
+
sizeof
(
SMgmtHead
)
+
sizeof
(
int16_t
)
*
TSDB_MAX_TAGS
;
minMsgSize
()
+
sizeof
(
SMetricMetaMsg
)
+
sizeof
(
SMgmtHead
)
+
sizeof
(
int16_t
)
*
TSDB_MAX_TAGS
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
int32_t
n
=
0
;
int32_t
n
=
0
;
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
tagCond
.
numOfTagCond
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
tagCond
.
numOfTagCond
;
++
i
)
{
n
+=
strlen
(
p
Cmd
->
pQueryInfo
[
0
].
tagCond
.
cond
[
i
].
cond
);
n
+=
strlen
(
p
QueryInfo
->
tagCond
.
cond
[
i
].
cond
);
}
}
int32_t
tagLen
=
n
*
TSDB_NCHAR_SIZE
;
int32_t
tagLen
=
n
*
TSDB_NCHAR_SIZE
;
if
(
p
Cmd
->
pQueryInfo
[
0
].
tagCond
.
tbnameCond
.
cond
!=
NULL
)
{
if
(
p
QueryInfo
->
tagCond
.
tbnameCond
.
cond
!=
NULL
)
{
tagLen
+=
strlen
(
p
Cmd
->
pQueryInfo
[
0
].
tagCond
.
tbnameCond
.
cond
)
*
TSDB_NCHAR_SIZE
;
tagLen
+=
strlen
(
p
QueryInfo
->
tagCond
.
tbnameCond
.
cond
)
*
TSDB_NCHAR_SIZE
;
}
}
int32_t
joinCondLen
=
(
TSDB_METER_ID_LEN
+
sizeof
(
int16_t
))
*
2
;
int32_t
joinCondLen
=
(
TSDB_METER_ID_LEN
+
sizeof
(
int16_t
))
*
2
;
int32_t
elemSize
=
sizeof
(
SMetricMetaElemMsg
)
*
p
Cmd
->
p
QueryInfo
->
numOfTables
;
int32_t
elemSize
=
sizeof
(
SMetricMetaElemMsg
)
*
pQueryInfo
->
numOfTables
;
int32_t
len
=
tagLen
+
joinCondLen
+
elemSize
+
defaultSize
;
int32_t
len
=
tagLen
+
joinCondLen
+
elemSize
+
defaultSize
;
...
@@ -2634,9 +2682,11 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2634,9 +2682,11 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
int
tableIndex
=
0
;
int
tableIndex
=
0
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
S
TagCond
*
pTagCond
=
&
pCmd
->
pQueryInfo
[
0
].
tagCond
;
S
QueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
)
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
tableIndex
);
STagCond
*
pTagCond
=
&
pQueryInfo
->
tagCond
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
tableIndex
);
int32_t
size
=
tscEstimateMetricMetaMsgSize
(
pCmd
);
int32_t
size
=
tscEstimateMetricMetaMsgSize
(
pCmd
);
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
pCmd
,
size
))
{
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
pCmd
,
size
))
{
...
@@ -2653,7 +2703,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2653,7 +2703,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg
+=
sizeof
(
SMgmtHead
);
pMsg
+=
sizeof
(
SMgmtHead
);
pMetaMsg
=
(
SMetricMetaMsg
*
)
pMsg
;
pMetaMsg
=
(
SMetricMetaMsg
*
)
pMsg
;
pMetaMsg
->
numOfMeters
=
htonl
(
p
Cmd
->
p
QueryInfo
->
numOfTables
);
pMetaMsg
->
numOfMeters
=
htonl
(
pQueryInfo
->
numOfTables
);
pMsg
+=
sizeof
(
SMetricMetaMsg
);
pMsg
+=
sizeof
(
SMetricMetaMsg
);
...
@@ -2675,8 +2725,8 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2675,8 +2725,8 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
*
(
int16_t
*
)
pMsg
=
pTagCond
->
joinInfo
.
right
.
tagCol
;
*
(
int16_t
*
)
pMsg
=
pTagCond
->
joinInfo
.
right
.
tagCol
;
pMsg
+=
sizeof
(
int16_t
);
pMsg
+=
sizeof
(
int16_t
);
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
p
QueryInfo
->
numOfTables
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
i
);
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
i
);
uint64_t
uid
=
pMeterMetaInfo
->
pMeterMeta
->
uid
;
uint64_t
uid
=
pMeterMetaInfo
->
pMeterMeta
->
uid
;
offset
=
pMsg
-
(
char
*
)
pMetaMsg
;
offset
=
pMsg
-
(
char
*
)
pMetaMsg
;
...
@@ -2719,7 +2769,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2719,7 +2769,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg
+=
len
;
pMsg
+=
len
;
}
}
SSqlGroupbyExpr
*
pGroupby
=
&
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
;
SSqlGroupbyExpr
*
pGroupby
=
&
p
QueryInfo
->
groupbyExpr
;
if
(
pGroupby
->
tableIndex
!=
i
&&
pGroupby
->
numOfGroupCols
>
0
)
{
if
(
pGroupby
->
tableIndex
!=
i
&&
pGroupby
->
numOfGroupCols
>
0
)
{
pElem
->
orderType
=
0
;
pElem
->
orderType
=
0
;
...
@@ -2737,8 +2787,8 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2737,8 +2787,8 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
offset
=
pMsg
-
(
char
*
)
pMetaMsg
;
offset
=
pMsg
-
(
char
*
)
pMetaMsg
;
pElem
->
groupbyTagColumnList
=
htonl
(
offset
);
pElem
->
groupbyTagColumnList
=
htonl
(
offset
);
for
(
int32_t
j
=
0
;
j
<
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
.
numOfGroupCols
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
p
QueryInfo
->
groupbyExpr
.
numOfGroupCols
;
++
j
)
{
SColIndexEx
*
pCol
=
&
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
.
columnInfo
[
j
];
SColIndexEx
*
pCol
=
&
p
QueryInfo
->
groupbyExpr
.
columnInfo
[
j
];
SColIndexEx
*
pDestCol
=
(
SColIndexEx
*
)
pMsg
;
SColIndexEx
*
pDestCol
=
(
SColIndexEx
*
)
pMsg
;
pDestCol
->
colIdxInBuf
=
0
;
pDestCol
->
colIdxInBuf
=
0
;
...
@@ -2833,7 +2883,8 @@ int tscProcessRetrieveRspFromMgmt(SSqlObj *pSql) {
...
@@ -2833,7 +2883,8 @@ int tscProcessRetrieveRspFromMgmt(SSqlObj *pSql) {
pRes
->
data
=
pRetrieve
->
data
;
pRes
->
data
=
pRetrieve
->
data
;
tscSetResultPointer
(
pCmd
,
pRes
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
tscSetResultPointer
(
pQueryInfo
,
pRes
);
if
(
pRes
->
numOfRows
==
0
)
{
if
(
pRes
->
numOfRows
==
0
)
{
taosAddConnIntoCache
(
tscConnCache
,
pSql
->
thandle
,
pSql
->
ip
,
pSql
->
vnode
,
pObj
->
user
);
taosAddConnIntoCache
(
tscConnCache
,
pSql
->
thandle
,
pSql
->
ip
,
pSql
->
vnode
,
pObj
->
user
);
...
@@ -2925,7 +2976,7 @@ int tscProcessMeterMetaRsp(SSqlObj *pSql) {
...
@@ -2925,7 +2976,7 @@ int tscProcessMeterMetaRsp(SSqlObj *pSql) {
pMeta
->
index
=
0
;
pMeta
->
index
=
0
;
// todo add one more function: taosAddDataIfNotExists();
// todo add one more function: taosAddDataIfNotExists();
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
taosRemoveDataFromCache
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
false
);
taosRemoveDataFromCache
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
false
);
pMeterMetaInfo
->
pMeterMeta
=
(
SMeterMeta
*
)
taosAddDataIntoCache
(
tscCacheHandle
,
pMeterMetaInfo
->
name
,
(
char
*
)
pMeta
,
pMeterMetaInfo
->
pMeterMeta
=
(
SMeterMeta
*
)
taosAddDataIntoCache
(
tscCacheHandle
,
pMeterMetaInfo
->
name
,
(
char
*
)
pMeta
,
...
@@ -3131,11 +3182,12 @@ int tscProcessMetricMetaRsp(SSqlObj *pSql) {
...
@@ -3131,11 +3182,12 @@ int tscProcessMetricMetaRsp(SSqlObj *pSql) {
sizes
[
k
]
=
pBuf
-
(
char
*
)
pNewMetricMeta
;
sizes
[
k
]
=
pBuf
-
(
char
*
)
pNewMetricMeta
;
}
}
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
char
name
[
TSDB_MAX_TAGS_LEN
+
1
]
=
{
0
};
char
name
[
TSDB_MAX_TAGS_LEN
+
1
]
=
{
0
};
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
i
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
i
);
tscGetMetricMetaCacheKey
(
&
pSql
->
cmd
,
name
,
pMeterMetaInfo
->
pMeterMeta
->
uid
);
tscGetMetricMetaCacheKey
(
&
pSql
->
cmd
,
0
,
name
,
pMeterMetaInfo
->
pMeterMeta
->
uid
);
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
printf
(
"generate the metric key:%s, index:%d
\n
"
,
name
,
i
);
printf
(
"generate the metric key:%s, index:%d
\n
"
,
name
,
i
);
...
@@ -3178,7 +3230,10 @@ int tscProcessShowRsp(SSqlObj *pSql) {
...
@@ -3178,7 +3230,10 @@ int tscProcessShowRsp(SSqlObj *pSql) {
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
//?
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
pShow
=
(
SShowRspMsg
*
)
pRes
->
pRsp
;
pShow
=
(
SShowRspMsg
*
)
pRes
->
pRsp
;
pRes
->
qhandle
=
pShow
->
qhandle
;
pRes
->
qhandle
=
pShow
->
qhandle
;
...
@@ -3203,19 +3258,19 @@ int tscProcessShowRsp(SSqlObj *pSql) {
...
@@ -3203,19 +3258,19 @@ int tscProcessShowRsp(SSqlObj *pSql) {
int32_t
size
=
pMeta
->
numOfColumns
*
sizeof
(
SSchema
)
+
sizeof
(
SMeterMeta
);
int32_t
size
=
pMeta
->
numOfColumns
*
sizeof
(
SSchema
)
+
sizeof
(
SMeterMeta
);
pMeterMetaInfo
->
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
=
(
SMeterMeta
*
)
taosAddDataIntoCache
(
tscCacheHandle
,
key
,
(
char
*
)
pMeta
,
size
,
tsMeterMetaKeepTimer
);
(
SMeterMeta
*
)
taosAddDataIntoCache
(
tscCacheHandle
,
key
,
(
char
*
)
pMeta
,
size
,
tsMeterMetaKeepTimer
);
pCmd
->
numOfCols
=
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
pCmd
->
numOfCols
=
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
SSchema
*
pMeterSchema
=
tsGetSchema
(
pMeterMetaInfo
->
pMeterMeta
);
SSchema
*
pMeterSchema
=
tsGetSchema
(
pMeterMetaInfo
->
pMeterMeta
);
tscColumnBaseInfoReserve
(
&
p
Cmd
->
pQueryInfo
[
0
].
colList
,
pMeta
->
numOfColumns
);
tscColumnBaseInfoReserve
(
&
p
QueryInfo
->
colList
,
pMeta
->
numOfColumns
);
SColumnIndex
index
=
{
0
};
SColumnIndex
index
=
{
0
};
for
(
int16_t
i
=
0
;
i
<
pMeta
->
numOfColumns
;
++
i
)
{
for
(
int16_t
i
=
0
;
i
<
pMeta
->
numOfColumns
;
++
i
)
{
index
.
columnIndex
=
i
;
index
.
columnIndex
=
i
;
tscColumnBaseInfoInsert
(
p
Cmd
,
&
index
);
tscColumnBaseInfoInsert
(
p
QueryInfo
,
&
index
);
tscFieldInfoSetValFromSchema
(
&
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
,
i
,
&
pMeterSchema
[
i
]);
tscFieldInfoSetValFromSchema
(
&
p
QueryInfo
->
fieldsInfo
,
i
,
&
pMeterSchema
[
i
]);
}
}
tscFieldInfoCalOffset
(
p
Cmd
);
tscFieldInfoCalOffset
(
p
QueryInfo
);
return
0
;
return
0
;
}
}
...
@@ -3257,7 +3312,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
...
@@ -3257,7 +3312,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
int
tscProcessUseDbRsp
(
SSqlObj
*
pSql
)
{
int
tscProcessUseDbRsp
(
SSqlObj
*
pSql
)
{
STscObj
*
pObj
=
pSql
->
pTscObj
;
STscObj
*
pObj
=
pSql
->
pTscObj
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
strcpy
(
pObj
->
db
,
pMeterMetaInfo
->
name
);
strcpy
(
pObj
->
db
,
pMeterMetaInfo
->
name
);
return
0
;
return
0
;
...
@@ -3269,7 +3324,7 @@ int tscProcessDropDbRsp(SSqlObj *UNUSED_PARAM(pSql)) {
...
@@ -3269,7 +3324,7 @@ int tscProcessDropDbRsp(SSqlObj *UNUSED_PARAM(pSql)) {
}
}
int
tscProcessDropTableRsp
(
SSqlObj
*
pSql
)
{
int
tscProcessDropTableRsp
(
SSqlObj
*
pSql
)
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
SMeterMeta
*
pMeterMeta
=
taosGetDataFromCache
(
tscCacheHandle
,
pMeterMetaInfo
->
name
);
SMeterMeta
*
pMeterMeta
=
taosGetDataFromCache
(
tscCacheHandle
,
pMeterMetaInfo
->
name
);
if
(
pMeterMeta
==
NULL
)
{
if
(
pMeterMeta
==
NULL
)
{
...
@@ -3296,7 +3351,7 @@ int tscProcessDropTableRsp(SSqlObj *pSql) {
...
@@ -3296,7 +3351,7 @@ int tscProcessDropTableRsp(SSqlObj *pSql) {
}
}
int
tscProcessAlterTableMsgRsp
(
SSqlObj
*
pSql
)
{
int
tscProcessAlterTableMsgRsp
(
SSqlObj
*
pSql
)
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
SMeterMeta
*
pMeterMeta
=
taosGetDataFromCache
(
tscCacheHandle
,
pMeterMetaInfo
->
name
);
SMeterMeta
*
pMeterMeta
=
taosGetDataFromCache
(
tscCacheHandle
,
pMeterMetaInfo
->
name
);
if
(
pMeterMeta
==
NULL
)
{
/* not in cache, abort */
if
(
pMeterMeta
==
NULL
)
{
/* not in cache, abort */
...
@@ -3307,7 +3362,7 @@ int tscProcessAlterTableMsgRsp(SSqlObj *pSql) {
...
@@ -3307,7 +3362,7 @@ int tscProcessAlterTableMsgRsp(SSqlObj *pSql) {
taosRemoveDataFromCache
(
tscCacheHandle
,
(
void
**
)
&
pMeterMeta
,
true
);
taosRemoveDataFromCache
(
tscCacheHandle
,
(
void
**
)
&
pMeterMeta
,
true
);
if
(
pMeterMetaInfo
->
pMeterMeta
)
{
if
(
pMeterMetaInfo
->
pMeterMeta
)
{
bool
isSuperTable
=
UTIL_METER_IS_
METRIC
(
pMeterMetaInfo
);
bool
isSuperTable
=
UTIL_METER_IS_
SUPERTABLE
(
pMeterMetaInfo
);
taosRemoveDataFromCache
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
true
);
taosRemoveDataFromCache
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
true
);
taosRemoveDataFromCache
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
true
);
taosRemoveDataFromCache
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
true
);
...
@@ -3340,6 +3395,8 @@ int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
...
@@ -3340,6 +3395,8 @@ int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
STscObj
*
pObj
=
pSql
->
pTscObj
;
STscObj
*
pObj
=
pSql
->
pTscObj
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SRetrieveMeterRsp
*
pRetrieve
=
(
SRetrieveMeterRsp
*
)
pRes
->
pRsp
;
SRetrieveMeterRsp
*
pRetrieve
=
(
SRetrieveMeterRsp
*
)
pRes
->
pRsp
;
pRes
->
numOfRows
=
htonl
(
pRetrieve
->
numOfRows
);
pRes
->
numOfRows
=
htonl
(
pRetrieve
->
numOfRows
);
...
@@ -3349,15 +3406,15 @@ int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
...
@@ -3349,15 +3406,15 @@ int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
pRes
->
useconds
=
htobe64
(
pRetrieve
->
useconds
);
pRes
->
useconds
=
htobe64
(
pRetrieve
->
useconds
);
pRes
->
data
=
pRetrieve
->
data
;
pRes
->
data
=
pRetrieve
->
data
;
tscSetResultPointer
(
pCmd
,
pRes
);
tscSetResultPointer
(
tscGetQueryInfoDetail
(
pCmd
,
0
)
,
pRes
);
pRes
->
row
=
0
;
pRes
->
row
=
0
;
/**
/**
* If the query result is exhausted, or current query is to free resource at server side,
* If the query result is exhausted, or current query is to free resource at server side,
* the connection will be recycled.
* the connection will be recycled.
*/
*/
if
((
pRes
->
numOfRows
==
0
&&
!
(
tscProjectionQueryOnMetric
(
pCmd
)
&&
pRes
->
offset
>
0
))
||
if
((
pRes
->
numOfRows
==
0
&&
!
(
tscProjectionQueryOnMetric
(
pCmd
,
0
)
&&
pRes
->
offset
>
0
))
||
((
p
Cmd
->
type
&
TSDB_QUERY_TYPE_FREE_RESOURCE
)
==
TSDB_QUERY_TYPE_FREE_RESOURCE
))
{
((
p
QueryInfo
->
type
&
TSDB_QUERY_TYPE_FREE_RESOURCE
)
==
TSDB_QUERY_TYPE_FREE_RESOURCE
))
{
tscTrace
(
"%p no result or free resource, recycle connection"
,
pSql
);
tscTrace
(
"%p no result or free resource, recycle connection"
,
pSql
);
taosAddConnIntoCache
(
tscConnCache
,
pSql
->
thandle
,
pSql
->
ip
,
pSql
->
vnode
,
pObj
->
user
);
taosAddConnIntoCache
(
tscConnCache
,
pSql
->
thandle
,
pSql
->
ip
,
pSql
->
vnode
,
pObj
->
user
);
pSql
->
thandle
=
NULL
;
pSql
->
thandle
=
NULL
;
...
@@ -3371,12 +3428,14 @@ int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
...
@@ -3371,12 +3428,14 @@ int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
int
tscProcessRetrieveRspFromLocal
(
SSqlObj
*
pSql
)
{
int
tscProcessRetrieveRspFromLocal
(
SSqlObj
*
pSql
)
{
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SRetrieveMeterRsp
*
pRetrieve
=
(
SRetrieveMeterRsp
*
)
pRes
->
pRsp
;
SRetrieveMeterRsp
*
pRetrieve
=
(
SRetrieveMeterRsp
*
)
pRes
->
pRsp
;
pRes
->
numOfRows
=
htonl
(
pRetrieve
->
numOfRows
);
pRes
->
numOfRows
=
htonl
(
pRetrieve
->
numOfRows
);
pRes
->
data
=
pRetrieve
->
data
;
pRes
->
data
=
pRetrieve
->
data
;
tscSetResultPointer
(
p
Cmd
,
pRes
);
tscSetResultPointer
(
p
QueryInfo
,
pRes
);
pRes
->
row
=
0
;
pRes
->
row
=
0
;
return
0
;
return
0
;
}
}
...
@@ -3385,6 +3444,7 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code);
...
@@ -3385,6 +3444,7 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code);
static
int32_t
tscDoGetMeterMeta
(
SSqlObj
*
pSql
,
char
*
meterId
,
int32_t
index
)
{
static
int32_t
tscDoGetMeterMeta
(
SSqlObj
*
pSql
,
char
*
meterId
,
int32_t
index
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SSqlObj
*
pNew
=
calloc
(
1
,
sizeof
(
SSqlObj
));
SSqlObj
*
pNew
=
calloc
(
1
,
sizeof
(
SSqlObj
));
if
(
NULL
==
pNew
)
{
if
(
NULL
==
pNew
)
{
...
@@ -3397,10 +3457,11 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) {
...
@@ -3397,10 +3457,11 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) {
pNew
->
cmd
.
payload
=
NULL
;
pNew
->
cmd
.
payload
=
NULL
;
pNew
->
cmd
.
allocSize
=
0
;
pNew
->
cmd
.
allocSize
=
0
;
pNew
->
cmd
.
pQueryInfo
=
calloc
(
1
,
sizeof
(
SQueryInfo
)
);
tscAddSubqueryInfo
(
&
pNew
->
cmd
);
pNew
->
cmd
.
numOf
Queries
=
1
;
pNew
->
cmd
.
numOf
Clause
=
1
;
pNew
->
cmd
.
pQueryInfo
[
0
].
defaultVal
[
0
]
=
pSql
->
cmd
.
pQueryInfo
[
0
].
defaultVal
[
0
];
// flag of create table if not exists
SQueryInfo
*
pNewQueryInfo
=
tscGetQueryInfoDetail
(
&
pNew
->
cmd
,
0
);
pNewQueryInfo
->
defaultVal
[
0
]
=
pQueryInfo
->
defaultVal
[
0
];
// flag of create table if not exists
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
&
pNew
->
cmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
))
{
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
&
pNew
->
cmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
))
{
tscError
(
"%p malloc failed for payload to get meter meta"
,
pSql
);
tscError
(
"%p malloc failed for payload to get meter meta"
,
pSql
);
free
(
pNew
);
free
(
pNew
);
...
@@ -3408,7 +3469,7 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) {
...
@@ -3408,7 +3469,7 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) {
return
TSDB_CODE_CLI_OUT_OF_MEMORY
;
return
TSDB_CODE_CLI_OUT_OF_MEMORY
;
}
}
SMeterMetaInfo
*
pMeterMetaInfo
=
tscAddEmptyMeterMetaInfo
(
&
pNew
->
cmd
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscAddEmptyMeterMetaInfo
(
&
pNew
->
cmd
,
0
);
strcpy
(
pMeterMetaInfo
->
name
,
meterId
);
strcpy
(
pMeterMetaInfo
->
name
,
meterId
);
memcpy
(
pNew
->
cmd
.
payload
,
pSql
->
cmd
.
payload
,
TSDB_DEFAULT_PAYLOAD_SIZE
);
memcpy
(
pNew
->
cmd
.
payload
,
pSql
->
cmd
.
payload
,
TSDB_DEFAULT_PAYLOAD_SIZE
);
...
@@ -3419,7 +3480,7 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) {
...
@@ -3419,7 +3480,7 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) {
tsem_init
(
&
pNew
->
emptyRspSem
,
0
,
1
);
tsem_init
(
&
pNew
->
emptyRspSem
,
0
,
1
);
code
=
tscProcessSql
(
pNew
);
code
=
tscProcessSql
(
pNew
);
SMeterMetaInfo
*
pInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
index
);
SMeterMetaInfo
*
pInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
index
);
// update cache only on success get metermeta
// update cache only on success get metermeta
if
(
code
==
TSDB_CODE_SUCCESS
)
{
if
(
code
==
TSDB_CODE_SUCCESS
)
{
...
@@ -3446,7 +3507,7 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) {
...
@@ -3446,7 +3507,7 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) {
int
tscGetMeterMeta
(
SSqlObj
*
pSql
,
char
*
meterId
,
int32_t
index
)
{
int
tscGetMeterMeta
(
SSqlObj
*
pSql
,
char
*
meterId
,
int32_t
index
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
index
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
index
);
// if the SSqlCmd owns a metermeta, release it first
// if the SSqlCmd owns a metermeta, release it first
taosRemoveDataFromCache
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
false
);
taosRemoveDataFromCache
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
false
);
...
@@ -3473,7 +3534,9 @@ int tscGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) {
...
@@ -3473,7 +3534,9 @@ int tscGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) {
}
}
int
tscGetMeterMetaEx
(
SSqlObj
*
pSql
,
char
*
meterId
,
bool
createIfNotExists
)
{
int
tscGetMeterMetaEx
(
SSqlObj
*
pSql
,
char
*
meterId
,
bool
createIfNotExists
)
{
pSql
->
cmd
.
pQueryInfo
[
0
].
defaultVal
[
0
]
=
createIfNotExists
?
1
:
0
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
pQueryInfo
->
defaultVal
[
0
]
=
createIfNotExists
?
1
:
0
;
return
tscGetMeterMeta
(
pSql
,
meterId
,
0
);
return
tscGetMeterMeta
(
pSql
,
meterId
,
0
);
}
}
...
@@ -3498,11 +3561,13 @@ static void tscWaitingForCreateTable(SSqlCmd *pCmd) {
...
@@ -3498,11 +3561,13 @@ static void tscWaitingForCreateTable(SSqlCmd *pCmd) {
*/
*/
int
tscRenewMeterMeta
(
SSqlObj
*
pSql
,
char
*
meterId
)
{
int
tscRenewMeterMeta
(
SSqlObj
*
pSql
,
char
*
meterId
)
{
int
code
=
0
;
int
code
=
0
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
// handle metric meta renew process
// handle metric meta renew process
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
// enforce the renew metermeta operation in async model
// enforce the renew metermeta operation in async model
if
(
pSql
->
fp
==
NULL
)
pSql
->
fp
=
(
void
*
)
0x1
;
if
(
pSql
->
fp
==
NULL
)
pSql
->
fp
=
(
void
*
)
0x1
;
...
@@ -3515,7 +3580,7 @@ int tscRenewMeterMeta(SSqlObj *pSql, char *meterId) {
...
@@ -3515,7 +3580,7 @@ int tscRenewMeterMeta(SSqlObj *pSql, char *meterId) {
tscTrace
(
"%p update meter meta, old: numOfTags:%d, numOfCols:%d, uid:%"
PRId64
", addr:%p"
,
pSql
,
tscTrace
(
"%p update meter meta, old: numOfTags:%d, numOfCols:%d, uid:%"
PRId64
", addr:%p"
,
pSql
,
pMeterMetaInfo
->
numOfTags
,
pCmd
->
numOfCols
,
pMeterMetaInfo
->
pMeterMeta
->
uid
,
pMeterMetaInfo
->
pMeterMeta
);
pMeterMetaInfo
->
numOfTags
,
pCmd
->
numOfCols
,
pMeterMetaInfo
->
pMeterMeta
->
uid
,
pMeterMetaInfo
->
pMeterMeta
);
}
}
tscWaitingForCreateTable
(
&
pSql
->
c
md
);
tscWaitingForCreateTable
(
pC
md
);
taosRemoveDataFromCache
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
true
);
taosRemoveDataFromCache
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
true
);
code
=
tscDoGetMeterMeta
(
pSql
,
meterId
,
0
);
// todo ??
code
=
tscDoGetMeterMeta
(
pSql
,
meterId
,
0
);
// todo ??
...
@@ -3542,11 +3607,14 @@ int tscGetMetricMeta(SSqlObj *pSql) {
...
@@ -3542,11 +3607,14 @@ int tscGetMetricMeta(SSqlObj *pSql) {
* the vnode query condition is serialized into pCmd->payload, we need to rebuild key for metricmeta info in cache.
* the vnode query condition is serialized into pCmd->payload, we need to rebuild key for metricmeta info in cache.
*/
*/
bool
reqMetricMeta
=
false
;
bool
reqMetricMeta
=
false
;
for
(
int32_t
i
=
0
;
i
<
pSql
->
cmd
.
pQueryInfo
[
0
].
numOfTables
;
++
i
)
{
int32_t
subClauseIndex
=
0
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
subClauseIndex
);
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
char
tagstr
[
TSDB_MAX_TAGS_LEN
+
1
]
=
{
0
};
char
tagstr
[
TSDB_MAX_TAGS_LEN
+
1
]
=
{
0
};
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
i
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
i
);
tscGetMetricMetaCacheKey
(
pCmd
,
tagstr
,
pMeterMetaInfo
->
pMeterMeta
->
uid
);
tscGetMetricMetaCacheKey
(
pCmd
,
subClauseIndex
,
tagstr
,
pMeterMetaInfo
->
pMeterMeta
->
uid
);
taosRemoveDataFromCache
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
false
);
taosRemoveDataFromCache
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
false
);
...
@@ -3570,11 +3638,11 @@ int tscGetMetricMeta(SSqlObj *pSql) {
...
@@ -3570,11 +3638,11 @@ int tscGetMetricMeta(SSqlObj *pSql) {
pNew
->
cmd
.
command
=
TSDB_SQL_METRIC
;
pNew
->
cmd
.
command
=
TSDB_SQL_METRIC
;
for
(
int32_t
i
=
0
;
i
<
p
Sql
->
cmd
.
pQueryInfo
[
0
].
numOfTables
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
numOfTables
;
++
i
)
{
SMeterMetaInfo
*
pMMInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
i
);
SMeterMetaInfo
*
pMMInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
i
);
SMeterMeta
*
pMeterMeta
=
taosGetDataFromCache
(
tscCacheHandle
,
pMMInfo
->
name
);
SMeterMeta
*
pMeterMeta
=
taosGetDataFromCache
(
tscCacheHandle
,
pMMInfo
->
name
);
tscAddMeterMetaInfo
(
&
pNew
->
cmd
,
pMMInfo
->
name
,
pMeterMeta
,
NULL
,
pMMInfo
->
numOfTags
,
pMMInfo
->
tagColumnIndex
);
tscAddMeterMetaInfo
(
&
pNew
->
cmd
,
0
,
pMMInfo
->
name
,
pMeterMeta
,
NULL
,
pMMInfo
->
numOfTags
,
pMMInfo
->
tagColumnIndex
);
}
}
if
((
code
=
tscAllocPayload
(
&
pNew
->
cmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
tscAllocPayload
(
&
pNew
->
cmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
))
!=
TSDB_CODE_SUCCESS
)
{
...
@@ -3583,16 +3651,18 @@ int tscGetMetricMeta(SSqlObj *pSql) {
...
@@ -3583,16 +3651,18 @@ int tscGetMetricMeta(SSqlObj *pSql) {
}
}
// the query condition on meter is serialized into payload
// the query condition on meter is serialized into payload
tscTagCondCopy
(
&
pNew
->
cmd
.
pQueryInfo
[
0
].
tagCond
,
&
pSql
->
cmd
.
pQueryInfo
[
0
].
tagCond
);
SQueryInfo
*
pNewQueryInfo
=
tscGetQueryInfoDetail
(
&
pNew
->
cmd
,
0
);
tscTagCondCopy
(
&
pNewQueryInfo
->
tagCond
,
&
pQueryInfo
->
tagCond
);
pNew
->
cmd
.
pQueryInfo
[
0
].
groupbyExpr
=
pSql
->
cmd
.
pQueryInfo
[
0
].
groupbyExpr
;
pNew
QueryInfo
->
groupbyExpr
=
pQueryInfo
->
groupbyExpr
;
pNew
->
cmd
.
pQueryInfo
[
0
].
numOfTables
=
pSql
->
cmd
.
pQueryInfo
[
0
].
numOfTables
;
pNew
QueryInfo
->
numOfTables
=
pQueryInfo
->
numOfTables
;
pNew
->
cmd
.
pQueryInfo
[
0
].
slimit
=
pSql
->
cmd
.
pQueryInfo
[
0
].
slimit
;
pNew
QueryInfo
->
slimit
=
pQueryInfo
->
slimit
;
pNew
->
cmd
.
order
=
pSql
->
cmd
.
order
;
pNew
QueryInfo
->
order
=
pQueryInfo
->
order
;
if
(
pSql
->
fp
!=
NULL
&&
pSql
->
pStream
==
NULL
)
{
if
(
pSql
->
fp
!=
NULL
&&
pSql
->
pStream
==
NULL
)
{
tscFreeSqlCmdData
(
&
pSql
->
cmd
);
pCmd
->
pDataBlocks
=
tscDestroyBlockArrayList
(
pCmd
->
pDataBlocks
);
tscFreeSubqueryInfo
(
pCmd
);
}
}
tscTrace
(
"%p allocate new pSqlObj:%p to get metricMeta"
,
pSql
,
pNew
);
tscTrace
(
"%p allocate new pSqlObj:%p to get metricMeta"
,
pSql
,
pNew
);
...
@@ -3602,11 +3672,11 @@ int tscGetMetricMeta(SSqlObj *pSql) {
...
@@ -3602,11 +3672,11 @@ int tscGetMetricMeta(SSqlObj *pSql) {
code
=
tscProcessSql
(
pNew
);
code
=
tscProcessSql
(
pNew
);
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
p
QueryInfo
->
numOfTables
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
char
tagstr
[
TSDB_MAX_TAGS_LEN
]
=
{
0
};
char
tagstr
[
TSDB_MAX_TAGS_LEN
]
=
{
0
};
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
i
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
i
);
tscGetMetricMetaCacheKey
(
pCmd
,
tagstr
,
pMeterMetaInfo
->
pMeterMeta
->
uid
);
tscGetMetricMetaCacheKey
(
pCmd
,
0
,
tagstr
,
pMeterMetaInfo
->
pMeterMeta
->
uid
);
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
printf
(
"create metric key:%s, index:%d
\n
"
,
tagstr
,
i
);
printf
(
"create metric key:%s, index:%d
\n
"
,
tagstr
,
i
);
...
...
src/client/src/tscSql.c
浏览文件 @
e15aa9b1
...
@@ -128,8 +128,7 @@ TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const
...
@@ -128,8 +128,7 @@ TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const
}
}
pSql
->
cmd
.
command
=
TSDB_SQL_CONNECT
;
pSql
->
cmd
.
command
=
TSDB_SQL_CONNECT
;
int
ret
=
tscAllocPayload
(
&
pSql
->
cmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
);
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
&
pSql
->
cmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
))
{
if
(
TSDB_CODE_SUCCESS
!=
ret
)
{
globalCode
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
globalCode
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
free
(
pSql
);
free
(
pSql
);
free
(
pObj
);
free
(
pObj
);
...
@@ -298,7 +297,8 @@ int taos_num_fields(TAOS_RES *res) {
...
@@ -298,7 +297,8 @@ int taos_num_fields(TAOS_RES *res) {
SSqlObj
*
pSql
=
(
SSqlObj
*
)
res
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
res
;
if
(
pSql
==
NULL
||
pSql
->
signature
!=
pSql
)
return
0
;
if
(
pSql
==
NULL
||
pSql
->
signature
!=
pSql
)
return
0
;
SFieldInfo
*
pFieldsInfo
=
&
pSql
->
cmd
.
pQueryInfo
[
0
].
fieldsInfo
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SFieldInfo
*
pFieldsInfo
=
&
pQueryInfo
->
fieldsInfo
;
return
(
pFieldsInfo
->
numOfOutputCols
-
pFieldsInfo
->
numOfHiddenCols
);
return
(
pFieldsInfo
->
numOfOutputCols
-
pFieldsInfo
->
numOfHiddenCols
);
}
}
...
@@ -321,7 +321,8 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
...
@@ -321,7 +321,8 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
SSqlObj
*
pSql
=
(
SSqlObj
*
)
res
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
res
;
if
(
pSql
==
NULL
||
pSql
->
signature
!=
pSql
)
return
0
;
if
(
pSql
==
NULL
||
pSql
->
signature
!=
pSql
)
return
0
;
return
pSql
->
cmd
.
pQueryInfo
[
0
].
fieldsInfo
.
pFields
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
return
pQueryInfo
->
fieldsInfo
.
pFields
;
}
}
int
taos_retrieve
(
TAOS_RES
*
res
)
{
int
taos_retrieve
(
TAOS_RES
*
res
)
{
...
@@ -370,31 +371,33 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
...
@@ -370,31 +371,33 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
pRes
->
numOfTotal
+=
pRes
->
numOfRows
;
pRes
->
numOfTotal
+=
pRes
->
numOfRows
;
}
}
for
(
int
i
=
0
;
i
<
pCmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
pCmd
,
i
,
pCmd
->
order
)
+
for
(
int
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
pRes
->
bytes
[
i
]
*
(
1
-
pCmd
->
order
.
order
)
*
(
pRes
->
numOfRows
-
1
);
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
pQueryInfo
,
i
,
pQueryInfo
->
order
)
+
pRes
->
bytes
[
i
]
*
(
1
-
pQueryInfo
->
order
.
order
)
*
(
pRes
->
numOfRows
-
1
);
}
}
*
rows
=
pRes
->
tsrow
;
*
rows
=
pRes
->
tsrow
;
return
(
p
Cmd
->
order
.
order
==
TSQL_SO_DESC
)
?
pRes
->
numOfRows
:
-
pRes
->
numOfRows
;
return
(
p
QueryInfo
->
order
.
order
==
TSQL_SO_DESC
)
?
pRes
->
numOfRows
:
-
pRes
->
numOfRows
;
}
}
static
void
**
doSetResultRowData
(
SSqlObj
*
pSql
)
{
static
void
**
doSetResultRowData
(
SSqlObj
*
pSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
int32_t
num
=
0
;
int32_t
num
=
0
;
for
(
int
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
p
Cmd
,
i
,
pCmd
->
order
)
+
pRes
->
bytes
[
i
]
*
pRes
->
row
;
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
p
QueryInfo
,
i
,
pQueryInfo
->
order
)
+
pRes
->
bytes
[
i
]
*
pRes
->
row
;
// primary key column cannot be null in interval query, no need to check
// primary key column cannot be null in interval query, no need to check
if
(
i
==
0
&&
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
>
0
)
{
if
(
i
==
0
&&
p
QueryInfo
->
nAggTimeInterval
>
0
)
{
continue
;
continue
;
}
}
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
i
);
if
(
isNull
(
pRes
->
tsrow
[
i
],
pField
->
type
))
{
if
(
isNull
(
pRes
->
tsrow
[
i
],
pField
->
type
))
{
pRes
->
tsrow
[
i
]
=
NULL
;
pRes
->
tsrow
[
i
]
=
NULL
;
...
@@ -419,7 +422,7 @@ static void **doSetResultRowData(SSqlObj *pSql) {
...
@@ -419,7 +422,7 @@ static void **doSetResultRowData(SSqlObj *pSql) {
}
}
}
}
assert
(
num
<=
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
);
assert
(
num
<=
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
);
return
pRes
->
tsrow
;
return
pRes
->
tsrow
;
}
}
...
@@ -437,15 +440,17 @@ static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) {
...
@@ -437,15 +440,17 @@ static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) {
bool
hasData
=
true
;
bool
hasData
=
true
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
if
(
tscProjectionQueryOnMetric
(
pCmd
))
{
if
(
tscProjectionQueryOnMetric
(
pCmd
,
0
))
{
bool
allSubqueryExhausted
=
true
;
bool
allSubqueryExhausted
=
true
;
for
(
int32_t
i
=
0
;
i
<
pSql
->
numOfSubs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pSql
->
numOfSubs
;
++
i
)
{
SSqlRes
*
pRes1
=
&
pSql
->
pSubs
[
i
]
->
res
;
SSqlRes
*
pRes1
=
&
pSql
->
pSubs
[
i
]
->
res
;
SSqlCmd
*
pCmd1
=
&
pSql
->
pSubs
[
i
]
->
cmd
;
SSqlCmd
*
pCmd1
=
&
pSql
->
pSubs
[
i
]
->
cmd
;
SMeterMetaInfo
*
pMetaInfo
=
tscGetMeterMetaInfo
(
pCmd1
,
0
);
SMeterMetaInfo
*
pMetaInfo
=
tscGetMeterMetaInfo
(
pCmd1
,
0
,
0
);
assert
(
pCmd1
->
pQueryInfo
[
0
].
numOfTables
==
1
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
assert
(
pQueryInfo
->
numOfTables
==
1
);
/*
/*
* if the global limitation is not reached, and current result has not exhausted, or next more vnodes are
* if the global limitation is not reached, and current result has not exhausted, or next more vnodes are
...
@@ -462,10 +467,10 @@ static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) {
...
@@ -462,10 +467,10 @@ static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) {
}
else
{
// otherwise, in case inner join, if any subquery exhausted, query completed.
}
else
{
// otherwise, in case inner join, if any subquery exhausted, query completed.
for
(
int32_t
i
=
0
;
i
<
pSql
->
numOfSubs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pSql
->
numOfSubs
;
++
i
)
{
SSqlRes
*
pRes1
=
&
pSql
->
pSubs
[
i
]
->
res
;
SSqlRes
*
pRes1
=
&
pSql
->
pSubs
[
i
]
->
res
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
pSubs
[
i
]
->
cmd
,
0
);
if
((
pRes1
->
row
>=
pRes1
->
numOfRows
&&
tscHasReachLimitation
(
pSql
->
pSubs
[
i
])
&&
if
((
pRes1
->
row
>=
pRes1
->
numOfRows
&&
tscHasReachLimitation
(
pSql
->
pSubs
[
i
])
&&
tscProjectionQueryOnTable
(
&
pSql
->
pSubs
[
i
]
->
cmd
))
||
tscProjectionQueryOnTable
(
pQueryInfo
))
||
(
pRes1
->
numOfRows
==
0
))
{
(
pRes1
->
numOfRows
==
0
))
{
hasData
=
false
;
hasData
=
false
;
break
;
break
;
...
@@ -477,7 +482,6 @@ static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) {
...
@@ -477,7 +482,6 @@ static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) {
}
}
static
void
**
tscJoinResultsetFromBuf
(
SSqlObj
*
pSql
)
{
static
void
**
tscJoinResultsetFromBuf
(
SSqlObj
*
pSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
while
(
1
)
{
while
(
1
)
{
...
@@ -499,8 +503,10 @@ static void **tscJoinResultsetFromBuf(SSqlObj *pSql) {
...
@@ -499,8 +503,10 @@ static void **tscJoinResultsetFromBuf(SSqlObj *pSql) {
return
NULL
;
return
NULL
;
}
}
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
if
(
pRes
->
tsrow
==
NULL
)
{
if
(
pRes
->
tsrow
==
NULL
)
{
pRes
->
tsrow
=
malloc
(
POINTER_BYTES
*
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
.
numOfExprs
);
pRes
->
tsrow
=
malloc
(
POINTER_BYTES
*
p
QueryInfo
->
exprsInfo
.
numOfExprs
);
}
}
bool
success
=
false
;
bool
success
=
false
;
...
@@ -526,7 +532,7 @@ static void **tscJoinResultsetFromBuf(SSqlObj *pSql) {
...
@@ -526,7 +532,7 @@ static void **tscJoinResultsetFromBuf(SSqlObj *pSql) {
}
}
if
(
success
)
{
// current row of final output has been built, return to app
if
(
success
)
{
// current row of final output has been built, return to app
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
.
numOfExprs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
int32_t
tableIndex
=
pRes
->
pColumnIndex
[
i
].
tableIndex
;
int32_t
tableIndex
=
pRes
->
pColumnIndex
[
i
].
tableIndex
;
int32_t
columnIndex
=
pRes
->
pColumnIndex
[
i
].
columnIndex
;
int32_t
columnIndex
=
pRes
->
pColumnIndex
[
i
].
columnIndex
;
...
@@ -599,8 +605,11 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
...
@@ -599,8 +605,11 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
// projection query on metric, pipeline retrieve data from vnode list, instead of two-stage merge
// projection query on metric, pipeline retrieve data from vnode list, instead of two-stage merge
TAOS_ROW
rows
=
taos_fetch_row_impl
(
res
);
TAOS_ROW
rows
=
taos_fetch_row_impl
(
res
);
while
(
rows
==
NULL
&&
tscProjectionQueryOnMetric
(
pCmd
))
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
while
(
rows
==
NULL
&&
tscProjectionQueryOnMetric
(
pCmd
,
0
))
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
// reach the maximum number of output rows, abort
// reach the maximum number of output rows, abort
if
(
tscHasReachLimitation
(
pSql
))
{
if
(
tscHasReachLimitation
(
pSql
))
{
...
@@ -611,8 +620,8 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
...
@@ -611,8 +620,8 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
* update the limit and offset value according to current retrieval results
* update the limit and offset value according to current retrieval results
* Note: if pRes->offset > 0, pRes->numOfRows = 0, pRes->numOfTotal = 0;
* Note: if pRes->offset > 0, pRes->numOfRows = 0, pRes->numOfTotal = 0;
*/
*/
p
Cmd
->
p
QueryInfo
->
limit
.
limit
=
pCmd
->
globalLimit
-
pRes
->
numOfTotal
;
pQueryInfo
->
limit
.
limit
=
pCmd
->
globalLimit
-
pRes
->
numOfTotal
;
p
Cmd
->
p
QueryInfo
->
limit
.
offset
=
pRes
->
offset
;
pQueryInfo
->
limit
.
offset
=
pRes
->
offset
;
assert
((
pRes
->
offset
>=
0
&&
pRes
->
numOfRows
==
0
)
||
(
pRes
->
offset
==
0
&&
pRes
->
numOfRows
>=
0
));
assert
((
pRes
->
offset
>=
0
&&
pRes
->
numOfRows
==
0
)
||
(
pRes
->
offset
==
0
&&
pRes
->
numOfRows
>=
0
));
...
@@ -656,17 +665,19 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
...
@@ -656,17 +665,19 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
// projection query on metric, pipeline retrieve data from vnode list,
// projection query on metric, pipeline retrieve data from vnode list,
// instead of two-stage mergevnodeProcessMsgFromShell free qhandle
// instead of two-stage mergevnodeProcessMsgFromShell free qhandle
nRows
=
taos_fetch_block_impl
(
res
,
rows
);
nRows
=
taos_fetch_block_impl
(
res
,
rows
);
while
(
*
rows
==
NULL
&&
tscProjectionQueryOnMetric
(
pCmd
))
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
while
(
*
rows
==
NULL
&&
tscProjectionQueryOnMetric
(
pCmd
,
0
))
{
/* reach the maximum number of output rows, abort */
/* reach the maximum number of output rows, abort */
if
(
tscHasReachLimitation
(
pSql
))
{
if
(
tscHasReachLimitation
(
pSql
))
{
return
0
;
return
0
;
}
}
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
0
);
/* update the limit value according to current retrieval results */
/* update the limit value according to current retrieval results */
p
Cmd
->
p
QueryInfo
->
limit
.
limit
=
pSql
->
cmd
.
globalLimit
-
pRes
->
numOfTotal
;
pQueryInfo
->
limit
.
limit
=
pSql
->
cmd
.
globalLimit
-
pRes
->
numOfTotal
;
p
Cmd
->
p
QueryInfo
->
limit
.
offset
=
pRes
->
offset
;
pQueryInfo
->
limit
.
offset
=
pRes
->
offset
;
if
((
++
pMeterMetaInfo
->
vnodeIndex
)
<
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
)
{
if
((
++
pMeterMetaInfo
->
vnodeIndex
)
<
pMeterMetaInfo
->
pMetricMeta
->
numOfVnodes
)
{
pSql
->
cmd
.
command
=
TSDB_SQL_SELECT
;
pSql
->
cmd
.
command
=
TSDB_SQL_SELECT
;
...
@@ -723,9 +734,10 @@ void taos_free_result(TAOS_RES *res) {
...
@@ -723,9 +734,10 @@ void taos_free_result(TAOS_RES *res) {
}
}
// set freeFlag to 1 in retrieve message if there are un-retrieved results
// set freeFlag to 1 in retrieve message if there are un-retrieved results
pCmd
->
type
=
TSDB_QUERY_TYPE_FREE_RESOURCE
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
pQueryInfo
->
type
=
TSDB_QUERY_TYPE_FREE_RESOURCE
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
0
);
/*
/*
* case 1. Partial data have been retrieved from vnodes, but not all data has been retrieved yet.
* case 1. Partial data have been retrieved from vnodes, but not all data has been retrieved yet.
...
@@ -971,7 +983,6 @@ int taos_validate_sql(TAOS *taos, const char *sql) {
...
@@ -971,7 +983,6 @@ int taos_validate_sql(TAOS *taos, const char *sql) {
static
int
tscParseTblNameList
(
SSqlObj
*
pSql
,
const
char
*
tblNameList
,
int32_t
tblListLen
)
{
static
int
tscParseTblNameList
(
SSqlObj
*
pSql
,
const
char
*
tblNameList
,
int32_t
tblListLen
)
{
// must before clean the sqlcmd object
// must before clean the sqlcmd object
tscRemoveAllMeterMetaInfo
(
&
pSql
->
cmd
,
false
);
tscCleanSqlCmd
(
&
pSql
->
cmd
);
tscCleanSqlCmd
(
&
pSql
->
cmd
);
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
...
@@ -982,7 +993,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
...
@@ -982,7 +993,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
int
code
=
TSDB_CODE_INVALID_METER_ID
;
int
code
=
TSDB_CODE_INVALID_METER_ID
;
char
*
str
=
(
char
*
)
tblNameList
;
char
*
str
=
(
char
*
)
tblNameList
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscAddEmptyMeterMetaInfo
(
pCmd
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscAddEmptyMeterMetaInfo
(
pCmd
,
0
);
if
((
code
=
tscAllocPayload
(
pCmd
,
tblListLen
+
16
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
tscAllocPayload
(
pCmd
,
tblListLen
+
16
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
...
@@ -1017,7 +1028,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
...
@@ -1017,7 +1028,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
return
code
;
return
code
;
}
}
if
((
code
=
setMeterID
(
pSql
,
&
sToken
,
0
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
setMeterID
(
pSql
,
0
,
&
sToken
,
0
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
}
}
...
...
src/client/src/tscStream.c
浏览文件 @
e15aa9b1
...
@@ -31,9 +31,9 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
...
@@ -31,9 +31,9 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
static
void
tscSetNextLaunchTimer
(
SSqlStream
*
pStream
,
SSqlObj
*
pSql
);
static
void
tscSetNextLaunchTimer
(
SSqlStream
*
pStream
,
SSqlObj
*
pSql
);
static
void
tscSetRetryTimer
(
SSqlStream
*
pStream
,
SSqlObj
*
pSql
,
int64_t
timer
);
static
void
tscSetRetryTimer
(
SSqlStream
*
pStream
,
SSqlObj
*
pSql
,
int64_t
timer
);
static
bool
isProjectStream
(
S
SqlCmd
*
pCmd
)
{
static
bool
isProjectStream
(
S
QueryInfo
*
pQueryInfo
)
{
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
i
);
if
(
pExpr
->
functionId
!=
TSDB_FUNC_PRJ
)
{
if
(
pExpr
->
functionId
!=
TSDB_FUNC_PRJ
)
{
return
false
;
return
false
;
}
}
...
@@ -66,21 +66,23 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) {
...
@@ -66,21 +66,23 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) {
pSql
->
fp
=
tscProcessStreamQueryCallback
;
pSql
->
fp
=
tscProcessStreamQueryCallback
;
pSql
->
param
=
pStream
;
pSql
->
param
=
pStream
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
int
code
=
tscGetMeterMeta
(
pSql
,
pMeterMetaInfo
->
name
,
0
);
int
code
=
tscGetMeterMeta
(
pSql
,
pMeterMetaInfo
->
name
,
0
);
pSql
->
res
.
code
=
code
;
pSql
->
res
.
code
=
code
;
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
return
;
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
return
;
if
(
code
==
0
&&
UTIL_METER_IS_
METRIC
(
pMeterMetaInfo
))
{
if
(
code
==
0
&&
UTIL_METER_IS_
SUPERTABLE
(
pMeterMetaInfo
))
{
code
=
tscGetMetricMeta
(
pSql
);
code
=
tscGetMetricMeta
(
pSql
);
pSql
->
res
.
code
=
code
;
pSql
->
res
.
code
=
code
;
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
return
;
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
return
;
}
}
tscTansformSQLFunctionForMetricQuery
(
&
pSql
->
cmd
);
tscTansformSQLFunctionForMetricQuery
(
pQueryInfo
);
// failed to get meter/metric meta, retry in 10sec.
// failed to get meter/metric meta, retry in 10sec.
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
@@ -105,22 +107,23 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) {
...
@@ -105,22 +107,23 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) {
pStream
->
numOfRes
=
0
;
// reset the numOfRes.
pStream
->
numOfRes
=
0
;
// reset the numOfRes.
SSqlObj
*
pSql
=
pStream
->
pSql
;
SSqlObj
*
pSql
=
pStream
->
pSql
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
tscTrace
(
"%p add into timer"
,
pSql
);
tscTrace
(
"%p add into timer"
,
pSql
);
if
(
isProjectStream
(
&
pSql
->
cmd
))
{
if
(
isProjectStream
(
pQueryInfo
))
{
/*
/*
* p
Sql->cmd.pQueryInfo[0].
etime, which is the start time, does not change in case of
* p
QueryInfo->
etime, which is the start time, does not change in case of
* repeat first execution, once the first execution failed.
* repeat first execution, once the first execution failed.
*/
*/
p
Sql
->
cmd
.
pQueryInfo
[
0
].
stime
=
pStream
->
stime
;
// start time
p
QueryInfo
->
stime
=
pStream
->
stime
;
// start time
p
Sql
->
cmd
.
pQueryInfo
[
0
].
etime
=
taosGetTimestamp
(
pStream
->
precision
);
// end time
p
QueryInfo
->
etime
=
taosGetTimestamp
(
pStream
->
precision
);
// end time
if
(
p
Sql
->
cmd
.
pQueryInfo
[
0
].
etime
>
pStream
->
etime
)
{
if
(
p
QueryInfo
->
etime
>
pStream
->
etime
)
{
p
Sql
->
cmd
.
pQueryInfo
[
0
].
etime
=
pStream
->
etime
;
p
QueryInfo
->
etime
=
pStream
->
etime
;
}
}
}
else
{
}
else
{
p
Sql
->
cmd
.
pQueryInfo
[
0
].
stime
=
pStream
->
stime
-
pStream
->
interval
;
p
QueryInfo
->
stime
=
pStream
->
stime
-
pStream
->
interval
;
p
Sql
->
cmd
.
pQueryInfo
[
0
].
etime
=
pStream
->
stime
-
1
;
p
QueryInfo
->
etime
=
pStream
->
stime
-
1
;
}
}
// launch stream computing in a new thread
// launch stream computing in a new thread
...
@@ -139,7 +142,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
...
@@ -139,7 +142,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
tscError
(
"%p stream:%p, query data failed, code:%d, retry in %"
PRId64
"ms"
,
pStream
->
pSql
,
pStream
,
numOfRows
,
tscError
(
"%p stream:%p, query data failed, code:%d, retry in %"
PRId64
"ms"
,
pStream
->
pSql
,
pStream
,
numOfRows
,
retryDelay
);
retryDelay
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pStream
->
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pStream
->
pSql
->
cmd
,
0
,
0
);
tscClearMeterMetaInfo
(
pMeterMetaInfo
,
true
);
tscClearMeterMetaInfo
(
pMeterMetaInfo
,
true
);
tscSetRetryTimer
(
pStream
,
pStream
->
pSql
,
retryDelay
);
tscSetRetryTimer
(
pStream
,
pStream
->
pSql
,
retryDelay
);
...
@@ -165,7 +168,7 @@ static void tscSetTimestampForRes(SSqlStream *pStream, SSqlObj *pSql) {
...
@@ -165,7 +168,7 @@ static void tscSetTimestampForRes(SSqlStream *pStream, SSqlObj *pSql) {
static
void
tscProcessStreamRetrieveResult
(
void
*
param
,
TAOS_RES
*
res
,
int
numOfRows
)
{
static
void
tscProcessStreamRetrieveResult
(
void
*
param
,
TAOS_RES
*
res
,
int
numOfRows
)
{
SSqlStream
*
pStream
=
(
SSqlStream
*
)
param
;
SSqlStream
*
pStream
=
(
SSqlStream
*
)
param
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
res
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
res
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
if
(
pSql
==
NULL
||
numOfRows
<
0
)
{
if
(
pSql
==
NULL
||
numOfRows
<
0
)
{
int64_t
retryDelayTime
=
tscGetRetryDelayTime
(
pStream
->
slidingTime
,
pStream
->
precision
);
int64_t
retryDelayTime
=
tscGetRetryDelayTime
(
pStream
->
slidingTime
,
pStream
->
precision
);
...
@@ -178,11 +181,12 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
...
@@ -178,11 +181,12 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
if
(
numOfRows
>
0
)
{
// when reaching here the first execution of stream computing is successful.
if
(
numOfRows
>
0
)
{
// when reaching here the first execution of stream computing is successful.
pStream
->
numOfRes
+=
numOfRows
;
pStream
->
numOfRes
+=
numOfRows
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
TAOS_ROW
row
=
taos_fetch_row
(
res
);
TAOS_ROW
row
=
taos_fetch_row
(
res
);
tscTrace
(
"%p stream:%p fetch result"
,
pSql
,
pStream
);
tscTrace
(
"%p stream:%p fetch result"
,
pSql
,
pStream
);
if
(
isProjectStream
(
&
pSql
->
cmd
))
{
if
(
isProjectStream
(
pQueryInfo
))
{
pStream
->
stime
=
*
(
TSKEY
*
)
row
[
0
];
pStream
->
stime
=
*
(
TSKEY
*
)
row
[
0
];
}
else
{
}
else
{
tscSetTimestampForRes
(
pStream
,
pSql
);
tscSetTimestampForRes
(
pStream
,
pSql
);
...
@@ -197,9 +201,10 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
...
@@ -197,9 +201,10 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
}
else
{
// numOfRows == 0, all data has been retrieved
}
else
{
// numOfRows == 0, all data has been retrieved
pStream
->
useconds
+=
pSql
->
res
.
useconds
;
pStream
->
useconds
+=
pSql
->
res
.
useconds
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
if
(
pStream
->
numOfRes
==
0
)
{
if
(
pStream
->
numOfRes
==
0
)
{
if
(
pSql
->
cmd
.
pQueryInfo
[
0
].
interpoType
==
TSDB_INTERPO_SET_VALUE
||
pSql
->
cmd
.
pQueryInfo
[
0
].
interpoType
==
TSDB_INTERPO_NULL
)
{
if
(
pQueryInfo
->
interpoType
==
TSDB_INTERPO_SET_VALUE
||
pQueryInfo
->
interpoType
==
TSDB_INTERPO_NULL
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
/* failed to retrieve any result in this retrieve */
/* failed to retrieve any result in this retrieve */
...
@@ -210,11 +215,11 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
...
@@ -210,11 +215,11 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
void
*
oldPtr
=
pSql
->
res
.
data
;
void
*
oldPtr
=
pSql
->
res
.
data
;
pSql
->
res
.
data
=
tmpRes
;
pSql
->
res
.
data
=
tmpRes
;
for
(
int32_t
i
=
1
;
i
<
p
Sql
->
cmd
.
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
1
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
int16_t
offset
=
tscFieldInfoGetOffset
(
p
Cmd
,
i
);
int16_t
offset
=
tscFieldInfoGetOffset
(
p
QueryInfo
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
i
);
assignVal
(
pSql
->
res
.
data
+
offset
,
(
char
*
)(
&
p
Cmd
->
pQueryInfo
[
0
].
defaultVal
[
i
]),
pField
->
bytes
,
pField
->
type
);
assignVal
(
pSql
->
res
.
data
+
offset
,
(
char
*
)(
&
p
QueryInfo
->
defaultVal
[
i
]),
pField
->
bytes
,
pField
->
type
);
row
[
i
]
=
pSql
->
res
.
data
+
offset
;
row
[
i
]
=
pSql
->
res
.
data
+
offset
;
}
}
...
@@ -222,7 +227,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
...
@@ -222,7 +227,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
row
[
0
]
=
pRes
->
data
;
row
[
0
]
=
pRes
->
data
;
// char result[512] = {0};
// char result[512] = {0};
// taos_print_row(result, row, p
Sql->cmd.pQueryInfo[0].fieldsInfo.pFields, pSql->cmd.pQueryInfo[0].
fieldsInfo.numOfOutputCols);
// taos_print_row(result, row, p
QueryInfo->fieldsInfo.pFields, pQueryInfo->
fieldsInfo.numOfOutputCols);
// tscPrint("%p stream:%p query result: %s", pSql, pStream, result);
// tscPrint("%p stream:%p query result: %s", pSql, pStream, result);
tscTrace
(
"%p stream:%p fetch result"
,
pSql
,
pStream
);
tscTrace
(
"%p stream:%p fetch result"
,
pSql
,
pStream
);
...
@@ -231,7 +236,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
...
@@ -231,7 +236,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
pRes
->
numOfRows
=
0
;
pRes
->
numOfRows
=
0
;
pRes
->
data
=
oldPtr
;
pRes
->
data
=
oldPtr
;
}
else
if
(
isProjectStream
(
&
pSql
->
cmd
))
{
}
else
if
(
isProjectStream
(
pQueryInfo
))
{
/* no resuls in the query range, retry */
/* no resuls in the query range, retry */
// todo set retry dynamic time
// todo set retry dynamic time
int32_t
retry
=
tsProjectExecInterval
;
int32_t
retry
=
tsProjectExecInterval
;
...
@@ -242,7 +247,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
...
@@ -242,7 +247,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
return
;
return
;
}
}
}
else
{
}
else
{
if
(
isProjectStream
(
&
pSql
->
cmd
))
{
if
(
isProjectStream
(
pQueryInfo
))
{
pStream
->
stime
+=
1
;
pStream
->
stime
+=
1
;
}
}
}
}
...
@@ -257,7 +262,9 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
...
@@ -257,7 +262,9 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
}
}
static
void
tscSetRetryTimer
(
SSqlStream
*
pStream
,
SSqlObj
*
pSql
,
int64_t
timer
)
{
static
void
tscSetRetryTimer
(
SSqlStream
*
pStream
,
SSqlObj
*
pSql
,
int64_t
timer
)
{
if
(
isProjectStream
(
&
pSql
->
cmd
))
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
if
(
isProjectStream
(
pQueryInfo
))
{
int64_t
now
=
taosGetTimestamp
(
pStream
->
precision
);
int64_t
now
=
taosGetTimestamp
(
pStream
->
precision
);
int64_t
etime
=
now
>
pStream
->
etime
?
pStream
->
etime
:
now
;
int64_t
etime
=
now
>
pStream
->
etime
?
pStream
->
etime
:
now
;
...
@@ -292,7 +299,8 @@ static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer)
...
@@ -292,7 +299,8 @@ static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer)
static
void
tscSetNextLaunchTimer
(
SSqlStream
*
pStream
,
SSqlObj
*
pSql
)
{
static
void
tscSetNextLaunchTimer
(
SSqlStream
*
pStream
,
SSqlObj
*
pSql
)
{
int64_t
timer
=
0
;
int64_t
timer
=
0
;
if
(
isProjectStream
(
&
pSql
->
cmd
))
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
if
(
isProjectStream
(
pQueryInfo
))
{
/*
/*
* for project query, no mater fetch data successfully or not, next launch will issue
* for project query, no mater fetch data successfully or not, next launch will issue
* more than the sliding time window
* more than the sliding time window
...
@@ -348,55 +356,56 @@ static void tscSetNextLaunchTimer(SSqlStream *pStream, SSqlObj *pSql) {
...
@@ -348,55 +356,56 @@ static void tscSetNextLaunchTimer(SSqlStream *pStream, SSqlObj *pSql) {
}
}
static
void
tscSetSlidingWindowInfo
(
SSqlObj
*
pSql
,
SSqlStream
*
pStream
)
{
static
void
tscSetSlidingWindowInfo
(
SSqlObj
*
pSql
,
SSqlStream
*
pStream
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
int64_t
minIntervalTime
=
int64_t
minIntervalTime
=
(
pStream
->
precision
==
TSDB_TIME_PRECISION_MICRO
)
?
tsMinIntervalTime
*
1000L
:
tsMinIntervalTime
;
(
pStream
->
precision
==
TSDB_TIME_PRECISION_MICRO
)
?
tsMinIntervalTime
*
1000L
:
tsMinIntervalTime
;
if
(
pCmd
->
pQueryInfo
[
0
].
nAggTimeInterval
<
minIntervalTime
)
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
if
(
pQueryInfo
->
nAggTimeInterval
<
minIntervalTime
)
{
tscWarn
(
"%p stream:%p, original sample interval:%ld too small, reset to:%"
PRId64
""
,
pSql
,
pStream
,
tscWarn
(
"%p stream:%p, original sample interval:%ld too small, reset to:%"
PRId64
""
,
pSql
,
pStream
,
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
,
minIntervalTime
);
p
QueryInfo
->
nAggTimeInterval
,
minIntervalTime
);
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
=
minIntervalTime
;
p
QueryInfo
->
nAggTimeInterval
=
minIntervalTime
;
}
}
pStream
->
interval
=
p
Cmd
->
pQueryInfo
[
0
].
nAggTimeInterval
;
// it shall be derived from sql string
pStream
->
interval
=
p
QueryInfo
->
nAggTimeInterval
;
// it shall be derived from sql string
if
(
p
Cmd
->
pQueryInfo
[
0
].
nSlidingTime
==
0
)
{
if
(
p
QueryInfo
->
nSlidingTime
==
0
)
{
p
Cmd
->
pQueryInfo
[
0
].
nSlidingTime
=
pCmd
->
pQueryInfo
[
0
].
nAggTimeInterval
;
p
QueryInfo
->
nSlidingTime
=
pQueryInfo
->
nAggTimeInterval
;
}
}
int64_t
minSlidingTime
=
int64_t
minSlidingTime
=
(
pStream
->
precision
==
TSDB_TIME_PRECISION_MICRO
)
?
tsMinSlidingTime
*
1000L
:
tsMinSlidingTime
;
(
pStream
->
precision
==
TSDB_TIME_PRECISION_MICRO
)
?
tsMinSlidingTime
*
1000L
:
tsMinSlidingTime
;
if
(
p
Cmd
->
pQueryInfo
[
0
].
nSlidingTime
<
minSlidingTime
)
{
if
(
p
QueryInfo
->
nSlidingTime
<
minSlidingTime
)
{
tscWarn
(
"%p stream:%p, original sliding value:%"
PRId64
" too small, reset to:%"
PRId64
""
,
pSql
,
pStream
,
tscWarn
(
"%p stream:%p, original sliding value:%"
PRId64
" too small, reset to:%"
PRId64
""
,
pSql
,
pStream
,
p
Cmd
->
pQueryInfo
[
0
].
nSlidingTime
,
minSlidingTime
);
p
QueryInfo
->
nSlidingTime
,
minSlidingTime
);
p
Cmd
->
pQueryInfo
[
0
].
nSlidingTime
=
minSlidingTime
;
p
QueryInfo
->
nSlidingTime
=
minSlidingTime
;
}
}
if
(
p
Cmd
->
pQueryInfo
[
0
].
nSlidingTime
>
pCmd
->
pQueryInfo
[
0
].
nAggTimeInterval
)
{
if
(
p
QueryInfo
->
nSlidingTime
>
pQueryInfo
->
nAggTimeInterval
)
{
tscWarn
(
"%p stream:%p, sliding value:%"
PRId64
" can not be larger than interval range, reset to:%"
PRId64
""
,
pSql
,
pStream
,
tscWarn
(
"%p stream:%p, sliding value:%"
PRId64
" can not be larger than interval range, reset to:%"
PRId64
""
,
pSql
,
pStream
,
p
Cmd
->
pQueryInfo
[
0
].
nSlidingTime
,
pCmd
->
pQueryInfo
[
0
].
nAggTimeInterval
);
p
QueryInfo
->
nSlidingTime
,
pQueryInfo
->
nAggTimeInterval
);
p
Cmd
->
pQueryInfo
[
0
].
nSlidingTime
=
pCmd
->
pQueryInfo
[
0
].
nAggTimeInterval
;
p
QueryInfo
->
nSlidingTime
=
pQueryInfo
->
nAggTimeInterval
;
}
}
pStream
->
slidingTime
=
p
Cmd
->
pQueryInfo
[
0
].
nSlidingTime
;
pStream
->
slidingTime
=
p
QueryInfo
->
nSlidingTime
;
}
}
static
int64_t
tscGetStreamStartTimestamp
(
SSqlObj
*
pSql
,
SSqlStream
*
pStream
,
int64_t
stime
)
{
static
int64_t
tscGetStreamStartTimestamp
(
SSqlObj
*
pSql
,
SSqlStream
*
pStream
,
int64_t
stime
)
{
S
SqlCmd
*
pCmd
=
&
pSql
->
cmd
;
S
QueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
)
;
if
(
isProjectStream
(
p
Cmd
))
{
if
(
isProjectStream
(
p
QueryInfo
))
{
// no data in table, flush all data till now to destination meter, 10sec delay
// no data in table, flush all data till now to destination meter, 10sec delay
pStream
->
interval
=
tsProjectExecInterval
;
pStream
->
interval
=
tsProjectExecInterval
;
pStream
->
slidingTime
=
tsProjectExecInterval
;
pStream
->
slidingTime
=
tsProjectExecInterval
;
if
(
stime
!=
0
)
{
// first projection start from the latest event timestamp
if
(
stime
!=
0
)
{
// first projection start from the latest event timestamp
assert
(
stime
>=
p
Cmd
->
pQueryInfo
[
0
].
stime
);
assert
(
stime
>=
p
QueryInfo
->
stime
);
stime
+=
1
;
// exclude the last records from table
stime
+=
1
;
// exclude the last records from table
}
else
{
}
else
{
stime
=
p
Cmd
->
pQueryInfo
[
0
].
stime
;
stime
=
p
QueryInfo
->
stime
;
}
}
}
else
{
// timewindow based aggregation stream
}
else
{
// timewindow based aggregation stream
if
(
stime
==
0
)
{
// no data in meter till now
if
(
stime
==
0
)
{
// no data in meter till now
...
@@ -520,7 +529,8 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
...
@@ -520,7 +529,8 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
return
NULL
;
return
NULL
;
}
}
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
pStream
->
fp
=
fp
;
pStream
->
fp
=
fp
;
pStream
->
callback
=
callback
;
pStream
->
callback
=
callback
;
...
@@ -529,7 +539,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
...
@@ -529,7 +539,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
pStream
->
precision
=
pMeterMetaInfo
->
pMeterMeta
->
precision
;
pStream
->
precision
=
pMeterMetaInfo
->
pMeterMeta
->
precision
;
pStream
->
ctime
=
taosGetTimestamp
(
pStream
->
precision
);
pStream
->
ctime
=
taosGetTimestamp
(
pStream
->
precision
);
pStream
->
etime
=
p
Cmd
->
pQueryInfo
[
0
].
etime
;
pStream
->
etime
=
p
QueryInfo
->
etime
;
pSql
->
pStream
=
pStream
;
pSql
->
pStream
=
pStream
;
tscAddIntoStreamList
(
pStream
);
tscAddIntoStreamList
(
pStream
);
...
...
src/client/src/tscUtil.c
浏览文件 @
e15aa9b1
...
@@ -37,9 +37,12 @@
...
@@ -37,9 +37,12 @@
* fullmetername + '.' + '(nil)' + '.' + '(nil)' + relation + '.' + [tagId1,
* fullmetername + '.' + '(nil)' + '.' + '(nil)' + relation + '.' + [tagId1,
* tagId2,...] + '.' + group_orderType
* tagId2,...] + '.' + group_orderType
*/
*/
void
tscGetMetricMetaCacheKey
(
SSqlCmd
*
pCmd
,
char
*
str
,
uint64_t
uid
)
{
void
tscGetMetricMetaCacheKey
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
,
char
*
str
,
uint64_t
uid
)
{
int32_t
index
=
-
1
;
int32_t
index
=
-
1
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoByUid
(
pCmd
,
uid
,
&
index
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoByUid
(
pQueryInfo
,
subClauseIndex
,
uid
,
&
index
);
int32_t
len
=
0
;
int32_t
len
=
0
;
char
tagIdBuf
[
128
]
=
{
0
};
char
tagIdBuf
[
128
]
=
{
0
};
...
@@ -47,7 +50,7 @@ void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* str, uint64_t uid) {
...
@@ -47,7 +50,7 @@ void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* str, uint64_t uid) {
len
+=
sprintf
(
&
tagIdBuf
[
len
],
"%d,"
,
pMeterMetaInfo
->
tagColumnIndex
[
i
]);
len
+=
sprintf
(
&
tagIdBuf
[
len
],
"%d,"
,
pMeterMetaInfo
->
tagColumnIndex
[
i
]);
}
}
STagCond
*
pTagCond
=
&
p
Cmd
->
pQueryInfo
[
0
].
tagCond
;
STagCond
*
pTagCond
=
&
p
QueryInfo
->
tagCond
;
assert
(
len
<
tListLen
(
tagIdBuf
));
assert
(
len
<
tListLen
(
tagIdBuf
));
const
int32_t
maxKeySize
=
TSDB_MAX_TAGS_LEN
;
// allowed max key size
const
int32_t
maxKeySize
=
TSDB_MAX_TAGS_LEN
;
// allowed max key size
...
@@ -73,7 +76,7 @@ void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* str, uint64_t uid) {
...
@@ -73,7 +76,7 @@ void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* str, uint64_t uid) {
int32_t
keyLen
=
snprintf
(
tmp
,
bufSize
,
"%s,%s,%s,%d,%s,[%s],%d"
,
pMeterMetaInfo
->
name
,
int32_t
keyLen
=
snprintf
(
tmp
,
bufSize
,
"%s,%s,%s,%d,%s,[%s],%d"
,
pMeterMetaInfo
->
name
,
(
cond
!=
NULL
?
cond
->
cond
:
NULL
),
(
tbnameCondLen
>
0
?
pTagCond
->
tbnameCond
.
cond
:
NULL
),
(
cond
!=
NULL
?
cond
->
cond
:
NULL
),
(
tbnameCondLen
>
0
?
pTagCond
->
tbnameCond
.
cond
:
NULL
),
pTagCond
->
relType
,
join
,
tagIdBuf
,
p
Cmd
->
pQueryInfo
[
0
].
groupbyExpr
.
orderType
);
pTagCond
->
relType
,
join
,
tagIdBuf
,
p
QueryInfo
->
groupbyExpr
.
orderType
);
assert
(
keyLen
<=
bufSize
);
assert
(
keyLen
<=
bufSize
);
...
@@ -115,13 +118,15 @@ void tsSetMetricQueryCond(STagCond* pTagCond, uint64_t uid, const char* str) {
...
@@ -115,13 +118,15 @@ void tsSetMetricQueryCond(STagCond* pTagCond, uint64_t uid, const char* str) {
}
}
bool
tscQueryOnMetric
(
SSqlCmd
*
pCmd
)
{
bool
tscQueryOnMetric
(
SSqlCmd
*
pCmd
)
{
return
((
pCmd
->
type
&
TSDB_QUERY_TYPE_STABLE_QUERY
)
==
TSDB_QUERY_TYPE_STABLE_QUERY
)
&&
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
return
((
pQueryInfo
->
type
&
TSDB_QUERY_TYPE_STABLE_QUERY
)
==
TSDB_QUERY_TYPE_STABLE_QUERY
)
&&
(
pCmd
->
msgType
==
TSDB_MSG_TYPE_QUERY
);
(
pCmd
->
msgType
==
TSDB_MSG_TYPE_QUERY
);
}
}
bool
tscQueryMetricTags
(
S
SqlCmd
*
pCmd
)
{
bool
tscQueryMetricTags
(
S
QueryInfo
*
pQueryInfo
)
{
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
if
(
tscSqlExprGet
(
p
Cmd
,
i
)
->
functionId
!=
TSDB_FUNC_TAGPRJ
)
{
if
(
tscSqlExprGet
(
p
QueryInfo
,
i
)
->
functionId
!=
TSDB_FUNC_TAGPRJ
)
{
return
false
;
return
false
;
}
}
}
}
...
@@ -133,8 +138,10 @@ bool tscIsSelectivityWithTagQuery(SSqlCmd* pCmd) {
...
@@ -133,8 +138,10 @@ bool tscIsSelectivityWithTagQuery(SSqlCmd* pCmd) {
bool
hasTags
=
false
;
bool
hasTags
=
false
;
int32_t
numOfSelectivity
=
0
;
int32_t
numOfSelectivity
=
0
;
for
(
int32_t
i
=
0
;
i
<
pCmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
int32_t
functId
=
tscSqlExprGet
(
pCmd
,
i
)
->
functionId
;
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
int32_t
functId
=
tscSqlExprGet
(
pQueryInfo
,
i
)
->
functionId
;
if
(
functId
==
TSDB_FUNC_TAG_DUMMY
)
{
if
(
functId
==
TSDB_FUNC_TAG_DUMMY
)
{
hasTags
=
true
;
hasTags
=
true
;
continue
;
continue
;
...
@@ -204,46 +211,53 @@ SMeterSidExtInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx) {
...
@@ -204,46 +211,53 @@ SMeterSidExtInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx) {
bool
tscIsTwoStageMergeMetricQuery
(
SSqlCmd
*
pCmd
)
{
bool
tscIsTwoStageMergeMetricQuery
(
SSqlCmd
*
pCmd
)
{
assert
(
pCmd
!=
NULL
);
assert
(
pCmd
!=
NULL
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
int32_t
subClauseIndex
=
0
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
subClauseIndex
);
if
(
pQueryInfo
==
NULL
)
{
return
false
;
}
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
if
(
pMeterMetaInfo
==
NULL
||
pMeterMetaInfo
->
pMetricMeta
==
NULL
)
{
if
(
pMeterMetaInfo
==
NULL
||
pMeterMetaInfo
->
pMetricMeta
==
NULL
)
{
return
false
;
return
false
;
}
}
// for projection query, iterate all qualified vnodes sequentially
// for projection query, iterate all qualified vnodes sequentially
if
(
tscProjectionQueryOnMetric
(
pCmd
))
{
if
(
tscProjectionQueryOnMetric
(
pCmd
,
subClauseIndex
))
{
return
false
;
return
false
;
}
}
if
(((
p
Cmd
->
type
&
TSDB_QUERY_TYPE_STABLE_SUBQUERY
)
!=
TSDB_QUERY_TYPE_STABLE_SUBQUERY
)
&&
if
(((
p
QueryInfo
->
type
&
TSDB_QUERY_TYPE_STABLE_SUBQUERY
)
!=
TSDB_QUERY_TYPE_STABLE_SUBQUERY
)
&&
pCmd
->
command
==
TSDB_SQL_SELECT
)
{
pCmd
->
command
==
TSDB_SQL_SELECT
)
{
return
UTIL_METER_IS_
METRIC
(
pMeterMetaInfo
);
return
UTIL_METER_IS_
SUPERTABLE
(
pMeterMetaInfo
);
}
}
return
false
;
return
false
;
}
}
bool
tscProjectionQueryOnMetric
(
SSqlCmd
*
pCmd
)
{
bool
tscProjectionQueryOnMetric
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
)
{
assert
(
pCmd
!=
NULL
);
assert
(
pCmd
!=
NULL
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
subClauseIndex
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
/*
/*
* In following cases, return false for project query on metric
* In following cases, return false for project query on metric
* 1. failed to get metermeta from server; 2. not a metric; 3. limit 0; 4. show query, instead of a select query
* 1. failed to get metermeta from server; 2. not a metric; 3. limit 0; 4. show query, instead of a select query
*/
*/
if
(
pMeterMetaInfo
==
NULL
||
!
UTIL_METER_IS_
METRIC
(
pMeterMetaInfo
)
||
if
(
pMeterMetaInfo
==
NULL
||
!
UTIL_METER_IS_
SUPERTABLE
(
pMeterMetaInfo
)
||
pCmd
->
command
==
TSDB_SQL_RETRIEVE_EMPTY_RESULT
||
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
.
numOfExprs
==
0
)
{
pCmd
->
command
==
TSDB_SQL_RETRIEVE_EMPTY_RESULT
||
p
QueryInfo
->
exprsInfo
.
numOfExprs
==
0
)
{
return
false
;
return
false
;
}
}
// only query on tag, not a projection query
// only query on tag, not a projection query
if
(
tscQueryMetricTags
(
p
Cmd
))
{
if
(
tscQueryMetricTags
(
p
QueryInfo
))
{
return
false
;
return
false
;
}
}
// for project query, only the following two function is allowed
// for project query, only the following two function is allowed
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
int32_t
functionId
=
tscSqlExprGet
(
p
Cmd
,
i
)
->
functionId
;
int32_t
functionId
=
tscSqlExprGet
(
p
QueryInfo
,
i
)
->
functionId
;
if
(
functionId
!=
TSDB_FUNC_PRJ
&&
functionId
!=
TSDB_FUNC_TAGPRJ
&&
functionId
!=
TSDB_FUNC_TAG
&&
if
(
functionId
!=
TSDB_FUNC_PRJ
&&
functionId
!=
TSDB_FUNC_TAGPRJ
&&
functionId
!=
TSDB_FUNC_TAG
&&
functionId
!=
TSDB_FUNC_TS
&&
functionId
!=
TSDB_FUNC_ARITHM
)
{
functionId
!=
TSDB_FUNC_TS
&&
functionId
!=
TSDB_FUNC_ARITHM
)
{
return
false
;
return
false
;
...
@@ -253,9 +267,9 @@ bool tscProjectionQueryOnMetric(SSqlCmd* pCmd) {
...
@@ -253,9 +267,9 @@ bool tscProjectionQueryOnMetric(SSqlCmd* pCmd) {
return
true
;
return
true
;
}
}
bool
tscProjectionQueryOnTable
(
S
SqlCmd
*
pCmd
)
{
bool
tscProjectionQueryOnTable
(
S
QueryInfo
*
pQueryInfo
)
{
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
int32_t
functionId
=
tscSqlExprGet
(
p
Cmd
,
i
)
->
functionId
;
int32_t
functionId
=
tscSqlExprGet
(
p
QueryInfo
,
i
)
->
functionId
;
if
(
functionId
!=
TSDB_FUNC_PRJ
&&
functionId
!=
TSDB_FUNC_TS
)
{
if
(
functionId
!=
TSDB_FUNC_PRJ
&&
functionId
!=
TSDB_FUNC_TS
)
{
return
false
;
return
false
;
}
}
...
@@ -264,9 +278,9 @@ bool tscProjectionQueryOnTable(SSqlCmd* pCmd) {
...
@@ -264,9 +278,9 @@ bool tscProjectionQueryOnTable(SSqlCmd* pCmd) {
return
true
;
return
true
;
}
}
bool
tscIsPointInterpQuery
(
S
SqlCmd
*
pCmd
)
{
bool
tscIsPointInterpQuery
(
S
QueryInfo
*
pQueryInfo
)
{
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
.
numOfExprs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
i
);
if
(
pExpr
==
NULL
)
{
if
(
pExpr
==
NULL
)
{
return
false
;
return
false
;
}
}
...
@@ -283,9 +297,9 @@ bool tscIsPointInterpQuery(SSqlCmd* pCmd) {
...
@@ -283,9 +297,9 @@ bool tscIsPointInterpQuery(SSqlCmd* pCmd) {
return
true
;
return
true
;
}
}
bool
tscIsTWAQuery
(
S
SqlCmd
*
pCmd
)
{
bool
tscIsTWAQuery
(
S
QueryInfo
*
pQueryInfo
)
{
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
.
numOfExprs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
i
);
if
(
pExpr
==
NULL
)
{
if
(
pExpr
==
NULL
)
{
continue
;
continue
;
}
}
...
@@ -299,30 +313,28 @@ bool tscIsTWAQuery(SSqlCmd* pCmd) {
...
@@ -299,30 +313,28 @@ bool tscIsTWAQuery(SSqlCmd* pCmd) {
return
false
;
return
false
;
}
}
void
tscClearInterpInfo
(
S
SqlCmd
*
pCmd
)
{
void
tscClearInterpInfo
(
S
QueryInfo
*
pQueryInfo
)
{
if
(
!
tscIsPointInterpQuery
(
p
Cmd
))
{
if
(
!
tscIsPointInterpQuery
(
p
QueryInfo
))
{
return
;
return
;
}
}
p
Cmd
->
pQueryInfo
[
0
].
interpoType
=
TSDB_INTERPO_NONE
;
p
QueryInfo
->
interpoType
=
TSDB_INTERPO_NONE
;
memset
(
p
Cmd
->
pQueryInfo
[
0
].
defaultVal
,
0
,
sizeof
(
pCmd
->
pQueryInfo
[
0
].
defaultVal
));
memset
(
p
QueryInfo
->
defaultVal
,
0
,
sizeof
(
pQueryInfo
->
defaultVal
));
}
}
void
tscClearSqlMetaInfoForce
(
SSqlCmd
*
pCmd
)
{
void
tscClearSqlMetaInfoForce
(
SSqlCmd
*
pCmd
)
{
/* remove the metermeta/metricmeta in cache */
/* remove the metermeta/metricmeta in cache */
// taosRemoveDataFromCache(tscCacheHandle, (void**)&(pCmd->pMeterMeta),
// taosRemoveDataFromCache(tscCacheHandle, (void**)&(pCmd->pMeterMeta), true);
// true);
// taosRemoveDataFromCache(tscCacheHandle, (void**)&(pCmd->pMetricMeta), true);
// taosRemoveDataFromCache(tscCacheHandle, (void**)&(pCmd->pMetricMeta),
// true);
}
}
int32_t
tscCreateResPointerInfo
(
S
SqlCmd
*
pCmd
,
SSqlRes
*
pRes
)
{
int32_t
tscCreateResPointerInfo
(
S
QueryInfo
*
pQueryInfo
,
SSqlRes
*
pRes
)
{
if
(
pRes
->
tsrow
==
NULL
)
{
if
(
pRes
->
tsrow
==
NULL
)
{
pRes
->
numOfnchar
=
0
;
pRes
->
numOfnchar
=
0
;
int32_t
numOfOutputCols
=
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
int32_t
numOfOutputCols
=
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
;
for
(
int32_t
i
=
0
;
i
<
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfOutputCols
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
Cmd
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
p
QueryInfo
,
i
);
if
(
pField
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
pField
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
pRes
->
numOfnchar
++
;
pRes
->
numOfnchar
++
;
}
}
...
@@ -360,24 +372,7 @@ void tscDestroyResPointerInfo(SSqlRes* pRes) {
...
@@ -360,24 +372,7 @@ void tscDestroyResPointerInfo(SSqlRes* pRes) {
void
tscFreeSqlCmdData
(
SSqlCmd
*
pCmd
)
{
void
tscFreeSqlCmdData
(
SSqlCmd
*
pCmd
)
{
pCmd
->
pDataBlocks
=
tscDestroyBlockArrayList
(
pCmd
->
pDataBlocks
);
pCmd
->
pDataBlocks
=
tscDestroyBlockArrayList
(
pCmd
->
pDataBlocks
);
tscFreeSubqueryInfo
(
pCmd
);
if
(
pCmd
->
pQueryInfo
==
NULL
)
{
return
;
}
tscTagCondRelease
(
&
pCmd
->
pQueryInfo
[
0
].
tagCond
);
tscClearFieldInfo
(
&
pCmd
->
pQueryInfo
[
0
].
fieldsInfo
);
tfree
(
pCmd
->
pQueryInfo
[
0
].
exprsInfo
.
pExprs
);
memset
(
&
pCmd
->
pQueryInfo
[
0
].
exprsInfo
,
0
,
sizeof
(
pCmd
->
pQueryInfo
[
0
].
exprsInfo
));
tscColumnBaseInfoDestroy
(
&
pCmd
->
pQueryInfo
[
0
].
colList
);
memset
(
&
pCmd
->
pQueryInfo
[
0
].
colList
,
0
,
sizeof
(
pCmd
->
pQueryInfo
[
0
].
colList
));
if
(
pCmd
->
pQueryInfo
[
0
].
tsBuf
!=
NULL
)
{
tsBufDestory
(
pCmd
->
pQueryInfo
[
0
].
tsBuf
);
pCmd
->
pQueryInfo
[
0
].
tsBuf
=
NULL
;
}
}
}
void
tscFreeSqlObjPartial
(
SSqlObj
*
pSql
)
{
void
tscFreeSqlObjPartial
(
SSqlObj
*
pSql
)
{
...
@@ -419,7 +414,6 @@ void tscFreeSqlObjPartial(SSqlObj* pSql) {
...
@@ -419,7 +414,6 @@ void tscFreeSqlObjPartial(SSqlObj* pSql) {
tfree
(
pSql
->
res
.
pColumnIndex
);
tfree
(
pSql
->
res
.
pColumnIndex
);
tscFreeSqlCmdData
(
pCmd
);
tscFreeSqlCmdData
(
pCmd
);
tscRemoveAllMeterMetaInfo
(
pCmd
,
false
);
}
}
void
tscFreeSqlObj
(
SSqlObj
*
pSql
)
{
void
tscFreeSqlObj
(
SSqlObj
*
pSql
)
{
...
@@ -438,7 +432,9 @@ void tscFreeSqlObj(SSqlObj* pSql) {
...
@@ -438,7 +432,9 @@ void tscFreeSqlObj(SSqlObj* pSql) {
pCmd
->
allocSize
=
0
;
pCmd
->
allocSize
=
0
;
if
(
pSql
->
res
.
buffer
!=
NULL
)
{
if
(
pSql
->
res
.
buffer
!=
NULL
)
{
for
(
int
i
=
0
;
i
<
pCmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
i
++
)
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
for
(
int
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
i
++
)
{
if
(
pSql
->
res
.
buffer
[
i
]
!=
NULL
)
{
if
(
pSql
->
res
.
buffer
[
i
]
!=
NULL
)
{
tfree
(
pSql
->
res
.
buffer
[
i
]);
tfree
(
pSql
->
res
.
buffer
[
i
]);
}
}
...
@@ -540,7 +536,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
...
@@ -540,7 +536,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
assert
(
pDataBlock
->
pMeterMeta
!=
NULL
);
assert
(
pDataBlock
->
pMeterMeta
!=
NULL
);
pCmd
->
count
=
pDataBlock
->
numOfMeters
;
pCmd
->
count
=
pDataBlock
->
numOfMeters
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
// set the correct metermeta object, the metermeta has been locked in pDataBlocks, so it must be in the cache
// set the correct metermeta object, the metermeta has been locked in pDataBlocks, so it must be in the cache
if
(
pMeterMetaInfo
->
pMeterMeta
!=
pDataBlock
->
pMeterMeta
)
{
if
(
pMeterMetaInfo
->
pMeterMeta
!=
pDataBlock
->
pMeterMeta
)
{
...
@@ -856,8 +852,8 @@ void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, co
...
@@ -856,8 +852,8 @@ void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, co
pFieldInfo
->
numOfOutputCols
++
;
pFieldInfo
->
numOfOutputCols
++
;
}
}
void
tscFieldInfoCalOffset
(
S
SqlCmd
*
pCmd
)
{
void
tscFieldInfoCalOffset
(
S
QueryInfo
*
pQueryInfo
)
{
SFieldInfo
*
pFieldInfo
=
&
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
;
SFieldInfo
*
pFieldInfo
=
&
p
QueryInfo
->
fieldsInfo
;
pFieldInfo
->
pOffset
[
0
]
=
0
;
pFieldInfo
->
pOffset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
pFieldInfo
->
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
1
;
i
<
pFieldInfo
->
numOfOutputCols
;
++
i
)
{
...
@@ -865,8 +861,8 @@ void tscFieldInfoCalOffset(SSqlCmd* pCmd) {
...
@@ -865,8 +861,8 @@ void tscFieldInfoCalOffset(SSqlCmd* pCmd) {
}
}
}
}
void
tscFieldInfoUpdateOffset
(
S
SqlCmd
*
pCmd
)
{
void
tscFieldInfoUpdateOffset
(
S
QueryInfo
*
pQueryInfo
)
{
SFieldInfo
*
pFieldInfo
=
&
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
;
SFieldInfo
*
pFieldInfo
=
&
p
QueryInfo
->
fieldsInfo
;
if
(
pFieldInfo
->
numOfOutputCols
==
0
)
{
if
(
pFieldInfo
->
numOfOutputCols
==
0
)
{
return
;
return
;
}
}
...
@@ -878,7 +874,7 @@ void tscFieldInfoUpdateOffset(SSqlCmd* pCmd) {
...
@@ -878,7 +874,7 @@ void tscFieldInfoUpdateOffset(SSqlCmd* pCmd) {
* for potential secondary merge exists
* for potential secondary merge exists
*/
*/
for
(
int32_t
i
=
1
;
i
<
pFieldInfo
->
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
1
;
i
<
pFieldInfo
->
numOfOutputCols
;
++
i
)
{
pFieldInfo
->
pOffset
[
i
]
=
pFieldInfo
->
pOffset
[
i
-
1
]
+
tscSqlExprGet
(
p
Cmd
,
i
-
1
)
->
resBytes
;
pFieldInfo
->
pOffset
[
i
]
=
pFieldInfo
->
pOffset
[
i
-
1
]
+
tscSqlExprGet
(
p
QueryInfo
,
i
-
1
)
->
resBytes
;
}
}
}
}
...
@@ -910,28 +906,26 @@ void tscFieldInfoCopyAll(SFieldInfo* src, SFieldInfo* dst) {
...
@@ -910,28 +906,26 @@ void tscFieldInfoCopyAll(SFieldInfo* src, SFieldInfo* dst) {
memcpy
(
dst
->
pVisibleCols
,
src
->
pVisibleCols
,
sizeof
(
bool
)
*
dst
->
numOfOutputCols
);
memcpy
(
dst
->
pVisibleCols
,
src
->
pVisibleCols
,
sizeof
(
bool
)
*
dst
->
numOfOutputCols
);
}
}
TAOS_FIELD
*
tscFieldInfoGetField
(
S
SqlCmd
*
pCmd
,
int32_t
index
)
{
TAOS_FIELD
*
tscFieldInfoGetField
(
S
QueryInfo
*
pQueryInfo
,
int32_t
index
)
{
if
(
index
>=
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
)
{
if
(
index
>=
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
)
{
return
NULL
;
return
NULL
;
}
}
return
&
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
pFields
[
index
];
return
&
p
QueryInfo
->
fieldsInfo
.
pFields
[
index
];
}
}
int32_t
tscNumOfFields
(
SSqlCmd
*
pCmd
)
{
int32_t
tscNumOfFields
(
SQueryInfo
*
pQueryInfo
)
{
return
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
}
return
pCmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
;
}
int16_t
tscFieldInfoGetOffset
(
S
SqlCmd
*
pCmd
,
int32_t
index
)
{
int16_t
tscFieldInfoGetOffset
(
S
QueryInfo
*
pQueryInfo
,
int32_t
index
)
{
if
(
index
>=
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
numOfOutputCols
)
{
if
(
index
>=
p
QueryInfo
->
fieldsInfo
.
numOfOutputCols
)
{
return
0
;
return
0
;
}
}
return
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
.
pOffset
[
index
];
return
p
QueryInfo
->
fieldsInfo
.
pOffset
[
index
];
}
}
int32_t
tscGetResRowLength
(
S
SqlCmd
*
pCmd
)
{
int32_t
tscGetResRowLength
(
S
QueryInfo
*
pQueryInfo
)
{
SFieldInfo
*
pFieldInfo
=
&
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
;
SFieldInfo
*
pFieldInfo
=
&
p
QueryInfo
->
fieldsInfo
;
if
(
pFieldInfo
->
numOfOutputCols
<=
0
)
{
if
(
pFieldInfo
->
numOfOutputCols
<=
0
)
{
return
0
;
return
0
;
}
}
...
@@ -981,8 +975,8 @@ static void _exprEvic(SSqlExprInfo* pExprInfo, int32_t index) {
...
@@ -981,8 +975,8 @@ static void _exprEvic(SSqlExprInfo* pExprInfo, int32_t index) {
}
}
}
}
SSqlExpr
*
tscSqlExprInsertEmpty
(
S
SqlCmd
*
pCmd
,
int32_t
index
,
int16_t
functionId
)
{
SSqlExpr
*
tscSqlExprInsertEmpty
(
S
QueryInfo
*
pQueryInfo
,
int32_t
index
,
int16_t
functionId
)
{
SSqlExprInfo
*
pExprInfo
=
&
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
;
SSqlExprInfo
*
pExprInfo
=
&
p
QueryInfo
->
exprsInfo
;
_exprCheckSpace
(
pExprInfo
,
pExprInfo
->
numOfExprs
+
1
);
_exprCheckSpace
(
pExprInfo
,
pExprInfo
->
numOfExprs
+
1
);
_exprEvic
(
pExprInfo
,
index
);
_exprEvic
(
pExprInfo
,
index
);
...
@@ -994,11 +988,11 @@ SSqlExpr* tscSqlExprInsertEmpty(SSqlCmd* pCmd, int32_t index, int16_t functionId
...
@@ -994,11 +988,11 @@ SSqlExpr* tscSqlExprInsertEmpty(SSqlCmd* pCmd, int32_t index, int16_t functionId
return
pExpr
;
return
pExpr
;
}
}
SSqlExpr
*
tscSqlExprInsert
(
S
SqlCmd
*
pCmd
,
int32_t
index
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
int16_t
type
,
SSqlExpr
*
tscSqlExprInsert
(
S
QueryInfo
*
pQueryInfo
,
int32_t
index
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
int16_t
size
,
int16_t
interSize
)
{
int16_t
type
,
int16_t
size
,
int16_t
interSize
)
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
pColIndex
->
tableIndex
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
pColIndex
->
tableIndex
);
SSqlExprInfo
*
pExprInfo
=
&
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
;
SSqlExprInfo
*
pExprInfo
=
&
p
QueryInfo
->
exprsInfo
;
_exprCheckSpace
(
pExprInfo
,
pExprInfo
->
numOfExprs
+
1
);
_exprCheckSpace
(
pExprInfo
,
pExprInfo
->
numOfExprs
+
1
);
_exprEvic
(
pExprInfo
,
index
);
_exprEvic
(
pExprInfo
,
index
);
...
@@ -1038,10 +1032,10 @@ SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, SCo
...
@@ -1038,10 +1032,10 @@ SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, SCo
return
pExpr
;
return
pExpr
;
}
}
SSqlExpr
*
tscSqlExprUpdate
(
S
SqlCmd
*
pCmd
,
int32_t
index
,
int16_t
functionId
,
int16_t
srcColumnIndex
,
int16_t
type
,
SSqlExpr
*
tscSqlExprUpdate
(
S
QueryInfo
*
pQueryInfo
,
int32_t
index
,
int16_t
functionId
,
int16_t
srcColumnIndex
,
int16_t
size
)
{
int16_t
type
,
int16_t
size
)
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
0
);
SSqlExprInfo
*
pExprInfo
=
&
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
;
SSqlExprInfo
*
pExprInfo
=
&
p
QueryInfo
->
exprsInfo
;
if
(
index
>
pExprInfo
->
numOfExprs
)
{
if
(
index
>
pExprInfo
->
numOfExprs
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -1072,12 +1066,12 @@ void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes,
...
@@ -1072,12 +1066,12 @@ void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes,
assert
(
pExpr
->
numOfParams
<=
3
);
assert
(
pExpr
->
numOfParams
<=
3
);
}
}
SSqlExpr
*
tscSqlExprGet
(
S
SqlCmd
*
pCmd
,
int32_t
index
)
{
SSqlExpr
*
tscSqlExprGet
(
S
QueryInfo
*
pQueryInfo
,
int32_t
index
)
{
if
(
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
.
numOfExprs
<=
index
)
{
if
(
p
QueryInfo
->
exprsInfo
.
numOfExprs
<=
index
)
{
return
NULL
;
return
NULL
;
}
}
return
&
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
.
pExprs
[
index
];
return
&
p
QueryInfo
->
exprsInfo
.
pExprs
[
index
];
}
}
void
tscSqlExprCopy
(
SSqlExprInfo
*
dst
,
const
SSqlExprInfo
*
src
,
uint64_t
tableuid
)
{
void
tscSqlExprCopy
(
SSqlExprInfo
*
dst
,
const
SSqlExprInfo
*
src
,
uint64_t
tableuid
)
{
...
@@ -1156,8 +1150,8 @@ void tscColumnBaseInfoUpdateTableIndex(SColumnBaseInfo* pColList, int16_t tableI
...
@@ -1156,8 +1150,8 @@ void tscColumnBaseInfoUpdateTableIndex(SColumnBaseInfo* pColList, int16_t tableI
}
}
// todo refactor
// todo refactor
SColumnBase
*
tscColumnBaseInfoInsert
(
S
SqlCmd
*
pCmd
,
SColumnIndex
*
pColIndex
)
{
SColumnBase
*
tscColumnBaseInfoInsert
(
S
QueryInfo
*
pQueryInfo
,
SColumnIndex
*
pColIndex
)
{
SColumnBaseInfo
*
pcolList
=
&
p
Cmd
->
pQueryInfo
[
0
].
colList
;
SColumnBaseInfo
*
pcolList
=
&
p
QueryInfo
->
colList
;
// ignore the tbname column to be inserted into source list
// ignore the tbname column to be inserted into source list
if
(
pColIndex
->
columnIndex
<
0
)
{
if
(
pColIndex
->
columnIndex
<
0
)
{
...
@@ -1185,7 +1179,6 @@ SColumnBase* tscColumnBaseInfoInsert(SSqlCmd* pCmd, SColumnIndex* pColIndex) {
...
@@ -1185,7 +1179,6 @@ SColumnBase* tscColumnBaseInfoInsert(SSqlCmd* pCmd, SColumnIndex* pColIndex) {
pcolList
->
pColList
[
i
].
colIndex
=
*
pColIndex
;
pcolList
->
pColList
[
i
].
colIndex
=
*
pColIndex
;
pcolList
->
numOfCols
++
;
pcolList
->
numOfCols
++
;
pCmd
->
numOfCols
++
;
}
}
return
&
pcolList
->
pColList
[
i
];
return
&
pcolList
->
pColList
[
i
];
...
@@ -1404,12 +1397,12 @@ void tscIncStreamExecutionCount(void* pStream) {
...
@@ -1404,12 +1397,12 @@ void tscIncStreamExecutionCount(void* pStream) {
}
}
bool
tscValidateColumnId
(
SSqlCmd
*
pCmd
,
int32_t
colId
)
{
bool
tscValidateColumnId
(
SSqlCmd
*
pCmd
,
int32_t
colId
)
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
0
);
if
(
pMeterMetaInfo
->
pMeterMeta
==
NULL
)
{
if
(
pMeterMetaInfo
->
pMeterMeta
==
NULL
)
{
return
false
;
return
false
;
}
}
if
(
colId
==
-
1
&&
UTIL_METER_IS_
METRIC
(
pMeterMetaInfo
))
{
if
(
colId
==
-
1
&&
UTIL_METER_IS_
SUPERTABLE
(
pMeterMetaInfo
))
{
return
true
;
return
true
;
}
}
...
@@ -1457,12 +1450,12 @@ void tscTagCondRelease(STagCond* pCond) {
...
@@ -1457,12 +1450,12 @@ void tscTagCondRelease(STagCond* pCond) {
memset
(
pCond
,
0
,
sizeof
(
STagCond
));
memset
(
pCond
,
0
,
sizeof
(
STagCond
));
}
}
void
tscGetSrcColumnInfo
(
SSrcColumnInfo
*
pColInfo
,
S
SqlCmd
*
pCmd
)
{
void
tscGetSrcColumnInfo
(
SSrcColumnInfo
*
pColInfo
,
S
QueryInfo
*
pQueryInfo
)
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
0
);
SSchema
*
pSchema
=
tsGetSchema
(
pMeterMetaInfo
->
pMeterMeta
);
SSchema
*
pSchema
=
tsGetSchema
(
pMeterMetaInfo
->
pMeterMeta
);
for
(
int32_t
i
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
.
numOfExprs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
QueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
i
);
pColInfo
[
i
].
functionId
=
pExpr
->
functionId
;
pColInfo
[
i
].
functionId
=
pExpr
->
functionId
;
if
(
TSDB_COL_IS_TAG
(
pExpr
->
colInfo
.
flag
))
{
if
(
TSDB_COL_IS_TAG
(
pExpr
->
colInfo
.
flag
))
{
...
@@ -1485,20 +1478,20 @@ void tscSetFreeHeatBeat(STscObj* pObj) {
...
@@ -1485,20 +1478,20 @@ void tscSetFreeHeatBeat(STscObj* pObj) {
assert
(
pHeatBeat
==
pHeatBeat
->
signature
);
assert
(
pHeatBeat
==
pHeatBeat
->
signature
);
// to denote the heart-beat timer close connection and free all allocated resources
// to denote the heart-beat timer close connection and free all allocated resources
pHeatBeat
->
cmd
.
type
=
TSDB_QUERY_TYPE_FREE_RESOURCE
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pHeatBeat
->
cmd
,
0
);
pQueryInfo
->
type
=
TSDB_QUERY_TYPE_FREE_RESOURCE
;
}
}
bool
tscShouldFreeHeatBeat
(
SSqlObj
*
pHb
)
{
bool
tscShouldFreeHeatBeat
(
SSqlObj
*
pHb
)
{
assert
(
pHb
==
pHb
->
signature
);
assert
(
pHb
==
pHb
->
signature
);
return
pHb
->
cmd
.
type
==
TSDB_QUERY_TYPE_FREE_RESOURCE
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pHb
->
cmd
,
0
);
return
pQueryInfo
->
type
==
TSDB_QUERY_TYPE_FREE_RESOURCE
;
}
}
void
tscCleanSqlCmd
(
SSqlCmd
*
pCmd
)
{
void
tscCleanSqlCmd
(
SSqlCmd
*
pCmd
)
{
tscFreeSqlCmdData
(
pCmd
);
pCmd
->
pDataBlocks
=
tscDestroyBlockArrayList
(
pCmd
->
pDataBlocks
);
tscFreeSubqueryInfo
(
pCmd
);
if
(
pCmd
->
pQueryInfo
!=
NULL
)
{
assert
(
pCmd
->
pQueryInfo
[
0
].
pMeterInfo
==
NULL
);
}
uint32_t
allocSize
=
pCmd
->
allocSize
;
uint32_t
allocSize
=
pCmd
->
allocSize
;
char
*
allocPtr
=
pCmd
->
payload
;
char
*
allocPtr
=
pCmd
->
payload
;
...
@@ -1552,9 +1545,10 @@ bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) {
...
@@ -1552,9 +1545,10 @@ bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) {
* data blocks have been submit to vnode.
* data blocks have been submit to vnode.
*/
*/
SDataBlockList
*
pDataBlocks
=
pCmd
->
pDataBlocks
;
SDataBlockList
*
pDataBlocks
=
pCmd
->
pDataBlocks
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
0
);
assert
(
p
Sql
->
cmd
.
pQueryInfo
[
0
].
numOfTables
==
1
);
assert
(
p
QueryInfo
->
numOfTables
==
1
);
if
(
pDataBlocks
==
NULL
||
pMeterMetaInfo
->
vnodeIndex
>=
pDataBlocks
->
nSize
)
{
if
(
pDataBlocks
==
NULL
||
pMeterMetaInfo
->
vnodeIndex
>=
pDataBlocks
->
nSize
)
{
tscTrace
(
"%p object should be release since all data blocks have been submit"
,
pSql
);
tscTrace
(
"%p object should be release since all data blocks have been submit"
,
pSql
);
...
@@ -1568,19 +1562,50 @@ bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) {
...
@@ -1568,19 +1562,50 @@ bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) {
}
}
}
}
SMeterMetaInfo
*
tscGetMeterMetaInfo
(
SSqlCmd
*
pCmd
,
int32_t
index
)
{
/**
if
(
pCmd
==
NULL
||
pCmd
->
numOfQueries
==
0
||
pCmd
->
pQueryInfo
[
0
].
numOfTables
==
0
)
{
*
* @param pCmd
* @param unionSubClause denote the index of the union sub clause, usually are 0, if no union query exists.
* @param tableIndex denote the table index for join query, where more than one table exists
* @return
*/
SMeterMetaInfo
*
tscGetMeterMetaInfo
(
SSqlCmd
*
pCmd
,
int32_t
unionClauseIndex
,
int32_t
tableIndex
)
{
if
(
pCmd
==
NULL
||
pCmd
->
numOfClause
==
0
)
{
return
NULL
;
}
assert
(
unionClauseIndex
>=
0
&&
unionClauseIndex
<
pCmd
->
numOfClause
);
SQueryInfo
*
pQueryInfo
=
pCmd
->
pQueryInfo
[
unionClauseIndex
];
return
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
tableIndex
);
}
SMeterMetaInfo
*
tscGetMeterMetaInfoFromQueryInfo
(
SQueryInfo
*
pQueryInfo
,
int32_t
tableIndex
)
{
if
(
pQueryInfo
->
pMeterInfo
==
NULL
)
{
assert
(
pQueryInfo
->
numOfTables
==
0
);
return
NULL
;
}
assert
(
pQueryInfo
!=
NULL
&&
tableIndex
>=
0
&&
tableIndex
<=
pQueryInfo
->
numOfTables
&&
pQueryInfo
->
pMeterInfo
!=
NULL
);
return
pQueryInfo
->
pMeterInfo
[
tableIndex
];
}
SQueryInfo
*
tscGetQueryInfoDetail
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
)
{
if
(
pCmd
->
pQueryInfo
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
assert
(
index
>=
0
&&
index
<=
pCmd
->
pQueryInfo
[
0
].
numOfTables
&&
pCmd
->
pQueryInfo
[
0
].
pMeterInfo
!=
NULL
);
assert
(
pCmd
!=
NULL
&&
subClauseIndex
>=
0
&&
subClauseIndex
<
pCmd
->
numOfClause
);
return
pCmd
->
pQueryInfo
[
0
].
pMeterInfo
[
i
ndex
];
return
pCmd
->
pQueryInfo
[
subClauseI
ndex
];
}
}
SMeterMetaInfo
*
tscGetMeterMetaInfoByUid
(
S
SqlCmd
*
pCmd
,
uint64_t
uid
,
int32_t
*
index
)
{
SMeterMetaInfo
*
tscGetMeterMetaInfoByUid
(
S
QueryInfo
*
pQueryInfo
,
int32_t
subClauseIndex
,
uint64_t
uid
,
int32_t
*
index
)
{
int32_t
k
=
-
1
;
int32_t
k
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
pCmd
->
pQueryInfo
->
numOfTables
;
++
i
)
{
if
(
pCmd
->
pQueryInfo
[
0
].
pMeterInfo
[
i
]
->
pMeterMeta
->
uid
==
uid
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
if
(
pQueryInfo
->
pMeterInfo
[
i
]
->
pMeterMeta
->
uid
==
uid
)
{
k
=
i
;
k
=
i
;
break
;
break
;
}
}
...
@@ -1590,40 +1615,80 @@ SMeterMetaInfo* tscGetMeterMetaInfoByUid(SSqlCmd* pCmd, uint64_t uid, int32_t* i
...
@@ -1590,40 +1615,80 @@ SMeterMetaInfo* tscGetMeterMetaInfoByUid(SSqlCmd* pCmd, uint64_t uid, int32_t* i
*
index
=
k
;
*
index
=
k
;
}
}
return
tscGetMeterMetaInfo
(
pCmd
,
k
);
return
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
k
);
}
}
int32_t
tscAdd
Q
ueryInfo
(
SSqlCmd
*
pCmd
)
{
int32_t
tscAdd
Subq
ueryInfo
(
SSqlCmd
*
pCmd
)
{
assert
(
pCmd
!=
NULL
);
assert
(
pCmd
!=
NULL
);
size_t
s
=
pCmd
->
numOf
Queries
+
1
;
size_t
s
=
pCmd
->
numOf
Clause
+
1
;
char
*
tmp
=
realloc
(
pCmd
->
pQueryInfo
,
s
*
sizeof
(
SQueryInfo
)
);
char
*
tmp
=
realloc
(
pCmd
->
pQueryInfo
,
s
*
POINTER_BYTES
);
if
(
tmp
==
NULL
)
{
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_CLI_OUT_OF_MEMORY
;
return
TSDB_CODE_CLI_OUT_OF_MEMORY
;
}
}
pCmd
->
pQueryInfo
=
(
SQueryInfo
*
)
tmp
;
pCmd
->
pQueryInfo
=
(
SQueryInfo
**
)
tmp
;
memset
(
&
pCmd
->
pQueryInfo
[
pCmd
->
numOfQueries
],
0
,
sizeof
(
SQueryInfo
));
SQueryInfo
*
pQueryInfo
=
calloc
(
1
,
sizeof
(
SQueryInfo
));
pQueryInfo
->
msg
=
pCmd
->
payload
;
// pointer to the parent error message buffer
pCmd
->
numOfQueries
++
;
pCmd
->
pQueryInfo
[
pCmd
->
numOfClause
++
]
=
pQueryInfo
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SMeterMetaInfo
*
tscAddMeterMetaInfo
(
SSqlCmd
*
pCmd
,
const
char
*
name
,
SMeterMeta
*
pMeterMeta
,
SMetricMeta
*
pMetricMeta
,
static
void
doFreeSubqueryInfo
(
SQueryInfo
*
pQueryInfo
,
int64_t
address
)
{
int16_t
numOfTags
,
int16_t
*
tags
)
{
tscTagCondRelease
(
&
pQueryInfo
->
tagCond
);
if
(
pCmd
->
pQueryInfo
==
NULL
)
{
tscClearFieldInfo
(
&
pQueryInfo
->
fieldsInfo
);
tscAddQueryInfo
(
pCmd
);
tfree
(
pQueryInfo
->
exprsInfo
.
pExprs
);
memset
(
&
pQueryInfo
->
exprsInfo
,
0
,
sizeof
(
pQueryInfo
->
exprsInfo
));
tscColumnBaseInfoDestroy
(
&
pQueryInfo
->
colList
);
memset
(
&
pQueryInfo
->
colList
,
0
,
sizeof
(
pQueryInfo
->
colList
));
if
(
pQueryInfo
->
tsBuf
!=
NULL
)
{
tsBufDestory
(
pQueryInfo
->
tsBuf
);
pQueryInfo
->
tsBuf
=
NULL
;
}
}
void
*
pAlloc
=
realloc
(
pCmd
->
pQueryInfo
[
0
].
pMeterInfo
,
(
pCmd
->
pQueryInfo
->
numOfTables
+
1
)
*
POINTER_BYTES
);
tscRemoveAllMeterMetaInfo
(
pQueryInfo
,
(
const
char
*
)
address
,
false
);
tfree
(
pQueryInfo
);
}
void
tscFreeSubqueryInfo
(
SSqlCmd
*
pCmd
)
{
if
(
pCmd
==
NULL
||
pCmd
->
numOfClause
==
0
)
{
return
;
}
for
(
int32_t
i
=
0
;
i
<
pCmd
->
numOfClause
;
++
i
)
{
int64_t
offset
=
offsetof
(
SSqlObj
,
cmd
);
int64_t
addr
=
(
char
*
)
pCmd
-
offset
;
doFreeSubqueryInfo
(
tscGetQueryInfoDetail
(
pCmd
,
i
),
addr
);
}
pCmd
->
numOfClause
=
0
;
tfree
(
pCmd
->
pQueryInfo
);
}
SMeterMetaInfo
*
tscAddMeterMetaInfo
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
,
const
char
*
name
,
SMeterMeta
*
pMeterMeta
,
SMetricMeta
*
pMetricMeta
,
int16_t
numOfTags
,
int16_t
*
tags
)
{
assert
(
subClauseIndex
>=
0
&&
subClauseIndex
<
TSDB_MAX_UNION_CLAUSE
);
while
(
pCmd
->
numOfClause
<=
subClauseIndex
)
{
tscAddSubqueryInfo
(
pCmd
);
}
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
void
*
pAlloc
=
realloc
(
pQueryInfo
->
pMeterInfo
,
(
pQueryInfo
->
numOfTables
+
1
)
*
POINTER_BYTES
);
if
(
pAlloc
==
NULL
)
{
if
(
pAlloc
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
p
Cmd
->
pQueryInfo
[
0
].
pMeterInfo
=
pAlloc
;
p
QueryInfo
->
pMeterInfo
=
pAlloc
;
p
Cmd
->
pQueryInfo
[
0
].
pMeterInfo
[
pCmd
->
pQueryInfo
->
numOfTables
]
=
calloc
(
1
,
sizeof
(
SMeterMetaInfo
));
p
QueryInfo
->
pMeterInfo
[
pQueryInfo
->
numOfTables
]
=
calloc
(
1
,
sizeof
(
SMeterMetaInfo
));
SMeterMetaInfo
*
pMeterMetaInfo
=
p
Cmd
->
pQueryInfo
[
0
].
pMeterInfo
[
pCmd
->
pQueryInfo
->
numOfTables
];
SMeterMetaInfo
*
pMeterMetaInfo
=
p
QueryInfo
->
pMeterInfo
[
pQueryInfo
->
numOfTables
];
assert
(
pMeterMetaInfo
!=
NULL
);
assert
(
pMeterMetaInfo
!=
NULL
);
if
(
name
!=
NULL
)
{
if
(
name
!=
NULL
)
{
...
@@ -1639,46 +1704,41 @@ SMeterMetaInfo* tscAddMeterMetaInfo(SSqlCmd* pCmd, const char* name, SMeterMeta*
...
@@ -1639,46 +1704,41 @@ SMeterMetaInfo* tscAddMeterMetaInfo(SSqlCmd* pCmd, const char* name, SMeterMeta*
memcpy
(
pMeterMetaInfo
->
tagColumnIndex
,
tags
,
sizeof
(
pMeterMetaInfo
->
tagColumnIndex
[
0
])
*
numOfTags
);
memcpy
(
pMeterMetaInfo
->
tagColumnIndex
,
tags
,
sizeof
(
pMeterMetaInfo
->
tagColumnIndex
[
0
])
*
numOfTags
);
}
}
pCmd
->
pQueryInfo
->
numOfTables
+=
1
;
pQueryInfo
->
numOfTables
+=
1
;
return
pMeterMetaInfo
;
return
pMeterMetaInfo
;
}
}
SMeterMetaInfo
*
tscAddEmptyMeterMetaInfo
(
SSqlCmd
*
pCmd
)
{
return
tscAddMeterMetaInfo
(
pCmd
,
NULL
,
NULL
,
NULL
,
0
,
NULL
);
}
SMeterMetaInfo
*
tscAddEmptyMeterMetaInfo
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
)
{
return
tscAddMeterMetaInfo
(
pCmd
,
subClauseIndex
,
NULL
,
NULL
,
NULL
,
0
,
NULL
);
}
void
tscRemoveMeterMetaInfo
(
SSqlCmd
*
pCmd
,
int32_t
index
,
bool
removeFromCache
)
{
void
doRemoveMeterMetaInfo
(
SQueryInfo
*
pQueryInfo
,
int32_t
index
,
bool
removeFromCache
)
{
if
(
index
<
0
||
index
>=
p
Cmd
->
p
QueryInfo
->
numOfTables
)
{
if
(
index
<
0
||
index
>=
pQueryInfo
->
numOfTables
)
{
return
;
return
;
}
}
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
index
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
FromQueryInfo
(
pQueryInfo
,
index
);
tscClearMeterMetaInfo
(
pMeterMetaInfo
,
removeFromCache
);
tscClearMeterMetaInfo
(
pMeterMetaInfo
,
removeFromCache
);
free
(
pMeterMetaInfo
);
free
(
pMeterMetaInfo
);
int32_t
after
=
p
Cmd
->
p
QueryInfo
->
numOfTables
-
index
-
1
;
int32_t
after
=
pQueryInfo
->
numOfTables
-
index
-
1
;
if
(
after
>
0
)
{
if
(
after
>
0
)
{
memmove
(
&
p
Cmd
->
pQueryInfo
[
0
].
pMeterInfo
[
index
],
&
pCmd
->
pQueryInfo
[
0
].
pMeterInfo
[
index
+
1
],
after
*
sizeof
(
void
*
));
memmove
(
&
p
QueryInfo
->
pMeterInfo
[
index
],
&
pQueryInfo
->
pMeterInfo
[
index
+
1
],
after
*
sizeof
(
void
*
));
}
}
p
Cmd
->
p
QueryInfo
->
numOfTables
-=
1
;
pQueryInfo
->
numOfTables
-=
1
;
}
}
void
tscRemoveAllMeterMetaInfo
(
SSqlCmd
*
pCmd
,
bool
removeFromCache
)
{
void
tscRemoveAllMeterMetaInfo
(
SQueryInfo
*
pQueryInfo
,
const
char
*
address
,
bool
removeFromCache
)
{
int64_t
addr
=
offsetof
(
SSqlObj
,
cmd
);
tscTrace
(
"%p deref the metric/meter meta in cache, numOfTables:%d"
,
address
,
pQueryInfo
->
numOfTables
);
if
(
pCmd
->
numOfQueries
==
0
)
{
return
;
}
tscTrace
(
"%p deref the metric/meter meta in cache, numOfTables:%d"
,
((
char
*
)
pCmd
-
addr
),
int32_t
index
=
pQueryInfo
->
numOfTables
;
pCmd
->
pQueryInfo
[
0
].
numOfTables
);
while
(
index
>=
0
)
{
doRemoveMeterMetaInfo
(
pQueryInfo
,
--
index
,
removeFromCache
);
while
(
pCmd
->
pQueryInfo
[
0
].
numOfTables
>
0
)
{
tscRemoveMeterMetaInfo
(
pCmd
,
pCmd
->
pQueryInfo
->
numOfTables
-
1
,
removeFromCache
);
}
}
tfree
(
p
Cmd
->
pQueryInfo
[
0
].
pMeterInfo
);
tfree
(
p
QueryInfo
->
pMeterInfo
);
}
}
void
tscClearMeterMetaInfo
(
SMeterMetaInfo
*
pMeterMetaInfo
,
bool
removeFromCache
)
{
void
tscClearMeterMetaInfo
(
SMeterMetaInfo
*
pMeterMetaInfo
,
bool
removeFromCache
)
{
...
@@ -1697,7 +1757,7 @@ void tscResetForNextRetrieve(SSqlRes* pRes) {
...
@@ -1697,7 +1757,7 @@ void tscResetForNextRetrieve(SSqlRes* pRes) {
SSqlObj
*
createSubqueryObj
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
void
(
*
fp
)(),
void
*
param
,
SSqlObj
*
pPrevSql
)
{
SSqlObj
*
createSubqueryObj
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
void
(
*
fp
)(),
void
*
param
,
SSqlObj
*
pPrevSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
tableIndex
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
,
tableIndex
);
SSqlObj
*
pNew
=
(
SSqlObj
*
)
calloc
(
1
,
sizeof
(
SSqlObj
));
SSqlObj
*
pNew
=
(
SSqlObj
*
)
calloc
(
1
,
sizeof
(
SSqlObj
));
if
(
pNew
==
NULL
)
{
if
(
pNew
==
NULL
)
{
...
@@ -1723,26 +1783,26 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
...
@@ -1723,26 +1783,26 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
pNew
->
cmd
.
allocSize
=
0
;
pNew
->
cmd
.
allocSize
=
0
;
pNew
->
cmd
.
pQueryInfo
=
NULL
;
pNew
->
cmd
.
pQueryInfo
=
NULL
;
pNew
->
cmd
.
numOf
Queries
=
0
;
pNew
->
cmd
.
numOf
Clause
=
0
;
if
(
tscAdd
Q
ueryInfo
(
&
pNew
->
cmd
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscAdd
Subq
ueryInfo
(
&
pNew
->
cmd
)
!=
TSDB_CODE_SUCCESS
)
{
tscFreeSqlObj
(
pNew
);
tscFreeSqlObj
(
pNew
);
return
NULL
;
return
NULL
;
}
}
memcpy
(
&
pNew
->
cmd
.
pQueryInfo
[
0
],
&
pCmd
->
pQueryInfo
[
0
],
sizeof
(
SQueryInfo
)
);
SQueryInfo
*
pNewQueryInfo
=
tscGetQueryInfoDetail
(
&
pNew
->
cmd
,
0
);
pNew
->
cmd
.
pQueryInfo
[
0
].
pMeterInfo
=
NULL
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
)
;
pNew
->
cmd
.
pQueryInfo
[
0
].
colList
.
pColList
=
NULL
;
memcpy
(
pNewQueryInfo
,
pQueryInfo
,
sizeof
(
SQueryInfo
));
pNew
->
cmd
.
pQueryInfo
[
0
].
colList
.
numOfAlloc
=
0
;
pNewQueryInfo
->
pMeterInfo
=
NULL
;
pNew
->
cmd
.
pQueryInfo
[
0
].
colList
.
numOfCols
=
0
;
pNew
->
cmd
.
pQueryInfo
[
0
].
numOfTables
=
0
;
memset
(
&
pNewQueryInfo
->
colList
,
0
,
sizeof
(
pNewQueryInfo
->
colList
))
;
pNew
->
cmd
.
pQueryInfo
[
0
].
tsBuf
=
NULL
;
memset
(
&
pNewQueryInfo
->
fieldsInfo
,
0
,
sizeof
(
SFieldInfo
))
;
memset
(
&
pNew
->
cmd
.
pQueryInfo
[
0
].
fieldsInfo
,
0
,
sizeof
(
SFieldInfo
));
pNewQueryInfo
->
numOfTables
=
0
;
pNewQueryInfo
->
tsBuf
=
NULL
;
tscTagCondCopy
(
&
pNew
->
cmd
.
pQueryInfo
[
0
].
tagCond
,
&
pCmd
->
pQueryInfo
[
0
].
tagCond
);
tscTagCondCopy
(
&
pNew
QueryInfo
->
tagCond
,
&
pQueryInfo
->
tagCond
);
if
(
tscAllocPayload
(
&
pNew
->
cmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscAllocPayload
(
&
pNew
->
cmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
)
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"%p new subquery failed, tableIndex:%d, vnodeIndex:%d"
,
pSql
,
tableIndex
,
pMeterMetaInfo
->
vnodeIndex
);
tscError
(
"%p new subquery failed, tableIndex:%d, vnodeIndex:%d"
,
pSql
,
tableIndex
,
pMeterMetaInfo
->
vnodeIndex
);
...
@@ -1750,40 +1810,41 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
...
@@ -1750,40 +1810,41 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
return
NULL
;
return
NULL
;
}
}
tscColumnBaseInfoCopy
(
&
pNew
->
cmd
.
pQueryInfo
[
0
].
colList
,
&
pCmd
->
pQueryInfo
[
0
].
colList
,
(
int16_t
)
tableIndex
);
tscColumnBaseInfoCopy
(
&
pNew
QueryInfo
->
colList
,
&
pQueryInfo
->
colList
,
(
int16_t
)
tableIndex
);
// set the correct query type
// set the correct query type
if
(
pPrevSql
!=
NULL
)
{
if
(
pPrevSql
!=
NULL
)
{
pNew
->
cmd
.
type
=
pPrevSql
->
cmd
.
type
;
SQueryInfo
*
pPrevQueryInfo
=
tscGetQueryInfoDetail
(
&
pPrevSql
->
cmd
,
0
);
pNewQueryInfo
->
type
=
pPrevQueryInfo
->
type
;
}
else
{
}
else
{
pNew
->
cmd
.
type
|=
TSDB_QUERY_TYPE_SUBQUERY
;
// it must be the subquery
pNew
QueryInfo
->
type
|=
TSDB_QUERY_TYPE_SUBQUERY
;
// it must be the subquery
}
}
uint64_t
uid
=
pMeterMetaInfo
->
pMeterMeta
->
uid
;
uint64_t
uid
=
pMeterMetaInfo
->
pMeterMeta
->
uid
;
tscSqlExprCopy
(
&
pNew
->
cmd
.
pQueryInfo
[
0
].
exprsInfo
,
&
pCmd
->
pQueryInfo
[
0
].
exprsInfo
,
uid
);
tscSqlExprCopy
(
&
pNew
QueryInfo
->
exprsInfo
,
&
pQueryInfo
->
exprsInfo
,
uid
);
int32_t
numOfOutputCols
=
pNew
->
cmd
.
pQueryInfo
[
0
].
exprsInfo
.
numOfExprs
;
int32_t
numOfOutputCols
=
pNew
QueryInfo
->
exprsInfo
.
numOfExprs
;
if
(
numOfOutputCols
>
0
)
{
if
(
numOfOutputCols
>
0
)
{
int32_t
*
indexList
=
calloc
(
1
,
numOfOutputCols
*
sizeof
(
int32_t
));
int32_t
*
indexList
=
calloc
(
1
,
numOfOutputCols
*
sizeof
(
int32_t
));
for
(
int32_t
i
=
0
,
j
=
0
;
i
<
p
Cmd
->
pQueryInfo
[
0
].
exprsInfo
.
numOfExprs
;
++
i
)
{
for
(
int32_t
i
=
0
,
j
=
0
;
i
<
p
QueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
Cmd
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
p
QueryInfo
,
i
);
if
(
pExpr
->
uid
==
uid
)
{
if
(
pExpr
->
uid
==
uid
)
{
indexList
[
j
++
]
=
i
;
indexList
[
j
++
]
=
i
;
}
}
}
}
tscFieldInfoCopy
(
&
p
Cmd
->
pQueryInfo
[
0
].
fieldsInfo
,
&
pNew
->
cmd
.
pQueryInfo
[
0
].
fieldsInfo
,
indexList
,
numOfOutputCols
);
tscFieldInfoCopy
(
&
p
QueryInfo
->
fieldsInfo
,
&
pNewQueryInfo
->
fieldsInfo
,
indexList
,
numOfOutputCols
);
free
(
indexList
);
free
(
indexList
);
tscFieldInfoUpdateOffset
(
&
pNew
->
cmd
);
tscFieldInfoUpdateOffset
(
pNewQueryInfo
);
}
}
pNew
->
fp
=
fp
;
pNew
->
fp
=
fp
;
pNew
->
param
=
param
;
pNew
->
param
=
param
;
char
key
[
TSDB_MAX_TAGS_LEN
+
1
]
=
{
0
};
char
key
[
TSDB_MAX_TAGS_LEN
+
1
]
=
{
0
};
tscGetMetricMetaCacheKey
(
pCmd
,
key
,
uid
);
tscGetMetricMetaCacheKey
(
pCmd
,
0
,
key
,
uid
);
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
printf
(
"the metricmeta key is:%s
\n
"
,
key
);
printf
(
"the metricmeta key is:%s
\n
"
,
key
);
...
@@ -1797,11 +1858,11 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
...
@@ -1797,11 +1858,11 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
SMeterMeta
*
pMeterMeta
=
taosGetDataFromCache
(
tscCacheHandle
,
name
);
SMeterMeta
*
pMeterMeta
=
taosGetDataFromCache
(
tscCacheHandle
,
name
);
SMetricMeta
*
pMetricMeta
=
taosGetDataFromCache
(
tscCacheHandle
,
key
);
SMetricMeta
*
pMetricMeta
=
taosGetDataFromCache
(
tscCacheHandle
,
key
);
pFinalInfo
=
tscAddMeterMetaInfo
(
&
pNew
->
cmd
,
name
,
pMeterMeta
,
pMetricMeta
,
pMeterMetaInfo
->
numOfTags
,
pFinalInfo
=
tscAddMeterMetaInfo
(
&
pNew
->
cmd
,
0
,
name
,
pMeterMeta
,
pMetricMeta
,
pMeterMetaInfo
->
numOfTags
,
pMeterMetaInfo
->
tagColumnIndex
);
pMeterMetaInfo
->
tagColumnIndex
);
}
else
{
}
else
{
SMeterMetaInfo
*
pPrevInfo
=
tscGetMeterMetaInfo
(
&
pPrevSql
->
cmd
,
0
);
SMeterMetaInfo
*
pPrevInfo
=
tscGetMeterMetaInfo
(
&
pPrevSql
->
cmd
,
0
,
0
);
pFinalInfo
=
tscAddMeterMetaInfo
(
&
pNew
->
cmd
,
name
,
pPrevInfo
->
pMeterMeta
,
pPrevInfo
->
pMetricMeta
,
pFinalInfo
=
tscAddMeterMetaInfo
(
&
pNew
->
cmd
,
0
,
name
,
pPrevInfo
->
pMeterMeta
,
pPrevInfo
->
pMetricMeta
,
pMeterMetaInfo
->
numOfTags
,
pMeterMetaInfo
->
tagColumnIndex
);
pMeterMetaInfo
->
numOfTags
,
pMeterMetaInfo
->
tagColumnIndex
);
pPrevInfo
->
pMeterMeta
=
NULL
;
pPrevInfo
->
pMeterMeta
=
NULL
;
...
@@ -1809,12 +1870,12 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
...
@@ -1809,12 +1870,12 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
}
}
assert
(
pFinalInfo
->
pMeterMeta
!=
NULL
);
assert
(
pFinalInfo
->
pMeterMeta
!=
NULL
);
if
(
UTIL_METER_IS_
METRIC
(
pMeterMetaInfo
))
{
if
(
UTIL_METER_IS_
SUPERTABLE
(
pMeterMetaInfo
))
{
assert
(
pFinalInfo
->
pMetricMeta
!=
NULL
);
assert
(
pFinalInfo
->
pMetricMeta
!=
NULL
);
}
}
tscTrace
(
"%p new subquery %p, tableIndex:%d, vnodeIdx:%d, type:%d"
,
pSql
,
pNew
,
tableIndex
,
tscTrace
(
"%p new subquery %p, tableIndex:%d, vnodeIdx:%d, type:%d"
,
pSql
,
pNew
,
tableIndex
,
pMeterMetaInfo
->
vnodeIndex
,
pNew
->
cmd
.
type
);
pMeterMetaInfo
->
vnodeIndex
,
pNew
QueryInfo
->
type
);
return
pNew
;
return
pNew
;
}
}
...
@@ -1893,3 +1954,5 @@ bool tscHasReachLimitation(SSqlObj* pSql) {
...
@@ -1893,3 +1954,5 @@ bool tscHasReachLimitation(SSqlObj* pSql) {
return
(
pCmd
->
globalLimit
>
0
&&
pRes
->
numOfTotal
>=
pCmd
->
globalLimit
);
return
(
pCmd
->
globalLimit
>
0
&&
pRes
->
numOfTotal
>=
pCmd
->
globalLimit
);
}
}
char
*
tscGetErrorMsgPayload
(
SSqlCmd
*
pCmd
)
{
return
pCmd
->
payload
;
}
src/inc/sql.y
浏览文件 @
e15aa9b1
...
@@ -354,7 +354,8 @@ select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_opt(K) fill_
...
@@ -354,7 +354,8 @@ select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_opt(K) fill_
union(Y) ::= select(X). { Y = setSubclause(NULL, X); }
union(Y) ::= select(X). { Y = setSubclause(NULL, X); }
union(Y) ::= LP union(X) RP. { Y = X; }
union(Y) ::= LP union(X) RP. { Y = X; }
union(Y) ::= union(Z) UNION select(X). { Y = appendSelectClause(Z, X); }
union(Y) ::= union(Z) UNION ALL select(X). { Y = appendSelectClause(Z, X); }
union(Y) ::= union(Z) UNION ALL LP select(X) RP. { Y = appendSelectClause(Z, X); }
cmd ::= union(X). { setSQLInfo(pInfo, X, NULL, TSDB_SQL_SELECT); }
cmd ::= union(X). { setSQLInfo(pInfo, X, NULL, TSDB_SQL_SELECT); }
...
...
src/inc/tsdb.h
浏览文件 @
e15aa9b1
...
@@ -186,6 +186,7 @@ extern "C" {
...
@@ -186,6 +186,7 @@ extern "C" {
#define TSDB_MAX_TABLES_PER_VNODE 220000
#define TSDB_MAX_TABLES_PER_VNODE 220000
#define TSDB_MAX_JOIN_TABLE_NUM 5
#define TSDB_MAX_JOIN_TABLE_NUM 5
#define TSDB_MAX_UNION_CLAUSE 5
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE)
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE)
#define TSDB_MAX_NCHAR_LEN (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE)
#define TSDB_MAX_NCHAR_LEN (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE)
...
...
src/inc/tsqldef.h
浏览文件 @
e15aa9b1
...
@@ -120,66 +120,66 @@
...
@@ -120,66 +120,66 @@
#define TK_NULL 102
#define TK_NULL 102
#define TK_SELECT 103
#define TK_SELECT 103
#define TK_UNION 104
#define TK_UNION 104
#define TK_
FROM
105
#define TK_
ALL
105
#define TK_
VARIABLE
106
#define TK_
FROM
106
#define TK_
INTERVAL
107
#define TK_
VARIABLE
107
#define TK_
FILL
108
#define TK_
INTERVAL
108
#define TK_
SLIDING
109
#define TK_
FILL
109
#define TK_
ORDER
110
#define TK_
SLIDING
110
#define TK_
BY
111
#define TK_
ORDER
111
#define TK_
ASC
112
#define TK_
BY
112
#define TK_
DESC
113
#define TK_
ASC
113
#define TK_
GROUP
114
#define TK_
DESC
114
#define TK_
HAVING
115
#define TK_
GROUP
115
#define TK_
LIMIT
116
#define TK_
HAVING
116
#define TK_
OFFSET
117
#define TK_
LIMIT
117
#define TK_
SLIMI
T 118
#define TK_
OFFSE
T 118
#define TK_S
OFFSET
119
#define TK_S
LIMIT
119
#define TK_
WHERE
120
#define TK_
SOFFSET
120
#define TK_
NOW
121
#define TK_
WHERE
121
#define TK_
RESET
122
#define TK_
NOW
122
#define TK_
QUERY
123
#define TK_
RESET
123
#define TK_
ADD
124
#define TK_
QUERY
124
#define TK_
COLUMN
125
#define TK_
ADD
125
#define TK_
TAG
126
#define TK_
COLUMN
126
#define TK_
CHANGE
127
#define TK_
TAG
127
#define TK_
SET
128
#define TK_
CHANGE
128
#define TK_
KILL
129
#define TK_
SET
129
#define TK_
CONNECTION
130
#define TK_
KILL
130
#define TK_CO
LON
131
#define TK_CO
NNECTION
131
#define TK_
STREAM
132
#define TK_
COLON
132
#define TK_
ABORT
133
#define TK_
STREAM
133
#define TK_A
FTER
134
#define TK_A
BORT
134
#define TK_A
TTACH
135
#define TK_A
FTER
135
#define TK_
BEFORE
136
#define TK_
ATTACH
136
#define TK_BE
GIN
137
#define TK_BE
FORE
137
#define TK_
CASCADE
138
#define TK_
BEGIN
138
#define TK_C
LUSTER
139
#define TK_C
ASCADE
139
#define TK_C
ONFLICT
140
#define TK_C
LUSTER
140
#define TK_CO
PY
141
#define TK_CO
NFLICT
141
#define TK_
DEFERRED
142
#define TK_
COPY
142
#define TK_DE
LIMITERS
143
#define TK_DE
FERRED
143
#define TK_DE
TACH
144
#define TK_DE
LIMITERS
144
#define TK_
EACH
145
#define TK_
DETACH
145
#define TK_E
ND
146
#define TK_E
ACH
146
#define TK_E
XPLAIN
147
#define TK_E
ND
147
#define TK_
FAIL
148
#define TK_
EXPLAIN
148
#define TK_F
OR
149
#define TK_F
AIL
149
#define TK_
IGNORE
150
#define TK_
FOR
150
#define TK_I
MMEDIATE
151
#define TK_I
GNORE
151
#define TK_I
NITIALLY
152
#define TK_I
MMEDIATE
152
#define TK_IN
STEAD
153
#define TK_IN
ITIALLY
153
#define TK_
MATCH
154
#define TK_
INSTEAD
154
#define TK_
KEY
155
#define TK_
MATCH
155
#define TK_
OF
156
#define TK_
KEY
156
#define TK_
RAISE
157
#define TK_
OF
157
#define TK_R
EPLACE
158
#define TK_R
AISE
158
#define TK_RE
STRICT
159
#define TK_RE
PLACE
159
#define TK_R
OW
160
#define TK_R
ESTRICT
160
#define TK_
STATEMENT
161
#define TK_
ROW
161
#define TK_
TRIGGER
162
#define TK_
STATEMENT
162
#define TK_
VIEW
163
#define TK_
TRIGGER
163
#define TK_
ALL
164
#define TK_
VIEW
164
#define TK_COUNT 165
#define TK_COUNT 165
#define TK_SUM 166
#define TK_SUM 166
#define TK_AVG 167
#define TK_AVG 167
...
...
src/inc/tutil.h
浏览文件 @
e15aa9b1
...
@@ -102,8 +102,8 @@ extern "C" {
...
@@ -102,8 +102,8 @@ extern "C" {
#define GET_FLOAT_VAL(x) taos_align_get_float(x)
#define GET_FLOAT_VAL(x) taos_align_get_float(x)
#define GET_DOUBLE_VAL(x) taos_align_get_double(x)
#define GET_DOUBLE_VAL(x) taos_align_get_double(x)
float
taos_align_get_float
(
char
*
pBuf
);
float
taos_align_get_float
(
c
onst
c
har
*
pBuf
);
double
taos_align_get_double
(
char
*
pBuf
);
double
taos_align_get_double
(
c
onst
c
har
*
pBuf
);
//#define __float_align_declear() float __underlyFloat = 0.0;
//#define __float_align_declear() float __underlyFloat = 0.0;
//#define __float_align_declear()
//#define __float_align_declear()
...
...
src/util/src/hash.c
浏览文件 @
e15aa9b1
...
@@ -480,6 +480,8 @@ void taosCleanUpHashTable(void *handle) {
...
@@ -480,6 +480,8 @@ void taosCleanUpHashTable(void *handle) {
free
(
pNode
);
free
(
pNode
);
pNode
=
pNext
;
pNode
=
pNext
;
}
}
tfree
(
pEntry
);
}
}
free
(
pObj
->
hashList
);
free
(
pObj
->
hashList
);
...
...
src/util/src/tutil.c
浏览文件 @
e15aa9b1
...
@@ -528,13 +528,13 @@ char *taosIpStr(uint32_t ipInt) {
...
@@ -528,13 +528,13 @@ char *taosIpStr(uint32_t ipInt) {
void
taosCleanupTier
()
{}
void
taosCleanupTier
()
{}
#endif
#endif
FORCE_INLINE
float
taos_align_get_float
(
char
*
pBuf
)
{
FORCE_INLINE
float
taos_align_get_float
(
c
onst
c
har
*
pBuf
)
{
float
fv
=
0
;
float
fv
=
0
;
*
(
int32_t
*
)(
&
fv
)
=
*
(
int32_t
*
)
pBuf
;
*
(
int32_t
*
)(
&
fv
)
=
*
(
int32_t
*
)
pBuf
;
return
fv
;
return
fv
;
}
}
FORCE_INLINE
double
taos_align_get_double
(
char
*
pBuf
)
{
FORCE_INLINE
double
taos_align_get_double
(
c
onst
c
har
*
pBuf
)
{
double
dv
=
0
;
double
dv
=
0
;
*
(
int64_t
*
)(
&
dv
)
=
*
(
int64_t
*
)
pBuf
;
*
(
int64_t
*
)(
&
dv
)
=
*
(
int64_t
*
)
pBuf
;
return
dv
;
return
dv
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录