fix(query): opt filter perf.

This commit is contained in:
Haojun Liao 2023-01-03 22:45:02 +08:00
parent 5c0fd80195
commit 00c2d382b1
2 changed files with 105 additions and 89 deletions

View File

@ -111,7 +111,7 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
uint32_t len = pColumnInfoData->varmeta.length; uint32_t len = pColumnInfoData->varmeta.length;
pColumnInfoData->varmeta.offset[currentRow] = len; pColumnInfoData->varmeta.offset[currentRow] = len;
memcpy(pColumnInfoData->pData + len, pData, dataLen); memmove(pColumnInfoData->pData + len, pData, dataLen);
pColumnInfoData->varmeta.length += dataLen; pColumnInfoData->varmeta.length += dataLen;
} else { } else {
memcpy(pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow, pData, pColumnInfoData->info.bytes); memcpy(pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow, pData, pColumnInfoData->info.bytes);

View File

@ -847,7 +847,7 @@ void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoD
return; return;
} }
int8_t* pIndicator = p->pData; int8_t* pIndicator = (int8_t*)p->pData;
int32_t totalRows = pBlock->info.rows; int32_t totalRows = pBlock->info.rows;
if (status == FILTER_RESULT_ALL_QUALIFIED) { if (status == FILTER_RESULT_ALL_QUALIFIED) {
@ -857,6 +857,7 @@ void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoD
} else { } else {
int32_t bmLen = BitmapLen(totalRows); int32_t bmLen = BitmapLen(totalRows);
char* pBitmap = NULL; char* pBitmap = NULL;
int32_t maxRows = 0;
size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
for (int32_t i = 0; i < numOfCols; ++i) { for (int32_t i = 0; i < numOfCols; ++i) {
@ -868,14 +869,31 @@ void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoD
int32_t numOfRows = 0; int32_t numOfRows = 0;
switch (pDst->info.type) { if (IS_VAR_DATA_TYPE(pDst->info.type)) {
case TSDB_DATA_TYPE_VARCHAR: int32_t j = 0;
case TSDB_DATA_TYPE_NCHAR: while(j < totalRows) {
break; if (pIndicator[j] == 0) {
default: continue;
}
if (colDataIsNull_var(pDst, j)) {
colDataSetNull_var(pDst, numOfRows);
} else {
char* p1 = colDataGetVarData(pDst, j);
colDataAppend(pDst, numOfRows, p1, false);
}
numOfRows += 1;
j += 1;
}
if (maxRows < numOfRows) {
maxRows = numOfRows;
}
} else {
if (pBitmap == NULL) { if (pBitmap == NULL) {
pBitmap = taosMemoryCalloc(1, bmLen); pBitmap = taosMemoryCalloc(1, bmLen);
} }
memcpy(pBitmap, pDst->nullbitmap, bmLen); memcpy(pBitmap, pDst->nullbitmap, bmLen);
memset(pDst->nullbitmap, 0, bmLen); memset(pDst->nullbitmap, 0, bmLen);
@ -893,7 +911,7 @@ void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoD
} }
if (colDataIsNull_f(pBitmap, j)) { if (colDataIsNull_f(pBitmap, j)) {
colDataAppendNULL(pDst, numOfRows); colDataSetNull_f(pDst->nullbitmap, numOfRows);
} else { } else {
((int64_t*)pDst->pData)[numOfRows] = ((int64_t*)pDst->pData)[j]; ((int64_t*)pDst->pData)[numOfRows] = ((int64_t*)pDst->pData)[j];
} }
@ -910,7 +928,7 @@ void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoD
continue; continue;
} }
if (colDataIsNull_f(pBitmap, j)) { if (colDataIsNull_f(pBitmap, j)) {
colDataAppendNULL(pDst, numOfRows); colDataSetNull_f(pDst->nullbitmap, numOfRows);
} else { } else {
((int32_t*)pDst->pData)[numOfRows++] = ((int32_t*)pDst->pData)[j]; ((int32_t*)pDst->pData)[numOfRows++] = ((int32_t*)pDst->pData)[j];
} }
@ -926,7 +944,7 @@ void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoD
continue; continue;
} }
if (colDataIsNull_f(pBitmap, j)) { if (colDataIsNull_f(pBitmap, j)) {
colDataAppendNULL(pDst, numOfRows); colDataSetNull_f(pDst->nullbitmap, numOfRows);
} else { } else {
((int16_t*)pDst->pData)[numOfRows++] = ((int16_t*)pDst->pData)[j]; ((int16_t*)pDst->pData)[numOfRows++] = ((int16_t*)pDst->pData)[j];
} }
@ -943,7 +961,7 @@ void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoD
continue; continue;
} }
if (colDataIsNull_f(pBitmap, j)) { if (colDataIsNull_f(pBitmap, j)) {
colDataAppendNULL(pDst, numOfRows); colDataSetNull_f(pDst->nullbitmap, numOfRows);
} else { } else {
((int8_t*)pDst->pData)[numOfRows] = ((int8_t*)pDst->pData)[j]; ((int8_t*)pDst->pData)[numOfRows] = ((int8_t*)pDst->pData)[j];
} }
@ -952,16 +970,14 @@ void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoD
} }
break; break;
} }
}; }
// todo this value can be assigned directly if (maxRows < numOfRows) {
if (pBlock->info.rows == totalRows) { maxRows = numOfRows;
pBlock->info.rows = numOfRows;
} else {
ASSERT(pBlock->info.rows == numOfRows);
} }
} }
pBlock->info.rows = maxRows;
if (pBitmap != NULL) { if (pBitmap != NULL) {
taosMemoryFree(pBitmap); taosMemoryFree(pBitmap);
} }