[td-225]fix bugs in empty super table query.

This commit is contained in:
Haojun Liao 2020-05-25 23:29:26 +08:00
parent 6f524d20ac
commit 7cbff7c2c2
3 changed files with 23 additions and 12 deletions

View File

@ -165,7 +165,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo
SSqlRes *pRes = &pSql->res; SSqlRes *pRes = &pSql->res;
if ((pRes->qhandle == 0 || numOfRows != 0) && pCmd->command < TSDB_SQL_LOCAL) { if ((pRes->qhandle == 0 || numOfRows != 0) && pCmd->command < TSDB_SQL_LOCAL) {
if (pRes->qhandle == 0) { if (pRes->qhandle == 0 && numOfRows != 0) {
tscError("qhandle is NULL"); tscError("qhandle is NULL");
} else { } else {
pRes->code = numOfRows; pRes->code = numOfRows;

View File

@ -2010,7 +2010,7 @@ bool hasMoreVnodesToTry(SSqlObj* pSql) {
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
assert(pRes->completed); assert(pRes->completed);
// for normal table, do not try any more if result are exhausted // for normal table, no need to try any more if results are all retrieved from one vnode
if (!UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo) || (pTableMetaInfo->vgroupList == NULL)) { if (!UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo) || (pTableMetaInfo->vgroupList == NULL)) {
return false; return false;
} }
@ -2036,7 +2036,7 @@ void tscTryQueryNextVnode(SSqlObj* pSql, __async_cb_func_t fp) {
int32_t totalVgroups = pTableMetaInfo->vgroupList->numOfVgroups; int32_t totalVgroups = pTableMetaInfo->vgroupList->numOfVgroups;
while (++pTableMetaInfo->vgroupIndex < totalVgroups) { while (++pTableMetaInfo->vgroupIndex < totalVgroups) {
tscTrace("%p current vnode:%d exhausted, try next:%d. total vnode:%d. current numOfRes:%d", pSql, tscTrace("%p results from vgroup index:%d completed, try next:%d. total vgroups:%d. current numOfRes:%d", pSql,
pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVgroups, pRes->numOfClauseTotal); pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVgroups, pRes->numOfClauseTotal);
/* /*

View File

@ -4234,7 +4234,6 @@ static void setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery) {
} }
} }
static SFillColInfo* taosCreateFillColInfo(SQuery* pQuery) { static SFillColInfo* taosCreateFillColInfo(SQuery* pQuery) {
int32_t numOfCols = pQuery->numOfOutput; int32_t numOfCols = pQuery->numOfOutput;
int32_t offset = 0; int32_t offset = 0;
@ -5875,6 +5874,14 @@ static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, int32_t vgId, SQ
sem_post(&pQInfo->dataReady); sem_post(&pQInfo->dataReady);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (pQInfo->groupInfo.numOfTables == 0) {
qTrace("QInfo:%p no table qualified for tag filter, abort query", pQInfo);
setQueryStatus(pQuery, QUERY_COMPLETED);
sem_post(&pQInfo->dataReady);
return TSDB_CODE_SUCCESS;
}
// filter the qualified // filter the qualified
if ((code = doInitQInfo(pQInfo, pTSBuf, tsdb, vgId, isSTable)) != TSDB_CODE_SUCCESS) { if ((code = doInitQInfo(pQInfo, pTSBuf, tsdb, vgId, isSTable)) != TSDB_CODE_SUCCESS) {
@ -6108,12 +6115,14 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi
// todo handle the error // todo handle the error
/*int32_t ret =*/tsdbQuerySTableByTagCond(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 _over; // qTrace("qmsg:%p no results to produce by tag filters, return directly", pQueryMsg);
}
// goto _over;
// }
} else { } else {
groupInfo.numOfTables = taosArrayGetSize(pTableIdList); // groupInfo.numOfTables = taosArrayGetSize(pTableIdList);
SArray* pTableGroup = taosArrayInit(1, POINTER_BYTES); SArray* pTableGroup = taosArrayInit(1, POINTER_BYTES);
SArray* sa = taosArrayInit(groupInfo.numOfTables, sizeof(STableId)); SArray* sa = taosArrayInit(groupInfo.numOfTables, sizeof(STableId));
@ -6142,7 +6151,6 @@ _over:
taosArrayDestroy(pTableIdList); taosArrayDestroy(pTableIdList);
// 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);
return code; return code;
} }
@ -6155,7 +6163,7 @@ void qTableQuery(qinfo_t qinfo) {
SQInfo *pQInfo = (SQInfo *)qinfo; SQInfo *pQInfo = (SQInfo *)qinfo;
if (pQInfo == NULL || pQInfo->signature != pQInfo) { if (pQInfo == NULL || pQInfo->signature != pQInfo) {
qTrace("%p freed abort query", pQInfo); qTrace("QInfo:%p has been freed, no need to execute", pQInfo);
return; return;
} }
@ -6268,7 +6276,10 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
size_t num = taosArrayGetSize(pQInfo->groupInfo.pGroupList); size_t num = taosArrayGetSize(pQInfo->groupInfo.pGroupList);
assert(num == 1); // only one group assert(num == 0 || num == 1);
if (num == 0) {
return;
}
SArray* pa = taosArrayGetP(pQInfo->groupInfo.pGroupList, 0); SArray* pa = taosArrayGetP(pQInfo->groupInfo.pGroupList, 0);
num = taosArrayGetSize(pa); num = taosArrayGetSize(pa);