提交 e0537fb1 编写于 作者: J jtao1735

Merge branch 'develop' into feature/unifie

d
...@@ -48,7 +48,7 @@ ELSEIF (TD_WINDOWS_64) ...@@ -48,7 +48,7 @@ ELSEIF (TD_WINDOWS_64)
IF (NOT TD_GODLL) IF (NOT TD_GODLL)
SET_TARGET_PROPERTIES(taos PROPERTIES LINK_FLAGS /DEF:${TD_COMMUNITY_DIR}/src/client/src/taos.def) SET_TARGET_PROPERTIES(taos PROPERTIES LINK_FLAGS /DEF:${TD_COMMUNITY_DIR}/src/client/src/taos.def)
ENDIF () ENDIF ()
TARGET_LINK_LIBRARIES(taos trpc) TARGET_LINK_LIBRARIES(taos trpc tutil)
ELSEIF (TD_DARWIN_64) ELSEIF (TD_DARWIN_64)
SET(CMAKE_MACOSX_RPATH 1) SET(CMAKE_MACOSX_RPATH 1)
......
...@@ -120,7 +120,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd ...@@ -120,7 +120,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
void tscDestroyLocalReducer(SSqlObj *pSql); void tscDestroyLocalReducer(SSqlObj *pSql);
int32_t tscDoLocalreduce(SSqlObj *pSql); int32_t tscDoLocalMerge(SSqlObj *pSql);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -29,8 +29,8 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql); ...@@ -29,8 +29,8 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql);
int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql); int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql);
void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code); void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code);
SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, int32_t index); SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, int32_t index);
void tscDestroyJoinSupporter(SJoinSubquerySupporter* pSupporter); void tscDestroyJoinSupporter(SJoinSupporter* pSupporter);
int32_t tscHandleMasterJoinQuery(SSqlObj* pSql); int32_t tscHandleMasterJoinQuery(SSqlObj* pSql);
...@@ -38,6 +38,9 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql); ...@@ -38,6 +38,9 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql);
int32_t tscHandleMultivnodeInsert(SSqlObj *pSql); int32_t tscHandleMultivnodeInsert(SSqlObj *pSql);
void tscBuildResFromSubqueries(SSqlObj *pSql);
void **doSetResultRowData(SSqlObj *pSql, bool finalResult);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -51,22 +51,38 @@ typedef struct SParsedDataColInfo { ...@@ -51,22 +51,38 @@ typedef struct SParsedDataColInfo {
bool hasVal[TSDB_MAX_COLUMNS]; bool hasVal[TSDB_MAX_COLUMNS];
} SParsedDataColInfo; } SParsedDataColInfo;
typedef struct SJoinSubquerySupporter { typedef struct STidTags {
int64_t uid;
int32_t tid;
int32_t vgId;
char tag[];
} STidTags;
typedef struct SJoinSupporter {
SSubqueryState* pState; SSubqueryState* pState;
SSqlObj* pObj; // parent SqlObj SSqlObj* pObj; // parent SqlObj
int32_t subqueryIndex; // index of sub query int32_t subqueryIndex; // index of sub query
int64_t interval; // interval time int64_t interval; // interval time
SLimitVal limit; // limit info SLimitVal limit; // limit info
uint64_t uid; // query meter uid uint64_t uid; // query meter uid
SArray* colList; // previous query information SArray* colList; // previous query information, no need to use this attribute, and the corresponding attribution
SArray* exprsInfo; SArray* exprList;
SFieldInfo fieldsInfo; SFieldInfo fieldsInfo;
STagCond tagCond; STagCond tagCond;
SSqlGroupbyExpr groupbyExpr; SSqlGroupbyExpr groupbyExpr;
struct STSBuf* pTSBuf; // the TSBuf struct that holds the compressed timestamp array struct STSBuf* pTSBuf; // the TSBuf struct that holds the compressed timestamp array
FILE* f; // temporary file in order to create TSBuf FILE* f; // temporary file in order to create TSBuf
char path[PATH_MAX]; // temporary file path char path[PATH_MAX]; // temporary file path, todo dynamic allocate memory
} SJoinSubquerySupporter; int32_t tagSize; // the length of each in the first filter stage
char* pIdTagList; // result of first stage tags
int32_t totalLen;
int32_t num;
} SJoinSupporter;
typedef struct SVgroupTableInfo {
SCMVgroupInfo vgInfo;
SArray* itemList; //SArray<STableIdInfo>
} SVgroupTableInfo;
int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, const char* name, int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, const char* name,
STableMeta* pTableMeta, STableDataBlocks** dataBlocks); STableMeta* pTableMeta, STableDataBlocks** dataBlocks);
...@@ -87,7 +103,7 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, ...@@ -87,7 +103,7 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList,
int32_t startOffset, int32_t rowSize, const char* tableId, STableMeta* pTableMeta, int32_t startOffset, int32_t rowSize, const char* tableId, STableMeta* pTableMeta,
STableDataBlocks** dataBlocks); STableDataBlocks** dataBlocks);
UNUSED_FUNC STableIdInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx); //UNUSED_FUNC STableIdInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx);
/** /**
* *
...@@ -120,7 +136,7 @@ void addRequiredTagColumn(STableMetaInfo* pTableMetaInfo, SColumnIndex* index); ...@@ -120,7 +136,7 @@ void addRequiredTagColumn(STableMetaInfo* pTableMetaInfo, SColumnIndex* index);
int32_t tscSetTableId(STableMetaInfo* pTableMetaInfo, SSQLToken* pzTableName, SSqlObj* pSql); int32_t tscSetTableId(STableMetaInfo* pTableMetaInfo, SSQLToken* pzTableName, SSqlObj* pSql);
void tscClearInterpInfo(SQueryInfo* pQueryInfo); void tscClearInterpInfo(SQueryInfo* pQueryInfo);
bool tscIsInsertOrImportData(char* sqlstr); bool tscIsInsertData(char* sqlstr);
/* use for keep current db info temporarily, for handle table with db prefix */ /* use for keep current db info temporarily, for handle table with db prefix */
// todo remove it // todo remove it
...@@ -160,7 +176,7 @@ SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functi ...@@ -160,7 +176,7 @@ SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
int32_t tscSqlExprNumOfExprs(SQueryInfo* pQueryInfo); int32_t tscSqlExprNumOfExprs(SQueryInfo* pQueryInfo);
SSqlExpr* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index); SSqlExpr* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index);
SArray* tscSqlExprCopy(const SArray* src, uint64_t uid, bool deepcopy); void tscSqlExprCopy(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy);
void tscSqlExprInfoDestroy(SArray* pExprInfo); void tscSqlExprInfoDestroy(SArray* pExprInfo);
SColumn* tscColumnClone(const SColumn* src); SColumn* tscColumnClone(const SColumn* src);
...@@ -190,7 +206,6 @@ bool tscShouldFreeHeatBeat(SSqlObj* pHb); ...@@ -190,7 +206,6 @@ bool tscShouldFreeHeatBeat(SSqlObj* pHb);
void tscCleanSqlCmd(SSqlCmd* pCmd); void tscCleanSqlCmd(SSqlCmd* pCmd);
bool tscShouldBeFreed(SSqlObj* pSql); bool tscShouldBeFreed(SSqlObj* pSql);
void tscClearAllTableMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache);
STableMetaInfo* tscGetTableMetaInfoFromCmd(SSqlCmd *pCmd, int32_t subClauseIndex, int32_t tableIndex); STableMetaInfo* tscGetTableMetaInfoFromCmd(SSqlCmd *pCmd, int32_t subClauseIndex, int32_t tableIndex);
STableMetaInfo* tscGetMetaInfo(SQueryInfo *pQueryInfo, int32_t tableIndex); STableMetaInfo* tscGetMetaInfo(SQueryInfo *pQueryInfo, int32_t tableIndex);
...@@ -204,7 +219,10 @@ STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, const char* name, ST ...@@ -204,7 +219,10 @@ STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, const char* name, ST
STableMetaInfo* tscAddEmptyMetaInfo(SQueryInfo *pQueryInfo); STableMetaInfo* tscAddEmptyMetaInfo(SQueryInfo *pQueryInfo);
int32_t tscAddSubqueryInfo(SSqlCmd *pCmd); int32_t tscAddSubqueryInfo(SSqlCmd *pCmd);
void tscFreeQueryInfo(SSqlCmd* pCmd); void tscFreeQueryInfo(SSqlCmd* pCmd);
void tscInitQueryInfo(SQueryInfo* pQueryInfo);
void tscClearSubqueryInfo(SSqlCmd* pCmd); void tscClearSubqueryInfo(SSqlCmd* pCmd);
int tscGetSTableVgroupInfo(SSqlObj* pSql, int32_t clauseIndex); int tscGetSTableVgroupInfo(SSqlObj* pSql, int32_t clauseIndex);
......
...@@ -45,8 +45,6 @@ enum { ...@@ -45,8 +45,6 @@ enum {
DATA_FROM_DATA_FILE = 2, DATA_FROM_DATA_FILE = 2,
}; };
typedef SCMSTableVgroupRspMsg SVgroupsInfo;
typedef struct STableComInfo { typedef struct STableComInfo {
uint8_t numOfTags; uint8_t numOfTags;
uint8_t precision; uint8_t precision;
...@@ -69,12 +67,13 @@ typedef struct STableMeta { ...@@ -69,12 +67,13 @@ typedef struct STableMeta {
} STableMeta; } STableMeta;
typedef struct STableMetaInfo { typedef struct STableMetaInfo {
STableMeta * pTableMeta; // table meta, cached in client side and acquried by name STableMeta * pTableMeta; // table meta, cached in client side and acquired by name
SVgroupsInfo *vgroupList; SVgroupsInfo *vgroupList;
SArray *pVgroupTables; // SArray<SVgroupTableInfo>
/* /*
* 1. keep the vnode index during the multi-vnode super table projection query * 1. keep the vgroup index during the multi-vnode super table projection query
* 2. keep the vnode index for multi-vnode insertion * 2. keep the vgroup index for multi-vnode insertion
*/ */
int32_t vgroupIndex; int32_t vgroupIndex;
char name[TSDB_TABLE_ID_LEN]; // (super) table name char name[TSDB_TABLE_ID_LEN]; // (super) table name
...@@ -102,7 +101,7 @@ typedef struct SColumnIndex { ...@@ -102,7 +101,7 @@ typedef struct SColumnIndex {
typedef struct SFieldSupInfo { typedef struct SFieldSupInfo {
bool visible; bool visible;
SArithExprInfo *pArithExprInfo; SExprInfo *pArithExprInfo;
SSqlExpr * pSqlExpr; SSqlExpr * pSqlExpr;
} SFieldSupInfo; } SFieldSupInfo;
...@@ -206,7 +205,7 @@ typedef struct SQueryInfo { ...@@ -206,7 +205,7 @@ typedef struct SQueryInfo {
SArray * colList; // SArray<SColumn*> SArray * colList; // SArray<SColumn*>
SFieldInfo fieldsInfo; SFieldInfo fieldsInfo;
SArray * exprsInfo; // SArray<SSqlExpr*> SArray * exprList; // SArray<SSqlExpr*>
SLimitVal limit; SLimitVal limit;
SLimitVal slimit; SLimitVal slimit;
STagCond tagCond; STagCond tagCond;
...@@ -381,7 +380,6 @@ int32_t tscCreateResPointerInfo(SSqlRes *pRes, SQueryInfo *pQueryInfo); ...@@ -381,7 +380,6 @@ int32_t tscCreateResPointerInfo(SSqlRes *pRes, SQueryInfo *pQueryInfo);
void tscDestroyResPointerInfo(SSqlRes *pRes); void tscDestroyResPointerInfo(SSqlRes *pRes);
void tscResetSqlCmdObj(SSqlCmd *pCmd); void tscResetSqlCmdObj(SSqlCmd *pCmd);
void tscFreeResData(SSqlObj *pSql);
/** /**
* free query result of the sql object * free query result of the sql object
...@@ -394,7 +392,7 @@ void tscFreeSqlResult(SSqlObj *pSql); ...@@ -394,7 +392,7 @@ void tscFreeSqlResult(SSqlObj *pSql);
* Note: this function is multi-thread safe. * Note: this function is multi-thread safe.
* @param pObj * @param pObj
*/ */
void tscFreeSqlObjPartial(SSqlObj *pObj); void tscPartiallyFreeSqlObj(SSqlObj *pObj);
/** /**
* free sql object, release allocated resource * free sql object, release allocated resource
...@@ -422,7 +420,7 @@ int32_t tscInvalidSQLErrMsg(char *msg, const char *additionalInfo, const char *s ...@@ -422,7 +420,7 @@ int32_t tscInvalidSQLErrMsg(char *msg, const char *additionalInfo, const char *s
void tscQueueAsyncFreeResult(SSqlObj *pSql); void tscQueueAsyncFreeResult(SSqlObj *pSql);
int32_t tscToSQLCmd(SSqlObj *pSql, struct SSqlInfo *pInfo); int32_t tscToSQLCmd(SSqlObj *pSql, struct SSqlInfo *pInfo);
char * tscGetResultColumnChr(SSqlRes *pRes, SQueryInfo *pQueryInfo, int32_t column); char * tscGetResultColumnChr(SSqlRes *pRes, SQueryInfo *pQueryInfo, int32_t column, int16_t bytes);
extern void * pDnodeConn; extern void * pDnodeConn;
extern void * tscCacheHandle; extern void * tscCacheHandle;
......
...@@ -14,17 +14,18 @@ ...@@ -14,17 +14,18 @@
*/ */
#include "os.h" #include "os.h"
#include "tutil.h"
#include "tnote.h"
#include "trpc.h" #include "trpc.h"
#include "tscLog.h" #include "tscLog.h"
#include "tscProfile.h" #include "tscProfile.h"
#include "tscSubquery.h"
#include "tscSecondaryMerge.h" #include "tscSecondaryMerge.h"
#include "tscUtil.h" #include "tscUtil.h"
#include "tsclient.h"
#include "tsocket.h"
#include "tutil.h"
#include "tnote.h"
#include "tsched.h" #include "tsched.h"
#include "tschemautil.h" #include "tschemautil.h"
#include "tsclient.h"
static void tscProcessFetchRow(SSchedMsg *pMsg); static void tscProcessFetchRow(SSchedMsg *pMsg);
static void tscAsyncQueryRowsForNextVnode(void *param, TAOS_RES *tres, int numOfRows); static void tscAsyncQueryRowsForNextVnode(void *param, TAOS_RES *tres, int numOfRows);
...@@ -145,7 +146,7 @@ static void tscAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOfRows) { ...@@ -145,7 +146,7 @@ static void tscAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOfRows) {
} }
// local reducer has handle this situation during super table non-projection query. // local reducer has handle this situation during super table non-projection query.
if (pCmd->command != TSDB_SQL_RETRIEVE_METRIC) { if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE) {
pRes->numOfTotalInCurrentClause += pRes->numOfRows; pRes->numOfTotalInCurrentClause += pRes->numOfRows;
} }
...@@ -175,7 +176,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo ...@@ -175,7 +176,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo
} }
pSql->fp = fp; pSql->fp = fp;
if (pCmd->command != TSDB_SQL_RETRIEVE_METRIC && pCmd->command < TSDB_SQL_LOCAL) { if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE && pCmd->command < TSDB_SQL_LOCAL) {
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
} }
tscProcessSql(pSql); tscProcessSql(pSql);
...@@ -220,11 +221,16 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi ...@@ -220,11 +221,16 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi
pSql->param = param; pSql->param = param;
tscResetForNextRetrieve(pRes); tscResetForNextRetrieve(pRes);
if (pCmd->command != TSDB_SQL_RETRIEVE_METRIC && pCmd->command < TSDB_SQL_LOCAL) { // handle the sub queries of join query
if (pCmd->command == TSDB_SQL_METRIC_JOIN_RETRIEVE) {
tscFetchDatablockFromSubquery(pSql);
} else {
if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE && pCmd->command < TSDB_SQL_LOCAL) {
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
} }
tscProcessSql(pSql); tscProcessSql(pSql);
}
} }
void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW), void *param) { void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW), void *param) {
...@@ -251,7 +257,7 @@ void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW), ...@@ -251,7 +257,7 @@ void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW),
tscResetForNextRetrieve(pRes); tscResetForNextRetrieve(pRes);
pSql->fp = tscAsyncFetchSingleRowProxy; pSql->fp = tscAsyncFetchSingleRowProxy;
if (pCmd->command != TSDB_SQL_RETRIEVE_METRIC && pCmd->command < TSDB_SQL_LOCAL) { if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE && pCmd->command < TSDB_SQL_LOCAL) {
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
} }
...@@ -311,7 +317,7 @@ void tscProcessFetchRow(SSchedMsg *pMsg) { ...@@ -311,7 +317,7 @@ void tscProcessFetchRow(SSchedMsg *pMsg) {
SFieldSupInfo* pSup = taosArrayGet(pQueryInfo->fieldsInfo.pSupportInfo, i); SFieldSupInfo* pSup = taosArrayGet(pQueryInfo->fieldsInfo.pSupportInfo, i);
if (pSup->pSqlExpr != NULL) { if (pSup->pSqlExpr != NULL) {
pRes->tsrow[i] = tscGetResultColumnChr(pRes, pQueryInfo, i); pRes->tsrow[i] = tscGetResultColumnChr(pRes, pQueryInfo, i, pSup->pSqlExpr->resBytes);
} else { } else {
// todo add // todo add
} }
......
...@@ -153,7 +153,7 @@ typedef struct SRateInfo { ...@@ -153,7 +153,7 @@ typedef struct SRateInfo {
int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type, int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type,
int16_t *bytes, int16_t *intermediateResBytes, int16_t extLength, bool isSuperTable) { int16_t *bytes, int16_t *interResBytes, int16_t extLength, bool isSuperTable) {
if (!isValidDataType(dataType, dataBytes)) { if (!isValidDataType(dataType, dataBytes)) {
tscError("Illegal data type %d or data type length %d", dataType, dataBytes); tscError("Illegal data type %d or data type length %d", dataType, dataBytes);
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
...@@ -164,28 +164,35 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI ...@@ -164,28 +164,35 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_INTERP) { functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_INTERP) {
*type = (int16_t)dataType; *type = (int16_t)dataType;
*bytes = (int16_t)dataBytes; *bytes = (int16_t)dataBytes;
*intermediateResBytes = *bytes + sizeof(SResultInfo); *interResBytes = *bytes + sizeof(SResultInfo);
return TSDB_CODE_SUCCESS;
}
if (functionId == TSDB_FUNC_TID_TAG) { // todo use struct
*type = TSDB_DATA_TYPE_BINARY;
*bytes = dataBytes + sizeof(int64_t) + sizeof(int32_t) + sizeof(int32_t); // (uid, tid) + VGID + TAGSIZE
*interResBytes = *bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (functionId == TSDB_FUNC_COUNT) { if (functionId == TSDB_FUNC_COUNT) {
*type = TSDB_DATA_TYPE_BIGINT; *type = TSDB_DATA_TYPE_BIGINT;
*bytes = sizeof(int64_t); *bytes = sizeof(int64_t);
*intermediateResBytes = *bytes; *interResBytes = *bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (functionId == TSDB_FUNC_ARITHM) { if (functionId == TSDB_FUNC_ARITHM) {
*type = TSDB_DATA_TYPE_DOUBLE; *type = TSDB_DATA_TYPE_DOUBLE;
*bytes = sizeof(double); *bytes = sizeof(double);
*intermediateResBytes = *bytes; *interResBytes = *bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (functionId == TSDB_FUNC_TS_COMP) { if (functionId == TSDB_FUNC_TS_COMP) {
*type = TSDB_DATA_TYPE_BINARY; *type = TSDB_DATA_TYPE_BINARY;
*bytes = sizeof(int32_t); // this results is compressed ts data *bytes = sizeof(int32_t); // this results is compressed ts data
*intermediateResBytes = POINTER_BYTES; *interResBytes = POINTER_BYTES;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -193,54 +200,54 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI ...@@ -193,54 +200,54 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
if (functionId == TSDB_FUNC_MIN || functionId == TSDB_FUNC_MAX) { if (functionId == TSDB_FUNC_MIN || functionId == TSDB_FUNC_MAX) {
*type = TSDB_DATA_TYPE_BINARY; *type = TSDB_DATA_TYPE_BINARY;
*bytes = dataBytes + DATA_SET_FLAG_SIZE; *bytes = dataBytes + DATA_SET_FLAG_SIZE;
*intermediateResBytes = *bytes; *interResBytes = *bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == TSDB_FUNC_SUM) { } else if (functionId == TSDB_FUNC_SUM) {
*type = TSDB_DATA_TYPE_BINARY; *type = TSDB_DATA_TYPE_BINARY;
*bytes = sizeof(SSumInfo); *bytes = sizeof(SSumInfo);
*intermediateResBytes = *bytes; *interResBytes = *bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == TSDB_FUNC_AVG) { } else if (functionId == TSDB_FUNC_AVG) {
*type = TSDB_DATA_TYPE_BINARY; *type = TSDB_DATA_TYPE_BINARY;
*bytes = sizeof(SAvgInfo); *bytes = sizeof(SAvgInfo);
*intermediateResBytes = *bytes; *interResBytes = *bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_AVG_IRATE) { } else if (functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_AVG_IRATE) {
*type = TSDB_DATA_TYPE_DOUBLE; *type = TSDB_DATA_TYPE_DOUBLE;
*bytes = sizeof(SRateInfo); *bytes = sizeof(SRateInfo);
*intermediateResBytes = sizeof(SRateInfo); *interResBytes = sizeof(SRateInfo);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM) { } else if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM) {
*type = TSDB_DATA_TYPE_BINARY; *type = TSDB_DATA_TYPE_BINARY;
*bytes = sizeof(STopBotInfo) + (sizeof(tValuePair) + POINTER_BYTES + extLength) * param; *bytes = sizeof(STopBotInfo) + (sizeof(tValuePair) + POINTER_BYTES + extLength) * param;
*intermediateResBytes = *bytes; *interResBytes = *bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == TSDB_FUNC_SPREAD) { } else if (functionId == TSDB_FUNC_SPREAD) {
*type = TSDB_DATA_TYPE_BINARY; *type = TSDB_DATA_TYPE_BINARY;
*bytes = sizeof(SSpreadInfo); *bytes = sizeof(SSpreadInfo);
*intermediateResBytes = *bytes; *interResBytes = *bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == TSDB_FUNC_APERCT) { } else if (functionId == TSDB_FUNC_APERCT) {
*type = TSDB_DATA_TYPE_BINARY; *type = TSDB_DATA_TYPE_BINARY;
*bytes = sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1) + sizeof(SHistogramInfo) + sizeof(SAPercentileInfo); *bytes = sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1) + sizeof(SHistogramInfo) + sizeof(SAPercentileInfo);
*intermediateResBytes = *bytes; *interResBytes = *bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == TSDB_FUNC_LAST_ROW) { } else if (functionId == TSDB_FUNC_LAST_ROW) {
*type = TSDB_DATA_TYPE_BINARY; *type = TSDB_DATA_TYPE_BINARY;
*bytes = sizeof(SLastrowInfo) + dataBytes; *bytes = sizeof(SLastrowInfo) + dataBytes;
*intermediateResBytes = *bytes; *interResBytes = *bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == TSDB_FUNC_TWA) { } else if (functionId == TSDB_FUNC_TWA) {
*type = TSDB_DATA_TYPE_DOUBLE; *type = TSDB_DATA_TYPE_DOUBLE;
*bytes = sizeof(STwaInfo); *bytes = sizeof(STwaInfo);
*intermediateResBytes = *bytes; *interResBytes = *bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
} }
...@@ -253,57 +260,57 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI ...@@ -253,57 +260,57 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
} }
*bytes = sizeof(int64_t); *bytes = sizeof(int64_t);
*intermediateResBytes = sizeof(SSumInfo); *interResBytes = sizeof(SSumInfo);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == TSDB_FUNC_APERCT) { } else if (functionId == TSDB_FUNC_APERCT) {
*type = TSDB_DATA_TYPE_DOUBLE; *type = TSDB_DATA_TYPE_DOUBLE;
*bytes = sizeof(double); *bytes = sizeof(double);
*intermediateResBytes = *interResBytes =
sizeof(SAPercentileInfo) + sizeof(SHistogramInfo) + sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1); sizeof(SAPercentileInfo) + sizeof(SHistogramInfo) + sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == TSDB_FUNC_TWA) { } else if (functionId == TSDB_FUNC_TWA) {
*type = TSDB_DATA_TYPE_DOUBLE; *type = TSDB_DATA_TYPE_DOUBLE;
*bytes = sizeof(double); *bytes = sizeof(double);
*intermediateResBytes = sizeof(STwaInfo); *interResBytes = sizeof(STwaInfo);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (functionId == TSDB_FUNC_AVG) { if (functionId == TSDB_FUNC_AVG) {
*type = TSDB_DATA_TYPE_DOUBLE; *type = TSDB_DATA_TYPE_DOUBLE;
*bytes = sizeof(double); *bytes = sizeof(double);
*intermediateResBytes = sizeof(SAvgInfo); *interResBytes = sizeof(SAvgInfo);
} else if (functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_AVG_IRATE) { } else if (functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_AVG_IRATE) {
*type = TSDB_DATA_TYPE_DOUBLE; *type = TSDB_DATA_TYPE_DOUBLE;
*bytes = sizeof(double); *bytes = sizeof(double);
*intermediateResBytes = sizeof(SRateInfo); *interResBytes = sizeof(SRateInfo);
} else if (functionId == TSDB_FUNC_STDDEV) { } else if (functionId == TSDB_FUNC_STDDEV) {
*type = TSDB_DATA_TYPE_DOUBLE; *type = TSDB_DATA_TYPE_DOUBLE;
*bytes = sizeof(double); *bytes = sizeof(double);
*intermediateResBytes = sizeof(SStddevInfo); *interResBytes = sizeof(SStddevInfo);
} else if (functionId == TSDB_FUNC_MIN || functionId == TSDB_FUNC_MAX) { } else if (functionId == TSDB_FUNC_MIN || functionId == TSDB_FUNC_MAX) {
*type = (int16_t)dataType; *type = (int16_t)dataType;
*bytes = (int16_t)dataBytes; *bytes = (int16_t)dataBytes;
*intermediateResBytes = dataBytes + DATA_SET_FLAG_SIZE; *interResBytes = dataBytes + DATA_SET_FLAG_SIZE;
} else if (functionId == TSDB_FUNC_FIRST || functionId == TSDB_FUNC_LAST) { } else if (functionId == TSDB_FUNC_FIRST || functionId == TSDB_FUNC_LAST) {
*type = (int16_t)dataType; *type = (int16_t)dataType;
*bytes = (int16_t)dataBytes; *bytes = (int16_t)dataBytes;
*intermediateResBytes = dataBytes + sizeof(SResultInfo); *interResBytes = dataBytes + sizeof(SResultInfo);
} else if (functionId == TSDB_FUNC_SPREAD) { } else if (functionId == TSDB_FUNC_SPREAD) {
*type = (int16_t)TSDB_DATA_TYPE_DOUBLE; *type = (int16_t)TSDB_DATA_TYPE_DOUBLE;
*bytes = sizeof(double); *bytes = sizeof(double);
*intermediateResBytes = sizeof(SSpreadInfo); *interResBytes = sizeof(SSpreadInfo);
} else if (functionId == TSDB_FUNC_PERCT) { } else if (functionId == TSDB_FUNC_PERCT) {
*type = (int16_t)TSDB_DATA_TYPE_DOUBLE; *type = (int16_t)TSDB_DATA_TYPE_DOUBLE;
*bytes = (int16_t)sizeof(double); *bytes = (int16_t)sizeof(double);
*intermediateResBytes = (int16_t)sizeof(double); *interResBytes = (int16_t)sizeof(double);
} else if (functionId == TSDB_FUNC_LEASTSQR) { } else if (functionId == TSDB_FUNC_LEASTSQR) {
*type = TSDB_DATA_TYPE_BINARY; *type = TSDB_DATA_TYPE_BINARY;
*bytes = TSDB_AVG_FUNCTION_INTER_BUFFER_SIZE; // string *bytes = TSDB_AVG_FUNCTION_INTER_BUFFER_SIZE; // string
*intermediateResBytes = *bytes + sizeof(SResultInfo); *interResBytes = *bytes + sizeof(SResultInfo);
} else if (functionId == TSDB_FUNC_FIRST_DST || functionId == TSDB_FUNC_LAST_DST) { } else if (functionId == TSDB_FUNC_FIRST_DST || functionId == TSDB_FUNC_LAST_DST) {
*type = TSDB_DATA_TYPE_BINARY; *type = TSDB_DATA_TYPE_BINARY;
*bytes = dataBytes + sizeof(SFirstLastInfo); *bytes = dataBytes + sizeof(SFirstLastInfo);
*intermediateResBytes = *bytes; *interResBytes = *bytes;
} else if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM) { } else if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM) {
*type = (int16_t)dataType; *type = (int16_t)dataType;
*bytes = (int16_t)dataBytes; *bytes = (int16_t)dataBytes;
...@@ -311,11 +318,11 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI ...@@ -311,11 +318,11 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
size_t size = sizeof(STopBotInfo) + (sizeof(tValuePair) + POINTER_BYTES + extLength) * param; size_t size = sizeof(STopBotInfo) + (sizeof(tValuePair) + POINTER_BYTES + extLength) * param;
// the output column may be larger than sizeof(STopBotInfo) // the output column may be larger than sizeof(STopBotInfo)
*intermediateResBytes = size; *interResBytes = size;
} else if (functionId == TSDB_FUNC_LAST_ROW) { } else if (functionId == TSDB_FUNC_LAST_ROW) {
*type = (int16_t)dataType; *type = (int16_t)dataType;
*bytes = (int16_t)dataBytes; *bytes = (int16_t)dataBytes;
*intermediateResBytes = dataBytes + sizeof(SLastrowInfo); *interResBytes = dataBytes + sizeof(SLastrowInfo);
} else { } else {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
...@@ -1837,6 +1844,7 @@ static void last_row_function(SQLFunctionCtx *pCtx) { ...@@ -1837,6 +1844,7 @@ static void last_row_function(SQLFunctionCtx *pCtx) {
assignVal(pCtx->aOutputBuf, pData, pCtx->inputBytes, pCtx->inputType); assignVal(pCtx->aOutputBuf, pData, pCtx->inputBytes, pCtx->inputType);
SResultInfo *pResInfo = GET_RES_INFO(pCtx); SResultInfo *pResInfo = GET_RES_INFO(pCtx);
pResInfo->hasResult = DATA_SET_FLAG;
SLastrowInfo *pInfo = (SLastrowInfo *)pResInfo->interResultBuf; SLastrowInfo *pInfo = (SLastrowInfo *)pResInfo->interResultBuf;
pInfo->ts = pCtx->param[0].i64Key; pInfo->ts = pCtx->param[0].i64Key;
...@@ -1856,14 +1864,17 @@ static void last_row_function(SQLFunctionCtx *pCtx) { ...@@ -1856,14 +1864,17 @@ static void last_row_function(SQLFunctionCtx *pCtx) {
static void last_row_finalizer(SQLFunctionCtx *pCtx) { static void last_row_finalizer(SQLFunctionCtx *pCtx) {
// do nothing at the first stage // do nothing at the first stage
if (pCtx->currentStage == SECONDARY_STAGE_MERGE) {
SResultInfo *pResInfo = GET_RES_INFO(pCtx); SResultInfo *pResInfo = GET_RES_INFO(pCtx);
if (pCtx->currentStage == SECONDARY_STAGE_MERGE) {
if (pResInfo->hasResult != DATA_SET_FLAG) { if (pResInfo->hasResult != DATA_SET_FLAG) {
setNull(pCtx->aOutputBuf, pCtx->outputType, pCtx->outputBytes); setNull(pCtx->aOutputBuf, pCtx->outputType, pCtx->outputBytes);
return; return;
} }
} else { } else {
// do nothing if (pResInfo->hasResult != DATA_SET_FLAG) {
setNull(pCtx->aOutputBuf, pCtx->outputType, pCtx->outputBytes);
return;
}
} }
GET_RES_INFO(pCtx)->numOfRes = 1; GET_RES_INFO(pCtx)->numOfRes = 1;
...@@ -2974,11 +2985,28 @@ static void tag_project_function_f(SQLFunctionCtx *pCtx, int32_t index) { ...@@ -2974,11 +2985,28 @@ static void tag_project_function_f(SQLFunctionCtx *pCtx, int32_t index) {
*/ */
static void tag_function(SQLFunctionCtx *pCtx) { static void tag_function(SQLFunctionCtx *pCtx) {
SET_VAL(pCtx, 1, 1); SET_VAL(pCtx, 1, 1);
tVariantDump(&pCtx->tag, pCtx->aOutputBuf, pCtx->tag.nType);
char* output = pCtx->aOutputBuf;
// todo refactor to dump length presented string(var string)
if (pCtx->tag.nType == TSDB_DATA_TYPE_BINARY || pCtx->tag.nType == TSDB_DATA_TYPE_NCHAR) {
*(int16_t*) output = pCtx->tag.nLen;
output += VARSTR_HEADER_SIZE;
}
tVariantDump(&pCtx->tag, output, pCtx->tag.nType);
} }
static void tag_function_f(SQLFunctionCtx *pCtx, int32_t index) { static void tag_function_f(SQLFunctionCtx *pCtx, int32_t index) {
SET_VAL(pCtx, 1, 1); SET_VAL(pCtx, 1, 1);
char* output = pCtx->aOutputBuf;
// todo refactor to dump length presented string(var string)
if (pCtx->tag.nType == TSDB_DATA_TYPE_BINARY || pCtx->tag.nType == TSDB_DATA_TYPE_NCHAR) {
*(int16_t*) output = pCtx->tag.nLen;
output += VARSTR_HEADER_SIZE;
}
tVariantDump(&pCtx->tag, pCtx->aOutputBuf, pCtx->tag.nType); tVariantDump(&pCtx->tag, pCtx->aOutputBuf, pCtx->tag.nType);
} }
...@@ -4836,7 +4864,7 @@ SQLAggFuncElem aAggs[] = {{ ...@@ -4836,7 +4864,7 @@ SQLAggFuncElem aAggs[] = {{
"apercentile", "apercentile",
TSDB_FUNC_APERCT, TSDB_FUNC_APERCT,
TSDB_FUNC_APERCT, TSDB_FUNC_APERCT,
TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_STREAM | TSDB_FUNCSTATE_OF | TSDB_FUNCSTATE_METRIC, TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_STREAM | TSDB_FUNCSTATE_OF | TSDB_FUNCSTATE_STABLE,
apercentile_function_setup, apercentile_function_setup,
apercentile_function, apercentile_function,
apercentile_function_f, apercentile_function_f,
...@@ -4881,7 +4909,7 @@ SQLAggFuncElem aAggs[] = {{ ...@@ -4881,7 +4909,7 @@ SQLAggFuncElem aAggs[] = {{
"last_row", "last_row",
TSDB_FUNC_LAST_ROW, TSDB_FUNC_LAST_ROW,
TSDB_FUNC_LAST_ROW, TSDB_FUNC_LAST_ROW,
TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_OF | TSDB_FUNCSTATE_METRIC | TSDB_FUNCSTATE_NEED_TS | TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_OF | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS |
TSDB_FUNCSTATE_SELECTIVITY, TSDB_FUNCSTATE_SELECTIVITY,
first_last_function_setup, first_last_function_setup,
last_row_function, last_row_function,
...@@ -4897,7 +4925,7 @@ SQLAggFuncElem aAggs[] = {{ ...@@ -4897,7 +4925,7 @@ SQLAggFuncElem aAggs[] = {{
"top", "top",
TSDB_FUNC_TOP, TSDB_FUNC_TOP,
TSDB_FUNC_TOP, TSDB_FUNC_TOP,
TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_METRIC | TSDB_FUNCSTATE_OF | TSDB_FUNCSTATE_NEED_TS | TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_OF | TSDB_FUNCSTATE_NEED_TS |
TSDB_FUNCSTATE_SELECTIVITY, TSDB_FUNCSTATE_SELECTIVITY,
top_bottom_function_setup, top_bottom_function_setup,
top_function, top_function,
...@@ -4913,7 +4941,7 @@ SQLAggFuncElem aAggs[] = {{ ...@@ -4913,7 +4941,7 @@ SQLAggFuncElem aAggs[] = {{
"bottom", "bottom",
TSDB_FUNC_BOTTOM, TSDB_FUNC_BOTTOM,
TSDB_FUNC_BOTTOM, TSDB_FUNC_BOTTOM,
TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_METRIC | TSDB_FUNCSTATE_OF | TSDB_FUNCSTATE_NEED_TS | TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_OF | TSDB_FUNCSTATE_NEED_TS |
TSDB_FUNCSTATE_SELECTIVITY, TSDB_FUNCSTATE_SELECTIVITY,
top_bottom_function_setup, top_bottom_function_setup,
bottom_function, bottom_function,
...@@ -5079,7 +5107,7 @@ SQLAggFuncElem aAggs[] = {{ ...@@ -5079,7 +5107,7 @@ SQLAggFuncElem aAggs[] = {{
"arithmetic", "arithmetic",
TSDB_FUNC_ARITHM, TSDB_FUNC_ARITHM,
TSDB_FUNC_ARITHM, TSDB_FUNC_ARITHM,
TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_METRIC | TSDB_FUNCSTATE_NEED_TS, TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS,
function_setup, function_setup,
arithmetic_function, arithmetic_function,
arithmetic_function_f, arithmetic_function_f,
...@@ -5140,7 +5168,7 @@ SQLAggFuncElem aAggs[] = {{ ...@@ -5140,7 +5168,7 @@ SQLAggFuncElem aAggs[] = {{
"interp", "interp",
TSDB_FUNC_INTERP, TSDB_FUNC_INTERP,
TSDB_FUNC_INTERP, TSDB_FUNC_INTERP,
TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_OF | TSDB_FUNCSTATE_METRIC | TSDB_FUNCSTATE_NEED_TS, TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_OF | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS,
function_setup, function_setup,
interp_function, interp_function,
do_sum_f, // todo filter handle do_sum_f, // todo filter handle
...@@ -5239,4 +5267,19 @@ SQLAggFuncElem aAggs[] = {{ ...@@ -5239,4 +5267,19 @@ SQLAggFuncElem aAggs[] = {{
sumrate_func_merge, sumrate_func_merge,
sumrate_func_second_merge, sumrate_func_second_merge,
data_req_load_info, data_req_load_info,
},
{
// 34
"tid_tag", // return table id and the corresponding tags for join match
TSDB_FUNC_TID_TAG,
TSDB_FUNC_TID_TAG,
TSDB_FUNCSTATE_MO,
function_setup,
noop1,
noop2,
no_next_step,
noop1,
noop1,
noop1,
data_req_load_info,
}}; }};
...@@ -131,26 +131,32 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { ...@@ -131,26 +131,32 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
for (int32_t i = 0; i < numOfRows; ++i) { for (int32_t i = 0; i < numOfRows; ++i) {
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0); TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0);
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 0) * totalNumOfRows + pField->bytes * i, pSchema[i].name, char* dst = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 0) * totalNumOfRows + pField->bytes * i;
TSDB_COL_NAME_LEN); STR_WITH_MAXSIZE_TO_VARSTR(dst, pSchema[i].name, TSDB_COL_NAME_LEN);
char *type = tDataTypeDesc[pSchema[i].type].aName; char *type = tDataTypeDesc[pSchema[i].type].aName;
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 1); pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 1);
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 1) * totalNumOfRows + pField->bytes * i, type, pField->bytes); dst = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 1) * totalNumOfRows + pField->bytes * i;
STR_TO_VARSTR(dst, type);
int32_t bytes = pSchema[i].bytes; int32_t bytes = pSchema[i].bytes;
if (pSchema[i].type == TSDB_DATA_TYPE_BINARY || pSchema[i].type == TSDB_DATA_TYPE_NCHAR) {
bytes -= VARSTR_HEADER_SIZE;
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(&pQueryInfo->fieldsInfo, 2); pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 2);
*(int32_t *)(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 2) * totalNumOfRows + pField->bytes * i) = bytes; *(int32_t *)(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 2) * totalNumOfRows + pField->bytes * i) = bytes;
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 3); pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 3);
if (i >= tscGetNumOfColumns(pMeta) && tscGetNumOfTags(pMeta) != 0) { if (i >= tscGetNumOfColumns(pMeta) && tscGetNumOfTags(pMeta) != 0) {
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 3) * totalNumOfRows + pField->bytes * i, "tag", char* output = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 3) * totalNumOfRows + pField->bytes * i;
strlen("tag") + 1); STR_WITH_SIZE_TO_VARSTR(output, "TAG", 3);
} }
} }
...@@ -163,13 +169,15 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { ...@@ -163,13 +169,15 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
for (int32_t i = numOfRows; i < totalNumOfRows; ++i) { for (int32_t i = numOfRows; i < totalNumOfRows; ++i) {
// field name // field name
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0); TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0);
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 0) * totalNumOfRows + pField->bytes * i, pSchema[i].name, char* output = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 0) * totalNumOfRows + pField->bytes * i;
TSDB_COL_NAME_LEN); STR_WITH_MAXSIZE_TO_VARSTR(output, pSchema[i].name, TSDB_COL_NAME_LEN);
// type name // type name
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 1); pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 1);
char *type = tDataTypeDesc[pSchema[i].type].aName; char *type = tDataTypeDesc[pSchema[i].type].aName;
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 1) * totalNumOfRows + pField->bytes * i, type, pField->bytes);
output = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 1) * totalNumOfRows + pField->bytes * i;
STR_WITH_MAXSIZE_TO_VARSTR(output, type, pField->bytes);
// type length // type length
int32_t bytes = pSchema[i].bytes; int32_t bytes = pSchema[i].bytes;
...@@ -183,49 +191,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { ...@@ -183,49 +191,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
// tag value // tag value
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 3); pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 3);
char *target = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 3) * totalNumOfRows + pField->bytes * i; char *target = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 3) * totalNumOfRows + pField->bytes * i;
STR_WITH_SIZE_TO_VARSTR(target, "TAG", 3);
if (isNull(pTagValue, pSchema[i].type)) {
sprintf(target, "%s", TSDB_DATA_NULL_STR);
} else {
switch (pSchema[i].type) {
case TSDB_DATA_TYPE_BINARY:
/* binary are not null-terminated string */
strncpy(target, pTagValue, pSchema[i].bytes);
break;
case TSDB_DATA_TYPE_NCHAR:
taosUcs4ToMbs(pTagValue, pSchema[i].bytes, target);
break;
case TSDB_DATA_TYPE_FLOAT: {
float fv = 0;
fv = GET_FLOAT_VAL(pTagValue);
sprintf(target, "%f", fv);
} break;
case TSDB_DATA_TYPE_DOUBLE: {
double dv = 0;
dv = GET_DOUBLE_VAL(pTagValue);
sprintf(target, "%lf", dv);
} break;
case TSDB_DATA_TYPE_TINYINT:
sprintf(target, "%d", *(int8_t *)pTagValue);
break;
case TSDB_DATA_TYPE_SMALLINT:
sprintf(target, "%d", *(int16_t *)pTagValue);
break;
case TSDB_DATA_TYPE_INT:
sprintf(target, "%d", *(int32_t *)pTagValue);
break;
case TSDB_DATA_TYPE_BIGINT:
sprintf(target, "%" PRId64 "", *(int64_t *)pTagValue);
break;
case TSDB_DATA_TYPE_BOOL: {
char *val = (*((int8_t *)pTagValue) == 0) ? "false" : "true";
sprintf(target, "%s", val);
break;
}
default:
break;
}
}
pTagValue += pSchema[i].bytes; pTagValue += pSchema[i].bytes;
} }
...@@ -233,7 +199,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { ...@@ -233,7 +199,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
return 0; return 0;
} }
static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols, int32_t typeColLength, static int32_t tscBuildTableSchemaResultFields(SSqlObj *pSql, int32_t numOfCols, int32_t typeColLength,
int32_t noteColLength) { int32_t noteColLength) {
int32_t rowLen = 0; int32_t rowLen = 0;
SColumnIndex index = {0}; SColumnIndex index = {0};
...@@ -243,14 +209,14 @@ static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols, ...@@ -243,14 +209,14 @@ static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
pQueryInfo->order.order = TSDB_ORDER_ASC; pQueryInfo->order.order = TSDB_ORDER_ASC;
TAOS_FIELD f = {.type = TSDB_DATA_TYPE_BINARY, .bytes = TSDB_COL_NAME_LEN}; TAOS_FIELD f = {.type = TSDB_DATA_TYPE_BINARY, .bytes = TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE};
strncpy(f.name, "Field", TSDB_COL_NAME_LEN); strncpy(f.name, "Field", TSDB_COL_NAME_LEN);
SFieldSupInfo* pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f); SFieldSupInfo* pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, TSDB_COL_NAME_LEN, pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY,
TSDB_COL_NAME_LEN, false); TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE, TSDB_COL_NAME_LEN, false);
rowLen += TSDB_COL_NAME_LEN; rowLen += (TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE);
f.bytes = typeColLength; f.bytes = typeColLength;
f.type = TSDB_DATA_TYPE_BINARY; f.type = TSDB_DATA_TYPE_BINARY;
...@@ -289,137 +255,24 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) { ...@@ -289,137 +255,24 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
assert(tscGetMetaInfo(pQueryInfo, 0)->pTableMeta != NULL); assert(tscGetMetaInfo(pQueryInfo, 0)->pTableMeta != NULL);
const int32_t NUM_OF_DESCRIBE_TABLE_COLUMNS = 4; const int32_t NUM_OF_DESC_TABLE_COLUMNS = 4;
const int32_t TYPE_COLUMN_LENGTH = 16; const int32_t TYPE_COLUMN_LENGTH = 16;
const int32_t NOTE_COLUMN_MIN_LENGTH = 8; const int32_t NOTE_COLUMN_MIN_LENGTH = 8;
int32_t note_field_length = tscMaxLengthOfTagsFields(pSql); int32_t noteFieldLen = tscMaxLengthOfTagsFields(pSql);
if (note_field_length == 0) { if (noteFieldLen == 0) {
note_field_length = NOTE_COLUMN_MIN_LENGTH; noteFieldLen = NOTE_COLUMN_MIN_LENGTH;
} }
int32_t rowLen = int32_t rowLen = tscBuildTableSchemaResultFields(pSql, NUM_OF_DESC_TABLE_COLUMNS, TYPE_COLUMN_LENGTH, noteFieldLen);
tscBuildMeterSchemaResultFields(pSql, NUM_OF_DESCRIBE_TABLE_COLUMNS, TYPE_COLUMN_LENGTH, note_field_length);
tscFieldInfoUpdateOffset(pQueryInfo); tscFieldInfoUpdateOffset(pQueryInfo);
return tscSetValueToResObj(pSql, rowLen); return tscSetValueToResObj(pSql, rowLen);
} }
// todo add order support
static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
#if 0
// the result structure has been completed in sql parse, so we
// only need to reorganize the results in the column format
SSqlCmd * pCmd = &pSql->cmd;
SSqlRes * pRes = &pSql->res;
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
SSuperTableMeta *pMetricMeta = pTableMetaInfo->pMetricMeta;
SSchema * pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta);
int32_t vOffset[TSDB_MAX_COLUMNS] = {0};
for (int32_t f = 1; f < pTableMetaInfo->numOfTags; ++f) {
int16_t tagColumnIndex = pTableMetaInfo->tagColumnIndex[f - 1];
if (tagColumnIndex == -1) {
vOffset[f] = vOffset[f - 1] + TSDB_TABLE_NAME_LEN;
} else {
vOffset[f] = vOffset[f - 1] + pSchema[tagColumnIndex].bytes;
}
}
int32_t totalNumOfResults = pMetricMeta->numOfTables;
int32_t rowLen = tscGetResRowLength(pQueryInfo->exprsInfo);
tscInitResObjForLocalQuery(pSql, totalNumOfResults, rowLen);
int32_t rowIdx = 0;
for (int32_t i = 0; i < pMetricMeta->numOfVnodes; ++i) {
SVnodeSidList *pSidList = (SVnodeSidList *)((char *)pMetricMeta + pMetricMeta->list[i]);
for (int32_t j = 0; j < pSidList->numOfSids; ++j) {
STableIdInfo *pSidExt = tscGetMeterSidInfo(pSidList, j);
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutput; ++k) {
SColIndex *pColIndex = &tscSqlExprGet(pQueryInfo, k)->colInfo;
int16_t offsetId = pColIndex->colIdx;
assert((pColIndex->flag & TSDB_COL_TAG) != 0);
assert(0);
char * val = NULL;//pSidExt->tags + vOffset[offsetId];
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, k);
memcpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, k) * totalNumOfResults + pField->bytes * rowIdx, val,
(size_t)pField->bytes);
}
rowIdx++;
}
}
#endif
return 0;
}
static int tscBuildMetricTagSqlFunctionResult(SSqlObj *pSql) {
// SSqlCmd *pCmd = &pSql->cmd;
// SSqlRes *pRes = &pSql->res;
// SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
#if 0
SSuperTableMeta *pMetricMeta = tscGetMetaInfo(pQueryInfo, 0)->pMetricMeta;
int32_t totalNumOfResults = 1; // count function only produce one result
int32_t rowLen = tscGetResRowLength(pQueryInfo->exprsInfo);
tscInitResObjForLocalQuery(pSql, totalNumOfResults, rowLen);
int32_t rowIdx = 0;
for (int32_t i = 0; i < totalNumOfResults; ++i) {
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutput; ++k) {
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
if (pExpr->colInfo.colIdx == -1 && pExpr->functionId == TSDB_FUNC_COUNT) {
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, k);
memcpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, i) * totalNumOfResults + pField->bytes * rowIdx,
&pMetricMeta->numOfTables, sizeof(pMetricMeta->numOfTables));
} else {
tscError("not support operations");
continue;
}
}
rowIdx++;
}
#endif
return 0;
}
static int tscProcessQueryTags(SSqlObj *pSql) {
SSqlCmd *pCmd = &pSql->cmd;
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
STableMeta *pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta;
if (pTableMeta == NULL || tscGetNumOfTags(pTableMeta) == 0 || tscGetNumOfColumns(pTableMeta) == 0) {
strcpy(pCmd->payload, "invalid table");
pSql->res.code = TSDB_CODE_INVALID_TABLE;
return pSql->res.code;
}
SSqlExpr *pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
if (pExpr->functionId == TSDB_FUNC_COUNT) {
return tscBuildMetricTagSqlFunctionResult(pSql);
} else {
return tscBuildMetricTagProjectionResult(pSql);
}
}
static void tscProcessCurrentUser(SSqlObj *pSql) { static void tscProcessCurrentUser(SSqlObj *pSql) {
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
tscSetLocalQueryResult(pSql, pSql->pTscObj->user, pExpr->aliasName, TSDB_USER_LEN); tscSetLocalQueryResult(pSql, pSql->pTscObj->user, pExpr->aliasName, TSDB_USER_LEN);
} }
...@@ -434,7 +287,7 @@ static void tscProcessCurrentDB(SSqlObj *pSql) { ...@@ -434,7 +287,7 @@ static void tscProcessCurrentDB(SSqlObj *pSql) {
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
tscSetLocalQueryResult(pSql, db, pExpr->aliasName, TSDB_DB_NAME_LEN); tscSetLocalQueryResult(pSql, db, pExpr->aliasName, TSDB_DB_NAME_LEN);
} }
...@@ -442,14 +295,14 @@ static void tscProcessServerVer(SSqlObj *pSql) { ...@@ -442,14 +295,14 @@ static void tscProcessServerVer(SSqlObj *pSql) {
const char* v = pSql->pTscObj->sversion; const char* v = pSql->pTscObj->sversion;
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 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) {
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
tscSetLocalQueryResult(pSql, version, pExpr->aliasName, strlen(version)); tscSetLocalQueryResult(pSql, version, pExpr->aliasName, strlen(version));
} }
...@@ -469,7 +322,7 @@ static void tscProcessServStatus(SSqlObj *pSql) { ...@@ -469,7 +322,7 @@ static void tscProcessServStatus(SSqlObj *pSql) {
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
tscSetLocalQueryResult(pSql, "1", pExpr->aliasName, 2); tscSetLocalQueryResult(pSql, "1", pExpr->aliasName, 2);
} }
...@@ -491,7 +344,7 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa ...@@ -491,7 +344,7 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0); TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0);
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, 0); SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, 0);
pInfo->pSqlExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0); pInfo->pSqlExpr = taosArrayGetP(pQueryInfo->exprList, 0);
strncpy(pRes->data, val, pField->bytes); strncpy(pRes->data, val, pField->bytes);
} }
...@@ -503,8 +356,6 @@ int tscProcessLocalCmd(SSqlObj *pSql) { ...@@ -503,8 +356,6 @@ int tscProcessLocalCmd(SSqlObj *pSql) {
pSql->res.code = (uint8_t)taosCfgDynamicOptions(pCmd->payload); pSql->res.code = (uint8_t)taosCfgDynamicOptions(pCmd->payload);
} else if (pCmd->command == TSDB_SQL_DESCRIBE_TABLE) { } else if (pCmd->command == TSDB_SQL_DESCRIBE_TABLE) {
pSql->res.code = (uint8_t)tscProcessDescribeTable(pSql); pSql->res.code = (uint8_t)tscProcessDescribeTable(pSql);
} else if (pCmd->command == TSDB_SQL_RETRIEVE_TAGS) {
pSql->res.code = (uint8_t)tscProcessQueryTags(pSql);
} else if (pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT) { } else if (pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT) {
/* /*
* set the qhandle to be 1 in order to pass the qhandle check, and to call partial release function to * set the qhandle to be 1 in order to pass the qhandle check, and to call partial release function to
......
...@@ -305,32 +305,37 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload, ...@@ -305,32 +305,37 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
// binary data cannot be null-terminated char string, otherwise the last char of the string is lost // binary data cannot be null-terminated char string, otherwise the last char of the string is lost
if (pToken->type == TK_NULL) { if (pToken->type == TK_NULL) {
*(int16_t*) payload = sizeof(int8_t);
payload += VARSTR_HEADER_SIZE;
*payload = TSDB_DATA_BINARY_NULL; *payload = TSDB_DATA_BINARY_NULL;
} else { // too long values will return invalid sql, not be truncated automatically } else { // too long values will return invalid sql, not be truncated automatically
if (pToken->n > pSchema->bytes) { if (pToken->n > pSchema->bytes) {
return tscInvalidSQLErrMsg(msg, "string data overflow", pToken->z); return tscInvalidSQLErrMsg(msg, "string data overflow", pToken->z);
} }
strncpy(payload, pToken->z, pToken->n); STR_WITH_SIZE_TO_VARSTR(payload, pToken->z, pToken->n);
if (pToken->n < pSchema->bytes) {
payload[pToken->n] = 0; // add the null-terminated char if the length of the string is shorter than the available space
}
} }
break; break;
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
if (pToken->type == TK_NULL) { if (pToken->type == TK_NULL) {
*(uint32_t *)payload = TSDB_DATA_NCHAR_NULL; *(int16_t*) payload = sizeof(int32_t);
payload += VARSTR_HEADER_SIZE;
*(uint32_t*) payload = TSDB_DATA_NCHAR_NULL;
} else { } else {
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long' // if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
if (!taosMbsToUcs4(pToken->z, pToken->n, payload, pSchema->bytes)) { int32_t resLen = -1;
if (!taosMbsToUcs4(pToken->z, pToken->n, payload + VARSTR_HEADER_SIZE, pSchema->bytes, &resLen)) {
char buf[512] = {0}; char buf[512] = {0};
snprintf(buf, 512, "%s", strerror(errno)); snprintf(buf, 512, "%s", strerror(errno));
return tscInvalidSQLErrMsg(msg, buf, pToken->z); return tscInvalidSQLErrMsg(msg, buf, pToken->z);
} }
*(uint16_t*)payload = (uint16_t) (resLen * TSDB_NCHAR_SIZE);
} }
break; break;
...@@ -1301,13 +1306,13 @@ int tsParseSql(SSqlObj *pSql, bool initialParse) { ...@@ -1301,13 +1306,13 @@ int tsParseSql(SSqlObj *pSql, bool initialParse) {
char* p = pSql->sqlstr; char* p = pSql->sqlstr;
pSql->sqlstr = NULL; pSql->sqlstr = NULL;
tscFreeSqlObjPartial(pSql); tscPartiallyFreeSqlObj(pSql);
pSql->sqlstr = p; pSql->sqlstr = p;
} else { } else {
tscTrace("continue parse sql: %s", pSql->cmd.curSql); tscTrace("continue parse sql: %s", pSql->cmd.curSql);
} }
if (tscIsInsertOrImportData(pSql->sqlstr)) { if (tscIsInsertData(pSql->sqlstr)) {
/* /*
* Set the fp before parse the sql string, in case of getTableMeta failed, in which * Set the fp before parse the sql string, in case of getTableMeta failed, in which
* the error handle callback function can rightfully restore the user-defined callback function (fp). * the error handle callback function can rightfully restore the user-defined callback function (fp).
......
...@@ -300,7 +300,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { ...@@ -300,7 +300,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) {
break; break;
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
if (!taosMbsToUcs4(bind->buffer, *bind->length, data + param->offset, param->bytes)) { if (!taosMbsToUcs4(bind->buffer, *bind->length, data + param->offset, param->bytes, NULL)) {
return TSDB_CODE_INVALID_VALUE; return TSDB_CODE_INVALID_VALUE;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -455,7 +455,7 @@ static int insertStmtExecute(STscStmt* stmt) { ...@@ -455,7 +455,7 @@ static int insertStmtExecute(STscStmt* stmt) {
// tscTrace("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj); // tscTrace("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
if (pRes->code != TSDB_CODE_SUCCESS) { if (pRes->code != TSDB_CODE_SUCCESS) {
tscFreeSqlObjPartial(pSql); tscPartiallyFreeSqlObj(pSql);
} }
return pRes->code; return pRes->code;
...@@ -510,7 +510,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { ...@@ -510,7 +510,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
strtolower(sqlstr, sqlstr); strtolower(sqlstr, sqlstr);
pStmt->pSql->sqlstr = sqlstr; pStmt->pSql->sqlstr = sqlstr;
if (tscIsInsertOrImportData(sqlstr)) { if (tscIsInsertData(sqlstr)) {
pStmt->isInsert = true; pStmt->isInsert = true;
return insertStmtPrepare(pStmt); return insertStmtPrepare(pStmt);
} }
......
...@@ -105,7 +105,7 @@ static int32_t getColumnIndexByName(const SSQLToken* pToken, SQueryInfo* pQueryI ...@@ -105,7 +105,7 @@ static int32_t getColumnIndexByName(const SSQLToken* pToken, SQueryInfo* pQueryI
static int32_t getTableIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex); static int32_t getTableIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex);
static int32_t optrToString(tSQLExpr* pExpr, char** exprString); static int32_t optrToString(tSQLExpr* pExpr, char** exprString);
static int32_t getMeterIndex(SSQLToken* pTableToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex); static int32_t getTableIndexImpl(SSQLToken* pTableToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex);
static int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo); static int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
static int32_t doLocalQueryProcess(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql); static int32_t doLocalQueryProcess(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql);
static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCMCreateDbMsg* pCreate); static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCMCreateDbMsg* pCreate);
...@@ -292,8 +292,8 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -292,8 +292,8 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
break; break;
} }
case TSDB_SQL_CREATE_DNODE: { // todo parse hostname case TSDB_SQL_CREATE_DNODE: { // todo hostname
const char* msg = "invalid ip address"; const char* msg = "invalid host name (ip address)";
if (pInfo->pDCLInfo->nTokens > 1) { if (pInfo->pDCLInfo->nTokens > 1) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
...@@ -360,14 +360,10 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -360,14 +360,10 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
case TSDB_SQL_CFG_DNODE: { case TSDB_SQL_CFG_DNODE: {
const char* msg1 = "invalid ip address";
const char* msg2 = "invalid configure options or values"; const char* msg2 = "invalid configure options or values";
/* validate the ip address */ /* validate the ip address */
tDCLSQL* pDCL = pInfo->pDCLInfo; tDCLSQL* pDCL = pInfo->pDCLInfo;
if (!validateIpAddress(pDCL->a[0].z, pDCL->a[0].n)) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
/* validate the parameter names and options */ /* validate the parameter names and options */
if (validateDNodeConfig(pDCL) != TSDB_CODE_SUCCESS) { if (validateDNodeConfig(pDCL) != TSDB_CODE_SUCCESS) {
...@@ -1172,7 +1168,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel ...@@ -1172,7 +1168,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
tExprNode* pNode = NULL; tExprNode* pNode = NULL;
SArray* colList = taosArrayInit(10, sizeof(SColIndex)); SArray* colList = taosArrayInit(10, sizeof(SColIndex));
int32_t ret = exprTreeFromSqlExpr(&pNode, pItem->pNode, pQueryInfo->exprsInfo, pQueryInfo, colList); int32_t ret = exprTreeFromSqlExpr(&pNode, pItem->pNode, pQueryInfo->exprList, pQueryInfo, colList);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
tExprTreeDestroy(&pNode, NULL); tExprTreeDestroy(&pNode, NULL);
return invalidSqlErrMsg(pQueryInfo->msg, "invalid arithmetic expression in select clause"); return invalidSqlErrMsg(pQueryInfo->msg, "invalid arithmetic expression in select clause");
...@@ -1208,7 +1204,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel ...@@ -1208,7 +1204,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, slot); SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, slot);
if (pInfo->pSqlExpr == NULL) { if (pInfo->pSqlExpr == NULL) {
SArithExprInfo* pFuncExpr = calloc(1, sizeof(SArithExprInfo)); SExprInfo* pFuncExpr = calloc(1, sizeof(SExprInfo));
pInfo->pArithExprInfo = pFuncExpr; pInfo->pArithExprInfo = pFuncExpr;
// arithmetic expression always return result in the format of double float // arithmetic expression always return result in the format of double float
...@@ -1219,7 +1215,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel ...@@ -1219,7 +1215,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
tExprNode* pNode = NULL; tExprNode* pNode = NULL;
// SArray* colList = taosArrayInit(10, sizeof(SColIndex)); // SArray* colList = taosArrayInit(10, sizeof(SColIndex));
int32_t ret = exprTreeFromSqlExpr(&pNode, pItem->pNode, pQueryInfo->exprsInfo, pQueryInfo, NULL); int32_t ret = exprTreeFromSqlExpr(&pNode, pItem->pNode, pQueryInfo->exprList, pQueryInfo, NULL);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
tExprTreeDestroy(&pNode, NULL); tExprTreeDestroy(&pNode, NULL);
return invalidSqlErrMsg(pQueryInfo->msg, "invalid expression in select clause"); return invalidSqlErrMsg(pQueryInfo->msg, "invalid expression in select clause");
...@@ -1265,14 +1261,6 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel ...@@ -1265,14 +1261,6 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
if (isSTable) { if (isSTable) {
pQueryInfo->type |= TSDB_QUERY_TYPE_STABLE_QUERY; pQueryInfo->type |= TSDB_QUERY_TYPE_STABLE_QUERY;
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
int32_t numOfCols = tscGetNumOfColumns(pTableMetaInfo->pTableMeta);
if (tscQueryTags(pQueryInfo)) { // local handle the metric tag query
pCmd->count = numOfCols; // the number of meter schema, tricky.
pQueryInfo->command = TSDB_SQL_RETRIEVE_TAGS;
}
/* /*
* transfer sql functions that need secondary merge into another format * transfer sql functions that need secondary merge into another format
* in dealing with metric queries such as: count/first/last * in dealing with metric queries such as: count/first/last
...@@ -1322,11 +1310,11 @@ SSqlExpr* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t outputIndex, int32_t c ...@@ -1322,11 +1310,11 @@ SSqlExpr* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t outputIndex, int32_t c
if (functionId == TSDB_FUNC_TAGPRJ) { if (functionId == TSDB_FUNC_TAGPRJ) {
index.columnIndex = colIndex - tscGetNumOfColumns(pTableMeta); index.columnIndex = colIndex - tscGetNumOfColumns(pTableMeta);
addRequiredTagColumn(pTableMetaInfo, &index); tscColumnListInsert(pTableMetaInfo->tagColList, &index);
pQueryInfo->type = TSDB_QUERY_TYPE_STABLE_QUERY; pQueryInfo->type = TSDB_QUERY_TYPE_STABLE_QUERY;
} else { } else {
index.columnIndex = colIndex; index.columnIndex = colIndex;
pQueryInfo->type = TSDB_QUERY_TYPE_PROJECTION_QUERY; pQueryInfo->type |= TSDB_QUERY_TYPE_PROJECTION_QUERY;
} }
return tscSqlExprAppend(pQueryInfo, functionId, &index, pSchema->type, pSchema->bytes, return tscSqlExprAppend(pQueryInfo, functionId, &index, pSchema->type, pSchema->bytes,
...@@ -1334,7 +1322,7 @@ SSqlExpr* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t outputIndex, int32_t c ...@@ -1334,7 +1322,7 @@ SSqlExpr* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t outputIndex, int32_t c
} }
void addRequiredTagColumn(STableMetaInfo* pTableMetaInfo, SColumnIndex* index) { void addRequiredTagColumn(STableMetaInfo* pTableMetaInfo, SColumnIndex* index) {
tscColumnListInsert(pTableMetaInfo->tagColList, index);
} }
static void addProjectQueryCol(SQueryInfo* pQueryInfo, int32_t startPos, SColumnIndex* pIndex, tSQLExprItem* pItem) { static void addProjectQueryCol(SQueryInfo* pQueryInfo, int32_t startPos, SColumnIndex* pIndex, tSQLExprItem* pItem) {
...@@ -1375,7 +1363,7 @@ void tscAddSpecialColumnForSelect(SQueryInfo* pQueryInfo, int32_t outputColIndex ...@@ -1375,7 +1363,7 @@ void tscAddSpecialColumnForSelect(SQueryInfo* pQueryInfo, int32_t outputColIndex
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pIndex->tableIndex); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pIndex->tableIndex);
if (TSDB_COL_IS_TAG(flag)) { if (TSDB_COL_IS_TAG(flag)) {
addRequiredTagColumn(pTableMetaInfo, pIndex); tscColumnListInsert(pTableMetaInfo->tagColList, pIndex);
} }
} }
...@@ -1439,7 +1427,7 @@ int32_t addProjectionExprAndResultField(SQueryInfo* pQueryInfo, tSQLExprItem* pI ...@@ -1439,7 +1427,7 @@ int32_t addProjectionExprAndResultField(SQueryInfo* pQueryInfo, tSQLExprItem* pI
} }
if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
SSchema colSchema = {.type = TSDB_DATA_TYPE_BINARY, .bytes = TSDB_TABLE_NAME_LEN}; SSchema colSchema = {.type = TSDB_DATA_TYPE_BINARY, .bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE};
strcpy(colSchema.name, TSQL_TBNAME_L); strcpy(colSchema.name, TSQL_TBNAME_L);
pQueryInfo->type = TSDB_QUERY_TYPE_STABLE_QUERY; pQueryInfo->type = TSDB_QUERY_TYPE_STABLE_QUERY;
...@@ -1549,7 +1537,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr ...@@ -1549,7 +1537,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
int32_t size = tDataTypeDesc[TSDB_DATA_TYPE_BIGINT].nSize; int32_t size = tDataTypeDesc[TSDB_DATA_TYPE_BIGINT].nSize;
pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size, false); pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size, false);
} else { } else {
// count the number of meters created according to the metric // count the number of meters created according to the super table
if (getColumnIndexByName(pToken, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { if (getColumnIndexByName(pToken, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
return invalidSqlErrMsg(pQueryInfo->msg, msg3); return invalidSqlErrMsg(pQueryInfo->msg, msg3);
} }
...@@ -2003,7 +1991,7 @@ int32_t doGetColumnIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColum ...@@ -2003,7 +1991,7 @@ int32_t doGetColumnIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColum
} }
} }
int32_t getMeterIndex(SSQLToken* pTableToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex) { int32_t getTableIndexImpl(SSQLToken* pTableToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex) {
if (pTableToken->n == 0) { // only one table and no table name prefix in column name if (pTableToken->n == 0) { // only one table and no table name prefix in column name
if (pQueryInfo->numOfTables == 1) { if (pQueryInfo->numOfTables == 1) {
pIndex->tableIndex = 0; pIndex->tableIndex = 0;
...@@ -2036,7 +2024,7 @@ int32_t getTableIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColumnIn ...@@ -2036,7 +2024,7 @@ int32_t getTableIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColumnIn
SSQLToken tableToken = {0}; SSQLToken tableToken = {0};
extractTableNameFromToken(pToken, &tableToken); extractTableNameFromToken(pToken, &tableToken);
if (getMeterIndex(&tableToken, pQueryInfo, pIndex) != TSDB_CODE_SUCCESS) { if (getTableIndexImpl(&tableToken, pQueryInfo, pIndex) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
...@@ -2343,7 +2331,7 @@ bool hasUnsupportFunctionsForSTableQuery(SQueryInfo* pQueryInfo) { ...@@ -2343,7 +2331,7 @@ bool hasUnsupportFunctionsForSTableQuery(SQueryInfo* pQueryInfo) {
size_t size = tscSqlExprNumOfExprs(pQueryInfo); size_t size = tscSqlExprNumOfExprs(pQueryInfo);
for (int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
int32_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId; int32_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId;
if ((aAggs[functionId].nStatus & TSDB_FUNCSTATE_METRIC) == 0) { if ((aAggs[functionId].nStatus & TSDB_FUNCSTATE_STABLE) == 0) {
invalidSqlErrMsg(pQueryInfo->msg, msg3); invalidSqlErrMsg(pQueryInfo->msg, msg3);
return true; return true;
} }
...@@ -2372,6 +2360,7 @@ bool hasUnsupportFunctionsForSTableQuery(SQueryInfo* pQueryInfo) { ...@@ -2372,6 +2360,7 @@ bool hasUnsupportFunctionsForSTableQuery(SQueryInfo* pQueryInfo) {
static bool functionCompatibleCheck(SQueryInfo* pQueryInfo) { static bool functionCompatibleCheck(SQueryInfo* pQueryInfo) {
int32_t startIdx = 0; int32_t startIdx = 0;
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, startIdx); SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, startIdx);
int32_t functionID = pExpr->functionId; int32_t functionID = pExpr->functionId;
...@@ -2387,14 +2376,14 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo) { ...@@ -2387,14 +2376,14 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo) {
size_t size = tscSqlExprNumOfExprs(pQueryInfo); size_t size = tscSqlExprNumOfExprs(pQueryInfo);
for (int32_t i = startIdx + 1; i < size; ++i) { for (int32_t i = startIdx + 1; i < size; ++i) {
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i); SSqlExpr* pExpr1 = tscSqlExprGet(pQueryInfo, i);
int16_t functionId = pExpr->functionId; int16_t functionId = pExpr1->functionId;
if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TS) { if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TS) {
continue; continue;
} }
if (functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { if (functionId == TSDB_FUNC_PRJ && pExpr1->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
continue; continue;
} }
...@@ -2533,12 +2522,11 @@ int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, tVariantList* pList, SSqlCmd* ...@@ -2533,12 +2522,11 @@ int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, tVariantList* pList, SSqlCmd*
relIndex -= numOfCols; relIndex -= numOfCols;
} }
SColIndex colIndex = { SColIndex colIndex = { .colIndex = relIndex, .flag = TSDB_COL_TAG, .colId = pSchema->colId, };
.colIndex = relIndex, .flag = TSDB_COL_TAG, .colId = pSchema->colId,
};
taosArrayPush(pGroupExpr->columnInfo, &colIndex); taosArrayPush(pGroupExpr->columnInfo, &colIndex);
addRequiredTagColumn(pTableMetaInfo, &index);
index.columnIndex = relIndex;
tscColumnListInsert(pTableMetaInfo->tagColList, &index);
} else { } else {
// check if the column type is valid, here only support the bool/tinyint/smallint/bigint group by // check if the column type is valid, here only support the bool/tinyint/smallint/bigint group by
if (pSchema->type > TSDB_DATA_TYPE_BINARY) { if (pSchema->type > TSDB_DATA_TYPE_BINARY) {
...@@ -3200,7 +3188,6 @@ static bool validateJoinExprNode(SQueryInfo* pQueryInfo, tSQLExpr* pExpr, SColum ...@@ -3200,7 +3188,6 @@ static bool validateJoinExprNode(SQueryInfo* pQueryInfo, tSQLExpr* pExpr, SColum
const char* msg3 = "join column must have same type"; const char* msg3 = "join column must have same type";
const char* msg4 = "self join is not allowed"; const char* msg4 = "self join is not allowed";
const char* msg5 = "join table must be the same type(table to table, super table to super table)"; const char* msg5 = "join table must be the same type(table to table, super table to super table)";
const char* msg6 = "tags in join condition not support binary/nchar types";
tSQLExpr* pRight = pExpr->pRight; tSQLExpr* pRight = pExpr->pRight;
...@@ -3235,9 +3222,6 @@ static bool validateJoinExprNode(SQueryInfo* pQueryInfo, tSQLExpr* pExpr, SColum ...@@ -3235,9 +3222,6 @@ static bool validateJoinExprNode(SQueryInfo* pQueryInfo, tSQLExpr* pExpr, SColum
} else if (pLeftIndex->tableIndex == rightIndex.tableIndex) { } else if (pLeftIndex->tableIndex == rightIndex.tableIndex) {
invalidSqlErrMsg(pQueryInfo->msg, msg4); invalidSqlErrMsg(pQueryInfo->msg, msg4);
return false; return false;
} else if (leftType == TSDB_DATA_TYPE_BINARY || leftType == TSDB_DATA_TYPE_NCHAR) {
invalidSqlErrMsg(pQueryInfo->msg, msg6);
return false;
} }
// table to table/ super table to super table are allowed // table to table/ super table to super table are allowed
...@@ -3307,7 +3291,7 @@ static int32_t handleExprInQueryCond(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, S ...@@ -3307,7 +3291,7 @@ static int32_t handleExprInQueryCond(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, S
// set join query condition // set join query condition
if (pRight->nSQLOptr == TK_ID) { // no need to keep the timestamp join condition if (pRight->nSQLOptr == TK_ID) { // no need to keep the timestamp join condition
pQueryInfo->type |= TSDB_QUERY_TYPE_JOIN_QUERY; TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_QUERY);
pCondExpr->tsJoin = true; pCondExpr->tsJoin = true;
/* /*
...@@ -3545,7 +3529,7 @@ static int32_t setTableCondForSTableQuery(SQueryInfo* pQueryInfo, const char* ac ...@@ -3545,7 +3529,7 @@ static int32_t setTableCondForSTableQuery(SQueryInfo* pQueryInfo, const char* ac
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
SStringBuilder sb1 = { 0 }; SStringBuilder sb1 = {0};
taosStringBuilderAppendStringLen(&sb1, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN); taosStringBuilderAppendStringLen(&sb1, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN);
char db[TSDB_TABLE_ID_LEN] = {0}; char db[TSDB_TABLE_ID_LEN] = {0};
...@@ -3728,14 +3712,14 @@ static void doAddJoinTagsColumnsIntoTagList(SQueryInfo* pQueryInfo, SCondExpr* p ...@@ -3728,14 +3712,14 @@ static void doAddJoinTagsColumnsIntoTagList(SQueryInfo* pQueryInfo, SCondExpr* p
getColumnIndexByName(&pCondExpr->pJoinExpr->pLeft->colInfo, pQueryInfo, &index); getColumnIndexByName(&pCondExpr->pJoinExpr->pLeft->colInfo, pQueryInfo, &index);
pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex);
// int32_t columnInfo = index.columnIndex - tscGetNumOfColumns(pTableMetaInfo->pTableMeta); index.columnIndex = index.columnIndex - tscGetNumOfColumns(pTableMetaInfo->pTableMeta);
addRequiredTagColumn(pTableMetaInfo, &index); tscColumnListInsert(pTableMetaInfo->tagColList, &index);
getColumnIndexByName(&pCondExpr->pJoinExpr->pRight->colInfo, pQueryInfo, &index); getColumnIndexByName(&pCondExpr->pJoinExpr->pRight->colInfo, pQueryInfo, &index);
pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex);
// columnInfo = index.columnIndex - tscGetNumOfColumns(pTableMetaInfo->pTableMeta); index.columnIndex = index.columnIndex - tscGetNumOfColumns(pTableMetaInfo->pTableMeta);
addRequiredTagColumn(pTableMetaInfo, &index); tscColumnListInsert(pTableMetaInfo->tagColList, &index);
} }
} }
...@@ -3771,7 +3755,7 @@ static int32_t getTagQueryCondExpr(SQueryInfo* pQueryInfo, SCondExpr* pCondExpr, ...@@ -3771,7 +3755,7 @@ static int32_t getTagQueryCondExpr(SQueryInfo* pQueryInfo, SCondExpr* pCondExpr,
for(int32_t j = 0; j < num; ++j) { for(int32_t j = 0; j < num; ++j) {
SColIndex* pIndex = taosArrayGet(colList, j); SColIndex* pIndex = taosArrayGet(colList, j);
SColumnIndex index = {.tableIndex = i, .columnIndex = pIndex->colIndex - numOfCols}; SColumnIndex index = {.tableIndex = i, .columnIndex = pIndex->colIndex - numOfCols};
addRequiredTagColumn(pTableMetaInfo, &index); tscColumnListInsert(pTableMetaInfo->tagColList, &index);
} }
tsSetSTableQueryCond(&pQueryInfo->tagCond, uid, &bw); tsSetSTableQueryCond(&pQueryInfo->tagCond, uid, &bw);
...@@ -4053,8 +4037,6 @@ int32_t parseFillClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL) { ...@@ -4053,8 +4037,6 @@ int32_t parseFillClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL) {
} }
} }
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo);
if ((pFillToken->nExpr < size) || if ((pFillToken->nExpr < size) ||
((pFillToken->nExpr - 1 < size) && (tscIsPointInterpQuery(pQueryInfo)))) { ((pFillToken->nExpr - 1 < size) && (tscIsPointInterpQuery(pQueryInfo)))) {
tVariantListItem* lastItem = &pFillToken->a[pFillToken->nExpr - 1]; tVariantListItem* lastItem = &pFillToken->a[pFillToken->nExpr - 1];
...@@ -4088,7 +4070,7 @@ static void setDefaultOrderInfo(SQueryInfo* pQueryInfo) { ...@@ -4088,7 +4070,7 @@ static void setDefaultOrderInfo(SQueryInfo* pQueryInfo) {
pQueryInfo->order.orderColId = -1; pQueryInfo->order.orderColId = -1;
} }
/* for metric query, set default ascending order for group output */ /* for super table query, set default ascending order for group output */
if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) { if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) {
pQueryInfo->groupbyExpr.orderType = TSDB_ORDER_ASC; pQueryInfo->groupbyExpr.orderType = TSDB_ORDER_ASC;
} }
...@@ -4136,7 +4118,7 @@ int32_t parseOrderbyClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql, SSchema ...@@ -4136,7 +4118,7 @@ int32_t parseOrderbyClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql, SSchema
SSQLToken columnName = {pVar->nLen, pVar->nType, pVar->pz}; SSQLToken columnName = {pVar->nLen, pVar->nType, pVar->pz};
SColumnIndex index = {0}; SColumnIndex index = {0};
if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) { // metric query if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) { // super table query
if (getColumnIndexByName(&columnName, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { if (getColumnIndexByName(&columnName, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
return invalidSqlErrMsg(pQueryInfo->msg, msg1); return invalidSqlErrMsg(pQueryInfo->msg, msg1);
} }
...@@ -4251,6 +4233,21 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4251,6 +4233,21 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const char* msg5 = "only support add one tag"; const char* msg5 = "only support add one tag";
const char* msg6 = "column can only be modified by super table"; const char* msg6 = "column can only be modified by super table";
const char* msg7 = "no tags can be dropped";
const char* msg8 = "only support one tag";
const char* msg9 = "tag name too long";
const char* msg10 = "invalid tag name";
const char* msg11 = "primary tag cannot be dropped";
const char* msg12 = "update normal column not supported";
const char* msg13 = "invalid tag value";
const char* msg14 = "tag value too long";
const char* msg15 = "no columns can be dropped";
const char* msg16 = "only support one column";
const char* msg17 = "invalid column name";
const char* msg18 = "primary timestamp column cannot be dropped";
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
SAlterTableSQL* pAlterSQL = pInfo->pAlterInfo; SAlterTableSQL* pAlterSQL = pInfo->pAlterInfo;
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
...@@ -4296,24 +4293,18 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4296,24 +4293,18 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]); tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]);
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN) { } else if (pAlterSQL->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN) {
const char* msg1 = "no tags can be dropped";
const char* msg2 = "only support one tag";
const char* msg3 = "tag name too long";
const char* msg4 = "illegal tag name";
const char* msg5 = "primary tag cannot be dropped";
if (tscGetNumOfTags(pTableMeta) == 1) { if (tscGetNumOfTags(pTableMeta) == 1) {
return invalidSqlErrMsg(pQueryInfo->msg, msg1); return invalidSqlErrMsg(pQueryInfo->msg, msg7);
} }
// numOfTags == 1 // numOfTags == 1
if (pAlterSQL->varList->nExpr > 1) { if (pAlterSQL->varList->nExpr > 1) {
return invalidSqlErrMsg(pQueryInfo->msg, msg2); return invalidSqlErrMsg(pQueryInfo->msg, msg8);
} }
tVariantListItem* pItem = &pAlterSQL->varList->a[0]; tVariantListItem* pItem = &pAlterSQL->varList->a[0];
if (pItem->pVar.nLen > TSDB_COL_NAME_LEN) { if (pItem->pVar.nLen > TSDB_COL_NAME_LEN) {
return invalidSqlErrMsg(pQueryInfo->msg, msg3); return invalidSqlErrMsg(pQueryInfo->msg, msg9);
} }
SColumnIndex index = COLUMN_INDEX_INITIALIZER; SColumnIndex index = COLUMN_INDEX_INITIALIZER;
...@@ -4324,9 +4315,9 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4324,9 +4315,9 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
if (index.columnIndex < tscGetNumOfColumns(pTableMeta)) { if (index.columnIndex < tscGetNumOfColumns(pTableMeta)) {
return invalidSqlErrMsg(pQueryInfo->msg, msg4); return invalidSqlErrMsg(pQueryInfo->msg, msg10);
} else if (index.columnIndex == 0) { } else if (index.columnIndex == 0) {
return invalidSqlErrMsg(pQueryInfo->msg, msg5); return invalidSqlErrMsg(pQueryInfo->msg, msg11);
} }
char name1[128] = {0}; char name1[128] = {0};
...@@ -4335,9 +4326,6 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4335,9 +4326,6 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_INT, name1, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_INT, name1, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f); tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) { } else if (pAlterSQL->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) {
const char* msg1 = "tag name too long";
const char* msg2 = "invalid tag name";
tVariantList* pVarList = pAlterSQL->varList; tVariantList* pVarList = pAlterSQL->varList;
if (pVarList->nExpr > 2) { if (pVarList->nExpr > 2) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
...@@ -4347,11 +4335,11 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4347,11 +4335,11 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
tVariantListItem* pDstItem = &pAlterSQL->varList->a[1]; tVariantListItem* pDstItem = &pAlterSQL->varList->a[1];
if (pSrcItem->pVar.nLen >= TSDB_COL_NAME_LEN || pDstItem->pVar.nLen >= TSDB_COL_NAME_LEN) { if (pSrcItem->pVar.nLen >= TSDB_COL_NAME_LEN || pDstItem->pVar.nLen >= TSDB_COL_NAME_LEN) {
return invalidSqlErrMsg(pQueryInfo->msg, msg1); return invalidSqlErrMsg(pQueryInfo->msg, msg9);
} }
if (pSrcItem->pVar.nType != TSDB_DATA_TYPE_BINARY || pDstItem->pVar.nType != TSDB_DATA_TYPE_BINARY) { if (pSrcItem->pVar.nType != TSDB_DATA_TYPE_BINARY || pDstItem->pVar.nType != TSDB_DATA_TYPE_BINARY) {
return invalidSqlErrMsg(pQueryInfo->msg, msg2); return invalidSqlErrMsg(pQueryInfo->msg, msg10);
} }
SColumnIndex srcIndex = COLUMN_INDEX_INITIALIZER; SColumnIndex srcIndex = COLUMN_INDEX_INITIALIZER;
...@@ -4377,10 +4365,6 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4377,10 +4365,6 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
f = tscCreateField(TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); f = tscCreateField(TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f); tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) { } else if (pAlterSQL->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) {
const char* msg1 = "invalid tag value";
const char* msg2 = "update normal column not supported";
const char* msg3 = "tag value too long";
// Note: update can only be applied to table not super table. // Note: update can only be applied to table not super table.
// the following is handle display tags value for meters created according to super table // the following is handle display tags value for meters created according to super table
tVariantList* pVarList = pAlterSQL->varList; tVariantList* pVarList = pAlterSQL->varList;
...@@ -4393,19 +4377,19 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4393,19 +4377,19 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
if (columnIndex.columnIndex < tscGetNumOfColumns(pTableMeta)) { if (columnIndex.columnIndex < tscGetNumOfColumns(pTableMeta)) {
return invalidSqlErrMsg(pQueryInfo->msg, msg2); return invalidSqlErrMsg(pQueryInfo->msg, msg12);
} }
SSchema* pTagsSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, columnIndex.columnIndex); SSchema* pTagsSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, columnIndex.columnIndex);
if (tVariantDump(&pVarList->a[1].pVar, pAlterSQL->tagData.data /*pCmd->payload*/, pTagsSchema->type) != if (tVariantDump(&pVarList->a[1].pVar, pAlterSQL->tagData.data /*pCmd->payload*/, pTagsSchema->type) !=
TSDB_CODE_SUCCESS) { TSDB_CODE_SUCCESS) {
return invalidSqlErrMsg(pQueryInfo->msg, msg1); return invalidSqlErrMsg(pQueryInfo->msg, msg13);
} }
// validate the length of binary // validate the length of binary
if ((pTagsSchema->type == TSDB_DATA_TYPE_BINARY || pTagsSchema->type == TSDB_DATA_TYPE_NCHAR) && if ((pTagsSchema->type == TSDB_DATA_TYPE_BINARY || pTagsSchema->type == TSDB_DATA_TYPE_NCHAR) &&
pVarList->a[1].pVar.nLen > pTagsSchema->bytes) { pVarList->a[1].pVar.nLen > pTagsSchema->bytes) {
return invalidSqlErrMsg(pQueryInfo->msg, msg3); return invalidSqlErrMsg(pQueryInfo->msg, msg14);
} }
char name1[128] = {0}; char name1[128] = {0};
...@@ -4427,17 +4411,12 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4427,17 +4411,12 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]); tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]);
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_DROP_COLUMN) { } else if (pAlterSQL->type == TSDB_ALTER_TABLE_DROP_COLUMN) {
const char* msg1 = "no columns can be dropped";
const char* msg2 = "only support one column";
const char* msg4 = "illegal column name";
const char* msg3 = "primary timestamp column cannot be dropped";
if (tscGetNumOfColumns(pTableMeta) == TSDB_MIN_COLUMNS) { // if (tscGetNumOfColumns(pTableMeta) == TSDB_MIN_COLUMNS) { //
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg15);
} }
if (pAlterSQL->varList->nExpr > 1) { if (pAlterSQL->varList->nExpr > 1) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg16);
} }
tVariantListItem* pItem = &pAlterSQL->varList->a[0]; tVariantListItem* pItem = &pAlterSQL->varList->a[0];
...@@ -4445,11 +4424,11 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4445,11 +4424,11 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SColumnIndex columnIndex = COLUMN_INDEX_INITIALIZER; SColumnIndex columnIndex = COLUMN_INDEX_INITIALIZER;
SSQLToken name = {.type = TK_STRING, .z = pItem->pVar.pz, .n = pItem->pVar.nLen}; SSQLToken name = {.type = TK_STRING, .z = pItem->pVar.pz, .n = pItem->pVar.nLen};
if (getColumnIndexByName(&name, pQueryInfo, &columnIndex) != TSDB_CODE_SUCCESS) { if (getColumnIndexByName(&name, pQueryInfo, &columnIndex) != TSDB_CODE_SUCCESS) {
return invalidSqlErrMsg(pQueryInfo->msg, msg4); return invalidSqlErrMsg(pQueryInfo->msg, msg17);
} }
if (columnIndex.columnIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX) { if (columnIndex.columnIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
return invalidSqlErrMsg(pQueryInfo->msg, msg3); return invalidSqlErrMsg(pQueryInfo->msg, msg18);
} }
char name1[TSDB_COL_NAME_LEN + 1] = {0}; char name1[TSDB_COL_NAME_LEN + 1] = {0};
...@@ -4469,7 +4448,7 @@ int32_t validateSqlFunctionInStreamSql(SQueryInfo* pQueryInfo) { ...@@ -4469,7 +4448,7 @@ int32_t validateSqlFunctionInStreamSql(SQueryInfo* pQueryInfo) {
return invalidSqlErrMsg(pQueryInfo->msg, msg0); return invalidSqlErrMsg(pQueryInfo->msg, msg0);
} }
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo); size_t size = taosArrayGetSize(pQueryInfo->exprList);
for (int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
int32_t functId = tscSqlExprGet(pQueryInfo, i)->functionId; int32_t functId = tscSqlExprGet(pQueryInfo, i)->functionId;
if (!IS_STREAM_QUERY_VALID(aAggs[functId].nStatus)) { if (!IS_STREAM_QUERY_VALID(aAggs[functId].nStatus)) {
...@@ -4485,7 +4464,7 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SQueryInfo* pQueryInfo) { ...@@ -4485,7 +4464,7 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SQueryInfo* pQueryInfo) {
const char* msg1 = "column projection is not compatible with interval"; const char* msg1 = "column projection is not compatible with interval";
// multi-output set/ todo refactor // multi-output set/ todo refactor
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo); size_t size = taosArrayGetSize(pQueryInfo->exprList);
for (int32_t k = 0; k < size; ++k) { for (int32_t k = 0; k < size; ++k) {
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, k); SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, k);
...@@ -4680,22 +4659,17 @@ int32_t parseLimitClause(SQueryInfo* pQueryInfo, int32_t clauseIndex, SQuerySQL* ...@@ -4680,22 +4659,17 @@ int32_t parseLimitClause(SQueryInfo* pQueryInfo, int32_t clauseIndex, SQuerySQL*
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
// todo refactor
if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) { if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) {
bool queryOnTags = false; if (!tscQueryTags(pQueryInfo)) { // local handle the super table tag query
// if (tscQueryOnlyMetricTags(pQueryInfo, &queryOnTags) != TSDB_CODE_SUCCESS) {
// return TSDB_CODE_INVALID_SQL;
// }
if (queryOnTags == true) { // local handle the super table tag query
pQueryInfo->command = TSDB_SQL_RETRIEVE_TAGS;
} else {
if (tscIsProjectionQueryOnSTable(pQueryInfo, 0)) { if (tscIsProjectionQueryOnSTable(pQueryInfo, 0)) {
if (pQueryInfo->slimit.limit > 0 || pQueryInfo->slimit.offset > 0) { if (pQueryInfo->slimit.limit > 0 || pQueryInfo->slimit.offset > 0) {
return invalidSqlErrMsg(pQueryInfo->msg, msg3); return invalidSqlErrMsg(pQueryInfo->msg, msg3);
} }
// for projection query on super table, all queries are subqueries // for projection query on super table, all queries are subqueries
if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) { if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) &&
!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_QUERY)) {
pQueryInfo->type |= TSDB_QUERY_TYPE_SUBQUERY; pQueryInfo->type |= TSDB_QUERY_TYPE_SUBQUERY;
} }
} }
...@@ -4722,6 +4696,7 @@ int32_t parseLimitClause(SQueryInfo* pQueryInfo, int32_t clauseIndex, SQuerySQL* ...@@ -4722,6 +4696,7 @@ int32_t parseLimitClause(SQueryInfo* pQueryInfo, int32_t clauseIndex, SQuerySQL*
if (pTableMetaInfo->vgroupList->numOfVgroups == 0) { if (pTableMetaInfo->vgroupList->numOfVgroups == 0) {
tscTrace("%p no table in super table, no output result", pSql); tscTrace("%p no table in super table, no output result", pSql);
pQueryInfo->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT; pQueryInfo->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
return TSDB_CODE_SUCCESS;
} }
// keep original limitation value in globalLimit // keep original limitation value in globalLimit
...@@ -4745,7 +4720,7 @@ int32_t parseLimitClause(SQueryInfo* pQueryInfo, int32_t clauseIndex, SQuerySQL* ...@@ -4745,7 +4720,7 @@ int32_t parseLimitClause(SQueryInfo* pQueryInfo, int32_t clauseIndex, SQuerySQL*
return invalidSqlErrMsg(pQueryInfo->msg, msg1); return invalidSqlErrMsg(pQueryInfo->msg, msg1);
} }
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo); size_t size = taosArrayGetSize(pQueryInfo->exprList);
// filter the query functions operating on "tbname" column that are not supported by normal columns. // filter the query functions operating on "tbname" column that are not supported by normal columns.
for (int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
...@@ -4857,7 +4832,7 @@ void tscAddTimestampColumn(SQueryInfo* pQueryInfo, int16_t functionId, int16_t t ...@@ -4857,7 +4832,7 @@ void tscAddTimestampColumn(SQueryInfo* pQueryInfo, int16_t functionId, int16_t t
if (pExpr == NULL || pExpr->colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX || pExpr->functionId != functionId) { if (pExpr == NULL || pExpr->colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX || pExpr->functionId != functionId) {
SColumnIndex index = {tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX}; SColumnIndex index = {tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX};
pExpr = tscSqlExprAppend(pQueryInfo, functionId, &index, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, TSDB_KEYSIZE, false); pExpr = tscSqlExprInsert(pQueryInfo, 0, functionId, &index, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, TSDB_KEYSIZE, false);
pExpr->colInfo.flag = TSDB_COL_NORMAL; pExpr->colInfo.flag = TSDB_COL_NORMAL;
// NOTE: tag column does not add to source column list // NOTE: tag column does not add to source column list
...@@ -4872,7 +4847,7 @@ void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t subClau ...@@ -4872,7 +4847,7 @@ void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t subClau
if (pParentQueryInfo->groupbyExpr.numOfGroupCols > 0) { if (pParentQueryInfo->groupbyExpr.numOfGroupCols > 0) {
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, subClauseIndex); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, subClauseIndex);
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo); size_t size = taosArrayGetSize(pQueryInfo->exprList);
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, size - 1); SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, size - 1);
...@@ -4900,7 +4875,7 @@ void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t subClau ...@@ -4900,7 +4875,7 @@ void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t subClau
pColIndex->colIndex = relIndex; pColIndex->colIndex = relIndex;
index = (SColumnIndex) {.tableIndex = tableIndex, .columnIndex = relIndex}; index = (SColumnIndex) {.tableIndex = tableIndex, .columnIndex = relIndex};
addRequiredTagColumn(pTableMetaInfo, &index); tscColumnListInsert(pTableMetaInfo->tagColList, &index);
} }
} }
} }
...@@ -4941,7 +4916,7 @@ void doAddGroupColumnForSubquery(SQueryInfo* pQueryInfo, int32_t tagIndex) { ...@@ -4941,7 +4916,7 @@ void doAddGroupColumnForSubquery(SQueryInfo* pQueryInfo, int32_t tagIndex) {
static void doUpdateSqlFunctionForTagPrj(SQueryInfo* pQueryInfo) { static void doUpdateSqlFunctionForTagPrj(SQueryInfo* pQueryInfo) {
int32_t tagLength = 0; int32_t tagLength = 0;
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo); size_t size = taosArrayGetSize(pQueryInfo->exprList);
for (int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i); SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
...@@ -4968,7 +4943,7 @@ static void doUpdateSqlFunctionForTagPrj(SQueryInfo* pQueryInfo) { ...@@ -4968,7 +4943,7 @@ static void doUpdateSqlFunctionForTagPrj(SQueryInfo* pQueryInfo) {
} }
static void doUpdateSqlFunctionForColPrj(SQueryInfo* pQueryInfo) { static void doUpdateSqlFunctionForColPrj(SQueryInfo* pQueryInfo) {
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo); size_t size = taosArrayGetSize(pQueryInfo->exprList);
for (int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i); SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
...@@ -5006,7 +4981,7 @@ static bool onlyTagPrjFunction(SQueryInfo* pQueryInfo) { ...@@ -5006,7 +4981,7 @@ static bool onlyTagPrjFunction(SQueryInfo* pQueryInfo) {
bool hasTagPrj = false; bool hasTagPrj = false;
bool hasColumnPrj = false; bool hasColumnPrj = false;
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo); size_t size = taosArrayGetSize(pQueryInfo->exprList);
for (int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i); SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
if (pExpr->functionId == TSDB_FUNC_PRJ) { if (pExpr->functionId == TSDB_FUNC_PRJ) {
...@@ -5041,7 +5016,7 @@ static bool allTagPrjInGroupby(SQueryInfo* pQueryInfo) { ...@@ -5041,7 +5016,7 @@ static bool allTagPrjInGroupby(SQueryInfo* pQueryInfo) {
} }
static void updateTagPrjFunction(SQueryInfo* pQueryInfo) { static void updateTagPrjFunction(SQueryInfo* pQueryInfo) {
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo); size_t size = taosArrayGetSize(pQueryInfo->exprList);
for (int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i); SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
...@@ -5065,9 +5040,9 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo) { ...@@ -5065,9 +5040,9 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo) {
int16_t numOfSelectivity = 0; int16_t numOfSelectivity = 0;
int16_t numOfAggregation = 0; int16_t numOfAggregation = 0;
size_t numOfExprs = taosArrayGetSize(pQueryInfo->exprsInfo); size_t numOfExprs = taosArrayGetSize(pQueryInfo->exprList);
for (int32_t i = 0; i < numOfExprs; ++i) { for (int32_t i = 0; i < numOfExprs; ++i) {
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, i); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, i);
if (pExpr->functionId == TSDB_FUNC_TAGPRJ || if (pExpr->functionId == TSDB_FUNC_TAGPRJ ||
(pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX)) { (pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX)) {
tagColExists = true; tagColExists = true;
...@@ -5076,7 +5051,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo) { ...@@ -5076,7 +5051,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo) {
} }
for (int32_t i = 0; i < numOfExprs; ++i) { for (int32_t i = 0; i < numOfExprs; ++i) {
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, i); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, i);
int16_t functionId = pExpr->functionId; int16_t functionId = pExpr->functionId;
if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TS || if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TS ||
...@@ -5125,7 +5100,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo) { ...@@ -5125,7 +5100,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo) {
doUpdateSqlFunctionForColPrj(pQueryInfo); doUpdateSqlFunctionForColPrj(pQueryInfo);
} }
} else { } else {
if ((pQueryInfo->type & TSDB_QUERY_TYPE_PROJECTION_QUERY) == TSDB_QUERY_TYPE_PROJECTION_QUERY) { if ((pQueryInfo->type & TSDB_QUERY_TYPE_PROJECTION_QUERY) != 0) {
if (numOfAggregation > 0 && pQueryInfo->groupbyExpr.numOfGroupCols == 0) { if (numOfAggregation > 0 && pQueryInfo->groupbyExpr.numOfGroupCols == 0) {
return invalidSqlErrMsg(pQueryInfo->msg, msg3); return invalidSqlErrMsg(pQueryInfo->msg, msg3);
} }
...@@ -5221,7 +5196,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { ...@@ -5221,7 +5196,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
const char* msg4 = "retrieve tags not compatible with group by or interval query"; const char* msg4 = "retrieve tags not compatible with group by or interval query";
// only retrieve tags, group by is not supportted // only retrieve tags, group by is not supportted
if (pCmd->command == TSDB_SQL_RETRIEVE_TAGS) { if (tscQueryTags(pQueryInfo)) {
if (pQueryInfo->groupbyExpr.numOfGroupCols > 0 || pQueryInfo->intervalTime > 0) { if (pQueryInfo->groupbyExpr.numOfGroupCols > 0 || pQueryInfo->intervalTime > 0) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
} else { } else {
...@@ -5283,7 +5258,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { ...@@ -5283,7 +5258,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
// projection query on metric does not compatible with "group by" syntax // projection query on super table does not compatible with "group by" syntax
if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) { if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
} }
...@@ -5485,7 +5460,7 @@ int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSqlInfo* p ...@@ -5485,7 +5460,7 @@ int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSqlInfo* p
pCmd->numOfCols = (int16_t)pFieldList->nField; pCmd->numOfCols = (int16_t)pFieldList->nField;
if (pTagList != NULL) { // create metric[optional] if (pTagList != NULL) { // create super table[optional]
for (int32_t i = 0; i < pTagList->nField; ++i) { for (int32_t i = 0; i < pTagList->nField; ++i) {
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pTagList->p[i]); tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pTagList->p[i]);
} }
...@@ -5761,6 +5736,8 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) { ...@@ -5761,6 +5736,8 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return code; return code;
} }
} else {
TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TABLE_QUERY);
} }
// parse the group by clause in the first place // parse the group by clause in the first place
......
...@@ -83,7 +83,6 @@ STableComInfo tscGetTableInfo(const STableMeta* pTableMeta) { ...@@ -83,7 +83,6 @@ STableComInfo tscGetTableInfo(const STableMeta* pTableMeta) {
return pTableMeta->tableInfo; return pTableMeta->tableInfo;
} }
bool isValidSchema(struct SSchema* pSchema, int32_t numOfCols) { bool isValidSchema(struct SSchema* pSchema, int32_t numOfCols) {
if (!VALIDNUMOFCOLS(numOfCols)) { if (!VALIDNUMOFCOLS(numOfCols)) {
return false; return false;
...@@ -184,7 +183,6 @@ STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg, size_t* size ...@@ -184,7 +183,6 @@ STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg, size_t* size
return pTableMeta; return pTableMeta;
} }
/** /**
* the TableMeta data format in memory is as follows: * the TableMeta data format in memory is as follows:
* *
......
...@@ -288,7 +288,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd ...@@ -288,7 +288,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
pReducer->nResultBufSize = pMemBuffer[0]->pageSize * 16; pReducer->nResultBufSize = pMemBuffer[0]->pageSize * 16;
pReducer->pResultBuf = (tFilePage *)calloc(1, pReducer->nResultBufSize + sizeof(tFilePage)); pReducer->pResultBuf = (tFilePage *)calloc(1, pReducer->nResultBufSize + sizeof(tFilePage));
int32_t finalRowLength = tscGetResRowLength(pQueryInfo->exprsInfo); int32_t finalRowLength = tscGetResRowLength(pQueryInfo->exprList);
pReducer->resColModel = finalmodel; pReducer->resColModel = finalmodel;
pReducer->resColModel->capacity = pReducer->nResultBufSize / finalRowLength; pReducer->resColModel->capacity = pReducer->nResultBufSize / finalRowLength;
assert(finalRowLength <= pReducer->rowSize); assert(finalRowLength <= pReducer->rowSize);
...@@ -810,7 +810,7 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo ...@@ -810,7 +810,7 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo
// todo merge with following function // todo merge with following function
// static void reversedCopyResultToDstBuf(SQueryInfo* pQueryInfo, SSqlRes *pRes, tFilePage *pFinalDataPage) { // static void reversedCopyResultToDstBuf(SQueryInfo* pQueryInfo, SSqlRes *pRes, tFilePage *pFinalDataPage) {
// //
// for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) { // for (int32_t i = 0; i < pQueryInfo->exprList.numOfExprs; ++i) {
// TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i); // TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
// //
// int32_t offset = tscFieldInfoGetOffset(pQueryInfo, i); // int32_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
...@@ -907,7 +907,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo ...@@ -907,7 +907,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
savePrevRecordAndSetupInterpoInfo(pLocalReducer, pQueryInfo, &pLocalReducer->interpolationInfo); savePrevRecordAndSetupInterpoInfo(pLocalReducer, pQueryInfo, &pLocalReducer->interpolationInfo);
} }
int32_t rowSize = tscGetResRowLength(pQueryInfo->exprsInfo); int32_t rowSize = tscGetResRowLength(pQueryInfo->exprList);
memcpy(pRes->data, pFinalDataPage->data, pRes->numOfRows * rowSize); memcpy(pRes->data, pFinalDataPage->data, pRes->numOfRows * rowSize);
pFinalDataPage->numOfElems = 0; pFinalDataPage->numOfElems = 0;
...@@ -1422,15 +1422,14 @@ static void doProcessResultInNextWindow(SSqlObj *pSql, int32_t numOfRes) { ...@@ -1422,15 +1422,14 @@ static void doProcessResultInNextWindow(SSqlObj *pSql, int32_t numOfRes) {
doExecuteSecondaryMerge(pCmd, pLocalReducer, true); doExecuteSecondaryMerge(pCmd, pLocalReducer, true);
} }
int32_t tscDoLocalreduce(SSqlObj *pSql) { int32_t tscDoLocalMerge(SSqlObj *pSql) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
SSqlRes *pRes = &pSql->res; SSqlRes *pRes = &pSql->res;
tscResetForNextRetrieve(pRes); tscResetForNextRetrieve(pRes);
if (pSql->signature != pSql || pRes == NULL || pRes->pLocalReducer == NULL) { // all data has been processed if (pSql->signature != pSql || pRes == NULL || pRes->pLocalReducer == NULL) { // all data has been processed
tscTrace("%s call the drop local reducer", __FUNCTION__); tscTrace("%p %s call the drop local reducer", pSql, __FUNCTION__);
tscDestroyLocalReducer(pSql); tscDestroyLocalReducer(pSql);
return 0; return 0;
} }
...@@ -1441,7 +1440,7 @@ int32_t tscDoLocalreduce(SSqlObj *pSql) { ...@@ -1441,7 +1440,7 @@ int32_t tscDoLocalreduce(SSqlObj *pSql) {
// 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);
if (prevStatus != TSC_LOCALREDUCE_READY || pLocalReducer == NULL) { if (prevStatus != TSC_LOCALREDUCE_READY) {
assert(prevStatus == TSC_LOCALREDUCE_TOBE_FREED); // it is in tscDestroyLocalReducer function already assert(prevStatus == TSC_LOCALREDUCE_TOBE_FREED); // it is in tscDestroyLocalReducer function already
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
......
...@@ -45,15 +45,15 @@ void tscSaveSubscriptionProgress(void* sub); ...@@ -45,15 +45,15 @@ void tscSaveSubscriptionProgress(void* sub);
static int32_t minMsgSize() { return tsRpcHeadSize + 100; } static int32_t minMsgSize() { return tsRpcHeadSize + 100; }
static void tscSetDnodeIpList(SSqlObj* pSql, STableMeta* pTableMeta) { static void tscSetDnodeIpList(SSqlObj* pSql, SCMVgroupInfo* pVgroupInfo) {
SRpcIpSet* pIpList = &pSql->ipList; SRpcIpSet* pIpList = &pSql->ipList;
pIpList->numOfIps = pTableMeta->vgroupInfo.numOfIps; pIpList->numOfIps = pVgroupInfo->numOfIps;
pIpList->inUse = 0; pIpList->inUse = 0;
for(int32_t i = 0; i < pTableMeta->vgroupInfo.numOfIps; ++i) { for(int32_t i = 0; i < pVgroupInfo->numOfIps; ++i) {
strcpy(pIpList->fqdn[i], pTableMeta->vgroupInfo.ipAddr[i].fqdn); strcpy(pIpList->fqdn[i], pVgroupInfo->ipAddr[i].fqdn);
pIpList->port[i] = pTableMeta->vgroupInfo.ipAddr[i].port; pIpList->port[i] = pVgroupInfo->ipAddr[i].port;
} }
} }
...@@ -206,7 +206,7 @@ int tscSendMsgToServer(SSqlObj *pSql) { ...@@ -206,7 +206,7 @@ int tscSendMsgToServer(SSqlObj *pSql) {
memcpy(pMsg, pSql->cmd.payload, pSql->cmd.payloadLen); memcpy(pMsg, pSql->cmd.payload, pSql->cmd.payloadLen);
} }
tscTrace("%p msg:%s is sent to server %d", pSql, taosMsg[pSql->cmd.msgType], pSql->ipList.port); tscTrace("%p msg:%s is sent to server", pSql, taosMsg[pSql->cmd.msgType]);
SRpcMsg rpcMsg = { SRpcMsg rpcMsg = {
.msgType = pSql->cmd.msgType, .msgType = pSql->cmd.msgType,
...@@ -320,11 +320,6 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) { ...@@ -320,11 +320,6 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
pRes->pRsp = NULL; pRes->pRsp = NULL;
} }
// ignore the error information returned from mnode when set ignore flag in sql
if (pRes->code == TSDB_CODE_DB_ALREADY_EXIST && pCmd->existsCheck && pRes->rspType == TSDB_MSG_TYPE_CM_CREATE_DB_RSP) {
pRes->code = TSDB_CODE_SUCCESS;
}
/* /*
* There is not response callback function for submit response. * There is not response callback function for submit response.
* The actual inserted number of points is the first number. * The actual inserted number of points is the first number.
...@@ -406,7 +401,6 @@ int doProcessSql(SSqlObj *pSql) { ...@@ -406,7 +401,6 @@ int doProcessSql(SSqlObj *pSql) {
int tscProcessSql(SSqlObj *pSql) { int tscProcessSql(SSqlObj *pSql) {
char * name = NULL; char * name = NULL;
SSqlRes *pRes = &pSql->res;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
...@@ -421,42 +415,40 @@ int tscProcessSql(SSqlObj *pSql) { ...@@ -421,42 +415,40 @@ int tscProcessSql(SSqlObj *pSql) {
type = pQueryInfo->type; type = pQueryInfo->type;
// for heartbeat, numOfTables == 0; // while numOfTables equals to 0, it must be Heartbeat
assert((pQueryInfo->numOfTables == 0 && pQueryInfo->command == TSDB_SQL_HB) || pQueryInfo->numOfTables > 0); assert((pQueryInfo->numOfTables == 0 && pQueryInfo->command == TSDB_SQL_HB) || pQueryInfo->numOfTables > 0);
} }
tscTrace("%p SQL cmd:%d will be processed, name:%s, type:%d", pSql, pCmd->command, name, type); tscTrace("%p SQL cmd:%d will be processed, name:%s, type:%d", pSql, pCmd->command, name, type);
if (pSql->cmd.command < TSDB_SQL_MGMT) { if (pCmd->command < TSDB_SQL_MGMT) { // the pTableMetaInfo cannot be NULL
// the pTableMetaInfo cannot be NULL
if (pTableMetaInfo == NULL) { if (pTableMetaInfo == NULL) {
pSql->res.code = TSDB_CODE_OTHERS; pSql->res.code = TSDB_CODE_OTHERS;
return pSql->res.code; return pSql->res.code;
} }
} else if (pSql->cmd.command < TSDB_SQL_LOCAL) { } else if (pCmd->command < TSDB_SQL_LOCAL) {
pSql->ipList = tscMgmtIpSet; pSql->ipList = tscMgmtIpSet; //?
} else { // local handler } else { // local handler
return (*tscProcessMsgRsp[pCmd->command])(pSql); return (*tscProcessMsgRsp[pCmd->command])(pSql);
} }
// todo handle async situation // if (QUERY_IS_JOIN_QUERY(type)) {
if (QUERY_IS_JOIN_QUERY(type)) { // if ((pQueryInfo->type & TSDB_QUERY_TYPE_SUBQUERY) == 0) {
if ((pQueryInfo->type & TSDB_QUERY_TYPE_SUBQUERY) == 0) { // return tscHandleMasterJoinQuery(pSql);
return tscHandleMasterJoinQuery(pSql); // } else {
} else { // // for first stage sub query, iterate all vnodes to get all timestamp
// for first stage sub query, iterate all vnodes to get all timestamp // if ((pQueryInfo->type & TSDB_QUERY_TYPE_JOIN_SEC_STAGE) != TSDB_QUERY_TYPE_JOIN_SEC_STAGE) {
if ((pQueryInfo->type & TSDB_QUERY_TYPE_JOIN_SEC_STAGE) != TSDB_QUERY_TYPE_JOIN_SEC_STAGE) { // return doProcessSql(pSql);
return doProcessSql(pSql); // }
} // }
} // }
} //
// if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) { // super table query
if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) { // super table query // tscHandleMasterSTableQuery(pSql);
tscHandleMasterSTableQuery(pSql); // return pRes->code;
return pRes->code; // } else if (pSql->fp == (void(*)())tscHandleMultivnodeInsert) { // multi-vnodes insertion
} else if (pSql->fp == (void(*)())tscHandleMultivnodeInsert) { // multi-vnodes insertion // tscHandleMultivnodeInsert(pSql);
tscHandleMultivnodeInsert(pSql); // return pRes->code;
return pSql->res.code; // }
}
return doProcessSql(pSql); return doProcessSql(pSql);
} }
...@@ -493,14 +485,14 @@ void tscKillSTableQuery(SSqlObj *pSql) { ...@@ -493,14 +485,14 @@ void tscKillSTableQuery(SSqlObj *pSql) {
const int64_t MAX_WAITING_TIME = 10000; // 10 Sec. const int64_t MAX_WAITING_TIME = 10000; // 10 Sec.
int64_t stime = taosGetTimestampMs(); int64_t stime = taosGetTimestampMs();
while (pSql->cmd.command != TSDB_SQL_RETRIEVE_METRIC && pSql->cmd.command != TSDB_SQL_RETRIEVE_EMPTY_RESULT) { while (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE && pCmd->command != TSDB_SQL_RETRIEVE_EMPTY_RESULT) {
taosMsleep(100); taosMsleep(100);
if (taosGetTimestampMs() - stime > MAX_WAITING_TIME) { if (taosGetTimestampMs() - stime > MAX_WAITING_TIME) {
break; break;
} }
} }
tscTrace("%p metric query is cancelled", pSql); tscTrace("%p super table query cancelled", pSql);
} }
int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...@@ -561,7 +553,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -561,7 +553,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
// pSql->cmd.payloadLen is set during copying data into payload // pSql->cmd.payloadLen is set during copying data into payload
pSql->cmd.msgType = TSDB_MSG_TYPE_SUBMIT; pSql->cmd.msgType = TSDB_MSG_TYPE_SUBMIT;
tscSetDnodeIpList(pSql, pTableMeta); tscSetDnodeIpList(pSql, &pTableMeta->vgroupInfo);
tscTrace("%p build submit msg, vgId:%d numOfVgroup:%d numberOfIP:%d", pSql, vgId, htonl(pMsgDesc->numOfVnodes), pSql->ipList.numOfIps); tscTrace("%p build submit msg, vgId:%d numOfVgroup:%d numberOfIP:%d", pSql, vgId, htonl(pMsgDesc->numOfVnodes), pSql->ipList.numOfIps);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -591,18 +583,65 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd, int32_t clauseIndex) { ...@@ -591,18 +583,65 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd, int32_t clauseIndex) {
return size; return size;
} }
static char *doSerializeTableInfo(SSqlObj *pSql, int32_t vgId, char *pMsg) { static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char *pMsg) {
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, pSql->cmd.clauseIndex, 0); STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, pSql->cmd.clauseIndex, 0);
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
tscTrace("%p vgId:%d, query on table:%s, uid:%" PRIu64, pSql, vgId, pTableMetaInfo->name, pTableMeta->uid); if (UTIL_TABLE_IS_NOMRAL_TABLE(pTableMetaInfo) || pTableMetaInfo->pVgroupTables == NULL) {
SCMVgroupInfo* pVgroupInfo = NULL;
if (UTIL_TABLE_IS_NOMRAL_TABLE(pTableMetaInfo)) {
pVgroupInfo = &pTableMeta->vgroupInfo;
} else {
int32_t index = pTableMetaInfo->vgroupIndex;
assert(index >= 0);
pVgroupInfo = &pTableMetaInfo->vgroupList->vgroups[index];
tscTrace("%p query on stable, vgIndex:%d, numOfVgroups:%d", pSql, index, pTableMetaInfo->vgroupList->numOfVgroups);
}
tscSetDnodeIpList(pSql, pVgroupInfo);
pQueryMsg->head.vgId = htonl(pVgroupInfo->vgId);
STableIdInfo *pTableIdInfo = (STableIdInfo *)pMsg; STableIdInfo *pTableIdInfo = (STableIdInfo *)pMsg;
pTableIdInfo->sid = htonl(pTableMeta->sid); pTableIdInfo->tid = htonl(pTableMeta->sid);
pTableIdInfo->uid = htobe64(pTableMeta->uid); pTableIdInfo->uid = htobe64(pTableMeta->uid);
pTableIdInfo->key = htobe64(tscGetSubscriptionProgress(pSql->pSubscription, pTableMeta->uid)); pTableIdInfo->key = htobe64(tscGetSubscriptionProgress(pSql->pSubscription, pTableMeta->uid));
pQueryMsg->numOfTables = htonl(1); // set the number of tables
pMsg += sizeof(STableIdInfo); pMsg += sizeof(STableIdInfo);
} else {
int32_t index = pTableMetaInfo->vgroupIndex;
int32_t numOfVgroups = taosArrayGetSize(pTableMetaInfo->pVgroupTables);
assert(index >= 0 && index < numOfVgroups);
tscTrace("%p query on stable, vgIndex:%d, numOfVgroups:%d", pSql, index, numOfVgroups);
SVgroupTableInfo* pTableIdList = taosArrayGet(pTableMetaInfo->pVgroupTables, index);
// set the vgroup info
tscSetDnodeIpList(pSql, &pTableIdList->vgInfo);
pQueryMsg->head.vgId = htonl(pTableIdList->vgInfo.vgId);
int32_t numOfTables = taosArrayGetSize(pTableIdList->itemList);
pQueryMsg->numOfTables = htonl(numOfTables); // set the number of tables
// serialize each table id info
for(int32_t i = 0; i < numOfTables; ++i) {
STableIdInfo* pItem = taosArrayGet(pTableIdList->itemList, i);
STableIdInfo *pTableIdInfo = (STableIdInfo *)pMsg;
pTableIdInfo->tid = htonl(pItem->tid);
pTableIdInfo->uid = htobe64(pItem->uid);
// pTableIdInfo->key = htobe64(tscGetSubscriptionProgress(pSql->pSubscription, pTableMeta->uid));
pMsg += sizeof(STableIdInfo);
}
}
tscTrace("%p vgId:%d, query on table:%s, uid:%" PRIu64, pSql, htonl(pQueryMsg->head.vgId), pTableMetaInfo->name,
pTableMeta->uid);
return pMsg; return pMsg;
} }
...@@ -620,7 +659,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -620,7 +659,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
if (taosArrayGetSize(pQueryInfo->colList) <= 0) { if (taosArrayGetSize(pQueryInfo->colList) <= 0 && !tscQueryTags(pQueryInfo)) {
tscError("%p illegal value of numOfCols in query msg: %d", pSql, tscGetNumOfColumns(pTableMeta)); tscError("%p illegal value of numOfCols in query msg: %d", pSql, tscGetNumOfColumns(pTableMeta));
return -1; return -1;
} }
...@@ -639,38 +678,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -639,38 +678,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SQueryTableMsg *pQueryMsg = (SQueryTableMsg *)pStart; SQueryTableMsg *pQueryMsg = (SQueryTableMsg *)pStart;
int32_t msgLen = 0;
int32_t numOfTables = 0;
int32_t numOfTags = taosArrayGetSize(pTableMetaInfo->tagColList); int32_t numOfTags = taosArrayGetSize(pTableMetaInfo->tagColList);
if (UTIL_TABLE_IS_NOMRAL_TABLE(pTableMetaInfo)) {
numOfTables = 1;
tscSetDnodeIpList(pSql, pTableMeta);
pQueryMsg->head.vgId = htonl(pTableMeta->vgroupInfo.vgId);
tscTrace("%p queried tables:%d, table id: %s", pSql, 1, pTableMetaInfo->name);
} else { // query super table
int32_t index = pTableMetaInfo->vgroupIndex;
if (index < 0) {
tscError("%p error vgroupIndex:%d", pSql, index);
return -1;
}
SCMVgroupInfo* pVgroupInfo = &pTableMetaInfo->vgroupList->vgroups[index];
pSql->ipList.numOfIps = pVgroupInfo->numOfIps; // todo fix me
pSql->ipList.inUse = 0;
for(int32_t i = 0; i < pVgroupInfo->numOfIps; ++i) {
strcpy(pSql->ipList.fqdn[i], pVgroupInfo->ipAddr[i].fqdn);
pSql->ipList.port[i] = pVgroupInfo->ipAddr[i].port;
}
tscTrace("%p query on super table, numOfVgroup:%d, vgroupIndex:%d", pSql, pTableMetaInfo->vgroupList->numOfVgroups, index);
pQueryMsg->head.vgId = htonl(pVgroupInfo->vgId);
numOfTables = 1;
}
if (pQueryInfo->order.order == TSDB_ORDER_ASC) { if (pQueryInfo->order.order == TSDB_ORDER_ASC) {
pQueryMsg->window.skey = htobe64(pQueryInfo->window.skey); pQueryMsg->window.skey = htobe64(pQueryInfo->window.skey);
pQueryMsg->window.ekey = htobe64(pQueryInfo->window.ekey); pQueryMsg->window.ekey = htobe64(pQueryInfo->window.ekey);
...@@ -679,7 +688,6 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -679,7 +688,6 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pQueryMsg->window.ekey = htobe64(pQueryInfo->window.skey); pQueryMsg->window.ekey = htobe64(pQueryInfo->window.skey);
} }
pQueryMsg->numOfTables = htonl(numOfTables);
pQueryMsg->order = htons(pQueryInfo->order.order); pQueryMsg->order = htons(pQueryInfo->order.order);
pQueryMsg->orderColId = htons(pQueryInfo->order.orderColId); pQueryMsg->orderColId = htons(pQueryInfo->order.orderColId);
pQueryMsg->interpoType = htons(pQueryInfo->interpoType); pQueryMsg->interpoType = htons(pQueryInfo->interpoType);
...@@ -786,7 +794,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -786,7 +794,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
} }
// serialize the table info (sid, uid, tags) // serialize the table info (sid, uid, tags)
pMsg = doSerializeTableInfo(pSql, htons(pQueryMsg->head.vgId), pMsg); pMsg = doSerializeTableInfo(pQueryMsg, pSql, pMsg);
SSqlGroupbyExpr *pGroupbyExpr = &pQueryInfo->groupbyExpr; SSqlGroupbyExpr *pGroupbyExpr = &pQueryInfo->groupbyExpr;
if (pGroupbyExpr->numOfGroupCols > 0) { if (pGroupbyExpr->numOfGroupCols > 0) {
...@@ -825,7 +833,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -825,7 +833,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pSchema = tscGetTableTagSchema(pTableMeta); pSchema = tscGetTableTagSchema(pTableMeta);
for (int32_t i = 0; i < numOfTags; ++i) { for (int32_t i = 0; i < numOfTags; ++i) {
SColumn *pCol = taosArrayGetP(pQueryInfo->colList, i); SColumn *pCol = taosArrayGetP(pTableMetaInfo->tagColList, i);
SSchema *pColSchema = &pSchema[pCol->colIndex.columnIndex]; SSchema *pColSchema = &pSchema[pCol->colIndex.columnIndex];
if ((pCol->colIndex.columnIndex >= numOfTagColumns || pCol->colIndex.columnIndex < -1) || if ((pCol->colIndex.columnIndex >= numOfTagColumns || pCol->colIndex.columnIndex < -1) ||
...@@ -893,8 +901,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -893,8 +901,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg += strlen(pQueryInfo->tagCond.tbnameCond.cond) + 1; pMsg += strlen(pQueryInfo->tagCond.tbnameCond.cond) + 1;
} }
// tbname in/like query expression should be sent to mgmt node int32_t msgLen = pMsg - pStart;
msgLen = pMsg - pStart;
tscTrace("%p msg built success,len:%d bytes", pSql, msgLen); tscTrace("%p msg built success,len:%d bytes", pSql, msgLen);
pCmd->payloadLen = msgLen; pCmd->payloadLen = msgLen;
...@@ -1450,11 +1457,11 @@ int tscProcessTagRetrieveRsp(SSqlObj *pSql) { ...@@ -1450,11 +1457,11 @@ int tscProcessTagRetrieveRsp(SSqlObj *pSql) {
return tscLocalResultCommonBuilder(pSql, numOfRes); return tscLocalResultCommonBuilder(pSql, numOfRes);
} }
int tscProcessRetrieveMetricRsp(SSqlObj *pSql) { int tscProcessRetrieveLocalMergeRsp(SSqlObj *pSql) {
SSqlRes *pRes = &pSql->res; SSqlRes *pRes = &pSql->res;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
pRes->code = tscDoLocalreduce(pSql); pRes->code = tscDoLocalMerge(pSql);
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
if (pRes->code == TSDB_CODE_SUCCESS && pRes->numOfRows > 0) { if (pRes->code == TSDB_CODE_SUCCESS && pRes->numOfRows > 0) {
...@@ -1464,13 +1471,11 @@ int tscProcessRetrieveMetricRsp(SSqlObj *pSql) { ...@@ -1464,13 +1471,11 @@ int tscProcessRetrieveMetricRsp(SSqlObj *pSql) {
pRes->row = 0; pRes->row = 0;
uint8_t code = pRes->code; uint8_t code = pRes->code;
if (pSql->fp) { // async retrieve metric data
if (pRes->code == TSDB_CODE_SUCCESS) { if (pRes->code == TSDB_CODE_SUCCESS) {
(*pSql->fp)(pSql->param, pSql, pRes->numOfRows); (*pSql->fp)(pSql->param, pSql, pRes->numOfRows);
} else { } else {
tscQueueAsyncRes(pSql); tscQueueAsyncRes(pSql);
} }
}
return code; return code;
} }
...@@ -1581,32 +1586,32 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -1581,32 +1586,32 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
return pCmd->payloadLen; return pCmd->payloadLen;
} }
static UNUSED_FUNC int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) { //static UNUSED_FUNC int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) {
const int32_t defaultSize = //// const int32_t defaultSize =
minMsgSize() + sizeof(SSuperTableMetaMsg) + sizeof(SMgmtHead) + sizeof(int16_t) * TSDB_MAX_TAGS; //// minMsgSize() + sizeof(SSuperTableMetaMsg) + sizeof(SMgmtHead) + sizeof(int16_t) * TSDB_MAX_TAGS;
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); //// SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
////
int32_t n = 0; //// int32_t n = 0;
size_t size = taosArrayGetSize(pQueryInfo->tagCond.pCond); //// size_t size = taosArrayGetSize(pQueryInfo->tagCond.pCond);
for (int32_t i = 0; i < size; ++i) { //// for (int32_t i = 0; i < size; ++i) {
assert(0); //// assert(0);
// n += strlen(pQueryInfo->tagCond.cond[i].cond); ////// n += strlen(pQueryInfo->tagCond.cond[i].cond);
} //// }
////
int32_t tagLen = n * TSDB_NCHAR_SIZE; //// int32_t tagLen = n * TSDB_NCHAR_SIZE;
if (pQueryInfo->tagCond.tbnameCond.cond != NULL) { //// if (pQueryInfo->tagCond.tbnameCond.cond != NULL) {
tagLen += strlen(pQueryInfo->tagCond.tbnameCond.cond) * TSDB_NCHAR_SIZE; //// tagLen += strlen(pQueryInfo->tagCond.tbnameCond.cond) * TSDB_NCHAR_SIZE;
} //// }
////
int32_t joinCondLen = (TSDB_TABLE_ID_LEN + sizeof(int16_t)) * 2; //// int32_t joinCondLen = (TSDB_TABLE_ID_LEN + sizeof(int16_t)) * 2;
int32_t elemSize = sizeof(SSuperTableMetaElemMsg) * pQueryInfo->numOfTables; //// int32_t elemSize = sizeof(SSuperTableMetaElemMsg) * pQueryInfo->numOfTables;
////
int32_t colSize = pQueryInfo->groupbyExpr.numOfGroupCols*sizeof(SColIndex); //// int32_t colSize = pQueryInfo->groupbyExpr.numOfGroupCols*sizeof(SColIndex);
////
int32_t len = tagLen + joinCondLen + elemSize + colSize + defaultSize; //// int32_t len = tagLen + joinCondLen + elemSize + colSize + defaultSize;
////
return MAX(len, TSDB_DEFAULT_PAYLOAD_SIZE); //// return MAX(len, TSDB_DEFAULT_PAYLOAD_SIZE);
} //}
int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...@@ -1755,13 +1760,21 @@ int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -1755,13 +1760,21 @@ int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); char* pMsg = pCmd->payload;
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
SCMSTableVgroupMsg *pStableVgroupMsg = (SCMSTableVgroupMsg *) pCmd->payload; SCMSTableVgroupMsg *pStableVgroupMsg = (SCMSTableVgroupMsg *) pMsg;
strncpy(pStableVgroupMsg->tableId, pTableMetaInfo->name, tListLen(pStableVgroupMsg->tableId)); pStableVgroupMsg->numOfTables = htonl(pQueryInfo->numOfTables);
pMsg += sizeof(SCMSTableVgroupMsg);
for(int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, i);
strncpy(pMsg, pTableMetaInfo->name, TSDB_TABLE_ID_LEN);
pMsg += TSDB_TABLE_ID_LEN;
}
pCmd->msgType = TSDB_MSG_TYPE_CM_STABLE_VGROUP; pCmd->msgType = TSDB_MSG_TYPE_CM_STABLE_VGROUP;
pCmd->payloadLen = sizeof(SCMSTableVgroupMsg); pCmd->payloadLen = (pMsg - pCmd->payload);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -2116,27 +2129,37 @@ _error_clean: ...@@ -2116,27 +2129,37 @@ _error_clean:
#endif #endif
SSqlRes* pRes = &pSql->res; SSqlRes* pRes = &pSql->res;
// NOTE: the order of several table must be preserved.
SCMSTableVgroupRspMsg *pStableVgroup = (SCMSTableVgroupRspMsg *)pRes->pRsp; SCMSTableVgroupRspMsg *pStableVgroup = (SCMSTableVgroupRspMsg *)pRes->pRsp;
pStableVgroup->numOfVgroups = htonl(pStableVgroup->numOfVgroups); pStableVgroup->numOfTables = htonl(pStableVgroup->numOfTables);
char* pMsg = pRes->pRsp + sizeof(SCMSTableVgroupRspMsg);
// master sqlObj locates in param // master sqlObj locates in param
SSqlObj* parent = pSql->param; SSqlObj* parent = pSql->param;
assert(parent != NULL); assert(parent != NULL);
SSqlCmd* pCmd = &parent->cmd; SSqlCmd* pCmd = &parent->cmd;
STableMetaInfo* pInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); for(int32_t i = 0; i < pStableVgroup->numOfTables; ++i) {
STableMetaInfo *pInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, i);
SVgroupsInfo * pVgroupInfo = (SVgroupsInfo *)pMsg;
pVgroupInfo->numOfVgroups = htonl(pVgroupInfo->numOfVgroups);
pInfo->vgroupList = malloc(pRes->rspLen); size_t size = sizeof(SCMVgroupInfo) * pVgroupInfo->numOfVgroups + sizeof(SVgroupsInfo);
memcpy(pInfo->vgroupList, pStableVgroup, pRes->rspLen); pInfo->vgroupList = calloc(1, size);
assert(pInfo->vgroupList != NULL);
for(int32_t i = 0; i < pInfo->vgroupList->numOfVgroups; ++i) { memcpy(pInfo->vgroupList, pVgroupInfo, size);
SCMVgroupInfo* pVgroups = &pInfo->vgroupList->vgroups[i]; for (int32_t j = 0; j < pInfo->vgroupList->numOfVgroups; ++j) {
SCMVgroupInfo *pVgroups = &pInfo->vgroupList->vgroups[j];
pVgroups->vgId = htonl(pVgroups->vgId); pVgroups->vgId = htonl(pVgroups->vgId);
assert(pVgroups->numOfIps >= 1); assert(pVgroups->numOfIps >= 1);
for(int32_t j = 0; j < pVgroups->numOfIps; ++j) { for (int32_t k = 0; k < pVgroups->numOfIps; ++k) {
pVgroups->ipAddr[j].port = htons(pVgroups->ipAddr[j].port); pVgroups->ipAddr[k].port = htons(pVgroups->ipAddr[k].port);
}
pMsg += size;
} }
} }
...@@ -2230,7 +2253,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) { ...@@ -2230,7 +2253,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
strcpy(pObj->sversion, pConnect->serverVersion); strcpy(pObj->sversion, pConnect->serverVersion);
pObj->writeAuth = pConnect->writeAuth; pObj->writeAuth = pConnect->writeAuth;
pObj->superAuth = pConnect->superAuth; pObj->superAuth = pConnect->superAuth;
taosTmrReset(tscProcessActivityTimer, tsShellActivityTimer * 500, pObj, tscTmr, &pObj->pTimer); // taosTmrReset(tscProcessActivityTimer, tsShellActivityTimer * 500, pObj, tscTmr, &pObj->pTimer);
return 0; return 0;
} }
...@@ -2269,7 +2292,6 @@ int tscProcessDropTableRsp(SSqlObj *pSql) { ...@@ -2269,7 +2292,6 @@ int tscProcessDropTableRsp(SSqlObj *pSql) {
if (pTableMetaInfo->pTableMeta) { if (pTableMetaInfo->pTableMeta) {
taosCacheRelease(tscCacheHandle, (void **)&(pTableMetaInfo->pTableMeta), true); taosCacheRelease(tscCacheHandle, (void **)&(pTableMetaInfo->pTableMeta), true);
// taosCacheRelease(tscCacheHandle, (void **)&(pTableMetaInfo->pMetricMeta), true);
} }
return 0; return 0;
...@@ -2495,41 +2517,26 @@ int tscRenewMeterMeta(SSqlObj *pSql, char *tableId) { ...@@ -2495,41 +2517,26 @@ int tscRenewMeterMeta(SSqlObj *pSql, char *tableId) {
return code; return code;
} }
int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) { static bool allVgroupInfoRetrieved(SSqlCmd* pCmd, int32_t clauseIndex) {
int code = TSDB_CODE_NETWORK_UNAVAIL;
SSqlCmd *pCmd = &pSql->cmd;
//the query condition is serialized into pCmd->payload, we need to rebuild key for stable meta info in cache.
// bool required = false;
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, clauseIndex); SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, clauseIndex);
if (pQueryInfo->pTableMetaInfo[0]->vgroupList != NULL) {
return TSDB_CODE_SUCCESS;
}
#if 0
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
char tagstr[TSDB_MAX_TAGS_LEN + 1] = {0};
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, i); STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, i);
tscGetMetricMetaCacheKey(pQueryInfo, tagstr, pTableMetaInfo->pTableMeta->uid); if (pTableMetaInfo->vgroupList == NULL) {
return false;
// taosCacheRelease(tscCacheHandle, (void **)&(pTableMetaInfo->pMetricMeta), false);
SSuperTableMeta *ppMeta = (SSuperTableMeta *)taosCacheAcquireByName(tscCacheHandle, tagstr);
if (ppMeta == NULL) {
required = true;
break;
} else {
// pTableMetaInfo->pMetricMeta = ppMeta;
} }
} }
// all metricmeta for one clause are retrieved from cache, no need to retrieve metricmeta from management node // all super tables vgroupinfo are retrieved, no need to retrieve vgroup info anymore
if (!required) { return true;
}
int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
int code = TSDB_CODE_NETWORK_UNAVAIL;
SSqlCmd *pCmd = &pSql->cmd;
if (allVgroupInfoRetrieved(pCmd, clauseIndex)) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
#endif
SSqlObj *pNew = calloc(1, sizeof(SSqlObj)); SSqlObj *pNew = calloc(1, sizeof(SSqlObj));
pNew->pTscObj = pSql->pTscObj; pNew->pTscObj = pSql->pTscObj;
...@@ -2542,11 +2549,11 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) { ...@@ -2542,11 +2549,11 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
return code; return code;
} }
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, clauseIndex);
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
STableMetaInfo *pMMInfo = tscGetMetaInfo(pQueryInfo, i); STableMetaInfo *pMInfo = tscGetMetaInfo(pQueryInfo, i);
STableMeta *pTableMeta = taosCacheAcquireByData(tscCacheHandle, pMInfo->pTableMeta);
STableMeta *pTableMeta = taosCacheAcquireByName(tscCacheHandle, pMMInfo->name); tscAddTableMetaInfo(pNewQueryInfo, pMInfo->name, pTableMeta, NULL, pMInfo->tagColList);
tscAddTableMetaInfo(pNewQueryInfo, pMMInfo->name, pTableMeta, NULL, pMMInfo->tagColList);
} }
if ((code = tscAllocPayload(&pNew->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) != TSDB_CODE_SUCCESS) { if ((code = tscAllocPayload(&pNew->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) != TSDB_CODE_SUCCESS) {
...@@ -2554,25 +2561,9 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) { ...@@ -2554,25 +2561,9 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
return code; return code;
} }
tscTagCondCopy(&pNewQueryInfo->tagCond, &pQueryInfo->tagCond);
pNewQueryInfo->groupbyExpr = pQueryInfo->groupbyExpr;
pNewQueryInfo->numOfTables = pQueryInfo->numOfTables; pNewQueryInfo->numOfTables = pQueryInfo->numOfTables;
tscTrace("%p new sqlObj:%p to get vgroupInfo, numOfTables:%d", pSql, pNew, pNewQueryInfo->numOfTables);
pNewQueryInfo->slimit = pQueryInfo->slimit;
pNewQueryInfo->order = pQueryInfo->order;
STagCond* pTagCond = &pNewQueryInfo->tagCond;
tscTrace("%p new sqlobj:%p info, numOfTables:%d, slimit:%" PRId64 ", soffset:%" PRId64 ", order:%d, tbname cond:%s",
pSql, pNew, pNewQueryInfo->numOfTables, pNewQueryInfo->slimit.limit, pNewQueryInfo->slimit.offset,
pNewQueryInfo->order.order, pTagCond->tbnameCond.cond)
// if (pSql->fp != NULL && pSql->pStream == NULL) {
// pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
// tscFreeQueryInfo(pCmd);
// }
tscTrace("%p allocate new pSqlObj:%p to get stable vgroupInfo", pSql, pNew);
pNew->fp = tscTableMetaCallBack; pNew->fp = tscTableMetaCallBack;
pNew->param = pSql; pNew->param = pSql;
code = tscProcessSql(pNew); code = tscProcessSql(pNew);
...@@ -2634,7 +2625,6 @@ void tscInitMsgsFp() { ...@@ -2634,7 +2625,6 @@ void tscInitMsgsFp() {
tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromNode; // rsp handled by same function. tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromNode; // rsp handled by same function.
tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp; tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp;
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_TAGS] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_CURRENT_USER] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_CURRENT_USER] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_SERV_VERSION] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_SERV_VERSION] = tscProcessTagRetrieveRsp;
...@@ -2643,7 +2633,7 @@ void tscInitMsgsFp() { ...@@ -2643,7 +2633,7 @@ void tscInitMsgsFp() {
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp;
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_METRIC] = tscProcessRetrieveMetricRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_LOCALMERGE] = tscProcessRetrieveLocalMergeRsp;
tscProcessMsgRsp[TSDB_SQL_ALTER_TABLE] = tscProcessAlterTableMsgRsp; tscProcessMsgRsp[TSDB_SQL_ALTER_TABLE] = tscProcessAlterTableMsgRsp;
tscProcessMsgRsp[TSDB_SQL_ALTER_DB] = tscProcessAlterDbMsgRsp; tscProcessMsgRsp[TSDB_SQL_ALTER_DB] = tscProcessAlterDbMsgRsp;
......
...@@ -218,8 +218,9 @@ TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, ...@@ -218,8 +218,9 @@ TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port,
void taos_close(TAOS *taos) { void taos_close(TAOS *taos) {
STscObj *pObj = (STscObj *)taos; STscObj *pObj = (STscObj *)taos;
if (pObj == NULL) return; if (pObj == NULL || pObj->signature != pObj) {
if (pObj->signature != pObj) return; return;
}
if (pObj->pHb != NULL) { if (pObj->pHb != NULL) {
tscSetFreeHeatBeat(pObj); tscSetFreeHeatBeat(pObj);
...@@ -264,7 +265,7 @@ int taos_query_imp(STscObj *pObj, SSqlObj *pSql) { ...@@ -264,7 +265,7 @@ int taos_query_imp(STscObj *pObj, SSqlObj *pSql) {
} }
if (pRes->code != TSDB_CODE_SUCCESS) { if (pRes->code != TSDB_CODE_SUCCESS) {
tscFreeSqlObjPartial(pSql); tscPartiallyFreeSqlObj(pSql);
} }
return pRes->code; return pRes->code;
...@@ -412,7 +413,7 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) { ...@@ -412,7 +413,7 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
} }
// secondary merge has handle this situation // secondary merge has handle this situation
if (pCmd->command != TSDB_SQL_RETRIEVE_METRIC) { if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE) {
pRes->numOfTotalInCurrentClause += pRes->numOfRows; pRes->numOfTotalInCurrentClause += pRes->numOfRows;
} }
...@@ -420,8 +421,9 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) { ...@@ -420,8 +421,9 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
if (pQueryInfo == NULL) if (pQueryInfo == NULL)
return 0; return 0;
assert(0);
for (int i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { for (int i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
pRes->tsrow[i] = tscGetResultColumnChr(pRes, pQueryInfo, i); pRes->tsrow[i] = tscGetResultColumnChr(pRes, pQueryInfo, i, 0);
} }
*rows = pRes->tsrow; *rows = pRes->tsrow;
...@@ -429,32 +431,9 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) { ...@@ -429,32 +431,9 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
return (pQueryInfo->order.order == TSDB_ORDER_DESC) ? pRes->numOfRows : -pRes->numOfRows; return (pQueryInfo->order.order == TSDB_ORDER_DESC) ? pRes->numOfRows : -pRes->numOfRows;
} }
static void transferNcharData(SSqlObj *pSql, int32_t columnIndex, TAOS_FIELD *pField) { static UNUSED_FUNC char *getArithemicInputSrc(void *param, const char *name, int32_t colId) {
SSqlRes *pRes = &pSql->res;
if (isNull(pRes->tsrow[columnIndex], pField->type)) {
pRes->tsrow[columnIndex] = NULL;
} else if (pField->type == TSDB_DATA_TYPE_NCHAR) {
// convert unicode to native code in a temporary buffer extra one byte for terminated symbol
if (pRes->buffer[columnIndex] == NULL) {
pRes->buffer[columnIndex] = malloc(pField->bytes + TSDB_NCHAR_SIZE);
}
/* string terminated char for binary data*/
memset(pRes->buffer[columnIndex], 0, pField->bytes + TSDB_NCHAR_SIZE);
if (taosUcs4ToMbs(pRes->tsrow[columnIndex], pField->bytes, pRes->buffer[columnIndex])) {
pRes->tsrow[columnIndex] = pRes->buffer[columnIndex];
} else {
tscError("%p charset:%s to %s. val:%ls convert failed.", pSql, DEFAULT_UNICODE_ENCODEC, tsCharset, pRes->tsrow);
pRes->tsrow[columnIndex] = NULL;
}
}
}
static char *getArithemicInputSrc(void *param, const char *name, int32_t colId) {
// SArithmeticSupport *pSupport = (SArithmeticSupport *)param; // SArithmeticSupport *pSupport = (SArithmeticSupport *)param;
// SArithExprInfo * pExpr = pSupport->pArithExpr; // SExprInfo * pExpr = pSupport->pArithExpr;
// int32_t index = -1; // int32_t index = -1;
// for (int32_t i = 0; i < pExpr->numOfCols; ++i) { // for (int32_t i = 0; i < pExpr->numOfCols; ++i) {
...@@ -469,210 +448,6 @@ static char *getArithemicInputSrc(void *param, const char *name, int32_t colId) ...@@ -469,210 +448,6 @@ static char *getArithemicInputSrc(void *param, const char *name, int32_t colId)
return 0; return 0;
} }
static void **doSetResultRowData(SSqlObj *pSql) {
SSqlCmd *pCmd = &pSql->cmd;
SSqlRes *pRes = &pSql->res;
assert(pRes->row >= 0 && pRes->row <= pRes->numOfRows);
if (pRes->row >= pRes->numOfRows) { // all the results has returned to invoker
tfree(pRes->tsrow);
return pRes->tsrow;
}
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
//todo refactor move away
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
for(int32_t k = 0; k < numOfExprs; ++k) {
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, k);
if (k > 0) {
SSqlExpr* pPrev = tscSqlExprGet(pQueryInfo, k - 1);
pExpr->offset = pPrev->offset + pPrev->resBytes;
}
}
int32_t num = 0;
for (int i = 0; i < tscNumOfFields(pQueryInfo); ++i) {
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, i);
if (pInfo->pSqlExpr != NULL) {
pRes->tsrow[i] = tscGetResultColumnChr(pRes, pQueryInfo, i) + pInfo->pSqlExpr->resBytes * pRes->row;
} else {
assert(0);
}
// primary key column cannot be null in interval query, no need to check
if (i == 0 && pQueryInfo->intervalTime > 0) {
continue;
}
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
transferNcharData(pSql, i, pField);
// calculate the result from several other columns
if (pInfo->pArithExprInfo != NULL) {
SArithmeticSupport *sas = (SArithmeticSupport *)calloc(1, sizeof(SArithmeticSupport));
sas->offset = 0;
sas->pArithExpr = pInfo->pArithExprInfo;
// sas->numOfCols = sas->pArithExpr->numOfCols;
if (pRes->buffer[i] == NULL) {
pRes->buffer[i] = malloc(tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i)->bytes);
}
for(int32_t k = 0; k < sas->numOfCols; ++k) {
// int32_t columnIndex = sas->pArithExpr->colList[k].colIndex;
// SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, columnIndex);
//
// sas->elemSize[k] = pExpr->resBytes;
// sas->data[k] = (pRes->data + pRes->numOfRows* pExpr->offset) + pRes->row*pExpr->resBytes;
}
tExprTreeCalcTraverse(sas->pArithExpr->pExpr, 1, pRes->buffer[i], sas, TSDB_ORDER_ASC, getArithemicInputSrc);
pRes->tsrow[i] = pRes->buffer[i];
free(sas); //todo optimization
}
}
assert(num <= pQueryInfo->fieldsInfo.numOfOutput);
pRes->row++; // index increase one-step
return pRes->tsrow;
}
static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) {
bool hasData = true;
SSqlCmd *pCmd = &pSql->cmd;
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) {
bool allSubqueryExhausted = true;
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
if (pSql->pSubs[i] == NULL) {
continue;
}
// SSqlRes *pRes1 = &pSql->pSubs[i]->res;
SSqlCmd *pCmd1 = &pSql->pSubs[i]->cmd;
SQueryInfo * pQueryInfo1 = tscGetQueryInfoDetail(pCmd1, pCmd1->clauseIndex);
// STableMetaInfo *pMetaInfo = tscGetMetaInfo(pQueryInfo1, 0);
assert(pQueryInfo1->numOfTables == 1);
/*
* if the global limitation is not reached, and current result has not exhausted, or next more vnodes are
* available, goes on
*/
// if (pMetaInfo->vnodeIndex < pMetaInfo->pMetricMeta->numOfVnodes && pRes1->row < pRes1->numOfRows &&
// (!tscHasReachLimitation(pQueryInfo1, pRes1))) {
// allSubqueryExhausted = false;
// break;
// }
}
hasData = !allSubqueryExhausted;
} else { // otherwise, in case inner join, if any subquery exhausted, query completed.
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
if (pSql->pSubs[i] == 0) {
continue;
}
SSqlRes * pRes1 = &pSql->pSubs[i]->res;
SQueryInfo *pQueryInfo1 = tscGetQueryInfoDetail(&pSql->pSubs[i]->cmd, 0);
if ((pRes1->row >= pRes1->numOfRows && tscHasReachLimitation(pQueryInfo1, pRes1) &&
tscProjectionQueryOnTable(pQueryInfo1)) ||
(pRes1->numOfRows == 0)) {
hasData = false;
break;
}
}
}
return hasData;
}
static UNUSED_FUNC void **tscBuildResFromSubqueries(SSqlObj *pSql) {
SSqlRes *pRes = &pSql->res;
while (1) {
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
if (pRes->tsrow == NULL) {
pRes->tsrow = calloc(numOfExprs, POINTER_BYTES);
}
bool success = false;
int32_t numOfTableHasRes = 0;
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
if (pSql->pSubs[i] != 0) {
numOfTableHasRes++;
}
}
if (numOfTableHasRes >= 2) { // do merge result
success = (doSetResultRowData(pSql->pSubs[0]) != NULL) && (doSetResultRowData(pSql->pSubs[1]) != NULL);
} else { // only one subquery
SSqlObj *pSub = pSql->pSubs[0];
if (pSub == NULL) {
pSub = pSql->pSubs[1];
}
success = (doSetResultRowData(pSub) != NULL);
}
if (success) { // current row of final output has been built, return to app
for (int32_t i = 0; i < numOfExprs; ++i) {
int32_t tableIndex = pRes->pColumnIndex[i].tableIndex;
int32_t columnIndex = pRes->pColumnIndex[i].columnIndex;
SSqlRes *pRes1 = &pSql->pSubs[tableIndex]->res;
pRes->tsrow[i] = pRes1->tsrow[columnIndex];
}
pRes->numOfTotalInCurrentClause++;
break;
} else { // continue retrieve data from vnode
if (!tscHashRemainDataInSubqueryResultSet(pSql)) {
tscTrace("%p at least one subquery exhausted, free all other %d subqueries", pSql, pSql->numOfSubs - 1);
SSubqueryState *pState = NULL;
// free all sub sqlobj
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
SSqlObj *pChildObj = pSql->pSubs[i];
if (pChildObj == NULL) {
continue;
}
SJoinSubquerySupporter *pSupporter = (SJoinSubquerySupporter *)pChildObj->param;
pState = pSupporter->pState;
tscDestroyJoinSupporter(pChildObj->param);
taos_free_result(pChildObj);
}
free(pState);
return NULL;
}
tscFetchDatablockFromSubquery(pSql);
if (pRes->code != TSDB_CODE_SUCCESS) {
return NULL;
}
}
}
return pRes->tsrow;
}
static void waitForRetrieveRsp(void *param, TAOS_RES *tres, int numOfRows) { static void waitForRetrieveRsp(void *param, TAOS_RES *tres, int numOfRows) {
SSqlObj* pSql = (SSqlObj*) tres; SSqlObj* pSql = (SSqlObj*) tres;
...@@ -699,15 +474,19 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { ...@@ -699,15 +474,19 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
} }
// current data are exhausted, fetch more data // current data are exhausted, fetch more data
if (pRes->data == NULL || (pRes->data != NULL && pRes->row >= pRes->numOfRows && pRes->completed != true && if (pRes->row >= pRes->numOfRows && pRes->completed != true &&
(pCmd->command == TSDB_SQL_RETRIEVE || pCmd->command == TSDB_SQL_RETRIEVE_METRIC || (pCmd->command == TSDB_SQL_RETRIEVE ||
pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_DESCRIBE_TABLE))) { pCmd->command == TSDB_SQL_RETRIEVE_LOCALMERGE ||
pCmd->command == TSDB_SQL_METRIC_JOIN_RETRIEVE ||
pCmd->command == TSDB_SQL_FETCH ||
pCmd->command == TSDB_SQL_SHOW ||
pCmd->command == TSDB_SQL_SELECT ||
pCmd->command == TSDB_SQL_DESCRIBE_TABLE)) {
taos_fetch_rows_a(res, waitForRetrieveRsp, pSql->pTscObj); taos_fetch_rows_a(res, waitForRetrieveRsp, pSql->pTscObj);
sem_wait(&pSql->rspSem); sem_wait(&pSql->rspSem);
} }
return doSetResultRowData(pSql); return doSetResultRowData(pSql, true);
} }
int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
...@@ -793,7 +572,7 @@ void taos_free_result_imp(TAOS_RES *res, int keepCmd) { ...@@ -793,7 +572,7 @@ void taos_free_result_imp(TAOS_RES *res, int keepCmd) {
if (keepCmd) { if (keepCmd) {
tscFreeSqlResult(pSql); tscFreeSqlResult(pSql);
} else { } else {
tscFreeSqlObjPartial(pSql); tscPartiallyFreeSqlObj(pSql);
} }
} }
...@@ -803,7 +582,7 @@ void taos_free_result_imp(TAOS_RES *res, int keepCmd) { ...@@ -803,7 +582,7 @@ void taos_free_result_imp(TAOS_RES *res, int keepCmd) {
// 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
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
if (pQueryInfo == NULL) { if (pQueryInfo == NULL) {
tscFreeSqlObjPartial(pSql); tscPartiallyFreeSqlObj(pSql);
return; return;
} }
...@@ -855,7 +634,7 @@ void taos_free_result_imp(TAOS_RES *res, int keepCmd) { ...@@ -855,7 +634,7 @@ void taos_free_result_imp(TAOS_RES *res, int keepCmd) {
tscFreeSqlResult(pSql); tscFreeSqlResult(pSql);
tscTrace("%p sql result is freed by app while sql command is kept", pSql); tscTrace("%p sql result is freed by app while sql command is kept", pSql);
} else { } else {
tscFreeSqlObjPartial(pSql); tscPartiallyFreeSqlObj(pSql);
tscTrace("%p sql result is freed by app", pSql); tscTrace("%p sql result is freed by app", pSql);
} }
} else { // for async release, remove its link } else { // for async release, remove its link
...@@ -876,7 +655,7 @@ void taos_free_result_imp(TAOS_RES *res, int keepCmd) { ...@@ -876,7 +655,7 @@ void taos_free_result_imp(TAOS_RES *res, int keepCmd) {
tscFreeSqlResult(pSql); tscFreeSqlResult(pSql);
tscTrace("%p sql result is freed while sql command is kept", pSql); tscTrace("%p sql result is freed while sql command is kept", pSql);
} else { } else {
tscFreeSqlObjPartial(pSql); tscPartiallyFreeSqlObj(pSql);
tscTrace("%p sql result is freed by app", pSql); tscTrace("%p sql result is freed by app", pSql);
} }
} }
...@@ -1221,7 +1000,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { ...@@ -1221,7 +1000,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
tscTrace("%p load multi metermeta result:%d %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj); tscTrace("%p load multi metermeta result:%d %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
if (pRes->code != TSDB_CODE_SUCCESS) { if (pRes->code != TSDB_CODE_SUCCESS) {
tscFreeSqlObjPartial(pSql); tscPartiallyFreeSqlObj(pSql);
} }
return pRes->code; return pRes->code;
......
...@@ -14,19 +14,22 @@ ...@@ -14,19 +14,22 @@
*/ */
#include "tscSubquery.h" #include "tscSubquery.h"
#include <tcompare.h>
#include <tschemautil.h>
#include "os.h" #include "os.h"
#include "qtsbuf.h" #include "qtsbuf.h"
#include "tsclient.h"
#include "tscLog.h" #include "tscLog.h"
#include "tsclient.h"
typedef struct SInsertSupporter { typedef struct SInsertSupporter {
SSubqueryState* pState; SSubqueryState* pState;
SSqlObj* pSql; SSqlObj* pSql;
} SInsertSupporter; } SInsertSupporter;
static void freeSubqueryObj(SSqlObj* pSql); static void freeJoinSubqueryObj(SSqlObj* pSql);
static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql);
static bool doCompare(int32_t order, int64_t left, int64_t right) { static bool tsCompare(int32_t order, int64_t left, int64_t right) {
if (order == TSDB_ORDER_ASC) { if (order == TSDB_ORDER_ASC) {
return left < right; return left < right;
} else { } else {
...@@ -34,8 +37,8 @@ static bool doCompare(int32_t order, int64_t left, int64_t right) { ...@@ -34,8 +37,8 @@ static bool doCompare(int32_t order, int64_t left, int64_t right) {
} }
} }
static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSupporter1, static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1,
SJoinSubquerySupporter* pSupporter2, TSKEY* st, TSKEY* et) { SJoinSupporter* pSupporter2, TSKEY* st, TSKEY* et) {
STSBuf* output1 = tsBufCreate(true); STSBuf* output1 = tsBufCreate(true);
STSBuf* output2 = tsBufCreate(true); STSBuf* output2 = tsBufCreate(true);
...@@ -81,17 +84,16 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor ...@@ -81,17 +84,16 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor
STSElem elem2 = tsBufGetElem(pSupporter2->pTSBuf); STSElem elem2 = tsBufGetElem(pSupporter2->pTSBuf);
#ifdef _DEBUG_VIEW #ifdef _DEBUG_VIEW
// for debug purpose
tscPrint("%" PRId64 ", tags:%d \t %" PRId64 ", tags:%d", elem1.ts, elem1.tag, elem2.ts, elem2.tag); tscPrint("%" PRId64 ", tags:%d \t %" PRId64 ", tags:%d", elem1.ts, elem1.tag, elem2.ts, elem2.tag);
#endif #endif
if (elem1.tag < elem2.tag || (elem1.tag == elem2.tag && doCompare(order, elem1.ts, elem2.ts))) { if (elem1.tag < elem2.tag || (elem1.tag == elem2.tag && tsCompare(order, elem1.ts, elem2.ts))) {
if (!tsBufNextPos(pSupporter1->pTSBuf)) { if (!tsBufNextPos(pSupporter1->pTSBuf)) {
break; break;
} }
numOfInput1++; numOfInput1++;
} else if (elem1.tag > elem2.tag || (elem1.tag == elem2.tag && doCompare(order, elem2.ts, elem1.ts))) { } else if (elem1.tag > elem2.tag || (elem1.tag == elem2.tag && tsCompare(order, elem2.ts, elem1.ts))) {
if (!tsBufNextPos(pSupporter2->pTSBuf)) { if (!tsBufNextPos(pSupporter2->pTSBuf)) {
break; break;
} }
...@@ -155,8 +157,8 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor ...@@ -155,8 +157,8 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor
} }
// todo handle failed to create sub query // todo handle failed to create sub query
SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, int32_t index) { SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, int32_t index) {
SJoinSubquerySupporter* pSupporter = calloc(1, sizeof(SJoinSubquerySupporter)); SJoinSupporter* pSupporter = calloc(1, sizeof(SJoinSupporter));
if (pSupporter == NULL) { if (pSupporter == NULL) {
return NULL; return NULL;
} }
...@@ -172,7 +174,6 @@ SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pS ...@@ -172,7 +174,6 @@ SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pS
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, pSql->cmd.clauseIndex, index); STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, pSql->cmd.clauseIndex, index);
pSupporter->uid = pTableMetaInfo->pTableMeta->uid; pSupporter->uid = pTableMetaInfo->pTableMeta->uid;
assert (pSupporter->uid != 0); assert (pSupporter->uid != 0);
getTmpfilePath("join-", pSupporter->path); getTmpfilePath("join-", pSupporter->path);
...@@ -185,19 +186,25 @@ SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pS ...@@ -185,19 +186,25 @@ SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pS
return pSupporter; return pSupporter;
} }
void tscDestroyJoinSupporter(SJoinSubquerySupporter* pSupporter) { void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) {
if (pSupporter == NULL) { if (pSupporter == NULL) {
return; return;
} }
tscSqlExprInfoDestroy(pSupporter->exprsInfo); if (pSupporter->exprList != NULL) {
tscSqlExprInfoDestroy(pSupporter->exprList);
}
if (pSupporter->colList != NULL) {
tscColumnListDestroy(pSupporter->colList); tscColumnListDestroy(pSupporter->colList);
}
tscFieldInfoClear(&pSupporter->fieldsInfo); tscFieldInfoClear(&pSupporter->fieldsInfo);
if (pSupporter->f != NULL) { if (pSupporter->f != NULL) {
fclose(pSupporter->f); fclose(pSupporter->f);
unlink(pSupporter->path); unlink(pSupporter->path);
pSupporter->f = NULL;
} }
tscTagCondRelease(&pSupporter->tagCond); tscTagCondRelease(&pSupporter->tagCond);
...@@ -228,17 +235,15 @@ bool needSecondaryQuery(SQueryInfo* pQueryInfo) { ...@@ -228,17 +235,15 @@ bool needSecondaryQuery(SQueryInfo* pQueryInfo) {
*/ */
int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
int32_t numOfSub = 0; int32_t numOfSub = 0;
SJoinSubquerySupporter* pSupporter = NULL; SJoinSupporter* pSupporter = NULL;
/* /*
* If the columns are not involved in the final select clause, the secondary query will not be launched * If the columns are not involved in the final select clause,
* for the subquery. * the corresponding query will not be issued.
*/ */
SSubqueryState* pState = NULL;
for (int32_t i = 0; i < pSql->numOfSubs; ++i) { for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
pSupporter = pSql->pSubs[i]->param; pSupporter = pSql->pSubs[i]->param;
if (taosArrayGetSize(pSupporter->exprsInfo) > 0) { if (taosArrayGetSize(pSupporter->exprList) > 0) {
++numOfSub; ++numOfSub;
} }
} }
...@@ -249,10 +254,8 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { ...@@ -249,10 +254,8 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
tscTrace("%p start to launch secondary subqueries, total:%d, only:%d needs to query, others are not retrieve in " tscTrace("%p start to launch secondary subqueries, total:%d, only:%d needs to query, others are not retrieve in "
"select clause", pSql, pSql->numOfSubs, numOfSub); "select clause", pSql, pSql->numOfSubs, numOfSub);
/* //the subqueries that do not actually launch the secondary query to virtual node is set as completed.
* the subqueries that do not actually launch the secondary query to virtual node is set as completed. SSubqueryState* pState = pSupporter->pState;
*/
pState = pSupporter->pState;
pState->numOfTotal = pSql->numOfSubs; pState->numOfTotal = pSql->numOfSubs;
pState->numOfCompleted = (pSql->numOfSubs - numOfSub); pState->numOfCompleted = (pSql->numOfSubs - numOfSub);
...@@ -264,8 +267,8 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { ...@@ -264,8 +267,8 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
pSupporter = pPrevSub->param; pSupporter = pPrevSub->param;
if (taosArrayGetSize(pSupporter->exprsInfo) == 0) { if (taosArrayGetSize(pSupporter->exprList) == 0) {
tscTrace("%p subIndex: %d, not need to launch query, ignore it", pSql, i); tscTrace("%p subIndex: %d, no need to launch query, ignore it", pSql, i);
tscDestroyJoinSupporter(pSupporter); tscDestroyJoinSupporter(pSupporter);
tscFreeSqlObj(pPrevSub); tscFreeSqlObj(pPrevSub);
...@@ -296,27 +299,20 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { ...@@ -296,27 +299,20 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
pQueryInfo->tsBuf = pTSBuf; // transfer the ownership of timestamp comp-z data to the new created object pQueryInfo->tsBuf = pTSBuf; // transfer the ownership of timestamp comp-z data to the new created object
// set the second stage sub query for join process // set the second stage sub query for join process
pQueryInfo->type |= TSDB_QUERY_TYPE_JOIN_SEC_STAGE; TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE);
pQueryInfo->intervalTime = pSupporter->interval; pQueryInfo->intervalTime = pSupporter->interval;
pQueryInfo->groupbyExpr = pSupporter->groupbyExpr; pQueryInfo->groupbyExpr = pSupporter->groupbyExpr;
tscColumnListCopy(pQueryInfo->colList, pSupporter->colList, 0);
tscTagCondCopy(&pQueryInfo->tagCond, &pSupporter->tagCond); tscTagCondCopy(&pQueryInfo->tagCond, &pSupporter->tagCond);
pQueryInfo->exprsInfo = tscSqlExprCopy(pSupporter->exprsInfo, pSupporter->uid, false); pQueryInfo->colList = pSupporter->colList;
tscFieldInfoCopy(&pQueryInfo->fieldsInfo, &pSupporter->fieldsInfo); pQueryInfo->exprList = pSupporter->exprList;
pQueryInfo->fieldsInfo = pSupporter->fieldsInfo;
pSupporter->fieldsInfo.numOfOutput = 0;
/* pSupporter->exprList = NULL;
* if the first column of the secondary query is not ts function, add this function. pSupporter->colList = NULL;
* Because this column is required to filter with timestamp after intersecting. memset(&pSupporter->fieldsInfo, 0, sizeof(SFieldInfo));
*/
SSqlExpr* pExpr = taosArrayGet(pSupporter->exprsInfo, 0);
if (pExpr->functionId != TSDB_FUNC_TS) {
tscAddTimestampColumn(pQueryInfo, TSDB_FUNC_TS, 0);
}
SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0); SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0);
assert(pNew->numOfSubs == 0 && pNew->cmd.numOfClause == 1 && pNewQueryInfo->numOfTables == 1); assert(pNew->numOfSubs == 0 && pNew->cmd.numOfClause == 1 && pNewQueryInfo->numOfTables == 1);
...@@ -334,7 +330,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { ...@@ -334,7 +330,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
// fetch the join tag column // fetch the join tag column
if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) { if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) {
SSqlExpr *pExpr = tscSqlExprGet(pNewQueryInfo, 0); SSqlExpr* pExpr = tscSqlExprGet(pNewQueryInfo, 0);
assert(pQueryInfo->tagCond.joinInfo.hasJoin); assert(pQueryInfo->tagCond.joinInfo.hasJoin);
int16_t tagColIndex = tscGetJoinTagColIndexByUid(&pQueryInfo->tagCond, pTableMetaInfo->pTableMeta->uid); int16_t tagColIndex = tscGetJoinTagColIndexByUid(&pQueryInfo->tagCond, pTableMetaInfo->pTableMeta->uid);
...@@ -342,12 +338,10 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { ...@@ -342,12 +338,10 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
pExpr->numOfParams = 1; pExpr->numOfParams = 1;
} }
tscPrintSelectClause(pNew, 0);
size_t numOfCols = taosArrayGetSize(pNewQueryInfo->colList); size_t numOfCols = taosArrayGetSize(pNewQueryInfo->colList);
tscTrace("%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s", tscTrace("%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s",
pSql, pNew, 0, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, pSql, pNew, 0, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type,
taosArrayGetSize(pNewQueryInfo->exprsInfo), numOfCols, taosArrayGetSize(pNewQueryInfo->exprList), numOfCols,
pNewQueryInfo->fieldsInfo.numOfOutput, pNewQueryInfo->pTableMetaInfo[0]->name); pNewQueryInfo->fieldsInfo.numOfOutput, pNewQueryInfo->pTableMetaInfo[0]->name);
} }
...@@ -356,7 +350,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { ...@@ -356,7 +350,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY;
tscError("%p failed to prepare subqueries objs for secondary phase query, numOfSub:%d, code:%d", pSql, tscError("%p failed to prepare subqueries objs for secondary phase query, numOfSub:%d, code:%d", pSql,
pSql->numOfSubs, pSql->res.code); pSql->numOfSubs, pSql->res.code);
freeSubqueryObj(pSql); freeJoinSubqueryObj(pSql);
return pSql->res.code; return pSql->res.code;
} }
...@@ -373,19 +367,22 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { ...@@ -373,19 +367,22 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
void freeSubqueryObj(SSqlObj* pSql) { void freeJoinSubqueryObj(SSqlObj* pSql) {
SSubqueryState* pState = NULL; SSubqueryState* pState = NULL;
for (int32_t i = 0; i < pSql->numOfSubs; ++i) { for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
if (pSql->pSubs[i] != NULL) { SSqlObj* pSub = pSql->pSubs[i];
SJoinSubquerySupporter* p = pSql->pSubs[i]->param; if (pSub == NULL) {
continue;
}
SJoinSupporter* p = pSub->param;
pState = p->pState; pState = p->pState;
tscDestroyJoinSupporter(p); tscDestroyJoinSupporter(p);
if (pSql->pSubs[i]->res.code == TSDB_CODE_SUCCESS) { if (pSub->res.code == TSDB_CODE_SUCCESS) {
taos_free_result(pSql->pSubs[i]); taos_free_result(pSub);
}
} }
} }
...@@ -393,24 +390,14 @@ void freeSubqueryObj(SSqlObj* pSql) { ...@@ -393,24 +390,14 @@ void freeSubqueryObj(SSqlObj* pSql) {
pSql->numOfSubs = 0; pSql->numOfSubs = 0;
} }
static void doQuitSubquery(SSqlObj* pParentSql) { static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSupporter* pSupporter) {
freeSubqueryObj(pParentSql);
// tsem_wait(&pParentSql->emptyRspSem);
// tsem_wait(&pParentSql->emptyRspSem);
// tsem_post(&pParentSql->rspSem);
}
static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSubquerySupporter* pSupporter) {
int32_t numOfTotal = pSupporter->pState->numOfTotal; int32_t numOfTotal = pSupporter->pState->numOfTotal;
int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1); int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1);
pSqlObj->res.code = pSupporter->pState->code;
if (finished >= numOfTotal) { if (finished >= numOfTotal) {
pSqlObj->res.code = abs(pSupporter->pState->code);
tscError("%p all subquery return and query failed, global code:%d", pSqlObj, pSqlObj->res.code); tscError("%p all subquery return and query failed, global code:%d", pSqlObj, pSqlObj->res.code);
freeJoinSubqueryObj(pSqlObj);
doQuitSubquery(pSqlObj);
} }
} }
...@@ -422,119 +409,368 @@ static void updateQueryTimeRange(SQueryInfo* pQueryInfo, int64_t st, int64_t et) ...@@ -422,119 +409,368 @@ static void updateQueryTimeRange(SQueryInfo* pQueryInfo, int64_t st, int64_t et)
pQueryInfo->window.ekey = et; pQueryInfo->window.ekey = et;
} }
static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) { static void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupporter, SSqlObj* pSql) {
SJoinSubquerySupporter* pSupporter = (SJoinSubquerySupporter*)param;
SSqlObj* pParentSql = pSupporter->pObj; SSqlObj* pParentSql = pSupporter->pObj;
// SSqlCmd* pCmd = &pSql->cmd;
// SSqlRes* pRes = &pSql->res;
SSqlObj* pSql = (SSqlObj*)tres; // SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
SSqlCmd* pCmd = &pSql->cmd; SQueryInfo* pParentQueryInfo = tscGetQueryInfoDetail(&pParentSql->cmd, pParentSql->cmd.clauseIndex);
SSqlRes* pRes = &pSql->res;
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); // if (tscNonOrderedProjectionQueryOnSTable(pParentQueryInfo, 0)) {
// STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
// assert(pQueryInfo->numOfTables == 1);
//
// // for projection query, need to try next vnode
//// int32_t totalVnode = pTableMetaInfo->pMetricMeta->numOfVnodes;
// int32_t totalVnode = 0;
// if ((++pTableMetaInfo->vgroupIndex) < totalVnode) {
// tscTrace("%p current vnode:%d exhausted, try next:%d. total vnode:%d. current numOfRes:%d", pSql,
// pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVnode, pRes->numOfTotal);
//
// pSql->cmd.command = TSDB_SQL_SELECT;
// pSql->fp = tscJoinQueryCallback;
// tscProcessSql(pSql);
//
// return;
// }
// }
if ((pQueryInfo->type & TSDB_QUERY_TYPE_JOIN_SEC_STAGE) == 0) { int32_t numOfTotal = pSupporter->pState->numOfTotal;
if (pSupporter->pState->code != TSDB_CODE_SUCCESS) { int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1);
tscError("%p abort query due to other subquery failure. code:%d, global code:%d", pSql, numOfRows,
pSupporter->pState->code);
quitAllSubquery(pParentSql, pSupporter); if (finished >= numOfTotal) {
assert(finished == numOfTotal);
if (pSupporter->pState->code != TSDB_CODE_SUCCESS) {
tscTrace("%p sub:%p, numOfSub:%d, quit from further procedure due to other queries failure", pParentSql, pSql,
pSupporter->subqueryIndex);
freeJoinSubqueryObj(pParentSql);
return; return;
} }
if (numOfRows > 0) { // write the data into disk tscTrace("%p all subqueries retrieve ts complete, do ts block intersect", pParentSql);
fwrite(pSql->res.data, pSql->res.numOfRows, 1, pSupporter->f);
fclose(pSupporter->f);
STSBuf* pBuf = tsBufCreateFromFile(pSupporter->path, true); SJoinSupporter* p1 = pParentSql->pSubs[0]->param;
if (pBuf == NULL) { SJoinSupporter* p2 = pParentSql->pSubs[1]->param;
tscError("%p invalid ts comp file from vnode, abort sub query, file size:%d", pSql, numOfRows);
pSupporter->pState->code = TSDB_CODE_APP_ERROR; // todo set the informative code TSKEY st, et;
quitAllSubquery(pParentSql, pSupporter); int64_t num = doTSBlockIntersect(pParentSql, p1, p2, &st, &et);
return; if (num <= 0) { // no result during ts intersect
tscTrace("%p free all sub SqlObj and quit", pParentSql);
freeJoinSubqueryObj(pParentSql);
} else {
updateQueryTimeRange(pParentQueryInfo, st, et);
tscLaunchSecondPhaseSubqueries(pParentSql);
}
} }
}
if (pSupporter->pTSBuf == NULL) { int32_t tagsOrderCompar(const void* p1, const void* p2) {
tscTrace("%p create tmp file for ts block:%s", pSql, pBuf->path); STidTags* t1 = (STidTags*) p1;
pSupporter->pTSBuf = pBuf; STidTags* t2 = (STidTags*) p2;
if (t1->vgId != t2->vgId) {
return (t1->vgId > t2->vgId)? 1:-1;
} else { } else {
assert(pQueryInfo->numOfTables == 1); // for subquery, only one metermetaInfo if (t1->tid != t2->tid) {
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); return (t1->tid > t2->tid)? 1:-1;
} else {
return 0;
}
}
}
tsBufMerge(pSupporter->pTSBuf, pBuf, pTableMetaInfo->vgroupIndex); static void doBuildVgroupTableInfo(SArray* res, STableMetaInfo* pTableMetaInfo) {
tsBufDestory(pBuf); SArray* pGroup = taosArrayInit(4, sizeof(SVgroupTableInfo));
SArray* vgTableIdItem = taosArrayInit(4, sizeof(STableIdInfo));
int32_t size = taosArrayGetSize(res);
STidTags* prev = taosArrayGet(res, 0);
int32_t prevVgId = prev->vgId;
STableIdInfo item = {.uid = prev->uid, .tid = prev->tid, .key = INT64_MIN};
taosArrayPush(vgTableIdItem, &item);
for(int32_t k = 1; k < size; ++k) {
STidTags* t1 = taosArrayGet(res, k);
if (prevVgId != t1->vgId) {
SVgroupTableInfo info = {0};
SVgroupsInfo* pvg = pTableMetaInfo->vgroupList;
for(int32_t m = 0; m < pvg->numOfVgroups; ++m) {
if (prevVgId == pvg->vgroups[m].vgId) {
info.vgInfo = pvg->vgroups[m];
break;
}
} }
// open new file to save the result assert(info.vgInfo.numOfIps != 0);
getTmpfilePath("ts-join", pSupporter->path); info.itemList = vgTableIdItem;
pSupporter->f = fopen(pSupporter->path, "w"); taosArrayPush(pGroup, &info);
pSql->res.row = pSql->res.numOfRows;
taos_fetch_rows_a(tres, joinRetrieveCallback, param); vgTableIdItem = taosArrayInit(4, sizeof(STableIdInfo));
} else if (numOfRows == 0) { // no data from this vnode anymore STableIdInfo item1 = {.uid = t1->uid, .tid = t1->tid, .key = INT64_MIN};
SQueryInfo* pParentQueryInfo = tscGetQueryInfoDetail(&pParentSql->cmd, pParentSql->cmd.clauseIndex); taosArrayPush(vgTableIdItem, &item1);
prevVgId = t1->vgId;
} else {
taosArrayPush(vgTableIdItem, &item);
}
}
if (taosArrayGetSize(vgTableIdItem) > 0) {
SVgroupTableInfo info = {0};
SVgroupsInfo* pvg = pTableMetaInfo->vgroupList;
for(int32_t m = 0; m < pvg->numOfVgroups; ++m) {
if (prevVgId == pvg->vgroups[m].vgId) {
info.vgInfo = pvg->vgroups[m];
break;
}
}
assert(info.vgInfo.numOfIps != 0);
info.itemList = vgTableIdItem;
taosArrayPush(pGroup, &info);
}
pTableMetaInfo->pVgroupTables = pGroup;
}
static void issueTSCompQuery(SSqlObj* pSql, SJoinSupporter* pSupporter, SSqlObj* pParent) {
SSqlCmd* pCmd = &pSql->cmd;
tscClearSubqueryInfo(pCmd);
tscFreeSqlResult(pSql);
//todo refactor SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
if (tscNonOrderedProjectionQueryOnSTable(pParentQueryInfo, 0)) {
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
assert(pQueryInfo->numOfTables == 1);
// for projection query, need to try next vnode tscInitQueryInfo(pQueryInfo);
// int32_t totalVnode = pTableMetaInfo->pMetricMeta->numOfVnodes;
int32_t totalVnode = 0;
if ((++pTableMetaInfo->vgroupIndex) < totalVnode) {
tscTrace("%p current vnode:%d exhausted, try next:%d. total vnode:%d. current numOfRes:%d", pSql,
pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVnode, pRes->numOfTotal);
pSql->cmd.command = TSDB_SQL_SELECT; TSDB_QUERY_CLEAR_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY);
TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_MULTITABLE_QUERY);
pCmd->command = TSDB_SQL_SELECT;
pSql->fp = tscJoinQueryCallback; pSql->fp = tscJoinQueryCallback;
tscProcessSql(pSql);
return; SSchema colSchema = {.type = TSDB_DATA_TYPE_BINARY, .bytes = 1};
SColumnIndex index = {0, PRIMARYKEY_TIMESTAMP_COL_INDEX};
tscAddSpecialColumnForSelect(pQueryInfo, 0, TSDB_FUNC_TS_COMP, &index, &colSchema, TSDB_COL_NORMAL);
// set the tags value for ts_comp function
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 0);
int16_t tagColIndex = tscGetJoinTagColIndexByUid(&pSupporter->tagCond, pTableMetaInfo->pTableMeta->uid);
pExpr->param->i64Key = tagColIndex;
pExpr->numOfParams = 1;
// add the filter tag column
if (pSupporter->colList != NULL) {
size_t s = taosArrayGetSize(pSupporter->colList);
for (int32_t i = 0; i < s; ++i) {
SColumn *pCol = taosArrayGetP(pSupporter->colList, i);
if (pCol->numOfFilters > 0) { // copy to the pNew->cmd.colList if it is filtered.
SColumn *p = tscColumnClone(pCol);
taosArrayPush(pQueryInfo->colList, &p);
}
} }
} }
size_t numOfCols = taosArrayGetSize(pQueryInfo->colList);
tscTrace(
"%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, transfer to ts_comp query to retrieve timestamps, "
"exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s",
pParent, pSql, 0, pTableMetaInfo->vgroupIndex, pQueryInfo->type, tscSqlExprNumOfExprs(pQueryInfo),
numOfCols, pQueryInfo->fieldsInfo.numOfOutput, pTableMetaInfo->name);
tscProcessSql(pSql);
}
static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
SJoinSupporter* pSupporter = (SJoinSupporter*)param;
SSqlObj* pParentSql = pSupporter->pObj;
SSqlObj* pSql = (SSqlObj*)tres;
SSqlCmd* pCmd = &pSql->cmd;
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
// if (pSupporter->pState->code != TSDB_CODE_SUCCESS) {
// tscError("%p abort query due to other subquery failure. code:%d, global code:%s", pSql, numOfRows,
// tstrerror(pSupporter->pState->code));
//
// quitAllSubquery(pParentSql, pSupporter);
// return;
// }
//
// if (numOfRows < 0) {
// tscError("%p sub query failed, code:%s, index:%d", pSql, tstrerror(numOfRows), pSupporter->subqueryIndex);
// pSupporter->pState->code = numOfRows;
// quitAllSubquery(pParentSql, pSupporter);
// return;
// }
// response of tag retrieve
if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY)) {
if (numOfRows == 0 || pSql->res.completed) {
if (numOfRows > 0) {
size_t length = pSupporter->totalLen + pSql->res.rspLen;
char* tmp = realloc(pSupporter->pIdTagList, length);
assert(tmp != NULL);
pSupporter->pIdTagList = tmp;
memcpy(pSupporter->pIdTagList, pSql->res.data, pSql->res.rspLen);
pSupporter->totalLen += pSql->res.rspLen;
pSupporter->num += pSql->res.numOfRows;
}
int32_t numOfTotal = pSupporter->pState->numOfTotal; int32_t numOfTotal = pSupporter->pState->numOfTotal;
int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1); int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1);
if (finished >= numOfTotal) { if (finished < numOfTotal) {
assert(finished == numOfTotal);
if (pSupporter->pState->code != TSDB_CODE_SUCCESS) {
tscTrace("%p sub:%p, numOfSub:%d, quit from further procedure due to other queries failure", pParentSql, tres,
pSupporter->subqueryIndex);
doQuitSubquery(pParentSql);
return; return;
} }
tscTrace("%p all subqueries retrieve ts complete, do ts block intersect", pParentSql); // all subqueries are returned, start to compare the tags
assert(finished == numOfTotal);
tscTrace("%p all subqueries retrieve tags complete, do tags match", pParentSql);
SJoinSubquerySupporter* p1 = pParentSql->pSubs[0]->param; SJoinSupporter* p1 = pParentSql->pSubs[0]->param;
SJoinSubquerySupporter* p2 = pParentSql->pSubs[1]->param; SJoinSupporter* p2 = pParentSql->pSubs[1]->param;
TSKEY st, et; qsort(p1->pIdTagList, p1->num, p1->tagSize, tagsOrderCompar);
qsort(p2->pIdTagList, p2->num, p2->tagSize, tagsOrderCompar);
int64_t num = doTSBlockIntersect(pParentSql, p1, p2, &st, &et); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
if (num <= 0) { // no result during ts intersect
SSchema* pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta);// todo: tags mismatch, tags not completed
SColumn *pCol = taosArrayGetP(pTableMetaInfo->tagColList, 0);
SSchema *pColSchema = &pSchema[pCol->colIndex.columnIndex];
SArray* s1 = taosArrayInit(p1->num, p1->tagSize);
SArray* s2 = taosArrayInit(p2->num, p2->tagSize);
int32_t i = 0, j = 0;
while(i < p1->num && j < p2->num) {
STidTags* pp1 = (STidTags*) p1->pIdTagList + i * p1->tagSize;
STidTags* pp2 = (STidTags*) p2->pIdTagList + j * p2->tagSize;
int32_t ret = doCompare(pp1->tag, pp2->tag, pColSchema->type, pColSchema->bytes);
if (ret == 0) {
taosArrayPush(s1, pp1);
taosArrayPush(s2, pp2);
j++;
i++;
} else if (ret > 0) {
j++;
} else {
i++;
}
}
if (taosArrayGetSize(s1) == 0 || taosArrayGetSize(s2) == 0) {// no results,return.
tscTrace("%p free all sub SqlObj and quit", pParentSql); tscTrace("%p free all sub SqlObj and quit", pParentSql);
doQuitSubquery(pParentSql); freeJoinSubqueryObj(pParentSql);
return;
} else { } else {
updateQueryTimeRange(pParentQueryInfo, st, et); SSqlCmd* pSubCmd1 = &pParentSql->pSubs[0]->cmd;
tscLaunchSecondPhaseSubqueries(pParentSql); SSqlCmd* pSubCmd2 = &pParentSql->pSubs[1]->cmd;
SQueryInfo* pQueryInfo1 = tscGetQueryInfoDetail(pSubCmd1, 0);
STableMetaInfo* pTableMetaInfo1 = tscGetMetaInfo(pQueryInfo1, 0);
doBuildVgroupTableInfo(s1, pTableMetaInfo1);
SQueryInfo* pQueryInfo2 = tscGetQueryInfoDetail(pSubCmd2, 0);
STableMetaInfo* pTableMetaInfo2 = tscGetMetaInfo(pQueryInfo2, 0);
doBuildVgroupTableInfo(s2, pTableMetaInfo2);
pSupporter->pState->numOfCompleted = 0;
pSupporter->pState->code = 0;
pSupporter->pState->numOfTotal = 2;
for(int32_t m = 0; m < pParentSql->numOfSubs; ++m) {
SSqlObj* psub = pParentSql->pSubs[m];
issueTSCompQuery(psub, psub->param, pParentSql);
} }
} }
} else { // failure of sub query
tscError("%p sub query failed, code:%d, index:%d", pSql, numOfRows, pSupporter->subqueryIndex); } else {
size_t length = pSupporter->totalLen + pSql->res.rspLen;
char* tmp = realloc(pSupporter->pIdTagList, length);
assert(tmp != NULL);
pSupporter->pIdTagList = tmp;
memcpy(pSupporter->pIdTagList, pSql->res.data, pSql->res.rspLen);
pSupporter->totalLen += pSql->res.rspLen;
pSupporter->num += pSql->res.numOfRows;
// continue retrieve data from vnode
taos_fetch_rows_a(tres, joinRetrieveCallback, param);
}
return;
}
if (!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE)) {
if (numOfRows < 0) {
tscError("%p sub query failed, code:%s, index:%d", pSql, tstrerror(numOfRows), pSupporter->subqueryIndex);
pSupporter->pState->code = numOfRows; pSupporter->pState->code = numOfRows;
quitAllSubquery(pParentSql, pSupporter);
return;
}
if (numOfRows == 0) {
tSIntersectionAndLaunchSecQuery(pSupporter, pSql);
return;
}
// write the compressed timestamp to disk file
fwrite(pSql->res.data, pSql->res.numOfRows, 1, pSupporter->f);
fclose(pSupporter->f);
pSupporter->f = NULL;
STSBuf* pBuf = tsBufCreateFromFile(pSupporter->path, true);
if (pBuf == NULL) {
tscError("%p invalid ts comp file from vnode, abort subquery, file size:%d", pSql, numOfRows);
pSupporter->pState->code = TSDB_CODE_APP_ERROR; // todo set the informative code
quitAllSubquery(pParentSql, pSupporter); quitAllSubquery(pParentSql, pSupporter);
return; return;
} }
if (pSupporter->pTSBuf == NULL) {
tscTrace("%p create tmp file for ts block:%s, size:%d bytes", pSql, pBuf->path, numOfRows);
pSupporter->pTSBuf = pBuf;
} else {
assert(pQueryInfo->numOfTables == 1); // for subquery, only one
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
tsBufMerge(pSupporter->pTSBuf, pBuf, pTableMetaInfo->vgroupIndex);
tsBufDestory(pBuf);
}
if (pSql->res.completed) {
tSIntersectionAndLaunchSecQuery(pSupporter, pSql);
} else { // open a new file to save the incoming result
getTmpfilePath("ts-join", pSupporter->path);
pSupporter->f = fopen(pSupporter->path, "w");
pSql->res.row = pSql->res.numOfRows;
taos_fetch_rows_a(tres, joinRetrieveCallback, param);
}
} else { // secondary stage retrieve, driven by taos_fetch_row or other functions } else { // secondary stage retrieve, driven by taos_fetch_row or other functions
if (numOfRows < 0) { if (numOfRows < 0) {
pSupporter->pState->code = numOfRows; pSupporter->pState->code = numOfRows;
tscError("%p retrieve failed, code:%d, index:%d", pSql, numOfRows, pSupporter->subqueryIndex); tscError("%p retrieve failed, code:%s, index:%d", pSql, tstrerror(numOfRows), pSupporter->subqueryIndex);
} }
if (numOfRows >= 0) { if (numOfRows >= 0) {
...@@ -542,20 +778,20 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) { ...@@ -542,20 +778,20 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
} }
if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) && numOfRows == 0) { if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) && numOfRows == 0) {
// STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
assert(pQueryInfo->numOfTables == 1); 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 ((++pTableMetaInfo->vgroupIndex) < pTableMetaInfo->pMetricMeta->numOfVnodes) { if ((++pTableMetaInfo->vgroupIndex) < pTableMetaInfo->vgroupList->numOfVgroups) {
// pSupporter->pState->numOfCompleted = 0; pSupporter->pState->numOfCompleted = 0;
// pSupporter->pState->numOfTotal = 1; pSupporter->pState->numOfTotal = 1;
//
// pSql->cmd.command = TSDB_SQL_SELECT; pSql->cmd.command = TSDB_SQL_SELECT;
// pSql->fp = tscJoinQueryCallback; pSql->fp = tscJoinQueryCallback;
// tscProcessSql(pSql); tscProcessSql(pSql);
//
// return; return;
// } }
} }
int32_t numOfTotal = pSupporter->pState->numOfTotal; int32_t numOfTotal = pSupporter->pState->numOfTotal;
...@@ -567,27 +803,39 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) { ...@@ -567,27 +803,39 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
pParentSql->res.code); pParentSql->res.code);
if (pSupporter->pState->code != TSDB_CODE_SUCCESS) { if (pSupporter->pState->code != TSDB_CODE_SUCCESS) {
pParentSql->res.code = abs(pSupporter->pState->code); pParentSql->res.code = pSupporter->pState->code;
freeSubqueryObj(pParentSql); freeJoinSubqueryObj(pParentSql);
pParentSql->res.completed = true;
}
// update the records for each subquery in parent sql object.
for(int32_t i = 0; i < pParentSql->numOfSubs; ++i) {
if (pParentSql->pSubs[i] == NULL) {
continue;
}
SSqlRes* pRes1 = &pParentSql->pSubs[i]->res;
pRes1->numOfTotalInCurrentClause += pRes1->numOfRows;
} }
// tsem_post(&pParentSql->rspSem); // data has retrieved to client, build the join results
tscBuildResFromSubqueries(pParentSql);
} else { } else {
tscTrace("%p sub:%p completed, completed:%d, total:%d", pParentSql, tres, finished, numOfTotal); tscTrace("%p sub:%p completed, completed:%d, total:%d", pParentSql, tres, finished, numOfTotal);
} }
} }
} }
static SJoinSubquerySupporter* tscUpdateSubqueryStatus(SSqlObj* pSql, int32_t numOfFetch) { static SJoinSupporter* tscUpdateSubqueryStatus(SSqlObj* pSql, int32_t numOfFetch) {
int32_t notInvolved = 0; int32_t notInvolved = 0;
SJoinSubquerySupporter* pSupporter = NULL; SJoinSupporter* pSupporter = NULL;
SSubqueryState* pState = NULL; SSubqueryState* pState = NULL;
for(int32_t i = 0; i < pSql->numOfSubs; ++i) { for(int32_t i = 0; i < pSql->numOfSubs; ++i) {
if (pSql->pSubs[i] == NULL) { if (pSql->pSubs[i] == NULL) {
notInvolved++; notInvolved++;
} else { } else {
pSupporter = (SJoinSubquerySupporter*)pSql->pSubs[i]->param; pSupporter = (SJoinSupporter*)pSql->pSubs[i]->param;
pState = pSupporter->pState; pState = pSupporter->pState;
} }
} }
...@@ -599,39 +847,62 @@ static SJoinSubquerySupporter* tscUpdateSubqueryStatus(SSqlObj* pSql, int32_t nu ...@@ -599,39 +847,62 @@ static SJoinSubquerySupporter* tscUpdateSubqueryStatus(SSqlObj* pSql, int32_t nu
} }
void tscFetchDatablockFromSubquery(SSqlObj* pSql) { void tscFetchDatablockFromSubquery(SSqlObj* pSql) {
int32_t numOfFetch = 0;
assert(pSql->numOfSubs >= 1); assert(pSql->numOfSubs >= 1);
int32_t numOfFetch = 0;
bool hasData = true;
for (int32_t i = 0; i < pSql->numOfSubs; ++i) { for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
if (pSql->pSubs[i] == NULL) { // this subquery does not need to involve in secondary query // if the subquery is NULL, it does not involved in the final result generation
SSqlObj* pSub = pSql->pSubs[i];
if (pSub == NULL) {
continue; continue;
} }
SSqlRes *pRes = &pSql->pSubs[i]->res; SSqlRes *pRes = &pSub->res;
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->pSubs[i]->cmd, 0); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSub->cmd, 0);
// STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); // STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) { // if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) {
// if (pRes->row >= pRes->numOfRows && pTableMetaInfo->vgroupIndex < pTableMetaInfo->pMetricMeta->numOfVnodes && // if (pRes->row >= pRes->numOfRows && pTableMetaInfo->vgroupIndex < pTableMetaInfo->vgroupList->numOfVgroups &&
// (!tscHasReachLimitation(pQueryInfo, pRes))) { // (!tscHasReachLimitation(pQueryInfo, pRes)) && !pRes->completed) {
// numOfFetch++; // numOfFetch++;
// } // }
} else { // } else {
if (pRes->row >= pRes->numOfRows && (!tscHasReachLimitation(pQueryInfo, pRes))) { if (!tscHasReachLimitation(pQueryInfo, pRes)) {
if (pRes->row >= pRes->numOfRows) {
hasData = false;
if (!pRes->completed) {
numOfFetch++; numOfFetch++;
} }
} }
} else { // has reach the limitation, no data anymore
hasData = false;
}
}
// }
// has data remains in client side, and continue to return data to app
if (hasData) {
tscBuildResFromSubqueries(pSql);
return;
} else if (numOfFetch <= 0) {
pSql->res.completed = true;
freeJoinSubqueryObj(pSql);
if (pSql->res.code == TSDB_CODE_SUCCESS) {
(*pSql->fp)(pSql->param, pSql, 0);
} else {
tscQueueAsyncRes(pSql);
} }
if (numOfFetch <= 0) {
return; return;
} }
// TODO multi-vnode retrieve for projection query with limitation has bugs, since the global limiation is not handled // TODO multi-vnode retrieve for projection query with limitation has bugs, since the global limiation is not handled
tscTrace("%p retrieve data from %d subqueries", pSql, numOfFetch); tscTrace("%p retrieve data from %d subqueries", pSql, numOfFetch);
SJoinSupporter* pSupporter = tscUpdateSubqueryStatus(pSql, numOfFetch);
SJoinSubquerySupporter* pSupporter = tscUpdateSubqueryStatus(pSql, numOfFetch);
for (int32_t i = 0; i < pSql->numOfSubs; ++i) { for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
SSqlObj* pSql1 = pSql->pSubs[i]; SSqlObj* pSql1 = pSql->pSubs[i];
...@@ -642,7 +913,7 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) { ...@@ -642,7 +913,7 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) {
SSqlRes* pRes1 = &pSql1->res; SSqlRes* pRes1 = &pSql1->res;
SSqlCmd* pCmd1 = &pSql1->cmd; SSqlCmd* pCmd1 = &pSql1->cmd;
pSupporter = (SJoinSubquerySupporter*)pSql1->param; pSupporter = (SJoinSupporter*)pSql1->param;
// wait for all subqueries completed // wait for all subqueries completed
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd1, 0); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd1, 0);
...@@ -664,19 +935,6 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) { ...@@ -664,19 +935,6 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) {
tscProcessSql(pSql1); tscProcessSql(pSql1);
} }
} }
// wait for all subquery completed
// tsem_wait(&pSql->rspSem);
// update the records for each subquery
for(int32_t i = 0; i < pSql->numOfSubs; ++i) {
if (pSql->pSubs[i] == NULL) {
continue;
}
SSqlRes* pRes1 = &pSql->pSubs[i]->res;
pRes1->numOfTotalInCurrentClause += pRes1->numOfRows;
}
} }
// all subqueries return, set the result output index // all subqueries return, set the result output index
...@@ -710,7 +968,7 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) { ...@@ -710,7 +968,7 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
SSqlCmd* pSubCmd = &pSql->pSubs[tableIndexOfSub]->cmd; SSqlCmd* pSubCmd = &pSql->pSubs[tableIndexOfSub]->cmd;
SQueryInfo* pSubQueryInfo = tscGetQueryInfoDetail(pSubCmd, 0); SQueryInfo* pSubQueryInfo = tscGetQueryInfoDetail(pSubCmd, 0);
size_t numOfExprs = taosArrayGetSize(pSubQueryInfo->exprsInfo); size_t numOfExprs = taosArrayGetSize(pSubQueryInfo->exprList);
for (int32_t k = 0; k < numOfExprs; ++k) { for (int32_t k = 0; k < numOfExprs; ++k) {
SSqlExpr* pSubExpr = tscSqlExprGet(pSubQueryInfo, 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) {
...@@ -723,35 +981,17 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) { ...@@ -723,35 +981,17 @@ 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;
// STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0);
SJoinSupporter* pSupporter = (SJoinSupporter*)param;
// int32_t idx = pSql->cmd.vnodeIdx;
// There is only one subquery and table for each subquery.
SJoinSubquerySupporter* pSupporter = (SJoinSubquerySupporter*)param;
// if (atomic_add_fetch_32(pSupporter->numOfComplete, 1) >=
// pSupporter->numOfTotal) {
// SSqlObj *pParentObj = pSupporter->pObj;
//
// if ((pSql->cmd.type & TSDB_QUERY_TYPE_JOIN_SEC_STAGE) != 1) {
// int32_t num = 0;
// tscFetchDatablockFromSubquery(pParentObj);
// TSKEY* ts = tscGetQualifiedTSList(pParentObj, &num);
//
// if (num <= 0) {
// // no qualified result
// }
//
// tscLaunchSecondPhaseSubqueries(pSql, ts, num);
// } else {
// }
// } else {
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
if ((pQueryInfo->type & TSDB_QUERY_TYPE_JOIN_SEC_STAGE) != TSDB_QUERY_TYPE_JOIN_SEC_STAGE) { assert(pQueryInfo->numOfTables == 1 && pSql->cmd.numOfClause == 1);
if (!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, 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 compressed time stamp data
pSql->fp = joinRetrieveCallback; pSql->fp = joinRetrieveCallback;
pSql->cmd.command = TSDB_SQL_FETCH; pSql->cmd.command = TSDB_SQL_FETCH;
tscProcessSql(pSql); tscProcessSql(pSql);
...@@ -769,10 +1009,10 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) { ...@@ -769,10 +1009,10 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
} }
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
tscError("%p sub query failed, code:%d, set global code:%d, index:%d", pSql, code, code, tscError("%p sub query failed, code:%s, set global code:%s, index:%d", pSql, tstrerror(code), tstrerror(code),
pSupporter->subqueryIndex); pSupporter->subqueryIndex);
pSupporter->pState->code = code; // todo set the informative code
pSupporter->pState->code = code;
quitAllSubquery(pParentSql, pSupporter); quitAllSubquery(pParentSql, pSupporter);
} else { } else {
int32_t numOfTotal = pSupporter->pState->numOfTotal; int32_t numOfTotal = pSupporter->pState->numOfTotal;
...@@ -789,24 +1029,17 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) { ...@@ -789,24 +1029,17 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
* data instead of returning to its invoker * data instead of returning to its invoker
*/ */
if (pTableMetaInfo->vgroupIndex > 0 && tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) { if (pTableMetaInfo->vgroupIndex > 0 && tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) {
// assert(pTableMetaInfo->vgroupIndex < pTableMetaInfo->pMetricMeta->numOfVnodes);
pSupporter->pState->numOfCompleted = 0; // reset the record value pSupporter->pState->numOfCompleted = 0; // reset the record value
pSql->fp = joinRetrieveCallback; // continue retrieve data pSql->fp = joinRetrieveCallback; // continue retrieve data
pSql->cmd.command = TSDB_SQL_FETCH; pSql->cmd.command = TSDB_SQL_FETCH;
tscProcessSql(pSql); tscProcessSql(pSql);
} else { // first retrieve from vnode during the secondary stage sub-query } else { // first retrieve from vnode during the secondary stage sub-query
if (pParentSql->fp == NULL) {
// tsem_post(&pParentSql->rspSem);
} else {
// set the command flag must be after the semaphore been correctly set. // set the command flag must be after the semaphore been correctly set.
// pPObj->cmd.command = TSDB_SQL_RETRIEVE_METRIC; if (pParentSql->res.code == TSDB_CODE_SUCCESS) {
// if (pPObj->res.code == TSDB_CODE_SUCCESS) { (*pParentSql->fp)(pParentSql->param, pParentSql, 0);
// (*pPObj->fp)(pPObj->param, pPObj, 0); } else {
// } else { tscQueueAsyncRes(pParentSql);
// tscQueueAsyncRes(pPObj);
// }
assert(0);
} }
} }
} }
...@@ -820,7 +1053,7 @@ static void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code); ...@@ -820,7 +1053,7 @@ static void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code);
static SSqlObj *tscCreateSqlObjForSubquery(SSqlObj *pSql, SRetrieveSupport *trsupport, SSqlObj *prevSqlObj); static SSqlObj *tscCreateSqlObjForSubquery(SSqlObj *pSql, SRetrieveSupport *trsupport, SSqlObj *prevSqlObj);
// todo merge with callback // todo merge with callback
int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySupporter *pSupporter) { int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter *pSupporter) {
SSqlCmd * pCmd = &pSql->cmd; SSqlCmd * pCmd = &pSql->cmd;
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
...@@ -856,12 +1089,19 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu ...@@ -856,12 +1089,19 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
pCol->colIndex.tableIndex = 0; pCol->colIndex.tableIndex = 0;
} }
tscColumnListCopy(pSupporter->colList, pNewQueryInfo->colList, 0); pSupporter->colList = pNewQueryInfo->colList;
pNewQueryInfo->colList = NULL;
pSupporter->exprsInfo = tscSqlExprCopy(pNewQueryInfo->exprsInfo, pSupporter->uid, false); pSupporter->exprList = pNewQueryInfo->exprList;
tscFieldInfoCopy(&pSupporter->fieldsInfo, &pNewQueryInfo->fieldsInfo); pNewQueryInfo->exprList = NULL;
tscTagCondCopy(&pSupporter->tagCond, &pNewQueryInfo->tagCond); pSupporter->fieldsInfo = pNewQueryInfo->fieldsInfo;
// this data needs to be transfer to support struct
memset(&pNewQueryInfo->fieldsInfo, 0, sizeof(SFieldInfo));
pSupporter->tagCond = pNewQueryInfo->tagCond;
memset(&pNewQueryInfo->tagCond, 0, sizeof(STagCond));
pNew->cmd.numOfCols = 0; pNew->cmd.numOfCols = 0;
pNewQueryInfo->intervalTime = 0; pNewQueryInfo->intervalTime = 0;
...@@ -871,72 +1111,98 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu ...@@ -871,72 +1111,98 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
pSupporter->groupbyExpr = pNewQueryInfo->groupbyExpr; pSupporter->groupbyExpr = pNewQueryInfo->groupbyExpr;
memset(&pNewQueryInfo->groupbyExpr, 0, sizeof(SSqlGroupbyExpr)); memset(&pNewQueryInfo->groupbyExpr, 0, sizeof(SSqlGroupbyExpr));
// this data needs to be transfer to support struct tscInitQueryInfo(pNewQueryInfo);
pNewQueryInfo->fieldsInfo.numOfOutput = 0; STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pNewQueryInfo, 0);
// set the ts,tags that involved in join, as the output column of intermediate result if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) { // return the tableId & tag
tscClearSubqueryInfo(&pNew->cmd); SSchema s = {0};
SColumnIndex index = {0};
size_t numOfTags = taosArrayGetSize(pTableMetaInfo->tagColList);
for(int32_t i = 0; i < numOfTags; ++i) {
SColumn* c = taosArrayGetP(pTableMetaInfo->tagColList, i);
index = (SColumnIndex) {.tableIndex = 0, .columnIndex = c->colIndex.columnIndex};
SSchema* pTagSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta);
s = pTagSchema[c->colIndex.columnIndex];
int16_t bytes = 0;
int16_t type = 0;
int16_t inter = 0;
getResultDataInfo(s.type, s.bytes, TSDB_FUNC_TID_TAG, 0, &type, &bytes, &inter, 0, 0);
s.type = type;
s.bytes = bytes;
pSupporter->tagSize = s.bytes;
}
// set get tags query type
TSDB_QUERY_SET_TYPE(pNewQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY);
tscAddSpecialColumnForSelect(pNewQueryInfo, 0, TSDB_FUNC_TID_TAG, &index, &s, TSDB_COL_TAG);
size_t numOfCols = taosArrayGetSize(pNewQueryInfo->colList);
tscTrace(
"%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, transfer to tid_tag query to retrieve (tableId, tags), "
"exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s",
pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo),
numOfCols, pNewQueryInfo->fieldsInfo.numOfOutput, pNewQueryInfo->pTableMetaInfo[0]->name);
} else {
SSchema colSchema = {.type = TSDB_DATA_TYPE_BINARY, .bytes = 1}; SSchema colSchema = {.type = TSDB_DATA_TYPE_BINARY, .bytes = 1};
SColumnIndex index = {0, PRIMARYKEY_TIMESTAMP_COL_INDEX}; SColumnIndex index = {0, PRIMARYKEY_TIMESTAMP_COL_INDEX};
tscAddSpecialColumnForSelect(pNewQueryInfo, 0, TSDB_FUNC_TS_COMP, &index, &colSchema, TSDB_COL_NORMAL); tscAddSpecialColumnForSelect(pNewQueryInfo, 0, TSDB_FUNC_TS_COMP, &index, &colSchema, TSDB_COL_NORMAL);
// set the tags value for ts_comp function // set the tags value for ts_comp function
SSqlExpr *pExpr = tscSqlExprGet(pNewQueryInfo, 0); SSqlExpr *pExpr = tscSqlExprGet(pNewQueryInfo, 0);
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pNewQueryInfo, 0);
int16_t tagColIndex = tscGetJoinTagColIndexByUid(&pSupporter->tagCond, pTableMetaInfo->pTableMeta->uid); int16_t tagColIndex = tscGetJoinTagColIndexByUid(&pSupporter->tagCond, pTableMetaInfo->pTableMeta->uid);
pExpr->param->i64Key = tagColIndex; pExpr->param->i64Key = tagColIndex;
pExpr->numOfParams = 1; pExpr->numOfParams = 1;
// add the filter tag column // add the filter tag column
if (pSupporter->colList != NULL) {
size_t s = taosArrayGetSize(pSupporter->colList); size_t s = taosArrayGetSize(pSupporter->colList);
for (int32_t i = 0; i < s; ++i) { for (int32_t i = 0; i < s; ++i) {
SColumn *pCol = taosArrayGetP(pSupporter->colList, i); SColumn *pCol = taosArrayGetP(pSupporter->colList, i);
if (pCol->numOfFilters > 0) { // copy to the pNew->cmd.colList if it is filtered. if (pCol->numOfFilters > 0) { // copy to the pNew->cmd.colList if it is filtered.
SColumn* p = tscColumnClone(pCol); SColumn *p = tscColumnClone(pCol);
taosArrayPush(pNewQueryInfo->colList, &p); taosArrayPush(pNewQueryInfo->colList, &p);
} }
} }
}
size_t numOfCols = taosArrayGetSize(pNewQueryInfo->colList); size_t numOfCols = taosArrayGetSize(pNewQueryInfo->colList);
tscTrace("%p subquery:%p tableIndex:%d, vnodeIdx:%d, type:%d, transfer to ts_comp query to retrieve timestamps, " tscTrace(
"%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, transfer to ts_comp query to retrieve timestamps, "
"exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s", "exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s",
pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo),
tscSqlExprNumOfExprs(pNewQueryInfo), numOfCols, numOfCols, pNewQueryInfo->fieldsInfo.numOfOutput, pNewQueryInfo->pTableMetaInfo[0]->name);
pNewQueryInfo->fieldsInfo.numOfOutput, pNewQueryInfo->pTableMetaInfo[0]->name); }
tscPrintSelectClause(pNew, 0);
} else { } else {
assert(0);
SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0); SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0);
pNewQueryInfo->type |= TSDB_QUERY_TYPE_SUBQUERY; pNewQueryInfo->type |= TSDB_QUERY_TYPE_SUBQUERY;
} }
#ifdef _DEBUG_VIEW
tscPrintSelectClause(pNew, 0);
#endif
return tscProcessSql(pNew); return tscProcessSql(pNew);
} }
// todo support async join query
int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) { int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) {
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
assert((pQueryInfo->type & TSDB_QUERY_TYPE_SUBQUERY) == 0); assert((pQueryInfo->type & TSDB_QUERY_TYPE_SUBQUERY) == 0);
SSubqueryState *pState = calloc(1, sizeof(SSubqueryState)); SSubqueryState *pState = calloc(1, sizeof(SSubqueryState));
pState->numOfTotal = pQueryInfo->numOfTables; pState->numOfTotal = pQueryInfo->numOfTables;
tscTrace("%p start launch subquery, total:%d", pSql, pQueryInfo->numOfTables);
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
SJoinSubquerySupporter *pSupporter = tscCreateJoinSupporter(pSql, pState, i); SJoinSupporter *pSupporter = tscCreateJoinSupporter(pSql, pState, i);
if (pSupporter == NULL) { // failed to create support struct, abort current query if (pSupporter == NULL) { // failed to create support struct, abort current query
tscError("%p tableIndex:%d, failed to allocate join support object, abort further query", pSql, i); tscError("%p tableIndex:%d, failed to allocate join support object, abort further query", pSql, i);
...@@ -955,13 +1221,7 @@ int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) { ...@@ -955,13 +1221,7 @@ int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) {
} }
} }
// tsem_wait(&pSql->rspSem); pSql->cmd.command = (pSql->numOfSubs <= 0)? TSDB_SQL_RETRIEVE_EMPTY_RESULT:TSDB_SQL_METRIC_JOIN_RETRIEVE;
if (pSql->numOfSubs <= 0) {
pSql->cmd.command = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
} else {
pSql->cmd.command = TSDB_SQL_METRIC_JOIN_RETRIEVE;
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -994,7 +1254,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { ...@@ -994,7 +1254,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
// pRes->code check only serves in launching metric sub-queries // pRes->code check only serves in launching metric sub-queries
if (pRes->code == TSDB_CODE_QUERY_CANCELLED) { if (pRes->code == TSDB_CODE_QUERY_CANCELLED) {
pCmd->command = TSDB_SQL_RETRIEVE_METRIC; // enable the abort of kill metric function. pCmd->command = TSDB_SQL_RETRIEVE_LOCALMERGE; // enable the abort of kill super table function.
return pRes->code; return pRes->code;
} }
...@@ -1015,10 +1275,8 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { ...@@ -1015,10 +1275,8 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
int32_t ret = tscLocalReducerEnvCreate(pSql, &pMemoryBuf, &pDesc, &pModel, nBufferSize); int32_t ret = tscLocalReducerEnvCreate(pSql, &pMemoryBuf, &pDesc, &pModel, nBufferSize);
if (ret != 0) { if (ret != 0) {
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
if (pSql->fp) {
tscQueueAsyncRes(pSql); tscQueueAsyncRes(pSql);
} return ret;
return pRes->code;
} }
pSql->pSubs = calloc(pSql->numOfSubs, POINTER_BYTES); pSql->pSubs = calloc(pSql->numOfSubs, POINTER_BYTES);
...@@ -1051,7 +1309,9 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { ...@@ -1051,7 +1309,9 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
trs->pParentSqlObj = pSql; trs->pParentSqlObj = pSql;
trs->pFinalColModel = pModel; trs->pFinalColModel = pModel;
pthread_mutexattr_t mutexattr = {0}; pthread_mutexattr_t mutexattr;
memset(&mutexattr, 0, sizeof(pthread_mutexattr_t));
pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE_NP); pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE_NP);
pthread_mutex_init(&trs->queryMutex, &mutexattr); pthread_mutex_init(&trs->queryMutex, &mutexattr);
pthread_mutexattr_destroy(&mutexattr); pthread_mutexattr_destroy(&mutexattr);
...@@ -1127,9 +1387,7 @@ static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES ...@@ -1127,9 +1387,7 @@ static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES
tscError("sub:%p failed to flush data to disk:reason:%s", tres, lpMsgBuf); tscError("sub:%p failed to flush data to disk:reason:%s", tres, lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
#else #else
char buf[256] = {0}; tscError("sub:%p failed to flush data to disk:reason:%s", tres, strerror(errno));
strerror_r(errno, buf, 256);
tscError("sub:%p failed to flush data to disk:reason:%s", tres, buf);
#endif #endif
trsupport->pState->code = -errCode; trsupport->pState->code = -errCode;
...@@ -1179,8 +1437,8 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO ...@@ -1179,8 +1437,8 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
trsupport->localBuffer->numOfElems = 0; trsupport->localBuffer->numOfElems = 0;
pthread_mutex_unlock(&trsupport->queryMutex); pthread_mutex_unlock(&trsupport->queryMutex);
tscTrace("%p sub:%p retrieve failed, code:%d, orderOfSub:%d, retry:%d", trsupport->pParentSqlObj, pSql, numOfRows, tscTrace("%p sub:%p retrieve failed, code:%s, orderOfSub:%d, retry:%d", trsupport->pParentSqlObj, pSql,
subqueryIndex, trsupport->numOfRetry); tstrerror(numOfRows), subqueryIndex, trsupport->numOfRetry);
SSqlObj *pNew = tscCreateSqlObjForSubquery(trsupport->pParentSqlObj, trsupport, pSql); SSqlObj *pNew = tscCreateSqlObjForSubquery(trsupport->pParentSqlObj, trsupport, pSql);
if (pNew == NULL) { if (pNew == NULL) {
...@@ -1196,8 +1454,8 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO ...@@ -1196,8 +1454,8 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
return; return;
} else { // reach the maximum retry count, abort } else { // reach the maximum retry count, abort
atomic_val_compare_exchange_32(&pState->code, TSDB_CODE_SUCCESS, numOfRows); atomic_val_compare_exchange_32(&pState->code, TSDB_CODE_SUCCESS, numOfRows);
tscError("%p sub:%p retrieve failed,code:%d,orderOfSub:%d failed.no more retry,set global code:%d", pPObj, pSql, tscError("%p sub:%p retrieve failed,code:%s,orderOfSub:%d failed.no more retry,set global code:%d", pPObj, pSql,
numOfRows, subqueryIndex, pState->code); numOfRows, subqueryIndex, tstrerror(pState->code));
} }
} }
...@@ -1306,7 +1564,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p ...@@ -1306,7 +1564,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
tscFreeSubSqlObj(trsupport, pSql); tscFreeSubSqlObj(trsupport, pSql);
// set the command flag must be after the semaphore been correctly set. // set the command flag must be after the semaphore been correctly set.
pPObj->cmd.command = TSDB_SQL_RETRIEVE_METRIC; pPObj->cmd.command = TSDB_SQL_RETRIEVE_LOCALMERGE;
if (pPObj->res.code == TSDB_CODE_SUCCESS) { if (pPObj->res.code == TSDB_CODE_SUCCESS) {
(*pPObj->fp)(pPObj->param, pPObj, 0); (*pPObj->fp)(pPObj->param, pPObj, 0);
} else { } else {
...@@ -1576,3 +1834,233 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) { ...@@ -1576,3 +1834,233 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
void tscBuildResFromSubqueries(SSqlObj *pSql) {
SSqlRes *pRes = &pSql->res;
if (pRes->code != TSDB_CODE_SUCCESS) {
tscQueueAsyncRes(pSql);
return;
}
while (1) {
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
if (pRes->tsrow == NULL) {
pRes->tsrow = calloc(numOfExprs, POINTER_BYTES);
}
bool success = false;
int32_t numOfTableHasRes = 0;
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
if (pSql->pSubs[i] != NULL) {
numOfTableHasRes++;
}
}
if (numOfTableHasRes >= 2) { // do merge result
success = (doSetResultRowData(pSql->pSubs[0], false) != NULL) && (doSetResultRowData(pSql->pSubs[1], false) != NULL);
} else { // only one subquery
SSqlObj *pSub = pSql->pSubs[0];
if (pSub == NULL) {
pSub = pSql->pSubs[1];
}
success = (doSetResultRowData(pSub, false) != NULL);
}
if (success) { // current row of final output has been built, return to app
for (int32_t i = 0; i < numOfExprs; ++i) {
SColumnIndex* pIndex = &pRes->pColumnIndex[i];
SSqlRes *pRes1 = &pSql->pSubs[pIndex->tableIndex]->res;
pRes->tsrow[i] = pRes1->tsrow[pIndex->columnIndex];
}
pRes->numOfTotalInCurrentClause++;
break;
} else { // continue retrieve data from vnode
if (!tscHashRemainDataInSubqueryResultSet(pSql)) {
tscTrace("%p at least one subquery exhausted, free all other %d subqueries", pSql, pSql->numOfSubs - 1);
SSubqueryState *pState = NULL;
// free all sub sqlobj
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
SSqlObj *pChildObj = pSql->pSubs[i];
if (pChildObj == NULL) {
continue;
}
SJoinSupporter *pSupporter = (SJoinSupporter *)pChildObj->param;
pState = pSupporter->pState;
tscDestroyJoinSupporter(pChildObj->param);
taos_free_result(pChildObj);
}
free(pState);
pRes->completed = true; // set query completed
sem_post(&pSql->rspSem);
return;
}
tscFetchDatablockFromSubquery(pSql);
if (pRes->code != TSDB_CODE_SUCCESS) {
return;
}
}
}
if (pSql->res.code == TSDB_CODE_SUCCESS) {
(*pSql->fp)(pSql->param, pSql, 0);
} else {
tscQueueAsyncRes(pSql);
}
}
static void transferNcharData(SSqlObj *pSql, int32_t columnIndex, TAOS_FIELD *pField) {
SSqlRes *pRes = &pSql->res;
if (isNull(pRes->tsrow[columnIndex], pField->type)) {
pRes->tsrow[columnIndex] = NULL;
} else if (pField->type == TSDB_DATA_TYPE_NCHAR) {
// convert unicode to native code in a temporary buffer extra one byte for terminated symbol
if (pRes->buffer[columnIndex] == NULL) {
pRes->buffer[columnIndex] = malloc(pField->bytes + TSDB_NCHAR_SIZE);
}
/* string terminated char for binary data*/
memset(pRes->buffer[columnIndex], 0, pField->bytes + TSDB_NCHAR_SIZE);
if (taosUcs4ToMbs(pRes->tsrow[columnIndex], pField->bytes - VARSTR_HEADER_SIZE, pRes->buffer[columnIndex])) {
pRes->tsrow[columnIndex] = pRes->buffer[columnIndex];
} else {
tscError("%p charset:%s to %s. val:%ls convert failed.", pSql, DEFAULT_UNICODE_ENCODEC, tsCharset, pRes->tsrow);
pRes->tsrow[columnIndex] = NULL;
}
}
}
void **doSetResultRowData(SSqlObj *pSql, bool finalResult) {
SSqlCmd *pCmd = &pSql->cmd;
SSqlRes *pRes = &pSql->res;
assert(pRes->row >= 0 && pRes->row <= pRes->numOfRows);
if(pCmd->command == TSDB_SQL_METRIC_JOIN_RETRIEVE) {
if (pRes->completed) {
tfree(pRes->tsrow);
}
return pRes->tsrow;
}
if (pRes->row >= pRes->numOfRows) { // all the results has returned to invoker
tfree(pRes->tsrow);
return pRes->tsrow;
}
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
for (int i = 0; i < tscNumOfFields(pQueryInfo); ++i) {
SFieldSupInfo* pSup = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, i);
if (pSup->pSqlExpr != NULL) {
pRes->tsrow[i] = tscGetResultColumnChr(pRes, pQueryInfo, i, pSup->pSqlExpr->resBytes);
}
// primary key column cannot be null in interval query, no need to check
if (i == 0 && pQueryInfo->intervalTime > 0) {
continue;
}
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
transferNcharData(pSql, i, pField);
// calculate the result from several other columns
if (pSup->pArithExprInfo != NULL) {
// SArithmeticSupport *sas = (SArithmeticSupport *)calloc(1, sizeof(SArithmeticSupport));
// sas->offset = 0;
// sas-> = pQueryInfo->fieldsInfo.pExpr[i];
//
// sas->numOfCols = sas->pExpr->binExprInfo.numOfCols;
//
// if (pRes->buffer[i] == NULL) {
// pRes->buffer[i] = malloc(tscFieldInfoGetField(pQueryInfo, i)->bytes);
// }
//
// for(int32_t k = 0; k < sas->numOfCols; ++k) {
// int32_t columnIndex = sas->pExpr->binExprInfo.pReqColumns[k].colIdxInBuf;
// SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, columnIndex);
//
// sas->elemSize[k] = pExpr->resBytes;
// sas->data[k] = (pRes->data + pRes->numOfRows* pExpr->offset) + pRes->row*pExpr->resBytes;
// }
//
// tSQLBinaryExprCalcTraverse(sas->pExpr->binExprInfo.pBinExpr, 1, pRes->buffer[i], sas, TSQL_SO_ASC, getArithemicInputSrc);
// pRes->tsrow[i] = pRes->buffer[i];
//
// free(sas); //todo optimization
}
}
pRes->row++; // index increase one-step
return pRes->tsrow;
}
static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) {
bool hasData = true;
SSqlCmd *pCmd = &pSql->cmd;
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) {
bool allSubqueryExhausted = true;
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
if (pSql->pSubs[i] == NULL) {
continue;
}
SSqlRes *pRes1 = &pSql->pSubs[i]->res;
SSqlCmd *pCmd1 = &pSql->pSubs[i]->cmd;
SQueryInfo *pQueryInfo1 = tscGetQueryInfoDetail(pCmd1, pCmd1->clauseIndex);
assert(pQueryInfo1->numOfTables == 1);
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo1, 0);
/*
* if the global limitation is not reached, and current result has not exhausted, or next more vnodes are
* available, goes on
*/
if (pTableMetaInfo->vgroupIndex < pTableMetaInfo->vgroupList->numOfVgroups && pRes1->row < pRes1->numOfRows &&
(!tscHasReachLimitation(pQueryInfo1, pRes1))) {
allSubqueryExhausted = false;
break;
}
}
hasData = !allSubqueryExhausted;
} else { // otherwise, in case inner join, if any subquery exhausted, query completed.
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
if (pSql->pSubs[i] == 0) {
continue;
}
SSqlRes * pRes1 = &pSql->pSubs[i]->res;
SQueryInfo *pQueryInfo1 = tscGetQueryInfoDetail(&pSql->pSubs[i]->cmd, 0);
if ((pRes1->row >= pRes1->numOfRows && tscHasReachLimitation(pQueryInfo1, pRes1) &&
tscProjectionQueryOnTable(pQueryInfo1)) ||
(pRes1->numOfRows == 0)) {
hasData = false;
break;
}
}
}
return hasData;
}
...@@ -76,7 +76,9 @@ bool tscQueryOnSTable(SSqlCmd* pCmd) { ...@@ -76,7 +76,9 @@ bool tscQueryOnSTable(SSqlCmd* pCmd) {
bool tscQueryTags(SQueryInfo* pQueryInfo) { bool tscQueryTags(SQueryInfo* pQueryInfo) {
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
if (tscSqlExprGet(pQueryInfo, i)->functionId != TSDB_FUNC_TAGPRJ) { int32_t functId = tscSqlExprGet(pQueryInfo, i)->functionId;
if (functId != TSDB_FUNC_TAGPRJ && functId != TSDB_FUNC_TID_TAG) {
return false; return false;
} }
} }
...@@ -123,23 +125,23 @@ void tscGetDBInfoFromMeterId(char* tableId, char* db) { ...@@ -123,23 +125,23 @@ void tscGetDBInfoFromMeterId(char* tableId, char* db) {
db[0] = 0; db[0] = 0;
} }
STableIdInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx) { //STableIdInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx) {
if (pSidList == NULL) { // if (pSidList == NULL) {
tscError("illegal sidlist"); // tscError("illegal sidlist");
return 0; // return 0;
} // }
//
if (idx < 0 || idx >= pSidList->numOfSids) { // if (idx < 0 || idx >= pSidList->numOfSids) {
int32_t sidRange = (pSidList->numOfSids > 0) ? (pSidList->numOfSids - 1) : 0; // int32_t sidRange = (pSidList->numOfSids > 0) ? (pSidList->numOfSids - 1) : 0;
//
tscError("illegal sidIdx:%d, reset to 0, sidIdx range:%d-%d", idx, 0, sidRange); // tscError("illegal sidIdx:%d, reset to 0, sidIdx range:%d-%d", idx, 0, sidRange);
idx = 0; // idx = 0;
} // }
//
assert(pSidList->pSidExtInfoList[idx] >= 0); // assert(pSidList->pSidExtInfoList[idx] >= 0);
//
return (STableIdInfo*)(pSidList->pSidExtInfoList[idx] + (char*)pSidList); // return (STableIdInfo*)(pSidList->pSidExtInfoList[idx] + (char*)pSidList);
} //}
bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex) { bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex) {
if (pQueryInfo == NULL) { if (pQueryInfo == NULL) {
...@@ -151,15 +153,11 @@ bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex) { ...@@ -151,15 +153,11 @@ bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex) {
return false; return false;
} }
// for select query super table, the metricmeta can not be null in any cases. // for select query super table, the super table vgroup list can not be null in any cases.
if (pQueryInfo->command == TSDB_SQL_SELECT && UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) { if (pQueryInfo->command == TSDB_SQL_SELECT && UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) {
// assert(pTableMetaInfo->pMetricMeta != NULL); assert(pTableMetaInfo->vgroupList != NULL);
} }
// if (pTableMetaInfo->pMetricMeta == NULL) {
// return false;
// }
if ((pQueryInfo->type & TSDB_QUERY_TYPE_FREE_RESOURCE) == TSDB_QUERY_TYPE_FREE_RESOURCE) { if ((pQueryInfo->type & TSDB_QUERY_TYPE_FREE_RESOURCE) == TSDB_QUERY_TYPE_FREE_RESOURCE) {
return false; return false;
} }
...@@ -191,12 +189,11 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { ...@@ -191,12 +189,11 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
return false; return false;
} }
// only query on tag, not a projection query // only query on tag, a project query
if (tscQueryTags(pQueryInfo)) { if (tscQueryTags(pQueryInfo)) {
return false; return true;
} }
// for project query, only the following two function is allowed
for (int32_t i = 0; i < numOfExprs; ++i) { for (int32_t i = 0; i < numOfExprs; ++i) {
int32_t functionId = tscSqlExprGet(pQueryInfo, 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 &&
...@@ -306,12 +303,10 @@ int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) { ...@@ -306,12 +303,10 @@ int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) {
} }
void tscDestroyResPointerInfo(SSqlRes* pRes) { void tscDestroyResPointerInfo(SSqlRes* pRes) {
if (pRes->buffer != NULL) { if (pRes->buffer != NULL) { // free all buffers containing the multibyte string
// free all buffers containing the multibyte string
for (int i = 0; i < pRes->numOfCols; i++) { for (int i = 0; i < pRes->numOfCols; i++) {
tfree(pRes->buffer[i]); tfree(pRes->buffer[i]);
} }
pRes->numOfCols = 0; pRes->numOfCols = 0;
} }
...@@ -340,50 +335,15 @@ void tscResetSqlCmdObj(SSqlCmd* pCmd) { ...@@ -340,50 +335,15 @@ void tscResetSqlCmdObj(SSqlCmd* pCmd) {
tscFreeQueryInfo(pCmd); tscFreeQueryInfo(pCmd);
} }
/*
* this function must not change the pRes->code value, since it may be used later.
*/
void tscFreeResData(SSqlObj* pSql) {
SSqlRes* pRes = &pSql->res;
pRes->row = 0;
pRes->rspType = 0;
pRes->rspLen = 0;
pRes->row = 0;
pRes->numOfRows = 0;
pRes->numOfTotal = 0;
pRes->numOfTotalInCurrentClause = 0;
pRes->numOfGroups = 0;
pRes->precision = 0;
pRes->qhandle = 0;
pRes->offset = 0;
pRes->useconds = 0;
tscDestroyLocalReducer(pSql);
tscDestroyResPointerInfo(pRes);
}
void tscFreeSqlResult(SSqlObj* pSql) { void tscFreeSqlResult(SSqlObj* pSql) {
tfree(pSql->res.pRsp);
pSql->res.row = 0;
pSql->res.numOfRows = 0;
pSql->res.numOfTotal = 0;
pSql->res.numOfGroups = 0;
tfree(pSql->res.pGroupRec);
tscDestroyLocalReducer(pSql); tscDestroyLocalReducer(pSql);
tscDestroyResPointerInfo(&pSql->res); SSqlRes* pRes = &pSql->res;
tfree(pSql->res.pColumnIndex); tscDestroyResPointerInfo(pRes);
memset(&pSql->res, 0, sizeof(SSqlRes));
} }
void tscFreeSqlObjPartial(SSqlObj* pSql) { void tscPartiallyFreeSqlObj(SSqlObj* pSql) {
if (pSql == NULL || pSql->signature != pSql) { if (pSql == NULL || pSql->signature != pSql) {
return; return;
} }
...@@ -392,7 +352,7 @@ void tscFreeSqlObjPartial(SSqlObj* pSql) { ...@@ -392,7 +352,7 @@ void tscFreeSqlObjPartial(SSqlObj* pSql) {
STscObj* pObj = pSql->pTscObj; STscObj* pObj = pSql->pTscObj;
int32_t cmd = pCmd->command; int32_t cmd = pCmd->command;
if (cmd < TSDB_SQL_INSERT || cmd == TSDB_SQL_RETRIEVE_METRIC || cmd == TSDB_SQL_RETRIEVE_EMPTY_RESULT || if (cmd < TSDB_SQL_INSERT || cmd == TSDB_SQL_RETRIEVE_LOCALMERGE || cmd == TSDB_SQL_RETRIEVE_EMPTY_RESULT ||
cmd == TSDB_SQL_METRIC_JOIN_RETRIEVE) { cmd == TSDB_SQL_METRIC_JOIN_RETRIEVE) {
tscRemoveFromSqlList(pSql); tscRemoveFromSqlList(pSql);
} }
...@@ -417,7 +377,7 @@ void tscFreeSqlObj(SSqlObj* pSql) { ...@@ -417,7 +377,7 @@ void tscFreeSqlObj(SSqlObj* pSql) {
if (pSql == NULL || pSql->signature != pSql) return; if (pSql == NULL || pSql->signature != pSql) return;
tscTrace("%p start to free sql object", pSql); tscTrace("%p start to free sql object", pSql);
tscFreeSqlObjPartial(pSql); tscPartiallyFreeSqlObj(pSql);
pSql->signature = NULL; pSql->signature = NULL;
pSql->fp = NULL; pSql->fp = NULL;
...@@ -643,14 +603,16 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock) { ...@@ -643,14 +603,16 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock) {
memcpy(pDataBlock, pTableDataBlock->pData, sizeof(SSubmitBlk)); memcpy(pDataBlock, pTableDataBlock->pData, sizeof(SSubmitBlk));
pDataBlock += sizeof(SSubmitBlk); pDataBlock += sizeof(SSubmitBlk);
int32_t flen = 0; int32_t flen = 0; // original total length of row
for (int32_t i = 0; i < tinfo.numOfColumns; ++i) { for (int32_t i = 0; i < tinfo.numOfColumns; ++i) {
flen += TYPE_BYTES[pSchema[i].type]; flen += TYPE_BYTES[pSchema[i].type];
} }
char* p = pTableDataBlock->pData + sizeof(SSubmitBlk); char* p = pTableDataBlock->pData + sizeof(SSubmitBlk);
pBlock->len = 0; pBlock->len = 0;
for (int32_t i = 0; i < htons(pBlock->numOfRows); ++i) { int32_t numOfRows = htons(pBlock->numOfRows);
for (int32_t i = 0; i < numOfRows; ++i) {
SDataRow trow = (SDataRow)pDataBlock; SDataRow trow = (SDataRow)pDataBlock;
dataRowSetLen(trow, TD_DATA_ROW_HEAD_SIZE + flen); dataRowSetLen(trow, TD_DATA_ROW_HEAD_SIZE + flen);
...@@ -748,10 +710,14 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi ...@@ -748,10 +710,14 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi
} }
void tscCloseTscObj(STscObj* pObj) { void tscCloseTscObj(STscObj* pObj) {
assert(pObj != NULL);
pObj->signature = NULL; pObj->signature = NULL;
SSqlObj* pSql = pObj->pSql; SSqlObj* pSql = pObj->pSql;
if (pSql) { if (pSql) {
terrno = pSql->res.code; terrno = pSql->res.code;
sem_destroy(&pSql->rspSem);
} }
taosTmrStopA(&(pObj->pTimer)); taosTmrStopA(&(pObj->pTimer));
...@@ -767,7 +733,7 @@ void tscCloseTscObj(STscObj* pObj) { ...@@ -767,7 +733,7 @@ void tscCloseTscObj(STscObj* pObj) {
tfree(pObj); tfree(pObj);
} }
bool tscIsInsertOrImportData(char* sqlstr) { bool tscIsInsertData(char* sqlstr) {
int32_t index = 0; int32_t index = 0;
do { do {
...@@ -842,12 +808,12 @@ SFieldSupInfo* tscFieldInfoInsert(SFieldInfo* pFieldInfo, int32_t index, TAOS_FI ...@@ -842,12 +808,12 @@ SFieldSupInfo* tscFieldInfoInsert(SFieldInfo* pFieldInfo, int32_t index, TAOS_FI
void tscFieldInfoUpdateOffset(SQueryInfo* pQueryInfo) { void tscFieldInfoUpdateOffset(SQueryInfo* pQueryInfo) {
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo); size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
pExpr->offset = 0; pExpr->offset = 0;
for (int32_t i = 1; i < numOfExprs; ++i) { for (int32_t i = 1; i < numOfExprs; ++i) {
SSqlExpr* prev = taosArrayGetP(pQueryInfo->exprsInfo, i - 1); SSqlExpr* prev = taosArrayGetP(pQueryInfo->exprList, i - 1);
SSqlExpr* p = taosArrayGetP(pQueryInfo->exprsInfo, i); SSqlExpr* p = taosArrayGetP(pQueryInfo->exprList, i);
p->offset = prev->offset + prev->resBytes; p->offset = prev->offset + prev->resBytes;
} }
...@@ -858,13 +824,13 @@ void tscFieldInfoUpdateOffsetForInterResult(SQueryInfo* pQueryInfo) { ...@@ -858,13 +824,13 @@ void tscFieldInfoUpdateOffsetForInterResult(SQueryInfo* pQueryInfo) {
return; return;
} }
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
pExpr->offset = 0; pExpr->offset = 0;
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo); size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
for (int32_t i = 1; i < numOfExprs; ++i) { for (int32_t i = 1; i < numOfExprs; ++i) {
SSqlExpr* prev = taosArrayGetP(pQueryInfo->exprsInfo, i - 1); SSqlExpr* prev = taosArrayGetP(pQueryInfo->exprList, i - 1);
SSqlExpr* p = taosArrayGetP(pQueryInfo->exprsInfo, i); SSqlExpr* p = taosArrayGetP(pQueryInfo->exprList, i);
p->offset = prev->offset + prev->resBytes; p->offset = prev->offset + prev->resBytes;
} }
...@@ -873,8 +839,17 @@ void tscFieldInfoUpdateOffsetForInterResult(SQueryInfo* pQueryInfo) { ...@@ -873,8 +839,17 @@ void tscFieldInfoUpdateOffsetForInterResult(SQueryInfo* pQueryInfo) {
void tscFieldInfoCopy(SFieldInfo* dst, const SFieldInfo* src) { void tscFieldInfoCopy(SFieldInfo* dst, const SFieldInfo* src) {
dst->numOfOutput = src->numOfOutput; dst->numOfOutput = src->numOfOutput;
if (dst->pFields == NULL) {
dst->pFields = taosArrayClone(src->pFields);
} else {
taosArrayCopy(dst->pFields, src->pFields); taosArrayCopy(dst->pFields, src->pFields);
}
if (dst->pSupportInfo == NULL) {
dst->pSupportInfo = taosArrayClone(src->pSupportInfo);
} else {
taosArrayCopy(dst->pSupportInfo, src->pSupportInfo); taosArrayCopy(dst->pSupportInfo, src->pSupportInfo);
}
} }
TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index) { TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index) {
...@@ -950,7 +925,6 @@ static SSqlExpr* doBuildSqlExpr(SQueryInfo* pQueryInfo, int16_t functionId, SCol ...@@ -950,7 +925,6 @@ static SSqlExpr* doBuildSqlExpr(SQueryInfo* pQueryInfo, int16_t functionId, SCol
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pColIndex->tableIndex); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pColIndex->tableIndex);
SSqlExpr* pExpr = calloc(1, sizeof(SSqlExpr)); SSqlExpr* pExpr = calloc(1, sizeof(SSqlExpr));
pExpr->functionId = functionId; pExpr->functionId = functionId;
// set the correct column index // set the correct column index
...@@ -981,20 +955,20 @@ static SSqlExpr* doBuildSqlExpr(SQueryInfo* pQueryInfo, int16_t functionId, SCol ...@@ -981,20 +955,20 @@ static SSqlExpr* doBuildSqlExpr(SQueryInfo* pQueryInfo, int16_t functionId, SCol
SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, 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, bool isTagCol) { int16_t size, int16_t interSize, bool isTagCol) {
int32_t num = taosArrayGetSize(pQueryInfo->exprsInfo); int32_t num = taosArrayGetSize(pQueryInfo->exprList);
if (index == num) { if (index == num) {
return tscSqlExprAppend(pQueryInfo, functionId, pColIndex, type, size, interSize, isTagCol); return tscSqlExprAppend(pQueryInfo, functionId, pColIndex, type, size, interSize, isTagCol);
} }
SSqlExpr* pExpr = doBuildSqlExpr(pQueryInfo, functionId, pColIndex, type, size, interSize, isTagCol); SSqlExpr* pExpr = doBuildSqlExpr(pQueryInfo, functionId, pColIndex, type, size, interSize, isTagCol);
taosArrayInsert(pQueryInfo->exprsInfo, index, &pExpr); taosArrayInsert(pQueryInfo->exprList, index, &pExpr);
return pExpr; return pExpr;
} }
SSqlExpr* tscSqlExprAppend(SQueryInfo* pQueryInfo, int16_t functionId, SColumnIndex* pColIndex, int16_t type, SSqlExpr* tscSqlExprAppend(SQueryInfo* pQueryInfo, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
int16_t size, int16_t interSize, bool isTagCol) { int16_t size, int16_t interSize, bool isTagCol) {
SSqlExpr* pExpr = doBuildSqlExpr(pQueryInfo, functionId, pColIndex, type, size, interSize, isTagCol); SSqlExpr* pExpr = doBuildSqlExpr(pQueryInfo, functionId, pColIndex, type, size, interSize, isTagCol);
taosArrayPush(pQueryInfo->exprsInfo, &pExpr); taosArrayPush(pQueryInfo->exprList, &pExpr);
return pExpr; return pExpr;
} }
...@@ -1018,7 +992,7 @@ SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functi ...@@ -1018,7 +992,7 @@ SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
} }
int32_t tscSqlExprNumOfExprs(SQueryInfo* pQueryInfo) { int32_t tscSqlExprNumOfExprs(SQueryInfo* pQueryInfo) {
return taosArrayGetSize(pQueryInfo->exprsInfo); return taosArrayGetSize(pQueryInfo->exprList);
} }
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) {
...@@ -1035,7 +1009,7 @@ void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes, ...@@ -1035,7 +1009,7 @@ void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes,
} }
SSqlExpr* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index) { SSqlExpr* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index) {
return taosArrayGetP(pQueryInfo->exprsInfo, index); return taosArrayGetP(pQueryInfo->exprList, index);
} }
void* sqlExprDestroy(SSqlExpr* pExpr) { void* sqlExprDestroy(SSqlExpr* pExpr) {
...@@ -1066,14 +1040,10 @@ void tscSqlExprInfoDestroy(SArray* pExprInfo) { ...@@ -1066,14 +1040,10 @@ void tscSqlExprInfoDestroy(SArray* pExprInfo) {
taosArrayDestroy(pExprInfo); taosArrayDestroy(pExprInfo);
} }
SArray* tscSqlExprCopy(const SArray* src, uint64_t uid, bool deepcopy) { void tscSqlExprCopy(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy) {
if (src == NULL || taosArrayGetSize(src) == 0) { assert(src != NULL && dst != NULL);
return taosArrayInit(1, POINTER_BYTES);
}
size_t size = taosArrayGetSize(src); size_t size = taosArrayGetSize(src);
SArray* dst = taosArrayInit(size, POINTER_BYTES);
for (int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
SSqlExpr* pExpr = taosArrayGetP(src, i); SSqlExpr* pExpr = taosArrayGetP(src, i);
...@@ -1093,8 +1063,6 @@ SArray* tscSqlExprCopy(const SArray* src, uint64_t uid, bool deepcopy) { ...@@ -1093,8 +1063,6 @@ SArray* tscSqlExprCopy(const SArray* src, uint64_t uid, bool deepcopy) {
} }
} }
} }
return dst;
} }
SColumn* tscColumnListInsert(SArray* pColumnList, SColumnIndex* pColIndex) { SColumn* tscColumnListInsert(SArray* pColumnList, SColumnIndex* pColIndex) {
...@@ -1192,9 +1160,7 @@ static void tscColumnDestroy(SColumn* pCol) { ...@@ -1192,9 +1160,7 @@ static void tscColumnDestroy(SColumn* pCol) {
} }
void tscColumnListCopy(SArray* dst, const SArray* src, int16_t tableIndex) { void tscColumnListCopy(SArray* dst, const SArray* src, int16_t tableIndex) {
if (src == NULL) { assert(src != NULL && dst != NULL);
return;
}
size_t num = taosArrayGetSize(src); size_t num = taosArrayGetSize(src);
for (int32_t i = 0; i < num; ++i) { for (int32_t i = 0; i < num; ++i) {
...@@ -1575,9 +1541,22 @@ STableMetaInfo* tscGetTableMetaInfoByUid(SQueryInfo* pQueryInfo, uint64_t uid, i ...@@ -1575,9 +1541,22 @@ STableMetaInfo* tscGetTableMetaInfoByUid(SQueryInfo* pQueryInfo, uint64_t uid, i
return tscGetMetaInfo(pQueryInfo, k); return tscGetMetaInfo(pQueryInfo, k);
} }
void tscInitQueryInfo(SQueryInfo* pQueryInfo) {
assert(pQueryInfo->fieldsInfo.pFields == NULL);
pQueryInfo->fieldsInfo.pFields = taosArrayInit(4, sizeof(TAOS_FIELD));
assert(pQueryInfo->fieldsInfo.pSupportInfo == NULL);
pQueryInfo->fieldsInfo.pSupportInfo = taosArrayInit(4, sizeof(SFieldSupInfo));
assert(pQueryInfo->exprList == NULL);
pQueryInfo->exprList = taosArrayInit(4, POINTER_BYTES);
pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES);
}
int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) { int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) {
assert(pCmd != NULL); assert(pCmd != NULL);
// todo refactor: remove this structure
size_t s = pCmd->numOfClause + 1; size_t s = pCmd->numOfClause + 1;
char* tmp = realloc(pCmd->pQueryInfo, s * POINTER_BYTES); char* tmp = realloc(pCmd->pQueryInfo, s * POINTER_BYTES);
if (tmp == NULL) { if (tmp == NULL) {
...@@ -1587,12 +1566,7 @@ int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) { ...@@ -1587,12 +1566,7 @@ int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) {
pCmd->pQueryInfo = (SQueryInfo**)tmp; pCmd->pQueryInfo = (SQueryInfo**)tmp;
SQueryInfo* pQueryInfo = calloc(1, sizeof(SQueryInfo)); SQueryInfo* pQueryInfo = calloc(1, sizeof(SQueryInfo));
tscInitQueryInfo(pQueryInfo);
// todo refactor to extract functions.
pQueryInfo->fieldsInfo.pFields = taosArrayInit(4, sizeof(TAOS_FIELD));
pQueryInfo->fieldsInfo.pSupportInfo = taosArrayInit(4, sizeof(SFieldSupInfo));
pQueryInfo->exprsInfo = taosArrayInit(4, POINTER_BYTES);
pQueryInfo->msg = pCmd->payload; // pointer to the parent error message buffer pQueryInfo->msg = pCmd->payload; // pointer to the parent error message buffer
...@@ -1604,11 +1578,11 @@ static void freeQueryInfoImpl(SQueryInfo* pQueryInfo) { ...@@ -1604,11 +1578,11 @@ static void freeQueryInfoImpl(SQueryInfo* pQueryInfo) {
tscTagCondRelease(&pQueryInfo->tagCond); tscTagCondRelease(&pQueryInfo->tagCond);
tscFieldInfoClear(&pQueryInfo->fieldsInfo); tscFieldInfoClear(&pQueryInfo->fieldsInfo);
tscSqlExprInfoDestroy(pQueryInfo->exprsInfo); tscSqlExprInfoDestroy(pQueryInfo->exprList);
memset(&pQueryInfo->exprsInfo, 0, sizeof(pQueryInfo->exprsInfo)); pQueryInfo->exprList = NULL;
tscColumnListDestroy(pQueryInfo->colList); tscColumnListDestroy(pQueryInfo->colList);
memset(&pQueryInfo->colList, 0, sizeof(pQueryInfo->colList)); pQueryInfo->colList = NULL;
if (pQueryInfo->groupbyExpr.columnInfo != NULL) { if (pQueryInfo->groupbyExpr.columnInfo != NULL) {
taosArrayDestroy(pQueryInfo->groupbyExpr.columnInfo); taosArrayDestroy(pQueryInfo->groupbyExpr.columnInfo);
...@@ -1627,6 +1601,35 @@ void tscClearSubqueryInfo(SSqlCmd* pCmd) { ...@@ -1627,6 +1601,35 @@ void tscClearSubqueryInfo(SSqlCmd* pCmd) {
} }
} }
void doRemoveTableMetaInfo(SQueryInfo* pQueryInfo, int32_t index, bool removeFromCache) {
if (index < 0 || index >= pQueryInfo->numOfTables) {
return;
}
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index);
tscClearTableMetaInfo(pTableMetaInfo, removeFromCache);
free(pTableMetaInfo);
int32_t after = pQueryInfo->numOfTables - index - 1;
if (after > 0) {
memmove(&pQueryInfo->pTableMetaInfo[index], &pQueryInfo->pTableMetaInfo[index + 1], after * POINTER_BYTES);
}
pQueryInfo->numOfTables -= 1;
}
void clearAllTableMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache) {
tscTrace("%p deref the table meta in cache, numOfTables:%d", address, pQueryInfo->numOfTables);
int32_t index = pQueryInfo->numOfTables;
while (index >= 0) {
doRemoveTableMetaInfo(pQueryInfo, --index, removeFromCache);
}
tfree(pQueryInfo->pTableMetaInfo);
}
void tscFreeQueryInfo(SSqlCmd* pCmd) { void tscFreeQueryInfo(SSqlCmd* pCmd) {
if (pCmd == NULL || pCmd->numOfClause == 0) { if (pCmd == NULL || pCmd->numOfClause == 0) {
return; return;
...@@ -1637,7 +1640,7 @@ void tscFreeQueryInfo(SSqlCmd* pCmd) { ...@@ -1637,7 +1640,7 @@ void tscFreeQueryInfo(SSqlCmd* pCmd) {
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, i); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, i);
freeQueryInfoImpl(pQueryInfo); freeQueryInfoImpl(pQueryInfo);
tscClearAllTableMetaInfo(pQueryInfo, (const char*)addr, false); clearAllTableMetaInfo(pQueryInfo, (const char*)addr, false);
tfree(pQueryInfo); tfree(pQueryInfo);
} }
...@@ -1688,35 +1691,6 @@ STableMetaInfo* tscAddEmptyMetaInfo(SQueryInfo* pQueryInfo) { ...@@ -1688,35 +1691,6 @@ STableMetaInfo* tscAddEmptyMetaInfo(SQueryInfo* pQueryInfo) {
return tscAddTableMetaInfo(pQueryInfo, NULL, NULL, NULL, NULL); return tscAddTableMetaInfo(pQueryInfo, NULL, NULL, NULL, NULL);
} }
void doRemoveTableMetaInfo(SQueryInfo* pQueryInfo, int32_t index, bool removeFromCache) {
if (index < 0 || index >= pQueryInfo->numOfTables) {
return;
}
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index);
tscClearTableMetaInfo(pTableMetaInfo, removeFromCache);
free(pTableMetaInfo);
int32_t after = pQueryInfo->numOfTables - index - 1;
if (after > 0) {
memmove(&pQueryInfo->pTableMetaInfo[index], &pQueryInfo->pTableMetaInfo[index + 1], after * POINTER_BYTES);
}
pQueryInfo->numOfTables -= 1;
}
void tscClearAllTableMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache) {
tscTrace("%p deref the table meta in cache, numOfTables:%d", address, pQueryInfo->numOfTables);
int32_t index = pQueryInfo->numOfTables;
while (index >= 0) {
doRemoveTableMetaInfo(pQueryInfo, --index, removeFromCache);
}
tfree(pQueryInfo->pTableMetaInfo);
}
void tscClearTableMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache) { void tscClearTableMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache) {
if (pTableMetaInfo == NULL) { if (pTableMetaInfo == NULL) {
return; return;
...@@ -1781,19 +1755,25 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void ...@@ -1781,19 +1755,25 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
SQueryInfo* pNewQueryInfo = tscGetQueryInfoDetail(pnCmd, 0); SQueryInfo* pNewQueryInfo = tscGetQueryInfoDetail(pnCmd, 0);
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
memcpy(pNewQueryInfo, pQueryInfo, sizeof(SQueryInfo)); pNewQueryInfo->command = pQueryInfo->command;
pNewQueryInfo->slidingTimeUnit = pQueryInfo->slidingTimeUnit;
memset(&pNewQueryInfo->fieldsInfo, 0, sizeof(SFieldInfo)); pNewQueryInfo->intervalTime = pQueryInfo->intervalTime;
pNewQueryInfo->slidingTime = pQueryInfo->slidingTime;
pNewQueryInfo->type = pQueryInfo->type;
pNewQueryInfo->window = pQueryInfo->window;
pNewQueryInfo->limit = pQueryInfo->limit;
pNewQueryInfo->slimit = pQueryInfo->slimit;
pNewQueryInfo->order = pQueryInfo->order;
pNewQueryInfo->clauseLimit = pQueryInfo->clauseLimit;
pNewQueryInfo->pTableMetaInfo = NULL; pNewQueryInfo->pTableMetaInfo = NULL;
pNewQueryInfo->defaultVal = NULL; pNewQueryInfo->defaultVal = NULL;
pNewQueryInfo->numOfTables = 0; pNewQueryInfo->numOfTables = 0;
pNewQueryInfo->tsBuf = NULL; pNewQueryInfo->tsBuf = NULL;
pNewQueryInfo->colList = taosArrayInit(4, POINTER_BYTES); pNewQueryInfo->groupbyExpr = pQueryInfo->groupbyExpr;
pNewQueryInfo->fieldsInfo.pFields = taosArrayInit(4, sizeof(TAOS_FIELD)); if (pQueryInfo->groupbyExpr.columnInfo != NULL) {
pNewQueryInfo->fieldsInfo.pSupportInfo = taosArrayInit(4, sizeof(SFieldSupInfo)); pNewQueryInfo->groupbyExpr.columnInfo = taosArrayClone(pQueryInfo->groupbyExpr.columnInfo);
pNewQueryInfo->exprsInfo = taosArrayInit(4, POINTER_BYTES); }
tscTagCondCopy(&pNewQueryInfo->tagCond, &pQueryInfo->tagCond); tscTagCondCopy(&pNewQueryInfo->tagCond, &pQueryInfo->tagCond);
...@@ -1819,7 +1799,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void ...@@ -1819,7 +1799,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
} }
uint64_t uid = pTableMetaInfo->pTableMeta->uid; uint64_t uid = pTableMetaInfo->pTableMeta->uid;
pNewQueryInfo->exprsInfo = tscSqlExprCopy(pQueryInfo->exprsInfo, uid, true); tscSqlExprCopy(pNewQueryInfo->exprList, pQueryInfo->exprList, uid, true);
int32_t numOfOutput = tscSqlExprNumOfExprs(pNewQueryInfo); int32_t numOfOutput = tscSqlExprNumOfExprs(pNewQueryInfo);
...@@ -1843,16 +1823,19 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void ...@@ -1843,16 +1823,19 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
// todo handle the agg arithmetic expression // todo handle the agg arithmetic expression
for(int32_t f = 0; f < pNewQueryInfo->fieldsInfo.numOfOutput; ++f) { for(int32_t f = 0; f < pNewQueryInfo->fieldsInfo.numOfOutput; ++f) {
TAOS_FIELD* field = tscFieldInfoGetField(&pNewQueryInfo->fieldsInfo, f); TAOS_FIELD* field = tscFieldInfoGetField(&pNewQueryInfo->fieldsInfo, f);
numOfExprs = tscSqlExprNumOfExprs(pNewQueryInfo);
for(int32_t k1 = 0; k1 < numOfExprs; ++k1) { for(int32_t k1 = 0; k1 < numOfExprs; ++k1) {
SSqlExpr* pExpr1 = tscSqlExprGet(pNewQueryInfo, k1); SSqlExpr* pExpr1 = tscSqlExprGet(pNewQueryInfo, k1);
if (strcmp(field->name, pExpr1->aliasName) == 0) {
if (strcmp(field->name, pExpr1->aliasName) == 0) { // eatablish link according to the result field name
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pNewQueryInfo->fieldsInfo, f); SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pNewQueryInfo->fieldsInfo, f);
pInfo->pSqlExpr = pExpr1; pInfo->pSqlExpr = pExpr1;
} }
} }
} }
tscFieldInfoUpdateOffsetForInterResult(pNewQueryInfo); tscFieldInfoUpdateOffset(pNewQueryInfo);
} }
pNew->fp = fp; pNew->fp = fp;
...@@ -1884,7 +1867,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void ...@@ -1884,7 +1867,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
size_t size = taosArrayGetSize(pNewQueryInfo->colList); size_t size = taosArrayGetSize(pNewQueryInfo->colList);
tscTrace( tscTrace(
"%p new subquery: %p, tableIndex:%d, vnodeIdx:%d, type:%d, exprInfo:%d, colList:%d," "%p new subquery:%p, tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%d, colList:%d,"
"fieldInfo:%d, name:%s, qrang:%" PRId64 " - %" PRId64 " order:%d, limit:%" PRId64, "fieldInfo:%d, name:%s, qrang:%" PRId64 " - %" PRId64 " order:%d, limit:%" PRId64,
pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo), pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo),
size, pNewQueryInfo->fieldsInfo.numOfOutput, pFinalInfo->name, pNewQueryInfo->window.skey, size, pNewQueryInfo->fieldsInfo.numOfOutput, pFinalInfo->name, pNewQueryInfo->window.skey,
...@@ -1898,14 +1881,22 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void ...@@ -1898,14 +1881,22 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
return pNew; return pNew;
} }
/**
* To decide if current is a two-stage super table query, join query, or insert. And invoke different
* procedure accordingly
* @param pSql
*/
void tscDoQuery(SSqlObj* pSql) { void tscDoQuery(SSqlObj* pSql) {
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
SSqlRes* pRes = &pSql->res;
pSql->res.code = TSDB_CODE_SUCCESS; pRes->code = TSDB_CODE_SUCCESS;
if (pCmd->command > TSDB_SQL_LOCAL) { if (pCmd->command > TSDB_SQL_LOCAL) {
tscProcessLocalCmd(pSql); tscProcessLocalCmd(pSql);
} else { return;
}
if (pCmd->command == TSDB_SQL_SELECT) { if (pCmd->command == TSDB_SQL_SELECT) {
tscAddIntoSqlList(pSql); tscAddIntoSqlList(pSql);
} }
...@@ -1913,9 +1904,31 @@ void tscDoQuery(SSqlObj* pSql) { ...@@ -1913,9 +1904,31 @@ void tscDoQuery(SSqlObj* pSql) {
if (pCmd->dataSourceType == DATA_FROM_DATA_FILE) { if (pCmd->dataSourceType == DATA_FROM_DATA_FILE) {
tscProcessMultiVnodesInsertFromFile(pSql); tscProcessMultiVnodesInsertFromFile(pSql);
} else { } else {
// pSql may be released in this function if it is a async insertion. SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
tscProcessSql(pSql); uint16_t type = pQueryInfo->type;
if (pSql->fp == (void(*)())tscHandleMultivnodeInsert) { // multi-vnodes insertion
tscHandleMultivnodeInsert(pSql);
return;
}
if (QUERY_IS_JOIN_QUERY(type)) {
if ((pQueryInfo->type & TSDB_QUERY_TYPE_SUBQUERY) == 0) {
tscHandleMasterJoinQuery(pSql);
return;
} else {
// for first stage sub query, iterate all vnodes to get all timestamp
if ((pQueryInfo->type & TSDB_QUERY_TYPE_JOIN_SEC_STAGE) != TSDB_QUERY_TYPE_JOIN_SEC_STAGE) {
// doProcessSql(pSql);
assert(0);
}
}
} else if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) { // super table query
tscHandleMasterSTableQuery(pSql);
return;
} }
tscProcessSql(pSql);
} }
} }
...@@ -2094,7 +2107,7 @@ void tscTryQueryNextClause(SSqlObj* pSql, void (*queryFp)()) { ...@@ -2094,7 +2107,7 @@ void tscTryQueryNextClause(SSqlObj* pSql, void (*queryFp)()) {
//backup the total number of result first //backup the total number of result first
int64_t num = pRes->numOfTotal + pRes->numOfTotalInCurrentClause; int64_t num = pRes->numOfTotal + pRes->numOfTotalInCurrentClause;
tscFreeResData(pSql); tscFreeSqlResult(pSql);
pRes->numOfTotal = num; pRes->numOfTotal = num;
...@@ -2114,10 +2127,22 @@ void tscTryQueryNextClause(SSqlObj* pSql, void (*queryFp)()) { ...@@ -2114,10 +2127,22 @@ void tscTryQueryNextClause(SSqlObj* pSql, void (*queryFp)()) {
} }
} }
char* tscGetResultColumnChr(SSqlRes* pRes, SQueryInfo* pQueryInfo, int32_t column) { char* tscGetResultColumnChr(SSqlRes* pRes, SQueryInfo* pQueryInfo, int32_t column, int16_t bytes) {
SFieldInfo* pFieldInfo = &pQueryInfo->fieldsInfo; SFieldInfo* pFieldInfo = &pQueryInfo->fieldsInfo;
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(pFieldInfo, column); SFieldSupInfo* pInfo = tscFieldInfoGetSupp(pFieldInfo, column);
return ((char*) pRes->data) + pInfo->pSqlExpr->offset * pRes->numOfRows; int32_t type = pInfo->pSqlExpr->resType;
char* pData = ((char*) pRes->data) + pInfo->pSqlExpr->offset * pRes->numOfRows + bytes * pRes->row;
if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) {
int32_t realLen = varDataLen(pData);
if (realLen < pInfo->pSqlExpr->resBytes - VARSTR_HEADER_SIZE) { // todo refactor
*(char*) (pData + realLen + sizeof(int16_t)) = 0;
}
return pData + VARSTR_HEADER_SIZE; // head is the length of binary/nchar data
} else {
return pData;
}
} }
...@@ -26,6 +26,20 @@ ...@@ -26,6 +26,20 @@
extern "C" { extern "C" {
#endif #endif
#define STR_TO_VARSTR(x, str) do {VarDataLenT __len = strlen(str); \
*(VarDataLenT*)(x) = __len; \
strncpy((char*)(x) + VARSTR_HEADER_SIZE, (str), __len);} while(0);
#define STR_WITH_MAXSIZE_TO_VARSTR(x, str, _maxs) do {\
char* _e = stpncpy((char*)(x) + VARSTR_HEADER_SIZE, (str), (_maxs));\
*(VarDataLenT*)(x) = _e - (x);\
} while(0)
#define STR_WITH_SIZE_TO_VARSTR(x, str, _size) do {\
*(VarDataLenT*)(x) = (_size); \
strncpy((char*)(x) + VARSTR_HEADER_SIZE, (str), (_size));\
} while(0);
// ----------------- TSDB COLUMN DEFINITION // ----------------- TSDB COLUMN DEFINITION
typedef struct { typedef struct {
int8_t type; // Column type int8_t type; // Column type
...@@ -182,7 +196,7 @@ void tdInitDataCols(SDataCols *pCols, STSchema *pSchema); ...@@ -182,7 +196,7 @@ void tdInitDataCols(SDataCols *pCols, STSchema *pSchema);
SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData); SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData);
void tdFreeDataCols(SDataCols *pCols); void tdFreeDataCols(SDataCols *pCols);
void tdAppendDataRowToDataCol(SDataRow row, SDataCols *pCols); void tdAppendDataRowToDataCol(SDataRow row, SDataCols *pCols);
void tdPopDataColsPoints(SDataCols *pCols, int pointsToPop); void tdPopDataColsPoints(SDataCols *pCols, int pointsToPop); //!!!!
int tdMergeDataCols(SDataCols *target, SDataCols *src, int rowsToMerge); int tdMergeDataCols(SDataCols *target, SDataCols *src, int rowsToMerge);
void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, SDataCols *src2, int *iter2, int tRows); void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, SDataCols *src2, int *iter2, int tRows);
......
...@@ -172,28 +172,9 @@ int tdAppendColVal(SDataRow row, void *value, int8_t type, int32_t bytes, int32_ ...@@ -172,28 +172,9 @@ int tdAppendColVal(SDataRow row, void *value, int8_t type, int32_t bytes, int32_
switch (type) { switch (type) {
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
// set offset
*(VarDataOffsetT *)POINTER_DRIFT(row, toffset) = dataRowLen(row); *(VarDataOffsetT *)POINTER_DRIFT(row, toffset) = dataRowLen(row);
memcpy(ptr, value, varDataTLen(value));
// set length dataRowLen(row) += varDataTLen(value);
VarDataLenT slen = 0;
if (isNull(value, type)) {
slen = (type == TSDB_DATA_TYPE_BINARY) ? sizeof(int8_t) : sizeof(int32_t);
} else {
if (type == TSDB_DATA_TYPE_BINARY) {
slen = strnlen((char *)value, bytes);
} else {
slen = wcsnlen((wchar_t *)value, (bytes) / TSDB_NCHAR_SIZE) * TSDB_NCHAR_SIZE;
}
}
ASSERT(slen <= bytes);
*(VarDataLenT *)ptr = slen;
ptr = POINTER_DRIFT(ptr, sizeof(VarDataLenT));
memcpy((void *)ptr, value, slen);
dataRowLen(row) += (sizeof(int16_t) + slen);
break; break;
default: default:
memcpy(POINTER_DRIFT(row, toffset), value, TYPE_BYTES[type]); memcpy(POINTER_DRIFT(row, toffset), value, TYPE_BYTES[type]);
......
...@@ -25,13 +25,10 @@ __attribute__((unused)) static FORCE_INLINE size_t copy(char* dst, const char* s ...@@ -25,13 +25,10 @@ __attribute__((unused)) static FORCE_INLINE size_t copy(char* dst, const char* s
} }
void extractTableName(const char* tableId, char* name) { void extractTableName(const char* tableId, char* name) {
size_t offset = strcspn(tableId, &TS_PATH_DELIMITER[0]); size_t s1 = strcspn(tableId, &TS_PATH_DELIMITER[0]);
offset = strcspn(&tableId[offset], &TS_PATH_DELIMITER[0]); size_t s2 = strcspn(&tableId[s1 + 1], &TS_PATH_DELIMITER[0]);
strncpy(name, &tableId[offset], TSDB_TABLE_NAME_LEN); strncpy(name, &tableId[s1 + s2 + 2], TSDB_TABLE_NAME_LEN);
// char* r = skipSegments(tableId, TS_PATH_DELIMITER[0], 2);
// return copy(name, r, TS_PATH_DELIMITER[0]);
} }
char* extractDBName(const char* tableId, char* name) { char* extractDBName(const char* tableId, char* name) {
......
...@@ -198,7 +198,7 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) { ...@@ -198,7 +198,7 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) {
break; break;
}; };
case TSDB_DATA_TYPE_BINARY: { case TSDB_DATA_TYPE_BINARY: {
strncpy(val, src, len); varDataCopy(val, src);
break; break;
}; };
case TSDB_DATA_TYPE_NCHAR: { case TSDB_DATA_TYPE_NCHAR: {
......
...@@ -228,7 +228,7 @@ static void dnodeHandleIdleWorker(SWriteWorker *pWorker) { ...@@ -228,7 +228,7 @@ static void dnodeHandleIdleWorker(SWriteWorker *pWorker) {
int32_t num = taosGetQueueNumber(pWorker->qset); int32_t num = taosGetQueueNumber(pWorker->qset);
if (num > 0) { if (num > 0) {
usleep(30000); usleep(30);
sched_yield(); sched_yield();
} else { } else {
taosFreeQall(pWorker->qall); taosFreeQall(pWorker->qall);
......
...@@ -23,12 +23,12 @@ typedef void* qinfo_t; ...@@ -23,12 +23,12 @@ typedef void* qinfo_t;
/** /**
* create the qinfo object according to QueryTableMsg * create the qinfo object according to QueryTableMsg
* @param pVnode * @param tsdb
* @param pQueryTableMsg * @param pQueryTableMsg
* @param qinfo * @param qinfo
* @return * @return
*/ */
int32_t qCreateQueryInfo(void* pVnode, SQueryTableMsg* pQueryTableMsg, qinfo_t* qinfo); int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryTableMsg, qinfo_t* qinfo);
/** /**
* Destroy QInfo object * Destroy QInfo object
......
...@@ -35,12 +35,15 @@ extern "C" { ...@@ -35,12 +35,15 @@ extern "C" {
// ----------------- For variable data types such as TSDB_DATA_TYPE_BINARY and TSDB_DATA_TYPE_NCHAR // ----------------- For variable data types such as TSDB_DATA_TYPE_BINARY and TSDB_DATA_TYPE_NCHAR
typedef int32_t VarDataOffsetT; typedef int32_t VarDataOffsetT;
typedef int16_t VarDataLenT; typedef int16_t VarDataLenT;
#define varDataLen(v) ((VarDataLenT *)(v))[0] #define varDataLen(v) ((VarDataLenT *)(v))[0]
#define varDataTLen(v) (sizeof(VarDataLenT) + varDataLen(v)) #define varDataTLen(v) (sizeof(VarDataLenT) + varDataLen(v))
#define varDataVal(v) ((void *)((char *)v + sizeof(VarDataLenT))) #define varDataVal(v) ((void *)((char *)v + sizeof(VarDataLenT)))
#define varDataCopy(dst, v) memcpy((dst), (void*) (v), varDataTLen(v))
// this data type is internally used only in 'in' query to hold the values // this data type is internally used only in 'in' query to hold the values
#define TSDB_DATA_TYPE_ARRAY (TSDB_DATA_TYPE_NCHAR + 1) #define TSDB_DATA_TYPE_ARRAY (TSDB_DATA_TYPE_NCHAR + 1)
#define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
// Bytes for each type. // Bytes for each type.
extern const int32_t TYPE_BYTES[11]; extern const int32_t TYPE_BYTES[11];
...@@ -209,7 +212,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); ...@@ -209,7 +212,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
#define TSDB_SHELL_VNODE_BITS 24 #define TSDB_SHELL_VNODE_BITS 24
#define TSDB_SHELL_SID_MASK 0xFF #define TSDB_SHELL_SID_MASK 0xFF
#define TSDB_HTTP_TOKEN_LEN 20 #define TSDB_HTTP_TOKEN_LEN 20
#define TSDB_SHOW_SQL_LEN 32 #define TSDB_SHOW_SQL_LEN 512
#define TSDB_METER_STATE_OFFLINE 0 #define TSDB_METER_STATE_OFFLINE 0
#define TSDB_METER_STATE_ONLLINE 1 #define TSDB_METER_STATE_ONLLINE 1
...@@ -290,27 +293,30 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); ...@@ -290,27 +293,30 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
#define TSDB_MAX_RPC_THREADS 5 #define TSDB_MAX_RPC_THREADS 5
#define TSDB_QUERY_TYPE_NON_TYPE 0x00U // none type #define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type
#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01U // free qhandle at vnode #define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode
/* /*
* 1. ordinary sub query for select * from super_table * 1. ordinary sub query for select * from super_table
* 2. all sqlobj generated by createSubqueryObj with this flag * 2. all sqlobj generated by createSubqueryObj with this flag
*/ */
#define TSDB_QUERY_TYPE_SUBQUERY 0x02U #define TSDB_QUERY_TYPE_SUBQUERY 0x02u
#define TSDB_QUERY_TYPE_STABLE_SUBQUERY 0x04U // two-stage subquery for super table #define TSDB_QUERY_TYPE_STABLE_SUBQUERY 0x04u // two-stage subquery for super table
#define TSDB_QUERY_TYPE_TABLE_QUERY 0x08U // query ordinary table; below only apply to client side #define TSDB_QUERY_TYPE_TABLE_QUERY 0x08u // query ordinary table; below only apply to client side
#define TSDB_QUERY_TYPE_STABLE_QUERY 0x10U // query on super table #define TSDB_QUERY_TYPE_STABLE_QUERY 0x10u // query on super table
#define TSDB_QUERY_TYPE_JOIN_QUERY 0x20U // join query #define TSDB_QUERY_TYPE_JOIN_QUERY 0x20u // join query
#define TSDB_QUERY_TYPE_PROJECTION_QUERY 0x40U // select *,columns... query #define TSDB_QUERY_TYPE_PROJECTION_QUERY 0x40u // select *,columns... query
#define TSDB_QUERY_TYPE_JOIN_SEC_STAGE 0x80U // join sub query at the second stage #define TSDB_QUERY_TYPE_JOIN_SEC_STAGE 0x80u // join sub query at the second stage
#define TSDB_QUERY_TYPE_INSERT 0x100U // insert type #define TSDB_QUERY_TYPE_TAG_FILTER_QUERY 0x400u
#define TSDB_QUERY_TYPE_IMPORT 0x200U // import data #define TSDB_QUERY_TYPE_INSERT 0x100u // insert type
#define TSDB_QUERY_TYPE_IMPORT 0x200u // import data
#define TSDB_QUERY_TYPE_MULTITABLE_QUERY 0x800u
#define TSDB_QUERY_HAS_TYPE(x, _type) (((x) & (_type)) != 0) #define TSDB_QUERY_HAS_TYPE(x, _type) (((x) & (_type)) != 0)
#define TSDB_QUERY_SET_TYPE(x, _type) ((x) |= (_type)) #define TSDB_QUERY_SET_TYPE(x, _type) ((x) |= (_type))
#define TSDB_QUERY_CLEAR_TYPE(x, _type) ((x) &= (~_type))
#define TSDB_QUERY_RESET_TYPE(x) ((x) = TSDB_QUERY_TYPE_NON_TYPE) #define TSDB_QUERY_RESET_TYPE(x) ((x) = TSDB_QUERY_TYPE_NON_TYPE)
#define TSDB_ORDER_ASC 1 #define TSDB_ORDER_ASC 1
......
...@@ -380,13 +380,13 @@ typedef struct SSqlFuncMsg { ...@@ -380,13 +380,13 @@ typedef struct SSqlFuncMsg {
} arg[3]; } arg[3];
} SSqlFuncMsg; } SSqlFuncMsg;
typedef struct SArithExprInfo { typedef struct SExprInfo {
SSqlFuncMsg base; SSqlFuncMsg base;
struct tExprNode* pExpr; struct tExprNode* pExpr;
int16_t bytes; int16_t bytes;
int16_t type; int16_t type;
int16_t interResBytes; int16_t interResBytes;
} SArithExprInfo; } SExprInfo;
typedef struct SColumnFilterInfo { typedef struct SColumnFilterInfo {
int16_t lowerRelOptr; int16_t lowerRelOptr;
...@@ -422,8 +422,8 @@ typedef struct SColumnInfo { ...@@ -422,8 +422,8 @@ typedef struct SColumnInfo {
} SColumnInfo; } SColumnInfo;
typedef struct STableIdInfo { typedef struct STableIdInfo {
int32_t sid;
int64_t uid; int64_t uid;
int32_t tid;
TSKEY key; // last accessed ts, for subscription TSKEY key; // last accessed ts, for subscription
} STableIdInfo; } STableIdInfo;
...@@ -459,9 +459,6 @@ typedef struct { ...@@ -459,9 +459,6 @@ typedef struct {
int16_t tagNameRelType; // relation of tag criteria and tbname criteria int16_t tagNameRelType; // relation of tag criteria and tbname criteria
int16_t interpoType; // interpolate type int16_t interpoType; // interpolate type
uint64_t defaultVal; // default value array list uint64_t defaultVal; // default value array list
// int32_t colNameLen;
// int64_t colNameList;
int32_t tsOffset; // offset value in current msg body, NOTE: ts list is compressed int32_t tsOffset; // offset value in current msg body, NOTE: ts list is compressed
int32_t tsLen; // total length of ts comp block int32_t tsLen; // total length of ts comp block
int32_t tsNumOfBlocks; // ts comp block numbers int32_t tsNumOfBlocks; // ts comp block numbers
...@@ -624,8 +621,8 @@ typedef struct { ...@@ -624,8 +621,8 @@ typedef struct {
} SCMMultiTableInfoMsg; } SCMMultiTableInfoMsg;
typedef struct SCMSTableVgroupMsg { typedef struct SCMSTableVgroupMsg {
char tableId[TSDB_TABLE_ID_LEN]; int32_t numOfTables;
} SCMSTableVgroupMsg; } SCMSTableVgroupMsg, SCMSTableVgroupRspMsg;
typedef struct { typedef struct {
int32_t vgId; int32_t vgId;
...@@ -636,57 +633,14 @@ typedef struct { ...@@ -636,57 +633,14 @@ typedef struct {
typedef struct { typedef struct {
int32_t numOfVgroups; int32_t numOfVgroups;
SCMVgroupInfo vgroups[]; SCMVgroupInfo vgroups[];
} SCMSTableVgroupRspMsg; } SVgroupsInfo;
typedef struct { //typedef struct {
int16_t elemLen; // int32_t numOfTables;
// int32_t join;
char tableId[TSDB_TABLE_ID_LEN + 1]; // int32_t joinCondLen; // for join condition
int16_t orderIndex; // int32_t metaElem[TSDB_MAX_JOIN_TABLE_NUM];
int16_t orderType; // used in group by xx order by xxx //} SSuperTableMetaMsg;
int16_t rel; // denotes the relation between condition and table list
int32_t tableCond; // offset value of table name condition
int32_t tableCondLen;
int32_t cond; // offset of column query condition
int32_t condLen;
int16_t tagCols[TSDB_MAX_TAGS + 1]; // required tag columns, plus one is for table name
int16_t numOfTags; // required number of tags
int16_t numOfGroupCols; // num of group by columns
int32_t groupbyTagColumnList;
} SSuperTableMetaElemMsg;
typedef struct {
int32_t numOfTables;
int32_t join;
int32_t joinCondLen; // for join condition
int32_t metaElem[TSDB_MAX_JOIN_TABLE_NUM];
} SSuperTableMetaMsg;
typedef struct {
int32_t nodeId;
uint32_t nodeIp;
uint16_t nodePort;
} SVnodeDesc;
typedef struct {
SVnodeDesc vpeerDesc[TSDB_MAX_REPLICA_NUM];
int16_t index; // used locally
int32_t vgId;
int32_t numOfSids;
int32_t pSidExtInfoList[]; // offset value of STableIdInfo
} SVnodeSidList;
typedef struct {
int32_t numOfTables;
int32_t numOfVnodes;
uint16_t tagLen; /* tag value length */
int32_t list[]; /* offset of SVnodeSidList, compared to the SSuperTableMeta struct */
} SSuperTableMeta;
typedef struct STableMetaMsg { typedef struct STableMetaMsg {
int32_t contLen; int32_t contLen;
......
...@@ -101,8 +101,8 @@ int tsdbTableSetName(STableCfg *config, char *name, bool dup); ...@@ -101,8 +101,8 @@ int tsdbTableSetName(STableCfg *config, char *name, bool dup);
int tsdbTableSetSName(STableCfg *config, char *sname, bool dup); int tsdbTableSetSName(STableCfg *config, char *sname, bool dup);
void tsdbClearTableCfg(STableCfg *config); void tsdbClearTableCfg(STableCfg *config);
int32_t tsdbGetTableTagVal(TsdbRepoT *repo, STableId id, int32_t col, int16_t *type, int16_t *bytes, char **val); int32_t tsdbGetTableTagVal(TsdbRepoT *repo, STableId* id, int32_t colId, int16_t *type, int16_t *bytes, char **val);
int32_t tsdbTableGetName(TsdbRepoT *repo, STableId id, char** name); int32_t tsdbGetTableName(TsdbRepoT *repo, STableId* id, char** name);
int tsdbCreateTable(TsdbRepoT *repo, STableCfg *pCfg); int tsdbCreateTable(TsdbRepoT *repo, STableCfg *pCfg);
int tsdbDropTable(TsdbRepoT *pRepo, STableId tableId); int tsdbDropTable(TsdbRepoT *pRepo, STableId tableId);
...@@ -142,34 +142,20 @@ int32_t tsdbInsertData(TsdbRepoT *pRepo, SSubmitMsg *pMsg); ...@@ -142,34 +142,20 @@ int32_t tsdbInsertData(TsdbRepoT *pRepo, SSubmitMsg *pMsg);
typedef void *TsdbQueryHandleT; // Use void to hide implementation details typedef void *TsdbQueryHandleT; // Use void to hide implementation details
typedef struct STableGroupList { // qualified table object list in group
SArray *pGroupList;
int32_t numOfTables;
} STableGroupList;
// query condition to build vnode iterator // query condition to build vnode iterator
typedef struct STsdbQueryCond { typedef struct STsdbQueryCond {
STimeWindow twindow; STimeWindow twindow;
int32_t order; // desc/asc order to iterate the data block int32_t order; // desc|asc order to iterate the data block
int32_t numOfCols; int32_t numOfCols;
SColumnInfo *colList; SColumnInfo *colList;
} STsdbQueryCond; } STsdbQueryCond;
typedef struct SBlockInfo {
STimeWindow window;
int32_t numOfRows;
int32_t numOfCols;
STableId tableId;
} SBlockInfo;
typedef struct SDataBlockInfo { typedef struct SDataBlockInfo {
STimeWindow window; STimeWindow window;
int32_t rows; int32_t rows;
int32_t numOfCols; int32_t numOfCols;
int64_t uid; int64_t uid;
int32_t sid; int32_t tid;
} SDataBlockInfo; } SDataBlockInfo;
typedef struct { typedef struct {
...@@ -192,14 +178,29 @@ typedef void *TsdbPosT; ...@@ -192,14 +178,29 @@ typedef void *TsdbPosT;
/** /**
* Get the data block iterator, starting from position according to the query condition * Get the data block iterator, starting from position according to the query condition
* @param pCond query condition, only includes the filter on primary time stamp *
* @param pTableList table sid list * @param tsdb tsdb handle
* @param pCond query condition, including time window, result set order, and basic required columns for each block
* @param groupInfo tableId list in the form of set, seperated into different groups according to group by condition
* @return * @return
*/ */
TsdbQueryHandleT *tsdbQueryTables(TsdbRepoT *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupInfo); TsdbQueryHandleT *tsdbQueryTables(TsdbRepoT *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupInfo);
/** /**
* move to next block * Get the last row of the given query time window for all the tables in STableGroupInfo object.
* Note that only one data block with only row will be returned while invoking retrieve data block function for
* all tables in this group.
*
* @param tsdb tsdb handle
* @param pCond query condition, including time window, result set order, and basic required columns for each block
* @param groupInfo tableId list.
* @return
*/
TsdbQueryHandleT tsdbQueryLastRow(TsdbRepoT *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupInfo);
/**
* move to next block if exists
*
* @param pQueryHandle * @param pQueryHandle
* @return * @return
*/ */
...@@ -226,26 +227,16 @@ SDataBlockInfo tsdbRetrieveDataBlockInfo(TsdbQueryHandleT *pQueryHandle); ...@@ -226,26 +227,16 @@ SDataBlockInfo tsdbRetrieveDataBlockInfo(TsdbQueryHandleT *pQueryHandle);
int32_t tsdbRetrieveDataBlockStatisInfo(TsdbQueryHandleT *pQueryHandle, SDataStatis **pBlockStatis); int32_t tsdbRetrieveDataBlockStatisInfo(TsdbQueryHandleT *pQueryHandle, SDataStatis **pBlockStatis);
/** /**
*
* The query condition with primary timestamp is passed to iterator during its constructor function, * The query condition with primary timestamp is passed to iterator during its constructor function,
* the returned data block must be satisfied with the time window condition in any cases, * the returned data block must be satisfied with the time window condition in any cases,
* which means the SData data block is not actually the completed disk data blocks. * which means the SData data block is not actually the completed disk data blocks.
* *
* @param pQueryHandle * @param pQueryHandle query handle
* @param pColumnIdList required data columns id list
* @return * @return
*/ */
SArray *tsdbRetrieveDataBlock(TsdbQueryHandleT *pQueryHandle, SArray *pIdList); SArray *tsdbRetrieveDataBlock(TsdbQueryHandleT *pQueryHandle, SArray *pColumnIdList);
/**
* todo remove the parameter of position, and order type
*
* Reset to the start(end) position of current query, from which the iterator starts.
*
* @param pQueryHandle
* @param position set the iterator traverses position
* @param order ascending order or descending order
* @return
*/
int32_t tsdbResetQuery(TsdbQueryHandleT *pQueryHandle, STimeWindow *window, TsdbPosT position, int16_t order);
/** /**
* todo remove this function later * todo remove this function later
...@@ -282,20 +273,19 @@ SArray *tsdbGetTableList(TsdbQueryHandleT *pQueryHandle); ...@@ -282,20 +273,19 @@ SArray *tsdbGetTableList(TsdbQueryHandleT *pQueryHandle);
* Get the qualified table id for a super table according to the tag query expression. * Get the qualified table id for a super table according to the tag query expression.
* @param stableid. super table sid * @param stableid. super table sid
* @param pTagCond. tag query condition * @param pTagCond. tag query condition
*
*/ */
int32_t tsdbQueryByTagsCond( int32_t tsdbQuerySTableByTagCond(TsdbRepoT *tsdb, int64_t uid, const char *pTagCond, size_t len,
TsdbRepoT *tsdb, int16_t tagNameRelType, const char* tbnameCond, STableGroupInfo *pGroupList, SColIndex *pColIndex, int32_t numOfCols);
int64_t uid,
const char *pTagCond,
size_t len,
int16_t tagNameRelType,
const char* tbnameCond,
STableGroupInfo *pGroupList,
SColIndex *pColIndex,
int32_t numOfCols
);
/**
* create the table group result including only one table, used to handle the normal table query
*
* @param tsdb tsdbHandle
* @param uid table uid
* @param pGroupInfo the generated result
* @return
*/
int32_t tsdbGetOneTableGroup(TsdbRepoT *tsdb, int64_t uid, STableGroupInfo *pGroupInfo); int32_t tsdbGetOneTableGroup(TsdbRepoT *tsdb, int64_t uid, STableGroupInfo *pGroupInfo);
/** /**
......
...@@ -22,7 +22,7 @@ extern "C" { ...@@ -22,7 +22,7 @@ extern "C" {
typedef enum _VN_STATUS { typedef enum _VN_STATUS {
TAOS_VN_STATUS_INIT, TAOS_VN_STATUS_INIT,
TAOS_VN_STATUS_CREATING, TAOS_VN_STATUS_UPDATING,
TAOS_VN_STATUS_READY, TAOS_VN_STATUS_READY,
TAOS_VN_STATUS_CLOSING, TAOS_VN_STATUS_CLOSING,
TAOS_VN_STATUS_DELETING, TAOS_VN_STATUS_DELETING,
......
...@@ -66,6 +66,7 @@ typedef struct SMnodeObj { ...@@ -66,6 +66,7 @@ typedef struct SMnodeObj {
SDnodeObj *pDnode; SDnodeObj *pDnode;
} SMnodeObj; } SMnodeObj;
// todo use dynamic length string
typedef struct { typedef struct {
char tableId[TSDB_TABLE_ID_LEN + 1]; char tableId[TSDB_TABLE_ID_LEN + 1];
int8_t type; int8_t type;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "ttime.h" #include "ttime.h"
#include "tname.h" #include "tname.h"
#include "tbalance.h" #include "tbalance.h"
#include "tdataformat.h"
#include "mgmtDef.h" #include "mgmtDef.h"
#include "mgmtLog.h" #include "mgmtLog.h"
#include "mgmtAcct.h" #include "mgmtAcct.h"
...@@ -431,7 +432,7 @@ static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) ...@@ -431,7 +432,7 @@ static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn)
SUserObj *pUser = mgmtGetUserFromConn(pConn); SUserObj *pUser = mgmtGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
pShow->bytes[cols] = TSDB_DB_NAME_LEN; pShow->bytes[cols] = TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "name"); strcpy(pSchema[cols].name, "name");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
...@@ -439,7 +440,7 @@ static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) ...@@ -439,7 +440,7 @@ static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn)
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "create time"); strcpy(pSchema[cols].name, "created_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
...@@ -586,7 +587,9 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void * ...@@ -586,7 +587,9 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *
cols = 0; cols = 0;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, mgmtGetDbStr(pDb->name));
char* name = mgmtGetDbStr(pDb->name);
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, TSDB_DB_NAME_LEN);
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
...@@ -622,7 +625,10 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void * ...@@ -622,7 +625,10 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *
#endif #endif
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
sprintf(pWrite, "%d,%d,%d", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2, pDb->cfg.daysToKeep);
char tmp[128] = {0};
size_t n = sprintf(tmp, "%d,%d,%d", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2, pDb->cfg.daysToKeep);
STR_WITH_SIZE_TO_VARSTR(pWrite, tmp, n);
cols++; cols++;
#ifndef __CLOUD_VERSION__ #ifndef __CLOUD_VERSION__
...@@ -670,7 +676,11 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void * ...@@ -670,7 +676,11 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, pDb->status != TSDB_DB_STATUS_READY ? "dropping" : "ready"); if (pDb->status == TSDB_DB_STATUS_READY) {
STR_WITH_SIZE_TO_VARSTR(pWrite, "ready", 5);
} else {
STR_WITH_SIZE_TO_VARSTR(pWrite, "dropping", 8);
}
cols++; cols++;
numOfRows++; numOfRows++;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "tsocket.h" #include "tsocket.h"
#include "tbalance.h" #include "tbalance.h"
#include "tsync.h" #include "tsync.h"
#include "tdataformat.h"
#include "dnode.h" #include "dnode.h"
#include "mgmtDef.h" #include "mgmtDef.h"
#include "mgmtLog.h" #include "mgmtLog.h"
...@@ -490,23 +491,23 @@ static int32_t mgmtGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo ...@@ -490,23 +491,23 @@ static int32_t mgmtGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
pShow->bytes[cols] = 40; pShow->bytes[cols] = 40;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "end point"); strcpy(pSchema[cols].name, "end_point");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 2; pShow->bytes[cols] = 2;
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
strcpy(pSchema[cols].name, "open vnodes"); strcpy(pSchema[cols].name, "open_vnodes");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 2; pShow->bytes[cols] = 2;
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
strcpy(pSchema[cols].name, "total vnodes"); strcpy(pSchema[cols].name, "total_vnodes");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 10; pShow->bytes[cols] = 12;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "status"); strcpy(pSchema[cols].name, "status");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
...@@ -514,7 +515,7 @@ static int32_t mgmtGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo ...@@ -514,7 +515,7 @@ static int32_t mgmtGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "create time"); strcpy(pSchema[cols].name, "create_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
...@@ -552,7 +553,7 @@ static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, voi ...@@ -552,7 +553,7 @@ static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, voi
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strncpy(pWrite, pDnode->dnodeEp, pShow->bytes[cols]-1); STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDnode->dnodeEp, pShow->bytes[cols] - VARSTR_HEADER_SIZE);
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
...@@ -564,7 +565,9 @@ static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, voi ...@@ -564,7 +565,9 @@ static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, voi
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, mgmtGetDnodeStatusStr(pDnode->status));
char* status = mgmtGetDnodeStatusStr(pDnode->status);
STR_TO_VARSTR(pWrite, status);
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "tutil.h" #include "tutil.h"
#include "ttime.h" #include "ttime.h"
#include "tsocket.h" #include "tsocket.h"
#include "tdataformat.h"
#include "mgmtDef.h" #include "mgmtDef.h"
#include "mgmtLog.h" #include "mgmtLog.h"
#include "mgmtMnode.h" #include "mgmtMnode.h"
...@@ -288,13 +289,13 @@ static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo ...@@ -288,13 +289,13 @@ static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 40; pShow->bytes[cols] = 40 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "end point"); strcpy(pSchema[cols].name, "end_point");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 10; pShow->bytes[cols] = 12;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "role"); strcpy(pSchema[cols].name, "role");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
...@@ -302,7 +303,7 @@ static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo ...@@ -302,7 +303,7 @@ static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "create time"); strcpy(pSchema[cols].name, "create_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
...@@ -339,11 +340,12 @@ static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, voi ...@@ -339,11 +340,12 @@ static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, voi
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strncpy(pWrite, pMnode->pDnode->dnodeEp, pShow->bytes[cols]-1); STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pMnode->pDnode->dnodeEp, pShow->bytes[cols] - VARSTR_HEADER_SIZE);
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, mgmtGetMnodeRoleStr(pMnode->role)); char* roles = mgmtGetMnodeRoleStr(pMnode->role);
STR_TO_VARSTR(pWrite, roles);
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "mgmtUser.h" #include "mgmtUser.h"
#include "mgmtVgroup.h" #include "mgmtVgroup.h"
#include "tcompare.h" #include "tcompare.h"
#include "tdataformat.h"
static void * tsChildTableSdb; static void * tsChildTableSdb;
static void * tsSuperTableSdb; static void * tsSuperTableSdb;
...@@ -623,6 +624,7 @@ void mgmtCleanUpTables() { ...@@ -623,6 +624,7 @@ void mgmtCleanUpTables() {
mgmtCleanUpSuperTables(); mgmtCleanUpSuperTables();
} }
// todo move to name.h, add length of table name
static void mgmtExtractTableName(char* tableId, char* name) { static void mgmtExtractTableName(char* tableId, char* name) {
int pos = -1; int pos = -1;
int num = 0; int num = 0;
...@@ -1055,7 +1057,7 @@ static int32_t mgmtGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, ...@@ -1055,7 +1057,7 @@ static int32_t mgmtGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow,
int32_t cols = 0; int32_t cols = 0;
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN; pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "name"); strcpy(pSchema[cols].name, "name");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
...@@ -1063,7 +1065,7 @@ static int32_t mgmtGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, ...@@ -1063,7 +1065,7 @@ static int32_t mgmtGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow,
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "create_time"); strcpy(pSchema[cols].name, "created_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
...@@ -1135,7 +1137,12 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v ...@@ -1135,7 +1137,12 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v
cols = 0; cols = 0;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strncpy(pWrite, stableName, TSDB_TABLE_NAME_LEN);
int16_t len = strnlen(stableName, TSDB_DB_NAME_LEN);
*(int16_t*) pWrite = len;
pWrite += sizeof(int16_t); // todo refactor
strncpy(pWrite, stableName, len);
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
...@@ -1232,46 +1239,66 @@ static void mgmtGetSuperTableMeta(SQueuedMsg *pMsg) { ...@@ -1232,46 +1239,66 @@ static void mgmtGetSuperTableMeta(SQueuedMsg *pMsg) {
static void mgmtProcessSuperTableVgroupMsg(SQueuedMsg *pMsg) { static void mgmtProcessSuperTableVgroupMsg(SQueuedMsg *pMsg) {
SCMSTableVgroupMsg *pInfo = pMsg->pCont; SCMSTableVgroupMsg *pInfo = pMsg->pCont;
if (pMsg->pTable == NULL) pMsg->pTable = mgmtGetSuperTable(pInfo->tableId); int32_t numOfTable = htonl(pInfo->numOfTables);
if (pMsg->pTable == NULL) {
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_TABLE);
return;
}
SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable; char* name = (char*) pInfo + sizeof(struct SCMSTableVgroupMsg);
int32_t contLen = sizeof(SCMSTableVgroupRspMsg) + sizeof(SCMVgroupInfo) * pTable->vgLen; SCMSTableVgroupRspMsg *pRsp = NULL;
SCMSTableVgroupRspMsg *pRsp = rpcMallocCont(contLen);
// todo set the initial size to be 10, fix me
int32_t contLen = sizeof(SCMSTableVgroupRspMsg) + (sizeof(SCMVgroupInfo) * 10 + sizeof(SVgroupsInfo))*numOfTable;
pRsp = rpcMallocCont(contLen);
if (pRsp == NULL) { if (pRsp == NULL) {
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SERV_OUT_OF_MEMORY); mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SERV_OUT_OF_MEMORY);
return; return;
} }
pRsp->numOfTables = htonl(numOfTable);
char* msg = (char*) pRsp + sizeof(SCMSTableVgroupRspMsg);
for(int32_t i = 0; i < numOfTable; ++i) {
SSuperTableObj *pTable = mgmtGetSuperTable(name);
pMsg->pTable = (STableObj *)pTable;
if (pMsg->pTable == NULL) {
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_TABLE);
return;
}
SVgroupsInfo* pVgroup = (SVgroupsInfo*) msg;
int32_t vg = 0; int32_t vg = 0;
for (; vg < pTable->vgLen; ++vg) { for (; vg < pTable->vgLen; ++vg) {
int32_t vgId = pTable->vgList[vg]; int32_t vgId = pTable->vgList[vg];
if (vgId == 0) break; if (vgId == 0) break;
SVgObj *pVgroup = mgmtGetVgroup(vgId); SVgObj *vgItem = mgmtGetVgroup(vgId);
if (pVgroup == NULL) break; if (vgItem == NULL) break;
pRsp->vgroups[vg].vgId = htonl(vgId); pVgroup->vgroups[vg].vgId = htonl(vgId);
for (int32_t vn = 0; vn < pVgroup->numOfVnodes; ++vn) { for (int32_t vn = 0; vn < vgItem->numOfVnodes; ++vn) {
SDnodeObj *pDnode = pVgroup->vnodeGid[vn].pDnode; SDnodeObj *pDnode = vgItem->vnodeGid[vn].pDnode;
if (pDnode == NULL) break; if (pDnode == NULL) break;
strcpy(pRsp->vgroups[vg].ipAddr[vn].fqdn, pDnode->dnodeFqdn); strncpy(pVgroup->vgroups[vg].ipAddr[vn].fqdn, pDnode->dnodeFqdn, tListLen(pDnode->dnodeFqdn));
pRsp->vgroups[vg].ipAddr[vn].port = htons(pDnode->dnodePort + TSDB_PORT_DNODESHELL); pVgroup->vgroups[vg].ipAddr[vn].port = htons(tsDnodeShellPort);
pRsp->vgroups[vg].numOfIps++;
pVgroup->vgroups[vg].numOfIps++;
} }
mgmtDecVgroupRef(pVgroup); mgmtDecVgroupRef(vgItem);
}
pVgroup->numOfVgroups = htonl(vg);
// one table is done, try the next table
msg += sizeof(SVgroupsInfo) + vg * sizeof(SCMVgroupInfo);
} }
pRsp->numOfVgroups = htonl(vg);
SRpcMsg rpcRsp = {0}; SRpcMsg rpcRsp = {0};
rpcRsp.handle = pMsg->thandle; rpcRsp.handle = pMsg->thandle;
rpcRsp.pCont = pRsp; rpcRsp.pCont = pRsp;
rpcRsp.contLen = sizeof(SCMSTableVgroupRspMsg) + sizeof(SCMVgroupInfo) * vg; rpcRsp.contLen = msg - (char*) pRsp;
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
} }
...@@ -1988,15 +2015,15 @@ static int32_t mgmtGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void ...@@ -1988,15 +2015,15 @@ static int32_t mgmtGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void
int32_t cols = 0; int32_t cols = 0;
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN; pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "table name"); strcpy(pSchema[cols].name, "table_name");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "create time"); strcpy(pSchema[cols].name, "created_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
...@@ -2006,9 +2033,9 @@ static int32_t mgmtGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void ...@@ -2006,9 +2033,9 @@ static int32_t mgmtGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN; pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "stable name"); strcpy(pSchema[cols].name, "stable_name");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
...@@ -2071,7 +2098,8 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, ...@@ -2071,7 +2098,8 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows,
int32_t cols = 0; int32_t cols = 0;
char *pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; char *pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strncpy(pWrite, tableName, TSDB_TABLE_NAME_LEN);
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tableName, TSDB_TABLE_NAME_LEN);
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
...@@ -2088,9 +2116,13 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, ...@@ -2088,9 +2116,13 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows,
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
memset(tableName, 0, tListLen(tableName));
if (pTable->info.type == TSDB_CHILD_TABLE) { if (pTable->info.type == TSDB_CHILD_TABLE) {
mgmtExtractTableName(pTable->superTable->info.tableId, pWrite); mgmtExtractTableName(pTable->superTable->info.tableId, tableName);
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tableName, TSDB_TABLE_NAME_LEN);
} }
cols++; cols++;
numOfRows++; numOfRows++;
......
...@@ -48,7 +48,8 @@ typedef struct tQueryInfo { ...@@ -48,7 +48,8 @@ typedef struct tQueryInfo {
int32_t colIndex; // index of column in schema int32_t colIndex; // index of column in schema
uint8_t optr; // expression operator uint8_t optr; // expression operator
SSchema sch; // schema of tags SSchema sch; // schema of tags
tVariant q; // query condition value on the specific schema, filter expression // tVariant q; // query condition value on the specific schema, filter expression
char* q;
__compar_fn_t compare; // filter function __compar_fn_t compare; // filter function
} tQueryInfo; } tQueryInfo;
......
...@@ -51,7 +51,7 @@ typedef struct SDiskbasedResultBuf { ...@@ -51,7 +51,7 @@ typedef struct SDiskbasedResultBuf {
* @param rowSize * @param rowSize
* @return * @return
*/ */
int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t size, int32_t rowSize); int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t size, int32_t rowSize, void* handle);
/** /**
* *
...@@ -103,7 +103,7 @@ int32_t getNumOfResultBufGroupId(SDiskbasedResultBuf* pResultBuf); ...@@ -103,7 +103,7 @@ int32_t getNumOfResultBufGroupId(SDiskbasedResultBuf* pResultBuf);
* destroy result buffer * destroy result buffer
* @param pResultBuf * @param pResultBuf
*/ */
void destroyResultBuf(SDiskbasedResultBuf* pResultBuf); void destroyResultBuf(SDiskbasedResultBuf* pResultBuf, void* handle);
/** /**
* *
......
...@@ -60,17 +60,16 @@ enum _sql_type { ...@@ -60,17 +60,16 @@ enum _sql_type {
TSDB_SQL_LOCAL, // SQL below for client local TSDB_SQL_LOCAL, // SQL below for client local
TSDB_SQL_DESCRIBE_TABLE, TSDB_SQL_DESCRIBE_TABLE,
TSDB_SQL_RETRIEVE_METRIC, TSDB_SQL_RETRIEVE_LOCALMERGE,
TSDB_SQL_METRIC_JOIN_RETRIEVE, TSDB_SQL_METRIC_JOIN_RETRIEVE,
TSDB_SQL_RETRIEVE_TAGS,
/* /*
* build empty result instead of accessing dnode to fetch result * build empty result instead of accessing dnode to fetch result
* reset the client cache * reset the client cache
*/ */
TSDB_SQL_RETRIEVE_EMPTY_RESULT, // 40 TSDB_SQL_RETRIEVE_EMPTY_RESULT,
TSDB_SQL_RESET_CACHE, TSDB_SQL_RESET_CACHE, // 40
TSDB_SQL_SERV_STATUS, TSDB_SQL_SERV_STATUS,
TSDB_SQL_CURRENT_DB, TSDB_SQL_CURRENT_DB,
TSDB_SQL_SERV_VERSION, TSDB_SQL_SERV_VERSION,
...@@ -78,7 +77,7 @@ enum _sql_type { ...@@ -78,7 +77,7 @@ enum _sql_type {
TSDB_SQL_CURRENT_USER, TSDB_SQL_CURRENT_USER,
TSDB_SQL_CFG_LOCAL, TSDB_SQL_CFG_LOCAL,
TSDB_SQL_MAX // 48 TSDB_SQL_MAX // 47
}; };
......
...@@ -48,7 +48,7 @@ typedef struct STSElem { ...@@ -48,7 +48,7 @@ typedef struct STSElem {
} STSElem; } STSElem;
typedef struct STSCursor { typedef struct STSCursor {
int32_t vnodeIndex; int32_t vgroupIndex;
int32_t blockIndex; int32_t blockIndex;
int32_t tsIndex; int32_t tsIndex;
uint32_t order; uint32_t order;
......
...@@ -96,24 +96,20 @@ typedef struct SSingleColumnFilterInfo { ...@@ -96,24 +96,20 @@ typedef struct SSingleColumnFilterInfo {
void* pData; void* pData;
} SSingleColumnFilterInfo; } SSingleColumnFilterInfo;
typedef struct STableQueryInfo { typedef struct STableQueryInfo { // todo merge with the STableQueryInfo struct
int64_t lastKey; int32_t tableIndex;
STimeWindow win; int32_t groupIdx; // group id in table list
TSKEY lastKey;
int32_t numOfRes; int32_t numOfRes;
int16_t queryRangeSet; // denote if the query range is set, only available for interval query int16_t queryRangeSet; // denote if the query range is set, only available for interval query
int64_t tag; int64_t tag;
STimeWindow win;
STSCursor cur; STSCursor cur;
int32_t tid; // for retrieve the page id list STableId id; // for retrieve the page id list
SWindowResInfo windowResInfo; SWindowResInfo windowResInfo;
} STableQueryInfo; } STableQueryInfo;
typedef struct STableDataInfo { // todo merge with the STableQueryInfo struct
int32_t tableIndex;
int32_t groupIdx; // group id in table list
STableQueryInfo* pTableQInfo;
} STableDataInfo;
typedef struct SQuery { typedef struct SQuery {
int16_t numOfCols; int16_t numOfCols;
int16_t numOfTags; int16_t numOfTags;
...@@ -130,7 +126,7 @@ typedef struct SQuery { ...@@ -130,7 +126,7 @@ typedef struct SQuery {
SLimitVal limit; SLimitVal limit;
int32_t rowSize; int32_t rowSize;
SSqlGroupbyExpr* pGroupbyExpr; SSqlGroupbyExpr* pGroupbyExpr;
SArithExprInfo* pSelectExpr; SExprInfo* pSelectExpr;
SColumnInfo* colList; SColumnInfo* colList;
SColumnInfo* tagColList; SColumnInfo* tagColList;
int32_t numOfFilterCols; int32_t numOfFilterCols;
...@@ -173,11 +169,13 @@ typedef struct SQInfo { ...@@ -173,11 +169,13 @@ typedef struct SQInfo {
int32_t code; // error code to returned to client int32_t code; // error code to returned to client
sem_t dataReady; sem_t dataReady;
void* tsdb; void* tsdb;
int32_t vgId;
STableGroupInfo groupInfo; // table id list STableGroupInfo tableIdGroupInfo; // table id list < only includes the STableId list>
STableGroupInfo groupInfo; //
SQueryRuntimeEnv runtimeEnv; SQueryRuntimeEnv runtimeEnv;
int32_t groupIndex; int32_t groupIndex;
int32_t offset; /* offset in group result set of subgroup */ int32_t offset; // offset in group result set of subgroup, todo refactor
T_REF_DECLARE() T_REF_DECLARE()
/* /*
...@@ -188,7 +186,6 @@ typedef struct SQInfo { ...@@ -188,7 +186,6 @@ typedef struct SQInfo {
*/ */
int32_t tableIndex; int32_t tableIndex;
int32_t numOfGroupResultPages; int32_t numOfGroupResultPages;
TSKEY* tsList;
} SQInfo; } SQInfo;
#endif // TDENGINE_QUERYEXECUTOR_H #endif // TDENGINE_QUERYEXECUTOR_H
...@@ -31,11 +31,11 @@ extern int32_t qdebugFlag; ...@@ -31,11 +31,11 @@ extern int32_t qdebugFlag;
#define qError(...) \ #define qError(...) \
if (qdebugFlag & DEBUG_ERROR) { \ if (qdebugFlag & DEBUG_ERROR) { \
taosPrintLog("ERROR RPC ", qdebugFlag, __VA_ARGS__); \ taosPrintLog("ERROR QRY ", qdebugFlag, __VA_ARGS__); \
} }
#define qWarn(...) \ #define qWarn(...) \
if (qdebugFlag & DEBUG_WARN) { \ if (qdebugFlag & DEBUG_WARN) { \
taosPrintLog("WARN RPC ", qdebugFlag, __VA_ARGS__); \ taosPrintLog("WARN QRY ", qdebugFlag, __VA_ARGS__); \
} }
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -120,7 +120,7 @@ cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). { ...@@ -120,7 +120,7 @@ cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). {
} }
cmd ::= DROP DATABASE ifexists(Y) ids(X). { setDropDBTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y); } cmd ::= DROP DATABASE ifexists(Y) ids(X). { setDropDBTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y); }
cmd ::= DROP DNODE IPTOKEN(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &X); } cmd ::= DROP DNODE ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &X); }
cmd ::= DROP USER ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_USER, 1, &X); } cmd ::= DROP USER ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_USER, 1, &X); }
cmd ::= DROP ACCOUNT ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &X); } cmd ::= DROP ACCOUNT ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &X); }
...@@ -136,8 +136,8 @@ cmd ::= DESCRIBE ids(X) cpxName(Y). { ...@@ -136,8 +136,8 @@ cmd ::= DESCRIBE ids(X) cpxName(Y). {
/////////////////////////////////THE ALTER STATEMENT//////////////////////////////////////// /////////////////////////////////THE ALTER STATEMENT////////////////////////////////////////
cmd ::= ALTER USER ids(X) PASS ids(Y). { setAlterUserSQL(pInfo, TSDB_ALTER_USER_PASSWD, &X, &Y, NULL); } cmd ::= ALTER USER ids(X) PASS ids(Y). { setAlterUserSQL(pInfo, TSDB_ALTER_USER_PASSWD, &X, &Y, NULL); }
cmd ::= ALTER USER ids(X) PRIVILEGE ids(Y). { setAlterUserSQL(pInfo, TSDB_ALTER_USER_PRIVILEGES, &X, NULL, &Y);} cmd ::= ALTER USER ids(X) PRIVILEGE ids(Y). { setAlterUserSQL(pInfo, TSDB_ALTER_USER_PRIVILEGES, &X, NULL, &Y);}
cmd ::= ALTER DNODE IPTOKEN(X) ids(Y). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_DNODE, 2, &X, &Y); } cmd ::= ALTER DNODE ids(X) ids(Y). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_DNODE, 2, &X, &Y); }
cmd ::= ALTER DNODE IPTOKEN(X) ids(Y) ids(Z). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_DNODE, 3, &X, &Y, &Z); } cmd ::= ALTER DNODE ids(X) ids(Y) ids(Z). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_DNODE, 3, &X, &Y, &Z); }
cmd ::= ALTER LOCAL ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &X); } cmd ::= ALTER LOCAL ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &X); }
cmd ::= ALTER LOCAL ids(X) ids(Y). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &X, &Y); } cmd ::= ALTER LOCAL ids(X) ids(Y). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &X, &Y); }
cmd ::= ALTER DATABASE ids(X) alter_db_optr(Y). { SSQLToken t = {0}; setCreateDBSQL(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);} cmd ::= ALTER DATABASE ids(X) alter_db_optr(Y). { SSQLToken t = {0}; setCreateDBSQL(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);}
...@@ -162,7 +162,7 @@ ifnotexists(X) ::= . {X.n = 0;} ...@@ -162,7 +162,7 @@ ifnotexists(X) ::= . {X.n = 0;}
/////////////////////////////////THE CREATE STATEMENT/////////////////////////////////////// /////////////////////////////////THE CREATE STATEMENT///////////////////////////////////////
//create option for dnode/db/user/account //create option for dnode/db/user/account
cmd ::= CREATE DNODE IPTOKEN(X). { setDCLSQLElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &X);} cmd ::= CREATE DNODE ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &X);}
cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z). cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z).
{ setCreateAcctSQL(pInfo, TSDB_SQL_CREATE_ACCT, &X, &Y, &Z);} { setCreateAcctSQL(pInfo, TSDB_SQL_CREATE_ACCT, &X, &Y, &Z);}
cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDBSQL(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);} cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDBSQL(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);}
......
...@@ -68,16 +68,18 @@ extern "C" { ...@@ -68,16 +68,18 @@ extern "C" {
#define TSDB_FUNC_AVG_RATE 32 #define TSDB_FUNC_AVG_RATE 32
#define TSDB_FUNC_AVG_IRATE 33 #define TSDB_FUNC_AVG_IRATE 33
#define TSDB_FUNCSTATE_SO 0x1U // single output #define TSDB_FUNC_TID_TAG 34
#define TSDB_FUNCSTATE_MO 0x2U // dynamic number of output, not multinumber of output e.g., TOP/BOTTOM
#define TSDB_FUNCSTATE_STREAM 0x4U // function avail for stream
#define TSDB_FUNCSTATE_METRIC 0x8U // function avail for metric
#define TSDB_FUNCSTATE_OF 0x10U // outer forward
#define TSDB_FUNCSTATE_NEED_TS 0x20U // timestamp is required during query processing
#define TSDB_FUNCSTATE_SELECTIVITY 0x40U // selectivity functions, can exists along with tag columns
#define TSDB_BASE_FUNC_SO TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_STREAM | TSDB_FUNCSTATE_METRIC | TSDB_FUNCSTATE_OF #define TSDB_FUNCSTATE_SO 0x1u // single output
#define TSDB_BASE_FUNC_MO TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STREAM | TSDB_FUNCSTATE_METRIC | TSDB_FUNCSTATE_OF #define TSDB_FUNCSTATE_MO 0x2u // dynamic number of output, not multinumber of output e.g., TOP/BOTTOM
#define TSDB_FUNCSTATE_STREAM 0x4u // function avail for stream
#define TSDB_FUNCSTATE_STABLE 0x8u // function avail for metric
#define TSDB_FUNCSTATE_OF 0x10u // outer forward
#define TSDB_FUNCSTATE_NEED_TS 0x20u // timestamp is required during query processing
#define TSDB_FUNCSTATE_SELECTIVITY 0x40u // selectivity functions, can exists along with tag columns
#define TSDB_BASE_FUNC_SO TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_STREAM | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_OF
#define TSDB_BASE_FUNC_MO TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STREAM | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_OF
#define TSDB_FUNCTIONS_NAME_MAX_LENGTH 16 #define TSDB_FUNCTIONS_NAME_MAX_LENGTH 16
...@@ -109,14 +111,14 @@ enum { ...@@ -109,14 +111,14 @@ enum {
}; };
#define QUERY_IS_STABLE_QUERY(type) (((type)&TSDB_QUERY_TYPE_STABLE_QUERY) != 0) #define QUERY_IS_STABLE_QUERY(type) (((type)&TSDB_QUERY_TYPE_STABLE_QUERY) != 0)
#define QUERY_IS_JOIN_QUERY(type) (((type)&TSDB_QUERY_TYPE_JOIN_QUERY) != 0) #define QUERY_IS_JOIN_QUERY(type) (TSDB_QUERY_HAS_TYPE(type, TSDB_QUERY_TYPE_JOIN_QUERY))
#define QUERY_IS_PROJECTION_QUERY(type) (((type)&TSDB_QUERY_TYPE_PROJECTION_QUERY) != 0) #define QUERY_IS_PROJECTION_QUERY(type) (((type)&TSDB_QUERY_TYPE_PROJECTION_QUERY) != 0)
#define QUERY_IS_FREE_RESOURCE(type) (((type)&TSDB_QUERY_TYPE_FREE_RESOURCE) != 0) #define QUERY_IS_FREE_RESOURCE(type) (((type)&TSDB_QUERY_TYPE_FREE_RESOURCE) != 0)
typedef struct SArithmeticSupport { typedef struct SArithmeticSupport {
SArithExprInfo *pArithExpr; SExprInfo *pArithExpr;
int32_t numOfCols; int32_t numOfCols;
SColumnInfo* colList; SColumnInfo *colList;
int32_t offset; int32_t offset;
char** data; char** data;
} SArithmeticSupport; } SArithmeticSupport;
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
* *
* @date 2018-2-15 * @date 2018-2-15
* @version 0.2 operation for column filter * @version 0.2 operation for column filter
* @author liaohj
* *
* @Description parse tag query expression to build ast * @Description parse tag query expression to build ast
* ver 0.2, filter the result on first column with high priority to limit the candidate set * ver 0.2, filter the result on first column with high priority to limit the candidate set
...@@ -468,7 +467,7 @@ void tExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) { ...@@ -468,7 +467,7 @@ void tExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
} }
typedef struct { typedef struct {
tVariant v; char* v;
int32_t optr; int32_t optr;
} SEndPoint; } SEndPoint;
...@@ -521,21 +520,19 @@ static int32_t setQueryCond(tQueryInfo *queryColInfo, SQueryCond* pCond) { ...@@ -521,21 +520,19 @@ static int32_t setQueryCond(tQueryInfo *queryColInfo, SQueryCond* pCond) {
if (optr == TSDB_RELATION_GREATER || optr == TSDB_RELATION_GREATER_EQUAL || if (optr == TSDB_RELATION_GREATER || optr == TSDB_RELATION_GREATER_EQUAL ||
optr == TSDB_RELATION_EQUAL || optr == TSDB_RELATION_NOT_EQUAL) { optr == TSDB_RELATION_EQUAL || optr == TSDB_RELATION_NOT_EQUAL) {
pCond->start = calloc(1, sizeof(tVariant)); pCond->start = calloc(1, sizeof(SEndPoint));
tVariantAssign(&pCond->start->v, &queryColInfo->q);
pCond->start->optr = queryColInfo->optr; pCond->start->optr = queryColInfo->optr;
pCond->start->v = queryColInfo->q;
} else if (optr == TSDB_RELATION_LESS || optr == TSDB_RELATION_LESS_EQUAL) { } else if (optr == TSDB_RELATION_LESS || optr == TSDB_RELATION_LESS_EQUAL) {
pCond->end = calloc(1, sizeof(tVariant)); pCond->end = calloc(1, sizeof(SEndPoint));
tVariantAssign(&pCond->end->v, &queryColInfo->q);
pCond->end->optr = queryColInfo->optr; pCond->end->optr = queryColInfo->optr;
pCond->end->v = queryColInfo->q;
} else if (optr == TSDB_RELATION_IN) { } else if (optr == TSDB_RELATION_IN) {
printf("relation is in\n"); printf("relation is in\n");
assert(0);
} else if (optr == TSDB_RELATION_LIKE) { } else if (optr == TSDB_RELATION_LIKE) {
printf("relation is like\n"); printf("relation is like\n");
assert(0);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -543,18 +540,16 @@ static int32_t setQueryCond(tQueryInfo *queryColInfo, SQueryCond* pCond) { ...@@ -543,18 +540,16 @@ static int32_t setQueryCond(tQueryInfo *queryColInfo, SQueryCond* pCond) {
static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArray* result) { static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArray* result) {
SSkipListIterator* iter = NULL; SSkipListIterator* iter = NULL;
int32_t type = pQueryInfo->q.nType; SQueryCond cond = {0};
SQueryCond cond = { 0 };
setQueryCond(pQueryInfo, &cond); setQueryCond(pQueryInfo, &cond);
if (cond.start != NULL) { if (cond.start != NULL) {
iter = tSkipListCreateIterFromVal(pSkipList, (char*) &cond.start->v.i64Key, type, TSDB_ORDER_ASC); iter = tSkipListCreateIterFromVal(pSkipList, (char*) &cond.start->v, pSkipList->keyInfo.type, TSDB_ORDER_ASC);
} else { } else {
iter = tSkipListCreateIterFromVal(pSkipList, (char*) &cond.end->v.i64Key, type, TSDB_ORDER_DESC); iter = tSkipListCreateIterFromVal(pSkipList, (char*) &cond.end->v, pSkipList->keyInfo.type, TSDB_ORDER_DESC);
} }
__compar_fn_t func = getComparFunc(pSkipList->keyInfo.type, type, 0); __compar_fn_t func = getKeyComparFunc(pSkipList->keyInfo.type);
if (cond.start != NULL) { if (cond.start != NULL) {
int32_t optr = cond.start->optr; int32_t optr = cond.start->optr;
...@@ -563,7 +558,7 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr ...@@ -563,7 +558,7 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr
while(tSkipListIterNext(iter)) { while(tSkipListIterNext(iter)) {
SSkipListNode* pNode = tSkipListIterGet(iter); SSkipListNode* pNode = tSkipListIterGet(iter);
int32_t ret = func(SL_GET_NODE_KEY(pSkipList, pNode), &cond.start->v.i64Key); int32_t ret = func(SL_GET_NODE_KEY(pSkipList, pNode), cond.start->v);
if (ret == 0) { if (ret == 0) {
taosArrayPush(result, SL_GET_NODE_DATA(pNode)); taosArrayPush(result, SL_GET_NODE_DATA(pNode));
} else { } else {
...@@ -578,7 +573,7 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr ...@@ -578,7 +573,7 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr
SSkipListNode* pNode = tSkipListIterGet(iter); SSkipListNode* pNode = tSkipListIterGet(iter);
if (comp) { if (comp) {
ret = func(SL_GET_NODE_KEY(pSkipList, pNode), &cond.start->v.i64Key); ret = func(SL_GET_NODE_KEY(pSkipList, pNode), cond.start->v);
assert(ret >= 0); assert(ret >= 0);
} }
...@@ -605,7 +600,7 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr ...@@ -605,7 +600,7 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr
SSkipListNode* pNode = tSkipListIterGet(iter); SSkipListNode* pNode = tSkipListIterGet(iter);
if (comp) { if (comp) {
ret = func(SL_GET_NODE_KEY(pSkipList, pNode), &cond.end->v.i64Key); ret = func(SL_GET_NODE_KEY(pSkipList, pNode), cond.end->v);
assert(ret <= 0); assert(ret <= 0);
} }
...@@ -699,21 +694,18 @@ int32_t intersect(SArray *pLeft, SArray *pRight, SArray *pFinalRes) { ...@@ -699,21 +694,18 @@ int32_t intersect(SArray *pLeft, SArray *pRight, SArray *pFinalRes) {
/* /*
* traverse the result and apply the function to each item to check if the item is qualified or not * traverse the result and apply the function to each item to check if the item is qualified or not
*/ */
static UNUSED_FUNC void tSQLListTraverseOnResult(struct tExprNode *pExpr, __result_filter_fn_t fp, SArray *pResult) { static void tArrayTraverse(tExprNode *pExpr, __result_filter_fn_t fp, SArray *pResult) {
// assert(pExpr->_node.pLeft->nodeType == TSQL_NODE_COL && pExpr->_node.pRight->nodeType == TSQL_NODE_VALUE); assert(pExpr->_node.pLeft->nodeType == TSQL_NODE_COL && pExpr->_node.pRight->nodeType == TSQL_NODE_VALUE && fp != NULL);
//
// // brutal force scan the result list and check for each item in the list // scan the result array list and check for each item in the list
// int64_t num = pResult->num; for (int32_t i = 0; i < taosArrayGetSize(pResult); ++i) {
// for (int32_t i = 0, j = 0; i < pResult->num; ++i) { void* item = taosArrayGet(pResult, i);
// if (fp == NULL || (fp(pResult->pRes[i], pExpr->_node.info) == true)) { if (fp(item, pExpr->_node.info)) {
// pResult->pRes[j++] = pResult->pRes[i]; i++;
// } else { } else {
// num--; taosArrayRemove(pResult, i);
// } }
// } }
//
// pResult->num = num;
assert(0);
} }
static bool filterItem(tExprNode *pExpr, const void *pItem, SBinaryFilterSupp *param) { static bool filterItem(tExprNode *pExpr, const void *pItem, SBinaryFilterSupp *param) {
...@@ -771,12 +763,7 @@ static void exprTreeTraverseImpl(tExprNode *pExpr, SArray *pResult, SBinaryFilte ...@@ -771,12 +763,7 @@ static void exprTreeTraverseImpl(tExprNode *pExpr, SArray *pResult, SBinaryFilte
} }
static void tSQLBinaryTraverseOnSkipList( static void tSQLBinaryTraverseOnSkipList(tExprNode *pExpr, SArray *pResult, SSkipList *pSkipList, SBinaryFilterSupp *param ) {
tExprNode *pExpr,
SArray *pResult,
SSkipList *pSkipList,
SBinaryFilterSupp *param
) {
SSkipListIterator* iter = tSkipListCreateIter(pSkipList); SSkipListIterator* iter = tSkipListCreateIter(pSkipList);
while (tSkipListIterNext(iter)) { while (tSkipListIterNext(iter)) {
...@@ -797,20 +784,26 @@ static void tQueryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, ...@@ -797,20 +784,26 @@ static void tQueryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo,
bool addToResult = false; bool addToResult = false;
SSkipListNode *pNode = tSkipListIterGet(iter); SSkipListNode *pNode = tSkipListIterGet(iter);
STable* table = *(STable**) SL_GET_NODE_DATA(pNode); char* pTable = SL_GET_NODE_DATA(pNode);
//todo refactor:
char* name = (*(STable**) pTable)->name;
// char* name = NULL;
// tsdbGetTableName(tsdb, pTable, &name);
// todo speed up by using hash
if (pQueryInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) { if (pQueryInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) {
if (pQueryInfo->optr == TSDB_RELATION_IN) { if (pQueryInfo->optr == TSDB_RELATION_IN) {
addToResult = pQueryInfo->compare(table->name, pQueryInfo->q.arr); addToResult = pQueryInfo->compare(name, pQueryInfo->q);
} else if(pQueryInfo->optr == TSDB_RELATION_LIKE) { } else if(pQueryInfo->optr == TSDB_RELATION_LIKE) {
addToResult = !pQueryInfo->compare(table->name, pQueryInfo->q.pz); addToResult = !pQueryInfo->compare(name, pQueryInfo->q);
} }
} else { } else {
// TODO: other columns // TODO: other columns
} }
if (addToResult) { if (addToResult) {
taosArrayPush(result, (void*)&table); taosArrayPush(result, pTable);
} }
} }
...@@ -834,7 +827,7 @@ void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, S ...@@ -834,7 +827,7 @@ void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, S
param->setupInfoFn(pExpr, param->pExtInfo); param->setupInfoFn(pExpr, param->pExtInfo);
if (pSkipList == NULL) { if (pSkipList == NULL) {
tSQLListTraverseOnResult(pExpr, param->fp, result); tArrayTraverse(pExpr, param->fp, result);
return; return;
} }
...@@ -920,7 +913,6 @@ void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, S ...@@ -920,7 +913,6 @@ void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, S
tExprTreeTraverse(pSecond, NULL, result, param); tExprTreeTraverse(pSecond, NULL, result, param);
} }
void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order, void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
char *(*getSourceDataBlock)(void *, const char*, int32_t)) { char *(*getSourceDataBlock)(void *, const char*, int32_t)) {
if (pExprs == NULL) { if (pExprs == NULL) {
......
...@@ -409,13 +409,21 @@ static FORCE_INLINE int32_t columnValueAscendingComparator(char *f1, char *f2, i ...@@ -409,13 +409,21 @@ static FORCE_INLINE int32_t columnValueAscendingComparator(char *f1, char *f2, i
return (first < second) ? -1 : 1; return (first < second) ? -1 : 1;
}; };
case TSDB_DATA_TYPE_BINARY: { case TSDB_DATA_TYPE_BINARY: {
int32_t ret = strncmp(f1, f2, bytes); int32_t len1 = varDataLen(f1);
int32_t len2 = varDataLen(f2);
if (len1 != len2) {
return len1 > len2? 1:-1;
} else {
int32_t ret = strncmp(varDataVal(f1), varDataVal(f2), len1);
if (ret == 0) { if (ret == 0) {
return 0; return 0;
} }
return (ret < 0) ? -1 : 1; return (ret < 0) ? -1 : 1;
}
}; };
case TSDB_DATA_TYPE_NCHAR: { case TSDB_DATA_TYPE_NCHAR: { // todo handle the var string compare
int32_t ret = tasoUcs4Compare(f1, f2, bytes); int32_t ret = tasoUcs4Compare(f1, f2, bytes);
if (ret == 0) { if (ret == 0) {
return 0; return 0;
......
...@@ -463,7 +463,8 @@ int32_t getTimestampInUsFromStrImpl(int64_t val, char unit, int64_t *result) { ...@@ -463,7 +463,8 @@ int32_t getTimestampInUsFromStrImpl(int64_t val, char unit, int64_t *result) {
void tSQLSetColumnInfo(TAOS_FIELD *pField, SSQLToken *pName, TAOS_FIELD *pType) { void tSQLSetColumnInfo(TAOS_FIELD *pField, SSQLToken *pName, TAOS_FIELD *pType) {
int32_t maxLen = sizeof(pField->name) / sizeof(pField->name[0]); int32_t maxLen = sizeof(pField->name) / sizeof(pField->name[0]);
/* truncate the column name */
// truncate the column name
if (pName->n >= maxLen) { if (pName->n >= maxLen) {
pName->n = maxLen - 1; pName->n = maxLen - 1;
} }
...@@ -478,7 +479,9 @@ void tSQLSetColumnInfo(TAOS_FIELD *pField, SSQLToken *pName, TAOS_FIELD *pType) ...@@ -478,7 +479,9 @@ void tSQLSetColumnInfo(TAOS_FIELD *pField, SSQLToken *pName, TAOS_FIELD *pType)
void tSQLSetColumnType(TAOS_FIELD *pField, SSQLToken *type) { void tSQLSetColumnType(TAOS_FIELD *pField, SSQLToken *type) {
pField->type = -1; pField->type = -1;
for (int8_t i = 0; i < sizeof(tDataTypeDesc) / sizeof(tDataTypeDesc[0]); ++i) { int32_t LENGTH_SIZE_OF_STR = 2; // in case of nchar and binary, there two bytes to keep the length of binary|nchar.
for (int8_t i = 0; i < tListLen(tDataTypeDesc); ++i) {
if ((strncasecmp(type->z, tDataTypeDesc[i].aName, tDataTypeDesc[i].nameLen) == 0) && if ((strncasecmp(type->z, tDataTypeDesc[i].aName, tDataTypeDesc[i].nameLen) == 0) &&
(type->n == tDataTypeDesc[i].nameLen)) { (type->n == tDataTypeDesc[i].nameLen)) {
pField->type = i; pField->type = i;
...@@ -490,10 +493,10 @@ void tSQLSetColumnType(TAOS_FIELD *pField, SSQLToken *type) { ...@@ -490,10 +493,10 @@ void tSQLSetColumnType(TAOS_FIELD *pField, SSQLToken *type) {
* number of bytes in UCS-4 format, which is 4 times larger than the * number of bytes in UCS-4 format, which is 4 times larger than the
* number of characters * number of characters
*/ */
pField->bytes = -(int32_t)type->type * TSDB_NCHAR_SIZE; pField->bytes = -(int32_t)type->type * TSDB_NCHAR_SIZE + LENGTH_SIZE_OF_STR;
} else if (i == TSDB_DATA_TYPE_BINARY) { } else if (i == TSDB_DATA_TYPE_BINARY) {
/* for binary, the TOKENTYPE is the length of binary */ /* for binary, the TOKENTYPE is the length of binary */
pField->bytes = -(int32_t)type->type; pField->bytes = -(int32_t) type->type + LENGTH_SIZE_OF_STR;
} }
break; break;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#define DEFAULT_INTERN_BUF_SIZE 16384L #define DEFAULT_INTERN_BUF_SIZE 16384L
int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t size, int32_t rowSize) { int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t size, int32_t rowSize, void* handle) {
SDiskbasedResultBuf* pResBuf = calloc(1, sizeof(SDiskbasedResultBuf)); SDiskbasedResultBuf* pResBuf = calloc(1, sizeof(SDiskbasedResultBuf));
pResBuf->numOfRowsPerPage = (DEFAULT_INTERN_BUF_SIZE - sizeof(tFilePage)) / rowSize; pResBuf->numOfRowsPerPage = (DEFAULT_INTERN_BUF_SIZE - sizeof(tFilePage)) / rowSize;
pResBuf->numOfPages = size; pResBuf->numOfPages = size;
...@@ -41,11 +41,13 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t si ...@@ -41,11 +41,13 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t si
pResBuf->pBuf = mmap(NULL, pResBuf->totalBufSize, PROT_READ | PROT_WRITE, MAP_SHARED, pResBuf->fd, 0); pResBuf->pBuf = mmap(NULL, pResBuf->totalBufSize, PROT_READ | PROT_WRITE, MAP_SHARED, pResBuf->fd, 0);
if (pResBuf->pBuf == MAP_FAILED) { if (pResBuf->pBuf == MAP_FAILED) {
qError("QInfo:%p failed to map temp file: %s. %s", pResBuf->path, strerror(errno)); qError("QInfo:%p failed to map temp file: %s. %s", handle, pResBuf->path, strerror(errno));
return TSDB_CODE_CLI_OUT_OF_MEMORY; // todo change error code return TSDB_CODE_CLI_OUT_OF_MEMORY; // todo change error code
} }
qTrace("create tmp file for output result, %s, " PRId64 "bytes", pResBuf->path, pResBuf->totalBufSize); qTrace("QInfo:%p create tmp file for output result, %s, %" PRId64 "bytes", handle, pResBuf->path,
pResBuf->totalBufSize);
*pResultBuf = pResBuf; *pResultBuf = pResBuf;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -189,7 +191,7 @@ SIDList getDataBufPagesIdList(SDiskbasedResultBuf* pResultBuf, int32_t groupId) ...@@ -189,7 +191,7 @@ SIDList getDataBufPagesIdList(SDiskbasedResultBuf* pResultBuf, int32_t groupId)
} }
} }
void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) { void destroyResultBuf(SDiskbasedResultBuf* pResultBuf, void* handle) {
if (pResultBuf == NULL) { if (pResultBuf == NULL) {
return; return;
} }
...@@ -198,7 +200,7 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) { ...@@ -198,7 +200,7 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) {
close(pResultBuf->fd); close(pResultBuf->fd);
} }
qTrace("disk-based output buffer closed, %" PRId64 " bytes, file:%s", pResultBuf->totalBufSize, pResultBuf->path); qTrace("QInfo:%p disk-based output buffer closed, %" PRId64 " bytes, file:%s", handle, pResultBuf->totalBufSize, pResultBuf->path);
munmap(pResultBuf->pBuf, pResultBuf->totalBufSize); munmap(pResultBuf->pBuf, pResultBuf->totalBufSize);
unlink(pResultBuf->path); unlink(pResultBuf->path);
......
...@@ -482,7 +482,7 @@ static void tsBufGetBlock(STSBuf* pTSBuf, int32_t vnodeIndex, int32_t blockIndex ...@@ -482,7 +482,7 @@ static void tsBufGetBlock(STSBuf* pTSBuf, int32_t vnodeIndex, int32_t blockIndex
} }
STSCursor* pCur = &pTSBuf->cur; STSCursor* pCur = &pTSBuf->cur;
if (pCur->vnodeIndex == vnodeIndex && ((pCur->blockIndex <= blockIndex && pCur->order == TSDB_ORDER_ASC) || if (pCur->vgroupIndex == vnodeIndex && ((pCur->blockIndex <= blockIndex && pCur->order == TSDB_ORDER_ASC) ||
(pCur->blockIndex >= blockIndex && pCur->order == TSDB_ORDER_DESC))) { (pCur->blockIndex >= blockIndex && pCur->order == TSDB_ORDER_DESC))) {
int32_t i = 0; int32_t i = 0;
bool decomp = false; bool decomp = false;
...@@ -517,7 +517,7 @@ static void tsBufGetBlock(STSBuf* pTSBuf, int32_t vnodeIndex, int32_t blockIndex ...@@ -517,7 +517,7 @@ static void tsBufGetBlock(STSBuf* pTSBuf, int32_t vnodeIndex, int32_t blockIndex
assert((pTSBuf->tsData.len / TSDB_KEYSIZE == pBlock->numOfElem) && (pTSBuf->tsData.allocSize >= pTSBuf->tsData.len)); assert((pTSBuf->tsData.len / TSDB_KEYSIZE == pBlock->numOfElem) && (pTSBuf->tsData.allocSize >= pTSBuf->tsData.len));
pCur->vnodeIndex = vnodeIndex; pCur->vgroupIndex = vnodeIndex;
pCur->blockIndex = blockIndex; pCur->blockIndex = blockIndex;
pCur->tsIndex = (pCur->order == TSDB_ORDER_ASC) ? 0 : pBlock->numOfElem - 1; pCur->tsIndex = (pCur->order == TSDB_ORDER_ASC) ? 0 : pBlock->numOfElem - 1;
...@@ -554,7 +554,7 @@ bool tsBufNextPos(STSBuf* pTSBuf) { ...@@ -554,7 +554,7 @@ bool tsBufNextPos(STSBuf* pTSBuf) {
STSCursor* pCur = &pTSBuf->cur; STSCursor* pCur = &pTSBuf->cur;
// get the first/last position according to traverse order // get the first/last position according to traverse order
if (pCur->vnodeIndex == -1) { if (pCur->vgroupIndex == -1) {
if (pCur->order == TSDB_ORDER_ASC) { if (pCur->order == TSDB_ORDER_ASC) {
tsBufGetBlock(pTSBuf, 0, 0); tsBufGetBlock(pTSBuf, 0, 0);
...@@ -569,9 +569,9 @@ bool tsBufNextPos(STSBuf* pTSBuf) { ...@@ -569,9 +569,9 @@ bool tsBufNextPos(STSBuf* pTSBuf) {
assert(pTSBuf->numOfVnodes > 0); assert(pTSBuf->numOfVnodes > 0);
int32_t vnodeIndex = pTSBuf->numOfVnodes - 1; int32_t vnodeIndex = pTSBuf->numOfVnodes - 1;
pCur->vnodeIndex = vnodeIndex; pCur->vgroupIndex = vnodeIndex;
int32_t vnodeId = pTSBuf->pData[pCur->vnodeIndex].info.vnode; int32_t vnodeId = pTSBuf->pData[pCur->vgroupIndex].info.vnode;
STSVnodeBlockInfo* pBlockInfo = tsBufGetVnodeBlockInfo(pTSBuf, vnodeId); STSVnodeBlockInfo* pBlockInfo = tsBufGetVnodeBlockInfo(pTSBuf, vnodeId);
int32_t blockIndex = pBlockInfo->numOfBlocks - 1; int32_t blockIndex = pBlockInfo->numOfBlocks - 1;
...@@ -594,14 +594,14 @@ bool tsBufNextPos(STSBuf* pTSBuf) { ...@@ -594,14 +594,14 @@ bool tsBufNextPos(STSBuf* pTSBuf) {
if ((pCur->order == TSDB_ORDER_ASC && pCur->tsIndex >= pTSBuf->block.numOfElem - 1) || if ((pCur->order == TSDB_ORDER_ASC && pCur->tsIndex >= pTSBuf->block.numOfElem - 1) ||
(pCur->order == TSDB_ORDER_DESC && pCur->tsIndex <= 0)) { (pCur->order == TSDB_ORDER_DESC && pCur->tsIndex <= 0)) {
int32_t vnodeId = pTSBuf->pData[pCur->vnodeIndex].info.vnode; int32_t vnodeId = pTSBuf->pData[pCur->vgroupIndex].info.vnode;
STSVnodeBlockInfo* pBlockInfo = tsBufGetVnodeBlockInfo(pTSBuf, vnodeId); STSVnodeBlockInfo* pBlockInfo = tsBufGetVnodeBlockInfo(pTSBuf, vnodeId);
if (pBlockInfo == NULL || (pCur->blockIndex >= pBlockInfo->numOfBlocks - 1 && pCur->order == TSDB_ORDER_ASC) || if (pBlockInfo == NULL || (pCur->blockIndex >= pBlockInfo->numOfBlocks - 1 && pCur->order == TSDB_ORDER_ASC) ||
(pCur->blockIndex <= 0 && pCur->order == TSDB_ORDER_DESC)) { (pCur->blockIndex <= 0 && pCur->order == TSDB_ORDER_DESC)) {
if ((pCur->vnodeIndex >= pTSBuf->numOfVnodes - 1 && pCur->order == TSDB_ORDER_ASC) || if ((pCur->vgroupIndex >= pTSBuf->numOfVnodes - 1 && pCur->order == TSDB_ORDER_ASC) ||
(pCur->vnodeIndex <= 0 && pCur->order == TSDB_ORDER_DESC)) { (pCur->vgroupIndex <= 0 && pCur->order == TSDB_ORDER_DESC)) {
pCur->vnodeIndex = -1; pCur->vgroupIndex = -1;
return false; return false;
} }
...@@ -610,11 +610,11 @@ bool tsBufNextPos(STSBuf* pTSBuf) { ...@@ -610,11 +610,11 @@ bool tsBufNextPos(STSBuf* pTSBuf) {
} }
int32_t blockIndex = pCur->order == TSDB_ORDER_ASC ? 0 : pBlockInfo->numOfBlocks - 1; int32_t blockIndex = pCur->order == TSDB_ORDER_ASC ? 0 : pBlockInfo->numOfBlocks - 1;
tsBufGetBlock(pTSBuf, pCur->vnodeIndex + step, blockIndex); tsBufGetBlock(pTSBuf, pCur->vgroupIndex + step, blockIndex);
break; break;
} else { } else {
tsBufGetBlock(pTSBuf, pCur->vnodeIndex, pCur->blockIndex + step); tsBufGetBlock(pTSBuf, pCur->vgroupIndex, pCur->blockIndex + step);
break; break;
} }
} else { } else {
...@@ -631,7 +631,7 @@ void tsBufResetPos(STSBuf* pTSBuf) { ...@@ -631,7 +631,7 @@ void tsBufResetPos(STSBuf* pTSBuf) {
return; return;
} }
pTSBuf->cur = (STSCursor){.tsIndex = -1, .blockIndex = -1, .vnodeIndex = -1, .order = pTSBuf->cur.order}; pTSBuf->cur = (STSCursor){.tsIndex = -1, .blockIndex = -1, .vgroupIndex = -1, .order = pTSBuf->cur.order};
} }
STSElem tsBufGetElem(STSBuf* pTSBuf) { STSElem tsBufGetElem(STSBuf* pTSBuf) {
...@@ -642,13 +642,13 @@ STSElem tsBufGetElem(STSBuf* pTSBuf) { ...@@ -642,13 +642,13 @@ STSElem tsBufGetElem(STSBuf* pTSBuf) {
} }
STSCursor* pCur = &pTSBuf->cur; STSCursor* pCur = &pTSBuf->cur;
if (pCur != NULL && pCur->vnodeIndex < 0) { if (pCur != NULL && pCur->vgroupIndex < 0) {
return elem1; return elem1;
} }
STSBlock* pBlock = &pTSBuf->block; STSBlock* pBlock = &pTSBuf->block;
elem1.vnode = pTSBuf->pData[pCur->vnodeIndex].info.vnode; elem1.vnode = pTSBuf->pData[pCur->vgroupIndex].info.vnode;
elem1.ts = *(TSKEY*)(pTSBuf->tsData.rawBuf + pCur->tsIndex * TSDB_KEYSIZE); elem1.ts = *(TSKEY*)(pTSBuf->tsData.rawBuf + pCur->tsIndex * TSDB_KEYSIZE);
elem1.tag = pBlock->tag; elem1.tag = pBlock->tag;
...@@ -804,7 +804,7 @@ STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t vnodeId, int64_t tag) { ...@@ -804,7 +804,7 @@ STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t vnodeId, int64_t tag) {
return elem; return elem;
} }
pCur->vnodeIndex = j; pCur->vgroupIndex = j;
pCur->blockIndex = blockIndex; pCur->blockIndex = blockIndex;
tsBufGetBlock(pTSBuf, j, blockIndex); tsBufGetBlock(pTSBuf, j, blockIndex);
...@@ -812,7 +812,7 @@ STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t vnodeId, int64_t tag) { ...@@ -812,7 +812,7 @@ STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t vnodeId, int64_t tag) {
} }
STSCursor tsBufGetCursor(STSBuf* pTSBuf) { STSCursor tsBufGetCursor(STSBuf* pTSBuf) {
STSCursor c = {.vnodeIndex = -1}; STSCursor c = {.vgroupIndex = -1};
if (pTSBuf == NULL) { if (pTSBuf == NULL) {
return c; return c;
} }
...@@ -825,9 +825,9 @@ void tsBufSetCursor(STSBuf* pTSBuf, STSCursor* pCur) { ...@@ -825,9 +825,9 @@ void tsBufSetCursor(STSBuf* pTSBuf, STSCursor* pCur) {
return; return;
} }
// assert(pCur->vnodeIndex != -1 && pCur->tsIndex >= 0 && pCur->blockIndex >= 0); // assert(pCur->vgroupIndex != -1 && pCur->tsIndex >= 0 && pCur->blockIndex >= 0);
if (pCur->vnodeIndex != -1) { if (pCur->vgroupIndex != -1) {
tsBufGetBlock(pTSBuf, pCur->vnodeIndex, pCur->blockIndex); tsBufGetBlock(pTSBuf, pCur->vgroupIndex, pCur->blockIndex);
} }
pTSBuf->cur = *pCur; pTSBuf->cur = *pCur;
......
...@@ -25,9 +25,9 @@ ...@@ -25,9 +25,9 @@
#include "taosmsg.h" #include "taosmsg.h"
#include "tlosertree.h" #include "tlosertree.h"
#include "tscompression.h" #include "tscompression.h"
#include "tsdbMain.h" //todo use TableId instead of STable object
#include "ttime.h" #include "ttime.h"
#include "tscUtil.h" // todo move the function to common module #include "tscUtil.h" // todo move the function to common module
#include "tdataformat.h"
#define DEFAULT_INTERN_BUF_SIZE 16384L #define DEFAULT_INTERN_BUF_SIZE 16384L
...@@ -35,8 +35,6 @@ ...@@ -35,8 +35,6 @@
* check if the primary column is load by default, otherwise, the program will * check if the primary column is load by default, otherwise, the program will
* forced to load primary column explicitly. * forced to load primary column explicitly.
*/ */
#define PRIMARY_TSCOL_LOADED(query) ((query)->colList[0].data.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX)
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0) #define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0)
#define TSDB_COL_IS_TAG(f) (((f)&TSDB_COL_TAG) != 0) #define TSDB_COL_IS_TAG(f) (((f)&TSDB_COL_TAG) != 0)
#define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP) #define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP)
...@@ -58,8 +56,8 @@ ...@@ -58,8 +56,8 @@
typedef struct SPointInterpoSupporter { typedef struct SPointInterpoSupporter {
int32_t numOfCols; int32_t numOfCols;
char ** pPrevPoint; SArray* prev;
char ** pNextPoint; SArray* next;
} SPointInterpoSupporter; } SPointInterpoSupporter;
typedef enum { typedef enum {
...@@ -98,12 +96,18 @@ typedef struct { ...@@ -98,12 +96,18 @@ typedef struct {
STSCursor cur; STSCursor cur;
} SQueryStatusInfo; } SQueryStatusInfo;
typedef struct SGroupItem {
STableId id;
STableQueryInfo* info;
} SGroupItem;
static void setQueryStatus(SQuery *pQuery, int8_t status); static void setQueryStatus(SQuery *pQuery, int8_t status);
bool isIntervalQuery(SQuery *pQuery) { return pQuery->intervalTime > 0; } static bool isIntervalQuery(SQuery *pQuery) { return pQuery->intervalTime > 0; }
// todo move to utility
static int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *group); static int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *group);
static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pResult);
static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pResult);
static void resetMergeResultBuf(SQuery *pQuery, SQLFunctionCtx *pCtx, SResultInfo *pResultInfo); static void resetMergeResultBuf(SQuery *pQuery, SQLFunctionCtx *pCtx, SResultInfo *pResultInfo);
static bool functionNeedToExecute(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx *pCtx, int32_t functionId); static bool functionNeedToExecute(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx *pCtx, int32_t functionId);
static void getNextTimeWindow(SQuery *pQuery, STimeWindow *pTimeWindow); static void getNextTimeWindow(SQuery *pQuery, STimeWindow *pTimeWindow);
...@@ -114,9 +118,10 @@ static void initCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv); ...@@ -114,9 +118,10 @@ static void initCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv);
static void destroyTableQueryInfo(STableQueryInfo *pTableQueryInfo, int32_t numOfCols); static void destroyTableQueryInfo(STableQueryInfo *pTableQueryInfo, int32_t numOfCols);
static void resetCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv); static void resetCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv);
static bool hasMainOutput(SQuery *pQuery); static bool hasMainOutput(SQuery *pQuery);
static void createTableDataInfo(SQInfo *pQInfo); static void createTableQueryInfo(SQInfo *pQInfo);
static void buildTagQueryResult(SQInfo *pQInfo);
static int32_t setAdditionalInfo(SQInfo *pQInfo, STable *pTable, STableQueryInfo *pTableQueryInfo); static int32_t setAdditionalInfo(SQInfo *pQInfo, STableId *pTaleId, STableQueryInfo *pTableQueryInfo);
static int32_t flushFromResultBuf(SQInfo *pQInfo); static int32_t flushFromResultBuf(SQInfo *pQInfo);
bool getNeighborPoints(SQInfo *pQInfo, void *pMeterObj, SPointInterpoSupporter *pPointInterpSupporter) { bool getNeighborPoints(SQInfo *pQInfo, void *pMeterObj, SPointInterpoSupporter *pPointInterpSupporter) {
...@@ -926,7 +931,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis * ...@@ -926,7 +931,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
TSKEY ts = primaryKeyCol[offset]; TSKEY ts = primaryKeyCol[offset];
STimeWindow win = getActiveTimeWindow(pWindowResInfo, ts, pQuery); STimeWindow win = getActiveTimeWindow(pWindowResInfo, ts, pQuery);
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo->sid, &win) != TSDB_CODE_SUCCESS) { if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo->tid, &win) != TSDB_CODE_SUCCESS) {
return; return;
} }
...@@ -947,7 +952,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis * ...@@ -947,7 +952,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
} }
// null data, failed to allocate more memory buffer // null data, failed to allocate more memory buffer
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo->sid, &nextWin) != TSDB_CODE_SUCCESS) { if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo->tid, &nextWin) != TSDB_CODE_SUCCESS) {
break; break;
} }
...@@ -1178,7 +1183,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS ...@@ -1178,7 +1183,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
int64_t ts = primaryKeyCol[offset]; int64_t ts = primaryKeyCol[offset];
STimeWindow win = getActiveTimeWindow(pWindowResInfo, ts, pQuery); STimeWindow win = getActiveTimeWindow(pWindowResInfo, ts, pQuery);
int32_t ret = setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo->sid, &win); int32_t ret = setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo->tid, &win);
if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code
continue; continue;
} }
...@@ -1206,7 +1211,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS ...@@ -1206,7 +1211,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
} }
// null data, failed to allocate more memory buffer // null data, failed to allocate more memory buffer
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo->sid, &nextWin) != TSDB_CODE_SUCCESS) { if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo->tid, &nextWin) != TSDB_CODE_SUCCESS) {
break; break;
} }
...@@ -1496,8 +1501,9 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { ...@@ -1496,8 +1501,9 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) {
} }
SQuery *pQuery = pRuntimeEnv->pQuery; SQuery *pQuery = pRuntimeEnv->pQuery;
SQInfo* pQInfo = (SQInfo*) GET_QINFO_ADDR(pRuntimeEnv);
qTrace("QInfo:%p teardown runtime env", GET_QINFO_ADDR(pQuery)); qTrace("QInfo:%p teardown runtime env", pQInfo);
cleanupTimeWindowInfo(&pRuntimeEnv->windowResInfo, pQuery->numOfOutput); cleanupTimeWindowInfo(&pRuntimeEnv->windowResInfo, pQuery->numOfOutput);
if (pRuntimeEnv->pCtx != NULL) { if (pRuntimeEnv->pCtx != NULL) {
...@@ -1527,7 +1533,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { ...@@ -1527,7 +1533,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) {
tfree(pRuntimeEnv->pInterpoBuf); tfree(pRuntimeEnv->pInterpoBuf);
} }
destroyResultBuf(pRuntimeEnv->pResultBuf); destroyResultBuf(pRuntimeEnv->pResultBuf, pQInfo);
tsdbCleanupQueryHandle(pRuntimeEnv->pQueryHandle); tsdbCleanupQueryHandle(pRuntimeEnv->pQueryHandle);
tsdbCleanupQueryHandle(pRuntimeEnv->pSecQueryHandle); tsdbCleanupQueryHandle(pRuntimeEnv->pSecQueryHandle);
...@@ -1553,7 +1559,7 @@ static bool isQueryKilled(SQInfo *pQInfo) { ...@@ -1553,7 +1559,7 @@ static bool isQueryKilled(SQInfo *pQInfo) {
static void setQueryKilled(SQInfo *pQInfo) { pQInfo->code = TSDB_CODE_QUERY_CANCELLED; } static void setQueryKilled(SQInfo *pQInfo) { pQInfo->code = TSDB_CODE_QUERY_CANCELLED; }
bool isFixedOutputQuery(SQuery *pQuery) { static bool isFixedOutputQuery(SQuery *pQuery) {
if (pQuery->intervalTime != 0) { if (pQuery->intervalTime != 0) {
return false; return false;
} }
...@@ -1584,7 +1590,7 @@ bool isFixedOutputQuery(SQuery *pQuery) { ...@@ -1584,7 +1590,7 @@ bool isFixedOutputQuery(SQuery *pQuery) {
return false; return false;
} }
bool isPointInterpoQuery(SQuery *pQuery) { static bool isPointInterpoQuery(SQuery *pQuery) {
for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { for (int32_t i = 0; i < pQuery->numOfOutput; ++i) {
int32_t functionID = pQuery->pSelectExpr[i].base.functionId; int32_t functionID = pQuery->pSelectExpr[i].base.functionId;
if (functionID == TSDB_FUNC_INTERP || functionID == TSDB_FUNC_LAST_ROW) { if (functionID == TSDB_FUNC_INTERP || functionID == TSDB_FUNC_LAST_ROW) {
...@@ -1596,7 +1602,7 @@ bool isPointInterpoQuery(SQuery *pQuery) { ...@@ -1596,7 +1602,7 @@ bool isPointInterpoQuery(SQuery *pQuery) {
} }
// TODO REFACTOR:MERGE WITH CLIENT-SIDE FUNCTION // TODO REFACTOR:MERGE WITH CLIENT-SIDE FUNCTION
bool isSumAvgRateQuery(SQuery *pQuery) { static bool isSumAvgRateQuery(SQuery *pQuery) {
for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { for (int32_t i = 0; i < pQuery->numOfOutput; ++i) {
int32_t functionId = pQuery->pSelectExpr[i].base.functionId; int32_t functionId = pQuery->pSelectExpr[i].base.functionId;
if (functionId == TSDB_FUNC_TS) { if (functionId == TSDB_FUNC_TS) {
...@@ -1612,7 +1618,7 @@ bool isSumAvgRateQuery(SQuery *pQuery) { ...@@ -1612,7 +1618,7 @@ bool isSumAvgRateQuery(SQuery *pQuery) {
return false; return false;
} }
bool isFirstLastRowQuery(SQuery *pQuery) { static bool isFirstLastRowQuery(SQuery *pQuery) {
for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { for (int32_t i = 0; i < pQuery->numOfOutput; ++i) {
int32_t functionID = pQuery->pSelectExpr[i].base.functionId; int32_t functionID = pQuery->pSelectExpr[i].base.functionId;
if (functionID == TSDB_FUNC_LAST_ROW) { if (functionID == TSDB_FUNC_LAST_ROW) {
...@@ -1623,7 +1629,7 @@ bool isFirstLastRowQuery(SQuery *pQuery) { ...@@ -1623,7 +1629,7 @@ bool isFirstLastRowQuery(SQuery *pQuery) {
return false; return false;
} }
bool notHasQueryTimeRange(SQuery *pQuery) { static UNUSED_FUNC bool notHasQueryTimeRange(SQuery *pQuery) {
return (pQuery->window.skey == 0 && pQuery->window.ekey == INT64_MAX && QUERY_IS_ASC_QUERY(pQuery)) || return (pQuery->window.skey == 0 && pQuery->window.ekey == INT64_MAX && QUERY_IS_ASC_QUERY(pQuery)) ||
(pQuery->window.skey == INT64_MAX && pQuery->window.ekey == 0 && (!QUERY_IS_ASC_QUERY(pQuery))); (pQuery->window.skey == INT64_MAX && pQuery->window.ekey == 0 && (!QUERY_IS_ASC_QUERY(pQuery)));
} }
...@@ -1643,6 +1649,18 @@ static bool needReverseScan(SQuery *pQuery) { ...@@ -1643,6 +1649,18 @@ static bool needReverseScan(SQuery *pQuery) {
return false; return false;
} }
static bool onlyQueryTags(SQuery* pQuery) {
for(int32_t i = 0; i < pQuery->numOfOutput; ++i) {
int32_t functionId = pQuery->pSelectExpr[i].base.functionId;
if (functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TID_TAG) {
return false;
}
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
void getAlignQueryTimeWindow(SQuery *pQuery, int64_t key, int64_t keyFirst, int64_t keyLast, int64_t *realSkey, void getAlignQueryTimeWindow(SQuery *pQuery, int64_t key, int64_t keyFirst, int64_t keyLast, int64_t *realSkey,
...@@ -1934,7 +1952,7 @@ static void changeExecuteScanOrder(SQuery *pQuery, bool metricQuery) { ...@@ -1934,7 +1952,7 @@ static void changeExecuteScanOrder(SQuery *pQuery, bool metricQuery) {
} }
} }
static void doSetInterpVal(SQLFunctionCtx *pCtx, TSKEY ts, int16_t type, int32_t index, char *data) { static UNUSED_FUNC void doSetInterpVal(SQLFunctionCtx *pCtx, TSKEY ts, int16_t type, int32_t index, char *data) {
assert(pCtx->param[index].pz == NULL); assert(pCtx->param[index].pz == NULL);
int32_t len = 0; int32_t len = 0;
...@@ -1999,6 +2017,7 @@ static void doSetInterpVal(SQLFunctionCtx *pCtx, TSKEY ts, int16_t type, int32_t ...@@ -1999,6 +2017,7 @@ static void doSetInterpVal(SQLFunctionCtx *pCtx, TSKEY ts, int16_t type, int32_t
* @param pInterpoRaw * @param pInterpoRaw
*/ */
void pointInterpSupporterSetData(SQInfo *pQInfo, SPointInterpoSupporter *pPointInterpSupport) { void pointInterpSupporterSetData(SQInfo *pQInfo, SPointInterpoSupporter *pPointInterpSupport) {
#if 0
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
...@@ -2008,7 +2027,7 @@ void pointInterpSupporterSetData(SQInfo *pQInfo, SPointInterpoSupporter *pPointI ...@@ -2008,7 +2027,7 @@ void pointInterpSupporterSetData(SQInfo *pQInfo, SPointInterpoSupporter *pPointI
} }
int32_t count = 1; int32_t count = 1;
TSKEY key = *(TSKEY *)pPointInterpSupport->pNextPoint[0]; TSKEY key = *(TSKEY *)pPointInterpSupport->next[0];
if (key == pQuery->window.skey) { if (key == pQuery->window.skey) {
// the queried timestamp has value, return it directly without interpolation // the queried timestamp has value, return it directly without interpolation
...@@ -2091,9 +2110,11 @@ void pointInterpSupporterSetData(SQInfo *pQInfo, SPointInterpoSupporter *pPointI ...@@ -2091,9 +2110,11 @@ void pointInterpSupporterSetData(SQInfo *pQInfo, SPointInterpoSupporter *pPointI
} }
} }
} }
#endif
} }
void pointInterpSupporterInit(SQuery *pQuery, SPointInterpoSupporter *pInterpoSupport) { void pointInterpSupporterInit(SQuery *pQuery, SPointInterpoSupporter *pInterpoSupport) {
#if 0
if (isPointInterpoQuery(pQuery)) { if (isPointInterpoQuery(pQuery)) {
pInterpoSupport->pPrevPoint = malloc(pQuery->numOfCols * POINTER_BYTES); pInterpoSupport->pPrevPoint = malloc(pQuery->numOfCols * POINTER_BYTES);
pInterpoSupport->pNextPoint = malloc(pQuery->numOfCols * POINTER_BYTES); pInterpoSupport->pNextPoint = malloc(pQuery->numOfCols * POINTER_BYTES);
...@@ -2120,9 +2141,11 @@ void pointInterpSupporterInit(SQuery *pQuery, SPointInterpoSupporter *pInterpoSu ...@@ -2120,9 +2141,11 @@ void pointInterpSupporterInit(SQuery *pQuery, SPointInterpoSupporter *pInterpoSu
offset += pQuery->colList[i].bytes; offset += pQuery->colList[i].bytes;
} }
} }
#endif
} }
void pointInterpSupporterDestroy(SPointInterpoSupporter *pPointInterpSupport) { void pointInterpSupporterDestroy(SPointInterpoSupporter *pPointInterpSupport) {
#if 0
if (pPointInterpSupport->numOfCols <= 0 || pPointInterpSupport->pPrevPoint == NULL) { if (pPointInterpSupport->numOfCols <= 0 || pPointInterpSupport->pPrevPoint == NULL) {
return; return;
} }
...@@ -2134,6 +2157,7 @@ void pointInterpSupporterDestroy(SPointInterpoSupporter *pPointInterpSupport) { ...@@ -2134,6 +2157,7 @@ void pointInterpSupporterDestroy(SPointInterpoSupporter *pPointInterpSupport) {
tfree(pPointInterpSupport->pNextPoint); tfree(pPointInterpSupport->pNextPoint);
pPointInterpSupport->numOfCols = 0; pPointInterpSupport->numOfCols = 0;
#endif
} }
static UNUSED_FUNC void allocMemForInterpo(SQInfo *pQInfo, SQuery *pQuery, void *pMeterObj) { static UNUSED_FUNC void allocMemForInterpo(SQInfo *pQInfo, SQuery *pQuery, void *pMeterObj) {
...@@ -2238,22 +2262,6 @@ UNUSED_FUNC void vnodeDecMeterRefcnt(SQInfo *pQInfo) { ...@@ -2238,22 +2262,6 @@ UNUSED_FUNC void vnodeDecMeterRefcnt(SQInfo *pQInfo) {
#endif #endif
} }
UNUSED_FUNC void setTimestampRange(SQueryRuntimeEnv *pRuntimeEnv, int64_t stime, int64_t etime) {
SQuery *pQuery = pRuntimeEnv->pQuery;
for (int32_t i = 0; i < pQuery->numOfOutput; ++i) {
int32_t functionId = pQuery->pSelectExpr[i].base.functionId;
if (functionId == TSDB_FUNC_SPREAD) {
pRuntimeEnv->pCtx[i].param[1].dKey = stime;
pRuntimeEnv->pCtx[i].param[2].dKey = etime;
pRuntimeEnv->pCtx[i].param[1].nType = TSDB_DATA_TYPE_DOUBLE;
pRuntimeEnv->pCtx[i].param[2].nType = TSDB_DATA_TYPE_DOUBLE;
}
}
}
static bool needToLoadDataBlock(SQuery *pQuery, SDataStatis *pDataStatis, SQLFunctionCtx *pCtx, static bool needToLoadDataBlock(SQuery *pQuery, SDataStatis *pDataStatis, SQLFunctionCtx *pCtx,
int32_t numOfTotalPoints) { int32_t numOfTotalPoints) {
if (pDataStatis == NULL) { if (pDataStatis == NULL) {
...@@ -2340,7 +2348,7 @@ SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBl ...@@ -2340,7 +2348,7 @@ SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBl
} }
if (r == BLK_DATA_NO_NEEDED) { if (r == BLK_DATA_NO_NEEDED) {
qTrace("QInfo:%p slot:%d, data block ignored, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_QINFO_ADDR(pRuntimeEnv), qTrace("QInfo:%p data block ignored, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_QINFO_ADDR(pRuntimeEnv),
pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows); pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows);
} else if (r == BLK_DATA_FILEDS_NEEDED) { } else if (r == BLK_DATA_FILEDS_NEEDED) {
if (tsdbRetrieveDataBlockStatisInfo(pRuntimeEnv->pQueryHandle, pStatis) != TSDB_CODE_SUCCESS) { if (tsdbRetrieveDataBlockStatisInfo(pRuntimeEnv->pQueryHandle, pStatis) != TSDB_CODE_SUCCESS) {
...@@ -2539,7 +2547,7 @@ static void updatelastkey(SQuery *pQuery, STableQueryInfo *pTableQInfo) { pTable ...@@ -2539,7 +2547,7 @@ static void updatelastkey(SQuery *pQuery, STableQueryInfo *pTableQInfo) { pTable
* set tag value in SQLFunctionCtx * set tag value in SQLFunctionCtx
* e.g.,tag information into input buffer * e.g.,tag information into input buffer
*/ */
static void doSetTagValueInParam(void *tsdb, STableId id, int32_t tagColId, tVariant *param) { static void doSetTagValueInParam(void *tsdb, STableId* pTableId, int32_t tagColId, tVariant *param) {
tVariantDestroy(param); tVariantDestroy(param);
char * val = NULL; char * val = NULL;
...@@ -2547,11 +2555,11 @@ static void doSetTagValueInParam(void *tsdb, STableId id, int32_t tagColId, tVar ...@@ -2547,11 +2555,11 @@ static void doSetTagValueInParam(void *tsdb, STableId id, int32_t tagColId, tVar
int16_t type = 0; int16_t type = 0;
if (tagColId == TSDB_TBNAME_COLUMN_INDEX) { if (tagColId == TSDB_TBNAME_COLUMN_INDEX) {
tsdbTableGetName(tsdb, id, &val); tsdbGetTableName(tsdb, pTableId, &val);
bytes = TSDB_TABLE_NAME_LEN; bytes = strnlen(val, TSDB_TABLE_NAME_LEN);
type = TSDB_DATA_TYPE_BINARY; type = TSDB_DATA_TYPE_BINARY;
} else { } else {
tsdbGetTableTagVal(tsdb, id, tagColId, &type, &bytes, &val); tsdbGetTableTagVal(tsdb, pTableId, tagColId, &type, &bytes, &val);
} }
tVariantCreateFromBinary(param, val, bytes, type); tVariantCreateFromBinary(param, val, bytes, type);
...@@ -2561,13 +2569,13 @@ static void doSetTagValueInParam(void *tsdb, STableId id, int32_t tagColId, tVar ...@@ -2561,13 +2569,13 @@ static void doSetTagValueInParam(void *tsdb, STableId id, int32_t tagColId, tVar
} }
} }
void setTagVal(SQueryRuntimeEnv *pRuntimeEnv, STableId id, void *tsdb) { void setTagVal(SQueryRuntimeEnv *pRuntimeEnv, STableId* pTableId, void *tsdb) {
SQuery *pQuery = pRuntimeEnv->pQuery; SQuery *pQuery = pRuntimeEnv->pQuery;
SSqlFuncMsg *pFuncMsg = &pQuery->pSelectExpr[0].base; SSqlFuncMsg *pFuncMsg = &pQuery->pSelectExpr[0].base;
if (pQuery->numOfOutput == 1 && pFuncMsg->functionId == TSDB_FUNC_TS_COMP) { if (pQuery->numOfOutput == 1 && pFuncMsg->functionId == TSDB_FUNC_TS_COMP) {
assert(pFuncMsg->numOfParams == 1); assert(pFuncMsg->numOfParams == 1);
doSetTagValueInParam(tsdb, id, pFuncMsg->arg->argValue.i64, &pRuntimeEnv->pCtx[0].tag); doSetTagValueInParam(tsdb, pTableId, pFuncMsg->arg->argValue.i64, &pRuntimeEnv->pCtx[0].tag);
} else { } else {
// set tag value, by which the results are aggregated. // set tag value, by which the results are aggregated.
for (int32_t idx = 0; idx < pQuery->numOfOutput; ++idx) { for (int32_t idx = 0; idx < pQuery->numOfOutput; ++idx) {
...@@ -2579,7 +2587,7 @@ void setTagVal(SQueryRuntimeEnv *pRuntimeEnv, STableId id, void *tsdb) { ...@@ -2579,7 +2587,7 @@ void setTagVal(SQueryRuntimeEnv *pRuntimeEnv, STableId id, void *tsdb) {
} }
// todo use tag column index to optimize performance // todo use tag column index to optimize performance
doSetTagValueInParam(tsdb, id, pCol->colId, &pRuntimeEnv->pCtx[idx].tag); doSetTagValueInParam(tsdb, pTableId, pCol->colId, &pRuntimeEnv->pCtx[idx].tag);
} }
// set the join tag for first column // set the join tag for first column
...@@ -2744,7 +2752,7 @@ void UNUSED_FUNC displayInterResult(SData **pdata, SQuery *pQuery, int32_t numOf ...@@ -2744,7 +2752,7 @@ void UNUSED_FUNC displayInterResult(SData **pdata, SQuery *pQuery, int32_t numOf
} }
typedef struct SCompSupporter { typedef struct SCompSupporter {
STableDataInfo **pTableDataInfo; STableQueryInfo **pTableQueryInfo;
int32_t * position; int32_t * position;
SQInfo * pQInfo; SQInfo * pQInfo;
} SCompSupporter; } SCompSupporter;
...@@ -2769,13 +2777,13 @@ int32_t tableResultComparFn(const void *pLeft, const void *pRight, void *param) ...@@ -2769,13 +2777,13 @@ int32_t tableResultComparFn(const void *pLeft, const void *pRight, void *param)
return -1; return -1;
} }
SWindowResInfo *pWindowResInfo1 = &supporter->pTableDataInfo[left]->pTableQInfo->windowResInfo; SWindowResInfo *pWindowResInfo1 = &supporter->pTableQueryInfo[left]->windowResInfo;
SWindowResult * pWindowRes1 = getWindowResult(pWindowResInfo1, leftPos); SWindowResult * pWindowRes1 = getWindowResult(pWindowResInfo1, leftPos);
char *b1 = getPosInResultPage(pRuntimeEnv, PRIMARYKEY_TIMESTAMP_COL_INDEX, pWindowRes1); char *b1 = getPosInResultPage(pRuntimeEnv, PRIMARYKEY_TIMESTAMP_COL_INDEX, pWindowRes1);
TSKEY leftTimestamp = GET_INT64_VAL(b1); TSKEY leftTimestamp = GET_INT64_VAL(b1);
SWindowResInfo *pWindowResInfo2 = &supporter->pTableDataInfo[right]->pTableQInfo->windowResInfo; SWindowResInfo *pWindowResInfo2 = &supporter->pTableQueryInfo[right]->windowResInfo;
SWindowResult * pWindowRes2 = getWindowResult(pWindowResInfo2, rightPos); SWindowResult * pWindowRes2 = getWindowResult(pWindowResInfo2, rightPos);
char *b2 = getPosInResultPage(pRuntimeEnv, PRIMARYKEY_TIMESTAMP_COL_INDEX, pWindowRes2); char *b2 = getPosInResultPage(pRuntimeEnv, PRIMARYKEY_TIMESTAMP_COL_INDEX, pWindowRes2);
...@@ -2902,16 +2910,16 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) { ...@@ -2902,16 +2910,16 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) {
tFilePage **buffer = (tFilePage **)pQuery->sdata; tFilePage **buffer = (tFilePage **)pQuery->sdata;
int32_t * posList = calloc(size, sizeof(int32_t)); int32_t * posList = calloc(size, sizeof(int32_t));
STableDataInfo **pTableList = malloc(POINTER_BYTES * size); STableQueryInfo **pTableList = malloc(POINTER_BYTES * size);
// todo opt for the case of one table per group // todo opt for the case of one table per group
int32_t numOfTables = 0; int32_t numOfTables = 0;
for (int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
SPair * p = taosArrayGet(pGroup, i); SGroupItem *item = taosArrayGet(pGroup, i);
STableDataInfo *pInfo = p->sec; STableQueryInfo *pInfo = item->info;
SIDList list = getDataBufPagesIdList(pRuntimeEnv->pResultBuf, pInfo->pTableQInfo->tid); SIDList list = getDataBufPagesIdList(pRuntimeEnv->pResultBuf, pInfo->id.tid);
if (list.size > 0 && pInfo->pTableQInfo->windowResInfo.size > 0) { if (list.size > 0 && pInfo->windowResInfo.size > 0) {
pTableList[numOfTables] = pInfo; pTableList[numOfTables] = pInfo;
numOfTables += 1; numOfTables += 1;
} }
...@@ -2940,7 +2948,7 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) { ...@@ -2940,7 +2948,7 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) {
while (1) { while (1) {
int32_t pos = pTree->pNode[0].index; int32_t pos = pTree->pNode[0].index;
SWindowResInfo *pWindowResInfo = &pTableList[pos]->pTableQInfo->windowResInfo; SWindowResInfo *pWindowResInfo = &pTableList[pos]->windowResInfo;
SWindowResult * pWindowRes = getWindowResult(pWindowResInfo, cs.position[pos]); SWindowResult * pWindowRes = getWindowResult(pWindowResInfo, cs.position[pos]);
char *b = getPosInResultPage(pRuntimeEnv, PRIMARYKEY_TIMESTAMP_COL_INDEX, pWindowRes); char *b = getPosInResultPage(pRuntimeEnv, PRIMARYKEY_TIMESTAMP_COL_INDEX, pWindowRes);
...@@ -3074,9 +3082,9 @@ void resetMergeResultBuf(SQuery *pQuery, SQLFunctionCtx *pCtx, SResultInfo *pRes ...@@ -3074,9 +3082,9 @@ void resetMergeResultBuf(SQuery *pQuery, SQLFunctionCtx *pCtx, SResultInfo *pRes
} }
} }
void setTableDataInfo(STableDataInfo *pTableDataInfo, int32_t tableIndex, int32_t groupId) { void setTableDataInfo(STableQueryInfo *pTableQueryInfo, int32_t tableIndex, int32_t groupId) {
pTableDataInfo->groupIdx = groupId; pTableQueryInfo->groupIdx = groupId;
pTableDataInfo->tableIndex = tableIndex; pTableQueryInfo->tableIndex = tableIndex;
} }
static void doDisableFunctsForSupplementaryScan(SQuery *pQuery, SWindowResInfo *pWindowResInfo, int32_t order) { static void doDisableFunctsForSupplementaryScan(SQuery *pQuery, SWindowResInfo *pWindowResInfo, int32_t order) {
...@@ -3136,7 +3144,7 @@ void disableFuncForReverseScan(SQInfo *pQInfo, int32_t order) { ...@@ -3136,7 +3144,7 @@ void disableFuncForReverseScan(SQInfo *pQInfo, int32_t order) {
if (isIntervalQuery(pQuery)) { if (isIntervalQuery(pQuery)) {
// for (int32_t i = 0; i < pQInfo->groupInfo.numOfTables; ++i) { // for (int32_t i = 0; i < pQInfo->groupInfo.numOfTables; ++i) {
// STableQueryInfo *pTableQueryInfo = pQInfo->pTableDataInfo[i].pTableQInfo; // STableQueryInfo *pTableQueryInfo = pQInfo->pTableQueryInfo[i].pTableQInfo;
// SWindowResInfo * pWindowResInfo = &pTableQueryInfo->windowResInfo; // SWindowResInfo * pWindowResInfo = &pTableQueryInfo->windowResInfo;
// //
// doDisableFunctsForSupplementaryScan(pQuery, pWindowResInfo, order); // doDisableFunctsForSupplementaryScan(pQuery, pWindowResInfo, order);
...@@ -3364,7 +3372,7 @@ static void setEnvBeforeReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusI ...@@ -3364,7 +3372,7 @@ static void setEnvBeforeReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusI
tsdbCleanupQueryHandle(pRuntimeEnv->pSecQueryHandle); tsdbCleanupQueryHandle(pRuntimeEnv->pSecQueryHandle);
} }
pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->groupInfo); pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableIdGroupInfo);
setQueryStatus(pQuery, QUERY_NOT_COMPLETED); setQueryStatus(pQuery, QUERY_NOT_COMPLETED);
switchCtxOrder(pRuntimeEnv); switchCtxOrder(pRuntimeEnv);
...@@ -3430,7 +3438,7 @@ void scanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { ...@@ -3430,7 +3438,7 @@ void scanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
tsdbCleanupQueryHandle(pRuntimeEnv->pSecQueryHandle); tsdbCleanupQueryHandle(pRuntimeEnv->pSecQueryHandle);
} }
pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->groupInfo); pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableIdGroupInfo);
pRuntimeEnv->windowResInfo.curIndex = qstatus.windowIndex; pRuntimeEnv->windowResInfo.curIndex = qstatus.windowIndex;
setQueryStatus(pQuery, QUERY_NOT_COMPLETED); setQueryStatus(pQuery, QUERY_NOT_COMPLETED);
...@@ -3503,14 +3511,14 @@ static bool hasMainOutput(SQuery *pQuery) { ...@@ -3503,14 +3511,14 @@ static bool hasMainOutput(SQuery *pQuery) {
return false; return false;
} }
STableQueryInfo *createTableQueryInfo(SQueryRuntimeEnv *pRuntimeEnv, int32_t tid, STimeWindow win) { STableQueryInfo *createTableQueryInfoImpl(SQueryRuntimeEnv *pRuntimeEnv, STableId tableId, STimeWindow win) {
STableQueryInfo *pTableQueryInfo = calloc(1, sizeof(STableQueryInfo)); STableQueryInfo *pTableQueryInfo = calloc(1, sizeof(STableQueryInfo));
pTableQueryInfo->win = win; pTableQueryInfo->win = win;
pTableQueryInfo->lastKey = win.skey; pTableQueryInfo->lastKey = win.skey;
pTableQueryInfo->tid = tid; pTableQueryInfo->id = tableId;
pTableQueryInfo->cur.vnodeIndex = -1; pTableQueryInfo->cur.vgroupIndex = -1;
initWindowResInfo(&pTableQueryInfo->windowResInfo, pRuntimeEnv, 100, 100, TSDB_DATA_TYPE_INT); initWindowResInfo(&pTableQueryInfo->windowResInfo, pRuntimeEnv, 100, 100, TSDB_DATA_TYPE_INT);
return pTableQueryInfo; return pTableQueryInfo;
...@@ -3544,7 +3552,7 @@ void changeMeterQueryInfoForSuppleQuery(SQuery *pQuery, STableQueryInfo *pTableQ ...@@ -3544,7 +3552,7 @@ void changeMeterQueryInfoForSuppleQuery(SQuery *pQuery, STableQueryInfo *pTableQ
pTableQueryInfo->lastKey = pTableQueryInfo->win.skey; pTableQueryInfo->lastKey = pTableQueryInfo->win.skey;
pTableQueryInfo->cur.order = pTableQueryInfo->cur.order ^ 1u; pTableQueryInfo->cur.order = pTableQueryInfo->cur.order ^ 1u;
pTableQueryInfo->cur.vnodeIndex = -1; pTableQueryInfo->cur.vgroupIndex = -1;
} }
void restoreIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, STableQueryInfo *pTableQueryInfo) { void restoreIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, STableQueryInfo *pTableQueryInfo) {
...@@ -3562,8 +3570,7 @@ void restoreIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, STableQueryInfo *p ...@@ -3562,8 +3570,7 @@ void restoreIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, STableQueryInfo *p
* @param pRuntimeEnv * @param pRuntimeEnv
* @param pDataBlockInfo * @param pDataBlockInfo
*/ */
void setExecutionContext(SQInfo *pQInfo, STableQueryInfo *pTableQueryInfo, STable *pTable, int32_t groupIdx, void setExecutionContext(SQInfo *pQInfo, STableQueryInfo *pTableQueryInfo, STableId* pTableId, int32_t groupIdx, TSKEY nextKey) {
TSKEY nextKey) {
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv;
SWindowResInfo * pWindowResInfo = &pRuntimeEnv->windowResInfo; SWindowResInfo * pWindowResInfo = &pRuntimeEnv->windowResInfo;
int32_t GROUPRESULTID = 1; int32_t GROUPRESULTID = 1;
...@@ -3588,7 +3595,7 @@ void setExecutionContext(SQInfo *pQInfo, STableQueryInfo *pTableQueryInfo, STabl ...@@ -3588,7 +3595,7 @@ void setExecutionContext(SQInfo *pQInfo, STableQueryInfo *pTableQueryInfo, STabl
initCtxOutputBuf(pRuntimeEnv); initCtxOutputBuf(pRuntimeEnv);
pTableQueryInfo->lastKey = nextKey; pTableQueryInfo->lastKey = nextKey;
setAdditionalInfo(pQInfo, pTable, pTableQueryInfo); setAdditionalInfo(pQInfo, pTableId, pTableQueryInfo);
} }
static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pResult) { static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pResult) {
...@@ -3616,15 +3623,15 @@ static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult * ...@@ -3616,15 +3623,15 @@ static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *
} }
} }
int32_t setAdditionalInfo(SQInfo *pQInfo, STable *pTable, STableQueryInfo *pTableQueryInfo) { int32_t setAdditionalInfo(SQInfo *pQInfo, STableId* pTableId, STableQueryInfo *pTableQueryInfo) {
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv;
assert(pTableQueryInfo->lastKey >= 0); assert(pTableQueryInfo->lastKey >= 0);
setTagVal(pRuntimeEnv, pTable->tableId, pQInfo->tsdb); setTagVal(pRuntimeEnv, pTableId, pQInfo->tsdb);
// both the master and supplement scan needs to set the correct ts comp start position // both the master and supplement scan needs to set the correct ts comp start position
if (pRuntimeEnv->pTSBuf != NULL) { if (pRuntimeEnv->pTSBuf != NULL) {
if (pTableQueryInfo->cur.vnodeIndex == -1) { if (pTableQueryInfo->cur.vgroupIndex == -1) {
pTableQueryInfo->tag = pRuntimeEnv->pCtx[0].tag.i64Key; pTableQueryInfo->tag = pRuntimeEnv->pCtx[0].tag.i64Key;
tsBufGetElemStartPos(pRuntimeEnv->pTSBuf, 0, pTableQueryInfo->tag); tsBufGetElemStartPos(pRuntimeEnv->pTSBuf, 0, pTableQueryInfo->tag);
...@@ -3819,12 +3826,12 @@ void copyFromWindowResToSData(SQInfo *pQInfo, SWindowResult *result) { ...@@ -3819,12 +3826,12 @@ void copyFromWindowResToSData(SQInfo *pQInfo, SWindowResult *result) {
assert(pQuery->rec.rows <= pQuery->rec.capacity); assert(pQuery->rec.rows <= pQuery->rec.capacity);
} }
static void updateWindowResNumOfRes(SQueryRuntimeEnv *pRuntimeEnv, STableDataInfo *pTableDataInfo) { static void updateWindowResNumOfRes(SQueryRuntimeEnv *pRuntimeEnv, STableQueryInfo *pTableQueryInfo) {
SQuery *pQuery = pRuntimeEnv->pQuery; SQuery *pQuery = pRuntimeEnv->pQuery;
// update the number of result for each, only update the number of rows for the corresponding window result. // update the number of result for each, only update the number of rows for the corresponding window result.
if (pQuery->intervalTime == 0) { if (pQuery->intervalTime == 0) {
int32_t g = pTableDataInfo->groupIdx; int32_t g = pTableQueryInfo->groupIdx;
assert(pRuntimeEnv->windowResInfo.size > 0); assert(pRuntimeEnv->windowResInfo.size > 0);
SWindowResult *pWindowRes = doSetTimeWindowFromKey(pRuntimeEnv, &pRuntimeEnv->windowResInfo, (char *)&g, sizeof(g)); SWindowResult *pWindowRes = doSetTimeWindowFromKey(pRuntimeEnv, &pRuntimeEnv->windowResInfo, (char *)&g, sizeof(g));
...@@ -3834,11 +3841,10 @@ static void updateWindowResNumOfRes(SQueryRuntimeEnv *pRuntimeEnv, STableDataInf ...@@ -3834,11 +3841,10 @@ static void updateWindowResNumOfRes(SQueryRuntimeEnv *pRuntimeEnv, STableDataInf
} }
} }
void stableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, STableDataInfo *pTableDataInfo, void stableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, STableQueryInfo *pTableQueryInfo,
SDataBlockInfo *pDataBlockInfo, SDataStatis *pStatis, SArray *pDataBlock, SDataBlockInfo *pDataBlockInfo, SDataStatis *pStatis, SArray *pDataBlock,
__block_search_fn_t searchFn) { __block_search_fn_t searchFn) {
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
STableQueryInfo *pTableQueryInfo = pTableDataInfo->pTableQInfo;
SWindowResInfo * pWindowResInfo = &pTableQueryInfo->windowResInfo; SWindowResInfo * pWindowResInfo = &pTableQueryInfo->windowResInfo;
pQuery->pos = QUERY_IS_ASC_QUERY(pQuery)? 0 : pDataBlockInfo->rows - 1; pQuery->pos = QUERY_IS_ASC_QUERY(pQuery)? 0 : pDataBlockInfo->rows - 1;
...@@ -3848,7 +3854,7 @@ void stableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, STableDataInfo * ...@@ -3848,7 +3854,7 @@ void stableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, STableDataInfo *
blockwiseApplyFunctions(pRuntimeEnv, pStatis, pDataBlockInfo, pWindowResInfo, searchFn, pDataBlock); blockwiseApplyFunctions(pRuntimeEnv, pStatis, pDataBlockInfo, pWindowResInfo, searchFn, pDataBlock);
} }
updateWindowResNumOfRes(pRuntimeEnv, pTableDataInfo); updateWindowResNumOfRes(pRuntimeEnv, pTableQueryInfo);
updatelastkey(pQuery, pTableQueryInfo); updatelastkey(pQuery, pTableQueryInfo);
} }
...@@ -4206,7 +4212,7 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv) { ...@@ -4206,7 +4212,7 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv) {
return true; return true;
} }
int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, bool isSTableQuery) { int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, int32_t vgId, bool isSTableQuery) {
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv;
SQuery *pQuery = pQInfo->runtimeEnv.pQuery; SQuery *pQuery = pQInfo->runtimeEnv.pQuery;
...@@ -4225,15 +4231,20 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, bool isSTableQuery) ...@@ -4225,15 +4231,20 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, bool isSTableQuery)
.numOfCols = pQuery->numOfCols, .numOfCols = pQuery->numOfCols,
}; };
if (!isSTableQuery || isIntervalQuery(pQuery) || isFixedOutputQuery(pQuery)) {
pRuntimeEnv->pQueryHandle = tsdbQueryTables(tsdb, &cond, &pQInfo->groupInfo); // normal query setup the queryhandle here
if (isFirstLastRowQuery(pQuery) && !isSTableQuery) { // in case of last_row query, invoke a different API.
pRuntimeEnv->pQueryHandle = tsdbQueryLastRow(tsdb, &cond, &pQInfo->tableIdGroupInfo);
} else if (!isSTableQuery || isIntervalQuery(pQuery) || isFixedOutputQuery(pQuery)) {
pRuntimeEnv->pQueryHandle = tsdbQueryTables(tsdb, &cond, &pQInfo->tableIdGroupInfo);
} }
pQInfo->tsdb = tsdb; pQInfo->tsdb = tsdb;
pQInfo->vgId = vgId;
pRuntimeEnv->pQuery = pQuery; pRuntimeEnv->pQuery = pQuery;
pRuntimeEnv->pTSBuf = param; pRuntimeEnv->pTSBuf = param;
pRuntimeEnv->cur.vnodeIndex = -1; pRuntimeEnv->cur.vgroupIndex = -1;
pRuntimeEnv->stableQuery = isSTableQuery; pRuntimeEnv->stableQuery = isSTableQuery;
if (param != NULL) { if (param != NULL) {
...@@ -4251,7 +4262,7 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, bool isSTableQuery) ...@@ -4251,7 +4262,7 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, bool isSTableQuery)
if (isSTableQuery) { if (isSTableQuery) {
int32_t rows = getInitialPageNum(pQInfo); int32_t rows = getInitialPageNum(pQInfo);
code = createDiskbasedResultBuffer(&pRuntimeEnv->pResultBuf, rows, pQuery->rowSize); code = createDiskbasedResultBuffer(&pRuntimeEnv->pResultBuf, rows, pQuery->rowSize, pQInfo);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return code; return code;
} }
...@@ -4270,7 +4281,7 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, bool isSTableQuery) ...@@ -4270,7 +4281,7 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, bool isSTableQuery)
} else if (isGroupbyNormalCol(pQuery->pGroupbyExpr) || isIntervalQuery(pQuery)) { } else if (isGroupbyNormalCol(pQuery->pGroupbyExpr) || isIntervalQuery(pQuery)) {
int32_t rows = getInitialPageNum(pQInfo); int32_t rows = getInitialPageNum(pQInfo);
code = createDiskbasedResultBuffer(&pRuntimeEnv->pResultBuf, rows, pQuery->rowSize); code = createDiskbasedResultBuffer(&pRuntimeEnv->pResultBuf, rows, pQuery->rowSize, pQInfo);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return code; return code;
} }
...@@ -4287,36 +4298,36 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, bool isSTableQuery) ...@@ -4287,36 +4298,36 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, bool isSTableQuery)
setQueryStatus(pQuery, QUERY_NOT_COMPLETED); setQueryStatus(pQuery, QUERY_NOT_COMPLETED);
SPointInterpoSupporter interpInfo = {0}; // SPointInterpoSupporter interpInfo = {0};
pointInterpSupporterInit(pQuery, &interpInfo); // pointInterpSupporterInit(pQuery, &interpInfo);
/* /*
* in case of last_row query without query range, we set the query timestamp to * in case of last_row query without query range, we set the query timestamp to be
* pMeterObj->lastKey. Otherwise, keep the initial query time range unchanged. * STable->lastKey. Otherwise, keep the initial query time range unchanged.
*/ */
if (isFirstLastRowQuery(pQuery) && notHasQueryTimeRange(pQuery)) { // if (isFirstLastRowQuery(pQuery)) {
if (!normalizeUnBoundLastRowQuery(pQInfo, &interpInfo)) { // if (!normalizeUnBoundLastRowQuery(pQInfo, &interpInfo)) {
sem_post(&pQInfo->dataReady); // sem_post(&pQInfo->dataReady);
pointInterpSupporterDestroy(&interpInfo); // pointInterpSupporterDestroy(&interpInfo);
return TSDB_CODE_SUCCESS; // return TSDB_CODE_SUCCESS;
} // }
} // }
/* /*
* here we set the value for before and after the specified time into the * here we set the value for before and after the specified time into the
* parameter for interpolation query * parameter for interpolation query
*/ */
pointInterpSupporterSetData(pQInfo, &interpInfo); // pointInterpSupporterSetData(pQInfo, &interpInfo);
pointInterpSupporterDestroy(&interpInfo); // pointInterpSupporterDestroy(&interpInfo);
int64_t rs = taosGetIntervalStartTimestamp(pQuery->window.skey, pQuery->intervalTime, pQuery->slidingTimeUnit, // int64_t rs = taosGetIntervalStartTimestamp(pQuery->window.skey, pQuery->intervalTime, pQuery->slidingTimeUnit,
pQuery->precision); // pQuery->precision);
taosInitInterpoInfo(&pRuntimeEnv->interpoInfo, pQuery->order.order, rs, 0, 0); // taosInitInterpoInfo(&pRuntimeEnv->interpoInfo, pQuery->order.order, rs, 0, 0);
// allocMemForInterpo(pQInfo, pQuery, pMeterObj); // allocMemForInterpo(pQInfo, pQuery, pMeterObj);
if (!isPointInterpoQuery(pQuery)) { // if (!isPointInterpoQuery(pQuery)) {
// assert(pQuery->pos >= 0 && pQuery->slot >= 0); // assert(pQuery->pos >= 0 && pQuery->slot >= 0);
} // }
// the pQuery->window.skey is changed during normalizedFirstQueryRange, so set the newest lastkey value // the pQuery->window.skey is changed during normalizedFirstQueryRange, so set the newest lastkey value
pQuery->lastKey = pQuery->window.skey; pQuery->lastKey = pQuery->window.skey;
...@@ -4362,8 +4373,7 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) { ...@@ -4362,8 +4373,7 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) {
} }
SDataBlockInfo blockInfo = tsdbRetrieveDataBlockInfo(pQueryHandle); SDataBlockInfo blockInfo = tsdbRetrieveDataBlockInfo(pQueryHandle);
STableDataInfo *pTableDataInfo = NULL; STableQueryInfo *pTableQueryInfo = NULL;
STable * pTable = NULL;
// todo opt performance using hash table // todo opt performance using hash table
size_t numOfGroup = taosArrayGetSize(pQInfo->groupInfo.pGroupList); size_t numOfGroup = taosArrayGetSize(pQInfo->groupInfo.pGroupList);
...@@ -4372,20 +4382,23 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) { ...@@ -4372,20 +4382,23 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) {
size_t num = taosArrayGetSize(group); size_t num = taosArrayGetSize(group);
for (int32_t j = 0; j < num; ++j) { for (int32_t j = 0; j < num; ++j) {
SPair * p = taosArrayGet(group, j); SGroupItem *item = taosArrayGet(group, j);
STableDataInfo *pInfo = p->sec; STableQueryInfo *pInfo = item->info;
if (pInfo->id.tid == blockInfo.tid) {
assert(pInfo->id.uid == blockInfo.uid);
pTableQueryInfo = item->info;
if (pInfo->pTableQInfo->tid == blockInfo.sid) {
pTableDataInfo = p->sec;
pTable = p->first;
break; break;
} }
} }
}
assert(pTableDataInfo != NULL && pTableDataInfo->pTableQInfo != NULL); if (pTableQueryInfo != NULL) {
STableQueryInfo *pTableQueryInfo = pTableDataInfo->pTableQInfo; break;
}
}
assert(pTableQueryInfo != NULL && pTableQueryInfo != NULL);
restoreIntervalQueryRange(pRuntimeEnv, pTableQueryInfo); restoreIntervalQueryRange(pRuntimeEnv, pTableQueryInfo);
SDataStatis *pStatis = NULL; SDataStatis *pStatis = NULL;
...@@ -4393,10 +4406,10 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) { ...@@ -4393,10 +4406,10 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) {
TSKEY nextKey = blockInfo.window.skey; TSKEY nextKey = blockInfo.window.skey;
if (!isIntervalQuery(pQuery)) { if (!isIntervalQuery(pQuery)) {
setExecutionContext(pQInfo, pTableQueryInfo, pTable, pTableDataInfo->groupIdx, nextKey); setExecutionContext(pQInfo, pTableQueryInfo, &pTableQueryInfo->id, pTableQueryInfo->groupIdx, nextKey);
} else { // interval query } else { // interval query
setIntervalQueryRange(pTableQueryInfo, pQInfo, nextKey); setIntervalQueryRange(pTableQueryInfo, pQInfo, nextKey);
int32_t ret = setAdditionalInfo(pQInfo, pTable, pTableQueryInfo); int32_t ret = setAdditionalInfo(pQInfo, &pTableQueryInfo->id, pTableQueryInfo);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
pQInfo->code = ret; pQInfo->code = ret;
...@@ -4404,7 +4417,7 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) { ...@@ -4404,7 +4417,7 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) {
} }
} }
stableApplyFunctionsOnBlock(pRuntimeEnv, pTableDataInfo, &blockInfo, pStatis, pDataBlock, binarySearchForKey); stableApplyFunctionsOnBlock(pRuntimeEnv, pTableQueryInfo, &blockInfo, pStatis, pDataBlock, binarySearchForKey);
} }
int64_t et = taosGetTimestampMs(); int64_t et = taosGetTimestampMs();
...@@ -4417,27 +4430,24 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) { ...@@ -4417,27 +4430,24 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) {
setQueryStatus(pQuery, QUERY_NOT_COMPLETED); setQueryStatus(pQuery, QUERY_NOT_COMPLETED);
SArray *group = taosArrayGetP(pQInfo->groupInfo.pGroupList, 0); SArray *group = taosArrayGetP(pQInfo->groupInfo.pGroupList, 0);
SPair * p = taosArrayGet(group, index); SGroupItem* item = taosArrayGet(group, index);
STable * pTable = p->first; setTagVal(pRuntimeEnv, &item->id, pQInfo->tsdb);
STableDataInfo *pInfo = p->sec;
setTagVal(pRuntimeEnv, pTable->tableId, pQInfo->tsdb);
qTrace("QInfo:%p query on (%d): uid:%" PRIu64 ", tid:%d, qrange:%" PRId64 "-%" PRId64, pQInfo, index, qTrace("QInfo:%p query on (%d): uid:%" PRIu64 ", tid:%d, qrange:%" PRId64 "-%" PRId64, pQInfo, index,
pTable->tableId.uid, pInfo->pTableQInfo->lastKey, pInfo->pTableQInfo->win.ekey); item->id.uid, item->id.tid, item->info->lastKey, item->info->win.ekey);
STsdbQueryCond cond = { STsdbQueryCond cond = {
.twindow = {pInfo->pTableQInfo->lastKey, pInfo->pTableQInfo->win.ekey}, .twindow = {item->info->lastKey, item->info->win.ekey},
.order = pQuery->order.order, .order = pQuery->order.order,
.colList = pQuery->colList, .colList = pQuery->colList,
.numOfCols = pQuery->numOfCols, .numOfCols = pQuery->numOfCols,
}; };
SArray *g1 = taosArrayInit(1, POINTER_BYTES); SArray *g1 = taosArrayInit(1, POINTER_BYTES);
SArray *tx = taosArrayInit(1, sizeof(SPair)); SArray *tx = taosArrayInit(1, sizeof(STableId));
taosArrayPush(tx, p); taosArrayPush(tx, &item->info->id);
taosArrayPush(g1, &tx); taosArrayPush(g1, &tx);
STableGroupInfo gp = {.numOfTables = 1, .pGroupList = g1}; STableGroupInfo gp = {.numOfTables = 1, .pGroupList = g1};
...@@ -4452,7 +4462,7 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) { ...@@ -4452,7 +4462,7 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) {
taosArrayDestroy(g1); taosArrayDestroy(g1);
if (pRuntimeEnv->pTSBuf != NULL) { if (pRuntimeEnv->pTSBuf != NULL) {
if (pRuntimeEnv->cur.vnodeIndex == -1) { if (pRuntimeEnv->cur.vgroupIndex == -1) {
int64_t tag = pRuntimeEnv->pCtx[0].tag.i64Key; int64_t tag = pRuntimeEnv->pCtx[0].tag.i64Key;
STSElem elem = tsBufGetElemStartPos(pRuntimeEnv->pTSBuf, 0, tag); STSElem elem = tsBufGetElemStartPos(pRuntimeEnv->pTSBuf, 0, tag);
...@@ -4469,22 +4479,16 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) { ...@@ -4469,22 +4479,16 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) {
return true; return true;
} }
static UNUSED_FUNC int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, int32_t start) { static UNUSED_FUNC int64_t doCheckTables(SQInfo *pQInfo, SArray* pTableList) {
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
if (!multiTableMultioutputHelper(pQInfo, index)) { if (!multiTableMultioutputHelper(pQInfo, 0)) {
return 0; return 0;
} }
SPointInterpoSupporter pointInterpSupporter = {0}; SPointInterpoSupporter pointInterpSupporter = {0};
pointInterpSupporterInit(pQuery, &pointInterpSupporter); pointInterpSupporterInit(pQuery, &pointInterpSupporter);
assert(0);
// if (!normalizedFirstQueryRange(dataInDisk, dataInCache, pSupporter, &pointInterpSupporter, NULL)) {
// pointInterpSupporterDestroy(&pointInterpSupporter);
// return 0;
// }
/* /*
* here we set the value for before and after the specified time into the * here we set the value for before and after the specified time into the
...@@ -4528,64 +4532,53 @@ static void sequentialTableProcess(SQInfo *pQInfo) { ...@@ -4528,64 +4532,53 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
resetCtxOutputBuf(pRuntimeEnv); resetCtxOutputBuf(pRuntimeEnv);
assert(pQuery->limit.offset == 0 && pQuery->limit.limit != 0); assert(pQuery->limit.offset == 0 && pQuery->limit.limit != 0);
#if 0
while (pQInfo->groupIndex < numOfGroups) { while (pQInfo->groupIndex < numOfGroups) {
SArray* group = taosArrayGetP(pQInfo->groupInfo.pGroupList, pQInfo->groupIndex); SArray* group = taosArrayGetP(pQInfo->groupInfo.pGroupList, pQInfo->groupIndex);
size_t numOfTable = taosArrayGetSize(group);
if (isFirstLastRowQuery(pQuery)) { if (isFirstLastRowQuery(pQuery)) {
qTrace("QInfo:%p last_row query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid, pTableIdList->numOfSubSet, qTrace("QInfo:%p last_row query on group:%d, total group:%d, current group:%d", pQInfo, pQInfo->groupIndex,
pQInfo->groupIndex); numOfGroups);
TSKEY key = -1; STsdbQueryCond cond = {
int32_t index = -1; .twindow = pQuery->window,
.colList = pQuery->colList,
// choose the last key for one group .order = pQuery->order.order,
pQInfo->tableIndex = 0; .numOfCols = pQuery->numOfCols,
};
for (int32_t k = 0; k < numOfTable; ++k, pQInfo->tableIndex++) {
if (isQueryKilled(pQInfo)) {
return;
}
}
pQuery->window.skey = key; SArray *g1 = taosArrayInit(1, POINTER_BYTES);
pQuery->window.ekey = key; SArray *tx = taosArrayClone(group);
taosArrayPush(g1, &tx);
// int64_t num = doCheckMetersInGroup(pQInfo, index, start); STableGroupInfo gp = {.numOfTables = taosArrayGetSize(tx), .pGroupList = g1};
// assert(num >= 0);
} else {
qTrace("QInfo:%p interp query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid, pTableIdList->numOfSubSet,
pQInfo->groupIndex);
for (int32_t k = start; k <= end; ++k) { // include only current table
if (isQueryKilled(pQInfo)) { if (pRuntimeEnv->pQueryHandle != NULL) {
setQueryStatus(pQuery, QUERY_NO_DATA_TO_CHECK); tsdbCleanupQueryHandle(pRuntimeEnv->pQueryHandle);
return; pRuntimeEnv->pQueryHandle = NULL;
} }
pQuery->skey = pSupporter->rawSKey; pRuntimeEnv->pQueryHandle = tsdbQueryLastRow(pQInfo->tsdb, &cond, &gp);
pQuery->ekey = pSupporter->rawEKey;
int64_t num = doCheckMetersInGroup(pQInfo, k, start); initCtxOutputBuf(pRuntimeEnv);
if (num == 1) { setTagVal(pRuntimeEnv, (STableId*) taosArrayGet(tx, 0), pQInfo->tsdb);
break; scanAllDataBlocks(pRuntimeEnv);
}
} int64_t numOfRes = getNumOfResult(pRuntimeEnv);
if (numOfRes > 0) {
pQuery->rec.rows += numOfRes;
forwardCtxOutputBuf(pRuntimeEnv, numOfRes);
} }
pSupporter->groupIndex++; skipResults(pRuntimeEnv);
pQInfo->groupIndex += 1;
// output buffer is full, return to client // enable execution for next table, when handling the projection query
if (pQuery->size >= pQuery->pointsToRead) { enableExecutionForNextTable(pRuntimeEnv);
break;
} }
} }
#endif
} else { } else {
createTableDataInfo(pQInfo); createTableQueryInfo(pQInfo);
/* /*
* 1. super table projection query, 2. group-by on normal columns query, 3. ts-comp query * 1. super table projection query, 2. group-by on normal columns query, 3. ts-comp query
...@@ -4618,12 +4611,11 @@ static void sequentialTableProcess(SQInfo *pQInfo) { ...@@ -4618,12 +4611,11 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
return; return;
} }
SPair * p = taosArrayGet(group, pQInfo->tableIndex); SGroupItem *item = taosArrayGet(group, pQInfo->tableIndex);
STableDataInfo *pInfo = p->sec;
TSKEY skey = pInfo->pTableQInfo->lastKey; STableQueryInfo *pInfo = item->info;
if (skey > 0) { if (pInfo->lastKey > 0) {
pQuery->window.skey = skey; pQuery->window.skey = pInfo->lastKey;
} }
if (!multiTableMultioutputHelper(pQInfo, pQInfo->tableIndex)) { if (!multiTableMultioutputHelper(pQInfo, pQInfo->tableIndex)) {
...@@ -4665,7 +4657,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) { ...@@ -4665,7 +4657,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
* to ensure that, we can reset the query range once query on a meter is completed. * to ensure that, we can reset the query range once query on a meter is completed.
*/ */
pQInfo->tableIndex++; pQInfo->tableIndex++;
pInfo->pTableQInfo->lastKey = pQuery->lastKey; pInfo->lastKey = pQuery->lastKey;
// if the buffer is full or group by each table, we need to jump out of the loop // if the buffer is full or group by each table, we need to jump out of the loop
if (Q_STATUS_EQUAL(pQuery->status, QUERY_RESBUF_FULL) /*|| if (Q_STATUS_EQUAL(pQuery->status, QUERY_RESBUF_FULL) /*||
...@@ -4731,13 +4723,12 @@ static void sequentialTableProcess(SQInfo *pQInfo) { ...@@ -4731,13 +4723,12 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
pQuery->rec.total += pQuery->rec.rows; pQuery->rec.total += pQuery->rec.rows;
qTrace( qTrace(
"QInfo %p, numOfTables:%d, index:%d, numOfGroups:%d, %d points returned, total:%d totalReturn:%d," "QInfo %p, numOfTables:%d, index:%d, numOfGroups:%d, %d points returned, total:%"PRId64", offset:%" PRId64,
" offset:%" PRId64,
pQInfo, pQInfo->groupInfo.numOfTables, pQInfo->tableIndex, numOfGroups, pQuery->rec.rows, pQuery->rec.total, pQInfo, pQInfo->groupInfo.numOfTables, pQInfo->tableIndex, numOfGroups, pQuery->rec.rows, pQuery->rec.total,
pQuery->limit.offset); pQuery->limit.offset);
} }
static void createTableDataInfo(SQInfo *pQInfo) { static void createTableQueryInfo(SQInfo *pQInfo) {
SQuery *pQuery = pQInfo->runtimeEnv.pQuery; SQuery *pQuery = pQInfo->runtimeEnv.pQuery;
// todo make sure the table are added the reference count to gauranteed that all involved tables are valid // todo make sure the table are added the reference count to gauranteed that all involved tables are valid
...@@ -4749,21 +4740,18 @@ static void createTableDataInfo(SQInfo *pQInfo) { ...@@ -4749,21 +4740,18 @@ static void createTableDataInfo(SQInfo *pQInfo) {
size_t s = taosArrayGetSize(group); size_t s = taosArrayGetSize(group);
for (int32_t j = 0; j < s; ++j) { for (int32_t j = 0; j < s; ++j) {
SPair *p = (SPair *)taosArrayGet(group, j); SGroupItem* item = (SGroupItem *)taosArrayGet(group, j);
// STableDataInfo has been created for each table // STableQueryInfo has been created for each table
if (p->sec != NULL) { // todo refactor if (item->info != NULL) {
return; return;
} }
STableDataInfo *pInfo = calloc(1, sizeof(STableDataInfo)); STableQueryInfo* pInfo = createTableQueryInfoImpl(&pQInfo->runtimeEnv, item->id, pQuery->window);
pInfo->groupIdx = i;
setTableDataInfo(pInfo, index, i); pInfo->tableIndex = index;
pInfo->pTableQInfo =
createTableQueryInfo(&pQInfo->runtimeEnv, ((STable *)(p->first))->tableId.tid, pQuery->window);
p->sec = pInfo;
item->info = pInfo;
index += 1; index += 1;
} }
} }
...@@ -4773,7 +4761,7 @@ static void prepareQueryInfoForReverseScan(SQInfo *pQInfo) { ...@@ -4773,7 +4761,7 @@ static void prepareQueryInfoForReverseScan(SQInfo *pQInfo) {
// SQuery *pQuery = pQInfo->runtimeEnv.pQuery; // SQuery *pQuery = pQInfo->runtimeEnv.pQuery;
// for (int32_t i = 0; i < pQInfo->groupInfo.numOfTables; ++i) { // for (int32_t i = 0; i < pQInfo->groupInfo.numOfTables; ++i) {
// STableQueryInfo *pTableQueryInfo = pQInfo->pTableDataInfo[i].pTableQInfo; // STableQueryInfo *pTableQueryInfo = pQInfo->pTableQueryInfo[i].pTableQInfo;
// changeMeterQueryInfoForSuppleQuery(pQuery, pTableQueryInfo); // changeMeterQueryInfoForSuppleQuery(pQuery, pTableQueryInfo);
// } // }
} }
...@@ -4811,20 +4799,14 @@ static void doCloseAllTimeWindowAfterScan(SQInfo *pQInfo) { ...@@ -4811,20 +4799,14 @@ static void doCloseAllTimeWindowAfterScan(SQInfo *pQInfo) {
SQuery *pQuery = pQInfo->runtimeEnv.pQuery; SQuery *pQuery = pQInfo->runtimeEnv.pQuery;
if (isIntervalQuery(pQuery)) { if (isIntervalQuery(pQuery)) {
// for (int32_t i = 0; i < pQInfo->groupInfo.numOfTables; ++i) {
// STableQueryInfo *pTableQueryInfo = pQInfo->pTableDataInfo[i].pTableQInfo;
// closeAllTimeWindow(&pTableQueryInfo->windowResInfo);
// }
size_t numOfGroup = taosArrayGetSize(pQInfo->groupInfo.pGroupList); size_t numOfGroup = taosArrayGetSize(pQInfo->groupInfo.pGroupList);
for (int32_t i = 0; i < numOfGroup; ++i) { for (int32_t i = 0; i < numOfGroup; ++i) {
SArray *group = taosArrayGetP(pQInfo->groupInfo.pGroupList, i); SArray *group = taosArrayGetP(pQInfo->groupInfo.pGroupList, i);
size_t num = taosArrayGetSize(group); size_t num = taosArrayGetSize(group);
for (int32_t j = 0; j < num; ++j) { for (int32_t j = 0; j < num; ++j) {
SPair * p = taosArrayGet(group, j); SGroupItem* item = taosArrayGet(group, j);
STableDataInfo *pInfo = p->sec; closeAllTimeWindow(&item->info->windowResInfo);
closeAllTimeWindow(&pInfo->pTableQInfo->windowResInfo);
} }
} }
} else { // close results for group result } else { // close results for group result
...@@ -4865,12 +4847,11 @@ static void multiTableQueryProcess(SQInfo *pQInfo) { ...@@ -4865,12 +4847,11 @@ static void multiTableQueryProcess(SQInfo *pQInfo) {
pQuery->window.skey, pQuery->window.ekey, pQuery->order.order); pQuery->window.skey, pQuery->window.ekey, pQuery->order.order);
// create the query support structures // create the query support structures
createTableDataInfo(pQInfo); createTableQueryInfo(pQInfo);
// do check all qualified data blocks // do check all qualified data blocks
int64_t el = queryOnDataBlocks(pQInfo); int64_t el = queryOnDataBlocks(pQInfo);
qTrace("QInfo:%p forward scan completed, elapsed time: %lldms, reversed scan start, order:%d", pQInfo, el, qTrace("QInfo:%p forward scan completed, elapsed time: %lldms, reversed scan start", pQInfo, el);
pQuery->order.order ^ 1u);
// query error occurred or query is killed, abort current execution // query error occurred or query is killed, abort current execution
if (pQInfo->code != TSDB_CODE_SUCCESS || isQueryKilled(pQInfo)) { if (pQInfo->code != TSDB_CODE_SUCCESS || isQueryKilled(pQInfo)) {
...@@ -4900,8 +4881,6 @@ static void multiTableQueryProcess(SQInfo *pQInfo) { ...@@ -4900,8 +4881,6 @@ static void multiTableQueryProcess(SQInfo *pQInfo) {
} }
if (isIntervalQuery(pQuery) || isSumAvgRateQuery(pQuery)) { if (isIntervalQuery(pQuery) || isSumAvgRateQuery(pQuery)) {
// assert(pSupporter->groupIndex == 0 && pSupporter->numOfGroupResultPages == 0);
if (mergeIntoGroupResult(pQInfo) == TSDB_CODE_SUCCESS) { if (mergeIntoGroupResult(pQInfo) == TSDB_CODE_SUCCESS) {
copyResToQueryResultBuf(pQInfo, pQuery); copyResToQueryResultBuf(pQInfo, pQuery);
...@@ -5112,7 +5091,6 @@ static void tableQueryImpl(SQInfo *pQInfo) { ...@@ -5112,7 +5091,6 @@ static void tableQueryImpl(SQInfo *pQInfo) {
pQInfo->pointsInterpo += numOfInterpo; pQInfo->pointsInterpo += numOfInterpo;
qTrace("QInfo:%p current:%d returned, total:%d", pQInfo, pQuery->rec.rows, pQuery->rec.total); qTrace("QInfo:%p current:%d returned, total:%d", pQInfo, pQuery->rec.rows, pQuery->rec.total);
sem_post(&pQInfo->dataReady);
return; return;
} }
...@@ -5133,7 +5111,6 @@ static void tableQueryImpl(SQInfo *pQInfo) { ...@@ -5133,7 +5111,6 @@ static void tableQueryImpl(SQInfo *pQInfo) {
if (pQuery->rec.rows > 0) { if (pQuery->rec.rows > 0) {
qTrace("QInfo:%p %d rows returned from group results, total:%d", pQInfo, pQuery->rec.rows, pQuery->rec.total); qTrace("QInfo:%p %d rows returned from group results, total:%d", pQInfo, pQuery->rec.rows, pQuery->rec.total);
sem_post(&pQInfo->dataReady);
return; return;
} }
} }
...@@ -5141,7 +5118,6 @@ static void tableQueryImpl(SQInfo *pQInfo) { ...@@ -5141,7 +5118,6 @@ static void tableQueryImpl(SQInfo *pQInfo) {
qTrace("QInfo:%p query over, %d rows are returned", pQInfo, pQuery->rec.total); qTrace("QInfo:%p query over, %d rows are returned", pQInfo, pQuery->rec.total);
// vnodePrintQueryStatistics(pSupporter); // vnodePrintQueryStatistics(pSupporter);
sem_post(&pQInfo->dataReady);
return; return;
} }
...@@ -5166,14 +5142,12 @@ static void tableQueryImpl(SQInfo *pQInfo) { ...@@ -5166,14 +5142,12 @@ static void tableQueryImpl(SQInfo *pQInfo) {
/* check if query is killed or not */ /* check if query is killed or not */
if (isQueryKilled(pQInfo)) { if (isQueryKilled(pQInfo)) {
qTrace("QInfo:%p query is killed", pQInfo); qTrace("QInfo:%p query is killed", pQInfo);
} else { } else {// todo set the table uid and tid in log
// STableId* pTableId = taosArrayGet(pQInfo->groupInfo, 0); // SArray* p = taosArrayGetP(pQInfo->groupInfo.pGroupList, 0);
// qTrace("QInfo:%p uid:%" PRIu64 " tid:%d, query completed, %" PRId64 " rows returned, numOfTotal:%" PRId64 " // SPair* pair = taosArrayGet(p, 0);
// rows", qTrace("QInfo:%p query paused, %" PRId64 " rows returned, numOfTotal:%" PRId64 " rows",
// pQInfo, pTableId->uid, pTableId->tid, pQuery->rec.rows, pQuery->rec.total + pQuery->rec.rows); pQInfo, pQuery->rec.rows, pQuery->rec.total + pQuery->rec.rows);
} }
sem_post(&pQInfo->dataReady);
} }
static void stableQueryImpl(SQInfo *pQInfo) { static void stableQueryImpl(SQInfo *pQInfo) {
...@@ -5201,8 +5175,6 @@ static void stableQueryImpl(SQInfo *pQInfo) { ...@@ -5201,8 +5175,6 @@ static void stableQueryImpl(SQInfo *pQInfo) {
pQuery->rec.total); pQuery->rec.total);
// vnodePrintQueryStatistics(pSupporter); // vnodePrintQueryStatistics(pSupporter);
} }
sem_post(&pQInfo->dataReady);
} }
static int32_t getColumnIndexInSource(SQueryTableMsg *pQueryMsg, SSqlFuncMsg *pExprMsg, SColumnInfo* pTagCols) { static int32_t getColumnIndexInSource(SQueryTableMsg *pQueryMsg, SSqlFuncMsg *pExprMsg, SColumnInfo* pTagCols) {
...@@ -5235,33 +5207,44 @@ bool validateExprColumnInfo(SQueryTableMsg *pQueryMsg, SSqlFuncMsg *pExprMsg, SC ...@@ -5235,33 +5207,44 @@ bool validateExprColumnInfo(SQueryTableMsg *pQueryMsg, SSqlFuncMsg *pExprMsg, SC
return j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags; return j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags;
} }
static int32_t validateQueryMsg(SQueryTableMsg *pQueryMsg) { static bool validateQueryMsg(SQueryTableMsg *pQueryMsg) {
if (pQueryMsg->intervalTime < 0) { if (pQueryMsg->intervalTime < 0) {
qError("qmsg:%p illegal value of aggTimeInterval %" PRId64 "", pQueryMsg, pQueryMsg->intervalTime); qError("qmsg:%p illegal value of interval time %" PRId64 "", pQueryMsg, pQueryMsg->intervalTime);
return -1; return false;
}
if (pQueryMsg->numOfCols <= 0 || pQueryMsg->numOfCols > TSDB_MAX_COLUMNS) {
qError("qmsg:%p illegal value of numOfCols %d", pQueryMsg, pQueryMsg->numOfCols);
return -1;
} }
if (pQueryMsg->numOfTables <= 0) { if (pQueryMsg->numOfTables <= 0) {
qError("qmsg:%p illegal value of numOfTables %d", pQueryMsg, pQueryMsg->numOfTables); qError("qmsg:%p illegal value of numOfTables %d", pQueryMsg, pQueryMsg->numOfTables);
return -1; return false;
} }
if (pQueryMsg->numOfGroupCols < 0) { if (pQueryMsg->numOfGroupCols < 0) {
qError("qmsg:%p illegal value of numOfGroupbyCols %d", pQueryMsg, pQueryMsg->numOfGroupCols); qError("qmsg:%p illegal value of numOfGroupbyCols %d", pQueryMsg, pQueryMsg->numOfGroupCols);
return -1; return false;
} }
if (pQueryMsg->numOfOutput > TSDB_MAX_COLUMNS || pQueryMsg->numOfOutput <= 0) { if (pQueryMsg->numOfOutput > TSDB_MAX_COLUMNS || pQueryMsg->numOfOutput <= 0) {
qError("qmsg:%p illegal value of output columns %d", pQueryMsg, pQueryMsg->numOfOutput); qError("qmsg:%p illegal value of output columns %d", pQueryMsg, pQueryMsg->numOfOutput);
return -1; return false;
} }
return 0; return true;
}
static bool validateQuerySourceCols(SQueryTableMsg *pQueryMsg, SSqlFuncMsg** pExprMsg) {
int32_t numOfTotal = pQueryMsg->numOfCols + pQueryMsg->numOfTags;
if (pQueryMsg->numOfCols < 0 || pQueryMsg->numOfTags < 0 || numOfTotal > TSDB_MAX_COLUMNS) {
qError("qmsg:%p illegal value of numOfCols %d numOfTags:%d", pQueryMsg, pQueryMsg->numOfCols, pQueryMsg->numOfTags);
return false;
} else if (numOfTotal == 0) {
for(int32_t i = 0; i < pQueryMsg->numOfOutput; ++i) {
if (pExprMsg[i]->functionId != TSDB_FUNC_TAGPRJ) {
return false;
}
}
}
return true;
} }
static char *createTableIdList(SQueryTableMsg *pQueryMsg, char *pMsg, SArray **pTableIdList) { static char *createTableIdList(SQueryTableMsg *pQueryMsg, char *pMsg, SArray **pTableIdList) {
...@@ -5270,11 +5253,11 @@ static char *createTableIdList(SQueryTableMsg *pQueryMsg, char *pMsg, SArray **p ...@@ -5270,11 +5253,11 @@ static char *createTableIdList(SQueryTableMsg *pQueryMsg, char *pMsg, SArray **p
*pTableIdList = taosArrayInit(pQueryMsg->numOfTables, sizeof(STableId)); *pTableIdList = taosArrayInit(pQueryMsg->numOfTables, sizeof(STableId));
STableIdInfo *pTableIdInfo = (STableIdInfo *)pMsg; STableIdInfo *pTableIdInfo = (STableIdInfo *)pMsg;
pTableIdInfo->sid = htonl(pTableIdInfo->sid); pTableIdInfo->tid = htonl(pTableIdInfo->tid);
pTableIdInfo->uid = htobe64(pTableIdInfo->uid); pTableIdInfo->uid = htobe64(pTableIdInfo->uid);
pTableIdInfo->key = htobe64(pTableIdInfo->key); pTableIdInfo->key = htobe64(pTableIdInfo->key);
STableId id = {.uid = pTableIdInfo->uid, .tid = pTableIdInfo->sid}; STableId id = {.uid = pTableIdInfo->uid, .tid = pTableIdInfo->tid};
taosArrayPush(*pTableIdList, &id); taosArrayPush(*pTableIdList, &id);
pMsg += sizeof(STableIdInfo); pMsg += sizeof(STableIdInfo);
...@@ -5282,7 +5265,7 @@ static char *createTableIdList(SQueryTableMsg *pQueryMsg, char *pMsg, SArray **p ...@@ -5282,7 +5265,7 @@ static char *createTableIdList(SQueryTableMsg *pQueryMsg, char *pMsg, SArray **p
for (int32_t j = 1; j < pQueryMsg->numOfTables; ++j) { for (int32_t j = 1; j < pQueryMsg->numOfTables; ++j) {
pTableIdInfo = (STableIdInfo *)pMsg; pTableIdInfo = (STableIdInfo *)pMsg;
pTableIdInfo->sid = htonl(pTableIdInfo->sid); pTableIdInfo->tid = htonl(pTableIdInfo->tid);
pTableIdInfo->uid = htobe64(pTableIdInfo->uid); pTableIdInfo->uid = htobe64(pTableIdInfo->uid);
pTableIdInfo->key = htobe64(pTableIdInfo->key); pTableIdInfo->key = htobe64(pTableIdInfo->key);
...@@ -5328,7 +5311,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, ...@@ -5328,7 +5311,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
pQueryMsg->numOfTags = htonl(pQueryMsg->numOfTags); pQueryMsg->numOfTags = htonl(pQueryMsg->numOfTags);
// query msg safety check // query msg safety check
if (validateQueryMsg(pQueryMsg) != 0) { if (!validateQueryMsg(pQueryMsg)) {
return TSDB_CODE_INVALID_QUERY_MSG; return TSDB_CODE_INVALID_QUERY_MSG;
} }
...@@ -5413,6 +5396,12 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, ...@@ -5413,6 +5396,12 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
pExprMsg = (SSqlFuncMsg *)pMsg; pExprMsg = (SSqlFuncMsg *)pMsg;
} }
if (!validateQuerySourceCols(pQueryMsg, *pExpr)) {
tfree(*pExpr);
return TSDB_CODE_INVALID_QUERY_MSG;
}
pMsg = createTableIdList(pQueryMsg, pMsg, pTableIdList); pMsg = createTableIdList(pQueryMsg, pMsg, pTableIdList);
if (pQueryMsg->numOfGroupCols > 0) { // group by tag columns if (pQueryMsg->numOfGroupCols > 0) { // group by tag columns
...@@ -5477,10 +5466,8 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, ...@@ -5477,10 +5466,8 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
pMsg += len; pMsg += len;
} }
qTrace("qmsg:%p query on %d table(s), qrange:%" PRId64 "-%" PRId64 qTrace("qmsg:%p query %d tables, qrange:%" PRId64 "-%" PRId64 ", numOfGroupbyTagCols:%d, order:%d, "
", numOfGroupbyTagCols:%d, ts order:%d, " "outputCols:%d, numOfCols:%d, interval:%" PRId64 ", fillType:%d, comptsLen:%d, limit:%" PRId64 ", offset:%" PRId64,
"outputCols:%d, numOfCols:%d, interval:%d" PRId64 ", fillType:%d, comptsLen:%d, limit:%" PRId64
", offset:%" PRId64,
pQueryMsg, pQueryMsg->numOfTables, pQueryMsg->window.skey, pQueryMsg->window.ekey, pQueryMsg->numOfGroupCols, pQueryMsg, pQueryMsg->numOfTables, pQueryMsg->window.skey, pQueryMsg->window.ekey, pQueryMsg->numOfGroupCols,
pQueryMsg->order, pQueryMsg->numOfOutput, pQueryMsg->numOfCols, pQueryMsg->intervalTime, pQueryMsg->order, pQueryMsg->numOfOutput, pQueryMsg->numOfCols, pQueryMsg->intervalTime,
pQueryMsg->interpoType, pQueryMsg->tsLen, pQueryMsg->limit, pQueryMsg->offset); pQueryMsg->interpoType, pQueryMsg->tsLen, pQueryMsg->limit, pQueryMsg->offset);
...@@ -5488,10 +5475,17 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, ...@@ -5488,10 +5475,17 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
return 0; return 0;
} }
static int32_t buildAirthmeticExprFromMsg(SArithExprInfo *pArithExprInfo, SQueryTableMsg *pQueryMsg) { static int32_t buildAirthmeticExprFromMsg(SExprInfo *pArithExprInfo, SQueryTableMsg *pQueryMsg) {
qTrace("qmsg:%p create arithmetic expr from binary string", pQueryMsg, pArithExprInfo->base.arg[0].argValue.pz); qTrace("qmsg:%p create arithmetic expr from binary string", pQueryMsg, pArithExprInfo->base.arg[0].argValue.pz);
tExprNode* pExprNode = exprTreeFromBinary(pArithExprInfo->base.arg[0].argValue.pz, pArithExprInfo->base.arg[0].argBytes); tExprNode* pExprNode = NULL;
TRY(32) {
pExprNode = exprTreeFromBinary(pArithExprInfo->base.arg[0].argValue.pz, pArithExprInfo->base.arg[0].argBytes);
} CATCH( code ) {
CLEANUP_EXECUTE();
return code;
} END_TRY
if (pExprNode == NULL) { if (pExprNode == NULL) {
qError("qmsg:%p failed to create arithmetic expression string from:%s", pQueryMsg, pArithExprInfo->base.arg[0].argValue.pz); qError("qmsg:%p failed to create arithmetic expression string from:%s", pQueryMsg, pArithExprInfo->base.arg[0].argValue.pz);
return TSDB_CODE_APP_ERROR; return TSDB_CODE_APP_ERROR;
...@@ -5501,12 +5495,12 @@ static int32_t buildAirthmeticExprFromMsg(SArithExprInfo *pArithExprInfo, SQuery ...@@ -5501,12 +5495,12 @@ static int32_t buildAirthmeticExprFromMsg(SArithExprInfo *pArithExprInfo, SQuery
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t createSqlFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SArithExprInfo **pSqlFuncExpr, static int32_t createSqlFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo **pSqlFuncExpr,
SSqlFuncMsg **pExprMsg, SColumnInfo* pTagCols) { SSqlFuncMsg **pExprMsg, SColumnInfo* pTagCols) {
*pSqlFuncExpr = NULL; *pSqlFuncExpr = NULL;
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SArithExprInfo *pExprs = (SArithExprInfo *)calloc(1, sizeof(SArithExprInfo) * pQueryMsg->numOfOutput); SExprInfo *pExprs = (SExprInfo *)calloc(1, sizeof(SExprInfo) * pQueryMsg->numOfOutput);
if (pExprs == NULL) { if (pExprs == NULL) {
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_SERV_OUT_OF_MEMORY;
} }
...@@ -5537,7 +5531,7 @@ static int32_t createSqlFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SArithExp ...@@ -5537,7 +5531,7 @@ static int32_t createSqlFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SArithExp
bytes = TSDB_TABLE_NAME_LEN; bytes = TSDB_TABLE_NAME_LEN;
} else{ } else{
int32_t j = getColumnIndexInSource(pQueryMsg, &pExprs[i].base, pTagCols); int32_t j = getColumnIndexInSource(pQueryMsg, &pExprs[i].base, pTagCols);
assert(j < pQueryMsg->numOfCols); assert(j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags);
SColumnInfo* pCol = (TSDB_COL_IS_TAG(pExprs[i].base.colInfo.flag))? &pTagCols[j]:&pQueryMsg->colList[j]; SColumnInfo* pCol = (TSDB_COL_IS_TAG(pExprs[i].base.colInfo.flag))? &pTagCols[j]:&pQueryMsg->colList[j];
type = pCol->type; type = pCol->type;
...@@ -5720,7 +5714,7 @@ static void doUpdateExprColumnIndex(SQuery *pQuery) { ...@@ -5720,7 +5714,7 @@ static void doUpdateExprColumnIndex(SQuery *pQuery) {
} }
} }
static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGroupbyExpr, SArithExprInfo *pExprs, static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGroupbyExpr, SExprInfo *pExprs,
STableGroupInfo *groupInfo, SColumnInfo* pTagCols) { STableGroupInfo *groupInfo, SColumnInfo* pTagCols) {
SQInfo *pQInfo = (SQInfo *)calloc(1, sizeof(SQInfo)); SQInfo *pQInfo = (SQInfo *)calloc(1, sizeof(SQInfo));
if (pQInfo == NULL) { if (pQInfo == NULL) {
...@@ -5808,7 +5802,26 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou ...@@ -5808,7 +5802,26 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou
// to make sure third party won't overwrite this structure // to make sure third party won't overwrite this structure
pQInfo->signature = pQInfo; pQInfo->signature = pQInfo;
pQInfo->groupInfo = *groupInfo;
pQInfo->tableIdGroupInfo = *groupInfo;
size_t numOfGroups = taosArrayGetSize(groupInfo->pGroupList);
pQInfo->groupInfo.pGroupList = taosArrayInit(numOfGroups, POINTER_BYTES);
pQInfo->groupInfo.numOfTables = groupInfo->numOfTables;
for(int32_t i = 0; i < numOfGroups; ++i) {
SArray* pa = taosArrayGetP(groupInfo->pGroupList, i);
size_t s = taosArrayGetSize(pa);
SArray* p1 = taosArrayInit(s, sizeof(SGroupItem));
for(int32_t j = 0; j < s; ++j) {
SGroupItem item = { .id = *(STableId*) taosArrayGet(pa, j), .info = NULL, };
taosArrayPush(p1, &item);
}
taosArrayPush(pQInfo->groupInfo.pGroupList, &p1);
}
pQuery->pos = -1; pQuery->pos = -1;
...@@ -5861,7 +5874,8 @@ static bool isValidQInfo(void *param) { ...@@ -5861,7 +5874,8 @@ static bool isValidQInfo(void *param) {
} }
static void freeQInfo(SQInfo *pQInfo); static void freeQInfo(SQInfo *pQInfo);
static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, SQInfo *pQInfo, bool isSTable) {
static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, int32_t vgId, SQInfo *pQInfo, bool isSTable) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SQuery *pQuery = pQInfo->runtimeEnv.pQuery; SQuery *pQuery = pQInfo->runtimeEnv.pQuery;
...@@ -5879,14 +5893,14 @@ static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, SQInfo *pQInfo, ...@@ -5879,14 +5893,14 @@ static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, SQInfo *pQInfo,
(!QUERY_IS_ASC_QUERY(pQuery) && (pQuery->window.ekey > pQuery->window.skey))) { (!QUERY_IS_ASC_QUERY(pQuery) && (pQuery->window.ekey > pQuery->window.skey))) {
qTrace("QInfo:%p no result in time range %" PRId64 "-%" PRId64 ", order %d", pQInfo, pQuery->window.skey, qTrace("QInfo:%p no result in time range %" PRId64 "-%" PRId64 ", order %d", pQInfo, pQuery->window.skey,
pQuery->window.ekey, pQuery->order.order); pQuery->window.ekey, pQuery->order.order);
setQueryStatus(pQuery, QUERY_COMPLETED);
sem_post(&pQInfo->dataReady); sem_post(&pQInfo->dataReady);
setQueryStatus(pQuery, QUERY_COMPLETED);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
// filter the qualified // filter the qualified
if ((code = doInitQInfo(pQInfo, pTSBuf, tsdb, isSTable)) != TSDB_CODE_SUCCESS) { if ((code = doInitQInfo(pQInfo, pTSBuf, tsdb, vgId, isSTable)) != TSDB_CODE_SUCCESS) {
goto _error; goto _error;
} }
...@@ -5925,12 +5939,11 @@ static void freeQInfo(SQInfo *pQInfo) { ...@@ -5925,12 +5939,11 @@ static void freeQInfo(SQInfo *pQInfo) {
if (pQuery->pSelectExpr != NULL) { if (pQuery->pSelectExpr != NULL) {
for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { for (int32_t i = 0; i < pQuery->numOfOutput; ++i) {
// SExprInfo *pBinExprInfo = &pQuery->pSelectExpr[i].arithExprInfo; SExprInfo* pExprInfo = &pQuery->pSelectExpr[i];
// if (pBinExprInfo->numOfCols > 0) { if (pExprInfo->pExpr != NULL) {
// tfree(pBinExprInfo->pReqColumns); tExprTreeDestroy(&pExprInfo->pExpr, NULL);
// tExprTreeDestroy(&pBinExprInfo->pBinExpr, NULL); }
// }
} }
tfree(pQuery->pSelectExpr); tfree(pQuery->pSelectExpr);
...@@ -5947,15 +5960,24 @@ static void freeQInfo(SQInfo *pQInfo) { ...@@ -5947,15 +5960,24 @@ static void freeQInfo(SQInfo *pQInfo) {
size_t num = taosArrayGetSize(p); size_t num = taosArrayGetSize(p);
for(int32_t j = 0; j < num; ++j) { for(int32_t j = 0; j < num; ++j) {
SPair* pair = taosArrayGet(p, j); SGroupItem* item = taosArrayGet(p, j);
if (pair->sec != NULL) { if (item->info != NULL) {
destroyTableQueryInfo(((STableDataInfo*)pair->sec)->pTableQInfo, pQuery->numOfOutput); destroyTableQueryInfo(item->info, pQuery->numOfOutput);
tfree(pair->sec);
} }
} }
taosArrayDestroy(p); taosArrayDestroy(p);
} }
taosArrayDestroy(pQInfo->groupInfo.pGroupList);
for(int32_t i = 0; i < numOfGroups; ++i) {
SArray* p = taosArrayGetP(pQInfo->tableIdGroupInfo.pGroupList, i);
taosArrayDestroy(p);
}
taosArrayDestroy(pQInfo->tableIdGroupInfo.pGroupList);
if (pQuery->pGroupbyExpr != NULL) { if (pQuery->pGroupbyExpr != NULL) {
taosArrayDestroy(pQuery->pGroupbyExpr->columnInfo); taosArrayDestroy(pQuery->pGroupbyExpr->columnInfo);
tfree(pQuery->pGroupbyExpr); tfree(pQuery->pGroupbyExpr);
...@@ -5966,7 +5988,6 @@ static void freeQInfo(SQInfo *pQInfo) { ...@@ -5966,7 +5988,6 @@ static void freeQInfo(SQInfo *pQInfo) {
tfree(pQuery->colList); tfree(pQuery->colList);
tfree(pQuery->sdata); tfree(pQuery->sdata);
taosArrayDestroy(pQInfo->groupInfo.pGroupList);
tfree(pQuery); tfree(pQuery);
qTrace("QInfo:%p QInfo is freed", pQInfo); qTrace("QInfo:%p QInfo is freed", pQInfo);
...@@ -6017,9 +6038,15 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) { ...@@ -6017,9 +6038,15 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) {
unlink(pQuery->sdata[0]->data); unlink(pQuery->sdata[0]->data);
} else { } else {
// todo return the error code to client
qError("QInfo:%p failed to open tmp file to send ts-comp data to client, path:%s, reason:%s", pQInfo, qError("QInfo:%p failed to open tmp file to send ts-comp data to client, path:%s, reason:%s", pQInfo,
pQuery->sdata[0]->data, strerror(errno)); pQuery->sdata[0]->data, strerror(errno));
} }
// all data returned, set query over
if (Q_STATUS_EQUAL(pQuery->status, QUERY_COMPLETED)) {
setQueryStatus(pQuery, QUERY_OVER);
}
} else { } else {
doCopyQueryResultToMsg(pQInfo, pQuery->rec.rows, data); doCopyQueryResultToMsg(pQInfo, pQuery->rec.rows, data);
} }
...@@ -6032,7 +6059,7 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) { ...@@ -6032,7 +6059,7 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) {
// todo if interpolation exists, the result may be dump to client by several rounds // todo if interpolation exists, the result may be dump to client by several rounds
} }
int32_t qCreateQueryInfo(void *tsdb, SQueryTableMsg *pQueryMsg, qinfo_t *pQInfo) { int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qinfo_t *pQInfo) {
assert(pQueryMsg != NULL); assert(pQueryMsg != NULL);
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
...@@ -6060,7 +6087,7 @@ int32_t qCreateQueryInfo(void *tsdb, SQueryTableMsg *pQueryMsg, qinfo_t *pQInfo) ...@@ -6060,7 +6087,7 @@ int32_t qCreateQueryInfo(void *tsdb, SQueryTableMsg *pQueryMsg, qinfo_t *pQInfo)
goto _query_over; goto _query_over;
} }
SArithExprInfo *pExprs = NULL; SExprInfo *pExprs = NULL;
if ((code = createSqlFunctionExprFromMsg(pQueryMsg, &pExprs, pExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) { if ((code = createSqlFunctionExprFromMsg(pQueryMsg, &pExprs, pExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) {
goto _query_over; goto _query_over;
} }
...@@ -6073,11 +6100,16 @@ int32_t qCreateQueryInfo(void *tsdb, SQueryTableMsg *pQueryMsg, qinfo_t *pQInfo) ...@@ -6073,11 +6100,16 @@ int32_t qCreateQueryInfo(void *tsdb, SQueryTableMsg *pQueryMsg, qinfo_t *pQInfo)
bool isSTableQuery = false; bool isSTableQuery = false;
STableGroupInfo groupInfo = {0}; STableGroupInfo groupInfo = {0};
if ((pQueryMsg->queryType & TSDB_QUERY_TYPE_STABLE_QUERY) != 0) { if (TSDB_QUERY_HAS_TYPE(pQueryMsg->queryType, TSDB_QUERY_TYPE_MULTITABLE_QUERY|TSDB_QUERY_TYPE_TABLE_QUERY)) {
isSTableQuery = true; isSTableQuery = TSDB_QUERY_HAS_TYPE(pQueryMsg->queryType, TSDB_QUERY_TYPE_MULTITABLE_QUERY);
STableId *id = taosArrayGet(pTableIdList, 0); STableId *id = taosArrayGet(pTableIdList, 0);
id->uid = -1; // todo fix me if ((code = tsdbGetOneTableGroup(tsdb, id->uid, &groupInfo)) != TSDB_CODE_SUCCESS) {
goto _query_over;
}
} else if (TSDB_QUERY_HAS_TYPE(pQueryMsg->queryType, TSDB_QUERY_TYPE_STABLE_QUERY)) {
isSTableQuery = true;
STableId *id = taosArrayGet(pTableIdList, 0);
// group by normal column, do not pass the group by condition to tsdb to group table into different group // group by normal column, do not pass the group by condition to tsdb to group table into different group
int32_t numOfGroupByCols = pQueryMsg->numOfGroupCols; int32_t numOfGroupByCols = pQueryMsg->numOfGroupCols;
...@@ -6086,19 +6118,14 @@ int32_t qCreateQueryInfo(void *tsdb, SQueryTableMsg *pQueryMsg, qinfo_t *pQInfo) ...@@ -6086,19 +6118,14 @@ int32_t qCreateQueryInfo(void *tsdb, SQueryTableMsg *pQueryMsg, qinfo_t *pQInfo)
} }
// todo handle the error // todo handle the error
/*int32_t ret =*/tsdbQueryByTagsCond(tsdb, id->uid, tagCond, pQueryMsg->tagCondLen, pQueryMsg->tagNameRelType, tbnameCond, &groupInfo, pGroupColIndex, /*int32_t ret =*/tsdbQuerySTableByTagCond(tsdb, id->uid, tagCond, pQueryMsg->tagCondLen, pQueryMsg->tagNameRelType, tbnameCond, &groupInfo, pGroupColIndex,
numOfGroupByCols); numOfGroupByCols);
if (groupInfo.numOfTables == 0) { // no qualified tables no need to do query if (groupInfo.numOfTables == 0) { // no qualified tables no need to do query
code = TSDB_CODE_SUCCESS; code = TSDB_CODE_SUCCESS;
goto _query_over; goto _query_over;
} }
} else { } else {
assert(taosArrayGetSize(pTableIdList) == 1); assert(0);
STableId *id = taosArrayGet(pTableIdList, 0);
if ((code = tsdbGetOneTableGroup(tsdb, id->uid, &groupInfo)) != TSDB_CODE_SUCCESS) {
goto _query_over;
}
} }
(*pQInfo) = createQInfoImpl(pQueryMsg, pGroupbyExpr, pExprs, &groupInfo, pTagColumnInfo); (*pQInfo) = createQInfoImpl(pQueryMsg, pGroupbyExpr, pExprs, &groupInfo, pTagColumnInfo);
...@@ -6106,7 +6133,7 @@ int32_t qCreateQueryInfo(void *tsdb, SQueryTableMsg *pQueryMsg, qinfo_t *pQInfo) ...@@ -6106,7 +6133,7 @@ int32_t qCreateQueryInfo(void *tsdb, SQueryTableMsg *pQueryMsg, qinfo_t *pQInfo)
code = TSDB_CODE_SERV_OUT_OF_MEMORY; code = TSDB_CODE_SERV_OUT_OF_MEMORY;
} }
code = initQInfo(pQueryMsg, tsdb, *pQInfo, isSTableQuery); code = initQInfo(pQueryMsg, tsdb, vgId, *pQInfo, isSTableQuery);
_query_over: _query_over:
tfree(tagCond); tfree(tagCond);
...@@ -6115,7 +6142,7 @@ _query_over: ...@@ -6115,7 +6142,7 @@ _query_over:
// if failed to add ref for all meters in this query, abort current query // if failed to add ref for all meters in this query, abort current query
// atomic_fetch_add_32(&vnodeSelectReqNum, 1); // atomic_fetch_add_32(&vnodeSelectReqNum, 1);
return TSDB_CODE_SUCCESS; return code;
} }
void qDestroyQueryInfo(qinfo_t pQInfo) { void qDestroyQueryInfo(qinfo_t pQInfo) {
...@@ -6138,12 +6165,15 @@ void qTableQuery(qinfo_t qinfo) { ...@@ -6138,12 +6165,15 @@ void qTableQuery(qinfo_t qinfo) {
qTrace("QInfo:%p query task is launched", pQInfo); qTrace("QInfo:%p query task is launched", pQInfo);
if (pQInfo->runtimeEnv.stableQuery) { if (onlyQueryTags(pQInfo->runtimeEnv.pQuery)) {
buildTagQueryResult(pQInfo); // todo support the limit/offset
} else if (pQInfo->runtimeEnv.stableQuery) {
stableQueryImpl(pQInfo); stableQueryImpl(pQInfo);
} else { } else {
tableQueryImpl(pQInfo); tableQueryImpl(pQInfo);
} }
sem_post(&pQInfo->dataReady);
// vnodeDecRefCount(pQInfo); // vnodeDecRefCount(pQInfo);
} }
...@@ -6229,3 +6259,80 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co ...@@ -6229,3 +6259,80 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co
// pObj->qhandle = NULL; // pObj->qhandle = NULL;
// } // }
} }
static void buildTagQueryResult(SQInfo* pQInfo) {
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery;
size_t num = taosArrayGetSize(pQInfo->groupInfo.pGroupList);
assert(num == 1); // only one group
SArray* pa = taosArrayGetP(pQInfo->groupInfo.pGroupList, 0);
num = taosArrayGetSize(pa);
assert(num == pQInfo->groupInfo.numOfTables);
int16_t type, bytes;
int32_t functionId = pQuery->pSelectExpr[0].base.functionId;
if (functionId == TSDB_FUNC_TID_TAG) { // return the tags & table Id
assert(pQuery->numOfOutput == 1);
SExprInfo* pExprInfo = &pQuery->pSelectExpr[0];
int32_t rsize = pExprInfo->bytes;
char* data = NULL;
for(int32_t i = 0; i < num; ++i) {
SGroupItem* item = taosArrayGet(pa, i);
char* output = pQuery->sdata[0]->data + i * rsize;
*(int64_t*) output = item->id.uid; // memory align problem
output += sizeof(item->id.uid);
*(int32_t*) output = item->id.tid;
output += sizeof(item->id.tid);
*(int32_t*) output = pQInfo->vgId;
output += sizeof(pQInfo->vgId);
tsdbGetTableTagVal(pQInfo->tsdb, &item->id, pExprInfo->base.colInfo.colId, &type, &bytes, &data);
memcpy(output, data, bytes);
}
qTrace("QInfo:%p create (tableId, tag) info completed, rows:%d", pQInfo, num);
} else { // return only the tags|table name etc.
for(int32_t i = 0; i < num; ++i) {
SExprInfo* pExprInfo = pQuery->pSelectExpr;
SGroupItem* item = taosArrayGet(pa, i);
char* data = NULL;
for(int32_t j = 0; j < pQuery->numOfOutput; ++j) {
// todo check the return value, refactor codes
if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) {
tsdbGetTableName(pQInfo->tsdb, &item->id, &data);
char* dst = pQuery->sdata[j]->data + i * (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE);
STR_WITH_MAXSIZE_TO_VARSTR(dst, data, TSDB_TABLE_NAME_LEN);
tfree(data);
} else {// todo refactor, return the true length of binary|nchar data
tsdbGetTableTagVal(pQInfo->tsdb, &item->id, pExprInfo[j].base.colInfo.colId, &type, &bytes, &data);
assert(bytes == pExprInfo[j].bytes && type == pExprInfo[j].type);
char* dst = pQuery->sdata[j]->data + i * bytes;
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) {
memcpy(dst, data, varDataTLen(data));
} else {
memcpy(dst, data, bytes);
}
}
}
}
qTrace("QInfo:%p create tag values results completed, rows:%d", pQInfo, num);
}
pQuery->rec.rows = num;
setQueryStatus(pQuery, QUERY_COMPLETED);
}
...@@ -408,7 +408,7 @@ static int32_t toNchar(tVariant *pVariant, char **pDest, int32_t *pDestSize) { ...@@ -408,7 +408,7 @@ static int32_t toNchar(tVariant *pVariant, char **pDest, int32_t *pDestSize) {
if (*pDest == pVariant->pz) { if (*pDest == pVariant->pz) {
wchar_t *pWStr = calloc(1, (nLen + 1) * TSDB_NCHAR_SIZE); wchar_t *pWStr = calloc(1, (nLen + 1) * TSDB_NCHAR_SIZE);
taosMbsToUcs4(pDst, nLen, (char *)pWStr, (nLen + 1) * TSDB_NCHAR_SIZE); taosMbsToUcs4(pDst, nLen, (char *)pWStr, (nLen + 1) * TSDB_NCHAR_SIZE, NULL);
// free the binary buffer in the first place // free the binary buffer in the first place
if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { if (pVariant->nType == TSDB_DATA_TYPE_BINARY) {
...@@ -424,7 +424,7 @@ static int32_t toNchar(tVariant *pVariant, char **pDest, int32_t *pDestSize) { ...@@ -424,7 +424,7 @@ static int32_t toNchar(tVariant *pVariant, char **pDest, int32_t *pDestSize) {
pVariant->wpz = (wchar_t *)tmp; pVariant->wpz = (wchar_t *)tmp;
} else { } else {
taosMbsToUcs4(pDst, nLen, *pDest, (nLen + 1) * TSDB_NCHAR_SIZE); taosMbsToUcs4(pDst, nLen, *pDest, (nLen + 1) * TSDB_NCHAR_SIZE, NULL);
} }
return 0; return 0;
......
...@@ -10,7 +10,7 @@ namespace { ...@@ -10,7 +10,7 @@ namespace {
// simple test // simple test
void simpleTest() { void simpleTest() {
SDiskbasedResultBuf* pResultBuf = NULL; SDiskbasedResultBuf* pResultBuf = NULL;
int32_t ret = createDiskbasedResultBuffer(&pResultBuf, 1000, 64); int32_t ret = createDiskbasedResultBuffer(&pResultBuf, 1000, 64, NULL);
int32_t pageId = 0; int32_t pageId = 0;
int32_t groupId = 0; int32_t groupId = 0;
...@@ -26,7 +26,7 @@ void simpleTest() { ...@@ -26,7 +26,7 @@ void simpleTest() {
ASSERT_EQ(getNumOfResultBufGroupId(pResultBuf), 1); ASSERT_EQ(getNumOfResultBufGroupId(pResultBuf), 1);
destroyResultBuf(pResultBuf); destroyResultBuf(pResultBuf, NULL);
} }
} // namespace } // namespace
......
...@@ -146,7 +146,6 @@ void rpcAddConnIntoCache(void *handle, void *data, char *fqdn, uint16_t port, in ...@@ -146,7 +146,6 @@ void rpcAddConnIntoCache(void *handle, void *data, char *fqdn, uint16_t port, in
rpcUnlockCache(pCache->lockedBy+hash); rpcUnlockCache(pCache->lockedBy+hash);
pCache->total++; pCache->total++;
tTrace("%p %s:%hu:%d:%d:%p added into cache, connections:%d", data, fqdn, port, connType, hash, pNode, pCache->count[hash]); tTrace("%p %s:%hu:%d:%d:%p added into cache, connections:%d", data, fqdn, port, connType, hash, pNode, pCache->count[hash]);
return; return;
...@@ -202,6 +201,8 @@ void *rpcGetConnFromCache(void *handle, char *fqdn, uint16_t port, int8_t connTy ...@@ -202,6 +201,8 @@ void *rpcGetConnFromCache(void *handle, char *fqdn, uint16_t port, int8_t connTy
if (pData) { if (pData) {
tTrace("%p %s:%hu:%d:%d:%p retrieved from cache, connections:%d", pData, fqdn, port, connType, hash, pNode, pCache->count[hash]); tTrace("%p %s:%hu:%d:%d:%p retrieved from cache, connections:%d", pData, fqdn, port, connType, hash, pNode, pCache->count[hash]);
} else {
tTrace("%s:%hu:%d:%d failed to retrieve conn from cache, connections:%d", fqdn, port, connType, hash, pCache->count[hash]);
} }
return pData; return pData;
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include "rpcCache.h" #include "rpcCache.h"
#include "rpcTcp.h" #include "rpcTcp.h"
#include "rpcHead.h" #include "rpcHead.h"
#include "shash.h"
#define RPC_MSG_OVERHEAD (sizeof(SRpcReqContext) + sizeof(SRpcHead) + sizeof(SRpcDigest)) #define RPC_MSG_OVERHEAD (sizeof(SRpcReqContext) + sizeof(SRpcHead) + sizeof(SRpcDigest))
#define rpcHeadFromCont(cont) ((SRpcHead *) (cont - sizeof(SRpcHead))) #define rpcHeadFromCont(cont) ((SRpcHead *) (cont - sizeof(SRpcHead)))
...@@ -260,7 +262,9 @@ void *rpcOpen(const SRpcInit *pInit) { ...@@ -260,7 +262,9 @@ void *rpcOpen(const SRpcInit *pInit) {
} }
if (pRpc->connType == TAOS_CONN_SERVER) { if (pRpc->connType == TAOS_CONN_SERVER) {
pRpc->hash = taosHashInit(pRpc->sessions, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true); pRpc->hash = taosInitStrHash(pRpc->sessions, sizeof(pRpc), taosHashString);
// pRpc->hash = taosHashInit(pRpc->sessions, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true);
if (pRpc->hash == NULL) { if (pRpc->hash == NULL) {
tError("%s failed to init string hash", pRpc->label); tError("%s failed to init string hash", pRpc->label);
rpcClose(pRpc); rpcClose(pRpc);
...@@ -294,7 +298,8 @@ void rpcClose(void *param) { ...@@ -294,7 +298,8 @@ void rpcClose(void *param) {
(*taosCleanUpConn[pRpc->connType | RPC_CONN_TCP])(pRpc->tcphandle); (*taosCleanUpConn[pRpc->connType | RPC_CONN_TCP])(pRpc->tcphandle);
(*taosCleanUpConn[pRpc->connType])(pRpc->udphandle); (*taosCleanUpConn[pRpc->connType])(pRpc->udphandle);
taosHashCleanup(pRpc->hash); // taosHashCleanup(pRpc->hash);
taosCleanUpStrHash(pRpc->hash);
taosTmrCleanUp(pRpc->tmrCtrl); taosTmrCleanUp(pRpc->tmrCtrl);
taosIdPoolCleanUp(pRpc->idPool); taosIdPoolCleanUp(pRpc->idPool);
rpcCloseConnCache(pRpc->pCache); rpcCloseConnCache(pRpc->pCache);
...@@ -543,8 +548,9 @@ static void rpcCloseConn(void *thandle) { ...@@ -543,8 +548,9 @@ static void rpcCloseConn(void *thandle) {
if ( pRpc->connType == TAOS_CONN_SERVER) { if ( pRpc->connType == TAOS_CONN_SERVER) {
char hashstr[40] = {0}; char hashstr[40] = {0};
size_t size = sprintf(hashstr, "%x:%x:%x:%d", pConn->peerIp, pConn->linkUid, pConn->peerId, pConn->connType); /*size_t size = */sprintf(hashstr, "%x:%x:%x:%d", pConn->peerIp, pConn->linkUid, pConn->peerId, pConn->connType);
taosHashRemove(pRpc->hash, hashstr, size); // taosHashRemove(pRpc->hash, hashstr, size);
taosDeleteStrHash(pRpc->hash, hashstr);
rpcFreeMsg(pConn->pRspMsg); // it may have a response msg saved, but not request msg rpcFreeMsg(pConn->pRspMsg); // it may have a response msg saved, but not request msg
pConn->pRspMsg = NULL; pConn->pRspMsg = NULL;
...@@ -593,10 +599,12 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) { ...@@ -593,10 +599,12 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) {
char hashstr[40] = {0}; char hashstr[40] = {0};
SRpcHead *pHead = (SRpcHead *)pRecv->msg; SRpcHead *pHead = (SRpcHead *)pRecv->msg;
size_t size = sprintf(hashstr, "%x:%x:%x:%d", pRecv->ip, pHead->linkUid, pHead->sourceId, pRecv->connType); /*size_t size = */sprintf(hashstr, "%x:%x:%x:%d", pRecv->ip, pHead->linkUid, pHead->sourceId, pRecv->connType);
// check if it is already allocated // check if it is already allocated
SRpcConn **ppConn = (SRpcConn **)(taosHashGet(pRpc->hash, hashstr, size)); SRpcConn **ppConn = (SRpcConn **)(taosGetStrHashData(pRpc->hash, hashstr));
// SRpcConn **ppConn = (SRpcConn **)(taosHashGet(pRpc->hash, hashstr, size));
if (ppConn) pConn = *ppConn; if (ppConn) pConn = *ppConn;
if (pConn) return pConn; if (pConn) return pConn;
...@@ -630,7 +638,9 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) { ...@@ -630,7 +638,9 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) {
pConn->localPort = (pRpc->localPort + pRpc->index); pConn->localPort = (pRpc->localPort + pRpc->index);
} }
taosHashPut(pRpc->hash, hashstr, size, (char *)&pConn, POINTER_BYTES); taosAddStrHash(pRpc->hash, hashstr, (char *)&pConn);
// taosHashPut(pRpc->hash, hashstr, size, (char *)&pConn, POINTER_BYTES);
tTrace("%s %p, rpc connection is allocated, sid:%d id:%s port:%u", tTrace("%s %p, rpc connection is allocated, sid:%d id:%s port:%u",
pRpc->label, pConn, sid, pConn->user, pConn->localPort); pRpc->label, pConn, sid, pConn->user, pConn->localPort);
......
...@@ -225,35 +225,47 @@ STSchema * tsdbGetTableTagSchema(STsdbMeta *pMeta, STable *pTable) { ...@@ -225,35 +225,47 @@ STSchema * tsdbGetTableTagSchema(STsdbMeta *pMeta, STable *pTable) {
} }
} }
int32_t tsdbGetTableTagVal(TsdbRepoT* repo, STableId id, int32_t colId, int16_t* type, int16_t* bytes, char** val) { int32_t tsdbGetTableTagVal(TsdbRepoT* repo, STableId* id, int32_t colId, int16_t* type, int16_t* bytes, char** val) {
STsdbMeta* pMeta = tsdbGetMeta(repo); STsdbMeta* pMeta = tsdbGetMeta(repo);
STable* pTable = tsdbGetTableByUid(pMeta, id.uid); STable* pTable = tsdbGetTableByUid(pMeta, id->uid);
STSchema* pSchema = tsdbGetTableTagSchema(pMeta, pTable); STSchema* pSchema = tsdbGetTableTagSchema(pMeta, pTable);
STColumn* pCol = NULL; STColumn* pCol = NULL;
int32_t offset = 0;
for(int32_t col = 0; col < schemaNCols(pSchema); ++col) { for(int32_t col = 0; col < schemaNCols(pSchema); ++col) {
STColumn* p = schemaColAt(pSchema, col); STColumn* p = schemaColAt(pSchema, col);
if (p->colId == colId) { if (p->colId == colId) {
pCol = p; pCol = p;
break;
}
if (p->type == TSDB_DATA_TYPE_BINARY || p->type == TSDB_DATA_TYPE_NCHAR) {
offset += sizeof(int32_t);
} else {
offset += p->bytes;
} }
} }
if (pCol == NULL) {
return -1; // No matched tags. Maybe the modification of tags has not been done yet.
}
assert(pCol != NULL); assert(pCol != NULL);
SDataRow row = (SDataRow)pTable->tagVal; SDataRow row = (SDataRow)pTable->tagVal;
char* d = dataRowTuple(row); char* d = tdGetRowDataOfCol(row, pCol->type, TD_DATA_ROW_HEAD_SIZE + offset);
*val = d; *val = d;
*type = pCol->type; *type = pCol->type;
*bytes = pCol->bytes; *bytes = pCol->bytes;
return 0; return TSDB_CODE_SUCCESS;
} }
int32_t tsdbTableGetName(TsdbRepoT *repo, STableId id, char** name) { int32_t tsdbGetTableName(TsdbRepoT *repo, STableId* id, char** name) {
STsdbMeta* pMeta = tsdbGetMeta(repo); STsdbMeta* pMeta = tsdbGetMeta(repo);
STable* pTable = tsdbGetTableByUid(pMeta, id.uid); STable* pTable = tsdbGetTableByUid(pMeta, id->uid);
*name = strndup(pTable->name, TSDB_TABLE_NAME_LEN); *name = strndup(pTable->name, TSDB_TABLE_NAME_LEN);
if (*name == NULL) { if (*name == NULL) {
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "tsdbMain.h" #include "tsdbMain.h"
#define EXTRA_BYTES 2 #define EXTRA_BYTES 2
#define PRIMARY_TSCOL_REQUIRED(c) (((SColumnInfoData*)taosArrayGet(c, 0))->info.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX)
#define ASCENDING_ORDER_TRAVERSE(o) (o == TSDB_ORDER_ASC) #define ASCENDING_ORDER_TRAVERSE(o) (o == TSDB_ORDER_ASC)
#define QH_GET_NUM_OF_COLS(handle) ((size_t)(taosArrayGetSize((handle)->pColumns))) #define QH_GET_NUM_OF_COLS(handle) ((size_t)(taosArrayGetSize((handle)->pColumns)))
...@@ -35,6 +34,12 @@ enum { ...@@ -35,6 +34,12 @@ enum {
QUERY_RANGE_GREATER_EQUAL = 1, QUERY_RANGE_GREATER_EQUAL = 1,
}; };
enum {
TSDB_QUERY_TYPE_ALL = 1,
TSDB_QUERY_TYPE_LAST = 2,
TSDB_QUERY_TYPE_EXTERNAL = 3,
};
typedef struct SField { typedef struct SField {
// todo need the definition // todo need the definition
} SField; } SField;
...@@ -54,7 +59,7 @@ typedef struct SDataBlockLoadInfo { ...@@ -54,7 +59,7 @@ typedef struct SDataBlockLoadInfo {
} SDataBlockLoadInfo; } SDataBlockLoadInfo;
typedef struct SLoadCompBlockInfo { typedef struct SLoadCompBlockInfo {
int32_t sid; /* meter sid */ int32_t sid; /* table sid */
int32_t fileId; int32_t fileId;
int32_t fileListIndex; int32_t fileListIndex;
} SLoadCompBlockInfo; } SLoadCompBlockInfo;
...@@ -63,16 +68,12 @@ typedef struct STableCheckInfo { ...@@ -63,16 +68,12 @@ typedef struct STableCheckInfo {
STableId tableId; STableId tableId;
TSKEY lastKey; TSKEY lastKey;
STable* pTableObj; STable* pTableObj;
int64_t offsetInHeaderFile;
int32_t start; int32_t start;
bool checkFirstFileBlock;
SCompInfo* pCompInfo; SCompInfo* pCompInfo;
int32_t compSize; int32_t compSize;
int32_t numOfBlocks; // number of qualified data blocks not the original blocks int32_t numOfBlocks; // number of qualified data blocks not the original blocks
SDataCols* pDataCols; SDataCols* pDataCols;
SSkipListIterator* iter; SSkipListIterator* iter;
} STableCheckInfo; } STableCheckInfo;
...@@ -92,7 +93,7 @@ typedef struct SBlockOrderSupporter { ...@@ -92,7 +93,7 @@ typedef struct SBlockOrderSupporter {
int32_t numOfTables; int32_t numOfTables;
STableBlockInfo** pDataBlockInfo; STableBlockInfo** pDataBlockInfo;
int32_t* blockIndexArray; int32_t* blockIndexArray;
int32_t* numOfBlocksPerMeter; int32_t* numOfBlocksPerTable;
} SBlockOrderSupporter; } SBlockOrderSupporter;
typedef struct STsdbQueryHandle { typedef struct STsdbQueryHandle {
...@@ -110,19 +111,20 @@ typedef struct STsdbQueryHandle { ...@@ -110,19 +111,20 @@ typedef struct STsdbQueryHandle {
SArray* pColumns; // column list, SColumnInfoData array list SArray* pColumns; // column list, SColumnInfoData array list
bool locateStart; bool locateStart;
int32_t realNumOfRows; int32_t realNumOfRows;
SArray* pTableCheckInfo; SArray* pTableCheckInfo; //SArray<STableCheckInfo>
int32_t activeIndex; int32_t activeIndex;
bool checkFiles; // check file stage bool checkFiles; // check file stage
void* qinfo; // query info handle, for debug purpose void* qinfo; // query info handle, for debug purpose
int32_t type; // query type: retrieve all data blocks, 2. retrieve only last row, 3. retrieve direct prev|next rows
STableBlockInfo* pDataBlockInfo; STableBlockInfo* pDataBlockInfo;
SFileGroup* pFileGroup; SFileGroup* pFileGroup;
SFileGroupIter fileIter; SFileGroupIter fileIter;
SCompIdx* compIndex;
SRWHelper rhelper; SRWHelper rhelper;
} STsdbQueryHandle; } STsdbQueryHandle;
static void changeQueryHandleForLastrowQuery(TsdbQueryHandleT pqHandle);
static void tsdbInitDataBlockLoadInfo(SDataBlockLoadInfo* pBlockLoadInfo) { static void tsdbInitDataBlockLoadInfo(SDataBlockLoadInfo* pBlockLoadInfo) {
pBlockLoadInfo->slot = -1; pBlockLoadInfo->slot = -1;
pBlockLoadInfo->sid = -1; pBlockLoadInfo->sid = -1;
...@@ -143,7 +145,7 @@ TsdbQueryHandleT* tsdbQueryTables(TsdbRepoT* tsdb, STsdbQueryCond* pCond, STable ...@@ -143,7 +145,7 @@ TsdbQueryHandleT* tsdbQueryTables(TsdbRepoT* tsdb, STsdbQueryCond* pCond, STable
pQueryHandle->order = pCond->order; pQueryHandle->order = pCond->order;
pQueryHandle->window = pCond->twindow; pQueryHandle->window = pCond->twindow;
pQueryHandle->pTsdb = tsdb; pQueryHandle->pTsdb = tsdb;
pQueryHandle->compIndex = calloc(10000, sizeof(SCompIdx)); pQueryHandle->type = TSDB_QUERY_TYPE_ALL;
tsdbInitReadHelper(&pQueryHandle->rhelper, (STsdbRepo*) tsdb); tsdbInitReadHelper(&pQueryHandle->rhelper, (STsdbRepo*) tsdb);
pQueryHandle->cur.fid = -1; pQueryHandle->cur.fid = -1;
...@@ -160,15 +162,15 @@ TsdbQueryHandleT* tsdbQueryTables(TsdbRepoT* tsdb, STsdbQueryCond* pCond, STable ...@@ -160,15 +162,15 @@ TsdbQueryHandleT* tsdbQueryTables(TsdbRepoT* tsdb, STsdbQueryCond* pCond, STable
assert(gsize > 0); assert(gsize > 0);
for (int32_t j = 0; j < gsize; ++j) { for (int32_t j = 0; j < gsize; ++j) {
SPair* d = (SPair*) taosArrayGet(group, j); STableId* id = (STableId*) taosArrayGet(group, j);
assert(d->first != NULL);
STableCheckInfo info = { STableCheckInfo info = {
.lastKey = pQueryHandle->window.skey, .lastKey = pQueryHandle->window.skey,
.tableId = ((STable*) d->first)->tableId, .tableId = *id,
.pTableObj = d->first, .pTableObj = tsdbGetTableByUid(tsdbGetMeta(tsdb), id->uid),
}; };
assert(info.pTableObj != NULL && info.pTableObj->tableId.tid == id->tid);
taosArrayPush(pQueryHandle->pTableCheckInfo, &info); taosArrayPush(pQueryHandle->pTableCheckInfo, &info);
} }
} }
...@@ -198,7 +200,27 @@ TsdbQueryHandleT* tsdbQueryTables(TsdbRepoT* tsdb, STsdbQueryCond* pCond, STable ...@@ -198,7 +200,27 @@ TsdbQueryHandleT* tsdbQueryTables(TsdbRepoT* tsdb, STsdbQueryCond* pCond, STable
tsdbInitDataBlockLoadInfo(&pQueryHandle->dataBlockLoadInfo); tsdbInitDataBlockLoadInfo(&pQueryHandle->dataBlockLoadInfo);
tsdbInitCompBlockLoadInfo(&pQueryHandle->compBlockLoadInfo); tsdbInitCompBlockLoadInfo(&pQueryHandle->compBlockLoadInfo);
return (TsdbQueryHandleT)pQueryHandle; return (TsdbQueryHandleT) pQueryHandle;
}
TsdbQueryHandleT tsdbQueryLastRow(TsdbRepoT *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList) {
STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList);
pQueryHandle->type = TSDB_QUERY_TYPE_LAST;
pQueryHandle->order = TSDB_ORDER_DESC;
changeQueryHandleForLastrowQuery(pQueryHandle);
return pQueryHandle;
}
TsdbQueryHandleT tsdbQueryRowsInExternalWindow(TsdbRepoT *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList) {
STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList);
pQueryHandle->type = TSDB_QUERY_TYPE_EXTERNAL;
pQueryHandle->order = TSDB_ORDER_ASC;
// changeQueryHandleForLastrowQuery(pQueryHandle);
return pQueryHandle;
} }
static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) { static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) {
...@@ -236,8 +258,8 @@ static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) { ...@@ -236,8 +258,8 @@ static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) {
SDataRow row = SL_GET_NODE_DATA(node); SDataRow row = SL_GET_NODE_DATA(node);
pCheckInfo->lastKey = dataRowKey(row); // first timestamp in buffer pCheckInfo->lastKey = dataRowKey(row); // first timestamp in buffer
uTrace("%p uid:%" PRId64", tid:%d check data in buffer from skey:%" PRId64 ", order:%d", pHandle, uTrace("%p uid:%" PRId64", tid:%d check data in buffer from skey:%" PRId64 ", order:%d, %p", pHandle,
pCheckInfo->tableId.uid, pCheckInfo->tableId.tid, pCheckInfo->lastKey, pHandle->order); pCheckInfo->tableId.uid, pCheckInfo->tableId.tid, pCheckInfo->lastKey, pHandle->order, pHandle->qinfo);
// all data in mem are checked already. // all data in mem are checked already.
if ((pCheckInfo->lastKey > pHandle->window.ekey && ASCENDING_ORDER_TRAVERSE(pHandle->order)) || if ((pCheckInfo->lastKey > pHandle->window.ekey && ASCENDING_ORDER_TRAVERSE(pHandle->order)) ||
...@@ -293,8 +315,6 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo ...@@ -293,8 +315,6 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo
tsdbSetAndOpenHelperFile(&pQueryHandle->rhelper, fileGroup); tsdbSetAndOpenHelperFile(&pQueryHandle->rhelper, fileGroup);
// load all the comp offset value for all tables in this file // load all the comp offset value for all tables in this file
// tsdbLoadCompIdx(fileGroup, pQueryHandle->compIndex, 10000); // todo set dynamic max tables
*numOfBlocks = 0; *numOfBlocks = 0;
size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo); size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo);
...@@ -358,7 +378,7 @@ static SDataBlockInfo getTrueDataBlockInfo(STableCheckInfo* pCheckInfo, SCompBlo ...@@ -358,7 +378,7 @@ static SDataBlockInfo getTrueDataBlockInfo(STableCheckInfo* pCheckInfo, SCompBlo
.window = {.skey = pBlock->keyFirst, .ekey = pBlock->keyLast}, .window = {.skey = pBlock->keyFirst, .ekey = pBlock->keyLast},
.numOfCols = pBlock->numOfCols, .numOfCols = pBlock->numOfCols,
.rows = pBlock->numOfPoints, .rows = pBlock->numOfPoints,
.sid = pCheckInfo->tableId.tid, .tid = pCheckInfo->tableId.tid,
.uid = pCheckInfo->tableId.uid, .uid = pCheckInfo->tableId.uid,
}; };
...@@ -407,16 +427,11 @@ static bool doLoadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlo ...@@ -407,16 +427,11 @@ static bool doLoadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlo
SArray* sa = getDefaultLoadColumns(pQueryHandle, true); SArray* sa = getDefaultLoadColumns(pQueryHandle, true);
if (pCheckInfo->pDataCols == NULL) { if (pCheckInfo->pDataCols == NULL) {
pCheckInfo->pDataCols = tdNewDataCols(1000, 2, 4096); pCheckInfo->pDataCols = tdNewDataCols(1000, 100, 4096); //todo fix me
} }
tdInitDataCols(pCheckInfo->pDataCols, tsdbGetTableSchema(tsdbGetMeta(pQueryHandle->pTsdb), pCheckInfo->pTableObj)); tdInitDataCols(pCheckInfo->pDataCols, tsdbGetTableSchema(tsdbGetMeta(pQueryHandle->pTsdb), pCheckInfo->pTableObj));
// SFile* pFile = &pQueryHandle->pFileGroup->files[TSDB_FILE_TYPE_DATA];
// if (pFile->fd == FD_INITIALIZER) {
// pFile->fd = open(pFile->fname, O_RDONLY);
// }
if (tsdbLoadBlockData(&(pQueryHandle->rhelper), pBlock, NULL) == 0) { if (tsdbLoadBlockData(&(pQueryHandle->rhelper), pBlock, NULL) == 0) {
SDataBlockLoadInfo* pBlockLoadInfo = &pQueryHandle->dataBlockLoadInfo; SDataBlockLoadInfo* pBlockLoadInfo = &pQueryHandle->dataBlockLoadInfo;
...@@ -552,7 +567,6 @@ static void filterDataInDataBlock(STsdbQueryHandle* pQueryHandle, STableCheckInf ...@@ -552,7 +567,6 @@ static void filterDataInDataBlock(STsdbQueryHandle* pQueryHandle, STableCheckInf
SQueryFilePos* cur = &pQueryHandle->cur; SQueryFilePos* cur = &pQueryHandle->cur;
SDataBlockInfo blockInfo = getTrueDataBlockInfo(pCheckInfo, pBlock); SDataBlockInfo blockInfo = getTrueDataBlockInfo(pCheckInfo, pBlock);
// pQueryHandle->rhelper.pDataCols[0]->cols[0];
SDataCols* pCols = pQueryHandle->rhelper.pDataCols[0]; SDataCols* pCols = pQueryHandle->rhelper.pDataCols[0];
int32_t endPos = cur->pos; int32_t endPos = cur->pos;
...@@ -589,18 +603,32 @@ static void filterDataInDataBlock(STsdbQueryHandle* pQueryHandle, STableCheckInf ...@@ -589,18 +603,32 @@ static void filterDataInDataBlock(STsdbQueryHandle* pQueryHandle, STableCheckInf
int32_t start = MIN(cur->pos, endPos); int32_t start = MIN(cur->pos, endPos);
// if (start > 0) {
// tdPopDataColsPoints(pQueryHandle->rhelper.pDataCols[0], start);
// }
// move the data block in the front to data block if needed // move the data block in the front to data block if needed
int32_t numOfCols = QH_GET_NUM_OF_COLS(pQueryHandle); int32_t numOfCols = pQueryHandle->rhelper.pDataCols[0]->numOfCols;
int32_t reqCols = taosArrayGetSize(pQueryHandle->pColumns);
for (int32_t i = 0; i < taosArrayGetSize(sa); ++i) { for (int32_t i = 0; i < reqCols; ++i) {
int16_t colId = *(int16_t*)taosArrayGet(sa, i); // int16_t colId = *(int16_t*)taosArrayGet(sa, i);
SColumnInfoData* pCol = taosArrayGet(pQueryHandle->pColumns, i);
int32_t bytes = pCol->info.bytes;
for (int32_t j = 0; j < numOfCols; ++j) { for (int32_t j = 0; j < numOfCols; ++j) {
SColumnInfoData* pCol = taosArrayGet(pQueryHandle->pColumns, j); SDataCol* src = &pQueryHandle->rhelper.pDataCols[0]->cols[j];
if (pCol->info.colId == src->colId) {
if (pCol->info.type != TSDB_DATA_TYPE_BINARY && pCol->info.type != TSDB_DATA_TYPE_NCHAR) {
memmove(pCol->pData, src->pData + bytes * start, bytes * pQueryHandle->realNumOfRows);
} else { // handle the var-string
for(int32_t k = start; k < pQueryHandle->realNumOfRows + start; ++k) {
char* p = tdGetColDataOfRow(src, k);
memcpy(pCol->pData + k * bytes, p, varDataTLen(p)); // todo refactor
}
}
if (pCol->info.colId == colId) {
memmove(pCol->pData, pQueryHandle->rhelper.pDataCols[0]->cols[i].pData + pCol->info.bytes * start,
pQueryHandle->realNumOfRows * pCol->info.bytes);
break; break;
} }
} }
...@@ -673,7 +701,7 @@ int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order) { ...@@ -673,7 +701,7 @@ int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order) {
} }
static void cleanBlockOrderSupporter(SBlockOrderSupporter* pSupporter, int32_t numOfTables) { static void cleanBlockOrderSupporter(SBlockOrderSupporter* pSupporter, int32_t numOfTables) {
tfree(pSupporter->numOfBlocksPerMeter); tfree(pSupporter->numOfBlocksPerTable);
tfree(pSupporter->blockIndexArray); tfree(pSupporter->blockIndexArray);
for (int32_t i = 0; i < numOfTables; ++i) { for (int32_t i = 0; i < numOfTables; ++i) {
...@@ -692,10 +720,10 @@ static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void* ...@@ -692,10 +720,10 @@ static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void*
int32_t leftTableBlockIndex = pSupporter->blockIndexArray[leftTableIndex]; int32_t leftTableBlockIndex = pSupporter->blockIndexArray[leftTableIndex];
int32_t rightTableBlockIndex = pSupporter->blockIndexArray[rightTableIndex]; int32_t rightTableBlockIndex = pSupporter->blockIndexArray[rightTableIndex];
if (leftTableBlockIndex > pSupporter->numOfBlocksPerMeter[leftTableIndex]) { if (leftTableBlockIndex > pSupporter->numOfBlocksPerTable[leftTableIndex]) {
/* left block is empty */ /* left block is empty */
return 1; return 1;
} else if (rightTableBlockIndex > pSupporter->numOfBlocksPerMeter[rightTableIndex]) { } else if (rightTableBlockIndex > pSupporter->numOfBlocksPerTable[rightTableIndex]) {
/* right block is empty */ /* right block is empty */
return -1; return -1;
} }
...@@ -727,11 +755,11 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO ...@@ -727,11 +755,11 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO
SBlockOrderSupporter sup = {0}; SBlockOrderSupporter sup = {0};
sup.numOfTables = numOfTables; sup.numOfTables = numOfTables;
sup.numOfBlocksPerMeter = calloc(1, sizeof(int32_t) * numOfTables); sup.numOfBlocksPerTable = calloc(1, sizeof(int32_t) * numOfTables);
sup.blockIndexArray = calloc(1, sizeof(int32_t) * numOfTables); sup.blockIndexArray = calloc(1, sizeof(int32_t) * numOfTables);
sup.pDataBlockInfo = calloc(1, POINTER_BYTES * numOfTables); sup.pDataBlockInfo = calloc(1, POINTER_BYTES * numOfTables);
if (sup.numOfBlocksPerMeter == NULL || sup.blockIndexArray == NULL || sup.pDataBlockInfo == NULL) { if (sup.numOfBlocksPerTable == NULL || sup.blockIndexArray == NULL || sup.pDataBlockInfo == NULL) {
cleanBlockOrderSupporter(&sup, 0); cleanBlockOrderSupporter(&sup, 0);
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_SERV_OUT_OF_MEMORY;
} }
...@@ -745,7 +773,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO ...@@ -745,7 +773,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO
} }
SCompBlock* pBlock = pTableCheck->pCompInfo->blocks; SCompBlock* pBlock = pTableCheck->pCompInfo->blocks;
sup.numOfBlocksPerMeter[numOfQualTables] = pTableCheck->numOfBlocks; sup.numOfBlocksPerTable[numOfQualTables] = pTableCheck->numOfBlocks;
char* buf = calloc(1, sizeof(STableBlockInfo) * pTableCheck->numOfBlocks); char* buf = calloc(1, sizeof(STableBlockInfo) * pTableCheck->numOfBlocks);
if (buf == NULL) { if (buf == NULL) {
...@@ -763,7 +791,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO ...@@ -763,7 +791,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO
pBlockInfoEx->pTableCheckInfo = pTableCheck; pBlockInfoEx->pTableCheckInfo = pTableCheck;
// pBlockInfoEx->groupIdx = pTableCheckInfo[j]->groupIdx; // set the group index // pBlockInfoEx->groupIdx = pTableCheckInfo[j]->groupIdx; // set the group index
// pBlockInfoEx->blockIndex = pTableCheckInfo[j]->start + k; // set the block index in original meter // pBlockInfoEx->blockIndex = pTableCheckInfo[j]->start + k; // set the block index in original table
cnt++; cnt++;
} }
...@@ -772,7 +800,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO ...@@ -772,7 +800,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO
uTrace("%p create data blocks info struct completed, %d blocks in %d tables", pQueryHandle, cnt, numOfQualTables); uTrace("%p create data blocks info struct completed, %d blocks in %d tables", pQueryHandle, cnt, numOfQualTables);
assert(cnt <= numOfBlocks && numOfQualTables <= numOfTables); // the pMeterDataInfo[j]->numOfBlocks may be 0 assert(cnt <= numOfBlocks && numOfQualTables <= numOfTables); // the pTableQueryInfo[j]->numOfBlocks may be 0
sup.numOfTables = numOfQualTables; sup.numOfTables = numOfQualTables;
SLoserTreeInfo* pTree = NULL; SLoserTreeInfo* pTree = NULL;
...@@ -792,8 +820,8 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO ...@@ -792,8 +820,8 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO
pQueryHandle->pDataBlockInfo[numOfTotal++] = pBlocksInfoEx[index]; pQueryHandle->pDataBlockInfo[numOfTotal++] = pBlocksInfoEx[index];
// set data block index overflow, in order to disable the offset comparator // set data block index overflow, in order to disable the offset comparator
if (sup.blockIndexArray[pos] >= sup.numOfBlocksPerMeter[pos]) { if (sup.blockIndexArray[pos] >= sup.numOfBlocksPerTable[pos]) {
sup.blockIndexArray[pos] = sup.numOfBlocksPerMeter[pos] + 1; sup.blockIndexArray[pos] = sup.numOfBlocksPerTable[pos] + 1;
} }
tLoserTreeAdjust(pTree, pos + sup.numOfTables); tLoserTreeAdjust(pTree, pos + sup.numOfTables);
...@@ -827,10 +855,14 @@ static bool getDataBlocksInFilesImpl(STsdbQueryHandle* pQueryHandle) { ...@@ -827,10 +855,14 @@ static bool getDataBlocksInFilesImpl(STsdbQueryHandle* pQueryHandle) {
break; break;
} }
assert(numOfBlocks >= 0);
uTrace("%p %d blocks found in file for %d table(s), fid:%d", pQueryHandle, numOfBlocks, uTrace("%p %d blocks found in file for %d table(s), fid:%d", pQueryHandle, numOfBlocks,
numOfTables, pQueryHandle->pFileGroup->fileId); numOfTables, pQueryHandle->pFileGroup->fileId);
assert(numOfBlocks >= 0);
if (numOfBlocks == 0) {
continue;
}
// todo return error code to query engine // todo return error code to query engine
if (createDataBlocksInfo(pQueryHandle, numOfBlocks, &pQueryHandle->numOfBlocks) != TSDB_CODE_SUCCESS) { if (createDataBlocksInfo(pQueryHandle, numOfBlocks, &pQueryHandle->numOfBlocks) != TSDB_CODE_SUCCESS) {
break; break;
...@@ -941,7 +973,60 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pqHandle) { ...@@ -941,7 +973,60 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pqHandle) {
} }
} }
static int tsdbReadRowsFromCache(SSkipListIterator* pIter, TSKEY maxKey, int maxRowsToRead, TSKEY* skey, TSKEY* ekey, void changeQueryHandleForLastrowQuery(TsdbQueryHandleT pqHandle) {
STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*) pqHandle;
assert(!ASCENDING_ORDER_TRAVERSE(pQueryHandle->order));
// starts from the buffer in case of descending timestamp order check data blocks
// todo consider the query time window, current last_row does not apply the query time window
size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo);
TSKEY key = 0;
int32_t index = -1;
for(int32_t i = 0; i < numOfTables; ++i) {
STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, i);
if (pCheckInfo->pTableObj->lastKey > key) { //todo lastKey should not be 0 by default
key = pCheckInfo->pTableObj->lastKey;
index = i;
}
}
// todo, there are no data in all the tables. opt performance
if (index == -1) {
return;
}
// erase all other elements in array list, todo refactor
size_t size = taosArrayGetSize(pQueryHandle->pTableCheckInfo);
for (int32_t i = 0; i < size; ++i) {
if (i == index) {
continue;
}
STableCheckInfo* pTableCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, i);
tSkipListDestroyIter(pTableCheckInfo->iter);
if (pTableCheckInfo->pDataCols != NULL) {
tfree(pTableCheckInfo->pDataCols->buf);
}
tfree(pTableCheckInfo->pDataCols);
tfree(pTableCheckInfo->pCompInfo);
}
STableCheckInfo info = *(STableCheckInfo*) taosArrayGet(pQueryHandle->pTableCheckInfo, index);
taosArrayDestroy(pQueryHandle->pTableCheckInfo);
pQueryHandle->pTableCheckInfo = taosArrayInit(1, sizeof(STableCheckInfo));
taosArrayPush(pQueryHandle->pTableCheckInfo, &info);
// update the query time window according to the chosen last timestamp
pQueryHandle->window = (STimeWindow) {key, key};
}
static int tsdbReadRowsFromCache(SSkipListIterator* pIter, STable* pTable, TSKEY maxKey, int maxRowsToRead, TSKEY* skey, TSKEY* ekey,
STsdbQueryHandle* pQueryHandle) { STsdbQueryHandle* pQueryHandle) {
int numOfRows = 0; int numOfRows = 0;
int32_t numOfCols = taosArrayGetSize(pQueryHandle->pColumns); int32_t numOfCols = taosArrayGetSize(pQueryHandle->pColumns);
...@@ -971,9 +1056,12 @@ static int tsdbReadRowsFromCache(SSkipListIterator* pIter, TSKEY maxKey, int max ...@@ -971,9 +1056,12 @@ static int tsdbReadRowsFromCache(SSkipListIterator* pIter, TSKEY maxKey, int max
*ekey = dataRowKey(row); *ekey = dataRowKey(row);
int32_t offset = 0; int32_t offset = -1;
char* pData = NULL; char* pData = NULL;
STSchema* pSchema = tsdbGetTableSchema(tsdbGetMeta(pQueryHandle->pTsdb), pTable);
int32_t numOfTableCols = schemaNCols(pSchema);
for (int32_t i = 0; i < numOfCols; ++i) { for (int32_t i = 0; i < numOfCols; ++i) {
SColumnInfoData* pColInfo = taosArrayGet(pQueryHandle->pColumns, i); SColumnInfoData* pColInfo = taosArrayGet(pQueryHandle->pColumns, i);
...@@ -983,10 +1071,27 @@ static int tsdbReadRowsFromCache(SSkipListIterator* pIter, TSKEY maxKey, int max ...@@ -983,10 +1071,27 @@ static int tsdbReadRowsFromCache(SSkipListIterator* pIter, TSKEY maxKey, int max
pData = pColInfo->pData + (maxRowsToRead - numOfRows - 1) * pColInfo->info.bytes; pData = pColInfo->pData + (maxRowsToRead - numOfRows - 1) * pColInfo->info.bytes;
} }
for(int32_t j = 0; j < numOfTableCols; ++j) {
if (pColInfo->info.colId == pSchema->columns[j].colId) {
offset = pSchema->columns[j].offset;
break;
}
}
assert(offset != -1); // todo handle error
if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) {
void *value = tdGetRowDataOfCol(row, pColInfo->info.type, TD_DATA_ROW_HEAD_SIZE + offset);
memcpy(pData, value, varDataTLen(value));
offset += sizeof(int32_t);
} else {
memcpy(pData, dataRowTuple(row) + offset, pColInfo->info.bytes); memcpy(pData, dataRowTuple(row) + offset, pColInfo->info.bytes);
offset += pColInfo->info.bytes; offset += pColInfo->info.bytes;
} }
}
numOfRows++; numOfRows++;
if (numOfRows >= maxRowsToRead) { if (numOfRows >= maxRowsToRead) {
break; break;
...@@ -1050,7 +1155,7 @@ SDataBlockInfo tsdbRetrieveDataBlockInfo(TsdbQueryHandleT* pQueryHandle) { ...@@ -1050,7 +1155,7 @@ SDataBlockInfo tsdbRetrieveDataBlockInfo(TsdbQueryHandleT* pQueryHandle) {
if (pTable->mem != NULL) { if (pTable->mem != NULL) {
// create mem table iterator if it is not created yet // create mem table iterator if it is not created yet
assert(pCheckInfo->iter != NULL); assert(pCheckInfo->iter != NULL);
rows = tsdbReadRowsFromCache(pCheckInfo->iter, pHandle->window.ekey, 4000, &skey, &ekey, pHandle); rows = tsdbReadRowsFromCache(pCheckInfo->iter, pCheckInfo->pTableObj, pHandle->window.ekey, 4000, &skey, &ekey, pHandle);
// update the last key value // update the last key value
pCheckInfo->lastKey = ekey + step; pCheckInfo->lastKey = ekey + step;
...@@ -1059,7 +1164,7 @@ SDataBlockInfo tsdbRetrieveDataBlockInfo(TsdbQueryHandleT* pQueryHandle) { ...@@ -1059,7 +1164,7 @@ SDataBlockInfo tsdbRetrieveDataBlockInfo(TsdbQueryHandleT* pQueryHandle) {
SDataBlockInfo blockInfo = { SDataBlockInfo blockInfo = {
.uid = pTable->tableId.uid, .uid = pTable->tableId.uid,
.sid = pTable->tableId.tid, .tid = pTable->tableId.tid,
.rows = rows, .rows = rows,
.window = {.skey = MIN(skey, ekey), .ekey = MAX(skey, ekey)} .window = {.skey = MIN(skey, ekey), .ekey = MAX(skey, ekey)}
}; };
...@@ -1110,10 +1215,6 @@ SArray* tsdbRetrieveDataBlock(TsdbQueryHandleT* pQueryHandle, SArray* pIdList) { ...@@ -1110,10 +1215,6 @@ SArray* tsdbRetrieveDataBlock(TsdbQueryHandleT* pQueryHandle, SArray* pIdList) {
} }
} }
int32_t tsdbResetQuery(TsdbQueryHandleT* pQueryHandle, STimeWindow* window, TsdbPosT position, int16_t order) {
return 0;
}
SArray* tsdbRetrieveDataRow(TsdbQueryHandleT* pQueryHandle, SArray* pIdList, SQueryRowCond* pCond) { return NULL; } SArray* tsdbRetrieveDataRow(TsdbQueryHandleT* pQueryHandle, SArray* pIdList, SQueryRowCond* pCond) { return NULL; }
TsdbQueryHandleT* tsdbQueryFromTagConds(STsdbQueryCond* pCond, int16_t stableId, const char* pTagFilterStr) { TsdbQueryHandleT* tsdbQueryFromTagConds(STsdbQueryCond* pCond, int16_t stableId, const char* pTagFilterStr) {
...@@ -1122,16 +1223,13 @@ TsdbQueryHandleT* tsdbQueryFromTagConds(STsdbQueryCond* pCond, int16_t stableId, ...@@ -1122,16 +1223,13 @@ TsdbQueryHandleT* tsdbQueryFromTagConds(STsdbQueryCond* pCond, int16_t stableId,
SArray* tsdbGetTableList(TsdbQueryHandleT* pQueryHandle) { return NULL; } SArray* tsdbGetTableList(TsdbQueryHandleT* pQueryHandle) { return NULL; }
static int32_t getAllTableIdList(STsdbRepo* tsdb, int64_t uid, SArray* list) { static int32_t getAllTableIdList(STable* pSuperTable, SArray* list) {
STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid); SSkipListIterator* iter = tSkipListCreateIter(pSuperTable->pIndex);
assert(pTable != NULL); // assert pTable is a super table
SSkipListIterator* iter = tSkipListCreateIter(pTable->pIndex);
while (tSkipListIterNext(iter)) { while (tSkipListIterNext(iter)) {
SSkipListNode* pNode = tSkipListIterGet(iter); SSkipListNode* pNode = tSkipListIterGet(iter);
STable* t = *(STable**)SL_GET_NODE_DATA(pNode); STable* t = *(STable**)SL_GET_NODE_DATA(pNode);
taosArrayPush(list, &t); taosArrayPush(list, &t->tableId);
} }
tSkipListDestroyIter(iter); tSkipListDestroyIter(iter);
...@@ -1156,7 +1254,7 @@ static void convertQueryResult(SArray* pRes, SArray* pTableList) { ...@@ -1156,7 +1254,7 @@ static void convertQueryResult(SArray* pRes, SArray* pTableList) {
size_t size = taosArrayGetSize(pTableList); size_t size = taosArrayGetSize(pTableList);
for (int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
STable* pTable = taosArrayGetP(pTableList, i); STable* pTable = taosArrayGetP(pTableList, i);
taosArrayPush(pRes, &pTable); taosArrayPush(pRes, &pTable->tableId);
} }
} }
...@@ -1165,27 +1263,31 @@ static void destroyHelper(void* param) { ...@@ -1165,27 +1263,31 @@ static void destroyHelper(void* param) {
return; return;
} }
tQueryInfo* pInfo = (tQueryInfo*)param; tQueryInfo* pInfo = (tQueryInfo*)param;
tVariantDestroy(&(pInfo->q)); if (pInfo->optr != TSDB_RELATION_IN) {
tfree(pInfo->q);
}
// tVariantDestroy(&(pInfo->q));
free(param); free(param);
} }
static void getTagColumnInfo(SExprTreeSupporter* pSupporter, SSchema* pSchema, int32_t* index) { static int32_t getTagColumnInfo(SExprTreeSupporter* pSupporter, SSchema* pSchema) {
*index = 0;
// filter on table name(TBNAME) // filter on table name(TBNAME)
if (strcasecmp(pSchema->name, TSQL_TBNAME_L) == 0) { if (strcasecmp(pSchema->name, TSQL_TBNAME_L) == 0) {
*index = TSDB_TBNAME_COLUMN_INDEX; return TSDB_TBNAME_COLUMN_INDEX;
return;
} }
while ((*index) < pSupporter->numOfTags) { for(int32_t i = 0; i < pSupporter->numOfTags; ++i) {
if (pSupporter->pTagSchema[*index].bytes == pSchema->bytes && if (pSupporter->pTagSchema[i].bytes == pSchema->bytes &&
pSupporter->pTagSchema[*index].type == pSchema->type && pSupporter->pTagSchema[i].type == pSchema->type &&
pSupporter->pTagSchema[*index].colId == pSchema->colId) { pSupporter->pTagSchema[i].colId == pSchema->colId) {
break; return i;
} }
} }
return -2;
} }
void filterPrepare(void* expr, void* param) { void filterPrepare(void* expr, void* param) {
...@@ -1194,55 +1296,29 @@ void filterPrepare(void* expr, void* param) { ...@@ -1194,55 +1296,29 @@ void filterPrepare(void* expr, void* param) {
return; return;
} }
int32_t i = 0, offset = 0; int32_t i = 0;
pExpr->_node.info = calloc(1, sizeof(tQueryInfo)); pExpr->_node.info = calloc(1, sizeof(tQueryInfo));
tQueryInfo* pInfo = pExpr->_node.info;
SExprTreeSupporter* pSupporter = (SExprTreeSupporter*)param; SExprTreeSupporter* pSupporter = (SExprTreeSupporter*)param;
tQueryInfo* pInfo = pExpr->_node.info;
tVariant* pCond = pExpr->_node.pRight->pVal; tVariant* pCond = pExpr->_node.pRight->pVal;
SSchema* pSchema = pExpr->_node.pLeft->pSchema; SSchema* pSchema = pExpr->_node.pLeft->pSchema;
getTagColumnInfo(pSupporter, pSchema, &i); // todo : if current super table does not change schema yet, this function may failed, add test case
assert((i >= 0 && i < TSDB_MAX_TAGS) || (i == TSDB_TBNAME_COLUMN_INDEX)); int32_t index = getTagColumnInfo(pSupporter, pSchema);
assert((offset >= 0 && offset < TSDB_MAX_TAGS_LEN) || (offset == TSDB_TBNAME_COLUMN_INDEX)); assert((index >= 0 && i < TSDB_MAX_TAGS) || (index == TSDB_TBNAME_COLUMN_INDEX));
pInfo->sch = *pSchema; pInfo->sch = *pSchema;
pInfo->colIndex = i; pInfo->colIndex = index;
pInfo->optr = pExpr->_node.optr; pInfo->optr = pExpr->_node.optr;
pInfo->compare = getComparFunc(pSchema->type, pCond->nType, pInfo->optr); pInfo->compare = getComparFunc(pSchema->type, pInfo->optr);
tVariantAssign(&pInfo->q, pCond);
if (pInfo->optr != TSDB_RELATION_IN) {
tVariantTypeSetType(&pInfo->q, pInfo->sch.type);
}
}
int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) { if (pInfo->optr == TSDB_RELATION_IN) {
switch (type) { pInfo->q = (char*) pCond->arr;
case TSDB_DATA_TYPE_INT: DEFAULT_COMP(GET_INT32_VAL(f1), GET_INT32_VAL(f2)); } else {
case TSDB_DATA_TYPE_DOUBLE: DEFAULT_COMP(GET_DOUBLE_VAL(f1), GET_DOUBLE_VAL(f2)); pInfo->q = calloc(1, pSchema->bytes);
case TSDB_DATA_TYPE_FLOAT: DEFAULT_COMP(GET_FLOAT_VAL(f1), GET_FLOAT_VAL(f2)); tVariantDump(pCond, pInfo->q, pSchema->type);
case TSDB_DATA_TYPE_BIGINT: DEFAULT_COMP(GET_INT64_VAL(f1), GET_INT64_VAL(f2));
case TSDB_DATA_TYPE_SMALLINT: DEFAULT_COMP(GET_INT16_VAL(f1), GET_INT16_VAL(f2));
case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_BOOL: DEFAULT_COMP(GET_INT8_VAL(f1), GET_INT8_VAL(f2));
case TSDB_DATA_TYPE_NCHAR: {
int32_t ret = wcsncmp((wchar_t*) f1, (wchar_t*) f2, size/TSDB_NCHAR_SIZE);
if (ret == 0) {
return ret;
}
return (ret < 0) ? -1 : 1;
}
default: {
int32_t ret = strncmp(f1, f2, (size_t)size);
if (ret == 0) {
return ret;
}
return (ret < 0) ? -1 : 1;
}
} }
} }
...@@ -1250,28 +1326,32 @@ typedef struct STableGroupSupporter { ...@@ -1250,28 +1326,32 @@ typedef struct STableGroupSupporter {
int32_t numOfCols; int32_t numOfCols;
SColIndex* pCols; SColIndex* pCols;
STSchema* pTagSchema; STSchema* pTagSchema;
void* tsdbMeta;
} STableGroupSupporter; } STableGroupSupporter;
int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) { int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) {
STableGroupSupporter* pTableGroupSupp = (STableGroupSupporter*) param; STableGroupSupporter* pTableGroupSupp = (STableGroupSupporter*) param;
STableId* id1 = (STableId*) p1;
STableId* id2 = (STableId*) p2;
STable *pTable1 = *(STable **) p1; STable *pTable1 = tsdbGetTableByUid(pTableGroupSupp->tsdbMeta, id1->uid);
STable *pTable2 = *(STable **) p2; STable *pTable2 = tsdbGetTableByUid(pTableGroupSupp->tsdbMeta, id2->uid);
for (int32_t i = 0; i < pTableGroupSupp->numOfCols; ++i) { for (int32_t i = 0; i < pTableGroupSupp->numOfCols; ++i) {
SColIndex* pColIndex = &pTableGroupSupp->pCols[i]; SColIndex* pColIndex = &pTableGroupSupp->pCols[i];
int32_t colIndex = pColIndex->colIndex; int32_t colIndex = pColIndex->colIndex;
assert(colIndex >= 0 && colIndex < schemaNCols(pTableGroupSupp->pTagSchema)); assert((colIndex >= 0 && colIndex < schemaNCols(pTableGroupSupp->pTagSchema)) ||
(colIndex == TSDB_TBNAME_COLUMN_INDEX));
char * f1 = NULL; char * f1 = NULL;
char * f2 = NULL; char * f2 = NULL;
int32_t type = 0; int32_t type = 0;
int32_t bytes = 0; int32_t bytes = 0;
if (colIndex == -1) { // todo fix me, table name if (colIndex == TSDB_TBNAME_COLUMN_INDEX) {
// f1 = s1->tags; f1 = pTable1->name;
// f2 = s2->tags; f2 = pTable2->name;
type = TSDB_DATA_TYPE_BINARY; type = TSDB_DATA_TYPE_BINARY;
bytes = TSDB_TABLE_NAME_LEN; bytes = TSDB_TABLE_NAME_LEN;
} else { } else {
...@@ -1293,34 +1373,36 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) { ...@@ -1293,34 +1373,36 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) {
return 0; return 0;
} }
void createTableGroupImpl(SArray* pGroups, STable** pTables, size_t numOfTables, STableGroupSupporter* pSupp, __ext_compar_fn_t compareFn) { void createTableGroupImpl(SArray* pGroups, SArray* pTableIdList, size_t numOfTables, STableGroupSupporter* pSupp,
SArray* g = taosArrayInit(16, sizeof(SPair)); __ext_compar_fn_t compareFn) {
STableId* pId = taosArrayGet(pTableIdList, 0);
SPair p = {.first = pTables[0]}; SArray* g = taosArrayInit(16, sizeof(STableId));
taosArrayPush(g, &p); taosArrayPush(g, pId);
for (int32_t i = 1; i < numOfTables; ++i) { for (int32_t i = 1; i < numOfTables; ++i) {
int32_t ret = compareFn(&pTables[i - 1], &pTables[i], pSupp); STableId* prev = taosArrayGet(pTableIdList, i - 1);
STableId* p = taosArrayGet(pTableIdList, i);
int32_t ret = compareFn(prev, p, pSupp);
assert(ret == 0 || ret == -1); assert(ret == 0 || ret == -1);
if (ret == 0) { if (ret == 0) {
SPair p1 = {.first = pTables[i]}; taosArrayPush(g, p);
taosArrayPush(g, &p1);
} else { } else {
taosArrayPush(pGroups, &g); // current group is ended, start a new group taosArrayPush(pGroups, &g); // current group is ended, start a new group
g = taosArrayInit(16, POINTER_BYTES); g = taosArrayInit(16, sizeof(STableId));
SPair p1 = {.first = pTables[i]}; taosArrayPush(g, p);
taosArrayPush(g, &p1);
} }
} }
taosArrayPush(pGroups, &g); taosArrayPush(pGroups, &g);
} }
SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pCols, int32_t numOfOrderCols) { SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pCols, int32_t numOfOrderCols,
TsdbRepoT* tsdb) {
assert(pTableList != NULL); assert(pTableList != NULL);
SArray* pTableGroup = taosArrayInit(1, POINTER_BYTES); SArray* pTableGroup = taosArrayInit(1, POINTER_BYTES);
size_t size = taosArrayGetSize(pTableList); size_t size = taosArrayGetSize(pTableList);
...@@ -1330,23 +1412,23 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC ...@@ -1330,23 +1412,23 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC
} }
if (numOfOrderCols == 0 || size == 1) { // no group by tags clause or only one table if (numOfOrderCols == 0 || size == 1) { // no group by tags clause or only one table
SArray* sa = taosArrayInit(size, sizeof(SPair)); SArray* sa = taosArrayInit(size, sizeof(STableId));
for(int32_t i = 0; i < size; ++i) { for(int32_t i = 0; i < size; ++i) {
STable* pTable = taosArrayGetP(pTableList, i); STableId* tableId = taosArrayGet(pTableList, i);
SPair p = {.first = pTable}; taosArrayPush(sa, tableId);
taosArrayPush(sa, &p);
} }
taosArrayPush(pTableGroup, &sa); taosArrayPush(pTableGroup, &sa);
uTrace("all %d tables belong to one group", size); uTrace("all %d tables belong to one group", size);
} else { } else {
STableGroupSupporter *pSupp = (STableGroupSupporter *) calloc(1, sizeof(STableGroupSupporter)); STableGroupSupporter *pSupp = (STableGroupSupporter *) calloc(1, sizeof(STableGroupSupporter));
pSupp->tsdbMeta = tsdbGetMeta(tsdb);
pSupp->numOfCols = numOfOrderCols; pSupp->numOfCols = numOfOrderCols;
pSupp->pTagSchema = pTagSchema; pSupp->pTagSchema = pTagSchema;
pSupp->pCols = pCols; pSupp->pCols = pCols;
taosqsort(pTableList->pData, size, POINTER_BYTES, pSupp, tableGroupComparFn); taosqsort(pTableList->pData, size, sizeof(STableId), pSupp, tableGroupComparFn);
createTableGroupImpl(pTableGroup, pTableList->pData, size, pSupp, tableGroupComparFn); createTableGroupImpl(pTableGroup, pTableList, size, pSupp, tableGroupComparFn);
tfree(pSupp); tfree(pSupp);
} }
...@@ -1371,14 +1453,14 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) { ...@@ -1371,14 +1453,14 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
int32_t ret = 0; int32_t ret = 0;
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) {
if (pInfo->optr == TSDB_RELATION_IN) { if (pInfo->optr == TSDB_RELATION_IN) {
ret = pInfo->compare(val, pInfo->q.arr); ret = pInfo->compare(val, pInfo->q);
} else { } else {
ret = pInfo->compare(val, pInfo->q.pz); ret = pInfo->compare(val, pInfo->q);
} }
} else { } else {
tVariant t = {0}; // tVariant t = {0};
tVariantCreateFromBinary(&t, val, (uint32_t)pInfo->sch.bytes, type); // tVariantCreateFromBinary(&t, val, (uint32_t)pInfo->sch.bytes, type);
ret = pInfo->compare(&t.i64Key, &pInfo->q.i64Key); ret = pInfo->compare(val, pInfo->q);
} }
switch (pInfo->optr) { switch (pInfo->optr) {
...@@ -1410,10 +1492,10 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) { ...@@ -1410,10 +1492,10 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
default: default:
assert(false); assert(false);
} }
return true; return true;
} }
static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr) { static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr) {
// query according to the binary expression // query according to the binary expression
STSchema* pSchema = pSTable->tagSchema; STSchema* pSchema = pSTable->tagSchema;
...@@ -1441,34 +1523,29 @@ static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr) ...@@ -1441,34 +1523,29 @@ static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr)
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t tsdbQuerySTableByTagCond(TsdbRepoT *tsdb, int64_t uid, const char *pTagCond, size_t len, int16_t tagNameRelType,
int32_t tsdbQueryByTagsCond( const char* tbnameCond, STableGroupInfo *pGroupInfo, SColIndex *pColIndex, int32_t numOfCols) {
TsdbRepoT *tsdb, STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid);
int64_t uid, if (pTable == NULL) {
const char *pTagCond, uError("failed to get stable, uid:%, %p" PRIu64, uid);
size_t len,
int16_t tagNameRelType,
const char* tbnameCond,
STableGroupInfo *pGroupInfo,
SColIndex *pColIndex,
int32_t numOfCols
) {
STable* pSTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid);
if (pSTable == NULL) {
uError("failed to get stable, uid:%" PRIu64, uid);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_INVALID_TABLE_ID;
} }
SArray* res = taosArrayInit(8, POINTER_BYTES); SArray* res = taosArrayInit(8, sizeof(STableId));
STSchema* pTagSchema = tsdbGetTableTagSchema(tsdbGetMeta(tsdb), pSTable); STSchema* pTagSchema = tsdbGetTableTagSchema(tsdbGetMeta(tsdb), pTable);
// no tags and tbname condition, all child tables of this stable are involved // no tags and tbname condition, all child tables of this stable are involved
if (tbnameCond == NULL && (pTagCond == NULL || len == 0)) { if (tbnameCond == NULL && (pTagCond == NULL || len == 0)) {
int32_t ret = getAllTableIdList(tsdb, uid, res); int32_t ret = getAllTableIdList(pTable, res);
if (ret == TSDB_CODE_SUCCESS) { if (ret == TSDB_CODE_SUCCESS) {
pGroupInfo->numOfTables = taosArrayGetSize(res); pGroupInfo->numOfTables = taosArrayGetSize(res);
pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols); pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, tsdb);
uTrace("no tbname condition or tagcond, all tables belongs to one group, numOfTables:%d", pGroupInfo->numOfTables);
} else {
// todo add error
} }
taosArrayDestroy(res); taosArrayDestroy(res);
return ret; return ret;
} }
...@@ -1504,9 +1581,9 @@ int32_t tsdbQueryByTagsCond( ...@@ -1504,9 +1581,9 @@ int32_t tsdbQueryByTagsCond(
// TODO: more error handling // TODO: more error handling
} END_TRY } END_TRY
doQueryTableList(pSTable, res, expr); doQueryTableList(pTable, res, expr);
pGroupInfo->numOfTables = taosArrayGetSize(res); pGroupInfo->numOfTables = taosArrayGetSize(res);
pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols); pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, tsdb);
taosArrayDestroy(res); taosArrayDestroy(res);
return ret; return ret;
...@@ -1522,9 +1599,9 @@ int32_t tsdbGetOneTableGroup(TsdbRepoT* tsdb, int64_t uid, STableGroupInfo* pGro ...@@ -1522,9 +1599,9 @@ int32_t tsdbGetOneTableGroup(TsdbRepoT* tsdb, int64_t uid, STableGroupInfo* pGro
pGroupInfo->numOfTables = 1; pGroupInfo->numOfTables = 1;
pGroupInfo->pGroupList = taosArrayInit(1, POINTER_BYTES); pGroupInfo->pGroupList = taosArrayInit(1, POINTER_BYTES);
SArray* group = taosArrayInit(1, POINTER_BYTES); SArray* group = taosArrayInit(1, sizeof(STableId));
taosArrayPush(group, &pTable); taosArrayPush(group, &pTable->tableId);
taosArrayPush(pGroupInfo->pGroupList, &group); taosArrayPush(pGroupInfo->pGroupList, &group);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -1546,12 +1623,10 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) { ...@@ -1546,12 +1623,10 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) {
} }
tfree(pTableCheckInfo->pDataCols); tfree(pTableCheckInfo->pDataCols);
tfree(pTableCheckInfo->pCompInfo); tfree(pTableCheckInfo->pCompInfo);
} }
taosArrayDestroy(pQueryHandle->pTableCheckInfo); taosArrayDestroy(pQueryHandle->pTableCheckInfo);
tfree(pQueryHandle->compIndex);
size_t cols = taosArrayGetSize(pQueryHandle->pColumns); size_t cols = taosArrayGetSize(pQueryHandle->pColumns);
for (int32_t i = 0; i < cols; ++i) { for (int32_t i = 0; i < cols; ++i) {
......
...@@ -98,13 +98,13 @@ void taosArrayRemove(SArray* pArray, size_t index); ...@@ -98,13 +98,13 @@ void taosArrayRemove(SArray* pArray, size_t index);
* @param pDst * @param pDst
* @param pSrc * @param pSrc
*/ */
void taosArrayCopy(SArray* pDst, SArray* pSrc); void taosArrayCopy(SArray* pDst, const SArray* pSrc);
/** /**
* clone a new array * clone a new array
* @param pSrc * @param pSrc
*/ */
SArray* taosArrayClone(SArray* pSrc); SArray* taosArrayClone(const SArray* pSrc);
/** /**
* destroy array list * destroy array list
......
...@@ -69,6 +69,7 @@ typedef struct { ...@@ -69,6 +69,7 @@ typedef struct {
SHashObj * pHashTable; SHashObj * pHashTable;
int numOfElemsInTrash; // number of element in trash int numOfElemsInTrash; // number of element in trash
int16_t deleting; // set the deleting flag to stop refreshing ASAP. int16_t deleting; // set the deleting flag to stop refreshing ASAP.
T_REF_DECLARE()
#if defined(LINUX) #if defined(LINUX)
pthread_rwlock_t lock; pthread_rwlock_t lock;
......
...@@ -38,9 +38,11 @@ int patternMatch(const char *zPattern, const char *zString, size_t size, const S ...@@ -38,9 +38,11 @@ int patternMatch(const char *zPattern, const char *zString, size_t size, const S
int WCSPatternMatch(const wchar_t *zPattern, const wchar_t *zString, size_t size, const SPatternCompareInfo *pInfo); int WCSPatternMatch(const wchar_t *zPattern, const wchar_t *zString, size_t size, const SPatternCompareInfo *pInfo);
int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size);
__compar_fn_t getKeyComparFunc(int32_t keyType); __compar_fn_t getKeyComparFunc(int32_t keyType);
__compar_fn_t getComparFunc(int32_t type, int32_t filterDataType, int32_t optr); __compar_fn_t getComparFunc(int32_t type, int32_t optr);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -110,11 +110,6 @@ extern "C" { ...@@ -110,11 +110,6 @@ extern "C" {
#define POW2(x) ((x) * (x)) #define POW2(x) ((x) * (x))
typedef struct SPair {
void* first;
void* sec;
} SPair;
int32_t strdequote(char *src); int32_t strdequote(char *src);
void strtrim(char *src); void strtrim(char *src);
...@@ -149,7 +144,7 @@ void getTmpfilePath(const char *fileNamePattern, char *dstPath); ...@@ -149,7 +144,7 @@ void getTmpfilePath(const char *fileNamePattern, char *dstPath);
int32_t taosInitTimer(void (*callback)(int), int32_t ms); int32_t taosInitTimer(void (*callback)(int), int32_t ms);
void taosUninitTimer(); void taosUninitTimer();
bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len); bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t* len);
int tasoUcs4Compare(void* f1_ucs4, void *f2_ucs4, int bytes); int tasoUcs4Compare(void* f1_ucs4, void *f2_ucs4, int bytes);
......
...@@ -143,7 +143,7 @@ void taosArrayRemove(SArray* pArray, size_t index) { ...@@ -143,7 +143,7 @@ void taosArrayRemove(SArray* pArray, size_t index) {
pArray->size -= 1; pArray->size -= 1;
} }
void taosArrayCopy(SArray* pDst, SArray* pSrc) { void taosArrayCopy(SArray* pDst, const SArray* pSrc) {
assert(pSrc != NULL && pDst != NULL); assert(pSrc != NULL && pDst != NULL);
if (pDst->capacity < pSrc->size) { if (pDst->capacity < pSrc->size) {
...@@ -162,7 +162,7 @@ void taosArrayCopy(SArray* pDst, SArray* pSrc) { ...@@ -162,7 +162,7 @@ void taosArrayCopy(SArray* pDst, SArray* pSrc) {
pDst->size = pSrc->size; pDst->size = pSrc->size;
} }
SArray* taosArrayClone(SArray* pSrc) { SArray* taosArrayClone(const SArray* pSrc) {
assert(pSrc != NULL); assert(pSrc != NULL);
if (pSrc->size == 0) { // empty array list if (pSrc->size == 0) { // empty array list
...@@ -176,7 +176,6 @@ SArray* taosArrayClone(SArray* pSrc) { ...@@ -176,7 +176,6 @@ SArray* taosArrayClone(SArray* pSrc) {
return dst; return dst;
} }
void taosArrayDestroy(SArray* pArray) { void taosArrayDestroy(SArray* pArray) {
if (pArray == NULL) { if (pArray == NULL) {
return; return;
......
...@@ -79,7 +79,7 @@ static FORCE_INLINE void taosFreeNode(void *data) { ...@@ -79,7 +79,7 @@ static FORCE_INLINE void taosFreeNode(void *data) {
*/ */
static SCacheDataNode *taosCreateHashNode(const char *key, size_t keyLen, const char *pData, size_t size, static SCacheDataNode *taosCreateHashNode(const char *key, size_t keyLen, const char *pData, size_t size,
uint64_t duration) { uint64_t duration) {
size_t totalSize = size + sizeof(SCacheDataNode) + keyLen; size_t totalSize = size + sizeof(SCacheDataNode) + keyLen + 1;
SCacheDataNode *pNewNode = calloc(1, totalSize); SCacheDataNode *pNewNode = calloc(1, totalSize);
if (pNewNode == NULL) { if (pNewNode == NULL) {
...@@ -324,13 +324,26 @@ static void doCleanupDataCache(SCacheObj *pCacheObj) { ...@@ -324,13 +324,26 @@ static void doCleanupDataCache(SCacheObj *pCacheObj) {
static void taosCacheRefresh(void *handle, void *tmrId) { static void taosCacheRefresh(void *handle, void *tmrId) {
SCacheObj *pCacheObj = (SCacheObj *)handle; SCacheObj *pCacheObj = (SCacheObj *)handle;
if (pCacheObj == NULL || taosHashGetSize(pCacheObj->pHashTable) == 0) { if (pCacheObj == NULL || T_REF_VAL_GET(pCacheObj) == 0) {
uTrace("object is destroyed. no refresh retry"); uTrace("object is destroyed. no refresh retry");
return; return;
} }
if (pCacheObj->deleting == 1) { int16_t ref = T_REF_INC(pCacheObj);
if (ref == 1) {
T_REF_DEC(pCacheObj);
return;
}
// todo add the ref before start the timer
int32_t num = taosHashGetSize(pCacheObj->pHashTable);
if (num == 0) {
ref = T_REF_DEC(pCacheObj);
if (ref == 0) {
doCleanupDataCache(pCacheObj); doCleanupDataCache(pCacheObj);
} else {
taosTmrReset(taosCacheRefresh, pCacheObj->refreshTime, pCacheObj, pCacheObj->tmrCtrl, &pCacheObj->pTimer);
}
return; return;
} }
...@@ -356,10 +369,13 @@ static void taosCacheRefresh(void *handle, void *tmrId) { ...@@ -356,10 +369,13 @@ static void taosCacheRefresh(void *handle, void *tmrId) {
taosHashDestroyIter(pIter); taosHashDestroyIter(pIter);
if (pCacheObj->deleting == 1) { // clean up resources and abort taosTrashEmpty(pCacheObj, false);
ref = T_REF_DEC(pCacheObj);
if (ref == 0) {
doCleanupDataCache(pCacheObj); doCleanupDataCache(pCacheObj);
return;
} else { } else {
taosTrashEmpty(pCacheObj, false);
taosTmrReset(taosCacheRefresh, pCacheObj->refreshTime, pCacheObj, pCacheObj->tmrCtrl, &pCacheObj->pTimer); taosTmrReset(taosCacheRefresh, pCacheObj->refreshTime, pCacheObj, pCacheObj->tmrCtrl, &pCacheObj->pTimer);
} }
} }
...@@ -399,6 +415,7 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTime) { ...@@ -399,6 +415,7 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTime) {
return NULL; return NULL;
} }
T_REF_INC(pCacheObj);
return pCacheObj; return pCacheObj;
} }
...@@ -552,5 +569,8 @@ void taosCacheCleanup(SCacheObj *pCacheObj) { ...@@ -552,5 +569,8 @@ void taosCacheCleanup(SCacheObj *pCacheObj) {
return; return;
} }
pCacheObj->deleting = 1; int32_t ref = T_REF_DEC(pCacheObj);
if (ref == 0) {
doCleanupDataCache(pCacheObj);
}
} }
...@@ -216,7 +216,7 @@ static UNUSED_FUNC int32_t compareStrPatternComp(const void* pLeft, const void* ...@@ -216,7 +216,7 @@ static UNUSED_FUNC int32_t compareStrPatternComp(const void* pLeft, const void*
} }
static int32_t compareFindStrInArray(const void* pLeft, const void* pRight) { static int32_t compareFindStrInArray(const void* pLeft, const void* pRight) {
const SArray* arr = (const SArray*)pRight; const SArray* arr = (const SArray*) pRight;
return taosArraySearchString(arr, pLeft) == NULL ? 0 : 1; return taosArraySearchString(arr, pLeft) == NULL ? 0 : 1;
} }
...@@ -232,55 +232,42 @@ static UNUSED_FUNC int32_t compareWStrPatternComp(const void* pLeft, const void* ...@@ -232,55 +232,42 @@ static UNUSED_FUNC int32_t compareWStrPatternComp(const void* pLeft, const void*
} }
// todo promote the type definition before the comparsion // todo promote the type definition before the comparsion
__compar_fn_t getComparFunc(int32_t type, int32_t filterDataType, int32_t optr) { __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
__compar_fn_t comparFn = NULL; __compar_fn_t comparFn = NULL;
switch (type) { switch (type) {
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_SMALLINT: {
case TSDB_DATA_TYPE_SMALLINT: comparFn = compareInt16Val; break;
case TSDB_DATA_TYPE_INT: }
case TSDB_DATA_TYPE_INT: {
comparFn = compareInt32Val; break;
}
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_TIMESTAMP: { case TSDB_DATA_TYPE_TIMESTAMP: {
// assert(type == filterDataType); comparFn = compareInt64Val; break;
if (filterDataType == TSDB_DATA_TYPE_BIGINT || filterDataType == TSDB_DATA_TYPE_TIMESTAMP) {
comparFn = compareInt64Val;
} else if (filterDataType >= TSDB_DATA_TYPE_FLOAT && filterDataType <= TSDB_DATA_TYPE_DOUBLE) {
comparFn = compareIntDoubleVal;
} }
break; case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT:{
comparFn = compareInt8Val; break;
} }
case TSDB_DATA_TYPE_BOOL: { case TSDB_DATA_TYPE_FLOAT: {
if (filterDataType >= TSDB_DATA_TYPE_BOOL && filterDataType <= TSDB_DATA_TYPE_BIGINT) { comparFn = compareDoubleVal; break;
comparFn = compareInt32Val;
} else if (filterDataType >= TSDB_DATA_TYPE_FLOAT && filterDataType <= TSDB_DATA_TYPE_DOUBLE) {
comparFn = compareIntDoubleVal;
}
break;
} }
case TSDB_DATA_TYPE_FLOAT:
case TSDB_DATA_TYPE_DOUBLE: { case TSDB_DATA_TYPE_DOUBLE: {
if (filterDataType >= TSDB_DATA_TYPE_BOOL && filterDataType <= TSDB_DATA_TYPE_BIGINT) { comparFn = compareDoubleVal; break;
comparFn = compareDoubleIntVal;
} else if (filterDataType >= TSDB_DATA_TYPE_FLOAT && filterDataType <= TSDB_DATA_TYPE_DOUBLE) {
comparFn = compareDoubleVal;
}
break;
} }
case TSDB_DATA_TYPE_BINARY: { case TSDB_DATA_TYPE_BINARY: {
if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */ if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */
assert(filterDataType == TSDB_DATA_TYPE_BINARY);
comparFn = compareStrPatternComp; comparFn = compareStrPatternComp;
} else if (optr == TSDB_RELATION_IN) { } else if (optr == TSDB_RELATION_IN) {
assert(filterDataType == TSDB_DATA_TYPE_ARRAY);
comparFn = compareFindStrInArray; comparFn = compareFindStrInArray;
} else { /* normal relational comparFn */ } else { /* normal relational comparFn */
assert(filterDataType == TSDB_DATA_TYPE_BINARY);
comparFn = compareStrVal; comparFn = compareStrVal;
} }
...@@ -288,8 +275,6 @@ __compar_fn_t getComparFunc(int32_t type, int32_t filterDataType, int32_t optr) ...@@ -288,8 +275,6 @@ __compar_fn_t getComparFunc(int32_t type, int32_t filterDataType, int32_t optr)
} }
case TSDB_DATA_TYPE_NCHAR: { case TSDB_DATA_TYPE_NCHAR: {
assert(filterDataType == TSDB_DATA_TYPE_NCHAR);
if (optr == TSDB_RELATION_LIKE) { if (optr == TSDB_RELATION_LIKE) {
comparFn = compareWStrPatternComp; comparFn = compareWStrPatternComp;
} else { } else {
...@@ -348,3 +333,30 @@ __compar_fn_t getKeyComparFunc(int32_t keyType) { ...@@ -348,3 +333,30 @@ __compar_fn_t getKeyComparFunc(int32_t keyType) {
return comparFn; return comparFn;
} }
int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) {
switch (type) {
case TSDB_DATA_TYPE_INT: DEFAULT_COMP(GET_INT32_VAL(f1), GET_INT32_VAL(f2));
case TSDB_DATA_TYPE_DOUBLE: DEFAULT_COMP(GET_DOUBLE_VAL(f1), GET_DOUBLE_VAL(f2));
case TSDB_DATA_TYPE_FLOAT: DEFAULT_COMP(GET_FLOAT_VAL(f1), GET_FLOAT_VAL(f2));
case TSDB_DATA_TYPE_BIGINT: DEFAULT_COMP(GET_INT64_VAL(f1), GET_INT64_VAL(f2));
case TSDB_DATA_TYPE_SMALLINT: DEFAULT_COMP(GET_INT16_VAL(f1), GET_INT16_VAL(f2));
case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_BOOL: DEFAULT_COMP(GET_INT8_VAL(f1), GET_INT8_VAL(f2));
case TSDB_DATA_TYPE_NCHAR: {
int32_t ret = wcsncmp((wchar_t*) f1, (wchar_t*) f2, size/TSDB_NCHAR_SIZE);
if (ret == 0) {
return ret;
}
return (ret < 0) ? -1 : 1;
}
default: {
int32_t ret = strncmp(f1, f2, (size_t)size);
if (ret == 0) {
return ret;
}
return (ret < 0) ? -1 : 1;
}
}
}
...@@ -325,7 +325,7 @@ SArray* tSkipListGet(SSkipList *pSkipList, SSkipListKey pKey, int16_t keyType) { ...@@ -325,7 +325,7 @@ SArray* tSkipListGet(SSkipList *pSkipList, SSkipListKey pKey, int16_t keyType) {
pSkipList->state.queryCount++; pSkipList->state.queryCount++;
#endif #endif
__compar_fn_t filterComparFn = getComparFunc(pSkipList->keyInfo.type, keyType, 0); __compar_fn_t filterComparFn = getComparFunc(pSkipList->keyInfo.type, 0);
int32_t ret = -1; int32_t ret = -1;
for (int32_t i = sLevel; i >= 0; --i) { for (int32_t i = sLevel; i >= 0; --i) {
SSkipListNode *p = SL_GET_FORWARD_POINTER(pNode, i); SSkipListNode *p = SL_GET_FORWARD_POINTER(pNode, i);
...@@ -389,7 +389,7 @@ SSkipListIterator *tSkipListCreateIterFromVal(SSkipList* pSkipList, const char* ...@@ -389,7 +389,7 @@ SSkipListIterator *tSkipListCreateIterFromVal(SSkipList* pSkipList, const char*
SSkipListNode *forward[MAX_SKIP_LIST_LEVEL] = {0}; SSkipListNode *forward[MAX_SKIP_LIST_LEVEL] = {0};
int32_t ret = -1; int32_t ret = -1;
__compar_fn_t filterComparFn = getComparFunc(pSkipList->keyInfo.type, type, 0); __compar_fn_t filterComparFn = getKeyComparFunc(pSkipList->keyInfo.type);
SSkipListNode* pNode = pSkipList->pHead; SSkipListNode* pNode = pSkipList->pHead;
for (int32_t i = pSkipList->level - 1; i >= 0; --i) { for (int32_t i = pSkipList->level - 1; i >= 0; --i) {
......
...@@ -490,7 +490,7 @@ bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) { ...@@ -490,7 +490,7 @@ bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
#endif #endif
} }
bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len) { bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t* len) {
memset(ucs4, 0, ucs4_max_len); memset(ucs4, 0, ucs4_max_len);
#ifdef USE_LIBICONV #ifdef USE_LIBICONV
iconv_t cd = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset); iconv_t cd = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
...@@ -501,6 +501,10 @@ bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len) ...@@ -501,6 +501,10 @@ bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len)
return false; return false;
} }
iconv_close(cd); iconv_close(cd);
if (len != NULL) {
*len = outLen;
}
return true; return true;
#else #else
mbstate_t state = {0}; mbstate_t state = {0};
......
...@@ -25,7 +25,7 @@ TEST(testCase, client_cache_test) { ...@@ -25,7 +25,7 @@ TEST(testCase, client_cache_test) {
const char* key1 = "test1"; const char* key1 = "test1";
char data1[] = "test11"; char data1[] = "test11";
char* cachedObj = (char*) taosCachePut(tscCacheHandle, key1, data1, strlen(data1), 1); char* cachedObj = (char*) taosCachePut(tscCacheHandle, key1, data1, strlen(data1)+1, 1);
sleep(REFRESH_TIME_IN_SEC+1); sleep(REFRESH_TIME_IN_SEC+1);
printf("obj is still valid: %s\n", cachedObj); printf("obj is still valid: %s\n", cachedObj);
...@@ -34,19 +34,17 @@ TEST(testCase, client_cache_test) { ...@@ -34,19 +34,17 @@ TEST(testCase, client_cache_test) {
taosCacheRelease(tscCacheHandle, (void**) &cachedObj, false); taosCacheRelease(tscCacheHandle, (void**) &cachedObj, false);
/* the object is cleared by cache clean operation */ /* the object is cleared by cache clean operation */
cachedObj = (char*) taosCachePut(tscCacheHandle, key1, data2, strlen(data2), 20); cachedObj = (char*) taosCachePut(tscCacheHandle, key1, data2, strlen(data2)+1, 20);
printf("after updated: %s\n", cachedObj); printf("after updated: %s\n", cachedObj);
printf("start to remove data from cache\n"); printf("start to remove data from cache\n");
taosCacheRelease(tscCacheHandle, (void**) &cachedObj, false); taosCacheRelease(tscCacheHandle, (void**) &cachedObj, false);
printf("end of removing data from cache\n"); printf("end of removing data from cache\n");
getchar();
const char* key3 = "test2"; const char* key3 = "test2";
const char* data3 = "kkkkkkk"; const char* data3 = "kkkkkkk";
char* cachedObj2 = (char*) taosCachePut(tscCacheHandle, key3, data3, strlen(data3), 1); char* cachedObj2 = (char*) taosCachePut(tscCacheHandle, key3, data3, strlen(data3) + 1, 1);
printf("%s\n", cachedObj2); printf("%s\n", cachedObj2);
taosCacheRelease(tscCacheHandle, (void**) &cachedObj2, false); taosCacheRelease(tscCacheHandle, (void**) &cachedObj2, false);
...@@ -57,18 +55,18 @@ TEST(testCase, client_cache_test) { ...@@ -57,18 +55,18 @@ TEST(testCase, client_cache_test) {
char key5[] = "test5"; char key5[] = "test5";
char data5[] = "data5kkkkk"; char data5[] = "data5kkkkk";
cachedObj2 = (char*) taosCachePut(tscCacheHandle, key5, data5, strlen(data5), 20); cachedObj2 = (char*) taosCachePut(tscCacheHandle, key5, data5, strlen(data5) + 1, 20);
const char* data6= "new Data after updated"; const char* data6= "new Data after updated";
taosCacheRelease(tscCacheHandle, (void**) &cachedObj2, false); taosCacheRelease(tscCacheHandle, (void**) &cachedObj2, false);
cachedObj2 = (char*) taosCachePut(tscCacheHandle, key5, data6, strlen(data6), 20); cachedObj2 = (char*) taosCachePut(tscCacheHandle, key5, data6, strlen(data6) + 1, 20);
printf("%s\n", cachedObj2); printf("%s\n", cachedObj2);
taosCacheRelease(tscCacheHandle, (void**) &cachedObj2, true); taosCacheRelease(tscCacheHandle, (void**) &cachedObj2, true);
const char* data7 = "add call update procedure"; const char* data7 = "add call update procedure";
cachedObj2 = (char*) taosCachePut(tscCacheHandle, key5, data7, strlen(data7), 20); cachedObj2 = (char*) taosCachePut(tscCacheHandle, key5, data7, strlen(data7) + 1, 20);
printf("%s\n=======================================\n\n", cachedObj2); printf("%s\n=======================================\n\n", cachedObj2);
char* cc = (char*) taosCacheAcquireByName(tscCacheHandle, key5); char* cc = (char*) taosCacheAcquireByName(tscCacheHandle, key5);
...@@ -137,6 +135,4 @@ TEST(testCase, cache_resize_test) { ...@@ -137,6 +135,4 @@ TEST(testCase, cache_resize_test) {
printf("retrieve %d object cost:%" PRIu64 " us,avg:%f\n", num, endTime - startTime, (endTime - startTime)/(double)num); printf("retrieve %d object cost:%" PRIu64 " us,avg:%f\n", num, endTime - startTime, (endTime - startTime)/(double)num);
taosCacheCleanup(pCache); taosCacheCleanup(pCache);
taosMsleep(20000);
getchar();
} }
\ No newline at end of file
...@@ -140,6 +140,8 @@ int32_t vnodeDrop(int32_t vgId) { ...@@ -140,6 +140,8 @@ int32_t vnodeDrop(int32_t vgId) {
int32_t vnodeAlter(void *param, SMDCreateVnodeMsg *pVnodeCfg) { int32_t vnodeAlter(void *param, SMDCreateVnodeMsg *pVnodeCfg) {
SVnodeObj *pVnode = param; SVnodeObj *pVnode = param;
pVnode->status = TAOS_VN_STATUS_UPDATING;
int32_t code = vnodeSaveCfg(pVnodeCfg); int32_t code = vnodeSaveCfg(pVnodeCfg);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
dError("vgId:%d, failed to save vnode cfg, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(code)); dError("vgId:%d, failed to save vnode cfg, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(code));
...@@ -167,6 +169,8 @@ int32_t vnodeAlter(void *param, SMDCreateVnodeMsg *pVnodeCfg) { ...@@ -167,6 +169,8 @@ int32_t vnodeAlter(void *param, SMDCreateVnodeMsg *pVnodeCfg) {
return code; return code;
} }
pVnode->status = TAOS_VN_STATUS_READY;
dTrace("pVnode:%p vgId:%d, vnode is altered", pVnode, pVnode->vgId); dTrace("pVnode:%p vgId:%d, vnode is altered", pVnode, pVnode->vgId);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
......
...@@ -56,7 +56,7 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, void *pCont, int32_t cont ...@@ -56,7 +56,7 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, void *pCont, int32_t cont
qinfo_t pQInfo = NULL; qinfo_t pQInfo = NULL;
if (contLen != 0) { if (contLen != 0) {
pRet->code = qCreateQueryInfo(pVnode->tsdb, pQueryTableMsg, &pQInfo); pRet->code = qCreateQueryInfo(pVnode->tsdb, pVnode->vgId, pQueryTableMsg, &pQInfo);
SQueryTableRsp *pRsp = (SQueryTableRsp *) rpcMallocCont(sizeof(SQueryTableRsp)); SQueryTableRsp *pRsp = (SQueryTableRsp *) rpcMallocCont(sizeof(SQueryTableRsp));
pRsp->qhandle = htobe64((uint64_t) (pQInfo)); pRsp->qhandle = htobe64((uint64_t) (pQInfo));
......
...@@ -51,7 +51,7 @@ int32_t vnodeProcessWrite(void *param1, int qtype, void *param2, void *item) { ...@@ -51,7 +51,7 @@ int32_t vnodeProcessWrite(void *param1, int qtype, void *param2, void *item) {
if (vnodeProcessWriteMsgFp[pHead->msgType] == NULL) if (vnodeProcessWriteMsgFp[pHead->msgType] == NULL)
return TSDB_CODE_MSG_NOT_PROCESSED; return TSDB_CODE_MSG_NOT_PROCESSED;
if (pVnode->status == TAOS_VN_STATUS_DELETING || pVnode->status == TAOS_VN_STATUS_CLOSING) if (pVnode->status != TAOS_VN_STATUS_READY)
return TSDB_CODE_NOT_ACTIVE_VNODE; return TSDB_CODE_NOT_ACTIVE_VNODE;
if (pHead->version == 0) { // from client if (pHead->version == 0) { // from client
...@@ -136,6 +136,7 @@ static int32_t vnodeProcessCreateTableMsg(SVnodeObj *pVnode, void *pCont, SRspRe ...@@ -136,6 +136,7 @@ static int32_t vnodeProcessCreateTableMsg(SVnodeObj *pVnode, void *pCont, SRspRe
} }
tsdbTableSetTagSchema(&tCfg, pDestTagSchema, false); tsdbTableSetTagSchema(&tCfg, pDestTagSchema, false);
tsdbTableSetSName(&tCfg, pTable->superTableId, false); tsdbTableSetSName(&tCfg, pTable->superTableId, false);
tsdbTableSetSuperUid(&tCfg, htobe64(pTable->superTableUid));
char *pTagData = pTable->data + totalCols * sizeof(SSchema); char *pTagData = pTable->data + totalCols * sizeof(SSchema);
int accumBytes = 0; int accumBytes = 0;
......
...@@ -75,7 +75,15 @@ int main(int argc, char *argv[]) { ...@@ -75,7 +75,15 @@ int main(int argc, char *argv[]) {
doQuery(taos, "create database if not exists test"); doQuery(taos, "create database if not exists test");
doQuery(taos, "use test"); doQuery(taos, "use test");
doQuery(taos, "select count(*),k,sum(k) from m1 group by k"); doQuery(taos, "select * from t1 order by ts desc");
// doQuery(taos, "create table t1(ts timestamp, k binary(12), f nchar(2))");
// for(int32_t i = 0; i< 100000; ++i) {
// doQuery(taos, "select m1.ts,m1.a from m1, m2 where m1.ts=m2.ts and m1.a=m2.b;");
// usleep(500000);
// }
// doQuery(taos, "insert into tm0 values('2020-1-1 1:1:1', 'abc')");
// doQuery(taos, "create table if not exists tm0 (ts timestamp, k int);"); // doQuery(taos, "create table if not exists tm0 (ts timestamp, k int);");
// doQuery(taos, "insert into tm0 values('2020-1-1 1:1:1', 1);"); // doQuery(taos, "insert into tm0 values('2020-1-1 1:1:1', 1);");
// doQuery(taos, "insert into tm0 values('2020-1-1 1:1:2', 2);"); // doQuery(taos, "insert into tm0 values('2020-1-1 1:1:2', 2);");
......
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
sleep 5000 sleep 5000
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c commitLog -v 0 system sh/cfg.sh -n dnode1 -c clog -v 0
system sh/cfg.sh -n dnode1 -c http -v 1
system sh/cfg.sh -n dnode1 -c httpEnableRecordSql -v 1 system sh/cfg.sh -n dnode1 -c httpEnableRecordSql -v 1
system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode1 -s start
......
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
sleep 5000
#sleep 5000
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c clog -v 0 system sh/cfg.sh -n dnode1 -c clog -v 0
system sh/cfg.sh -n dnode1 -c http -v 1
system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode1 -s start
#sleep 3000 #sleep 3000
...@@ -14,57 +12,57 @@ print ============================ dnode1 start ...@@ -14,57 +12,57 @@ print ============================ dnode1 start
print =============== step1 - login print =============== step1 - login
system_content curl 192.168.0.1:6020/rest/ system_content curl 127.0.0.1:6020/rest/
print 1-> $system_content print 1-> $system_content
if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then
return -1 return -1
endi endi
system_content curl 192.168.0.1:6020/rest/xx system_content curl 127.0.0.1:6020/rest/xx
print 2-> $system_content print 2-> $system_content
if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then
return -1 return -1
endi endi
system_content curl 192.168.0.1:6020/rest/login system_content curl 127.0.0.1:6020/rest/login
print 3-> $system_content print 3-> $system_content
if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then
return -1 return -1
endi endi
#4 #4
system_content curl 192.168.0.1:6020/rest/login/root system_content curl 127.0.0.1:6020/rest/login/root
print 4-> $system_content print 4-> $system_content
if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then
return -1 return -1
endi endi
system_content curl 192.168.0.1:6020/rest/login/root/123 system_content curl 127.0.0.1:6020/rest/login/root/123
print 5-> $system_content print 5-> $system_content
if $system_content != @{"status":"error","code":1000,"desc":"auth failure"}@ then if $system_content != @{"status":"error","code":1000,"desc":"auth failure"}@ then
return -1 return -1
endi endi
system_content curl 192.168.0.1:6020/rest/login/root/123/1/1/3 system_content curl 127.0.0.1:6020/rest/login/root/123/1/1/3
print 6-> $system_content print 6-> $system_content
if $system_content != @{"status":"error","code":1000,"desc":"auth failure"}@ then if $system_content != @{"status":"error","code":1000,"desc":"auth failure"}@ then
return -1 return -1
endi endi
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 192.168.0.1:6020/rest/login/root/1 system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:6020/rest/login/root/1
print 7-> $system_content print 7-> $system_content
if $system_content != @{"status":"error","code":1000,"desc":"auth failure"}@ then if $system_content != @{"status":"error","code":1000,"desc":"auth failure"}@ then
return -1 return -1
endi endi
#8 #8
system_content curl -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3d3cudGFvc2RhdGEuY29tIiwicGFzcyI6InRhb3NkYXRhIiwic3ViIjoicm9vdCJ9.xPv3b5odlR7YF8G_QWASjIRbMtA5v4ItToJ35fFgi' -d 'show databases' 192.168.0.1:6020/rest/login/root/1 system_content curl -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3d3cudGFvc2RhdGEuY29tIiwicGFzcyI6InRhb3NkYXRhIiwic3ViIjoicm9vdCJ9.xPv3b5odlR7YF8G_QWASjIRbMtA5v4ItToJ35fFgi' -d 'show databases' 127.0.0.1:6020/rest/login/root/1
print 8-> $system_content print 8-> $system_content
if $system_content != @{"status":"error","code":1010,"desc":"invalid type of Authorization"}@ then if $system_content != @{"status":"error","code":1010,"desc":"invalid type of Authorization"}@ then
return -1 return -1
endi endi
system_content curl -H 'Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3d3cudGFvc2RhdGEuY29tIiwicGFzcyI6InRhb3NkYXRhIiwic3ViIjoicm9vdCJ9.xPv3b5odlR7YF8G_QWASjIRbMtA5v4ItToJ35fFgi' -d 'show databases' 192.168.0.1:6020/rest/login/root/1 system_content curl -H 'Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3d3cudGFvc2RhdGEuY29tIiwicGFzcyI6InRhb3NkYXRhIiwic3ViIjoicm9vdCJ9.xPv3b5odlR7YF8G_QWASjIRbMtA5v4ItToJ35fFgi' -d 'show databases' 127.0.0.1:6020/rest/login/root/1
print 9-> $system_content print 9-> $system_content
if $system_content != @{"status":"error","code":1010,"desc":"invalid type of Authorization"}@ then if $system_content != @{"status":"error","code":1010,"desc":"invalid type of Authorization"}@ then
return -1 return -1
...@@ -72,7 +70,7 @@ endi ...@@ -72,7 +70,7 @@ endi
sleep 3000 sleep 3000
system_content curl 192.168.0.1:6020/rest/login/root/taosdata/ system_content curl 127.0.0.1:6020/rest/login/root/taosdata/
print 10-> $system_content print 10-> $system_content
if $system_content != @{"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04"}@ then if $system_content != @{"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04"}@ then
return -1 return -1
...@@ -81,52 +79,52 @@ endi ...@@ -81,52 +79,52 @@ endi
print =============== step2 - no db print =============== step2 - no db
#11 #11
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:6020/rest/sql
print 11-> $system_content print 11-> $system_content
if $system_content != @{"status":"succ","head":["name","create time","ntables","vgroups","replica","days","keep1,keep2,keep(D)","tables","cache(MB)","blocks","minrows","maxrows","ctime(s)","clog","comp","precision","status"],"data":[],"rows":0}@ then if $system_content != @{"status":"succ","head":["name","create time","ntables","vgroups","replica","days","keep1,keep2,keep(D)","tables","cache(MB)","blocks","minrows","maxrows","ctime(s)","clog","comp","precision","status"],"data":[],"rows":0}@ then
return -1 return -1
endi endi
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database d1' 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database d1' 127.0.0.1:6020/rest/sql
print 12-> $system_content print 12-> $system_content
if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[0]],"rows":0}@ then if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[0]],"rows":0}@ then
return -1 return -1
endi endi
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database d1' 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database d1' 127.0.0.1:6020/rest/sql
print 13-> $system_content print 13-> $system_content
if $system_content != @{"status":"error","code":1000,"desc":"DB already there"}@ then if $system_content != @{"status":"error","code":1000,"desc":"DB already there"}@ then
return -1 return -1
endi endi
#14 #14
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d '' 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d '' 127.0.0.1:6020/rest/sql
print 14-> $system_content print 14-> $system_content
if $system_content != @{"status":"error","code":1012,"desc":"no sql input"}@ then if $system_content != @{"status":"error","code":1012,"desc":"no sql input"}@ then
return -1 return -1
endi endi
#system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'use d1' 192.168.0.1:6020/rest/sql #system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'use d1' 127.0.0.1:6020/rest/sql
#print 15-> $system_content #print 15-> $system_content
#if $system_content != @{"status":"error","code":1017,"desc":"no need to execute use db cmd"}@ then #if $system_content != @{"status":"error","code":1017,"desc":"no need to execute use db cmd"}@ then
#if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[1]],"rows":1}@ then #if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[1]],"rows":1}@ then
# return -1 # return -1
#endi #endi
#system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' use d1' 192.168.0.1:6020/rest/sql #system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' use d1' 127.0.0.1:6020/rest/sql
#print 16-> $system_content #print 16-> $system_content
#if $system_content != @{"status":"error","code":1017,"desc":"no need to execute use db cmd"}@ then #if $system_content != @{"status":"error","code":1017,"desc":"no need to execute use db cmd"}@ then
# return -1 # return -1
#endi #endi
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' used1' 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' used1' 127.0.0.1:6020/rest/sql
print 17-> $system_content print 17-> $system_content
if $system_content != @{"status":"error","code":1000,"desc":"invalid SQL: invalid SQL: syntax error near 'used1'"}@ then if $system_content != @{"status":"error","code":1000,"desc":"invalid SQL: invalid SQL: syntax error near 'used1'"}@ then
return -1 return -1
endi endi
#18 #18
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' show tables;' 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' show tables;' 127.0.0.1:6020/rest/sql
print 18-> $system_content print 18-> $system_content
if $system_content != @{"status":"error","code":1000,"desc":"db not selected"}@ then if $system_content != @{"status":"error","code":1000,"desc":"db not selected"}@ then
return -1 return -1
...@@ -135,44 +133,44 @@ endi ...@@ -135,44 +133,44 @@ endi
print =============== step3 - db print =============== step3 - db
#19 #19
#system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' show tables;' 192.168.0.1:6020/rest/sql/d4 #system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' show tables;' 127.0.0.1:6020/rest/sql/d4
#print 19-> $system_content #print 19-> $system_content
#if $system_content != @{"status":"error","code":1000,"desc":"invalid DB"}@ then #if $system_content != @{"status":"error","code":1000,"desc":"invalid DB"}@ then
# return -1 # return -1
#endi #endi
#system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' show tables;' 192.168.0.1:6020/rest/sql/d1 #system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' show tables;' 127.0.0.1:6020/rest/sql/d1
#print 20-> $system_content #print 20-> $system_content
#if $system_content != @{"status":"succ","head":["name","created time","columns","metric"],"data":[],"rows":0}@ then #if $system_content != @{"status":"succ","head":["name","created time","columns","metric"],"data":[],"rows":0}@ then
# return -1 # return -1
#endi #endi
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d1.t1;' 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d1.t1;' 127.0.0.1:6020/rest/sql
print 21-> $system_content print 21-> $system_content
if $system_content != @{"status":"error","code":1000,"desc":"invalid table name"}@ then if $system_content != @{"status":"error","code":1000,"desc":"invalid table name"}@ then
return -1 return -1
endi endi
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' create table d1.t1 (ts timestamp, speed int)' 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' create table d1.t1 (ts timestamp, speed int)' 127.0.0.1:6020/rest/sql
print 22-> $system_content print 22-> $system_content
if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[0]],"rows":0}@ then if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[0]],"rows":0}@ then
return -1 return -1
endi endi
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d1.t1 ' 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d1.t1 ' 127.0.0.1:6020/rest/sql
print 23-> $system_content print 23-> $system_content
if $system_content != @{"status":"succ","head":["ts","speed"],"data":[],"rows":0}@ then if $system_content != @{"status":"succ","head":["ts","speed"],"data":[],"rows":0}@ then
return -1 return -1
endi endi
#24 #24
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:41.022', 1)" 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:41.022', 1)" 127.0.0.1:6020/rest/sql
print 24-> $system_content print 24-> $system_content
if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[1]],"rows":1}@ then if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[1]],"rows":1}@ then
return -1 return -1
endi endi
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d1.t1 ' 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d1.t1 ' 127.0.0.1:6020/rest/sql
print 25-> $system_content print 25-> $system_content
if $system_content != @{"status":"succ","head":["ts","speed"],"data":[["2017-12-25 21:28:41.022",1]],"rows":1}@ then if $system_content != @{"status":"succ","head":["ts","speed"],"data":[["2017-12-25 21:28:41.022",1]],"rows":1}@ then
return -1 return -1
...@@ -180,53 +178,53 @@ endi ...@@ -180,53 +178,53 @@ endi
#26 #26
print 25-> no print print 25-> no print
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:42.022', 2)" 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:42.022', 2)" 127.0.0.1:6020/rest/sql
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:43.022', 3)" 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:43.022', 3)" 127.0.0.1:6020/rest/sql
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:44.022', 4)" 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:44.022', 4)" 127.0.0.1:6020/rest/sql
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:45.022', 5)" 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:45.022', 5)" 127.0.0.1:6020/rest/sql
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:46.022', 6)" 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:46.022', 6)" 127.0.0.1:6020/rest/sql
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:47.022', 7)" 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:47.022', 7)" 127.0.0.1:6020/rest/sql
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:48.022', 8)" 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:48.022', 8)" 127.0.0.1:6020/rest/sql
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:49.022', 9)" 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:49.022', 9)" 127.0.0.1:6020/rest/sql
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:50.022', 10)" 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:50.022', 10)" 127.0.0.1:6020/rest/sql
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:51.022', 11)" 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:51.022', 11)" 127.0.0.1:6020/rest/sql
#27 #27
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d1.t1 ' 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d1.t1 ' 127.0.0.1:6020/rest/sql
print 27-> $system_content print 27-> $system_content
if $system_content != @{"status":"succ","head":["ts","speed"],"data":[["2017-12-25 21:28:41.022",1],["2017-12-25 21:28:42.022",2],["2017-12-25 21:28:43.022",3],["2017-12-25 21:28:44.022",4],["2017-12-25 21:28:45.022",5],["2017-12-25 21:28:46.022",6],["2017-12-25 21:28:47.022",7],["2017-12-25 21:28:48.022",8],["2017-12-25 21:28:49.022",9],["2017-12-25 21:28:50.022",10],["2017-12-25 21:28:51.022",11]],"rows":11}@ then if $system_content != @{"status":"succ","head":["ts","speed"],"data":[["2017-12-25 21:28:41.022",1],["2017-12-25 21:28:42.022",2],["2017-12-25 21:28:43.022",3],["2017-12-25 21:28:44.022",4],["2017-12-25 21:28:45.022",5],["2017-12-25 21:28:46.022",6],["2017-12-25 21:28:47.022",7],["2017-12-25 21:28:48.022",8],["2017-12-25 21:28:49.022",9],["2017-12-25 21:28:50.022",10],["2017-12-25 21:28:51.022",11]],"rows":11}@ then
return -1 return -1
endi endi
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database d2' 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database d2' 127.0.0.1:6020/rest/sql
print 28-> $system_content print 28-> $system_content
if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[0]],"rows":0}@ then if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[0]],"rows":0}@ then
return -1 return -1
endi endi
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' create table d2.t1 (ts timestamp, speed int)' 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' create table d2.t1 (ts timestamp, speed int)' 127.0.0.1:6020/rest/sql
print 29-> $system_content print 29-> $system_content
if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[0]],"rows":0}@ then if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[0]],"rows":0}@ then
return -1 return -1
endi endi
#30 #30
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d2.t1 values('2017-12-25 21:28:41.022', 1)" 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d2.t1 values('2017-12-25 21:28:41.022', 1)" 127.0.0.1:6020/rest/sql
print 30-> $system_content print 30-> $system_content
if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[1]],"rows":1}@ then if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[1]],"rows":1}@ then
return -1 return -1
endi endi
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d2.t1 ' 192.168.0.1:6020/rest/sql system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d2.t1 ' 127.0.0.1:6020/rest/sql
print 31-> $system_content print 31-> $system_content
if $system_content != @{"status":"succ","head":["ts","speed"],"data":[["2017-12-25 21:28:41.022",1]],"rows":1}@ then if $system_content != @{"status":"succ","head":["ts","speed"],"data":[["2017-12-25 21:28:41.022",1]],"rows":1}@ then
return -1 return -1
......
...@@ -106,6 +106,7 @@ echo "httpDebugFlag 135" >> $TAOS_CFG ...@@ -106,6 +106,7 @@ echo "httpDebugFlag 135" >> $TAOS_CFG
echo "monitorDebugFlag 131" >> $TAOS_CFG echo "monitorDebugFlag 131" >> $TAOS_CFG
echo "udebugFlag 131" >> $TAOS_CFG echo "udebugFlag 131" >> $TAOS_CFG
echo "jnidebugFlag 131" >> $TAOS_CFG echo "jnidebugFlag 131" >> $TAOS_CFG
echo "sdebugFlag 135" >> $TAOS_CFG
echo "monitor 0" >> $TAOS_CFG echo "monitor 0" >> $TAOS_CFG
echo "http 0" >> $TAOS_CFG echo "http 0" >> $TAOS_CFG
echo "numOfThreadsPerCore 2.0" >> $TAOS_CFG echo "numOfThreadsPerCore 2.0" >> $TAOS_CFG
......
...@@ -43,6 +43,7 @@ step3: ...@@ -43,6 +43,7 @@ step3:
print ============= step4 print ============= step4
sql close sql close
sleep 1000
sql connect sql connect
sleep 2000 sleep 2000
sql create account oroot pass 'taosdata' sql create account oroot pass 'taosdata'
......
...@@ -4,7 +4,7 @@ run unique/account/account_len.sim ...@@ -4,7 +4,7 @@ run unique/account/account_len.sim
run unique/account/authority.sim run unique/account/authority.sim
run unique/account/basic.sim run unique/account/basic.sim
run unique/account/paras.sim run unique/account/paras.sim
run unique/account/pass_alter.sim #run unique/account/pass_alter.sim
run unique/account/pass_len.sim run unique/account/pass_len.sim
run unique/account/usage.sim run unique/account/usage.sim
run unique/account/user_create.sim run unique/account/user_create.sim
......
...@@ -3,30 +3,50 @@ system sh/deploy.sh -n dnode1 -i 1 ...@@ -3,30 +3,50 @@ system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2 system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3 system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4 system sh/deploy.sh -n dnode4 -i 4
system sh/deploy.sh -n dnode5 -i 5
system sh/cfg.sh -n dnode1 -c numOfMPeers -v 3 system sh/deploy.sh -n dnode6 -i 6
system sh/cfg.sh -n dnode2 -c numOfMPeers -v 3 system sh/deploy.sh -n dnode7 -i 7
system sh/cfg.sh -n dnode3 -c numOfMPeers -v 3 system sh/deploy.sh -n dnode8 -i 8
system sh/cfg.sh -n dnode4 -c numOfMPeers -v 3
system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode5 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode1 -c clog -v 1 system sh/cfg.sh -n dnode6 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode2 -c clog -v 1 system sh/cfg.sh -n dnode7 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode3 -c clog -v 1 system sh/cfg.sh -n dnode8 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode4 -c clog -v 1
system sh/cfg.sh -n dnode1 -c numOfMpeers -v 3
system sh/cfg.sh -n dnode2 -c numOfMpeers -v 3
system sh/cfg.sh -n dnode3 -c numOfMpeers -v 3
system sh/cfg.sh -n dnode4 -c numOfMpeers -v 3
system sh/cfg.sh -n dnode5 -c numOfMpeers -v 3
system sh/cfg.sh -n dnode6 -c numOfMpeers -v 3
system sh/cfg.sh -n dnode7 -c numOfMpeers -v 3
system sh/cfg.sh -n dnode8 -c numOfMpeers -v 3
system sh/cfg.sh -n dnode1 -c mgmtEqualVnodeNum -v 0 system sh/cfg.sh -n dnode1 -c mgmtEqualVnodeNum -v 0
system sh/cfg.sh -n dnode2 -c mgmtEqualVnodeNum -v 0 system sh/cfg.sh -n dnode2 -c mgmtEqualVnodeNum -v 0
system sh/cfg.sh -n dnode3 -c mgmtEqualVnodeNum -v 0 system sh/cfg.sh -n dnode3 -c mgmtEqualVnodeNum -v 0
system sh/cfg.sh -n dnode4 -c mgmtEqualVnodeNum -v 0 system sh/cfg.sh -n dnode4 -c mgmtEqualVnodeNum -v 0
system sh/cfg.sh -n dnode5 -c mgmtEqualVnodeNum -v 0
system sh/cfg.sh -n dnode6 -c mgmtEqualVnodeNum -v 0
system sh/cfg.sh -n dnode7 -c mgmtEqualVnodeNum -v 0
system sh/cfg.sh -n dnode8 -c mgmtEqualVnodeNum -v 0
system sh/cfg.sh -n dnode1 -c clog -v 1
system sh/cfg.sh -n dnode2 -c clog -v 1
system sh/cfg.sh -n dnode3 -c clog -v 1
system sh/cfg.sh -n dnode4 -c clog -v 1
system sh/cfg.sh -n dnode5 -c clog -v 1
system sh/cfg.sh -n dnode6 -c clog -v 1
system sh/cfg.sh -n dnode7 -c clog -v 1
system sh/cfg.sh -n dnode8 -c clog -v 1
print ============== step1 print ============== step1
print ========= start dnode1 print ========= start dnode1
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sql connect sql connect
sql create database c_b1_d1 tables 4 sql create database c_b1_d1 tables 4
...@@ -49,9 +69,9 @@ sql insert into c_b1_t2 values(1520000023022, 22) ...@@ -49,9 +69,9 @@ sql insert into c_b1_t2 values(1520000023022, 22)
sql insert into c_b1_t2 values(1520000024021, 21) sql insert into c_b1_t2 values(1520000024021, 21)
sql show dnodes sql show dnodes
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
...@@ -65,7 +85,7 @@ print ============================== step2 ...@@ -65,7 +85,7 @@ print ============================== step2
print ========= start dnode2 print ========= start dnode2
sleep 2000 sleep 2000
sql create dnode $hostname2 sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 5000 sleep 5000
$x = 0 $x = 0
...@@ -76,27 +96,23 @@ show2: ...@@ -76,27 +96,23 @@ show2:
return -1 return -1
endi endi
sql show dnodes -x show2 sql show dnodes -x show2
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 3 then if $dnode1Vnodes != 1 then
goto show2 goto show2
endi endi
if $dnode2Vnodes != 3 then if $dnode2Vnodes != 1 then
goto show2 goto show2
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3
$dnode4Role = $data3_192.168.0.4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role
print ============================== step3 print ============================== step3
print ========= add db3 print ========= add db3
...@@ -122,12 +138,12 @@ show4: ...@@ -122,12 +138,12 @@ show4:
return -1 return -1
endi endi
sql show dnodes -x show4 sql show dnodes -x show4
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 1 then if $dnode1Vnodes != 3 then
goto show4 goto show4
endi endi
if $dnode2Vnodes != null then if $dnode2Vnodes != null then
...@@ -135,10 +151,10 @@ if $dnode2Vnodes != null then ...@@ -135,10 +151,10 @@ if $dnode2Vnodes != null then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -146,16 +162,10 @@ print dnode4 ==> $dnode4Role ...@@ -146,16 +162,10 @@ print dnode4 ==> $dnode4Role
print ============================== step5 print ============================== step5
print ========= add dnode2 print ========= add dnode2
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec_up.sh -n dnode2 -s stop -x SIGINT
sleep 3000
system sh/deploy.sh -n dnode2 -i 2
system sh/cfg.sh -n dnode2 -c numOfMPeers -v 3
system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode2 -c clog -v 1
system sh/cfg.sh -n dnode2 -c mgmtEqualVnodeNum -v 0
sleep 3000 sleep 3000
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode3 -s start
sql create dnode $hostname2 sql create dnode $hostname3
sleep 9000 sleep 9000
$x = 0 $x = 0
...@@ -166,119 +176,42 @@ show5: ...@@ -166,119 +176,42 @@ show5:
return -1 return -1
endi endi
sql show dnodes -x show5 sql show dnodes -x show5
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode3Vnodes = $data2_3
print dnode2 $dnode2Vnodes print dnode2 $dnode3Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
goto show5 goto show5
endi endi
if $dnode2Vnodes != 3 then if $dnode3Vnodes != 1 then
goto show5 goto show5
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode3Role = $data2_3
$dnode3Role = $data3_192.168.0.3 $dnode4Role = $data2_4
$dnode4Role = $data3_192.168.0.4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role print dnode4 ==> $dnode4Role
print ============================== step6 if $dnode1Role != master then
print ========= drop dnode1
system sh/exec.sh -n dnode1 -s stop -x SIGINT
print stop dnode1 and sleep 10000
sleep 10000
sql drop dnode $hostname1
print drop dnode1 and sleep 9000
sleep 9000
$x = 0
show6:
$x = $x + 1
sleep 2000
if $x == 30 then
return -1 return -1
endi
sql show dnodes -x show6
$dnode1Vnodes = $data3_192.168.0.1
print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2
print dnode2 $dnode2Vnodes
if $dnode1Vnodes != null then
goto show6
endi endi
if $dnode2Vnodes != 1 then if $dnode3Role != slave then
goto show6 return -1
endi endi
sql show mnodes print ============================== step6
$dnode1Role = $data3_192.168.0.1 sql_error drop dnode $hostname1
$dnode2Role = $data3_192.168.0.2
$dnode3Role = $data3_192.168.0.3
$dnode4Role = $data3_192.168.0.4
print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role
print ============================== step7 print ============================== step7
print ========= add dnode1 sql_error create dnode $hostname1
sql create dnode $hostname1
sleep 3000
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c numOfMPeers -v 3
system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode1 -c clog -v 1
system sh/cfg.sh -n dnode1 -c mgmtEqualVnodeNum -v 0
sleep 23000
system sh/exec.sh -n dnode1 -s start
sleep 14000
$x = 0
show7:
$x = $x + 1
sleep 2000
if $x == 20 then
return -1
endi
sql show dnodes -x show7
$dnode1Vnodes = $data3_192.168.0.1
print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2
print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 3 then
goto show7
endi
if $dnode2Vnodes != 2 then
goto show7
endi
sql show mnodes
$dnode1Role = $data3_192.168.0.1
$dnode2Role = $data3_192.168.0.2
$dnode3Role = $data3_192.168.0.3
$dnode4Role = $data3_192.168.0.4
print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role
print ============================== step8 print ============================== step8
print ========= drop dnode2 sql drop dnode $hostname3
system sh/exec.sh -n dnode2 -s stop -x SIGINT sleep 15000
print stop dnode2 and sleep 10000
sleep 20000
sql drop dnode $hostname2
print drop dnode2 and sleep 9000
sleep 19000
$x = 0 $x = 0
show8: show8:
...@@ -288,25 +221,23 @@ show8: ...@@ -288,25 +221,23 @@ show8:
return -1 return -1
endi endi
sql show dnodes -x show8 sql show dnodes -x show8
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode3Vnodes = $data2_3
print dnode2 $dnode2Vnodes print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 1 then if $dnode1Vnodes != 3 then
goto show8 goto show8
endi endi
if $dnode2Vnodes != null then if $dnode3Vnodes != null then
goto show8 goto show8
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode3Role = $data2_3
$dnode3Role = $data3_192.168.0.3 $dnode4Role = $data2_4
$dnode4Role = $data3_192.168.0.4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role print dnode4 ==> $dnode4Role
...@@ -314,16 +245,13 @@ if $dnode1Role != master then ...@@ -314,16 +245,13 @@ if $dnode1Role != master then
return -1 return -1
endi endi
if $dnode3Role != null then
return -1
endi
print ============================== step9 print ============================== step9
print ========= add dnode2 sql create dnode $hostname4
sql create dnode $hostname2 system sh/exec_up.sh -n dnode4 -s start
system sh/deploy.sh -n dnode2 -i 2
system sh/cfg.sh -n dnode2 -c numOfMPeers -v 3
system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode2 -c clog -v 1
system sh/cfg.sh -n dnode2 -c mgmtEqualVnodeNum -v 0
sleep 3000
system sh/exec.sh -n dnode2 -s start
sleep 9000 sleep 9000
$x = 0 $x = 0
...@@ -334,30 +262,33 @@ show9: ...@@ -334,30 +262,33 @@ show9:
return -1 return -1
endi endi
sql show dnodes -x show9 sql show dnodes -x show9
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode4Vnodes = $data2_4
print dnode2 $dnode2Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
goto show9 goto show9
endi endi
if $dnode2Vnodes != 3 then if $dnode4Vnodes != 1 then
goto show9 goto show9
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode4Role = $data2_4
$dnode3Role = $data3_192.168.0.3
$dnode4Role = $data3_192.168.0.4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role print dnode4 ==> $dnode4Role
if $dnode1Role != master then
return -1
endi
if $dnode4Role != slave then
return -1
endi
print ============================== step10 print ============================== step10
print ========= add db4
sql create database c_b1_d4 tables 4 sql create database c_b1_d4 tables 4
sql use c_b1_d4 sql use c_b1_d4
sql create table c_b1_t4 (t timestamp, i int) sql create table c_b1_t4 (t timestamp, i int)
...@@ -375,102 +306,43 @@ show10: ...@@ -375,102 +306,43 @@ show10:
return -1 return -1
endi endi
sql show dnodes -x show10 sql show dnodes -x show10
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode4Vnodes = $data2_4
print dnode2 $dnode2Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
goto show10 goto show10
endi endi
if $dnode2Vnodes != 2 then if $dnode4Vnodes != 2 then
goto show10 goto show10
endi endi
sql reset query cache
sql use c_b1_d3 sql use c_b1_d3
sql insert into c_b1_t3 values(1520000025036, 36) sql insert into c_b1_t3 values(1520000025036, 36)
sql use c_b1_d2 sql use c_b1_d2
sql insert into c_b1_t2 values(1520000025026, 26) sql insert into c_b1_t2 values(1520000025026, 26)
sql show mnodes
$dnode1Role = $data3_192.168.0.1
$dnode2Role = $data3_192.168.0.2
print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
if $dnode1Role != master then
return -1
endi
print ============================== step11
print ========= drop dnode2
sleep 2000
sql drop dnode $hostname2
sleep 9000
$x = 0
show11:
$x = $x + 1
sleep 2000
if $x == 20 then
return -1
endi
sql show dnodes -x show11
$dnode1Vnodes = $data3_192.168.0.1
print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2
print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 0 then
goto show11
endi
if $dnode2Vnodes != null then
goto show11
endi
sql show mnodes
$dnode1Role = $data3_192.168.0.1
$dnode2Role = $data3_192.168.0.2
$dnode3Role = $data3_192.168.0.3
$dnode4Role = $data3_192.168.0.4
print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role
system sh/exec.sh -n dnode2 -s stop -x SIGINT
print ============================== step12 print ============================== step12
print ========= add db5
sql create database c_b1_d5 tables 4 sql create database c_b1_d5 tables 4
sql use c_b1_d5 sql use c_b1_d5
sql create table c_b1_t5 (t timestamp, i int) -x error3 sql_error create table c_b1_t5 (t timestamp, i int) -x error3
print no enough vnodes, but create success
return -1
error3:
print ============================== step13 print ============================== step13
print ========= add dnode2 sql create dnode $hostname5
sql create dnode $hostname2 system sh/exec_up.sh -n dnode5 -s start
system sh/deploy.sh -n dnode2 -i 2
system sh/cfg.sh -n dnode2 -c numOfMPeers -v 3
system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode2 -c clog -v 1
system sh/cfg.sh -n dnode2 -c mgmtEqualVnodeNum -v 0
sleep 3000
system sh/exec.sh -n dnode2 -s start
sleep 9000 sleep 9000
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode4Role = $data2_4
$dnode3Role = $data3_192.168.0.3 $dnode5Role = $data2_5
$dnode4Role = $data3_192.168.0.4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role print dnode4 ==> $dnode4Role
print dnode5 ==> $dnode5Role
sql use c_b1_d5; sql use c_b1_d5;
sql create table c_b1_t5 (t timestamp, i int) sql create table c_b1_t5 (t timestamp, i int)
...@@ -490,71 +362,27 @@ sql insert into c_b1_t6 values(1520000023062, 62) ...@@ -490,71 +362,27 @@ sql insert into c_b1_t6 values(1520000023062, 62)
sql insert into c_b1_t6 values(1520000024061, 61) sql insert into c_b1_t6 values(1520000024061, 61)
sql show dnodes sql show dnodes
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode4Vnodes = $data2_4
print dnode2 $dnode2Vnodes print dnode4 $dnode2Vnodes
$dnode5Vnodes = $data2_5
#if $dnode1Vnodes != 1 then print dnode5 $dnode2Vnodes
# return -1
#endi
#if $dnode2Vnodes != 1 then
# return -1
#endi
print ============================== step14
print ========= add dnode3
sql show mnodes
$dnode1Role = $data3_192.168.0.1
$dnode2Role = $data3_192.168.0.2
$dnode3Role = $data3_192.168.0.3
$dnode4Role = $data3_192.168.0.4
print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role
sleep 2000
sql create dnode $hostname3
system sh/exec.sh -n dnode3 -s start
sleep 15000
$x = 0
show14:
$x = $x + 1
sleep 2000
if $x == 30 then
return -1
endi
sql show dnodes -x show14
$dnode1Vnodes = $data3_192.168.0.1
print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2
print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3
print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
goto show14 return -1
endi endi
if $dnode2Vnodes != 2 then if $dnode4Vnodes != 2 then
goto show14 return -1
endi endi
if $dnode3Vnodes != 2 then if $dnode5Vnodes != 2 then
goto show14 return -1
endi endi
sql show mnodes print ============================== step14
$dnode1Role = $data3_192.168.0.1 sql create dnode $hostname6
$dnode2Role = $data3_192.168.0.2 system sh/exec_up.sh -n dnode6 -s start
$dnode3Role = $data3_192.168.0.3 sleep 15000
print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role
print ============================== step15
print ========= create db7 db8
sql create database c_b1_d7 tables 4 sql create database c_b1_d7 tables 4
sql use c_b1_d7 sql use c_b1_d7
...@@ -574,96 +402,39 @@ sql insert into c_b1_t8 values(1520000022083, 83) ...@@ -574,96 +402,39 @@ sql insert into c_b1_t8 values(1520000022083, 83)
sql insert into c_b1_t8 values(1520000023082, 82) sql insert into c_b1_t8 values(1520000023082, 82)
sql insert into c_b1_t8 values(1520000024081, 81) sql insert into c_b1_t8 values(1520000024081, 81)
sql show mnodes
$dnode1Role = $data3_192.168.0.1
$dnode2Role = $data3_192.168.0.2
$dnode3Role = $data3_192.168.0.3
$dnode4Role = $data3_192.168.0.4
print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role
print ========== add dnode4
sleep 2000
sql create dnode $hostname4
print sql create dnode $hostname4 over
system sh/exec.sh -n dnode4 -s start
print sleep 12000
sleep 12000
print sleep 12000 over
$x = 0 $x = 0
show15: show14:
$x = $x + 1 $x = $x + 1
sleep 2000 sleep 2000
if $x == 15 then if $x == 30 then
return -1 return -1
endi endi
sql show dnodes -x show15 sql show dnodes -x show14
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode4Vnodes = $data2_4
print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3
print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
$dnode5Vnodes = $data2_5
print dnode5 $dnode5Vnodes
$dnode6Vnodes = $data2_6
print dnode6 $dnode6Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
goto show15 goto show14
endi
if $dnode2Vnodes != 2 then
goto show15
endi
if $dnode3Vnodes != 2 then
goto show15
endi endi
if $dnode4Vnodes != 2 then if $dnode4Vnodes != 2 then
goto show15 goto show14
endi
print ============================== step16
print ========= drop dnode4, create db9
sql drop dnode $hostname4
sleep 10000
sql create database c_b1_d9 tables 4
sql use c_b1_d9
sql create table c_b1_t9 (t timestamp, i int)
sql insert into c_b1_t9 values(1520000020095, 95)
sql insert into c_b1_t9 values(1520000021094, 94)
sql insert into c_b1_t9 values(1520000022093, 93)
sql insert into c_b1_t9 values(1520000023092, 92)
sql insert into c_b1_t9 values(1520000024091, 91)
system sh/exec.sh -n dnode4 -s stop -x SIGINT
$x = 0
show16:
$x = $x + 1
sleep 2000
if $x == 30 then
return -1
endi
sql show dnodes -x show16
$dnode1Vnodes = $data3_192.168.0.1
print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2
print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3
print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 1 then
goto show16
endi endi
if $dnode2Vnodes != 1 then if $dnode5Vnodes != 2 then
goto show16 goto show14
endi endi
if $dnode3Vnodes != 1 then if $dnode6Vnodes != 2 then
goto show16 goto show14
endi endi
sql reset query cache
sleep 1000
print ============================== step17 print ============================== step17
print ========= check data print ========= check data
...@@ -788,12 +559,11 @@ if $data41 != 95 then ...@@ -788,12 +559,11 @@ if $data41 != 95 then
return -1 return -1
endi endi
print ============================================ over print ============================================ over
#system sh/exec.sh -n dnode2 -s stop -x SIGINT #system sh/exec_up.sh -n dnode2 -s stop -x SIGINT
#system sh/exec.sh -n dnode3 -s stop -x SIGINT #system sh/exec_up.sh -n dnode3 -s stop -x SIGINT
#system sh/exec.sh -n dnode4 -s stop -x SIGINT #system sh/exec_up.sh -n dnode4 -s stop -x SIGINT
#system sh/exec.sh -n dnode5 -s stop -x SIGINT #system sh/exec_up.sh -n dnode5 -s stop -x SIGINT
...@@ -26,7 +26,7 @@ system sh/cfg.sh -n dnode4 -c mgmtEqualVnodeNum -v 0 ...@@ -26,7 +26,7 @@ system sh/cfg.sh -n dnode4 -c mgmtEqualVnodeNum -v 0
print ============== step1 print ============== step1
print ========= start dnode1 print ========= start dnode1
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sql connect sql connect
sql create database c_b1_d1 tables 4 sql create database c_b1_d1 tables 4
...@@ -49,9 +49,9 @@ sql insert into c_b1_t2 values(now+4s, 22) ...@@ -49,9 +49,9 @@ sql insert into c_b1_t2 values(now+4s, 22)
sql insert into c_b1_t2 values(now+5s, 21) sql insert into c_b1_t2 values(now+5s, 21)
sql show dnodes sql show dnodes
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
...@@ -65,7 +65,7 @@ print ============================== step2 ...@@ -65,7 +65,7 @@ print ============================== step2
print ========= start dnode2 print ========= start dnode2
sleep 2000 sleep 2000
sql create dnode $hostname2 sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 5000 sleep 5000
$x = 0 $x = 0
...@@ -76,9 +76,9 @@ show2: ...@@ -76,9 +76,9 @@ show2:
return -1 return -1
endi endi
sql show dnodes -x show2 sql show dnodes -x show2
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 3 then if $dnode1Vnodes != 3 then
...@@ -89,10 +89,10 @@ if $dnode2Vnodes != 3 then ...@@ -89,10 +89,10 @@ if $dnode2Vnodes != 3 then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -122,9 +122,9 @@ show4: ...@@ -122,9 +122,9 @@ show4:
return -1 return -1
endi endi
sql show dnodes -x show4 sql show dnodes -x show4
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 1 then if $dnode1Vnodes != 1 then
...@@ -135,10 +135,10 @@ if $dnode2Vnodes != null then ...@@ -135,10 +135,10 @@ if $dnode2Vnodes != null then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -146,9 +146,9 @@ print dnode4 ==> $dnode4Role ...@@ -146,9 +146,9 @@ print dnode4 ==> $dnode4Role
print ============================== step5 print ============================== step5
print ========= add dnode2 print ========= add dnode2
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec_up.sh -n dnode2 -s stop -x SIGINT
sleep 5000 sleep 5000
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sql create dnode $hostname2 sql create dnode $hostname2
sleep 9000 sleep 9000
...@@ -160,9 +160,9 @@ show5: ...@@ -160,9 +160,9 @@ show5:
return -1 return -1
endi endi
sql show dnodes -x show5 sql show dnodes -x show5
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
...@@ -173,10 +173,10 @@ if $dnode2Vnodes != 3 then ...@@ -173,10 +173,10 @@ if $dnode2Vnodes != 3 then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -184,7 +184,7 @@ print dnode4 ==> $dnode4Role ...@@ -184,7 +184,7 @@ print dnode4 ==> $dnode4Role
print ============================== step6 print ============================== step6
print ========= drop dnode1 print ========= drop dnode1
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec_up.sh -n dnode1 -s stop -x SIGINT
print stop dnode1 and sleep 10000 print stop dnode1 and sleep 10000
sleep 10000 sleep 10000
...@@ -200,9 +200,9 @@ show6: ...@@ -200,9 +200,9 @@ show6:
return -1 return -1
endi endi
sql show dnodes -x show6 sql show dnodes -x show6
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
if $dnode1Vnodes != null then if $dnode1Vnodes != null then
...@@ -213,10 +213,10 @@ if $dnode2Vnodes != 1 then ...@@ -213,10 +213,10 @@ if $dnode2Vnodes != 1 then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -226,7 +226,7 @@ print ============================== step7 ...@@ -226,7 +226,7 @@ print ============================== step7
print ========= add dnode1 print ========= add dnode1
sql create dnode $hostname1 sql create dnode $hostname1
sleep 23000 sleep 23000
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sleep 14000 sleep 14000
$x = 0 $x = 0
...@@ -237,9 +237,9 @@ show7: ...@@ -237,9 +237,9 @@ show7:
return -1 return -1
endi endi
sql show dnodes -x show7 sql show dnodes -x show7
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 3 then if $dnode1Vnodes != 3 then
...@@ -250,10 +250,10 @@ if $dnode2Vnodes != 2 then ...@@ -250,10 +250,10 @@ if $dnode2Vnodes != 2 then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -261,7 +261,7 @@ print dnode4 ==> $dnode4Role ...@@ -261,7 +261,7 @@ print dnode4 ==> $dnode4Role
print ============================== step8 print ============================== step8
print ========= drop dnode2 print ========= drop dnode2
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec_up.sh -n dnode2 -s stop -x SIGINT
print stop dnode2 and sleep 10000 print stop dnode2 and sleep 10000
sleep 20000 sleep 20000
sql drop dnode $hostname2 sql drop dnode $hostname2
...@@ -276,9 +276,9 @@ show8: ...@@ -276,9 +276,9 @@ show8:
return -1 return -1
endi endi
sql show dnodes -x show8 sql show dnodes -x show8
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 1 then if $dnode1Vnodes != 1 then
...@@ -289,10 +289,10 @@ if $dnode2Vnodes != null then ...@@ -289,10 +289,10 @@ if $dnode2Vnodes != null then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -305,7 +305,7 @@ endi ...@@ -305,7 +305,7 @@ endi
print ============================== step9 print ============================== step9
print ========= add dnode2 print ========= add dnode2
sql create dnode $hostname2 sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 9000 sleep 9000
$x = 0 $x = 0
...@@ -316,9 +316,9 @@ show9: ...@@ -316,9 +316,9 @@ show9:
return -1 return -1
endi endi
sql show dnodes -x show9 sql show dnodes -x show9
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
...@@ -329,10 +329,10 @@ if $dnode2Vnodes != 3 then ...@@ -329,10 +329,10 @@ if $dnode2Vnodes != 3 then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -357,9 +357,9 @@ show10: ...@@ -357,9 +357,9 @@ show10:
return -1 return -1
endi endi
sql show dnodes -x show10 sql show dnodes -x show10
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
...@@ -376,8 +376,8 @@ sql use c_b1_d2 ...@@ -376,8 +376,8 @@ sql use c_b1_d2
sql insert into c_b1_t2 values(now+1s, 25) sql insert into c_b1_t2 values(now+1s, 25)
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
...@@ -399,9 +399,9 @@ show11: ...@@ -399,9 +399,9 @@ show11:
return -1 return -1
endi endi
sql show dnodes -x show11 sql show dnodes -x show11
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 0 then if $dnode1Vnodes != 0 then
...@@ -412,16 +412,16 @@ if $dnode2Vnodes != null then ...@@ -412,16 +412,16 @@ if $dnode2Vnodes != null then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role print dnode4 ==> $dnode4Role
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec_up.sh -n dnode2 -s stop -x SIGINT
print ============================== step12 print ============================== step12
print ========= add db5 print ========= add db5
...@@ -435,14 +435,14 @@ error3: ...@@ -435,14 +435,14 @@ error3:
print ============================== step13 print ============================== step13
print ========= add dnode2 print ========= add dnode2
sql create dnode $hostname2 sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 9000 sleep 9000
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -480,9 +480,9 @@ sql insert into c_b1_t6 values(now+4s, 62) ...@@ -480,9 +480,9 @@ sql insert into c_b1_t6 values(now+4s, 62)
sql insert into c_b1_t6 values(now+5s, 61) sql insert into c_b1_t6 values(now+5s, 61)
sql show dnodes sql show dnodes
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
#if $dnode1Vnodes != 1 then #if $dnode1Vnodes != 1 then
...@@ -496,10 +496,10 @@ print ============================== step14 ...@@ -496,10 +496,10 @@ print ============================== step14
print ========= add dnode3 print ========= add dnode3
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -507,7 +507,7 @@ print dnode4 ==> $dnode4Role ...@@ -507,7 +507,7 @@ print dnode4 ==> $dnode4Role
sleep 2000 sleep 2000
sql create dnode $hostname3 sql create dnode $hostname3
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 15000 sleep 15000
$x = 0 $x = 0
...@@ -518,11 +518,11 @@ show14: ...@@ -518,11 +518,11 @@ show14:
return -1 return -1
endi endi
sql show dnodes -x show14 sql show dnodes -x show14
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
...@@ -536,9 +536,9 @@ if $dnode3Vnodes != 2 then ...@@ -536,9 +536,9 @@ if $dnode3Vnodes != 2 then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -565,10 +565,10 @@ sql insert into c_b1_t8 values(now+4s, 82) ...@@ -565,10 +565,10 @@ sql insert into c_b1_t8 values(now+4s, 82)
sql insert into c_b1_t8 values(now+5s, 81) sql insert into c_b1_t8 values(now+5s, 81)
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -578,7 +578,7 @@ print ========== add dnode4 ...@@ -578,7 +578,7 @@ print ========== add dnode4
sleep 2000 sleep 2000
sql create dnode $hostname4 sql create dnode $hostname4
print sql create dnode $hostname4 over print sql create dnode $hostname4 over
system sh/exec.sh -n dnode4 -s start system sh/exec_up.sh -n dnode4 -s start
print sleep 12000 print sleep 12000
sleep 12000 sleep 12000
print sleep 12000 over print sleep 12000 over
...@@ -591,13 +591,13 @@ show15: ...@@ -591,13 +591,13 @@ show15:
return -1 return -1
endi endi
sql show dnodes -x show15 sql show dnodes -x show15
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
...@@ -627,7 +627,7 @@ sql insert into c_b1_t9 values(now+3s, 93) ...@@ -627,7 +627,7 @@ sql insert into c_b1_t9 values(now+3s, 93)
sql insert into c_b1_t9 values(now+4s, 92) sql insert into c_b1_t9 values(now+4s, 92)
sql insert into c_b1_t9 values(now+5s, 91) sql insert into c_b1_t9 values(now+5s, 91)
system sh/exec.sh -n dnode4 -s stop -x SIGINT system sh/exec_up.sh -n dnode4 -s stop -x SIGINT
$x = 0 $x = 0
show16: show16:
...@@ -637,11 +637,11 @@ show16: ...@@ -637,11 +637,11 @@ show16:
return -1 return -1
endi endi
sql show dnodes -x show16 sql show dnodes -x show16
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 1 then if $dnode1Vnodes != 1 then
...@@ -780,10 +780,10 @@ endi ...@@ -780,10 +780,10 @@ endi
s8: s8:
print ============================================ over print ============================================ over
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec_up.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec_up.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT system sh/exec_up.sh -n dnode3 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT system sh/exec_up.sh -n dnode4 -s stop -x SIGINT
...@@ -31,11 +31,11 @@ system sh/cfg.sh -n dnode5 -c mgmtEqualVnodeNum -v 4 ...@@ -31,11 +31,11 @@ system sh/cfg.sh -n dnode5 -c mgmtEqualVnodeNum -v 4
print ============== step1 print ============== step1
print ========= start dnode1 print ========= start dnode1
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sleep 3000 sleep 3000
sql connect sql connect
sql create dnode $hostname2 sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
$x = 0 $x = 0
show1: show1:
...@@ -45,9 +45,9 @@ show1: ...@@ -45,9 +45,9 @@ show1:
return -1 return -1
endi endi
sql show dnodes -x show1 sql show dnodes -x show1
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode2Vnodes print dnode1 $dnode2Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode3Vnodes print dnode2 $dnode3Vnodes
if $dnode1Vnodes != 4 then if $dnode1Vnodes != 4 then
...@@ -78,9 +78,9 @@ sql insert into c_b1_t2 values(now+4s, 22) ...@@ -78,9 +78,9 @@ sql insert into c_b1_t2 values(now+4s, 22)
sql insert into c_b1_t2 values(now+5s, 21) sql insert into c_b1_t2 values(now+5s, 21)
sql show dnodes sql show dnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode2Vnodes != 2 then if $dnode2Vnodes != 2 then
...@@ -94,7 +94,7 @@ print ============================== step2 ...@@ -94,7 +94,7 @@ print ============================== step2
print ========= start dnode3 print ========= start dnode3
sleep 3000 sleep 3000
sql create dnode $hostname3 sql create dnode $hostname3
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 8000 sleep 8000
$x = 0 $x = 0
...@@ -105,9 +105,9 @@ show2: ...@@ -105,9 +105,9 @@ show2:
return -1 return -1
endi endi
sql show dnodes -x show2 sql show dnodes -x show2
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode2Vnodes != 3 then if $dnode2Vnodes != 3 then
...@@ -118,10 +118,10 @@ if $dnode3Vnodes != 3 then ...@@ -118,10 +118,10 @@ if $dnode3Vnodes != 3 then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -152,9 +152,9 @@ show4: ...@@ -152,9 +152,9 @@ show4:
return -1 return -1
endi endi
sql show dnodes -x show4 sql show dnodes -x show4
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode2Vnodes != 1 then if $dnode2Vnodes != 1 then
...@@ -165,10 +165,10 @@ if $dnode3Vnodes != null then ...@@ -165,10 +165,10 @@ if $dnode3Vnodes != null then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -176,9 +176,9 @@ print dnode4 ==> $dnode4Role ...@@ -176,9 +176,9 @@ print dnode4 ==> $dnode4Role
print ============================== step5 print ============================== step5
print ========= add dnode3 print ========= add dnode3
system sh/exec.sh -n dnode3 -s stop -x SIGINT system sh/exec_up.sh -n dnode3 -s stop -x SIGINT
sleep 5000 sleep 5000
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sql create dnode $hostname3 sql create dnode $hostname3
sleep 9000 sleep 9000
...@@ -190,9 +190,9 @@ show5: ...@@ -190,9 +190,9 @@ show5:
return -1 return -1
endi endi
sql show dnodes -x show5 sql show dnodes -x show5
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode2Vnodes != 2 then if $dnode2Vnodes != 2 then
...@@ -204,7 +204,7 @@ endi ...@@ -204,7 +204,7 @@ endi
print ============================== step6 print ============================== step6
print ========= drop dnode2 print ========= drop dnode2
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec_up.sh -n dnode2 -s stop -x SIGINT
print stop dnode2 and sleep 10000 print stop dnode2 and sleep 10000
sleep 10000 sleep 10000
...@@ -220,9 +220,9 @@ show6: ...@@ -220,9 +220,9 @@ show6:
return -1 return -1
endi endi
sql show dnodes -x show6 sql show dnodes -x show6
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode2Vnodes != null then if $dnode2Vnodes != null then
...@@ -237,7 +237,7 @@ endi ...@@ -237,7 +237,7 @@ endi
print ============================== step7 print ============================== step7
print ========= add dnode2 print ========= add dnode2
sql create dnode $hostname2 sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 9000 sleep 9000
$x = 0 $x = 0
...@@ -248,9 +248,9 @@ show7: ...@@ -248,9 +248,9 @@ show7:
return -1 return -1
endi endi
sql show dnodes -x show7 sql show dnodes -x show7
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode2Vnodes != 3 then if $dnode2Vnodes != 3 then
...@@ -262,7 +262,7 @@ endi ...@@ -262,7 +262,7 @@ endi
print ============================== step8 print ============================== step8
print ========= drop dnode3 print ========= drop dnode3
system sh/exec.sh -n dnode3 -s stop -x SIGINT system sh/exec_up.sh -n dnode3 -s stop -x SIGINT
print stop dnode3 and sleep 10000 print stop dnode3 and sleep 10000
sleep 10000 sleep 10000
sql drop dnode $hostname3 sql drop dnode $hostname3
...@@ -277,9 +277,9 @@ show8: ...@@ -277,9 +277,9 @@ show8:
return -1 return -1
endi endi
sql show dnodes -x show8 sql show dnodes -x show8
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode2Vnodes != 1 then if $dnode2Vnodes != 1 then
...@@ -292,7 +292,7 @@ endi ...@@ -292,7 +292,7 @@ endi
print ============================== step9 print ============================== step9
print ========= add dnode3 print ========= add dnode3
sql create dnode $hostname3 sql create dnode $hostname3
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 9000 sleep 9000
$x = 0 $x = 0
...@@ -303,9 +303,9 @@ show9: ...@@ -303,9 +303,9 @@ show9:
return -1 return -1
endi endi
sql show dnodes -x show9 sql show dnodes -x show9
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode2Vnodes != 2 then if $dnode2Vnodes != 2 then
...@@ -334,9 +334,9 @@ show10: ...@@ -334,9 +334,9 @@ show10:
return -1 return -1
endi endi
sql show dnodes -x show10 sql show dnodes -x show10
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode2Vnodes != 2 then if $dnode2Vnodes != 2 then
...@@ -365,9 +365,9 @@ show11: ...@@ -365,9 +365,9 @@ show11:
return -1 return -1
endi endi
sql show dnodes -x show11 sql show dnodes -x show11
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode2Vnodes != 0 then if $dnode2Vnodes != 0 then
...@@ -377,7 +377,7 @@ if $dnode3Vnodes != null then ...@@ -377,7 +377,7 @@ if $dnode3Vnodes != null then
goto show11 goto show11
endi endi
system sh/exec.sh -n dnode3 -s stop -x SIGINT system sh/exec_up.sh -n dnode3 -s stop -x SIGINT
print ============================== step12 print ============================== step12
print ========= add db5 print ========= add db5
...@@ -387,7 +387,7 @@ sql use c_b1_d5 ...@@ -387,7 +387,7 @@ sql use c_b1_d5
print ============================== step13 print ============================== step13
print ========= add dnode3 print ========= add dnode3
sql create dnode $hostname3 sql create dnode $hostname3
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 9000 sleep 9000
sql use c_b1_d5; sql use c_b1_d5;
...@@ -422,9 +422,9 @@ sql insert into c_b1_t6 values(now+4s, 62) ...@@ -422,9 +422,9 @@ sql insert into c_b1_t6 values(now+4s, 62)
sql insert into c_b1_t6 values(now+5s, 61) sql insert into c_b1_t6 values(now+5s, 61)
sql show dnodes sql show dnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
#if $dnode2Vnodes != 1 then #if $dnode2Vnodes != 1 then
...@@ -437,7 +437,7 @@ print dnode3 $dnode3Vnodes ...@@ -437,7 +437,7 @@ print dnode3 $dnode3Vnodes
print ============================== step14 print ============================== step14
print ========= add dnode4 print ========= add dnode4
sql create dnode $hostname4 sql create dnode $hostname4
system sh/exec.sh -n dnode4 -s start system sh/exec_up.sh -n dnode4 -s start
sleep 10000 sleep 10000
$x = 0 $x = 0
...@@ -448,11 +448,11 @@ show14: ...@@ -448,11 +448,11 @@ show14:
return -1 return -1
endi endi
sql show dnodes -x show14 sql show dnodes -x show14
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode2Vnodes != 2 then if $dnode2Vnodes != 2 then
...@@ -490,7 +490,7 @@ sql insert into c_b1_t8 values(now+5s, 81) ...@@ -490,7 +490,7 @@ sql insert into c_b1_t8 values(now+5s, 81)
print ========== add dnode5 print ========== add dnode5
sql create dnode $hostname5 sql create dnode $hostname5
print sql create dnode $hostname5 over print sql create dnode $hostname5 over
system sh/exec.sh -n dnode5 -s start system sh/exec_up.sh -n dnode5 -s start
print sleep 12000 print sleep 12000
sleep 12000 sleep 12000
print sleep 12000 over print sleep 12000 over
...@@ -503,13 +503,13 @@ show15: ...@@ -503,13 +503,13 @@ show15:
return -1 return -1
endi endi
sql show dnodes -x show15 sql show dnodes -x show15
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
$dnode5Vnodes = $data3_192.168.0.5 $dnode5Vnodes = $data2_5
print dnode5 $dnode5Vnodes print dnode5 $dnode5Vnodes
if $dnode2Vnodes != 2 then if $dnode2Vnodes != 2 then
...@@ -539,7 +539,7 @@ sql insert into c_b1_t9 values(now+3s, 93) ...@@ -539,7 +539,7 @@ sql insert into c_b1_t9 values(now+3s, 93)
sql insert into c_b1_t9 values(now+4s, 92) sql insert into c_b1_t9 values(now+4s, 92)
sql insert into c_b1_t9 values(now+5s, 91) sql insert into c_b1_t9 values(now+5s, 91)
system sh/exec.sh -n dnode5 -s stop -x SIGINT system sh/exec_up.sh -n dnode5 -s stop -x SIGINT
$x = 0 $x = 0
show16: show16:
...@@ -549,11 +549,11 @@ show16: ...@@ -549,11 +549,11 @@ show16:
return -1 return -1
endi endi
sql show dnodes -x show16 sql show dnodes -x show16
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode2Vnodes != 1 then if $dnode2Vnodes != 1 then
...@@ -707,10 +707,10 @@ endi ...@@ -707,10 +707,10 @@ endi
print ============================================ over print ============================================ over
#system sh/exec.sh -n dnode2 -s stop -x SIGINT #system sh/exec_up.sh -n dnode2 -s stop -x SIGINT
#system sh/exec.sh -n dnode3 -s stop -x SIGINT #system sh/exec_up.sh -n dnode3 -s stop -x SIGINT
#system sh/exec.sh -n dnode4 -s stop -x SIGINT #system sh/exec_up.sh -n dnode4 -s stop -x SIGINT
#system sh/exec.sh -n dnode5 -s stop -x SIGINT #system sh/exec_up.sh -n dnode5 -s stop -x SIGINT
...@@ -46,14 +46,14 @@ system sh/cfg.sh -n dnode8 -c mgmtEqualVnodeNum -v 0 ...@@ -46,14 +46,14 @@ system sh/cfg.sh -n dnode8 -c mgmtEqualVnodeNum -v 0
print ============== step1 print ============== step1
print ========= start dnode1 print ========= start dnode1
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sql connect sql connect
sleep 4001 sleep 4001
sql create dnode $hostname2 sql create dnode $hostname2
sql create dnode $hostname3 sql create dnode $hostname3
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 4001 sleep 4001
sql create database c_b2_d1 replica 2 tables 4 sql create database c_b2_d1 replica 2 tables 4
...@@ -91,11 +91,11 @@ show1: ...@@ -91,11 +91,11 @@ show1:
return -1 return -1
endi endi
sql show dnodes -x show1 sql show dnodes -x show1
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
...@@ -121,11 +121,11 @@ show2: ...@@ -121,11 +121,11 @@ show2:
return -1 return -1
endi endi
sql show dnodes -x show2 sql show dnodes -x show2
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 1 then if $dnode1Vnodes != 1 then
...@@ -139,16 +139,16 @@ if $dnode3Vnodes != 1 then ...@@ -139,16 +139,16 @@ if $dnode3Vnodes != 1 then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role print dnode4 ==> $dnode4Role
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec_up.sh -n dnode2 -s stop -x SIGINT
print ============================== step3 print ============================== step3
print ========= start dnode2 print ========= start dnode2
...@@ -162,7 +162,7 @@ system sh/cfg.sh -n dnode2 -c clog -v 1 ...@@ -162,7 +162,7 @@ system sh/cfg.sh -n dnode2 -c clog -v 1
system sh/cfg.sh -n dnode2 -c mgmtEqualVnodeNum -v 0 system sh/cfg.sh -n dnode2 -c mgmtEqualVnodeNum -v 0
sleep 3000 sleep 3000
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 10000 sleep 10000
$x = 0 $x = 0
...@@ -173,11 +173,11 @@ show3: ...@@ -173,11 +173,11 @@ show3:
return -1 return -1
endi endi
sql show dnodes -x show3 sql show dnodes -x show3
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
...@@ -191,10 +191,10 @@ if $dnode3Vnodes != 2 then ...@@ -191,10 +191,10 @@ if $dnode3Vnodes != 2 then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -213,11 +213,11 @@ show4: ...@@ -213,11 +213,11 @@ show4:
return -1 return -1
endi endi
sql show dnodes -x show4 sql show dnodes -x show4
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 1 then if $dnode1Vnodes != 1 then
...@@ -231,16 +231,16 @@ if $dnode3Vnodes != null then ...@@ -231,16 +231,16 @@ if $dnode3Vnodes != null then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role print dnode4 ==> $dnode4Role
system sh/exec.sh -n dnode3 -s stop -x SIGINT system sh/exec_up.sh -n dnode3 -s stop -x SIGINT
print ============================== step5 print ============================== step5
print ========= start dnode3 print ========= start dnode3
...@@ -254,7 +254,7 @@ system sh/cfg.sh -n dnode3 -c clog -v 1 ...@@ -254,7 +254,7 @@ system sh/cfg.sh -n dnode3 -c clog -v 1
system sh/cfg.sh -n dnode3 -c mgmtEqualVnodeNum -v 0 system sh/cfg.sh -n dnode3 -c mgmtEqualVnodeNum -v 0
sleep 3000 sleep 3000
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 9000 sleep 9000
$x = 0 $x = 0
...@@ -265,11 +265,11 @@ show5: ...@@ -265,11 +265,11 @@ show5:
return -1 return -1
endi endi
sql show dnodes -x show5 sql show dnodes -x show5
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
...@@ -283,10 +283,10 @@ if $dnode3Vnodes != 2 then ...@@ -283,10 +283,10 @@ if $dnode3Vnodes != 2 then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -294,7 +294,7 @@ print dnode4 ==> $dnode4Role ...@@ -294,7 +294,7 @@ print dnode4 ==> $dnode4Role
print ============================== step6 print ============================== step6
print ========= drop dnode1 print ========= drop dnode1
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec_up.sh -n dnode1 -s stop -x SIGINT
print stop dnode1 and sleep 10000 print stop dnode1 and sleep 10000
sleep 10000 sleep 10000
...@@ -310,11 +310,11 @@ show6: ...@@ -310,11 +310,11 @@ show6:
return -1 return -1
endi endi
sql show dnodes -x show6 sql show dnodes -x show6
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode1Vnodes != null then if $dnode1Vnodes != null then
...@@ -328,10 +328,10 @@ if $dnode3Vnodes != 1 then ...@@ -328,10 +328,10 @@ if $dnode3Vnodes != 1 then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -342,10 +342,10 @@ print ========= start dnode1 ...@@ -342,10 +342,10 @@ print ========= start dnode1
sql create dnode $hostname1 sql create dnode $hostname1
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -359,17 +359,17 @@ system sh/cfg.sh -n dnode1 -c clog -v 1 ...@@ -359,17 +359,17 @@ system sh/cfg.sh -n dnode1 -c clog -v 1
system sh/cfg.sh -n dnode1 -c mgmtEqualVnodeNum -v 0 system sh/cfg.sh -n dnode1 -c mgmtEqualVnodeNum -v 0
sleep 3000 sleep 3000
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sleep 9000 sleep 9000
$x = 0 $x = 0
show7: show7:
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -381,11 +381,11 @@ show7: ...@@ -381,11 +381,11 @@ show7:
return -1 return -1
endi endi
sql show dnodes -x show7 sql show dnodes -x show7
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
...@@ -411,14 +411,14 @@ sql insert into c_b2_t4 values(1520000023042, 42) ...@@ -411,14 +411,14 @@ sql insert into c_b2_t4 values(1520000023042, 42)
sql insert into c_b2_t4 values(1520000024041, 41) sql insert into c_b2_t4 values(1520000024041, 41)
sql create dnode $hostname4 sql create dnode $hostname4
system sh/exec.sh -n dnode4 -s start system sh/exec_up.sh -n dnode4 -s start
sleep 9000 sleep 9000
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -432,13 +432,13 @@ show8: ...@@ -432,13 +432,13 @@ show8:
return -1 return -1
endi endi
sql show dnodes -x show8 sql show dnodes -x show8
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
...@@ -461,10 +461,10 @@ sql drop dnode $hostname4 ...@@ -461,10 +461,10 @@ sql drop dnode $hostname4
sleep 10000 sleep 10000
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -478,13 +478,13 @@ show9: ...@@ -478,13 +478,13 @@ show9:
return -1 return -1
endi endi
sql show dnodes -x show9 sql show dnodes -x show9
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != null then if $dnode1Vnodes != null then
...@@ -500,8 +500,8 @@ if $dnode4Vnodes != null then ...@@ -500,8 +500,8 @@ if $dnode4Vnodes != null then
goto show9 goto show9
endi endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec_up.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT system sh/exec_up.sh -n dnode4 -s stop -x SIGINT
print ============================== step10 print ============================== step10
print ========= start dnode1.4 print ========= start dnode1.4
...@@ -524,17 +524,17 @@ system sh/cfg.sh -n dnode4 -c clog -v 1 ...@@ -524,17 +524,17 @@ system sh/cfg.sh -n dnode4 -c clog -v 1
system sh/cfg.sh -n dnode4 -c mgmtEqualVnodeNum -v 0 system sh/cfg.sh -n dnode4 -c mgmtEqualVnodeNum -v 0
sleep 3000 sleep 3000
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
system sh/exec.sh -n dnode4 -s start system sh/exec_up.sh -n dnode4 -s start
sleep 10000 sleep 10000
$x = 0 $x = 0
show10: show10:
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -546,13 +546,13 @@ show10: ...@@ -546,13 +546,13 @@ show10:
return -1 return -1
endi endi
sql show dnodes -x show10 sql show dnodes -x show10
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
...@@ -571,10 +571,10 @@ endi ...@@ -571,10 +571,10 @@ endi
print ============================== step11 print ============================== step11
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -606,13 +606,13 @@ show11: ...@@ -606,13 +606,13 @@ show11:
return -1 return -1
endi endi
sql show dnodes -x show11 sql show dnodes -x show11
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != 1 then if $dnode1Vnodes != 1 then
...@@ -629,10 +629,10 @@ if $dnode4Vnodes != 1 then ...@@ -629,10 +629,10 @@ if $dnode4Vnodes != 1 then
endi endi
sql show mnodes sql show mnodes
$dnode1Role = $data3_192.168.0.1 $dnode1Role = $data2_1
$dnode2Role = $data3_192.168.0.2 $dnode2Role = $data2_2
$dnode3Role = $data3_192.168.0.3 $dnode3Role = $data2_3
$dnode4Role = $data3_192.168.0.4 $dnode4Role = $data2_4
print dnode1 ==> $dnode1Role print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role print dnode3 ==> $dnode3Role
...@@ -758,13 +758,13 @@ endi ...@@ -758,13 +758,13 @@ endi
print ============================================ over print ============================================ over
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec_up.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec_up.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT system sh/exec_up.sh -n dnode3 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT system sh/exec_up.sh -n dnode4 -s stop -x SIGINT
system sh/exec.sh -n dnode5 -s stop -x SIGINT system sh/exec_up.sh -n dnode5 -s stop -x SIGINT
system sh/exec.sh -n dnode6 -s stop -x SIGINT system sh/exec_up.sh -n dnode6 -s stop -x SIGINT
system sh/exec.sh -n dnode7 -s stop -x SIGINT system sh/exec_up.sh -n dnode7 -s stop -x SIGINT
system sh/exec.sh -n dnode8 -s stop -x SIGINT system sh/exec_up.sh -n dnode8 -s stop -x SIGINT
...@@ -56,14 +56,14 @@ system sh/cfg.sh -n dnode8 -c clog -v 1 ...@@ -56,14 +56,14 @@ system sh/cfg.sh -n dnode8 -c clog -v 1
print ============== step1 print ============== step1
print ========= start dnode1 print ========= start dnode1
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sql connect sql connect
sleep 2001 sleep 2001
sql create dnode $hostname2 sql create dnode $hostname2
sql create dnode $hostname3 sql create dnode $hostname3
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 3001 sleep 3001
sql create database c_b3_d1 replica 3 sql create database c_b3_d1 replica 3
...@@ -101,13 +101,13 @@ show1: ...@@ -101,13 +101,13 @@ show1:
return -1 return -1
endi endi
sql show dnodes -x show1 sql show dnodes -x show1
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != 1 then if $dnode1Vnodes != 1 then
...@@ -126,7 +126,7 @@ endi ...@@ -126,7 +126,7 @@ endi
print ============================== step2 print ============================== step2
print ========= start dnode4 print ========= start dnode4
sql create dnode $hostname4 sql create dnode $hostname4
system sh/exec.sh -n dnode4 -s start system sh/exec_up.sh -n dnode4 -s start
sleep 9000 sleep 9000
$x = 0 $x = 0
...@@ -137,13 +137,13 @@ show2: ...@@ -137,13 +137,13 @@ show2:
return -1 return -1
endi endi
sql show dnodes -x show2 sql show dnodes -x show2
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode4Vnodes != 2 then if $dnode4Vnodes != 2 then
...@@ -163,13 +163,13 @@ show3: ...@@ -163,13 +163,13 @@ show3:
return -1 return -1
endi endi
sql show dnodes -x show3 sql show dnodes -x show3
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != 1 then if $dnode1Vnodes != 1 then
...@@ -185,7 +185,7 @@ if $dnode4Vnodes != 1 then ...@@ -185,7 +185,7 @@ if $dnode4Vnodes != 1 then
goto show3 goto show3
endi endi
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec_up.sh -n dnode2 -s stop -x SIGINT
print ============================== step4 print ============================== step4
print ========= start dnode2 print ========= start dnode2
...@@ -197,7 +197,7 @@ system sh/cfg.sh -n dnode2 -c clog -v 1 ...@@ -197,7 +197,7 @@ system sh/cfg.sh -n dnode2 -c clog -v 1
system sh/cfg.sh -n dnode2 -c mgmtEqualVnodeNum -v 0 system sh/cfg.sh -n dnode2 -c mgmtEqualVnodeNum -v 0
sleep 3000 sleep 3000
sql create dnode $hostname2 sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 10000 sleep 10000
$x = 0 $x = 0
...@@ -208,13 +208,13 @@ show4: ...@@ -208,13 +208,13 @@ show4:
return -1 return -1
endi endi
sql show dnodes -x show4 sql show dnodes -x show4
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode2Vnodes != 2 then if $dnode2Vnodes != 2 then
...@@ -234,13 +234,13 @@ show5: ...@@ -234,13 +234,13 @@ show5:
return -1 return -1
endi endi
sql show dnodes -x show5 sql show dnodes -x show5
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != 1 then if $dnode1Vnodes != 1 then
...@@ -257,7 +257,7 @@ if $dnode4Vnodes != 1 then ...@@ -257,7 +257,7 @@ if $dnode4Vnodes != 1 then
endi endi
system sh/exec.sh -n dnode3 -s stop -x SIGINT system sh/exec_up.sh -n dnode3 -s stop -x SIGINT
print ============================== step6 print ============================== step6
print ========= start dnode3 print ========= start dnode3
...@@ -269,7 +269,7 @@ system sh/cfg.sh -n dnode3 -c clog -v 1 ...@@ -269,7 +269,7 @@ system sh/cfg.sh -n dnode3 -c clog -v 1
system sh/cfg.sh -n dnode3 -c mgmtEqualVnodeNum -v 0 system sh/cfg.sh -n dnode3 -c mgmtEqualVnodeNum -v 0
sleep 3000 sleep 3000
sql create dnode $hostname3 sql create dnode $hostname3
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 9000 sleep 9000
$x = 0 $x = 0
...@@ -280,13 +280,13 @@ show6: ...@@ -280,13 +280,13 @@ show6:
return -1 return -1
endi endi
sql show dnodes -x show6 sql show dnodes -x show6
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode3Vnodes != 2 then if $dnode3Vnodes != 2 then
...@@ -306,13 +306,13 @@ show7: ...@@ -306,13 +306,13 @@ show7:
return -1 return -1
endi endi
sql show dnodes -x show7 sql show dnodes -x show7
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != 1 then if $dnode1Vnodes != 1 then
...@@ -328,7 +328,7 @@ if $dnode4Vnodes != null then ...@@ -328,7 +328,7 @@ if $dnode4Vnodes != null then
goto show7 goto show7
endi endi
system sh/exec.sh -n dnode4 -s stop -x SIGINT system sh/exec_up.sh -n dnode4 -s stop -x SIGINT
print ============================== step8 print ============================== step8
print ========= start dnode4 print ========= start dnode4
...@@ -340,7 +340,7 @@ system sh/cfg.sh -n dnode4 -c clog -v 1 ...@@ -340,7 +340,7 @@ system sh/cfg.sh -n dnode4 -c clog -v 1
system sh/cfg.sh -n dnode4 -c mgmtEqualVnodeNum -v 0 system sh/cfg.sh -n dnode4 -c mgmtEqualVnodeNum -v 0
sleep 3000 sleep 3000
sql create dnode $hostname4 sql create dnode $hostname4
system sh/exec.sh -n dnode4 -s start system sh/exec_up.sh -n dnode4 -s start
sleep 9000 sleep 9000
$x = 0 $x = 0
...@@ -351,13 +351,13 @@ show8: ...@@ -351,13 +351,13 @@ show8:
return -1 return -1
endi endi
sql show dnodes -x show8 sql show dnodes -x show8
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode4Vnodes != 2 then if $dnode4Vnodes != 2 then
...@@ -366,7 +366,7 @@ endi ...@@ -366,7 +366,7 @@ endi
print ============================== step9 print ============================== step9
print ========= drop dnode1 print ========= drop dnode1
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec_up.sh -n dnode1 -s stop -x SIGINT
print stop dnode1 and sleep 10000 print stop dnode1 and sleep 10000
sleep 10000 sleep 10000
...@@ -382,13 +382,13 @@ show9: ...@@ -382,13 +382,13 @@ show9:
return -1 return -1
endi endi
sql show dnodes -x show9 sql show dnodes -x show9
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != null then if $dnode1Vnodes != null then
...@@ -414,7 +414,7 @@ system sh/cfg.sh -n dnode1 -c clog -v 1 ...@@ -414,7 +414,7 @@ system sh/cfg.sh -n dnode1 -c clog -v 1
system sh/cfg.sh -n dnode1 -c mgmtEqualVnodeNum -v 0 system sh/cfg.sh -n dnode1 -c mgmtEqualVnodeNum -v 0
sleep 3000 sleep 3000
sql create dnode $hostname1 sql create dnode $hostname1
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sleep 9000 sleep 9000
$x = 0 $x = 0
...@@ -425,13 +425,13 @@ show10: ...@@ -425,13 +425,13 @@ show10:
return -1 return -1
endi endi
sql show dnodes -x show10 sql show dnodes -x show10
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != 2 then if $dnode1Vnodes != 2 then
...@@ -466,13 +466,13 @@ show11: ...@@ -466,13 +466,13 @@ show11:
return -1 return -1
endi endi
sql show dnodes -x show11 sql show dnodes -x show11
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != 1 then if $dnode1Vnodes != 1 then
...@@ -501,13 +501,13 @@ show12: ...@@ -501,13 +501,13 @@ show12:
return -1 return -1
endi endi
sql show dnodes -x show12 sql show dnodes -x show12
$dnode1Vnodes = $data3_192.168.0.1 $dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data3_192.168.0.2 $dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data3_192.168.0.3 $dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes print dnode3 $dnode3Vnodes
$dnode4Vnodes = $data3_192.168.0.4 $dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes print dnode4 $dnode4Vnodes
if $dnode1Vnodes != null then if $dnode1Vnodes != null then
...@@ -523,7 +523,7 @@ if $dnode4Vnodes != 0 then ...@@ -523,7 +523,7 @@ if $dnode4Vnodes != 0 then
goto show12 goto show12
endi endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec_up.sh -n dnode1 -s stop -x SIGINT
print ============================== step13 print ============================== step13
print ========= check data print ========= check data
...@@ -607,13 +607,13 @@ endi ...@@ -607,13 +607,13 @@ endi
print ============================================ over print ============================================ over
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec_up.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec_up.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT system sh/exec_up.sh -n dnode3 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT system sh/exec_up.sh -n dnode4 -s stop -x SIGINT
system sh/exec.sh -n dnode5 -s stop -x SIGINT system sh/exec_up.sh -n dnode5 -s stop -x SIGINT
system sh/exec.sh -n dnode6 -s stop -x SIGINT system sh/exec_up.sh -n dnode6 -s stop -x SIGINT
system sh/exec.sh -n dnode7 -s stop -x SIGINT system sh/exec_up.sh -n dnode7 -s stop -x SIGINT
system sh/exec.sh -n dnode8 -s stop -x SIGINT system sh/exec_up.sh -n dnode8 -s stop -x SIGINT
#run unique/unique/balance1.sim run unique/cluster/balance1.sim
#run unique/unique/balance2.sim run unique/cluster/balance2.sim
#run unique/unique/balance3.sim run unique/cluster/balance3.sim
#run unique/unique/balance1_bug.sim run unique/cluster/balance1_bug.sim
#run unique/unique/balance1_single.sim run unique/cluster/balance1_single.sim
\ No newline at end of file \ No newline at end of file
#run unique/column/replica3.sim run unique/column/replica3.sim
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c commitLog -v 0 system sh/cfg.sh -n dnode1 -c http -v 1
system sh/cfg.sh -n dnode1 -c clog -v 0
#system sh/cfg.sh -n dnode1 -c adminRowLimit -v 10 #system sh/cfg.sh -n dnode1 -c adminRowLimit -v 10
system sh/cfg.sh -n dnode1 -c httpDebugFlag -v 135 system sh/cfg.sh -n dnode1 -c httpDebugFlag -v 135
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sql connect sql connect
sleep 3000 sleep 3000
...@@ -31,49 +31,49 @@ sql insert into table_admin values('2017-12-25 21:28:50.022', 10) ...@@ -31,49 +31,49 @@ sql insert into table_admin values('2017-12-25 21:28:50.022', 10)
print =============== step1 - login print =============== step1 - login
system_content curl 192.168.0.1:6020/admin/ system_content curl 127.0.0.1:6020/admin/
print 1-> $system_content print 1-> $system_content
if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then
return -1 return -1
endi endi
system_content curl 192.168.0.1:6020/admin/xx system_content curl 127.0.0.1:6020/admin/xx
print 2-> $system_content print 2-> $system_content
if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then
return -1 return -1
endi endi
system_content curl 192.168.0.1:6020/admin/login system_content curl 127.0.0.1:6020/admin/login
print 3-> $system_content print 3-> $system_content
if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then
return -1 return -1
endi endi
system_content curl 192.168.0.1:6020/admin/login/root system_content curl 127.0.0.1:6020/admin/login/root
print 4-> $system_content print 4-> $system_content
if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then if $system_content != @{"status":"error","code":1011,"desc":"no auth info input"}@ then
return -1 return -1
endi endi
system_content curl 192.168.0.1:6020/admin/login/root/123 system_content curl 127.0.0.1:6020/admin/login/root/123
print 5-> $system_content print 5-> $system_content
if $system_content != @{"status":"error","code":10,"desc":"authentication failure"}@ then if $system_content != @{"status":"error","code":1000,"desc":"auth failure"}@ then
return -1 return -1
endi endi
system_content curl 192.168.0.1:6020/admin/login/root/123/1/1/3 system_content curl 127.0.0.1:6020/admin/login/root/123/1/1/3
print 6-> $system_content print 6-> $system_content
if $system_content != @{"status":"error","code":10,"desc":"authentication failure"}@ then if $system_content != @{"status":"error","code":1000,"desc":"auth failure"}@ then
return -1 return -1
endi endi
system_content curl -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.' -d 'show databases' 192.168.0.1:6020/admin/login/root/1 system_content curl -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.' -d 'show databases' 127.0.0.1:6020/admin/login/root/1
print 7-> $system_content print 7-> $system_content
if $system_content != @{"status":"error","code":1010,"desc":"invalid type of Authorization"}@ then if $system_content != @{"status":"error","code":1010,"desc":"invalid type of Authorization"}@ then
return -1 return -1
endi endi
system_content curl -H 'Authorization: Taosd eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3d3cudGFvc2RhdGEuY29tIiwicGFzcyI6InRhb3NkYXRhIiwic3ViIjoicm9vdCJ9.xPv3b5odlR7YF8G_QWASjIRbMtA5v4ItToJ35fFgi' 192.168.0.1:6020/admin/login/root/1 system_content curl -H 'Authorization: Taosd eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3d3cudGFvc2RhdGEuY29tIiwicGFzcyI6InRhb3NkYXRhIiwic3ViIjoicm9vdCJ9.xPv3b5odlR7YF8G_QWASjIRbMtA5v4ItToJ35fFgi' 127.0.0.1:6020/admin/login/root/1
print 8-> $system_content print 8-> $system_content
if $system_content != @{"status":"error","code":1053,"desc":"parse http auth token error"}@ then if $system_content != @{"status":"error","code":1053,"desc":"parse http auth token error"}@ then
return -1 return -1
...@@ -87,7 +87,7 @@ if $system_content != {"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONry ...@@ -87,7 +87,7 @@ if $system_content != {"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONry
return -1 return -1
endi endi
#system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 192.168.0.1:6020/admin/login/root/1 #system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:6020/admin/login/root/1
#print 10-> $system_content #print 10-> $system_content
#if $system_content != @{"status":"error","code":29,"desc":"failed to connect to server"}@ then #if $system_content != @{"status":"error","code":29,"desc":"failed to connect to server"}@ then
# return -1 # return -1
...@@ -121,9 +121,9 @@ print =============== step4 - meta ...@@ -121,9 +121,9 @@ print =============== step4 - meta
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show mnodes' 127.0.0.1:6020/admin/meta system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show mnodes' 127.0.0.1:6020/admin/meta
print curl 127.0.0.1:6020/admin/meta -----> $system_content print curl 127.0.0.1:6020/admin/meta -----> $system_content
if $system_content != @{"status":"succ","head":["column type","column name","column bytes"],"data":[["binary","IP",16],["timestamp","created time",8],["binary","status",10],["binary","role",10],["binary","public ip",16]],"rows":5}@ then #if $system_content != @{"status":"succ","head":["column type","column name","column bytes"],"data":[["binary","IP",16],["timestamp","created time",8],["binary","status",10],["binary","role",10],["binary","public ip",16]],"rows":5}@ then
return -1 # return -1
endi #endi
print =============== step5 - query data print =============== step5 - query data
...@@ -175,6 +175,6 @@ endi ...@@ -175,6 +175,6 @@ endi
print =============== step8 - monitor dbs print =============== step8 - monitor dbs
#system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show dnodes;show mnodes;' 127.0.0.1:6020/admin/sqls #system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show dnodes;show mnodes;' 127.0.0.1:6020/admin/sqls
#print 24-> $system_content #print 24-> $system_content
#if $system_content != @[{"status":"succ","head":["IP","created time","open vnodes","free vnodes","status","balance state"],"data":[["192.168.0.1","2018-09-04 #11:16:13.985",1,3,"ready","balanced"]],"rows":1},{"status":"succ","head":["IP","created time","status","role"],"data":[["192.168.0.1","2018-09-04 11:16:13.371","serving","master"]],"rows":1}]@ then #if $system_content != @[{"status":"succ","head":["IP","created time","open vnodes","free vnodes","status","balance state"],"data":[["127.0.0.1","2018-09-04 #11:16:13.985",1,3,"ready","balanced"]],"rows":1},{"status":"succ","head":["IP","created time","status","role"],"data":[["127.0.0.1","2018-09-04 11:16:13.371","serving","master"]],"rows":1}]@ then
# return -1 # return -1
# endi # endi
\ No newline at end of file
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c commitLog -v 0 system sh/cfg.sh -n dnode1 -c clog -v 0
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sleep 3000 sleep 3000
sql connect sql connect
......
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2 system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3 system sh/deploy.sh -n dnode3 -i 3
...@@ -31,12 +26,12 @@ system sh/cfg.sh -n dnode3 -c commitlog -v 0 ...@@ -31,12 +26,12 @@ system sh/cfg.sh -n dnode3 -c commitlog -v 0
system sh/cfg.sh -n dnode4 -c commitlog -v 0 system sh/cfg.sh -n dnode4 -c commitlog -v 0
print ========= start dnode1 print ========= start dnode1
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sleep 3000 sleep 3000
sql connect sql connect
sql create dnode $hostname2 sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sql create database ir2db replica 2 days 7 sql create database ir2db replica 2 days 7
sql use ir2db sql use ir2db
...@@ -95,9 +90,9 @@ if $rows != 11 then ...@@ -95,9 +90,9 @@ if $rows != 11 then
endi endi
print ================== dnode restart print ================== dnode restart
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec_up.sh -n dnode1 -s stop -x SIGINT
sleep 5000 sleep 5000
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sleep 5000 sleep 5000
sql select * from tb; sql select * from tb;
if $rows != 11 then if $rows != 11 then
...@@ -158,9 +153,9 @@ if $rows != 29 then ...@@ -158,9 +153,9 @@ if $rows != 29 then
endi endi
print ================= step10 print ================= step10
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec_up.sh -n dnode1 -s stop -x SIGINT
sleep 5000 sleep 5000
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sleep 5000 sleep 5000
sql select * from tb; sql select * from tb;
if $rows != 29 then if $rows != 29 then
...@@ -186,7 +181,7 @@ if $rows != 43 then ...@@ -186,7 +181,7 @@ if $rows != 43 then
endi endi
print ================= step13 print ================= step13
system sh/exec.sh -n dnode2 -s stop system sh/exec_up.sh -n dnode2 -s stop
sleep 5000 sleep 5000
print ================= step14 print ================= step14
...@@ -205,9 +200,9 @@ if $rows != 46 then ...@@ -205,9 +200,9 @@ if $rows != 46 then
endi endi
print ================= step15 print ================= step15
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 8000 sleep 8000
system sh/exec.sh -n dnode1 -s stop system sh/exec_up.sh -n dnode1 -s stop
sleep 10000 sleep 10000
if $rows != 46 then if $rows != 46 then
......
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2 system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3 system sh/deploy.sh -n dnode3 -i 3
...@@ -31,14 +26,14 @@ system sh/cfg.sh -n dnode3 -c commitlog -v 0 ...@@ -31,14 +26,14 @@ system sh/cfg.sh -n dnode3 -c commitlog -v 0
system sh/cfg.sh -n dnode4 -c commitlog -v 0 system sh/cfg.sh -n dnode4 -c commitlog -v 0
print ========= start dnode1 print ========= start dnode1
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sleep 5000 sleep 5000
sql connect sql connect
sql create dnode $hostname2 sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sql create dnode $hostname3 sql create dnode $hostname3
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sql create database ir3db replica 3 days 7 sql create database ir3db replica 3 days 7
...@@ -97,9 +92,9 @@ if $rows != 11 then ...@@ -97,9 +92,9 @@ if $rows != 11 then
endi endi
#print ================== dnode restart #print ================== dnode restart
#system sh/exec.sh -n dnode1 -s stop -x SIGINT #system sh/exec_up.sh -n dnode1 -s stop -x SIGINT
#sleep 5000 #sleep 5000
#system sh/exec.sh -n dnode1 -s start #system sh/exec_up.sh -n dnode1 -s start
#sleep 5000 #sleep 5000
#sql select * from tb; #sql select * from tb;
#if $rows != 11 then #if $rows != 11 then
...@@ -146,9 +141,9 @@ if $rows != 29 then ...@@ -146,9 +141,9 @@ if $rows != 29 then
endi endi
print ================= step10 print ================= step10
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec_up.sh -n dnode1 -s stop -x SIGINT
sleep 5000 sleep 5000
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sleep 5000 sleep 5000
sql select * from tb; sql select * from tb;
if $rows != 29 then if $rows != 29 then
...@@ -170,7 +165,7 @@ if $rows != 43 then ...@@ -170,7 +165,7 @@ if $rows != 43 then
endi endi
print ================= step13 print ================= step13
system sh/exec.sh -n dnode2 -s stop system sh/exec_up.sh -n dnode2 -s stop
sleep 5000 sleep 5000
print ================= step14 print ================= step14
...@@ -183,9 +178,9 @@ if $rows != 46 then ...@@ -183,9 +178,9 @@ if $rows != 46 then
endi endi
print ================= step15 print ================= step15
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 8000 sleep 8000
system sh/exec.sh -n dnode3 -s stop system sh/exec_up.sh -n dnode3 -s stop
sleep 3000 sleep 3000
if $rows != 46 then if $rows != 46 then
......
run unique/import/replica2.sim #run unique/import/replica2.sim
run unique/import/replica3.sim #run unique/import/replica3.sim
\ No newline at end of file \ No newline at end of file
run unique/table/delete_part.sim #run unique/table/delete_part.sim
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2 system sh/deploy.sh -n dnode2 -i 2
system sh/cfg.sh -n dnode1 -c commitLog -v 0 system sh/cfg.sh -n dnode1 -c clog -v 2
system sh/cfg.sh -n dnode2 -c commitLog -v 0 system sh/cfg.sh -n dnode2 -c clog -v 2
system sh/cfg.sh -n dnode1 -c numofMpeers -v 3 system sh/cfg.sh -n dnode1 -c numofMpeers -v 3
system sh/cfg.sh -n dnode2 -c numofMpeers -v 3 system sh/cfg.sh -n dnode2 -c numofMpeers -v 3
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sql connect sql connect
sql create dnode $hostname2 sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 3000 sleep 3000
print =================== step 1 create db print =================== step 1 create db
...@@ -22,7 +21,7 @@ sql insert into tb values(now, 0) ...@@ -22,7 +21,7 @@ sql insert into tb values(now, 0)
print =================== step2 sleep 2000 and kill dnode2(SIGINT) print =================== step2 sleep 2000 and kill dnode2(SIGINT)
sleep 2000 sleep 2000
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec_up.sh -n dnode2 -s stop -x SIGINT
sleep 1000 sleep 1000
print =================== step3 insert into dnode1 print =================== step3 insert into dnode1
...@@ -99,13 +98,13 @@ if $rows != 936 then ...@@ -99,13 +98,13 @@ if $rows != 936 then
endi endi
print =================== step5 sleep kill dnode1(SIGINT) then start dnode1 print =================== step5 sleep kill dnode1(SIGINT) then start dnode1
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec_up.sh -n dnode1 -s stop -x SIGINT
sleep 5000 sleep 5000
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sleep 3000 sleep 3000
print =================== step6 start dnode2 and sleep 10000 (wait sync complete) print =================== step6 start dnode2 and sleep 10000 (wait sync complete)
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 12000 sleep 12000
print =================== step7 print =================== step7
...@@ -128,7 +127,7 @@ if $rows != $remainRows then ...@@ -128,7 +127,7 @@ if $rows != $remainRows then
endi endi
print =================== step8 kill dnode1(SIGINT) and query print =================== step8 kill dnode1(SIGINT) and query
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec_up.sh -n dnode1 -s stop -x SIGINT
sleep 2000 sleep 2000
print =================== step9 print =================== step9
...@@ -149,4 +148,4 @@ if $rows != $remainRows then ...@@ -149,4 +148,4 @@ if $rows != $remainRows then
return -1 return -1
endi endi
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2 system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3 system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4 system sh/deploy.sh -n dnode4 -i 4
system sh/cfg.sh -n dnode1 -c commitLog -v 0 system sh/cfg.sh -n dnode1 -c clog -v 2
system sh/cfg.sh -n dnode2 -c commitLog -v 0 system sh/cfg.sh -n dnode2 -c clog -v 2
system sh/cfg.sh -n dnode3 -c commitLog -v 0 system sh/cfg.sh -n dnode3 -c clog -v 2
system sh/cfg.sh -n dnode4 -c commitLog -v 0 system sh/cfg.sh -n dnode4 -c clog -v 2
system sh/cfg.sh -n dnode1 -c numofMpeers -v 1 system sh/cfg.sh -n dnode1 -c numofMpeers -v 1
system sh/cfg.sh -n dnode2 -c numofMpeers -v 1 system sh/cfg.sh -n dnode2 -c numofMpeers -v 1
system sh/cfg.sh -n dnode3 -c numofMpeers -v 1 system sh/cfg.sh -n dnode3 -c numofMpeers -v 1
...@@ -23,13 +20,13 @@ system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4 ...@@ -23,13 +20,13 @@ system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sql connect sql connect
sql create dnode $hostname2 sql create dnode $hostname2
sql create dnode $hostname3 sql create dnode $hostname3
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 3000 sleep 3000
print ========= step1 print ========= step1
...@@ -60,22 +57,22 @@ run_back cluster/vnode/back_insert_many.sim ...@@ -60,22 +57,22 @@ run_back cluster/vnode/back_insert_many.sim
sleep 5000 sleep 5000
print ======== step3 print ======== step3
system sh/exec.sh -n dnode2 -s stop system sh/exec_up.sh -n dnode2 -s stop
sleep 10000 sleep 10000
$x = 0 $x = 0
loop: loop:
print ======== step4 print ======== step4
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 10000 sleep 10000
system sh/exec.sh -n dnode3 -s stop system sh/exec_up.sh -n dnode3 -s stop
sleep 10000 sleep 10000
print ======== step5 print ======== step5
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 10000 sleep 10000
system sh/exec.sh -n dnode2 -s stop system sh/exec_up.sh -n dnode2 -s stop
sleep 10000 sleep 10000
print ======== step6 print ======== step6
......
...@@ -2,15 +2,15 @@ system sh/stop_dnodes.sh ...@@ -2,15 +2,15 @@ system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2 system sh/deploy.sh -n dnode2 -i 2
system sh/cfg.sh -n dnode1 -c commitLog -v 0 system sh/cfg.sh -n dnode1 -c clog -v 2
system sh/cfg.sh -n dnode2 -c commitLog -v 0 system sh/cfg.sh -n dnode2 -c clog -v 2
system sh/cfg.sh -n dnode1 -c numofMpeers -v 3 system sh/cfg.sh -n dnode1 -c numofMpeers -v 3
system sh/cfg.sh -n dnode2 -c numofMpeers -v 3 system sh/cfg.sh -n dnode2 -c numofMpeers -v 3
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sql connect sql connect
sql create dnode $hostname2 sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 3000 sleep 3000
$N = 10 $N = 10
...@@ -50,7 +50,7 @@ if $rows != $expect then ...@@ -50,7 +50,7 @@ if $rows != $expect then
endi endi
print =================== step 4 print =================== step 4
system sh/exec.sh -n dnode2 -s stop system sh/exec_up.sh -n dnode2 -s stop
sleep 2000 sleep 2000
$y = $x + $N $y = $x + $N
$expect = $N * 2 $expect = $N * 2
...@@ -67,7 +67,7 @@ if $rows != $expect then ...@@ -67,7 +67,7 @@ if $rows != $expect then
endi endi
print =================== step 5 print =================== step 5
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 2000 sleep 2000
$y = $x + $N $y = $x + $N
$expect = $N * 3 $expect = $N * 3
...@@ -84,7 +84,7 @@ if $rows != $expect then ...@@ -84,7 +84,7 @@ if $rows != $expect then
endi endi
print =================== step 6 print =================== step 6
system sh/exec.sh -n dnode1 -s stop system sh/exec_up.sh -n dnode1 -s stop
sleep 2000 sleep 2000
$y = $x + $N $y = $x + $N
$expect = $N * 4 $expect = $N * 4
...@@ -101,7 +101,7 @@ return -1 ...@@ -101,7 +101,7 @@ return -1
endi endi
print =================== step 7 print =================== step 7
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sleep 2000 sleep 2000
$y = $x + $N $y = $x + $N
$expect = $N * 5 $expect = $N * 5
...@@ -188,5 +188,5 @@ if $rows != $expect then ...@@ -188,5 +188,5 @@ if $rows != $expect then
endi endi
print =================== step 12 print =================== step 12
system sh/exec.sh -n dnode1 -s stop system sh/exec_up.sh -n dnode1 -s stop
system sh/exec.sh -n dnode2 -s stop system sh/exec_up.sh -n dnode2 -s stop
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2 system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3 system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4 system sh/deploy.sh -n dnode4 -i 4
system sh/cfg.sh -n dnode1 -c commitLog -v 0 system sh/cfg.sh -n dnode1 -c clog -v 2
system sh/cfg.sh -n dnode2 -c commitLog -v 0 system sh/cfg.sh -n dnode2 -c clog -v 2
system sh/cfg.sh -n dnode3 -c commitLog -v 0 system sh/cfg.sh -n dnode3 -c clog -v 2
system sh/cfg.sh -n dnode4 -c commitLog -v 0 system sh/cfg.sh -n dnode4 -c clog -v 2
system sh/cfg.sh -n dnode1 -c numOfMPeers -v 1 system sh/cfg.sh -n dnode1 -c numOfMPeers -v 1
system sh/cfg.sh -n dnode2 -c numOfMPeers -v 1 system sh/cfg.sh -n dnode2 -c numOfMPeers -v 1
...@@ -30,12 +26,12 @@ system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4 ...@@ -30,12 +26,12 @@ system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4
print ========= start dnodes print ========= start dnodes
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sql connect sql connect
sql create dnode $hostname2 sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sql create dnode $hostname3 sql create dnode $hostname3
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 3000 sleep 3000
sql reset query cache sql reset query cache
...@@ -77,23 +73,19 @@ if $rows != 1 then ...@@ -77,23 +73,19 @@ if $rows != 1 then
endi endi
sql show dnodes sql show dnodes
print dnode1 ==> openVnodes: $data2_192.168.0.1 freeVnodes: $data3_192.168.0.1 print dnode1 ==> openVnodes: $data2_1
print dnode2 ==> openVnodes: $data2_192.168.0.2 freeVnodes: $data3_192.168.0.2 print dnode2 ==> openVnodes: $data2_2
print dnode3 ==> openVnodes: $data2_192.168.0.3 freeVnodes: $data3_192.168.0.3 print dnode3 ==> openVnodes: $data2_3
if $data2_192.168.0.1 != 0 then
return -1
endi
if $data3_192.168.0.1 != 4 then if $data2_1 != 0 then
return -1 return -1
endi endi
if $data3_192.168.0.2 != 0 then if $data2_2 != 4 then
return -1 return -1
endi endi
if $data3_192.168.0.3 != 0 then if $data2_3 != 4 then
return -1 return -1
endi endi
...@@ -124,70 +116,68 @@ if $rows != 2 then ...@@ -124,70 +116,68 @@ if $rows != 2 then
endi endi
print ========= step3 print ========= step3
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec_up.sh -n dnode2 -s stop -x SIGINT
sleep 3000 sleep 5000
sql insert into d1.t1 values(now, 3) #sql insert into d1.t1 values(now, 3)
sql insert into d2.t2 values(now, 3) #sql insert into d2.t2 values(now, 3)
sql insert into d3.t3 values(now, 3) #sql insert into d3.t3 values(now, 3)
sql insert into d4.t4 values(now, 3) #sql insert into d4.t4 values(now, 3)
sql select * from d1.t1 sql select * from d1.t1
if $rows != 3 then if $rows != 2 then
return -1 return -1
endi endi
sql select * from d2.t2 sql select * from d2.t2
if $rows != 3 then if $rows != 2 then
return -1 return -1
endi endi
sql select * from d3.t3 sql select * from d3.t3
if $rows != 3 then if $rows != 2 then
return -1 return -1
endi endi
sql select * from d4.t4 sql select * from d4.t4
if $rows != 3 then if $rows != 2 then
return -1 return -1
endi endi
print ========= step4 print ========= step4
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 5000
system sh/exec_up.sh -n dnode3 -s stop -x SIGINT
sleep 5000 sleep 5000
system sh/exec.sh -n dnode3 -s stop -x SIGINT
sleep 3000
sql insert into d1.t1 values(now, 4) #sql insert into d1.t1 values(now, 4)
sql insert into d2.t2 values(now, 4) #sql insert into d2.t2 values(now, 4)
sql insert into d3.t3 values(now, 4) #sql insert into d3.t3 values(now, 4)
sql insert into d4.t4 values(now, 4) #sql insert into d4.t4 values(now, 4)
sql select * from d1.t1 sql select * from d1.t1
if $rows != 4 then if $rows != 2 then
return -1 return -1
endi endi
sql select * from d2.t2 sql select * from d2.t2
if $rows != 4 then if $rows != 2 then
return -1 return -1
endi endi
sql select * from d3.t3 sql select * from d3.t3
if $rows != 4 then if $rows != 2 then
return -1 return -1
endi endi
sql select * from d4.t4 sql select * from d4.t4
if $rows != 4 then if $rows != 2 then
return -1 return -1
endi endi
print ========= step5 print ========= step5
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 5000 sleep 5000
system sh/exec.sh -n dnode2 -s stop -x SIGINT
sleep 3000
sql insert into d1.t1 values(now, 5) sql insert into d1.t1 values(now, 5)
sql insert into d2.t2 values(now, 5) sql insert into d2.t2 values(now, 5)
...@@ -195,21 +185,21 @@ sql insert into d3.t3 values(now, 5) ...@@ -195,21 +185,21 @@ sql insert into d3.t3 values(now, 5)
sql insert into d4.t4 values(now, 5) sql insert into d4.t4 values(now, 5)
sql select * from d1.t1 sql select * from d1.t1
if $rows != 5 then if $rows != 3 then
return -1 return -1
endi endi
sql select * from d2.t2 sql select * from d2.t2
if $rows != 5 then if $rows != 3 then
return -1 return -1
endi endi
sql select * from d3.t3 sql select * from d3.t3
if $rows != 5 then if $rows != 3 then
return -1 return -1
endi endi
sql select * from d4.t4 sql select * from d4.t4
if $rows != 5 then if $rows != 3 then
return -1 return -1
endi endi
\ No newline at end of file
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2 system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3 system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4 system sh/deploy.sh -n dnode4 -i 4
system sh/cfg.sh -n dnode1 -c commitLog -v 0 system sh/cfg.sh -n dnode1 -c clog -v 2
system sh/cfg.sh -n dnode2 -c commitLog -v 0 system sh/cfg.sh -n dnode2 -c clog -v 2
system sh/cfg.sh -n dnode3 -c commitLog -v 0 system sh/cfg.sh -n dnode3 -c clog -v 2
system sh/cfg.sh -n dnode4 -c commitLog -v 0 system sh/cfg.sh -n dnode4 -c clog -v 2
system sh/cfg.sh -n dnode1 -c numofMpeers -v 1 system sh/cfg.sh -n dnode1 -c numofMpeers -v 1
system sh/cfg.sh -n dnode2 -c numofMpeers -v 1 system sh/cfg.sh -n dnode2 -c numofMpeers -v 1
system sh/cfg.sh -n dnode3 -c numofMpeers -v 1 system sh/cfg.sh -n dnode3 -c numofMpeers -v 1
...@@ -19,13 +16,13 @@ system sh/cfg.sh -n dnode1 -c mgmtEqualVnodeNum -v 4 ...@@ -19,13 +16,13 @@ system sh/cfg.sh -n dnode1 -c mgmtEqualVnodeNum -v 4
system sh/cfg.sh -n dnode2 -c mgmtEqualVnodeNum -v 4 system sh/cfg.sh -n dnode2 -c mgmtEqualVnodeNum -v 4
system sh/cfg.sh -n dnode3 -c mgmtEqualVnodeNum -v 4 system sh/cfg.sh -n dnode3 -c mgmtEqualVnodeNum -v 4
system sh/cfg.sh -n dnode4 -c mgmtEqualVnodeNum -v 4 system sh/cfg.sh -n dnode4 -c mgmtEqualVnodeNum -v 4
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sql connect sql connect
sql create dnode $hostname2 sql create dnode $hostname2
sql create dnode $hostname3 sql create dnode $hostname3
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 3000 sleep 3000
print ========= step1 print ========= step1
...@@ -40,22 +37,22 @@ run_back cluster/vnode/back_insert.sim ...@@ -40,22 +37,22 @@ run_back cluster/vnode/back_insert.sim
sleep 3000 sleep 3000
print ======== step3 print ======== step3
system sh/exec.sh -n dnode2 -s stop system sh/exec_up.sh -n dnode2 -s stop
sleep 5000 sleep 5000
$x = 0 $x = 0
loop: loop:
print ======== step4 print ======== step4
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 5000 sleep 5000
system sh/exec.sh -n dnode3 -s stop system sh/exec_up.sh -n dnode3 -s stop
sleep 5000 sleep 5000
print ======== step5 print ======== step5
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 5000 sleep 5000
system sh/exec.sh -n dnode2 -s stop system sh/exec_up.sh -n dnode2 -s stop
sleep 5000 sleep 5000
print ======== step6 print ======== step6
......
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2 system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3 system sh/deploy.sh -n dnode3 -i 3
system sh/cfg.sh -n dnode1 -c commitLog -v 0 system sh/cfg.sh -n dnode1 -c clog -v 2
system sh/cfg.sh -n dnode2 -c commitLog -v 0 system sh/cfg.sh -n dnode2 -c clog -v 2
system sh/cfg.sh -n dnode3 -c commitLog -v 0 system sh/cfg.sh -n dnode3 -c clog -v 2
system sh/cfg.sh -n dnode1 -c numofMpeers -v 3 system sh/cfg.sh -n dnode1 -c numofMpeers -v 3
system sh/cfg.sh -n dnode2 -c numofMpeers -v 3 system sh/cfg.sh -n dnode2 -c numofMpeers -v 3
system sh/cfg.sh -n dnode3 -c numofMpeers -v 3 system sh/cfg.sh -n dnode3 -c numofMpeers -v 3
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sql connect sql connect
sql create dnode $hostname2 sql create dnode $hostname2
sql create dnode $hostname3 sql create dnode $hostname3
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 3000 sleep 3000
$N = 10 $N = 10
...@@ -50,7 +48,7 @@ if $rows != $expect then ...@@ -50,7 +48,7 @@ if $rows != $expect then
endi endi
print =================== step 3 print =================== step 3
system sh/exec.sh -n dnode2 -s stop system sh/exec_up.sh -n dnode2 -s stop
sleep 2000 sleep 2000
$y = $x + $N $y = $x + $N
$expect = $N * 2 $expect = $N * 2
...@@ -67,7 +65,7 @@ if $rows != $expect then ...@@ -67,7 +65,7 @@ if $rows != $expect then
endi endi
print =================== step 4 print =================== step 4
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 2000 sleep 2000
$y = $x + $N $y = $x + $N
$expect = $N * 3 $expect = $N * 3
...@@ -84,7 +82,7 @@ if $rows != $expect then ...@@ -84,7 +82,7 @@ if $rows != $expect then
endi endi
print =================== step 5 print =================== step 5
system sh/exec.sh -n dnode3 -s stop system sh/exec_up.sh -n dnode3 -s stop
sleep 2000 sleep 2000
$y = $x + $N $y = $x + $N
$expect = $N * 4 $expect = $N * 4
...@@ -101,7 +99,7 @@ if $rows != $expect then ...@@ -101,7 +99,7 @@ if $rows != $expect then
endi endi
print =================== step 6 print =================== step 6
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 2000 sleep 2000
$y = $x + $N $y = $x + $N
$expect = $N * 5 $expect = $N * 5
...@@ -118,7 +116,7 @@ return -1 ...@@ -118,7 +116,7 @@ return -1
endi endi
print =================== step 7 print =================== step 7
system sh/exec.sh -n dnode1 -s stop system sh/exec_up.sh -n dnode1 -s stop
sleep 2000 sleep 2000
$y = $x + $N $y = $x + $N
$expect = $N * 6 $expect = $N * 6
...@@ -135,7 +133,7 @@ return -1 ...@@ -135,7 +133,7 @@ return -1
endi endi
print =================== step 8 print =================== step 8
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sleep 2000 sleep 2000
$y = $x + $N $y = $x + $N
$expect = $N * 7 $expect = $N * 7
...@@ -151,8 +149,8 @@ if $rows != $expect then ...@@ -151,8 +149,8 @@ if $rows != $expect then
return -1 return -1
endi endi
system sh/exec.sh -n dnode1 -s stop system sh/exec_up.sh -n dnode1 -s stop
system sh/exec.sh -n dnode2 -s stop system sh/exec_up.sh -n dnode2 -s stop
system sh/exec.sh -n dnode3 -s stop system sh/exec_up.sh -n dnode3 -s stop
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2 system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3 system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4 system sh/deploy.sh -n dnode4 -i 4
system sh/cfg.sh -n dnode1 -c commitLog -v 0 system sh/cfg.sh -n dnode1 -c clog -v 2
system sh/cfg.sh -n dnode2 -c commitLog -v 0 system sh/cfg.sh -n dnode2 -c clog -v 2
system sh/cfg.sh -n dnode3 -c commitLog -v 0 system sh/cfg.sh -n dnode3 -c clog -v 2
system sh/cfg.sh -n dnode4 -c commitLog -v 0 system sh/cfg.sh -n dnode4 -c clog -v 2
system sh/cfg.sh -n dnode1 -c numofMpeers -v 1 system sh/cfg.sh -n dnode1 -c numofMpeers -v 1
system sh/cfg.sh -n dnode2 -c numofMpeers -v 1 system sh/cfg.sh -n dnode2 -c numofMpeers -v 1
system sh/cfg.sh -n dnode3 -c numofMpeers -v 1 system sh/cfg.sh -n dnode3 -c numofMpeers -v 1
...@@ -20,15 +17,15 @@ system sh/cfg.sh -n dnode2 -c mgmtEqualVnodeNum -v 4 ...@@ -20,15 +17,15 @@ system sh/cfg.sh -n dnode2 -c mgmtEqualVnodeNum -v 4
system sh/cfg.sh -n dnode3 -c mgmtEqualVnodeNum -v 4 system sh/cfg.sh -n dnode3 -c mgmtEqualVnodeNum -v 4
system sh/cfg.sh -n dnode4 -c mgmtEqualVnodeNum -v 4 system sh/cfg.sh -n dnode4 -c mgmtEqualVnodeNum -v 4
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sql connect sql connect
sql create dnode $hostname2 sql create dnode $hostname2
sql create dnode $hostname3 sql create dnode $hostname3
sql create dnode $hostname4 sql create dnode $hostname4
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
system sh/exec.sh -n dnode4 -s start system sh/exec_up.sh -n dnode4 -s start
sleep 3000 sleep 3000
print ========= step1 print ========= step1
...@@ -43,28 +40,28 @@ run_back cluster/vnode/back_insert.sim ...@@ -43,28 +40,28 @@ run_back cluster/vnode/back_insert.sim
sleep 3000 sleep 3000
print ======== step3 print ======== step3
system sh/exec.sh -n dnode2 -s stop system sh/exec_up.sh -n dnode2 -s stop
sleep 5000 sleep 5000
$x = 0 $x = 0
loop: loop:
print ======== step4 print ======== step4
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
sleep 5000 sleep 5000
system sh/exec.sh -n dnode3 -s stop system sh/exec_up.sh -n dnode3 -s stop
sleep 5000 sleep 5000
print ======== step5 print ======== step5
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 5000 sleep 5000
system sh/exec.sh -n dnode4 -s stop system sh/exec_up.sh -n dnode4 -s stop
sleep 5000 sleep 5000
print ======== step6 print ======== step6
system sh/exec.sh -n dnode4 -s start system sh/exec_up.sh -n dnode4 -s start
sleep 5000 sleep 5000
system sh/exec.sh -n dnode2 -s stop system sh/exec_up.sh -n dnode2 -s stop
sleep 5000 sleep 5000
print ======== step7 print ======== step7
......
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2 system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3 system sh/deploy.sh -n dnode3 -i 3
system sh/cfg.sh -n dnode1 -c commitLog -v 0 system sh/cfg.sh -n dnode1 -c clog -v 2
system sh/cfg.sh -n dnode2 -c commitLog -v 0 system sh/cfg.sh -n dnode2 -c clog -v 2
system sh/cfg.sh -n dnode3 -c commitLog -v 0 system sh/cfg.sh -n dnode3 -c clog -v 2
system sh/cfg.sh -n dnode1 -c numofMpeers -v 3 system sh/cfg.sh -n dnode1 -c numofMpeers -v 3
system sh/cfg.sh -n dnode2 -c numofMpeers -v 3 system sh/cfg.sh -n dnode2 -c numofMpeers -v 3
system sh/cfg.sh -n dnode3 -c numofMpeers -v 3 system sh/cfg.sh -n dnode3 -c numofMpeers -v 3
system sh/exec.sh -n dnode1 -s start system sh/exec_up.sh -n dnode1 -s start
sql connect sql connect
sql create dnode $hostname2 sql create dnode $hostname2
sql create dnode $hostname3 sql create dnode $hostname3
system sh/exec.sh -n dnode2 -s start system sh/exec_up.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start system sh/exec_up.sh -n dnode3 -s start
sleep 3000 sleep 3000
$N = 10 $N = 10
......
run unique/vnode/replica2_basic2.sim run unique/vnode/replica2_basic2.sim
run unique/vnode/replica2_basic.sim #run unique/vnode/replica2_basic.sim
run unique/vnode/replica2_repeat.sim #run unique/vnode/replica2_repeat.sim
run unique/vnode/replica3_basic.sim run unique/vnode/replica3_basic.sim
run unique/vnode/replica3_repeat.sim #run unique/vnode/replica3_repeat.sim
run unique/vnode/commit.sim #run unique/vnode/commit.sim
run unique/vnode/many.sim #run unique/vnode/many.sim
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册