From 36ae97a0e53458b39a60d679b6dd2d8981186d48 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 24 Oct 2020 17:13:00 +0800 Subject: [PATCH] [td-1373] refactor --- src/client/src/tscSubquery.c | 8 +++----- src/query/inc/qTsbuf.h | 11 +++-------- src/query/src/qExecutor.c | 12 ++---------- src/query/src/qTsbuf.c | 6 +++--- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index f4b6ea2c94..938ec09beb 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -96,7 +96,7 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1, SJ tscInfo("%" PRId64 ", tags:%"PRId64" \t %" PRId64 ", tags:%"PRId64, elem1.ts, elem1.tag.i64Key, elem2.ts, elem2.tag.i64Key); #endif - int32_t res = tVariantCompare(&elem1.tag, &elem2.tag); + int32_t res = tVariantCompare(elem1.tag, elem2.tag); if (res == -1 || (res == 0 && tsCompare(order, elem1.ts, elem2.ts))) { if (!tsBufNextPos(pSupporter1->pTSBuf)) { break; @@ -123,11 +123,9 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1, SJ win->ekey = elem1.ts; } - tsBufAppend(output1, elem1.vnode, &elem1.tag, (const char*)&elem1.ts, sizeof(elem1.ts)); - tsBufAppend(output2, elem2.vnode, &elem2.tag, (const char*)&elem2.ts, sizeof(elem2.ts)); + tsBufAppend(output1, elem1.vnode, elem1.tag, (const char*)&elem1.ts, sizeof(elem1.ts)); + tsBufAppend(output2, elem2.vnode, elem2.tag, (const char*)&elem2.ts, sizeof(elem2.ts)); - tVariantDestroy(&elem1.tag); - tVariantDestroy(&elem2.tag); } else { pLimit->offset -= 1; } diff --git a/src/query/inc/qTsbuf.h b/src/query/inc/qTsbuf.h index fe5de8b25a..6c2a955f47 100644 --- a/src/query/inc/qTsbuf.h +++ b/src/query/inc/qTsbuf.h @@ -35,16 +35,9 @@ typedef struct STSList { int32_t len; } STSList; -typedef struct STSRawBlock { - int32_t vnode; - int64_t tag; - TSKEY* ts; - int32_t len; -} STSRawBlock; - typedef struct STSElem { TSKEY ts; - tVariant tag; + tVariant* tag; int32_t vnode; } STSElem; @@ -84,6 +77,7 @@ typedef struct STSBuf { char path[PATH_MAX]; uint32_t fileSize; + // todo use array STSVnodeBlockInfoEx* pData; uint32_t numOfAlloc; uint32_t numOfVnodes; @@ -121,6 +115,7 @@ void tsBufFlush(STSBuf* pTSBuf); void tsBufResetPos(STSBuf* pTSBuf); STSElem tsBufGetElem(STSBuf* pTSBuf); + bool tsBufNextPos(STSBuf* pTSBuf); STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t vnodeId, tVariant* tag); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 4e7f065dec..37394b9769 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1201,7 +1201,7 @@ static int32_t doTSJoinFilter(SQueryRuntimeEnv *pRuntimeEnv, int32_t offset) { SQLFunctionCtx *pCtx = pRuntimeEnv->pCtx; // compare tag first - if (tVariantCompare(&pCtx[0].tag, &elem.tag) != 0) { + if (tVariantCompare(&pCtx[0].tag, elem.tag) != 0) { return TS_JOIN_TAG_NOT_EQUALS; } @@ -3888,7 +3888,6 @@ int32_t setAdditionalInfo(SQInfo *pQInfo, void* pTable, STableQueryInfo *pTableQ qError("QInfo:%p failed to find tag:%" PRId64 " in ts_comp", pQInfo, pTag->i64Key); } - tVariantDestroy(&elem.tag); return false; } @@ -4815,7 +4814,6 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) { qError("QInfo:%p failed to find tag:%"PRId64" in ts_comp", pQInfo, pTag->i64Key); } - tVariantDestroy(&elem.tag); return false; } else { STSCursor cur = tsBufGetCursor(pRuntimeEnv->pTSBuf); @@ -4830,7 +4828,7 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) { } } else { STSElem elem = tsBufGetElem(pRuntimeEnv->pTSBuf); - if (tVariantCompare(&elem.tag, &pRuntimeEnv->pCtx[0].tag) != 0) { + if (tVariantCompare(elem.tag, &pRuntimeEnv->pCtx[0].tag) != 0) { STSElem elem1 = tsBufGetElemStartPos(pRuntimeEnv->pTSBuf, pQInfo->vgId, pTag); // failed to find data with the specified tag value and vnodeId @@ -4841,9 +4839,6 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) { qError("QInfo:%p failed to find tag:%"PRId64" in ts_comp", pQInfo, pTag->i64Key); } - tVariantDestroy(&elem.tag); - tVariantDestroy(&elem1.tag); - return false; } else { STSCursor cur = tsBufGetCursor(pRuntimeEnv->pTSBuf); @@ -4854,7 +4849,6 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) { } } - tVariantDestroy(&elem1.tag); } else { tsBufSetCursor(pRuntimeEnv->pTSBuf, &pRuntimeEnv->cur); STSCursor cur = tsBufGetCursor(pRuntimeEnv->pTSBuf); @@ -4864,8 +4858,6 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) { qDebug("QInfo:%p continue scan ts_comp file, tag:%"PRId64" blockIndex:%d, tsIndex:%d", pQInfo, pTag->i64Key, cur.blockIndex, cur.tsIndex); } } - - tVariantDestroy(&elem.tag); } } diff --git a/src/query/src/qTsbuf.c b/src/query/src/qTsbuf.c index 42b6e3f6e0..ad29cef5c2 100644 --- a/src/query/src/qTsbuf.c +++ b/src/query/src/qTsbuf.c @@ -702,7 +702,7 @@ STSElem tsBufGetElem(STSBuf* pTSBuf) { elem1.vnode = pTSBuf->pData[pCur->vgroupIndex].info.vnode; elem1.ts = *(TSKEY*)(pTSBuf->tsData.rawBuf + pCur->tsIndex * TSDB_KEYSIZE); - tVariantAssign(&elem1.tag, &pBlock->tag); + elem1.tag = &pBlock->tag; return elem1; } @@ -913,8 +913,8 @@ void tsBufDisplay(STSBuf* pTSBuf) { while (tsBufNextPos(pTSBuf)) { STSElem elem = tsBufGetElem(pTSBuf); - if (elem.tag.nType == TSDB_DATA_TYPE_BIGINT) { - printf("%d-%" PRId64 "-%" PRId64 "\n", elem.vnode, elem.tag.i64Key, elem.ts); + if (elem.tag->nType == TSDB_DATA_TYPE_BIGINT) { + printf("%d-%" PRId64 "-%" PRId64 "\n", elem.vnode, elem.tag->i64Key, elem.ts); } } -- GitLab