diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 7bad8ba5793b26eea26e01b9b6a8447da9bfc730..794eca4e59a9e950c7562f2a883f0237783b0b30 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2806,10 +2806,19 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) { tscDebug("0x%"PRIx64" numOfRows:%d, offset:%" PRId64 ", complete:%d, qId:0x%"PRIx64, pSql->self, pRes->numOfRows, pRes->offset, pRes->completed, pRes->qId); + int32_t numOfCols = pQueryInfo->fieldsInfo.numOfOutput; + int32_t rowBytes = 0; + for (int i = 0; i < numOfCols; ++i) { + SInternalField* internalField = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, i); + rowBytes += internalField->field.bytes; + } + int32_t origSize = rowBytes * pRes->numOfRows; + int32_t compSize = htonl(pRetrieve->compLen) + numOfCols * sizeof(int32_t); + int32_t dataLen = (pRetrieve->compressed) ? compSize : origSize; if (pRetrieve->extend == 1) { - STLV* tlv = (STLV*)(pRetrieve->data + ntohl(pRetrieve->compLen)); + STLV* tlv = (STLV*)(pRetrieve->data + dataLen); while (tlv->type != TLV_TYPE_END_MARK) { - switch (tlv->type) { + switch (ntohs(tlv->type)) { case TLV_TYPE_META_VERSION: pRes->sVersion = ntohl(*(int32_t*)tlv->value); pRes->tVersion = ntohl(*(int32_t*)(tlv->value + sizeof(int32_t))); diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index c5365a0c68486719fdf6d69420aec501c521b97f..2de0e1f4e94e6b56515f906650864a07d54dded4 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -421,10 +421,12 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co RESET_NUM_OF_RESULTS(&(pQInfo->runtimeEnv)); pQInfo->lastRetrieveTs = taosGetTimestampMs(); + int32_t numOfCols = pQueryAttr->pExpr2 ? pQueryAttr->numOfExpr2 : pQueryAttr->numOfOutput; + int32_t origSize = pQueryAttr->resultRowSize * s; + int32_t compSize = compLen + numOfCols * sizeof(int32_t); + int32_t dataLen = origSize; if ((*pRsp)->compressed && compLen != 0) { - int32_t numOfCols = pQueryAttr->pExpr2 ? pQueryAttr->numOfExpr2 : pQueryAttr->numOfOutput; - int32_t origSize = pQueryAttr->resultRowSize * s; - int32_t compSize = compLen + numOfCols * sizeof(int32_t); + dataLen = compSize; *contLen = *contLen - origSize + compSize; *pRsp = (SRetrieveTableRsp *)rpcReallocCont(*pRsp, *contLen); qDebug("QInfo:0x%"PRIx64" compress col data, uncompressed size:%d, compressed size:%d, ratio:%.2f", @@ -446,7 +448,7 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co } (*pRsp)->extend = 1; - STLV* tlv = (STLV*)((*pRsp)->data + compLen); + STLV* tlv = (STLV*)((*pRsp)->data + dataLen); tlv->type = htons(TLV_TYPE_META_VERSION); tlv->len = htonl(sizeof(int32_t) + sizeof(int32_t)); int32_t sVersion = htonl(pQueryAttr->tableGroupInfo.sVersion);