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

[td-11818] opt perf.

上级 ec4e6fe7
......@@ -22,6 +22,11 @@ extern "C" {
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 {
int32_t numOfSources;
int32_t totalSources;
......@@ -30,6 +35,9 @@ typedef struct SMultiwayMergeTreeInfo {
struct STreeNode *pNode;
} 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);
void tMergeTreeDestroy(SMultiwayMergeTreeInfo* pTree);
......@@ -40,10 +48,6 @@ void tMergeTreeRebuild(SMultiwayMergeTreeInfo *pTree);
void tMergeTreePrint(const SMultiwayMergeTreeInfo *pTree);
int32_t tMergeTreeGetChosenIndex(const SMultiwayMergeTreeInfo* pTree);
int32_t tMergeTreeAdjustIndex(const SMultiwayMergeTreeInfo* pTree);
#ifdef __cplusplus
}
#endif
......
......@@ -2192,7 +2192,7 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu
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
}
}
tMergeTreeAdjust(pTree, tMergeTreeAdjustIndex(pTree));
tMergeTreeAdjust(pTree, tMergeTreeGetAdjustIndex(pTree));
}
int64_t endt = taosGetTimestampMs();
......
......@@ -5548,31 +5548,39 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) {
int32_t pRightIdx = *(int32_t *)pRight;
SMsortComparParam *pParam = (SMsortComparParam *)param;
SExternalMemSource **pSources = pParam->pSources;
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
if (pSources[pLeftIdx]->rowIndex == -1) {
if (pLeftSource->rowIndex == -1) {
return 1;
}
if (pSources[pRightIdx]->rowIndex == -1) {
if (pRightSource->rowIndex == -1) {
return -1;
}
SSDataBlock* pLeftBlock = pSources[pLeftIdx]->pBlock;
SSDataBlock* pRightBlock = pSources[pRightIdx]->pBlock;
SSDataBlock* pLeftBlock = pLeftSource->pBlock;
SSDataBlock* pRightBlock = pRightSource->pBlock;
size_t num = taosArrayGetSize(pInfo);
for(int32_t i = 0; i < num; ++i) {
SBlockOrderInfo* pOrder = taosArrayGet(pInfo, i);
for(int32_t i = 0; i < pInfo->size; ++i) {
SBlockOrderInfo* pOrder = TARRAY_GET_ELEM(pInfo, i);
SColumnInfoData* pLeftColInfoData = taosArrayGet(pLeftBlock->pDataBlock, pOrder->colIndex);
bool leftNull = colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pSources[pLeftIdx]->rowIndex, pLeftBlock->pBlockAgg);
SColumnInfoData* pLeftColInfoData = TARRAY_GET_ELEM(pLeftBlock->pDataBlock, pOrder->colIndex);
SColumnInfoData* pRightColInfoData = taosArrayGet(pRightBlock->pDataBlock, pOrder->colIndex);
bool rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pSources[pRightIdx]->rowIndex, pRightBlock->pBlockAgg);
bool leftNull = false;
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) {
continue; // continue to next slot
......@@ -5586,20 +5594,24 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) {
return pParam->nullFirst? -1:1;
}
void* left1 = colDataGet(pLeftColInfoData, pSources[pLeftIdx]->rowIndex);
void* right1 = colDataGet(pRightColInfoData, pSources[pRightIdx]->rowIndex);
void* left1 = colDataGet(pLeftColInfoData, pLeftSource->rowIndex);
void* right1 = colDataGet(pRightColInfoData, pRightSource->rowIndex);
switch(pLeftColInfoData->info.type) {
case TSDB_DATA_TYPE_INT:
if (*(int32_t*) left1 == *(int32_t*) right1) {
case TSDB_DATA_TYPE_INT: {
int32_t leftv = *(int32_t*)left1;
int32_t rightv = *(int32_t*)right1;
if (leftv == rightv) {
break;
} else {
if (pOrder->order == TSDB_ORDER_ASC) {
return *(int32_t*) left1 <= *(int32_t*) right1? -1:1;
return leftv < rightv? -1 : 1;
} else {
return *(int32_t*) left1 <= *(int32_t*) right1? 1:-1;
return leftv < rightv? 1 : -1;
}
}
}
default:
assert(0);
}
......@@ -5634,7 +5646,7 @@ static int32_t adjustMergeTreeForNextTuple(SExternalMemSource *pSource, SMultiwa
* Adjust loser tree otherwise, according to new candidate data
* 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
printf("before adjust:\t");
......
......@@ -262,6 +262,9 @@ TEST(testCase, external_sort_Test) {
int32_t total = 1;
int64_t s1 = taosGetTimestampUs();
while(1) {
int64_t s = taosGetTimestampUs();
pRes = pOperator->exec(pOperator, &newgroup);
......@@ -281,6 +284,10 @@ TEST(testCase, external_sort_Test) {
// }
}
int64_t s2 = taosGetTimestampUs();
printf("total:%ld\n", s2 - s1);
pOperator->cleanupFn(pOperator->info, 2);
tfree(exp);
tfree(exp1);
......
......@@ -18,10 +18,7 @@
#include "tlosertree.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.
static void tMergeTreeInit(SMultiwayMergeTreeInfo* pTree) {
......@@ -137,11 +134,3 @@ void tMergeTreePrint(const SMultiwayMergeTreeInfo* pTree) {
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.
先完成此消息的编辑!
想要评论请 注册