提交 86e230cf 编写于 作者: H Haojun Liao

[td-11818] opt perf.

上级 ec4e6fe7
...@@ -22,6 +22,11 @@ extern "C" { ...@@ -22,6 +22,11 @@ extern "C" {
typedef int (*__merge_compare_fn_t)(const void *, const void *, void *param); typedef int (*__merge_compare_fn_t)(const void *, const void *, void *param);
typedef struct STreeNode {
int32_t index;
void *pData; // TODO remove it?
} STreeNode;
typedef struct SMultiwayMergeTreeInfo { typedef struct SMultiwayMergeTreeInfo {
int32_t numOfSources; int32_t numOfSources;
int32_t totalSources; int32_t totalSources;
...@@ -30,6 +35,9 @@ typedef struct SMultiwayMergeTreeInfo { ...@@ -30,6 +35,9 @@ typedef struct SMultiwayMergeTreeInfo {
struct STreeNode *pNode; struct STreeNode *pNode;
} SMultiwayMergeTreeInfo; } SMultiwayMergeTreeInfo;
#define tMergeTreeGetChosenIndex(t_) ((t_)->pNode[0].index)
#define tMergeTreeGetAdjustIndex(t_) (tMergeTreeGetChosenIndex(t_) + (t_)->numOfSources)
int32_t tMergeTreeCreate(SMultiwayMergeTreeInfo **pTree, uint32_t numOfEntries, void *param, __merge_compare_fn_t compareFn); int32_t tMergeTreeCreate(SMultiwayMergeTreeInfo **pTree, uint32_t numOfEntries, void *param, __merge_compare_fn_t compareFn);
void tMergeTreeDestroy(SMultiwayMergeTreeInfo* pTree); void tMergeTreeDestroy(SMultiwayMergeTreeInfo* pTree);
...@@ -40,10 +48,6 @@ void tMergeTreeRebuild(SMultiwayMergeTreeInfo *pTree); ...@@ -40,10 +48,6 @@ void tMergeTreeRebuild(SMultiwayMergeTreeInfo *pTree);
void tMergeTreePrint(const SMultiwayMergeTreeInfo *pTree); void tMergeTreePrint(const SMultiwayMergeTreeInfo *pTree);
int32_t tMergeTreeGetChosenIndex(const SMultiwayMergeTreeInfo* pTree);
int32_t tMergeTreeAdjustIndex(const SMultiwayMergeTreeInfo* pTree);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -2192,7 +2192,7 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu ...@@ -2192,7 +2192,7 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu
sup.blockIndexArray[pos] = sup.numOfBlocksPerTable[pos] + 1; sup.blockIndexArray[pos] = sup.numOfBlocksPerTable[pos] + 1;
} }
tMergeTreeAdjust(pTree, tMergeTreeAdjustIndex(pTree)); tMergeTreeAdjust(pTree, tMergeTreeGetAdjustIndex(pTree));
} }
/* /*
......
...@@ -612,7 +612,7 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv ...@@ -612,7 +612,7 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv
} }
} }
tMergeTreeAdjust(pTree, tMergeTreeAdjustIndex(pTree)); tMergeTreeAdjust(pTree, tMergeTreeGetAdjustIndex(pTree));
} }
int64_t endt = taosGetTimestampMs(); int64_t endt = taosGetTimestampMs();
......
...@@ -5548,31 +5548,39 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) { ...@@ -5548,31 +5548,39 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) {
int32_t pRightIdx = *(int32_t *)pRight; int32_t pRightIdx = *(int32_t *)pRight;
SMsortComparParam *pParam = (SMsortComparParam *)param; SMsortComparParam *pParam = (SMsortComparParam *)param;
SExternalMemSource **pSources = pParam->pSources;
SArray *pInfo = pParam->orderInfo; SArray *pInfo = pParam->orderInfo;
SExternalMemSource* pLeftSource = pParam->pSources[pLeftIdx];
SExternalMemSource* pRightSource = pParam->pSources[pRightIdx];
// this input is exhausted, set the special value to denote this // this input is exhausted, set the special value to denote this
if (pSources[pLeftIdx]->rowIndex == -1) { if (pLeftSource->rowIndex == -1) {
return 1; return 1;
} }
if (pSources[pRightIdx]->rowIndex == -1) { if (pRightSource->rowIndex == -1) {
return -1; return -1;
} }
SSDataBlock* pLeftBlock = pSources[pLeftIdx]->pBlock; SSDataBlock* pLeftBlock = pLeftSource->pBlock;
SSDataBlock* pRightBlock = pSources[pRightIdx]->pBlock; SSDataBlock* pRightBlock = pRightSource->pBlock;
size_t num = taosArrayGetSize(pInfo); for(int32_t i = 0; i < pInfo->size; ++i) {
for(int32_t i = 0; i < num; ++i) { SBlockOrderInfo* pOrder = TARRAY_GET_ELEM(pInfo, i);
SBlockOrderInfo* pOrder = taosArrayGet(pInfo, i);
SColumnInfoData* pLeftColInfoData = taosArrayGet(pLeftBlock->pDataBlock, pOrder->colIndex); SColumnInfoData* pLeftColInfoData = TARRAY_GET_ELEM(pLeftBlock->pDataBlock, pOrder->colIndex);
bool leftNull = colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pSources[pLeftIdx]->rowIndex, pLeftBlock->pBlockAgg);
SColumnInfoData* pRightColInfoData = taosArrayGet(pRightBlock->pDataBlock, pOrder->colIndex); bool leftNull = false;
bool rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pSources[pRightIdx]->rowIndex, pRightBlock->pBlockAgg); if (pLeftColInfoData->hasNull) {
leftNull = colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pLeftSource->rowIndex, pLeftBlock->pBlockAgg);
}
SColumnInfoData* pRightColInfoData = TARRAY_GET_ELEM(pRightBlock->pDataBlock, pOrder->colIndex);
bool rightNull = false;
if (pRightColInfoData->hasNull) {
rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pRightSource->rowIndex, pRightBlock->pBlockAgg);
}
if (leftNull && rightNull) { if (leftNull && rightNull) {
continue; // continue to next slot continue; // continue to next slot
...@@ -5586,20 +5594,24 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) { ...@@ -5586,20 +5594,24 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) {
return pParam->nullFirst? -1:1; return pParam->nullFirst? -1:1;
} }
void* left1 = colDataGet(pLeftColInfoData, pSources[pLeftIdx]->rowIndex); void* left1 = colDataGet(pLeftColInfoData, pLeftSource->rowIndex);
void* right1 = colDataGet(pRightColInfoData, pSources[pRightIdx]->rowIndex); void* right1 = colDataGet(pRightColInfoData, pRightSource->rowIndex);
switch(pLeftColInfoData->info.type) { switch(pLeftColInfoData->info.type) {
case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_INT: {
if (*(int32_t*) left1 == *(int32_t*) right1) { int32_t leftv = *(int32_t*)left1;
int32_t rightv = *(int32_t*)right1;
if (leftv == rightv) {
break; break;
} else { } else {
if (pOrder->order == TSDB_ORDER_ASC) { if (pOrder->order == TSDB_ORDER_ASC) {
return *(int32_t*) left1 <= *(int32_t*) right1? -1:1; return leftv < rightv? -1 : 1;
} else { } else {
return *(int32_t*) left1 <= *(int32_t*) right1? 1:-1; return leftv < rightv? 1 : -1;
} }
} }
}
default: default:
assert(0); assert(0);
} }
...@@ -5634,7 +5646,7 @@ static int32_t adjustMergeTreeForNextTuple(SExternalMemSource *pSource, SMultiwa ...@@ -5634,7 +5646,7 @@ static int32_t adjustMergeTreeForNextTuple(SExternalMemSource *pSource, SMultiwa
* Adjust loser tree otherwise, according to new candidate data * Adjust loser tree otherwise, according to new candidate data
* if the loser tree is rebuild completed, we do not need to adjust * if the loser tree is rebuild completed, we do not need to adjust
*/ */
int32_t leafNodeIndex = tMergeTreeAdjustIndex(pTree); int32_t leafNodeIndex = tMergeTreeGetAdjustIndex(pTree);
#ifdef _DEBUG_VIEW #ifdef _DEBUG_VIEW
printf("before adjust:\t"); printf("before adjust:\t");
......
...@@ -262,6 +262,9 @@ TEST(testCase, external_sort_Test) { ...@@ -262,6 +262,9 @@ TEST(testCase, external_sort_Test) {
int32_t total = 1; int32_t total = 1;
int64_t s1 = taosGetTimestampUs();
while(1) { while(1) {
int64_t s = taosGetTimestampUs(); int64_t s = taosGetTimestampUs();
pRes = pOperator->exec(pOperator, &newgroup); pRes = pOperator->exec(pOperator, &newgroup);
...@@ -281,6 +284,10 @@ TEST(testCase, external_sort_Test) { ...@@ -281,6 +284,10 @@ TEST(testCase, external_sort_Test) {
// } // }
} }
int64_t s2 = taosGetTimestampUs();
printf("total:%ld\n", s2 - s1);
pOperator->cleanupFn(pOperator->info, 2); pOperator->cleanupFn(pOperator->info, 2);
tfree(exp); tfree(exp);
tfree(exp1); tfree(exp1);
......
...@@ -18,10 +18,7 @@ ...@@ -18,10 +18,7 @@
#include "tlosertree.h" #include "tlosertree.h"
#include "taoserror.h" #include "taoserror.h"
typedef struct STreeNode {
int32_t index;
void *pData; // TODO remove it?
} STreeNode;
// Set the initial value of the multiway merge tree. // Set the initial value of the multiway merge tree.
static void tMergeTreeInit(SMultiwayMergeTreeInfo* pTree) { static void tMergeTreeInit(SMultiwayMergeTreeInfo* pTree) {
...@@ -137,11 +134,3 @@ void tMergeTreePrint(const SMultiwayMergeTreeInfo* pTree) { ...@@ -137,11 +134,3 @@ void tMergeTreePrint(const SMultiwayMergeTreeInfo* pTree) {
printf("\n"); printf("\n");
} }
int32_t tMergeTreeGetChosenIndex(const SMultiwayMergeTreeInfo* pTree) {
return pTree->pNode[0].index;
}
int32_t tMergeTreeAdjustIndex(const SMultiwayMergeTreeInfo* pTree) {
return tMergeTreeGetChosenIndex(pTree) + pTree->numOfSources;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册