commit
ff7794c0d6
|
@ -30,7 +30,7 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code);
|
||||||
|
|
||||||
SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, int32_t index);
|
SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, int32_t index);
|
||||||
|
|
||||||
int32_t tscHandleMasterJoinQuery(SSqlObj* pSql);
|
void tscHandleMasterJoinQuery(SSqlObj* pSql);
|
||||||
|
|
||||||
int32_t tscHandleMasterSTableQuery(SSqlObj *pSql);
|
int32_t tscHandleMasterSTableQuery(SSqlObj *pSql);
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,7 @@ SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
|
||||||
size_t tscSqlExprNumOfExprs(SQueryInfo* pQueryInfo);
|
size_t tscSqlExprNumOfExprs(SQueryInfo* pQueryInfo);
|
||||||
|
|
||||||
SSqlExpr* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index);
|
SSqlExpr* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index);
|
||||||
void tscSqlExprCopy(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy);
|
int32_t 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);
|
||||||
|
@ -205,7 +205,7 @@ bool tscValidateColumnId(STableMetaInfo* pTableMetaInfo, int32_t colId, int32_t
|
||||||
SCond* tsGetSTableQueryCond(STagCond* pCond, uint64_t uid);
|
SCond* tsGetSTableQueryCond(STagCond* pCond, uint64_t uid);
|
||||||
void tsSetSTableQueryCond(STagCond* pTagCond, uint64_t uid, SBufferWriter* bw);
|
void tsSetSTableQueryCond(STagCond* pTagCond, uint64_t uid, SBufferWriter* bw);
|
||||||
|
|
||||||
void tscTagCondCopy(STagCond* dest, const STagCond* src);
|
int32_t tscTagCondCopy(STagCond* dest, const STagCond* src);
|
||||||
void tscTagCondRelease(STagCond* pCond);
|
void tscTagCondRelease(STagCond* pCond);
|
||||||
|
|
||||||
void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* pQueryInfo);
|
void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* pQueryInfo);
|
||||||
|
|
|
@ -50,7 +50,8 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const
|
||||||
pSql->sqlstr = calloc(1, sqlLen + 1);
|
pSql->sqlstr = calloc(1, sqlLen + 1);
|
||||||
if (pSql->sqlstr == NULL) {
|
if (pSql->sqlstr == NULL) {
|
||||||
tscError("%p failed to malloc sql string buffer", pSql);
|
tscError("%p failed to malloc sql string buffer", pSql);
|
||||||
tscQueueAsyncError(pSql->fp, pSql->param, TSDB_CODE_TSC_OUT_OF_MEMORY);
|
pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
tscQueueAsyncRes(pSql);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +95,6 @@ void taos_query_a(TAOS *taos, const char *sqlstr, __async_cb_func_t fp, void *pa
|
||||||
SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj));
|
SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj));
|
||||||
if (pSql == NULL) {
|
if (pSql == NULL) {
|
||||||
tscError("failed to malloc sqlObj");
|
tscError("failed to malloc sqlObj");
|
||||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
|
||||||
tscQueueAsyncError(fp, param, TSDB_CODE_TSC_OUT_OF_MEMORY);
|
tscQueueAsyncError(fp, param, TSDB_CODE_TSC_OUT_OF_MEMORY);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ void tscAsyncQuerySingleRowForNextVnode(void *param, TAOS_RES *tres, int numOfRo
|
||||||
tscProcessAsyncRetrieveImpl(param, tres, numOfRows, tscAsyncFetchSingleRowProxy);
|
tscProcessAsyncRetrieveImpl(param, tres, numOfRows, tscAsyncFetchSingleRowProxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), void *param) {
|
void taos_fetch_rows_a(TAOS_RES *taosa, __async_cb_func_t fp, void *param) {
|
||||||
SSqlObj *pSql = (SSqlObj *)taosa;
|
SSqlObj *pSql = (SSqlObj *)taosa;
|
||||||
if (pSql == NULL || pSql->signature != pSql) {
|
if (pSql == NULL || pSql->signature != pSql) {
|
||||||
tscError("sql object is NULL");
|
tscError("sql object is NULL");
|
||||||
|
@ -209,6 +209,8 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi
|
||||||
if (pRes->qhandle == 0) {
|
if (pRes->qhandle == 0) {
|
||||||
tscError("qhandle is NULL");
|
tscError("qhandle is NULL");
|
||||||
pRes->code = TSDB_CODE_TSC_INVALID_QHANDLE;
|
pRes->code = TSDB_CODE_TSC_INVALID_QHANDLE;
|
||||||
|
pSql->param = param;
|
||||||
|
|
||||||
tscQueueAsyncRes(pSql);
|
tscQueueAsyncRes(pSql);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -269,7 +271,10 @@ void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW),
|
||||||
|
|
||||||
if (pRes->qhandle == 0) {
|
if (pRes->qhandle == 0) {
|
||||||
tscError("qhandle is NULL");
|
tscError("qhandle is NULL");
|
||||||
tscQueueAsyncError(fp, param, TSDB_CODE_TSC_INVALID_QHANDLE);
|
pSql->param = param;
|
||||||
|
pRes->code = TSDB_CODE_TSC_INVALID_QHANDLE;
|
||||||
|
|
||||||
|
tscQueueAsyncRes(pSql);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,36 +357,17 @@ void tscProcessFetchRow(SSchedMsg *pMsg) {
|
||||||
|
|
||||||
void tscProcessAsyncRes(SSchedMsg *pMsg) {
|
void tscProcessAsyncRes(SSchedMsg *pMsg) {
|
||||||
SSqlObj *pSql = (SSqlObj *)pMsg->ahandle;
|
SSqlObj *pSql = (SSqlObj *)pMsg->ahandle;
|
||||||
// SSqlCmd *pCmd = &pSql->cmd;
|
|
||||||
SSqlRes *pRes = &pSql->res;
|
SSqlRes *pRes = &pSql->res;
|
||||||
|
|
||||||
// void *taosres = pSql;
|
|
||||||
|
|
||||||
// pCmd may be released, so cache pCmd->command
|
|
||||||
// int cmd = pCmd->command;
|
|
||||||
// int code = pRes->code;
|
|
||||||
|
|
||||||
// in case of async insert, restore the user specified callback function
|
|
||||||
// bool shouldFree = tscShouldBeFreed(pSql);
|
|
||||||
|
|
||||||
// if (pCmd->command == TSDB_SQL_INSERT) {
|
|
||||||
// assert(pSql->fp != NULL);
|
|
||||||
assert(pSql->fp != NULL && pSql->fetchFp != NULL);
|
assert(pSql->fp != NULL && pSql->fetchFp != NULL);
|
||||||
// }
|
|
||||||
|
|
||||||
// if (pSql->fp) {
|
|
||||||
pSql->fp = pSql->fetchFp;
|
pSql->fp = pSql->fetchFp;
|
||||||
(*pSql->fp)(pSql->param, pSql, pRes->code);
|
(*pSql->fp)(pSql->param, pSql, pRes->code);
|
||||||
// }
|
|
||||||
|
|
||||||
// if (shouldFree) {
|
|
||||||
// tscDebug("%p sqlObj is automatically freed in async res", pSql);
|
|
||||||
// tscFreeSqlObj(pSql);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this function will be executed by queue task threads, so the terrno is not valid
|
||||||
static void tscProcessAsyncError(SSchedMsg *pMsg) {
|
static void tscProcessAsyncError(SSchedMsg *pMsg) {
|
||||||
void (*fp)() = pMsg->ahandle;
|
void (*fp)() = pMsg->ahandle;
|
||||||
|
terrno = *(int32_t*) pMsg->msg;
|
||||||
(*fp)(pMsg->thandle, NULL, *(int32_t*)pMsg->msg);
|
(*fp)(pMsg->thandle, NULL, *(int32_t*)pMsg->msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2425,24 +2425,14 @@ static void top_bottom_func_finalizer(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
static bool percentile_function_setup(SQLFunctionCtx *pCtx) {
|
static bool percentile_function_setup(SQLFunctionCtx *pCtx) {
|
||||||
const int32_t MAX_AVAILABLE_BUFFER_SIZE = 1 << 20; // 1MB
|
|
||||||
const int32_t NUMOFCOLS = 1;
|
|
||||||
|
|
||||||
if (!function_setup(pCtx)) {
|
if (!function_setup(pCtx)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SResultInfo *pResInfo = GET_RES_INFO(pCtx);
|
SResultInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||||
SSchema field[1] = { { (uint8_t)pCtx->inputType, "dummyCol", 0, pCtx->inputBytes } };
|
|
||||||
|
|
||||||
SColumnModel *pModel = createColumnModel(field, 1, 1000);
|
|
||||||
int32_t orderIdx = 0;
|
|
||||||
|
|
||||||
// tOrderDesc object
|
|
||||||
tOrderDescriptor *pDesc = tOrderDesCreate(&orderIdx, NUMOFCOLS, pModel, TSDB_ORDER_DESC);
|
|
||||||
|
|
||||||
((SPercentileInfo *)(pResInfo->interResultBuf))->pMemBucket =
|
((SPercentileInfo *)(pResInfo->interResultBuf))->pMemBucket =
|
||||||
tMemBucketCreate(1024, MAX_AVAILABLE_BUFFER_SIZE, pCtx->inputBytes, pCtx->inputType, pDesc);
|
tMemBucketCreate(pCtx->inputBytes, pCtx->inputType);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2488,15 +2478,13 @@ static void percentile_finalizer(SQLFunctionCtx *pCtx) {
|
||||||
SResultInfo *pResInfo = GET_RES_INFO(pCtx);
|
SResultInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||||
tMemBucket * pMemBucket = ((SPercentileInfo *)pResInfo->interResultBuf)->pMemBucket;
|
tMemBucket * pMemBucket = ((SPercentileInfo *)pResInfo->interResultBuf)->pMemBucket;
|
||||||
|
|
||||||
if (pMemBucket->numOfElems > 0) { // check for null
|
if (pMemBucket->total > 0) { // check for null
|
||||||
*(double *)pCtx->aOutputBuf = getPercentile(pMemBucket, v);
|
*(double *)pCtx->aOutputBuf = getPercentile(pMemBucket, v);
|
||||||
} else {
|
} else {
|
||||||
setNull(pCtx->aOutputBuf, pCtx->outputType, pCtx->outputBytes);
|
setNull(pCtx->aOutputBuf, pCtx->outputType, pCtx->outputBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
tOrderDescDestroy(pMemBucket->pOrderDesc);
|
|
||||||
tMemBucketDestroy(pMemBucket);
|
tMemBucketDestroy(pMemBucket);
|
||||||
|
|
||||||
doFinalizer(pCtx);
|
doFinalizer(pCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -274,7 +274,7 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
|
||||||
return tscSetValueToResObj(pSql, rowLen);
|
return tscSetValueToResObj(pSql, rowLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tscProcessCurrentUser(SSqlObj *pSql) {
|
static int32_t tscProcessCurrentUser(SSqlObj *pSql) {
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||||
|
@ -282,14 +282,20 @@ static void tscProcessCurrentUser(SSqlObj *pSql) {
|
||||||
pExpr->resType = TSDB_DATA_TYPE_BINARY;
|
pExpr->resType = TSDB_DATA_TYPE_BINARY;
|
||||||
|
|
||||||
char* vx = calloc(1, pExpr->resBytes);
|
char* vx = calloc(1, pExpr->resBytes);
|
||||||
|
if (vx == NULL) {
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
size_t size = sizeof(pSql->pTscObj->user);
|
size_t size = sizeof(pSql->pTscObj->user);
|
||||||
STR_WITH_MAXSIZE_TO_VARSTR(vx, pSql->pTscObj->user, size);
|
STR_WITH_MAXSIZE_TO_VARSTR(vx, pSql->pTscObj->user, size);
|
||||||
|
|
||||||
tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
||||||
free(vx);
|
free(vx);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tscProcessCurrentDB(SSqlObj *pSql) {
|
static int32_t tscProcessCurrentDB(SSqlObj *pSql) {
|
||||||
char db[TSDB_DB_NAME_LEN] = {0};
|
char db[TSDB_DB_NAME_LEN] = {0};
|
||||||
extractDBName(pSql->pTscObj->db, db);
|
extractDBName(pSql->pTscObj->db, db);
|
||||||
|
|
||||||
|
@ -302,6 +308,10 @@ static void tscProcessCurrentDB(SSqlObj *pSql) {
|
||||||
pExpr->resBytes = TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE;
|
pExpr->resBytes = TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE;
|
||||||
|
|
||||||
char* vx = calloc(1, pExpr->resBytes);
|
char* vx = calloc(1, pExpr->resBytes);
|
||||||
|
if (vx == NULL) {
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
if (t == 0) {
|
if (t == 0) {
|
||||||
setVardataNull(vx, TSDB_DATA_TYPE_BINARY);
|
setVardataNull(vx, TSDB_DATA_TYPE_BINARY);
|
||||||
} else {
|
} else {
|
||||||
|
@ -310,9 +320,11 @@ static void tscProcessCurrentDB(SSqlObj *pSql) {
|
||||||
|
|
||||||
tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
||||||
free(vx);
|
free(vx);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tscProcessServerVer(SSqlObj *pSql) {
|
static int32_t tscProcessServerVer(SSqlObj *pSql) {
|
||||||
const char* v = pSql->pTscObj->sversion;
|
const char* v = pSql->pTscObj->sversion;
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
||||||
|
|
||||||
|
@ -323,13 +335,18 @@ static void tscProcessServerVer(SSqlObj *pSql) {
|
||||||
pExpr->resBytes = (int16_t)(t + VARSTR_HEADER_SIZE);
|
pExpr->resBytes = (int16_t)(t + VARSTR_HEADER_SIZE);
|
||||||
|
|
||||||
char* vx = calloc(1, pExpr->resBytes);
|
char* vx = calloc(1, pExpr->resBytes);
|
||||||
|
if (vx == NULL) {
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
STR_WITH_SIZE_TO_VARSTR(vx, v, (VarDataLenT)t);
|
STR_WITH_SIZE_TO_VARSTR(vx, v, (VarDataLenT)t);
|
||||||
tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
||||||
|
|
||||||
taosTFree(vx);
|
free(vx);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tscProcessClientVer(SSqlObj *pSql) {
|
static int32_t tscProcessClientVer(SSqlObj *pSql) {
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||||
|
@ -339,23 +356,28 @@ static void tscProcessClientVer(SSqlObj *pSql) {
|
||||||
pExpr->resBytes = (int16_t)(t + VARSTR_HEADER_SIZE);
|
pExpr->resBytes = (int16_t)(t + VARSTR_HEADER_SIZE);
|
||||||
|
|
||||||
char* v = calloc(1, pExpr->resBytes);
|
char* v = calloc(1, pExpr->resBytes);
|
||||||
|
if (v == NULL) {
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
STR_WITH_SIZE_TO_VARSTR(v, version, (VarDataLenT)t);
|
STR_WITH_SIZE_TO_VARSTR(v, version, (VarDataLenT)t);
|
||||||
tscSetLocalQueryResult(pSql, v, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
tscSetLocalQueryResult(pSql, v, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
||||||
|
|
||||||
taosTFree(v);
|
free(v);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tscProcessServStatus(SSqlObj *pSql) {
|
static int32_t tscProcessServStatus(SSqlObj *pSql) {
|
||||||
STscObj* pObj = pSql->pTscObj;
|
STscObj* pObj = pSql->pTscObj;
|
||||||
|
|
||||||
if (pObj->pHb != NULL) {
|
if (pObj->pHb != NULL) {
|
||||||
if (pObj->pHb->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
if (pObj->pHb->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
||||||
pSql->res.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
pSql->res.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||||
return;
|
return pSql->res.code;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (pSql->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
if (pSql->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
||||||
return;
|
return pSql->res.code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,6 +386,7 @@ static void tscProcessServStatus(SSqlObj *pSql) {
|
||||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||||
int32_t val = 1;
|
int32_t val = 1;
|
||||||
tscSetLocalQueryResult(pSql, (char*) &val, pExpr->aliasName, TSDB_DATA_TYPE_INT, sizeof(int32_t));
|
tscSetLocalQueryResult(pSql, (char*) &val, pExpr->aliasName, TSDB_DATA_TYPE_INT, sizeof(int32_t));
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, int16_t type, size_t valueLength) {
|
void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, int16_t type, size_t valueLength) {
|
||||||
|
@ -393,37 +416,39 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
|
||||||
|
|
||||||
int tscProcessLocalCmd(SSqlObj *pSql) {
|
int tscProcessLocalCmd(SSqlObj *pSql) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
|
SSqlRes *pRes = &pSql->res;
|
||||||
|
|
||||||
if (pCmd->command == TSDB_SQL_CFG_LOCAL) {
|
if (pCmd->command == TSDB_SQL_CFG_LOCAL) {
|
||||||
pSql->res.code = (uint8_t)taosCfgDynamicOptions(pCmd->payload);
|
pRes->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);
|
pRes->code = (uint8_t)tscProcessDescribeTable(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
|
||||||
* free allocated resources and remove the SqlObj from sql query linked list
|
* free allocated resources and remove the SqlObj from sql query linked list
|
||||||
*/
|
*/
|
||||||
pSql->res.qhandle = 0x1;
|
pRes->qhandle = 0x1;
|
||||||
pSql->res.numOfRows = 0;
|
pRes->numOfRows = 0;
|
||||||
} else if (pCmd->command == TSDB_SQL_RESET_CACHE) {
|
} else if (pCmd->command == TSDB_SQL_RESET_CACHE) {
|
||||||
taosCacheEmpty(tscCacheHandle);
|
taosCacheEmpty(tscCacheHandle);
|
||||||
|
pRes->code = TSDB_CODE_SUCCESS;
|
||||||
} else if (pCmd->command == TSDB_SQL_SERV_VERSION) {
|
} else if (pCmd->command == TSDB_SQL_SERV_VERSION) {
|
||||||
tscProcessServerVer(pSql);
|
pRes->code = tscProcessServerVer(pSql);
|
||||||
} else if (pCmd->command == TSDB_SQL_CLI_VERSION) {
|
} else if (pCmd->command == TSDB_SQL_CLI_VERSION) {
|
||||||
tscProcessClientVer(pSql);
|
pRes->code = tscProcessClientVer(pSql);
|
||||||
} else if (pCmd->command == TSDB_SQL_CURRENT_USER) {
|
} else if (pCmd->command == TSDB_SQL_CURRENT_USER) {
|
||||||
tscProcessCurrentUser(pSql);
|
pRes->code = tscProcessCurrentUser(pSql);
|
||||||
} else if (pCmd->command == TSDB_SQL_CURRENT_DB) {
|
} else if (pCmd->command == TSDB_SQL_CURRENT_DB) {
|
||||||
tscProcessCurrentDB(pSql);
|
pRes->code = tscProcessCurrentDB(pSql);
|
||||||
} else if (pCmd->command == TSDB_SQL_SERV_STATUS) {
|
} else if (pCmd->command == TSDB_SQL_SERV_STATUS) {
|
||||||
tscProcessServStatus(pSql);
|
pRes->code = tscProcessServStatus(pSql);
|
||||||
} else {
|
} else {
|
||||||
pSql->res.code = TSDB_CODE_TSC_INVALID_SQL;
|
pRes->code = TSDB_CODE_TSC_INVALID_SQL;
|
||||||
tscError("%p not support command:%d", pSql, pCmd->command);
|
tscError("%p not support command:%d", pSql, pCmd->command);
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep the code in local variable in order to avoid invalid read in case of async query
|
// keep the code in local variable in order to avoid invalid read in case of async query
|
||||||
int32_t code = pSql->res.code;
|
int32_t code = pRes->code;
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
(*pSql->fp)(pSql->param, pSql, code);
|
(*pSql->fp)(pSql->param, pSql, code);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -67,8 +67,7 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SLocalReducer *pReducer, tOrderDesc
|
||||||
SQLFunctionCtx *pCtx = &pReducer->pCtx[i];
|
SQLFunctionCtx *pCtx = &pReducer->pCtx[i];
|
||||||
SSqlExpr * pExpr = tscSqlExprGet(pQueryInfo, i);
|
SSqlExpr * pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||||
|
|
||||||
pCtx->aOutputBuf =
|
pCtx->aOutputBuf = pReducer->pResultBuf->data + pExpr->offset * pReducer->resColModel->capacity;
|
||||||
pReducer->pResultBuf->data + pExpr->offset * pReducer->resColModel->capacity;
|
|
||||||
pCtx->order = pQueryInfo->order.order;
|
pCtx->order = pQueryInfo->order.order;
|
||||||
pCtx->functionId = pExpr->functionId;
|
pCtx->functionId = pExpr->functionId;
|
||||||
|
|
||||||
|
@ -160,7 +159,6 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
||||||
|
|
||||||
if (pMemBuffer == NULL) {
|
if (pMemBuffer == NULL) {
|
||||||
tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer);
|
tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer);
|
||||||
|
|
||||||
tscError("%p pMemBuffer is NULL", pMemBuffer);
|
tscError("%p pMemBuffer is NULL", pMemBuffer);
|
||||||
pRes->code = TSDB_CODE_TSC_APP_ERROR;
|
pRes->code = TSDB_CODE_TSC_APP_ERROR;
|
||||||
return;
|
return;
|
||||||
|
@ -168,7 +166,6 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
||||||
|
|
||||||
if (pDesc->pColumnModel == NULL) {
|
if (pDesc->pColumnModel == NULL) {
|
||||||
tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer);
|
tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer);
|
||||||
|
|
||||||
tscError("%p no local buffer or intermediate result format model", pSql);
|
tscError("%p no local buffer or intermediate result format model", pSql);
|
||||||
pRes->code = TSDB_CODE_TSC_APP_ERROR;
|
pRes->code = TSDB_CODE_TSC_APP_ERROR;
|
||||||
return;
|
return;
|
||||||
|
@ -188,7 +185,6 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
||||||
if (numOfFlush == 0 || numOfBuffer == 0) {
|
if (numOfFlush == 0 || numOfBuffer == 0) {
|
||||||
tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer);
|
tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer);
|
||||||
tscDebug("%p retrieved no data", pSql);
|
tscDebug("%p retrieved no data", pSql);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,6 +275,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
||||||
taosTFree(pReducer);
|
taosTFree(pReducer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
param->pLocalData = pReducer->pLocalDataSrc;
|
param->pLocalData = pReducer->pLocalDataSrc;
|
||||||
param->pDesc = pReducer->pDesc;
|
param->pDesc = pReducer->pDesc;
|
||||||
param->num = pReducer->pLocalDataSrc[0]->pMemBuffer->numOfElemsPerPage;
|
param->num = pReducer->pLocalDataSrc[0]->pMemBuffer->numOfElemsPerPage;
|
||||||
|
|
|
@ -5827,22 +5827,34 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
|
||||||
|
|
||||||
int32_t ret = TSDB_CODE_SUCCESS;
|
int32_t ret = TSDB_CODE_SUCCESS;
|
||||||
for (int32_t i = 0; i < pList->nExpr; ++i) {
|
for (int32_t i = 0; i < pList->nExpr; ++i) {
|
||||||
SSchema* pSchema = pTagSchema + i;
|
SSchema* pSchema = &pTagSchema[i];
|
||||||
|
|
||||||
|
char tagVal[TSDB_MAX_TAGS_LEN];
|
||||||
if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) {
|
if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) {
|
||||||
// validate the length of binary
|
if (pList->a[i].pVar.nLen > pSchema->bytes) {
|
||||||
if (pList->a[i].pVar.nLen + VARSTR_HEADER_SIZE > pSchema->bytes) {
|
|
||||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char tagVal[TSDB_MAX_TAGS_LEN];
|
|
||||||
ret = tVariantDump(&(pList->a[i].pVar), tagVal, pSchema->type, true);
|
ret = tVariantDump(&(pList->a[i].pVar), tagVal, pSchema->type, true);
|
||||||
|
|
||||||
|
// check again after the convert since it may be converted from binary to nchar.
|
||||||
|
if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
int16_t len = varDataTLen(tagVal);
|
||||||
|
if (len > pSchema->bytes) {
|
||||||
|
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal);
|
tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,17 +226,13 @@ int tscSendMsgToServer(SSqlObj *pSql) {
|
||||||
.handle = &pSql->pRpcCtx,
|
.handle = &pSql->pRpcCtx,
|
||||||
.code = 0
|
.code = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
// NOTE: the rpc context should be acquired before sending data to server.
|
// NOTE: the rpc context should be acquired before sending data to server.
|
||||||
// Otherwise, the pSql object may have been released already during the response function, which is
|
// Otherwise, the pSql object may have been released already during the response function, which is
|
||||||
// processMsgFromServer function. In the meanwhile, the assignment of the rpc context to sql object will absolutely
|
// processMsgFromServer function. In the meanwhile, the assignment of the rpc context to sql object will absolutely
|
||||||
// cause crash.
|
// cause crash.
|
||||||
if (pObj != NULL && pObj->signature == pObj) {
|
rpcSendRequest(pObj->pDnodeConn, &pSql->epSet, &rpcMsg);
|
||||||
rpcSendRequest(pObj->pDnodeConn, &pSql->epSet, &rpcMsg);
|
return TSDB_CODE_SUCCESS;
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
} else {
|
|
||||||
//pObj->signature has been reset by other thread, ignore concurrency problem
|
|
||||||
return TSDB_CODE_TSC_CONN_KILLED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
|
void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
|
||||||
|
@ -1496,8 +1492,7 @@ int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
char *tmpData = NULL;
|
char *tmpData = NULL;
|
||||||
uint32_t len = pSql->cmd.payloadLen;
|
uint32_t len = pSql->cmd.payloadLen;
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
tmpData = calloc(1, len);
|
if ((tmpData = calloc(1, len)) == NULL) {
|
||||||
if (NULL == tmpData) {
|
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1542,8 +1537,7 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
// copy payload content to temp buff
|
// copy payload content to temp buff
|
||||||
char *tmpData = 0;
|
char *tmpData = 0;
|
||||||
if (pCmd->payloadLen > 0) {
|
if (pCmd->payloadLen > 0) {
|
||||||
tmpData = calloc(1, pCmd->payloadLen + 1);
|
if ((tmpData = calloc(1, pCmd->payloadLen + 1)) == NULL) return -1;
|
||||||
if (NULL == tmpData) return -1;
|
|
||||||
memcpy(tmpData, pCmd->payload, pCmd->payloadLen);
|
memcpy(tmpData, pCmd->payload, pCmd->payloadLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -574,8 +574,9 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar
|
||||||
|
|
||||||
SSchema* pColSchema = tscGetTableColumnSchemaById(pTableMetaInfo->pTableMeta, tagColId);
|
SSchema* pColSchema = tscGetTableColumnSchemaById(pTableMetaInfo->pTableMeta, tagColId);
|
||||||
|
|
||||||
*s1 = taosArrayInit(p1->num, p1->tagSize);
|
// int16_t for padding
|
||||||
*s2 = taosArrayInit(p2->num, p2->tagSize);
|
*s1 = taosArrayInit(p1->num, p1->tagSize - sizeof(int16_t));
|
||||||
|
*s2 = taosArrayInit(p2->num, p2->tagSize - sizeof(int16_t));
|
||||||
|
|
||||||
if (!(checkForDuplicateTagVal(pQueryInfo, p1, pParentSql) && checkForDuplicateTagVal(pQueryInfo, p2, pParentSql))) {
|
if (!(checkForDuplicateTagVal(pQueryInfo, p1, pParentSql) && checkForDuplicateTagVal(pQueryInfo, p2, pParentSql))) {
|
||||||
return TSDB_CODE_QRY_DUP_JOIN_KEY;
|
return TSDB_CODE_QRY_DUP_JOIN_KEY;
|
||||||
|
@ -1043,6 +1044,10 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
|
||||||
|
|
||||||
int32_t numOfExprs = (int32_t)tscSqlExprNumOfExprs(pQueryInfo);
|
int32_t numOfExprs = (int32_t)tscSqlExprNumOfExprs(pQueryInfo);
|
||||||
pRes->pColumnIndex = calloc(1, sizeof(SColumnIndex) * numOfExprs);
|
pRes->pColumnIndex = calloc(1, sizeof(SColumnIndex) * numOfExprs);
|
||||||
|
if (pRes->pColumnIndex == NULL) {
|
||||||
|
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||||
|
@ -1157,7 +1162,8 @@ static void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code);
|
||||||
|
|
||||||
static SSqlObj *tscCreateSTableSubquery(SSqlObj *pSql, SRetrieveSupport *trsupport, SSqlObj *prevSqlObj);
|
static SSqlObj *tscCreateSTableSubquery(SSqlObj *pSql, SRetrieveSupport *trsupport, SSqlObj *prevSqlObj);
|
||||||
|
|
||||||
int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter *pSupporter) {
|
// TODO
|
||||||
|
int32_t tscCreateJoinSubquery(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);
|
||||||
|
|
||||||
|
@ -1203,7 +1209,9 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter
|
||||||
|
|
||||||
// this data needs to be transfer to support struct
|
// this data needs to be transfer to support struct
|
||||||
memset(&pNewQueryInfo->fieldsInfo, 0, sizeof(SFieldInfo));
|
memset(&pNewQueryInfo->fieldsInfo, 0, sizeof(SFieldInfo));
|
||||||
tscTagCondCopy(&pSupporter->tagCond, &pNewQueryInfo->tagCond);//pNewQueryInfo->tagCond;
|
if (tscTagCondCopy(&pSupporter->tagCond, &pNewQueryInfo->tagCond) != 0) {
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
pNew->cmd.numOfCols = 0;
|
pNew->cmd.numOfCols = 0;
|
||||||
pNewQueryInfo->intervalTime = 0;
|
pNewQueryInfo->intervalTime = 0;
|
||||||
|
@ -1300,52 +1308,75 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter
|
||||||
pNewQueryInfo->type |= TSDB_QUERY_TYPE_SUBQUERY;
|
pNewQueryInfo->type |= TSDB_QUERY_TYPE_SUBQUERY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tscProcessSql(pNew);
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) {
|
void tscHandleMasterJoinQuery(SSqlObj* pSql) {
|
||||||
SSqlCmd* pCmd = &pSql->cmd;
|
SSqlCmd* pCmd = &pSql->cmd;
|
||||||
|
SSqlRes* pRes = &pSql->res;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
// todo add test
|
// todo add test
|
||||||
SSubqueryState *pState = calloc(1, sizeof(SSubqueryState));
|
SSubqueryState *pState = calloc(1, sizeof(SSubqueryState));
|
||||||
if (pState == NULL) {
|
if (pState == NULL) {
|
||||||
pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
return pSql->res.code;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
pState->numOfTotal = pQueryInfo->numOfTables;
|
pState->numOfTotal = pQueryInfo->numOfTables;
|
||||||
pState->numOfRemain = pState->numOfTotal;
|
pState->numOfRemain = pState->numOfTotal;
|
||||||
|
|
||||||
|
bool hasEmptySub = false;
|
||||||
|
|
||||||
tscDebug("%p start subquery, total:%d", pSql, pQueryInfo->numOfTables);
|
tscDebug("%p start subquery, total:%d", pSql, pQueryInfo->numOfTables);
|
||||||
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
|
||||||
SJoinSupporter *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);
|
||||||
pState->numOfRemain = i;
|
code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
goto _error;
|
||||||
if (0 == i) {
|
|
||||||
taosTFree(pState);
|
|
||||||
}
|
|
||||||
return pSql->res.code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = tscLaunchJoinSubquery(pSql, i, pSupporter);
|
code = tscCreateJoinSubquery(pSql, i, pSupporter);
|
||||||
if (code != TSDB_CODE_SUCCESS) { // failed to create subquery object, quit query
|
if (code != TSDB_CODE_SUCCESS) { // failed to create subquery object, quit query
|
||||||
tscDestroyJoinSupporter(pSupporter);
|
tscDestroyJoinSupporter(pSupporter);
|
||||||
pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
goto _error;
|
||||||
if (0 == i) {
|
}
|
||||||
taosTFree(pState);
|
|
||||||
}
|
SSqlObj* pSub = pSql->pSubs[i];
|
||||||
|
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSub->cmd, 0, 0);
|
||||||
|
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo) && (pTableMetaInfo->vgroupList->numOfVgroups == 0)) {
|
||||||
|
hasEmptySub = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pSql->cmd.command = (pSql->numOfSubs <= 0)? TSDB_SQL_RETRIEVE_EMPTY_RESULT:TSDB_SQL_TABLE_JOIN_RETRIEVE;
|
if (hasEmptySub) { // at least one subquery is empty, do nothing and return
|
||||||
|
freeJoinSubqueryObj(pSql);
|
||||||
return TSDB_CODE_SUCCESS;
|
pSql->cmd.command = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
|
||||||
|
(*pSql->fp)(pSql->param, pSql, 0);
|
||||||
|
} else {
|
||||||
|
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
|
||||||
|
SSqlObj* pSub = pSql->pSubs[i];
|
||||||
|
if ((code = tscProcessSql(pSub)) != TSDB_CODE_SUCCESS) {
|
||||||
|
pState->numOfRemain = i - 1; // the already sent reques will continue and do not go to the error process routine
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pSql->cmd.command = TSDB_SQL_TABLE_JOIN_RETRIEVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
_error:
|
||||||
|
pRes->code = code;
|
||||||
|
tscQueueAsyncRes(pSql);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs, SSubqueryState* pState) {
|
static void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs, SSubqueryState* pState) {
|
||||||
|
@ -1384,7 +1415,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
|
||||||
|
|
||||||
const uint32_t nBufferSize = (1u << 16); // 64KB
|
const uint32_t nBufferSize = (1u << 16); // 64KB
|
||||||
|
|
||||||
SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
|
||||||
pSql->numOfSubs = pTableMetaInfo->vgroupList->numOfVgroups;
|
pSql->numOfSubs = pTableMetaInfo->vgroupList->numOfVgroups;
|
||||||
|
@ -1399,9 +1430,20 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pSql->pSubs = calloc(pSql->numOfSubs, POINTER_BYTES);
|
pSql->pSubs = calloc(pSql->numOfSubs, POINTER_BYTES);
|
||||||
|
|
||||||
tscDebug("%p retrieved query data from %d vnode(s)", pSql, pSql->numOfSubs);
|
tscDebug("%p retrieved query data from %d vnode(s)", pSql, pSql->numOfSubs);
|
||||||
SSubqueryState *pState = calloc(1, sizeof(SSubqueryState));
|
SSubqueryState *pState = calloc(1, sizeof(SSubqueryState));
|
||||||
|
|
||||||
|
if (pSql->pSubs == NULL || pState == NULL) {
|
||||||
|
taosTFree(pState);
|
||||||
|
taosTFree(pSql->pSubs);
|
||||||
|
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
tscLocalReducerEnvDestroy(pMemoryBuf, pDesc, pModel, pSql->numOfSubs);
|
||||||
|
|
||||||
|
tscQueueAsyncRes(pSql);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
pState->numOfTotal = pSql->numOfSubs;
|
pState->numOfTotal = pSql->numOfSubs;
|
||||||
pState->numOfRemain = pSql->numOfSubs;
|
pState->numOfRemain = pSql->numOfSubs;
|
||||||
|
|
||||||
|
@ -2033,8 +2075,21 @@ static void doBuildResFromSubqueries(SSqlObj* pSql) {
|
||||||
numOfRes = (int32_t)(MIN(numOfRes, pSql->pSubs[i]->res.numOfRows));
|
numOfRes = (int32_t)(MIN(numOfRes, pSql->pSubs[i]->res.numOfRows));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (numOfRes == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t totalSize = tscGetResRowLength(pQueryInfo->exprList);
|
int32_t totalSize = tscGetResRowLength(pQueryInfo->exprList);
|
||||||
pRes->pRsp = realloc(pRes->pRsp, numOfRes * totalSize);
|
|
||||||
|
assert(numOfRes * totalSize > 0);
|
||||||
|
char* tmp = realloc(pRes->pRsp, numOfRes * totalSize);
|
||||||
|
if (tmp == NULL) {
|
||||||
|
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
pRes->pRsp = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
pRes->data = pRes->pRsp;
|
pRes->data = pRes->pRsp;
|
||||||
|
|
||||||
char* data = pRes->data;
|
char* data = pRes->data;
|
||||||
|
@ -2073,6 +2128,12 @@ void tscBuildResFromSubqueries(SSqlObj *pSql) {
|
||||||
pRes->buffer = calloc(numOfExprs, POINTER_BYTES);
|
pRes->buffer = calloc(numOfExprs, POINTER_BYTES);
|
||||||
pRes->length = calloc(numOfExprs, sizeof(int32_t));
|
pRes->length = calloc(numOfExprs, sizeof(int32_t));
|
||||||
|
|
||||||
|
if (pRes->tsrow == NULL || pRes->buffer == NULL || pRes->length == NULL) {
|
||||||
|
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
tscQueueAsyncRes(pSql);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
tscRestoreSQLFuncForSTableQuery(pQueryInfo);
|
tscRestoreSQLFuncForSTableQuery(pQueryInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -254,15 +254,12 @@ int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) {
|
||||||
pRes->numOfCols = numOfOutput;
|
pRes->numOfCols = numOfOutput;
|
||||||
|
|
||||||
pRes->tsrow = calloc(numOfOutput, POINTER_BYTES);
|
pRes->tsrow = calloc(numOfOutput, POINTER_BYTES);
|
||||||
pRes->length = calloc(numOfOutput, sizeof(int32_t)); // todo refactor
|
pRes->length = calloc(numOfOutput, sizeof(int32_t));
|
||||||
pRes->buffer = calloc(numOfOutput, POINTER_BYTES);
|
pRes->buffer = calloc(numOfOutput, POINTER_BYTES);
|
||||||
|
|
||||||
// not enough memory
|
// not enough memory
|
||||||
if (pRes->tsrow == NULL || (pRes->buffer == NULL && pRes->numOfCols > 0)) {
|
if (pRes->tsrow == NULL || (pRes->buffer == NULL && pRes->numOfCols > 0)) {
|
||||||
taosTFree(pRes->tsrow);
|
taosTFree(pRes->tsrow);
|
||||||
taosTFree(pRes->buffer);
|
|
||||||
taosTFree(pRes->length);
|
|
||||||
|
|
||||||
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
return pRes->code;
|
return pRes->code;
|
||||||
}
|
}
|
||||||
|
@ -281,13 +278,14 @@ void tscDestroyResPointerInfo(SSqlRes* pRes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
taosTFree(pRes->pRsp);
|
taosTFree(pRes->pRsp);
|
||||||
|
|
||||||
taosTFree(pRes->tsrow);
|
taosTFree(pRes->tsrow);
|
||||||
taosTFree(pRes->length);
|
taosTFree(pRes->length);
|
||||||
|
taosTFree(pRes->buffer);
|
||||||
|
|
||||||
taosTFree(pRes->pGroupRec);
|
taosTFree(pRes->pGroupRec);
|
||||||
taosTFree(pRes->pColumnIndex);
|
taosTFree(pRes->pColumnIndex);
|
||||||
taosTFree(pRes->buffer);
|
|
||||||
|
|
||||||
if (pRes->pArithSup != NULL) {
|
if (pRes->pArithSup != NULL) {
|
||||||
taosTFree(pRes->pArithSup->data);
|
taosTFree(pRes->pArithSup->data);
|
||||||
taosTFree(pRes->pArithSup);
|
taosTFree(pRes->pArithSup);
|
||||||
|
@ -1052,7 +1050,7 @@ void tscSqlExprInfoDestroy(SArray* pExprInfo) {
|
||||||
taosArrayDestroy(pExprInfo);
|
taosArrayDestroy(pExprInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscSqlExprCopy(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy) {
|
int32_t tscSqlExprCopy(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy) {
|
||||||
assert(src != NULL && dst != NULL);
|
assert(src != NULL && dst != NULL);
|
||||||
|
|
||||||
size_t size = taosArrayGetSize(src);
|
size_t size = taosArrayGetSize(src);
|
||||||
|
@ -1064,7 +1062,7 @@ void tscSqlExprCopy(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy)
|
||||||
if (deepcopy) {
|
if (deepcopy) {
|
||||||
SSqlExpr* p1 = calloc(1, sizeof(SSqlExpr));
|
SSqlExpr* p1 = calloc(1, sizeof(SSqlExpr));
|
||||||
if (p1 == NULL) {
|
if (p1 == NULL) {
|
||||||
assert(0);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*p1 = *pExpr;
|
*p1 = *pExpr;
|
||||||
|
@ -1078,6 +1076,8 @@ void tscSqlExprCopy(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SColumn* tscColumnListInsert(SArray* pColumnList, SColumnIndex* pColIndex) {
|
SColumn* tscColumnListInsert(SArray* pColumnList, SColumnIndex* pColIndex) {
|
||||||
|
@ -1324,11 +1324,14 @@ bool tscValidateColumnId(STableMetaInfo* pTableMetaInfo, int32_t colId, int32_t
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscTagCondCopy(STagCond* dest, const STagCond* src) {
|
int32_t tscTagCondCopy(STagCond* dest, const STagCond* src) {
|
||||||
memset(dest, 0, sizeof(STagCond));
|
memset(dest, 0, sizeof(STagCond));
|
||||||
|
|
||||||
if (src->tbnameCond.cond != NULL) {
|
if (src->tbnameCond.cond != NULL) {
|
||||||
dest->tbnameCond.cond = strdup(src->tbnameCond.cond);
|
dest->tbnameCond.cond = strdup(src->tbnameCond.cond);
|
||||||
|
if (dest->tbnameCond.cond == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dest->tbnameCond.uid = src->tbnameCond.uid;
|
dest->tbnameCond.uid = src->tbnameCond.uid;
|
||||||
|
@ -1337,7 +1340,7 @@ void tscTagCondCopy(STagCond* dest, const STagCond* src) {
|
||||||
dest->relType = src->relType;
|
dest->relType = src->relType;
|
||||||
|
|
||||||
if (src->pCond == NULL) {
|
if (src->pCond == NULL) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t s = taosArrayGetSize(src->pCond);
|
size_t s = taosArrayGetSize(src->pCond);
|
||||||
|
@ -1354,7 +1357,7 @@ void tscTagCondCopy(STagCond* dest, const STagCond* src) {
|
||||||
assert(pCond->cond != NULL);
|
assert(pCond->cond != NULL);
|
||||||
c.cond = malloc(c.len);
|
c.cond = malloc(c.len);
|
||||||
if (c.cond == NULL) {
|
if (c.cond == NULL) {
|
||||||
assert(0);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(c.cond, pCond->cond, c.len);
|
memcpy(c.cond, pCond->cond, c.len);
|
||||||
|
@ -1362,6 +1365,8 @@ void tscTagCondCopy(STagCond* dest, const STagCond* src) {
|
||||||
|
|
||||||
taosArrayPush(dest->pCond, &c);
|
taosArrayPush(dest->pCond, &c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscTagCondRelease(STagCond* pTagCond) {
|
void tscTagCondRelease(STagCond* pTagCond) {
|
||||||
|
@ -1855,7 +1860,10 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tscTagCondCopy(&pNewQueryInfo->tagCond, &pQueryInfo->tagCond);
|
if (tscTagCondCopy(&pNewQueryInfo->tagCond, &pQueryInfo->tagCond) != 0) {
|
||||||
|
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
|
||||||
if (pQueryInfo->fillType != TSDB_FILL_NONE) {
|
if (pQueryInfo->fillType != TSDB_FILL_NONE) {
|
||||||
pNewQueryInfo->fillVal = malloc(pQueryInfo->fieldsInfo.numOfOutput * sizeof(int64_t));
|
pNewQueryInfo->fillVal = malloc(pQueryInfo->fieldsInfo.numOfOutput * sizeof(int64_t));
|
||||||
|
@ -1884,7 +1892,10 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t uid = pTableMetaInfo->pTableMeta->id.uid;
|
uint64_t uid = pTableMetaInfo->pTableMeta->id.uid;
|
||||||
tscSqlExprCopy(pNewQueryInfo->exprList, pQueryInfo->exprList, uid, true);
|
if (tscSqlExprCopy(pNewQueryInfo->exprList, pQueryInfo->exprList, uid, true) != 0) {
|
||||||
|
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
|
||||||
doSetSqlExprAndResultFieldInfo(pQueryInfo, pNewQueryInfo, uid);
|
doSetSqlExprAndResultFieldInfo(pQueryInfo, pNewQueryInfo, uid);
|
||||||
|
|
||||||
|
|
|
@ -189,7 +189,10 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in
|
||||||
start *= 1000L;
|
start *= 1000L;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
start = ((start - intervalTime) / slidingTime + 1) * slidingTime;
|
int64_t delta = startTime - intervalTime;
|
||||||
|
int32_t factor = delta > 0? 1:-1;
|
||||||
|
|
||||||
|
start = (delta / slidingTime + factor) * slidingTime;
|
||||||
|
|
||||||
if (timeUnit == 'd' || timeUnit == 'w') {
|
if (timeUnit == 'd' || timeUnit == 'w') {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#define TDENGINE_QPERCENTILE_H
|
#define TDENGINE_QPERCENTILE_H
|
||||||
|
|
||||||
#include "qExtbuffer.h"
|
#include "qExtbuffer.h"
|
||||||
|
#include "qResultbuf.h"
|
||||||
|
#include "qTsbuf.h"
|
||||||
|
|
||||||
typedef struct MinMaxEntry {
|
typedef struct MinMaxEntry {
|
||||||
union {
|
union {
|
||||||
|
@ -31,47 +33,43 @@ typedef struct MinMaxEntry {
|
||||||
};
|
};
|
||||||
} MinMaxEntry;
|
} MinMaxEntry;
|
||||||
|
|
||||||
typedef struct tMemBucketSegment {
|
typedef struct {
|
||||||
int32_t numOfSlots;
|
int32_t size;
|
||||||
MinMaxEntry * pBoundingEntries;
|
int32_t pageId;
|
||||||
tExtMemBuffer **pBuffer;
|
tFilePage *data;
|
||||||
} tMemBucketSegment;
|
} SSlotInfo;
|
||||||
|
|
||||||
|
typedef struct tMemBucketSlot {
|
||||||
|
SSlotInfo info;
|
||||||
|
MinMaxEntry range;
|
||||||
|
} tMemBucketSlot;
|
||||||
|
|
||||||
|
struct tMemBucket;
|
||||||
|
typedef int32_t (*__perc_hash_func_t)(struct tMemBucket *pBucket, const void *value);
|
||||||
|
|
||||||
typedef struct tMemBucket {
|
typedef struct tMemBucket {
|
||||||
int16_t numOfSegs;
|
int16_t numOfSlots;
|
||||||
int16_t nTotalSlots;
|
int16_t type;
|
||||||
int16_t nSlotsOfSeg;
|
int16_t bytes;
|
||||||
int16_t dataType;
|
int32_t total;
|
||||||
|
int32_t elemPerPage; // number of elements for each object
|
||||||
int16_t nElemSize;
|
int32_t maxCapacity; // maximum allowed number of elements that can be sort directly to get the result
|
||||||
int32_t numOfElems;
|
int32_t bufPageSize; // disk page size
|
||||||
|
MinMaxEntry range; // value range
|
||||||
int32_t nTotalBufferSize;
|
int32_t times; // count that has been checked for deciding the correct data value buckets.
|
||||||
int32_t maxElemsCapacity;
|
__compar_fn_t comparFn;
|
||||||
|
|
||||||
int32_t pageSize;
|
tMemBucketSlot *pSlots;
|
||||||
int16_t numOfTotalPages;
|
SDiskbasedResultBuf *pBuffer;
|
||||||
int16_t numOfAvailPages; /* remain available buffer pages */
|
__perc_hash_func_t hashFunc;
|
||||||
|
|
||||||
tMemBucketSegment *pSegs;
|
|
||||||
tOrderDescriptor * pOrderDesc;
|
|
||||||
|
|
||||||
MinMaxEntry nRange;
|
|
||||||
|
|
||||||
void (*HashFunc)(struct tMemBucket *pBucket, void *value, int16_t *segIdx, int16_t *slotIdx);
|
|
||||||
} tMemBucket;
|
} tMemBucket;
|
||||||
|
|
||||||
tMemBucket *tMemBucketCreate(int32_t totalSlots, int32_t nBufferSize, int16_t nElemSize, int16_t dataType,
|
tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType);
|
||||||
tOrderDescriptor *pDesc);
|
|
||||||
|
|
||||||
void tMemBucketDestroy(tMemBucket *pBucket);
|
void tMemBucketDestroy(tMemBucket *pBucket);
|
||||||
|
|
||||||
void tMemBucketPut(tMemBucket *pBucket, void *data, int32_t numOfRows);
|
void tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size);
|
||||||
|
|
||||||
double getPercentile(tMemBucket *pMemBucket, double percent);
|
double getPercentile(tMemBucket *pMemBucket, double percent);
|
||||||
|
|
||||||
void tBucketIntHash(tMemBucket *pBucket, void *value, int16_t *segIdx, int16_t *slotIdx);
|
|
||||||
|
|
||||||
void tBucketDoubleHash(tMemBucket *pBucket, void *value, int16_t *segIdx, int16_t *slotIdx);
|
|
||||||
|
|
||||||
#endif // TDENGINE_QPERCENTILE_H
|
#endif // TDENGINE_QPERCENTILE_H
|
||||||
|
|
|
@ -1964,6 +1964,15 @@ static void changeExecuteScanOrder(SQInfo *pQInfo, bool stableQuery) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) {
|
||||||
|
pQuery->order.order = TSDB_ORDER_ASC;
|
||||||
|
if (pQuery->window.skey > pQuery->window.ekey) {
|
||||||
|
SWAP(pQuery->window.skey, pQuery->window.ekey, TSKEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isPointInterpoQuery(pQuery) && pQuery->intervalTime == 0) {
|
if (isPointInterpoQuery(pQuery) && pQuery->intervalTime == 0) {
|
||||||
if (!QUERY_IS_ASC_QUERY(pQuery)) {
|
if (!QUERY_IS_ASC_QUERY(pQuery)) {
|
||||||
qDebug(msg, GET_QINFO_ADDR(pQuery), "interp", pQuery->order.order, TSDB_ORDER_ASC, pQuery->window.skey,
|
qDebug(msg, GET_QINFO_ADDR(pQuery), "interp", pQuery->order.order, TSDB_ORDER_ASC, pQuery->window.skey,
|
||||||
|
@ -2125,35 +2134,36 @@ static bool needToLoadDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SDataStatis *pDat
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PT_IN_WINDOW(_p, _w) ((_p) > (_w).skey && (_p) < (_w).ekey)
|
|
||||||
|
|
||||||
static bool overlapWithTimeWindow(SQuery* pQuery, SDataBlockInfo* pBlockInfo) {
|
static bool overlapWithTimeWindow(SQuery* pQuery, SDataBlockInfo* pBlockInfo) {
|
||||||
STimeWindow w = {0};
|
STimeWindow w = {0};
|
||||||
|
|
||||||
TSKEY sk = MIN(pQuery->window.skey, pQuery->window.ekey);
|
TSKEY sk = MIN(pQuery->window.skey, pQuery->window.ekey);
|
||||||
TSKEY ek = MAX(pQuery->window.skey, pQuery->window.ekey);
|
TSKEY ek = MAX(pQuery->window.skey, pQuery->window.ekey);
|
||||||
|
|
||||||
|
|
||||||
if (QUERY_IS_ASC_QUERY(pQuery)) {
|
if (QUERY_IS_ASC_QUERY(pQuery)) {
|
||||||
getAlignQueryTimeWindow(pQuery, pBlockInfo->window.skey, sk, ek, &w);
|
getAlignQueryTimeWindow(pQuery, pBlockInfo->window.skey, sk, ek, &w);
|
||||||
|
assert(w.ekey >= pBlockInfo->window.skey);
|
||||||
|
|
||||||
if (PT_IN_WINDOW(w.ekey, pBlockInfo->window)) {
|
if (w.ekey < pBlockInfo->window.ekey) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
GET_NEXT_TIMEWINDOW(pQuery, &w);
|
GET_NEXT_TIMEWINDOW(pQuery, &w);
|
||||||
if (w.skey > pBlockInfo->window.skey) {
|
if (w.skey > pBlockInfo->window.ekey) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PT_IN_WINDOW(w.skey, pBlockInfo->window) || PT_IN_WINDOW(w.ekey, pBlockInfo->window)) {
|
assert(w.ekey > pBlockInfo->window.ekey);
|
||||||
|
if (w.skey <= pBlockInfo->window.ekey && w.skey > pBlockInfo->window.skey) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getAlignQueryTimeWindow(pQuery, pBlockInfo->window.ekey, sk, ek, &w);
|
getAlignQueryTimeWindow(pQuery, pBlockInfo->window.ekey, sk, ek, &w);
|
||||||
if (PT_IN_WINDOW(w.skey, pBlockInfo->window)) {
|
assert(w.skey <= pBlockInfo->window.ekey);
|
||||||
|
|
||||||
|
if (w.skey > pBlockInfo->window.skey) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2163,7 +2173,8 @@ static bool overlapWithTimeWindow(SQuery* pQuery, SDataBlockInfo* pBlockInfo) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PT_IN_WINDOW(w.skey, pBlockInfo->window) || PT_IN_WINDOW(w.ekey, pBlockInfo->window)) {
|
assert(w.skey < pBlockInfo->window.skey);
|
||||||
|
if (w.ekey < pBlockInfo->window.ekey && w.ekey >= pBlockInfo->window.skey) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4440,7 +4451,7 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, void *tsdb, int32_t vgId, bo
|
||||||
|
|
||||||
// NOTE: pTableCheckInfo need to update the query time range and the lastKey info
|
// NOTE: pTableCheckInfo need to update the query time range and the lastKey info
|
||||||
// TODO fixme
|
// TODO fixme
|
||||||
changeExecuteScanOrder(pQInfo, false);
|
changeExecuteScanOrder(pQInfo, isSTableQuery);
|
||||||
|
|
||||||
code = setupQueryHandle(tsdb, pQInfo, isSTableQuery);
|
code = setupQueryHandle(tsdb, pQInfo, isSTableQuery);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -6149,6 +6160,9 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList,
|
||||||
goto _cleanup;
|
goto _cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: pTableCheckInfo need to update the query time range and the lastKey info
|
||||||
|
// changeExecuteScanOrder(pQInfo, stableQuery);
|
||||||
|
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
|
|
||||||
for(int32_t i = 0; i < numOfGroups; ++i) {
|
for(int32_t i = 0; i < numOfGroups; ++i) {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -272,6 +272,7 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen
|
||||||
|
|
||||||
void* pData = (ptNode != NULL)? (*ptNode)->data:NULL;
|
void* pData = (ptNode != NULL)? (*ptNode)->data:NULL;
|
||||||
assert((int64_t)pData != 0x40);
|
assert((int64_t)pData != 0x40);
|
||||||
|
|
||||||
if (pData != NULL) {
|
if (pData != NULL) {
|
||||||
atomic_add_fetch_32(&pCacheObj->statistics.hitCount, 1);
|
atomic_add_fetch_32(&pCacheObj->statistics.hitCount, 1);
|
||||||
uDebug("cache:%s, key:%p, %p is retrieved from cache, refcnt:%d", pCacheObj->name, key, pData, T_REF_VAL_GET(*ptNode));
|
uDebug("cache:%s, key:%p, %p is retrieved from cache, refcnt:%d", pCacheObj->name, key, pData, T_REF_VAL_GET(*ptNode));
|
||||||
|
@ -498,7 +499,7 @@ void taosAddToTrash(SCacheObj *pCacheObj, SCacheDataNode *pNode) {
|
||||||
|
|
||||||
STrashElem *pElem = calloc(1, sizeof(STrashElem));
|
STrashElem *pElem = calloc(1, sizeof(STrashElem));
|
||||||
pElem->pData = pNode;
|
pElem->pData = pNode;
|
||||||
pElem->prev = NULL;
|
pElem->prev = NULL;
|
||||||
pNode->inTrashCan = true;
|
pNode->inTrashCan = true;
|
||||||
pNode->pTNodeHeader = pElem;
|
pNode->pTNodeHeader = pElem;
|
||||||
|
|
||||||
|
|
|
@ -482,15 +482,31 @@ sql insert into um2 using m2 tags(9) values(1000001, 10)(2000000, 20);
|
||||||
|
|
||||||
sql_error select count(*) from m1,m2 where m1.a=m2.a and m1.ts=m2.ts;
|
sql_error select count(*) from m1,m2 where m1.a=m2.a and m1.ts=m2.ts;
|
||||||
|
|
||||||
#empty table join test, add for no result join test
|
print ====> empty table/empty super-table join test, add for no result join test
|
||||||
sql create database ux1;
|
sql create database ux1;
|
||||||
sql use ux1;
|
sql use ux1;
|
||||||
sql create table m1(ts timestamp, k int) tags(a binary(12), b int);
|
sql create table m1(ts timestamp, k int) tags(a binary(12), b int);
|
||||||
sql create table tm0 using m1 tags('abc', 1);
|
sql create table tm0 using m1 tags('abc', 1);
|
||||||
sql create table m2(ts timestamp, k int) tags(a int, b binary(12));
|
sql create table m2(ts timestamp, k int) tags(a int, b binary(12));
|
||||||
|
|
||||||
|
sql select count(*) from m1, m2 where m1.ts=m2.ts and m1.b=m2.a;
|
||||||
|
if $rows != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
sql create table tm2 using m2 tags(2, 'abc');
|
sql create table tm2 using m2 tags(2, 'abc');
|
||||||
sql select count(*) from tm0, tm2 where tm0.ts=tm2.ts;
|
sql select count(*) from tm0, tm2 where tm0.ts=tm2.ts;
|
||||||
sql select count(*) from m1, m2 where m1.ts=m2.ts and m1.b=m2.a
|
if $rows != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql select count(*) from m1, m2 where m1.ts=m2.ts and m1.b=m2.a;
|
||||||
|
if $rows != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql drop table tm2;
|
||||||
|
sql select count(*) from m1, m2 where m1.ts=m2.ts and m1.b=m2.a;
|
||||||
sql drop database ux1;
|
sql drop database ux1;
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
Loading…
Reference in New Issue