From 9e1db3f3db7d2761a070016e1b5d373ca4437936 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Wed, 18 Dec 2019 16:49:36 +0800 Subject: [PATCH] fix bug in issue #941 [tbase-1359] --- src/system/detail/src/mgmtSupertableQuery.c | 36 +++++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/system/detail/src/mgmtSupertableQuery.c b/src/system/detail/src/mgmtSupertableQuery.c index 1aabe2feda..f83ffd4247 100644 --- a/src/system/detail/src/mgmtSupertableQuery.c +++ b/src/system/detail/src/mgmtSupertableQuery.c @@ -100,6 +100,32 @@ static int32_t tabObjResultComparator(const void* p1, const void* p2, void* para return 0; } +/** + * update the tag order index according to the tags column index. The tags column index needs to be checked one-by-one, + * since the normal columns may be passed to server for handling the group by on status column. + * + * @param pMetricMetaMsg + * @param tableIndex + * @param pOrderIndexInfo + * @param numOfTags + */ +static void mgmtUpdateOrderTagColIndex(SMetricMetaMsg* pMetricMetaMsg, int32_t tableIndex, tOrderIdx* pOrderIndexInfo, + int32_t numOfTags) { + SMetricMetaElemMsg* pElem = (SMetricMetaElemMsg*)((char*)pMetricMetaMsg + pMetricMetaMsg->metaElem[tableIndex]); + SColIndexEx* groupColumnList = (SColIndexEx*)((char*)pMetricMetaMsg + pElem->groupbyTagColumnList); + + int32_t numOfGroupbyTags = 0; + for (int32_t i = 0; i < pElem->numOfGroupCols; ++i) { + if (groupColumnList[i].flag == TSDB_COL_TAG) { // ignore this column if it is not a tag column. + pOrderIndexInfo->pData[numOfGroupbyTags++] = groupColumnList[i].colIdx; + + assert(groupColumnList[i].colIdx < numOfTags); + } + } + + pOrderIndexInfo->numOfOrderedCols = numOfGroupbyTags; +} + // todo merge sort function with losertree used void mgmtReorganizeMetersInMetricMeta(SMetricMetaMsg* pMetricMetaMsg, int32_t tableIndex, tQueryResultset* pRes) { if (pRes->num <= 0) { // no result, no need to pagination @@ -122,13 +148,9 @@ void mgmtReorganizeMetersInMetricMeta(SMetricMetaMsg* pMetricMetaMsg, int32_t ta int32_t* startPos = NULL; int32_t numOfSubset = 1; - - if (pElem->numOfGroupCols > 0) { - SColIndexEx* groupColumnList = (SColIndexEx*)((char*)pMetricMetaMsg + pElem->groupbyTagColumnList); - for (int32_t i = 0; i < pElem->numOfGroupCols; ++i) { - descriptor->orderIdx.pData[i] = groupColumnList[i].colIdx; - } - + + mgmtUpdateOrderTagColIndex(pMetricMetaMsg, tableIndex, &descriptor->orderIdx, pMetric->numOfTags); + if (descriptor->orderIdx.numOfOrderedCols > 0) { tQSortEx(pRes->pRes, POINTER_BYTES, 0, pRes->num - 1, descriptor, tabObjResultComparator); startPos = calculateSubGroup(pRes->pRes, pRes->num, &numOfSubset, descriptor, tabObjResultComparator); } else {