提交 74223b34 编写于 作者: H Hongze Cheng

more optimize

上级 057af11a
......@@ -1015,6 +1015,182 @@ _err:
return code;
}
static int32_t tBlockDataAppendBlockRow(SBlockData *pBlockData, SBlockData *pBlockDataFrom, int32_t iRow) {
int32_t code = 0;
SColVal cv = {0};
int32_t iColDataFrom = 0;
SColData *pColDataFrom =
(iColDataFrom < pBlockDataFrom->nColData) ? &((SColData *)pBlockDataFrom->aColData->pData)[iColDataFrom] : NULL;
for (int32_t iColDataTo = 0; iColDataTo < pBlockData->nColData; iColDataTo++) {
SColData *pColDataTo = &((SColData *)pBlockData->aColData->pData)[iColDataTo];
while (pColDataFrom && pColDataFrom->cid < pColDataTo->cid) {
iColDataFrom++;
pColDataFrom = (iColDataFrom < pBlockDataFrom->nColData)
? &((SColData *)pBlockDataFrom->aColData->pData)[iColDataFrom]
: NULL;
}
if (pColDataFrom == NULL || pColDataFrom->cid > pColDataTo->cid) {
code = tColDataAppendValue(pColDataTo, &COL_VAL_NONE(pColDataTo->cid, pColDataTo->type));
if (code) goto _exit;
} else {
tColDataGetValue(pColDataFrom, iRow, &cv);
code = tColDataAppendValue(pColDataTo, &cv);
if (code) goto _exit;
iColDataFrom++;
pColDataFrom = (iColDataFrom < pBlockDataFrom->nColData)
? &((SColData *)pBlockDataFrom->aColData->pData)[iColDataFrom]
: NULL;
}
}
_exit:
return code;
}
static int32_t tBlockDataAppendTPRow(SBlockData *pBlockData, STSRow *pRow, STSchema *pTSchema) {
int32_t code = 0;
int32_t iTColumn = 1;
STColumn *pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
SColData *pColData = &((SColData *)pBlockData->aColData->pData)[iColData];
while (pTColumn && pTColumn->colId < pColData->cid) {
iTColumn++;
pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
}
if (pTColumn == NULL || pTColumn->colId > pColData->cid) {
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
if (code) goto _exit;
} else {
ASSERT(pTColumn->type == pColData->type);
SColVal cv = {.cid = pTColumn->colId, .type = pTColumn->type};
if (pRow->statis) {
TDRowValT vt;
tdGetBitmapValTypeII(tdGetBitmapAddrTp(pRow, pTSchema->flen), iTColumn - 1, &vt);
if (vt == TD_VTYPE_NORM) {
cv.flag = CV_FLAG_VALUE;
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
void *pData = pRow->data + *(int32_t *)(pRow->data + pTColumn->offset - sizeof(TSKEY));
cv.value.nData = varDataLen(pData);
cv.value.pData = varDataVal(pData);
} else {
memcpy(&cv.value.val, pRow->data + pTColumn->offset - sizeof(TSKEY), pTColumn->bytes);
}
code = tColDataAppendValue(pColData, &cv);
if (code) goto _exit;
} else if (vt == TD_VTYPE_NONE) {
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
if (code) goto _exit;
} else if (vt == TD_VTYPE_NULL) {
code = tColDataAppendValue(pColData, &COL_VAL_NULL(pColData->cid, pColData->type));
if (code) goto _exit;
} else {
ASSERT(0);
}
} else {
cv.flag = CV_FLAG_VALUE;
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
void *pData = pRow->data + *(int32_t *)(pRow->data + pTColumn->offset - sizeof(TSKEY));
cv.value.nData = varDataLen(pData);
cv.value.pData = varDataVal(pData);
} else {
memcpy(&cv.value.val, pRow->data + pTColumn->offset - sizeof(TSKEY), pTColumn->bytes);
}
code = tColDataAppendValue(pColData, &cv);
if (code) goto _exit;
}
iTColumn++;
pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
}
}
_exit:
return code;
}
static int32_t tBlockDataAppendKVRow(SBlockData *pBlockData, STSRow *pRow, STSchema *pTSchema) {
int32_t code = 0;
int32_t iTColumn = 1;
STColumn *pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
SColData *pColData = &((SColData *)pBlockData->aColData->pData)[iColData];
while (pTColumn && pTColumn->colId < pColData->cid) {
iTColumn++;
pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
}
if (pTColumn == NULL || pTColumn->colId > pColData->cid) {
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
if (code) goto _exit;
} else {
ASSERT(pTColumn->type == pColData->type);
// SColVal cv = {.cid = pTColumn->colId, .type = pTColumn->type};
// if (pRow->statis) {
// TDRowValT vt;
// tdGetBitmapValTypeII(tdGetBitmapAddrTp(pRow, pTSchema->flen), iTColumn - 1, &vt);
// if (vt == TD_VTYPE_NORM) {
// cv.flag = CV_FLAG_VALUE;
// if (IS_VAR_DATA_TYPE(pTColumn->type)) {
// void *pData = pRow->data + *(int32_t *)(pRow->data + pTColumn->offset);
// cv.value.nData = varDataLen(pData);
// cv.value.pData = varDataVal(pData);
// } else {
// memcpy(&cv.value.val, pRow->data + pTColumn->offset, pTColumn->bytes);
// }
// code = tColDataAppendValue(pColData, &cv);
// if (code) goto _exit;
// } else if (vt == TD_VTYPE_NONE) {
// code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
// if (code) goto _exit;
// } else if (vt == TD_VTYPE_NULL) {
// code = tColDataAppendValue(pColData, &COL_VAL_NULL(pColData->cid, pColData->type));
// if (code) goto _exit;
// } else {
// ASSERT(0);
// }
// } else {
// cv.flag = CV_FLAG_VALUE;
// if (IS_VAR_DATA_TYPE(pTColumn->type)) {
// void *pData = pRow->data + *(int32_t *)(pRow->data + pTColumn->offset);
// cv.value.nData = varDataLen(pData);
// cv.value.pData = varDataVal(pData);
// } else {
// memcpy(&cv.value.val, pRow->data + pTColumn->offset, pT
// }
// }
}
}
_exit:
return code;
}
int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema, int64_t uid) {
int32_t code = 0;
......@@ -1036,27 +1212,20 @@ int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS
if (code) goto _err;
pBlockData->aTSKEY[pBlockData->nRow] = TSDBROW_TS(pRow);
// OTHER
SRowIter rIter = {0};
SColVal *pColVal;
tRowIterInit(&rIter, pRow, pTSchema);
pColVal = tRowIterNext(&rIter);
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
SColData *pColData = &((SColData *)pBlockData->aColData->pData)[iColData];
while (pColVal && pColVal->cid < pColData->cid) {
pColVal = tRowIterNext(&rIter);
}
if (pColVal == NULL || pColVal->cid > pColData->cid) {
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
SColVal cv = {0};
if (pRow->type == 0) {
if (TD_IS_TP_ROW(pRow->pTSRow)) {
code = tBlockDataAppendTPRow(pBlockData, pRow->pTSRow, pTSchema);
if (code) goto _err;
} else {
code = tColDataAppendValue(pColData, pColVal);
} else if (TD_IS_KV_ROW(pRow->pTSRow)) {
code = tBlockDataAppendKVRow(pBlockData, pRow->pTSRow, pTSchema);
if (code) goto _err;
pColVal = tRowIterNext(&rIter);
} else {
ASSERT(0);
}
} else {
code = tBlockDataAppendBlockRow(pBlockData, pRow->pBlockData, pRow->iRow);
if (code) goto _err;
}
pBlockData->nRow++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册