diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index f324a832fa85ef75cc43caf18d4944424d62b9e5..dc534c275b8729915ed67e38c2e74f191d5d62f4 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1252,19 +1252,28 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pQueryMsg->tsBuf.tsOffset = htonl((int32_t)(pMsg - pCmd->payload)); if (pQueryInfo->tsBuf != NULL) { - // note: here used the idx instead of actual vnode id. - int32_t vgId = 0; - if (pTableMetaInfo->pVgroupTables != NULL) { - int32_t vnodeIndex = pTableMetaInfo->vgroupIndex; - SVgroupTableInfo* pTableInfo = taosArrayGet(pTableMetaInfo->pVgroupTables, vnodeIndex); - vgId = pTableInfo->vgInfo.vgId; + bool qType = tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0); + if (qType) { + dumpFileBlockByGroupIndex(pQueryInfo->tsBuf, pTableMetaInfo->vgroupIndex, pMsg, &pQueryMsg->tsBuf.tsLen, &pQueryMsg->tsBuf.tsNumOfBlocks); + if (code != TSDB_CODE_SUCCESS) { + goto _end; + } } else { - vgId = query.vgId; - } + // note: here used the idx instead of actual vnode id. + int32_t vgId = 0; + if (pTableMetaInfo->pVgroupTables != NULL) { + int32_t vnodeIndex = pTableMetaInfo->vgroupIndex; + SVgroupTableInfo *pTableInfo = taosArrayGet(pTableMetaInfo->pVgroupTables, vnodeIndex); + vgId = pTableInfo->vgInfo.vgId; + } else { + vgId = query.vgId; + } - code = dumpFileBlockByGroupId(pQueryInfo->tsBuf, vgId, pMsg, &pQueryMsg->tsBuf.tsLen, &pQueryMsg->tsBuf.tsNumOfBlocks); - if (code != TSDB_CODE_SUCCESS) { - goto _end; + code = dumpFileBlockByGroupId(pQueryInfo->tsBuf, vgId, pMsg, &pQueryMsg->tsBuf.tsLen, + &pQueryMsg->tsBuf.tsNumOfBlocks); + if (code != TSDB_CODE_SUCCESS) { + goto _end; + } } pMsg += pQueryMsg->tsBuf.tsLen; diff --git a/src/query/inc/qTsbuf.h b/src/query/inc/qTsbuf.h index 109065b962d5a8dd9f02c7aa767a8fbf9e84983b..c56e36ad45f714eab82dd0ef50b853bf07c5ce85 100644 --- a/src/query/inc/qTsbuf.h +++ b/src/query/inc/qTsbuf.h @@ -136,6 +136,8 @@ void tsBufGetGroupIdList(STSBuf* pTSBuf, int32_t* num, int32_t** id); int32_t dumpFileBlockByGroupId(STSBuf* pTSBuf, int32_t id, void* buf, int32_t* len, int32_t* numOfBlocks); +int32_t dumpFileBlockByGroupIndex(STSBuf* pTSBuf, int32_t groupIndex, void* pBuf, int32_t* len, int32_t* numOfBlocks); + STSElem tsBufFindElemStartPosByTag(STSBuf* pTSBuf, tVariant* pTag); bool tsBufIsValidElem(STSElem* pElem); diff --git a/src/query/src/qTsbuf.c b/src/query/src/qTsbuf.c index e25737ef3205dcde0edc9bb67e7deda3dde11504..2d0b70627d9e652bd5f6b3c4d00a82b90f331b4c 100644 --- a/src/query/src/qTsbuf.c +++ b/src/query/src/qTsbuf.c @@ -1133,6 +1133,32 @@ int32_t dumpFileBlockByGroupId(STSBuf* pTSBuf, int32_t groupId, void* buf, int32 return TSDB_CODE_SUCCESS; } +int32_t dumpFileBlockByGroupIndex(STSBuf* pTSBuf, int32_t groupIndex, void* pBuf, int32_t* len, int32_t* numOfBlocks) { + assert(groupIndex >= 0 && groupIndex < pTSBuf->numOfGroups); + STSGroupBlockInfo* pBlockInfo = &pTSBuf->pData[groupIndex].info; + + *len = 0; + *numOfBlocks = 0; + + if (fseek(pTSBuf->f, pBlockInfo->offset, SEEK_SET) != 0) { + int code = TAOS_SYSTEM_ERROR(ferror(pTSBuf->f)); + // qError("%p: fseek failed: %s", pSql, tstrerror(code)); + return code; + } + + size_t s = fread(pBuf, 1, pBlockInfo->compLen, pTSBuf->f); + if (s != pBlockInfo->compLen) { + int code = TAOS_SYSTEM_ERROR(ferror(pTSBuf->f)); + // tscError("%p: fread didn't return expected data: %s", pSql, tstrerror(code)); + return code; + } + + *len = pBlockInfo->compLen; + *numOfBlocks = pBlockInfo->numOfBlocks; + + return TSDB_CODE_SUCCESS; +} + STSElem tsBufFindElemStartPosByTag(STSBuf* pTSBuf, tVariant* pTag) { STSElem el = {.id = -1};