add the union support in sql parser. #1032. [TBASE-1140]
This commit is contained in:
parent
c18b6b1ba4
commit
e15aa9b1f9
|
@ -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);
|
||||||
* @param pSql sql object
|
* @param pSql sql object
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
bool tscIsPointInterpQuery(SSqlCmd* pCmd);
|
bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo);
|
||||||
bool tscIsTWAQuery(SSqlCmd* pCmd);
|
bool tscIsTWAQuery(SQueryInfo* pQueryInfo);
|
||||||
bool tscProjectionQueryOnMetric(SSqlCmd* pCmd);
|
bool tscProjectionQueryOnMetric(SSqlCmd* pCmd, int32_t subClauseIndex);
|
||||||
bool tscProjectionQueryOnTable(SSqlCmd* pCmd);
|
bool tscProjectionQueryOnTable(SQueryInfo* pQueryInfo);
|
||||||
|
|
||||||
bool tscIsTwoStageMergeMetricQuery(SSqlCmd* pCmd);
|
bool tscIsTwoStageMergeMetricQuery(SSqlCmd* pCmd);
|
||||||
bool tscQueryOnMetric(SSqlCmd* pCmd);
|
bool tscQueryOnMetric(SSqlCmd* pCmd);
|
||||||
bool tscQueryMetricTags(SSqlCmd* pCmd);
|
bool tscQueryMetricTags(SQueryInfo* pQueryInfo);
|
||||||
bool tscIsSelectivityWithTagQuery(SSqlCmd* pCmd);
|
bool tscIsSelectivityWithTagQuery(SSqlCmd* pCmd);
|
||||||
|
|
||||||
void tscAddSpecialColumnForSelect(SSqlCmd* pCmd, int32_t outputColIndex, int16_t functionId, SColumnIndex* pIndex,
|
void tscAddSpecialColumnForSelect(SQueryInfo* pQueryInfo, int32_t outputColIndex, int16_t functionId, SColumnIndex* pIndex,
|
||||||
SSchema* pColSchema, int16_t isTag);
|
SSchema* pColSchema, int16_t isTag);
|
||||||
|
|
||||||
void addRequiredTagColumn(SSqlCmd* pCmd, int32_t tagColIndex, int32_t tableIndex);
|
void addRequiredTagColumn(SQueryInfo* 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(SSqlCmd* pCmd);
|
void tscClearInterpInfo(SQueryInfo* pQueryInfo);
|
||||||
|
|
||||||
bool tscIsInsertOrImportData(char* sqlstr);
|
bool tscIsInsertOrImportData(char* sqlstr);
|
||||||
|
|
||||||
|
@ -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(SSqlCmd* pCmd);
|
void tscFieldInfoCalOffset(SQueryInfo* pQueryInfo);
|
||||||
void tscFieldInfoUpdateOffset(SSqlCmd* pCmd);
|
void tscFieldInfoUpdateOffset(SQueryInfo* 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(SSqlCmd* pCmd, int32_t index);
|
TAOS_FIELD* tscFieldInfoGetField(SQueryInfo* pQueryInfo, int32_t index);
|
||||||
int16_t tscFieldInfoGetOffset(SSqlCmd* pCmd, int32_t index);
|
int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index);
|
||||||
int32_t tscGetResRowLength(SSqlCmd* pCmd);
|
int32_t tscGetResRowLength(SQueryInfo* pQueryInfo);
|
||||||
void tscClearFieldInfo(SFieldInfo* pFieldInfo);
|
void tscClearFieldInfo(SFieldInfo* pFieldInfo);
|
||||||
int32_t tscNumOfFields(SSqlCmd* pCmd);
|
int32_t tscNumOfFields(SQueryInfo* 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(SSqlCmd* pCmd, int32_t index, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
|
SSqlExpr* tscSqlExprInsert(SQueryInfo* 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(SSqlCmd* pCmd, int32_t index, int16_t functionId);
|
SSqlExpr* tscSqlExprInsertEmpty(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId);
|
||||||
|
|
||||||
SSqlExpr* tscSqlExprUpdate(SSqlCmd* pCmd, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type,
|
SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type,
|
||||||
int16_t size);
|
int16_t size);
|
||||||
|
|
||||||
SSqlExpr* tscSqlExprGet(SSqlCmd* pCmd, int32_t index);
|
SSqlExpr* tscSqlExprGet(SQueryInfo* 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(SSqlCmd* pCmd, SColumnIndex* colIndex);
|
SColumnBase* tscColumnBaseInfoInsert(SQueryInfo* 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);
|
||||||
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, SSqlCmd* pCmd);
|
void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* 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(SSqlCmd* pCmd, int16_t functionId, int16_t tableIndex);
|
void tscAddTimestampColumn(SQueryInfo* pQueryInfo, int16_t functionId, int16_t tableIndex);
|
||||||
void tscDoQuery(SSqlObj* pSql);
|
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(SSqlCmd* pCmd, int32_t tagIndex);
|
void doAddGroupColumnForSubquery(SQueryInfo* 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,
|
||||||
|
|
||||||
void sortRemoveDuplicates(STableDataBlocks* dataBuf);
|
void sortRemoveDuplicates(STableDataBlocks* dataBuf);
|
||||||
|
|
||||||
void tscPrintSelectClause(SSqlCmd* pCmd);
|
void tscPrintSelectClause(SSqlCmd* pCmd, int32_t subClauseIndex);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
} 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 {
|
||||||
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 {
|
||||||
|
|
||||||
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 {
|
||||||
short numOfCols;
|
short numOfCols;
|
||||||
int64_t globalLimit;
|
int64_t globalLimit;
|
||||||
|
|
||||||
SQueryInfo *pQueryInfo;
|
SQueryInfo **pQueryInfo;
|
||||||
int32_t numOfQueries;
|
int32_t numOfClause;
|
||||||
|
|
||||||
// char intervalTimeUnit;
|
// char intervalTimeUnit;
|
||||||
// int64_t etime, stime;
|
// int64_t etime, stime;
|
||||||
|
@ -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(SSqlCmd *pCmd);
|
int32_t tscTansformSQLFunctionForMetricQuery(SQueryInfo* pQueryInfo);
|
||||||
void tscRestoreSQLFunctionForMetricQuery(SSqlCmd *pCmd);
|
void tscRestoreSQLFunctionForMetricQuery(SQueryInfo* pQueryInfo);
|
||||||
|
|
||||||
void tscClearSqlMetaInfoForce(SSqlCmd *pCmd);
|
void tscClearSqlMetaInfoForce(SSqlCmd *pCmd);
|
||||||
|
|
||||||
int32_t tscCreateResPointerInfo(SSqlCmd *pCmd, SSqlRes *pRes);
|
int32_t tscCreateResPointerInfo(SQueryInfo* 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
|
||||||
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
|
||||||
|
|
1037
src/client/src/sql.c
1037
src/client/src/sql.c
File diff suppressed because it is too large
Load Diff
|
@ -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 = tscGetMeterMetaInfoFromQueryInfo(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
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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) {
|
||||||
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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) {
|
||||||
}
|
}
|
||||||
} 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, pCmd, i, pCmd->order) + pRes->bytes[i] * pRes->row;
|
pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, 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) {
|
||||||
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, pCmd, i, pCmd->order) + pRes->bytes[i] * pRes->row;
|
pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, 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)
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -464,10 +476,11 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||||
} else {
|
} else {
|
||||||
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) {
|
||||||
|
|
||||||
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} 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) {
|
||||||
* 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);
|
||||||
|
|
|
@ -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;
|
|
||||||
|
SLimitVal* pLimit = &pQueryInfo->limit;
|
||||||
pSql->pSubs[0]->cmd.pQueryInfo->tsBuf = output1;
|
int32_t order = pQueryInfo->order.order;
|
||||||
pSql->pSubs[1]->cmd.pQueryInfo->tsBuf = output2;
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
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) {
|
||||||
* 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) {
|
||||||
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
|
||||||
pNew->cmd.type |= TSDB_QUERY_TYPE_JOIN_SEC_STAGE;
|
pQueryInfo->type |= TSDB_QUERY_TYPE_JOIN_SEC_STAGE;
|
||||||
|
|
||||||
pNew->cmd.pQueryInfo->nAggTimeInterval = pSupporter->interval;
|
pQueryInfo->nAggTimeInterval = pSupporter->interval;
|
||||||
pNew->cmd.pQueryInfo->groupbyExpr = pSupporter->groupbyExpr;
|
pQueryInfo->groupbyExpr = pSupporter->groupbyExpr;
|
||||||
|
|
||||||
tscColumnBaseInfoCopy(&pNew->cmd.pQueryInfo->colList, &pSupporter->colList, 0);
|
tscColumnBaseInfoCopy(&pQueryInfo->colList, &pSupporter->colList, 0);
|
||||||
tscTagCondCopy(&pNew->cmd.pQueryInfo->tagCond, &pSupporter->tagCond);
|
tscTagCondCopy(&pQueryInfo->tagCond, &pSupporter->tagCond);
|
||||||
|
|
||||||
tscSqlExprCopy(&pNew->cmd.pQueryInfo->exprsInfo, &pSupporter->exprsInfo, pSupporter->uid);
|
tscSqlExprCopy(&pQueryInfo->exprsInfo, &pSupporter->exprsInfo, pSupporter->uid);
|
||||||
tscFieldInfoCopyAll(&pSupporter->fieldsInfo, &pNew->cmd.pQueryInfo->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 && pNew->cmd.pQueryInfo->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 = tscGetMeterMetaInfoFromQueryInfo(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 = pSql->cmd.pQueryInfo->limit;
|
pSupporter->limit = pQueryInfo->limit;
|
||||||
pNew->cmd.pQueryInfo->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(pNew->cmd.pQueryInfo->tagCond.joinInfo.hasJoin);
|
assert(pQueryInfo->tagCond.joinInfo.hasJoin);
|
||||||
|
|
||||||
int16_t tagColIndex = tscGetJoinTagColIndexByUid(&pNew->cmd.pQueryInfo->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
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
|
assert(pQueryInfo->stime <= st && pQueryInfo->etime >= et);
|
||||||
|
|
||||||
pSql->cmd.pQueryInfo->stime = st;
|
pQueryInfo->stime = st;
|
||||||
pSql->cmd.pQueryInfo->etime = et;
|
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) {
|
||||||
SSqlObj* pParentSql = pSupporter->pObj;
|
SSqlObj* pParentSql = pSupporter->pObj;
|
||||||
|
|
||||||
SSqlObj* pSql = (SSqlObj*)tres;
|
SSqlObj* pSql = (SSqlObj*)tres;
|
||||||
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
if ((pSql->cmd.type & TSDB_QUERY_TYPE_JOIN_SEC_STAGE) == 0) {
|
|
||||||
|
if ((pQueryInfo->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) {
|
||||||
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(pSql->cmd.pQueryInfo->numOfTables == 1); // for subquery, only one metermetaInfo
|
assert(pQueryInfo->numOfTables == 1); // for subquery, only one metermetaInfo
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0);
|
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(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) {
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -477,10 +495,12 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
|
||||||
if (numOfRows >= 0) {
|
if (numOfRows >= 0) {
|
||||||
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) {
|
||||||
|
|
||||||
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;
|
||||||
SSqlCmd *pCmd = &pSql->pSubs[i]->cmd;
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->pSubs[i]->cmd, 0);
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(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) {
|
||||||
|
|
||||||
// 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 = tscGetMeterMetaInfoFromQueryInfo(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) {
|
||||||
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 < pCmd->pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
|
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||||
|
|
||||||
int32_t tableIndexOfSub = -1;
|
int32_t tableIndexOfSub = -1;
|
||||||
for (int32_t j = 0; j < pCmd->pQueryInfo->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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SSqlCmd* pSubCmd = &pSql->pSubs[tableIndexOfSub]->cmd;
|
SSqlCmd* pSubCmd = &pSql->pSubs[tableIndexOfSub]->cmd;
|
||||||
|
SQueryInfo* pSubQueryInfo = tscGetQueryInfoDetail(pSubCmd, 0);
|
||||||
for (int32_t k = 0; k < pSubCmd->pQueryInfo->exprsInfo.numOfExprs; ++k) {
|
|
||||||
SSqlExpr* pSubExpr = tscSqlExprGet(pSubCmd, k);
|
for (int32_t k = 0; k < pSubQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||||
|
SSqlExpr* pSubExpr = tscSqlExprGet(pSubQueryInfo, 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) {
|
||||||
|
|
||||||
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) {
|
||||||
|
|
||||||
// }
|
// }
|
||||||
// } 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) {
|
||||||
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
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
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) {
|
||||||
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) {
|
||||||
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(pCmd, 0);
|
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 0);
|
||||||
strncpy(pRes->data + tscFieldInfoGetOffset(pCmd, 0) * totalNumOfRows + pField->bytes * i, pSchema[i].name,
|
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 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(pCmd, 1);
|
pField = tscFieldInfoGetField(pQueryInfo, 1);
|
||||||
strncpy(pRes->data + tscFieldInfoGetOffset(pCmd, 1) * totalNumOfRows + pField->bytes * i, type, pField->bytes);
|
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 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(pCmd, 2);
|
pField = tscFieldInfoGetField(pQueryInfo, 2);
|
||||||
*(int32_t *)(pRes->data + tscFieldInfoGetOffset(pCmd, 2) * totalNumOfRows + pField->bytes * i) = bytes;
|
*(int32_t *)(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 2) * totalNumOfRows + pField->bytes * i) = bytes;
|
||||||
|
|
||||||
pField = tscFieldInfoGetField(pCmd, 3);
|
pField = tscFieldInfoGetField(pQueryInfo, 3);
|
||||||
if (i >= pMeta->numOfColumns && pMeta->numOfTags != 0) {
|
if (i >= pMeta->numOfColumns && pMeta->numOfTags != 0) {
|
||||||
strncpy(pRes->data + tscFieldInfoGetOffset(pCmd, 3) * totalNumOfRows + pField->bytes * i, "tag",
|
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 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) {
|
||||||
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(pCmd, 0);
|
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 0);
|
||||||
strncpy(pRes->data + tscFieldInfoGetOffset(pCmd, 0) * totalNumOfRows + pField->bytes * i, pSchema[i].name,
|
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 0) * totalNumOfRows + pField->bytes * i, pSchema[i].name,
|
||||||
TSDB_COL_NAME_LEN);
|
TSDB_COL_NAME_LEN);
|
||||||
|
|
||||||
// type name
|
// type name
|
||||||
pField = tscFieldInfoGetField(pCmd, 1);
|
pField = tscFieldInfoGetField(pQueryInfo, 1);
|
||||||
char *type = tDataTypeDesc[pSchema[i].type].aName;
|
char *type = tDataTypeDesc[pSchema[i].type].aName;
|
||||||
strncpy(pRes->data + tscFieldInfoGetOffset(pCmd, 1) * totalNumOfRows + pField->bytes * i, type, pField->bytes);
|
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 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(pCmd, 2);
|
pField = tscFieldInfoGetField(pQueryInfo, 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(pCmd, 2) * totalNumOfRows + pField->bytes * i) = bytes;
|
*(int32_t *)(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 2) * totalNumOfRows + pField->bytes * i) = bytes;
|
||||||
|
|
||||||
// tag value
|
// tag value
|
||||||
pField = tscFieldInfoGetField(pCmd, 3);
|
pField = tscFieldInfoGetField(pQueryInfo, 3);
|
||||||
char *target = pRes->data + tscFieldInfoGetOffset(pCmd, 3) * totalNumOfRows + pField->bytes * i;
|
char *target = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 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,
|
||||||
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(&pCmd->pQueryInfo->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(&pCmd->pQueryInfo->fieldsInfo, 1, TSDB_DATA_TYPE_BINARY, "Type", typeColLength);
|
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 1, TSDB_DATA_TYPE_BINARY, "Type", typeColLength);
|
||||||
rowLen += typeColLength;
|
rowLen += typeColLength;
|
||||||
|
|
||||||
tscFieldInfoSetValue(&pCmd->pQueryInfo->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(&pCmd->pQueryInfo->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) {
|
||||||
|
|
||||||
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) {
|
||||||
// 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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t totalNumOfResults = pMetricMeta->numOfMeters;
|
int32_t totalNumOfResults = pMetricMeta->numOfMeters;
|
||||||
int32_t rowLen = tscGetResRowLength(pCmd);
|
int32_t rowLen = tscGetResRowLength(pQueryInfo);
|
||||||
|
|
||||||
tscInitResObjForLocalQuery(pSql, totalNumOfResults, rowLen);
|
tscInitResObjForLocalQuery(pSql, totalNumOfResults, rowLen);
|
||||||
|
|
||||||
|
@ -320,17 +326,17 @@ 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 < pCmd->pQueryInfo->fieldsInfo.numOfOutputCols; ++k) {
|
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutputCols; ++k) {
|
||||||
SColIndexEx *pColIndex = &tscSqlExprGet(pCmd, k)->colInfo;
|
SColIndexEx *pColIndex = &tscSqlExprGet(pQueryInfo, 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(pCmd, k);
|
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, k);
|
||||||
|
|
||||||
memcpy(pRes->data + tscFieldInfoGetOffset(pCmd, k) * totalNumOfResults + pField->bytes * rowIdx, val,
|
memcpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 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) {
|
||||||
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(pCmd);
|
int32_t rowLen = tscGetResRowLength(pQueryInfo);
|
||||||
|
|
||||||
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 < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++k) {
|
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutputCols; ++k) {
|
||||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
|
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 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(pCmd, k);
|
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, k);
|
||||||
|
|
||||||
memcpy(pRes->data + tscFieldInfoGetOffset(pCmd, i) * totalNumOfResults + pField->bytes * rowIdx,
|
memcpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 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");
|
||||||
|
@ -373,15 +381,17 @@ 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(pCmd, 0);
|
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
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) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
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(&pCmd->pQueryInfo[0].fieldsInfo, 0, TSDB_DATA_TYPE_BINARY, columnName, valueLength);
|
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 0, TSDB_DATA_TYPE_BINARY, columnName, valueLength);
|
||||||
tscInitResObjForLocalQuery(pSql, 1, valueLength);
|
tscInitResObjForLocalQuery(pSql, 1, valueLength);
|
||||||
|
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, 0);
|
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 0);
|
||||||
strncpy(pRes->data, val, pField->bytes);
|
strncpy(pRes->data, val, pField->bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
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) {
|
||||||
|
|
||||||
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) {
|
||||||
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) {
|
||||||
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) {
|
||||||
* @param pSql
|
* @param pSql
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int doParserInsertSql(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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//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) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
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) {
|
||||||
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:
|
||||||
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
||||||
|
|
||||||
_clean:
|
_clean:
|
||||||
taosCleanUpIntHash(pSql->pTableHashList);
|
taosCleanUpHashTable(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) {
|
||||||
pCmd->isInsertFromFile = -1;
|
pCmd->isInsertFromFile = -1;
|
||||||
pSql->res.numOfRows = 0;
|
pSql->res.numOfRows = 0;
|
||||||
|
|
||||||
return doParserInsertSql(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
|
||||||
tscRemoveAllMeterMetaInfo(&pSql->cmd, false);
|
// tscRemoveMeterMetaInfo(&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
|
||||||
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) {
|
||||||
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
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;
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
++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
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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(pCmd, i) * pReducer->resColModel->maxCapacity;
|
pCtx->aOutputBuf = pReducer->pResultBuf->data + tscFieldInfoGetOffset(pQueryInfo, i) * pReducer->resColModel->maxCapacity;
|
||||||
pCtx->order = pCmd->order.order;
|
pCtx->order = pQueryInfo->order.order;
|
||||||
pCtx->functionId = pCmd->pQueryInfo[0].exprsInfo.pExprs[i].functionId;
|
pCtx->functionId = pQueryInfo->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
|
||||||
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(pCmd, i);
|
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 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
|
||||||
|
|
||||||
pRes->bytes[i] = pField->bytes;
|
pRes->bytes[i] = pField->bytes;
|
||||||
|
|
||||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
|
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 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 = pCmd->order.order;
|
pCtx->param[2].i64Key = pQueryInfo->order.order;
|
||||||
pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT;
|
pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT;
|
||||||
pCtx->param[1].i64Key = pCmd->order.orderColId;
|
pCtx->param[1].i64Key = pQueryInfo->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
|
||||||
|
|
||||||
int16_t n = 0;
|
int16_t n = 0;
|
||||||
int16_t tagLen = 0;
|
int16_t tagLen = 0;
|
||||||
SQLFunctionCtx** pTagCtx = calloc(pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, POINTER_BYTES);
|
SQLFunctionCtx** pTagCtx = calloc(pQueryInfo->fieldsInfo.numOfOutputCols, POINTER_BYTES);
|
||||||
|
|
||||||
SQLFunctionCtx* pCtx = NULL;
|
SQLFunctionCtx* pCtx = NULL;
|
||||||
for(int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for(int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
|
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 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
|
||||||
#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
|
||||||
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
|
||||||
|
|
||||||
// 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(pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, sizeof(SQLFunctionCtx));
|
pReducer->pCtx = (SQLFunctionCtx *)calloc(pQueryInfo->fieldsInfo.numOfOutputCols, sizeof(SQLFunctionCtx));
|
||||||
|
|
||||||
pReducer->rowSize = pMemBuffer[0]->nElemSize;
|
pReducer->rowSize = pMemBuffer[0]->nElemSize;
|
||||||
|
|
||||||
tscRestoreSQLFunctionForMetricQuery(pCmd);
|
tscRestoreSQLFunctionForMetricQuery(pQueryInfo);
|
||||||
tscFieldInfoCalOffset(pCmd);
|
tscFieldInfoCalOffset(pQueryInfo);
|
||||||
|
|
||||||
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
|
||||||
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(pCmd);
|
int32_t finalRowLength = tscGetResRowLength(pQueryInfo);
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
pReducer->pTempBuffer->numOfElems = 0;
|
pReducer->pTempBuffer->numOfElems = 0;
|
||||||
pReducer->pResInfo = calloc((size_t)pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, sizeof(SResultInfo));
|
pReducer->pResInfo = calloc((size_t)pQueryInfo->fieldsInfo.numOfOutputCols, sizeof(SResultInfo));
|
||||||
|
|
||||||
tscCreateResPointerInfo(pCmd, pRes);
|
tscCreateResPointerInfo(pQueryInfo, 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 = pCmd->pQueryInfo->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 = (pCmd->pQueryInfo[0].stime < pCmd->pQueryInfo[0].etime) ? pCmd->pQueryInfo[0].stime : pCmd->pQueryInfo[0].etime;
|
int64_t stime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->stime : pQueryInfo->etime;
|
||||||
int64_t revisedSTime = taosGetIntervalStartTimestamp(stime, pCmd->pQueryInfo[0].nAggTimeInterval, pCmd->pQueryInfo[0].intervalTimeUnit, prec);
|
int64_t revisedSTime = taosGetIntervalStartTimestamp(stime, pQueryInfo->nAggTimeInterval, pQueryInfo->intervalTimeUnit, prec);
|
||||||
|
|
||||||
SInterpolationInfo *pInterpoInfo = &pReducer->interpolationInfo;
|
SInterpolationInfo *pInterpoInfo = &pReducer->interpolationInfo;
|
||||||
taosInitInterpoInfo(pInterpoInfo, pCmd->order.order, revisedSTime, pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols,
|
taosInitInterpoInfo(pInterpoInfo, pQueryInfo->order.order, revisedSTime, pQueryInfo->groupbyExpr.numOfGroupCols,
|
||||||
pReducer->rowSize);
|
pReducer->rowSize);
|
||||||
|
|
||||||
int32_t startIndex = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols - pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols;
|
int32_t startIndex = pQueryInfo->fieldsInfo.numOfOutputCols - pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||||
|
|
||||||
if (pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols > 0) {
|
if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) {
|
||||||
pInterpoInfo->pTags[0] = (char *)pInterpoInfo->pTags + POINTER_BYTES * pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols;
|
pInterpoInfo->pTags[0] = (char *)pInterpoInfo->pTags + POINTER_BYTES * pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||||
for (int32_t i = 1; i < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++i) {
|
for (int32_t i = 1; i < pQueryInfo->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,7 +434,8 @@ 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);
|
||||||
if (pLocalReducer != NULL) {
|
if (pLocalReducer != NULL) {
|
||||||
|
@ -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 < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for(int32_t i = 0; i < pQueryInfo->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) {
|
||||||
tfree(pLocalReducer->pResultBuf);
|
tfree(pLocalReducer->pResultBuf);
|
||||||
|
|
||||||
if (pLocalReducer->pResInfo != NULL) {
|
if (pLocalReducer->pResInfo != NULL) {
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
tfree(pLocalReducer->pResInfo[i].interResultBuf);
|
tfree(pLocalReducer->pResInfo[i].interResultBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 (pCmd->pQueryInfo[0].nAggTimeInterval != 0) {
|
if (pQueryInfo->nAggTimeInterval != 0) {
|
||||||
numOfGroupByCols++;
|
numOfGroupByCols++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,20 +517,20 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numOfGroupByCols > 0) {
|
if (numOfGroupByCols > 0) {
|
||||||
int32_t startCols = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols - pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols;
|
int32_t startCols = pQueryInfo->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 < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->groupbyExpr.numOfGroupCols; ++i) {
|
||||||
orderIdx[i] = startCols++;
|
orderIdx[i] = startCols++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCmd->pQueryInfo[0].nAggTimeInterval != 0) {
|
if (pQueryInfo->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, pCmd->order.order);
|
*pOrderDesc = tOrderDesCreate(orderIdx, numOfGroupByCols, pModel, pQueryInfo->order.order);
|
||||||
tfree(orderIdx);
|
tfree(orderIdx);
|
||||||
|
|
||||||
if (*pOrderDesc == NULL) {
|
if (*pOrderDesc == NULL) {
|
||||||
|
@ -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
|
||||||
|
|
||||||
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(pCmd->pQueryInfo[0].nAggTimeInterval > 0);
|
assert(pQueryInfo->nAggTimeInterval > 0);
|
||||||
pOrderDesc->orderIdx.numOfOrderedCols -= 1;
|
pOrderDesc->orderIdx.numOfOrderedCols -= 1;
|
||||||
} else { // simple group by query
|
} else { // simple group by query
|
||||||
assert(pCmd->pQueryInfo[0].nAggTimeInterval == 0);
|
assert(pQueryInfo->nAggTimeInterval == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// only one row exists
|
// only one row exists
|
||||||
|
@ -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
|
||||||
return pRes->code;
|
return pRes->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
pSchema = (SSchema *)calloc(1, sizeof(SSchema) * pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols);
|
pSchema = (SSchema *)calloc(1, sizeof(SSchema) * pQueryInfo->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
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t rlen = 0;
|
int32_t rlen = 0;
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
|
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 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
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t capacity = nBufferSizes / rlen;
|
int32_t capacity = nBufferSizes / rlen;
|
||||||
pModel = tColModelCreate(pSchema, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, capacity);
|
pModel = tColModelCreate(pSchema, pQueryInfo->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
|
||||||
return pRes->code;
|
return pRes->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(pSchema, 0, sizeof(SSchema) * pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols);
|
memset(pSchema, 0, sizeof(SSchema) * pQueryInfo->fieldsInfo.numOfOutputCols);
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i);
|
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 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, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, capacity);
|
*pFinalModel = tColModelCreate(pSchema, pQueryInfo->fieldsInfo.numOfOutputCols, capacity);
|
||||||
tfree(pSchema);
|
tfree(pSchema);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -714,15 +725,15 @@ void adjustLoserTreeFromNewData(SLocalReducer *pLocalReducer, SLocalDataSource *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SSqlCmd *pCmd, SInterpolationInfo *pInterpoInfo) {
|
void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo* 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 = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
||||||
int16_t prec = pMeterMetaInfo->pMeterMeta->precision;
|
int16_t prec = pMeterMetaInfo->pMeterMeta->precision;
|
||||||
|
|
||||||
int64_t stime = (pCmd->pQueryInfo[0].stime < pCmd->pQueryInfo[0].etime) ? pCmd->pQueryInfo[0].stime : pCmd->pQueryInfo[0].etime;
|
int64_t stime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->stime : pQueryInfo->etime;
|
||||||
int64_t revisedSTime = taosGetIntervalStartTimestamp(stime, pCmd->pQueryInfo[0].nAggTimeInterval, pCmd->pQueryInfo[0].intervalTimeUnit, prec);
|
int64_t revisedSTime = taosGetIntervalStartTimestamp(stime, pQueryInfo->nAggTimeInterval, pQueryInfo->intervalTimeUnit, prec);
|
||||||
|
|
||||||
taosInitInterpoInfo(pInterpoInfo, pCmd->order.order, revisedSTime, pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols,
|
taosInitInterpoInfo(pInterpoInfo, pQueryInfo->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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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(pCmd, i);
|
int32_t offset = tscFieldInfoGetOffset(pQueryInfo, 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 *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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(pCmd, i);
|
int32_t offset = tscFieldInfoGetOffset(pQueryInfo, 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,7 +787,8 @@ 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) {
|
||||||
/*
|
/*
|
||||||
* Release the SSqlObj is called, and it is int destroying function invoked by other thread.
|
* Release the SSqlObj is called, and it is int destroying function invoked by other thread.
|
||||||
|
@ -786,100 +798,101 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
||||||
assert(pRes->pLocalReducer == NULL);
|
assert(pRes->pLocalReducer == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCmd->pQueryInfo[0].nAggTimeInterval == 0 || pCmd->pQueryInfo[0].interpoType == TSDB_INTERPO_NONE) {
|
if (pQueryInfo->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 (pCmd->pQueryInfo->limit.offset > 0) {
|
if (pQueryInfo->limit.offset > 0) {
|
||||||
if (pCmd->pQueryInfo->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, pCmd->pQueryInfo->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 -= pCmd->pQueryInfo->limit.offset;
|
pRes->numOfRows -= pQueryInfo->limit.offset;
|
||||||
pRes->numOfTotal -= pCmd->pQueryInfo->limit.offset;
|
pRes->numOfTotal -= pQueryInfo->limit.offset;
|
||||||
pCmd->pQueryInfo->limit.offset = 0;
|
pQueryInfo->limit.offset = 0;
|
||||||
} else {
|
} else {
|
||||||
pCmd->pQueryInfo->limit.offset -= pRes->numOfRows;
|
pQueryInfo->limit.offset -= pRes->numOfRows;
|
||||||
pRes->numOfRows = 0;
|
pRes->numOfRows = 0;
|
||||||
pRes->numOfTotal = 0;
|
pRes->numOfTotal = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCmd->pQueryInfo->limit.limit >= 0 && pRes->numOfTotal > pCmd->pQueryInfo->limit.limit) {
|
if (pQueryInfo->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 - pCmd->pQueryInfo->limit.limit;
|
int32_t overFlow = pRes->numOfTotal - pQueryInfo->limit.limit;
|
||||||
|
|
||||||
assert(overFlow < pRes->numOfRows);
|
assert(overFlow < pRes->numOfRows);
|
||||||
|
|
||||||
pRes->numOfTotal = pCmd->pQueryInfo->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, pCmd, &pLocalReducer->interpolationInfo);
|
savePrevRecordAndSetupInterpoInfo(pLocalReducer, pQueryInfo, &pLocalReducer->interpolationInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t rowSize = tscGetResRowLength(pCmd);
|
int32_t rowSize = tscGetResRowLength(pQueryInfo);
|
||||||
// handle the descend order output
|
// handle the descend order output
|
||||||
if (pCmd->order.order == TSQL_SO_ASC) {
|
if (pQueryInfo->order.order == TSQL_SO_ASC) {
|
||||||
memcpy(pRes->data, pFinalDataPage->data, pRes->numOfRows * rowSize);
|
memcpy(pRes->data, pFinalDataPage->data, pRes->numOfRows * rowSize);
|
||||||
} else {
|
} else {
|
||||||
reversedCopyResultToDstBuf(pCmd, pRes, pFinalDataPage);
|
reversedCopyResultToDstBuf(pQueryInfo, 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 = (pCmd->pQueryInfo[0].stime < pCmd->pQueryInfo[0].etime) ? pCmd->pQueryInfo[0].etime : pCmd->pQueryInfo[0].stime;
|
int64_t actualETime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->etime : pQueryInfo->stime;
|
||||||
|
|
||||||
tFilePage **pResPages = malloc(POINTER_BYTES * pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols);
|
tFilePage **pResPages = malloc(POINTER_BYTES * pQueryInfo->fieldsInfo.numOfOutputCols);
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i);
|
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 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)) * pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols);
|
char ** srcData = (char **)malloc((POINTER_BYTES + sizeof(int32_t)) * pQueryInfo->fieldsInfo.numOfOutputCols);
|
||||||
int32_t *functions = (int32_t *)((char *)srcData + pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols * sizeof(void *));
|
int32_t *functions = (int32_t *)((char *)srcData + pQueryInfo->fieldsInfo.numOfOutputCols * sizeof(void *));
|
||||||
|
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
srcData[i] = pLocalReducer->pBufForInterpo + tscFieldInfoGetOffset(pCmd, i) * pInterpoInfo->numOfRawDataInRows;
|
srcData[i] = pLocalReducer->pBufForInterpo + tscFieldInfoGetOffset(pQueryInfo, i) * pInterpoInfo->numOfRawDataInRows;
|
||||||
functions[i] = tscSqlExprGet(pCmd, i)->functionId;
|
functions[i] = tscSqlExprGet(pQueryInfo, 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, pCmd->order.order, pCmd->pQueryInfo[0].nAggTimeInterval, pCmd->pQueryInfo[0].intervalTimeUnit,
|
TSKEY etime = taosGetRevisedEndKey(actualETime, pQueryInfo->order.order, pQueryInfo->nAggTimeInterval, pQueryInfo->intervalTimeUnit,
|
||||||
precision);
|
precision);
|
||||||
int32_t nrows = taosGetNumOfResultWithInterpo(pInterpoInfo, pPrimaryKeys, remains, pCmd->pQueryInfo[0].nAggTimeInterval, etime,
|
int32_t nrows = taosGetNumOfResultWithInterpo(pInterpoInfo, pPrimaryKeys, remains, pQueryInfo->nAggTimeInterval, etime,
|
||||||
pLocalReducer->resColModel->maxCapacity);
|
pLocalReducer->resColModel->maxCapacity);
|
||||||
|
|
||||||
int32_t newRows = taosDoInterpoResult(pInterpoInfo, pCmd->pQueryInfo[0].interpoType, pResPages, remains, nrows,
|
int32_t newRows = taosDoInterpoResult(pInterpoInfo, pQueryInfo->interpoType, pResPages, remains, nrows,
|
||||||
pCmd->pQueryInfo[0].nAggTimeInterval, pPrimaryKeys, pLocalReducer->resColModel, srcData,
|
pQueryInfo->nAggTimeInterval, pPrimaryKeys, pLocalReducer->resColModel, srcData,
|
||||||
pCmd->pQueryInfo[0].defaultVal, functions, pLocalReducer->resColModel->maxCapacity);
|
pQueryInfo->defaultVal, functions, pLocalReducer->resColModel->maxCapacity);
|
||||||
assert(newRows <= nrows);
|
assert(newRows <= nrows);
|
||||||
|
|
||||||
if (pCmd->pQueryInfo->limit.offset < newRows) {
|
if (pQueryInfo->limit.offset < newRows) {
|
||||||
newRows -= pCmd->pQueryInfo->limit.offset;
|
newRows -= pQueryInfo->limit.offset;
|
||||||
|
|
||||||
if (pCmd->pQueryInfo->limit.offset > 0) {
|
if (pQueryInfo->limit.offset > 0) {
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i);
|
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||||
memmove(pResPages[i]->data, pResPages[i]->data + pField->bytes * pCmd->pQueryInfo->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
|
||||||
pRes->numOfRows = newRows;
|
pRes->numOfRows = newRows;
|
||||||
pRes->numOfTotal += newRows;
|
pRes->numOfTotal += newRows;
|
||||||
|
|
||||||
pCmd->pQueryInfo->limit.offset = 0;
|
pQueryInfo->limit.offset = 0;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
pCmd->pQueryInfo->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
|
||||||
|
|
||||||
/* all output for current group are completed */
|
/* all output for current group are completed */
|
||||||
int32_t totalRemainRows =
|
int32_t totalRemainRows =
|
||||||
taosGetNumOfResWithoutLimit(pInterpoInfo, pPrimaryKeys, rpoints, pCmd->pQueryInfo[0].nAggTimeInterval, actualETime);
|
taosGetNumOfResWithoutLimit(pInterpoInfo, pPrimaryKeys, rpoints, pQueryInfo->nAggTimeInterval, actualETime);
|
||||||
if (totalRemainRows <= 0) {
|
if (totalRemainRows <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -911,33 +924,33 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pRes->numOfRows > 0) {
|
if (pRes->numOfRows > 0) {
|
||||||
if (pCmd->pQueryInfo->limit.limit >= 0 && pRes->numOfTotal > pCmd->pQueryInfo->limit.limit) {
|
if (pQueryInfo->limit.limit >= 0 && pRes->numOfTotal > pQueryInfo->limit.limit) {
|
||||||
int32_t overFlow = pRes->numOfTotal - pCmd->pQueryInfo->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 = pCmd->pQueryInfo->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, pCmd, pInterpoInfo);
|
savePrevRecordAndSetupInterpoInfo(pLocalReducer, pQueryInfo, pInterpoInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCmd->order.order == TSQL_SO_ASC) {
|
if (pQueryInfo->order.order == TSQL_SO_ASC) {
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i);
|
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 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(pCmd, pRes, pResPages, pLocalReducer);
|
reversedCopyFromInterpolationToDstBuf(pQueryInfo, pRes, pResPages, pLocalReducer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pFinalDataPage->numOfElems = 0;
|
pFinalDataPage->numOfElems = 0;
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
tfree(pResPages[i]);
|
tfree(pResPages[i]);
|
||||||
}
|
}
|
||||||
tfree(pResPages);
|
tfree(pResPages);
|
||||||
|
@ -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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t j = 0; j < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++j) {
|
for (int32_t j = 0; j < pQueryInfo->fieldsInfo.numOfOutputCols; ++j) {
|
||||||
int32_t functionId = tscSqlExprGet(pCmd, j)->functionId;
|
int32_t functionId = tscSqlExprGet(pQueryInfo, 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t getNumOfResultLocal(SSqlCmd *pCmd, SQLFunctionCtx *pCtx) {
|
static int64_t getNumOfResultLocal(SQueryInfo *pQueryInfo, SQLFunctionCtx *pCtx) {
|
||||||
int64_t maxOutput = 0;
|
int64_t maxOutput = 0;
|
||||||
|
|
||||||
for (int32_t j = 0; j < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++j) {
|
for (int32_t j = 0; j < pQueryInfo->exprsInfo.numOfExprs; ++j) {
|
||||||
int32_t functionId = tscSqlExprGet(pCmd, j)->functionId;
|
int32_t functionId = tscSqlExprGet(pQueryInfo, 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) {
|
||||||
* 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(SSqlCmd *pCmd, int32_t numOfRes, SLocalReducer *pLocalReducer) {
|
static void fillMultiRowsOfTagsVal(SQueryInfo* 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 < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++k) {
|
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutputCols; ++k) {
|
||||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, k);
|
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 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
|
||||||
assert(maxBufSize >= 0);
|
assert(maxBufSize >= 0);
|
||||||
|
|
||||||
char *buf = malloc((size_t) maxBufSize);
|
char *buf = malloc((size_t) maxBufSize);
|
||||||
for (int32_t k = 0; k < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++k) {
|
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutputCols; ++k) {
|
||||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, k);
|
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 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
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t finalizeRes(SSqlCmd *pCmd, SLocalReducer *pLocalReducer) {
|
int32_t finalizeRes(SQueryInfo* pQueryInfo, SLocalReducer *pLocalReducer) {
|
||||||
for (int32_t k = 0; k < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++k) {
|
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutputCols; ++k) {
|
||||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, k);
|
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 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) {
|
||||||
|
|
||||||
pLocalReducer->hasPrevRow = false;
|
pLocalReducer->hasPrevRow = false;
|
||||||
|
|
||||||
int32_t numOfRes = (int32_t)getNumOfResultLocal(pCmd, pLocalReducer->pCtx);
|
int32_t numOfRes = (int32_t)getNumOfResultLocal(pQueryInfo, pLocalReducer->pCtx);
|
||||||
pLocalReducer->pResultBuf->numOfElems += numOfRes;
|
pLocalReducer->pResultBuf->numOfElems += numOfRes;
|
||||||
|
|
||||||
fillMultiRowsOfTagsVal(pCmd, numOfRes, pLocalReducer);
|
fillMultiRowsOfTagsVal(pQueryInfo, numOfRes, pLocalReducer);
|
||||||
return numOfRes;
|
return numOfRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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(SSqlCmd *pCmd, SLocalReducer *pLocalReducer, tFilePage *tmpBuffer) {
|
bool needToMerge(SQueryInfo* 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(pCmd, 0)->functionId;
|
int16_t functionId = tscSqlExprGet(pQueryInfo, 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
|
||||||
return (ret == 0);
|
return (ret == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool reachGroupResultLimit(SSqlCmd *pCmd, SSqlRes *pRes) {
|
static bool reachGroupResultLimit(SQueryInfo* pQueryInfo, SSqlRes *pRes) {
|
||||||
return (pRes->numOfGroups >= pCmd->pQueryInfo[0].slimit.limit && pCmd->pQueryInfo[0].slimit.limit >= 0);
|
return (pRes->numOfGroups >= pQueryInfo->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(pCmd, pRes)) {
|
if (reachGroupResultLimit(pQueryInfo, pRes)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
* 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 (pCmd->pQueryInfo[0].slimit.offset > 0) {
|
if (pQueryInfo->slimit.offset > 0) {
|
||||||
pRes->numOfRows = 0;
|
pRes->numOfRows = 0;
|
||||||
pCmd->pQueryInfo[0].slimit.offset -= 1;
|
pQueryInfo->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
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SInterpolationInfo *pInterpoInfo = &pLocalReducer->interpolationInfo;
|
SInterpolationInfo *pInterpoInfo = &pLocalReducer->interpolationInfo;
|
||||||
int32_t startIndex = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols - pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols;
|
int32_t startIndex = pQueryInfo->fieldsInfo.numOfOutputCols - pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||||
|
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->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, pCmd->pQueryInfo[0].interpoType);
|
taosInterpoSetStartInfo(&pLocalReducer->interpolationInfo, pResBuf->numOfElems, pQueryInfo->interpoType);
|
||||||
doInterpolateResult(pSql, pLocalReducer, noMoreCurrentGroupRes);
|
doInterpolateResult(pSql, pLocalReducer, noMoreCurrentGroupRes);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetOutputBuf(SSqlCmd *pCmd, SLocalReducer *pLocalReducer) { // reset output buffer to the beginning
|
void resetOutputBuf(SQueryInfo* pQueryInfo, SLocalReducer *pLocalReducer) { // reset output buffer to the beginning
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
pLocalReducer->pCtx[i].aOutputBuf =
|
pLocalReducer->pCtx[i].aOutputBuf =
|
||||||
pLocalReducer->pResultBuf->data + tscFieldInfoGetOffset(pCmd, i) * pLocalReducer->resColModel->maxCapacity;
|
pLocalReducer->pResultBuf->data + tscFieldInfoGetOffset(pQueryInfo, 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
|
||||||
// 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 (pCmd->pQueryInfo[0].interpoType != TSDB_INTERPO_NONE) {
|
if (pQueryInfo->interpoType != TSDB_INTERPO_NONE) {
|
||||||
int64_t stime = (pCmd->pQueryInfo[0].stime < pCmd->pQueryInfo[0].etime) ? pCmd->pQueryInfo[0].stime : pCmd->pQueryInfo[0].etime;
|
int64_t stime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->stime : pQueryInfo->etime;
|
||||||
int64_t newTime = taosGetIntervalStartTimestamp(stime, pCmd->pQueryInfo[0].nAggTimeInterval, pCmd->pQueryInfo[0].intervalTimeUnit, precision);
|
int64_t newTime = taosGetIntervalStartTimestamp(stime, pQueryInfo->nAggTimeInterval, pQueryInfo->intervalTimeUnit, precision);
|
||||||
|
|
||||||
taosInitInterpoInfo(&pLocalReducer->interpolationInfo, pCmd->order.order, newTime, pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols,
|
taosInitInterpoInfo(&pLocalReducer->interpolationInfo, pQueryInfo->order.order, newTime, pQueryInfo->groupbyExpr.numOfGroupCols,
|
||||||
pLocalReducer->rowSize);
|
pLocalReducer->rowSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
||||||
int8_t p = pMeterMetaInfo->pMeterMeta->precision;
|
int8_t p = pMeterMetaInfo->pMeterMeta->precision;
|
||||||
|
|
||||||
if (taosHasRemainsDataForInterpolation(pInterpoInfo)) {
|
if (taosHasRemainsDataForInterpolation(pInterpoInfo)) {
|
||||||
assert(pCmd->pQueryInfo[0].interpoType != TSDB_INTERPO_NONE);
|
assert(pQueryInfo->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, pCmd->order.order, pCmd->pQueryInfo[0].nAggTimeInterval, pCmd->pQueryInfo[0].intervalTimeUnit, p);
|
TSKEY ekey = taosGetRevisedEndKey(etime, pQueryInfo->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,
|
||||||
pCmd->pQueryInfo[0].nAggTimeInterval, ekey, pLocalReducer->resColModel->maxCapacity);
|
pQueryInfo->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) {
|
||||||
|
|
||||||
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 (pCmd->pQueryInfo[0].interpoType != TSDB_INTERPO_NONE) {
|
if (pQueryInfo->interpoType != TSDB_INTERPO_NONE) {
|
||||||
int64_t etime = (pCmd->pQueryInfo[0].stime < pCmd->pQueryInfo[0].etime) ? pCmd->pQueryInfo[0].etime : pCmd->pQueryInfo[0].stime;
|
int64_t etime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->etime : pQueryInfo->stime;
|
||||||
|
|
||||||
etime = taosGetRevisedEndKey(etime, pCmd->order.order, pCmd->pQueryInfo[0].nAggTimeInterval, pCmd->pQueryInfo[0].intervalTimeUnit, precision);
|
etime = taosGetRevisedEndKey(etime, pQueryInfo->order.order, pQueryInfo->nAggTimeInterval, pQueryInfo->intervalTimeUnit, precision);
|
||||||
int32_t rows = taosGetNumOfResultWithInterpo(pInterpoInfo, NULL, 0, pCmd->pQueryInfo[0].nAggTimeInterval, etime,
|
int32_t rows = taosGetNumOfResultWithInterpo(pInterpoInfo, NULL, 0, pQueryInfo->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) {
|
||||||
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 < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++k) {
|
|
||||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, k);
|
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutputCols; ++k) {
|
||||||
|
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, k);
|
||||||
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[k];
|
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[k];
|
||||||
|
|
||||||
pCtx->aOutputBuf += pCtx->outputBytes * numOfRes;
|
pCtx->aOutputBuf += pCtx->outputBytes * numOfRes;
|
||||||
|
@ -1325,7 +1349,8 @@ 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 =
|
||||||
atomic_val_compare_exchange_32(&pLocalReducer->status, TSC_LOCALREDUCE_READY, TSC_LOCALREDUCE_IN_PROGRESS);
|
atomic_val_compare_exchange_32(&pLocalReducer->status, TSC_LOCALREDUCE_READY, TSC_LOCALREDUCE_IN_PROGRESS);
|
||||||
|
@ -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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pLocalReducer->hasPrevRow) {
|
if (pLocalReducer->hasPrevRow) {
|
||||||
if (needToMerge(pCmd, pLocalReducer, tmpBuffer)) {
|
if (needToMerge(pQueryInfo, 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) {
|
||||||
* 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(pCmd, pLocalReducer);
|
int32_t numOfRes = finalizeRes(pQueryInfo, 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) {
|
||||||
pLocalReducer->hasUnprocessedRow = true;
|
pLocalReducer->hasUnprocessedRow = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
resetOutputBuf(pCmd, pLocalReducer);
|
resetOutputBuf(pQueryInfo, 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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pLocalReducer->hasPrevRow) {
|
if (pLocalReducer->hasPrevRow) {
|
||||||
finalizeRes(pCmd, pLocalReducer);
|
finalizeRes(pQueryInfo, pLocalReducer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pLocalReducer->pResultBuf->numOfElems) {
|
if (pLocalReducer->pResultBuf->numOfElems) {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -320,8 +320,9 @@ int taos_affected_rows(TAOS *taos) {
|
||||||
TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
|
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) {
|
||||||
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 (pCmd->order.order == TSQL_SO_DESC) ? pRes->numOfRows : -pRes->numOfRows;
|
return (pQueryInfo->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 < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for (int i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pCmd, i, pCmd->order) + pRes->bytes[i] * pRes->row;
|
pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, 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 && pCmd->pQueryInfo[0].nAggTimeInterval > 0) {
|
if (i == 0 && pQueryInfo->nAggTimeInterval > 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i);
|
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 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) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(num <= pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols);
|
assert(num <= pQueryInfo->fieldsInfo.numOfOutputCols);
|
||||||
|
|
||||||
return pRes->tsrow;
|
return pRes->tsrow;
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
} 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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -498,9 +502,11 @@ static void **tscJoinResultsetFromBuf(SSqlObj *pSql) {
|
||||||
free(pState);
|
free(pState);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
if (pRes->tsrow == NULL) {
|
if (pRes->tsrow == NULL) {
|
||||||
pRes->tsrow = malloc(POINTER_BYTES * pCmd->pQueryInfo[0].exprsInfo.numOfExprs);
|
pRes->tsrow = malloc(POINTER_BYTES * pQueryInfo->exprsInfo.numOfExprs);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
@ -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 < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->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) {
|
||||||
|
|
||||||
// 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) {
|
||||||
* 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;
|
||||||
*/
|
*/
|
||||||
pCmd->pQueryInfo->limit.limit = pCmd->globalLimit - pRes->numOfTotal;
|
pQueryInfo->limit.limit = pCmd->globalLimit - pRes->numOfTotal;
|
||||||
pCmd->pQueryInfo->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) {
|
||||||
// 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 = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
||||||
|
|
||||||
/* update the limit value according to current retrieval results */
|
/* update the limit value according to current retrieval results */
|
||||||
pCmd->pQueryInfo->limit.limit = pSql->cmd.globalLimit - pRes->numOfTotal;
|
pQueryInfo->limit.limit = pSql->cmd.globalLimit - pRes->numOfTotal;
|
||||||
pCmd->pQueryInfo->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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 = tscGetMeterMetaInfoFromQueryInfo(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) {
|
||||||
|
|
||||||
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
|
||||||
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
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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(SSqlCmd *pCmd) {
|
static bool isProjectStream(SQueryInfo* pQueryInfo) {
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
|
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 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) {
|
||||||
|
|
||||||
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) {
|
||||||
|
|
||||||
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)) {
|
||||||
/*
|
/*
|
||||||
* pSql->cmd.pQueryInfo[0].etime, which is the start time, does not change in case of
|
* pQueryInfo->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.
|
||||||
*/
|
*/
|
||||||
pSql->cmd.pQueryInfo[0].stime = pStream->stime; // start time
|
pQueryInfo->stime = pStream->stime; // start time
|
||||||
|
|
||||||
pSql->cmd.pQueryInfo[0].etime = taosGetTimestamp(pStream->precision); // end time
|
pQueryInfo->etime = taosGetTimestamp(pStream->precision); // end time
|
||||||
if (pSql->cmd.pQueryInfo[0].etime > pStream->etime) {
|
if (pQueryInfo->etime > pStream->etime) {
|
||||||
pSql->cmd.pQueryInfo[0].etime = pStream->etime;
|
pQueryInfo->etime = pStream->etime;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pSql->cmd.pQueryInfo[0].stime = pStream->stime - pStream->interval;
|
pQueryInfo->stime = pStream->stime - pStream->interval;
|
||||||
pSql->cmd.pQueryInfo[0].etime = pStream->stime - 1;
|
pQueryInfo->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
|
||||||
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) {
|
||||||
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
|
||||||
|
|
||||||
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
|
||||||
} 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 */
|
||||||
|
@ -209,12 +214,12 @@ 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 < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
|
int16_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
|
||||||
|
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||||
|
|
||||||
for (int32_t i = 1; i < pSql->cmd.pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
assignVal(pSql->res.data + offset, (char *)(&pQueryInfo->defaultVal[i]), pField->bytes, pField->type);
|
||||||
int16_t offset = tscFieldInfoGetOffset(pCmd, i);
|
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i);
|
|
||||||
|
|
||||||
assignVal(pSql->res.data + offset, (char *)(&pCmd->pQueryInfo[0].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
|
||||||
row[0] = pRes->data;
|
row[0] = pRes->data;
|
||||||
|
|
||||||
// char result[512] = {0};
|
// char result[512] = {0};
|
||||||
// taos_print_row(result, row, pSql->cmd.pQueryInfo[0].fieldsInfo.pFields, pSql->cmd.pQueryInfo[0].fieldsInfo.numOfOutputCols);
|
// taos_print_row(result, row, pQueryInfo->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
|
||||||
|
|
||||||
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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
@ -291,8 +298,9 @@ 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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
pCmd->pQueryInfo[0].nAggTimeInterval, minIntervalTime);
|
pQueryInfo->nAggTimeInterval, minIntervalTime);
|
||||||
pCmd->pQueryInfo[0].nAggTimeInterval = minIntervalTime;
|
pQueryInfo->nAggTimeInterval = minIntervalTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
pStream->interval = pCmd->pQueryInfo[0].nAggTimeInterval; // it shall be derived from sql string
|
pStream->interval = pQueryInfo->nAggTimeInterval; // it shall be derived from sql string
|
||||||
|
|
||||||
if (pCmd->pQueryInfo[0].nSlidingTime == 0) {
|
if (pQueryInfo->nSlidingTime == 0) {
|
||||||
pCmd->pQueryInfo[0].nSlidingTime = pCmd->pQueryInfo[0].nAggTimeInterval;
|
pQueryInfo->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 (pCmd->pQueryInfo[0].nSlidingTime < minSlidingTime) {
|
if (pQueryInfo->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,
|
||||||
pCmd->pQueryInfo[0].nSlidingTime, minSlidingTime);
|
pQueryInfo->nSlidingTime, minSlidingTime);
|
||||||
|
|
||||||
pCmd->pQueryInfo[0].nSlidingTime = minSlidingTime;
|
pQueryInfo->nSlidingTime = minSlidingTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCmd->pQueryInfo[0].nSlidingTime > pCmd->pQueryInfo[0].nAggTimeInterval) {
|
if (pQueryInfo->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,
|
||||||
pCmd->pQueryInfo[0].nSlidingTime, pCmd->pQueryInfo[0].nAggTimeInterval);
|
pQueryInfo->nSlidingTime, pQueryInfo->nAggTimeInterval);
|
||||||
|
|
||||||
pCmd->pQueryInfo[0].nSlidingTime = pCmd->pQueryInfo[0].nAggTimeInterval;
|
pQueryInfo->nSlidingTime = pQueryInfo->nAggTimeInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
pStream->slidingTime = pCmd->pQueryInfo[0].nSlidingTime;
|
pStream->slidingTime = pQueryInfo->nSlidingTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, int64_t stime) {
|
static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, int64_t stime) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
if (isProjectStream(pCmd)) {
|
if (isProjectStream(pQueryInfo)) {
|
||||||
// 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 >= pCmd->pQueryInfo[0].stime);
|
assert(stime >= pQueryInfo->stime);
|
||||||
stime += 1; // exclude the last records from table
|
stime += 1; // exclude the last records from table
|
||||||
} else {
|
} else {
|
||||||
stime = pCmd->pQueryInfo[0].stime;
|
stime = pQueryInfo->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
|
||||||
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
|
||||||
pStream->precision = pMeterMetaInfo->pMeterMeta->precision;
|
pStream->precision = pMeterMetaInfo->pMeterMeta->precision;
|
||||||
|
|
||||||
pStream->ctime = taosGetTimestamp(pStream->precision);
|
pStream->ctime = taosGetTimestamp(pStream->precision);
|
||||||
pStream->etime = pCmd->pQueryInfo[0].etime;
|
pStream->etime = pQueryInfo->etime;
|
||||||
|
|
||||||
pSql->pStream = pStream;
|
pSql->pStream = pStream;
|
||||||
tscAddIntoStreamList(pStream);
|
tscAddIntoStreamList(pStream);
|
||||||
|
|
|
@ -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) {
|
||||||
len += sprintf(&tagIdBuf[len], "%d,", pMeterMetaInfo->tagColumnIndex[i]);
|
len += sprintf(&tagIdBuf[len], "%d,", pMeterMetaInfo->tagColumnIndex[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
STagCond* pTagCond = &pCmd->pQueryInfo[0].tagCond;
|
STagCond* pTagCond = &pQueryInfo->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) {
|
||||||
|
|
||||||
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, pCmd->pQueryInfo[0].groupbyExpr.orderType);
|
pTagCond->relType, join, tagIdBuf, pQueryInfo->groupbyExpr.orderType);
|
||||||
|
|
||||||
assert(keyLen <= bufSize);
|
assert(keyLen <= bufSize);
|
||||||
|
|
||||||
|
@ -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(SSqlCmd* pCmd) {
|
bool tscQueryMetricTags(SQueryInfo* pQueryInfo) {
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
if (tscSqlExprGet(pCmd, i)->functionId != TSDB_FUNC_TAGPRJ) {
|
if (tscSqlExprGet(pQueryInfo, i)->functionId != TSDB_FUNC_TAGPRJ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
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 (((pCmd->type & TSDB_QUERY_TYPE_STABLE_SUBQUERY) != TSDB_QUERY_TYPE_STABLE_SUBQUERY) &&
|
if (((pQueryInfo->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 || pCmd->pQueryInfo[0].exprsInfo.numOfExprs == 0) {
|
pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pQueryInfo->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(pCmd)) {
|
if (tscQueryMetricTags(pQueryInfo)) {
|
||||||
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 < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
int32_t functionId = tscSqlExprGet(pCmd, i)->functionId;
|
int32_t functionId = tscSqlExprGet(pQueryInfo, 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) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tscProjectionQueryOnTable(SSqlCmd* pCmd) {
|
bool tscProjectionQueryOnTable(SQueryInfo* pQueryInfo) {
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
int32_t functionId = tscSqlExprGet(pCmd, i)->functionId;
|
int32_t functionId = tscSqlExprGet(pQueryInfo, 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) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tscIsPointInterpQuery(SSqlCmd* pCmd) {
|
bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo) {
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||||
SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
|
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||||
if (pExpr == NULL) {
|
if (pExpr == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -283,9 +297,9 @@ bool tscIsPointInterpQuery(SSqlCmd* pCmd) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tscIsTWAQuery(SSqlCmd* pCmd) {
|
bool tscIsTWAQuery(SQueryInfo* pQueryInfo) {
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||||
SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
|
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||||
if (pExpr == NULL) {
|
if (pExpr == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -299,30 +313,28 @@ bool tscIsTWAQuery(SSqlCmd* pCmd) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscClearInterpInfo(SSqlCmd* pCmd) {
|
void tscClearInterpInfo(SQueryInfo* pQueryInfo) {
|
||||||
if (!tscIsPointInterpQuery(pCmd)) {
|
if (!tscIsPointInterpQuery(pQueryInfo)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pCmd->pQueryInfo[0].interpoType = TSDB_INTERPO_NONE;
|
pQueryInfo->interpoType = TSDB_INTERPO_NONE;
|
||||||
memset(pCmd->pQueryInfo[0].defaultVal, 0, sizeof(pCmd->pQueryInfo[0].defaultVal));
|
memset(pQueryInfo->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(SSqlCmd* pCmd, SSqlRes* pRes) {
|
int32_t tscCreateResPointerInfo(SQueryInfo* pQueryInfo, SSqlRes* pRes) {
|
||||||
if (pRes->tsrow == NULL) {
|
if (pRes->tsrow == NULL) {
|
||||||
pRes->numOfnchar = 0;
|
pRes->numOfnchar = 0;
|
||||||
int32_t numOfOutputCols = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols;
|
int32_t numOfOutputCols = pQueryInfo->fieldsInfo.numOfOutputCols;
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < numOfOutputCols; ++i) {
|
||||||
TAOS_FIELD* pField = tscFieldInfoGetField(pCmd, i);
|
TAOS_FIELD* pField = tscFieldInfoGetField(pQueryInfo, 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) {
|
||||||
|
|
||||||
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) {
|
||||||
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) {
|
||||||
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) {
|
||||||
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
|
||||||
pFieldInfo->numOfOutputCols++;
|
pFieldInfo->numOfOutputCols++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscFieldInfoCalOffset(SSqlCmd* pCmd) {
|
void tscFieldInfoCalOffset(SQueryInfo* pQueryInfo) {
|
||||||
SFieldInfo* pFieldInfo = &pCmd->pQueryInfo[0].fieldsInfo;
|
SFieldInfo* pFieldInfo = &pQueryInfo->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) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscFieldInfoUpdateOffset(SSqlCmd* pCmd) {
|
void tscFieldInfoUpdateOffset(SQueryInfo* pQueryInfo) {
|
||||||
SFieldInfo* pFieldInfo = &pCmd->pQueryInfo[0].fieldsInfo;
|
SFieldInfo* pFieldInfo = &pQueryInfo->fieldsInfo;
|
||||||
if (pFieldInfo->numOfOutputCols == 0) {
|
if (pFieldInfo->numOfOutputCols == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -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(pCmd, i - 1)->resBytes;
|
pFieldInfo->pOffset[i] = pFieldInfo->pOffset[i - 1] + tscSqlExprGet(pQueryInfo, i - 1)->resBytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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(SSqlCmd* pCmd, int32_t index) {
|
TAOS_FIELD* tscFieldInfoGetField(SQueryInfo* pQueryInfo, int32_t index) {
|
||||||
if (index >= pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols) {
|
if (index >= pQueryInfo->fieldsInfo.numOfOutputCols) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return &pCmd->pQueryInfo[0].fieldsInfo.pFields[index];
|
return &pQueryInfo->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(SSqlCmd* pCmd, int32_t index) {
|
int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index) {
|
||||||
if (index >= pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols) {
|
if (index >= pQueryInfo->fieldsInfo.numOfOutputCols) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pCmd->pQueryInfo[0].fieldsInfo.pOffset[index];
|
return pQueryInfo->fieldsInfo.pOffset[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tscGetResRowLength(SSqlCmd* pCmd) {
|
int32_t tscGetResRowLength(SQueryInfo* pQueryInfo) {
|
||||||
SFieldInfo* pFieldInfo = &pCmd->pQueryInfo[0].fieldsInfo;
|
SFieldInfo* pFieldInfo = &pQueryInfo->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) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SSqlExpr* tscSqlExprInsertEmpty(SSqlCmd* pCmd, int32_t index, int16_t functionId) {
|
SSqlExpr* tscSqlExprInsertEmpty(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId) {
|
||||||
SSqlExprInfo* pExprInfo = &pCmd->pQueryInfo[0].exprsInfo;
|
SSqlExprInfo* pExprInfo = &pQueryInfo->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
|
||||||
return pExpr;
|
return pExpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
|
SSqlExpr* tscSqlExprInsert(SQueryInfo* 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 = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, pColIndex->tableIndex);
|
||||||
|
|
||||||
SSqlExprInfo* pExprInfo = &pCmd->pQueryInfo[0].exprsInfo;
|
SSqlExprInfo* pExprInfo = &pQueryInfo->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
|
||||||
return pExpr;
|
return pExpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSqlExpr* tscSqlExprUpdate(SSqlCmd* pCmd, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type,
|
SSqlExpr* tscSqlExprUpdate(SQueryInfo* 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 = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
||||||
SSqlExprInfo* pExprInfo = &pCmd->pQueryInfo[0].exprsInfo;
|
SSqlExprInfo* pExprInfo = &pQueryInfo->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,
|
||||||
assert(pExpr->numOfParams <= 3);
|
assert(pExpr->numOfParams <= 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSqlExpr* tscSqlExprGet(SSqlCmd* pCmd, int32_t index) {
|
SSqlExpr* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index) {
|
||||||
if (pCmd->pQueryInfo[0].exprsInfo.numOfExprs <= index) {
|
if (pQueryInfo->exprsInfo.numOfExprs <= index) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return &pCmd->pQueryInfo[0].exprsInfo.pExprs[index];
|
return &pQueryInfo->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
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo refactor
|
// todo refactor
|
||||||
SColumnBase* tscColumnBaseInfoInsert(SSqlCmd* pCmd, SColumnIndex* pColIndex) {
|
SColumnBase* tscColumnBaseInfoInsert(SQueryInfo* pQueryInfo, SColumnIndex* pColIndex) {
|
||||||
SColumnBaseInfo* pcolList = &pCmd->pQueryInfo[0].colList;
|
SColumnBaseInfo* pcolList = &pQueryInfo->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) {
|
||||||
|
|
||||||
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
memset(pCond, 0, sizeof(STagCond));
|
memset(pCond, 0, sizeof(STagCond));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SSqlCmd* pCmd) {
|
void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* pQueryInfo) {
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
||||||
SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta);
|
SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta);
|
||||||
|
|
||||||
for (int32_t i = 0; i < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||||
SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
|
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 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) {
|
||||||
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) {
|
||||||
* 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 = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
||||||
assert(pSql->cmd.pQueryInfo[0].numOfTables == 1);
|
assert(pQueryInfo->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) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(index >= 0 && index <= pCmd->pQueryInfo[0].numOfTables && pCmd->pQueryInfo[0].pMeterInfo != NULL);
|
assert(unionClauseIndex >= 0 && unionClauseIndex < pCmd->numOfClause);
|
||||||
return pCmd->pQueryInfo[0].pMeterInfo[index];
|
|
||||||
|
SQueryInfo* pQueryInfo = pCmd->pQueryInfo[unionClauseIndex];
|
||||||
|
return tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, tableIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
SMeterMetaInfo* tscGetMeterMetaInfoByUid(SSqlCmd* pCmd, uint64_t uid, int32_t* index) {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(pCmd != NULL && subClauseIndex >= 0 && subClauseIndex < pCmd->numOfClause);
|
||||||
|
return pCmd->pQueryInfo[subClauseIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
SMeterMetaInfo* tscGetMeterMetaInfoByUid(SQueryInfo* 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
|
||||||
*index = k;
|
*index = k;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tscGetMeterMetaInfo(pCmd, k);
|
return tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tscAddQueryInfo(SSqlCmd* pCmd) {
|
int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) {
|
||||||
assert(pCmd != NULL);
|
assert(pCmd != NULL);
|
||||||
|
|
||||||
size_t s = pCmd->numOfQueries + 1;
|
size_t s = pCmd->numOfClause + 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));
|
||||||
pCmd->numOfQueries++;
|
pQueryInfo->msg = pCmd->payload; // pointer to the parent error message buffer
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
tscRemoveAllMeterMetaInfo(pQueryInfo, (const char*) address, false);
|
||||||
|
tfree(pQueryInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tscFreeSubqueryInfo(SSqlCmd* pCmd) {
|
||||||
|
if (pCmd == NULL || pCmd->numOfClause == 0) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* pAlloc = realloc(pCmd->pQueryInfo[0].pMeterInfo, (pCmd->pQueryInfo->numOfTables + 1) * POINTER_BYTES);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
pCmd->pQueryInfo[0].pMeterInfo = pAlloc;
|
pQueryInfo->pMeterInfo = pAlloc;
|
||||||
pCmd->pQueryInfo[0].pMeterInfo[pCmd->pQueryInfo->numOfTables] = calloc(1, sizeof(SMeterMetaInfo));
|
pQueryInfo->pMeterInfo[pQueryInfo->numOfTables] = calloc(1, sizeof(SMeterMetaInfo));
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = pCmd->pQueryInfo[0].pMeterInfo[pCmd->pQueryInfo->numOfTables];
|
SMeterMetaInfo* pMeterMetaInfo = pQueryInfo->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*
|
||||||
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 >= pCmd->pQueryInfo->numOfTables) {
|
if (index < 0 || index >= pQueryInfo->numOfTables) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, index);
|
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, index);
|
||||||
|
|
||||||
tscClearMeterMetaInfo(pMeterMetaInfo, removeFromCache);
|
tscClearMeterMetaInfo(pMeterMetaInfo, removeFromCache);
|
||||||
free(pMeterMetaInfo);
|
free(pMeterMetaInfo);
|
||||||
|
|
||||||
int32_t after = pCmd->pQueryInfo->numOfTables - index - 1;
|
int32_t after = pQueryInfo->numOfTables - index - 1;
|
||||||
if (after > 0) {
|
if (after > 0) {
|
||||||
memmove(&pCmd->pQueryInfo[0].pMeterInfo[index], &pCmd->pQueryInfo[0].pMeterInfo[index + 1], after * sizeof(void*));
|
memmove(&pQueryInfo->pMeterInfo[index], &pQueryInfo->pMeterInfo[index + 1], after * sizeof(void*));
|
||||||
}
|
}
|
||||||
|
|
||||||
pCmd->pQueryInfo->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) {
|
int32_t index = pQueryInfo->numOfTables;
|
||||||
return;
|
while (index >= 0) {
|
||||||
|
doRemoveMeterMetaInfo(pQueryInfo, --index, removeFromCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
tscTrace("%p deref the metric/meter meta in cache, numOfTables:%d", ((char*)pCmd - addr),
|
tfree(pQueryInfo->pMeterInfo);
|
||||||
pCmd->pQueryInfo[0].numOfTables);
|
|
||||||
|
|
||||||
while (pCmd->pQueryInfo[0].numOfTables > 0) {
|
|
||||||
tscRemoveMeterMetaInfo(pCmd, pCmd->pQueryInfo->numOfTables - 1, removeFromCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
tfree(pCmd->pQueryInfo[0].pMeterInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscClearMeterMetaInfo(SMeterMetaInfo* pMeterMetaInfo, bool removeFromCache) {
|
void tscClearMeterMetaInfo(SMeterMetaInfo* pMeterMetaInfo, bool removeFromCache) {
|
||||||
|
@ -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
|
||||||
pNew->cmd.allocSize = 0;
|
pNew->cmd.allocSize = 0;
|
||||||
|
|
||||||
pNew->cmd.pQueryInfo = NULL;
|
pNew->cmd.pQueryInfo = NULL;
|
||||||
pNew->cmd.numOfQueries = 0;
|
pNew->cmd.numOfClause = 0;
|
||||||
|
|
||||||
if (tscAddQueryInfo(&pNew->cmd) != TSDB_CODE_SUCCESS) {
|
if (tscAddSubqueryInfo(&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;
|
|
||||||
|
memset(&pNewQueryInfo->colList, 0, sizeof(pNewQueryInfo->colList));
|
||||||
pNew->cmd.pQueryInfo[0].numOfTables = 0;
|
memset(&pNewQueryInfo->fieldsInfo, 0, sizeof(SFieldInfo));
|
||||||
pNew->cmd.pQueryInfo[0].tsBuf = NULL;
|
|
||||||
|
pNewQueryInfo->numOfTables = 0;
|
||||||
memset(&pNew->cmd.pQueryInfo[0].fieldsInfo, 0, sizeof(SFieldInfo));
|
pNewQueryInfo->tsBuf = NULL;
|
||||||
|
|
||||||
tscTagCondCopy(&pNew->cmd.pQueryInfo[0].tagCond, &pCmd->pQueryInfo[0].tagCond);
|
tscTagCondCopy(&pNewQueryInfo->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
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tscColumnBaseInfoCopy(&pNew->cmd.pQueryInfo[0].colList, &pCmd->pQueryInfo[0].colList, (int16_t)tableIndex);
|
tscColumnBaseInfoCopy(&pNewQueryInfo->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
|
pNewQueryInfo->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(&pNewQueryInfo->exprsInfo, &pQueryInfo->exprsInfo, uid);
|
||||||
|
|
||||||
int32_t numOfOutputCols = pNew->cmd.pQueryInfo[0].exprsInfo.numOfExprs;
|
int32_t numOfOutputCols = pNewQueryInfo->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 < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++i) {
|
for (int32_t i = 0, j = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||||
SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
|
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||||
if (pExpr->uid == uid) {
|
if (pExpr->uid == uid) {
|
||||||
indexList[j++] = i;
|
indexList[j++] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tscFieldInfoCopy(&pCmd->pQueryInfo[0].fieldsInfo, &pNew->cmd.pQueryInfo[0].fieldsInfo, indexList, numOfOutputCols);
|
tscFieldInfoCopy(&pQueryInfo->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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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, pNewQueryInfo->type);
|
||||||
return pNew;
|
return pNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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; }
|
||||||
|
|
|
@ -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); }
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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_SLIMIT 118
|
#define TK_OFFSET 118
|
||||||
#define TK_SOFFSET 119
|
#define TK_SLIMIT 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_COLON 131
|
#define TK_CONNECTION 131
|
||||||
#define TK_STREAM 132
|
#define TK_COLON 132
|
||||||
#define TK_ABORT 133
|
#define TK_STREAM 133
|
||||||
#define TK_AFTER 134
|
#define TK_ABORT 134
|
||||||
#define TK_ATTACH 135
|
#define TK_AFTER 135
|
||||||
#define TK_BEFORE 136
|
#define TK_ATTACH 136
|
||||||
#define TK_BEGIN 137
|
#define TK_BEFORE 137
|
||||||
#define TK_CASCADE 138
|
#define TK_BEGIN 138
|
||||||
#define TK_CLUSTER 139
|
#define TK_CASCADE 139
|
||||||
#define TK_CONFLICT 140
|
#define TK_CLUSTER 140
|
||||||
#define TK_COPY 141
|
#define TK_CONFLICT 141
|
||||||
#define TK_DEFERRED 142
|
#define TK_COPY 142
|
||||||
#define TK_DELIMITERS 143
|
#define TK_DEFERRED 143
|
||||||
#define TK_DETACH 144
|
#define TK_DELIMITERS 144
|
||||||
#define TK_EACH 145
|
#define TK_DETACH 145
|
||||||
#define TK_END 146
|
#define TK_EACH 146
|
||||||
#define TK_EXPLAIN 147
|
#define TK_END 147
|
||||||
#define TK_FAIL 148
|
#define TK_EXPLAIN 148
|
||||||
#define TK_FOR 149
|
#define TK_FAIL 149
|
||||||
#define TK_IGNORE 150
|
#define TK_FOR 150
|
||||||
#define TK_IMMEDIATE 151
|
#define TK_IGNORE 151
|
||||||
#define TK_INITIALLY 152
|
#define TK_IMMEDIATE 152
|
||||||
#define TK_INSTEAD 153
|
#define TK_INITIALLY 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_REPLACE 158
|
#define TK_RAISE 158
|
||||||
#define TK_RESTRICT 159
|
#define TK_REPLACE 159
|
||||||
#define TK_ROW 160
|
#define TK_RESTRICT 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
|
||||||
|
|
|
@ -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(const char* pBuf);
|
||||||
double taos_align_get_double(char* pBuf);
|
double taos_align_get_double(const char* 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()
|
||||||
|
|
|
@ -480,6 +480,8 @@ void taosCleanUpHashTable(void *handle) {
|
||||||
free(pNode);
|
free(pNode);
|
||||||
pNode = pNext;
|
pNode = pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tfree(pEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(pObj->hashList);
|
free(pObj->hashList);
|
||||||
|
|
|
@ -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(const char* 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(const char* pBuf) {
|
||||||
double dv = 0;
|
double dv = 0;
|
||||||
*(int64_t*)(&dv) = *(int64_t*)pBuf;
|
*(int64_t*)(&dv) = *(int64_t*)pBuf;
|
||||||
return dv;
|
return dv;
|
||||||
|
|
Loading…
Reference in New Issue