提交 803762c4 编写于 作者: H Haojun Liao

enh(query): avoid repeatly load del file.

上级 392fe988
......@@ -170,7 +170,9 @@ struct STsdbReader {
SIOCostSummary cost;
STSchema* pSchema; // the newest version schema
STSchema* pMemSchema; // the previous schema for in-memory data, to avoid load schema too many times
SDataFReader* pFileReader;
SDataFReader* pFileReader; // the file reader
SDelFReader* pDelFReader; // the del file reader
SArray* pDelIdx; // del file block index;
SVersionRange verRange;
SBlockInfoBuf blockInfoBuf;
int32_t step;
......@@ -2531,42 +2533,17 @@ int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader*
}
int32_t code = 0;
STsdb* pTsdb = pReader->pTsdb;
SArray* pDelData = taosArrayInit(4, sizeof(SDelData));
SDelFile* pDelFile = pReader->pReadSnap->fs.pDelFile;
if (pDelFile) {
SDelFReader* pDelFReader = NULL;
code = tsdbDelFReaderOpen(&pDelFReader, pDelFile, pTsdb);
if (code != TSDB_CODE_SUCCESS) {
goto _err;
}
SArray* aDelIdx = taosArrayInit(4, sizeof(SDelIdx));
if (aDelIdx == NULL) {
tsdbDelFReaderClose(&pDelFReader);
goto _err;
}
// TODO: opt the perf of read del index
code = tsdbReadDelIdx(pDelFReader, aDelIdx);
if (code != TSDB_CODE_SUCCESS) {
taosArrayDestroy(aDelIdx);
tsdbDelFReaderClose(&pDelFReader);
goto _err;
}
if (pDelFile && taosArrayGetSize(pReader->pDelIdx) > 0) {
SDelIdx idx = {.suid = pReader->suid, .uid = pBlockScanInfo->uid};
SDelIdx* pIdx = taosArraySearch(aDelIdx, &idx, tCmprDelIdx, TD_EQ);
SDelIdx* pIdx = taosArraySearch(pReader->pDelIdx, &idx, tCmprDelIdx, TD_EQ);
if (pIdx != NULL) {
code = tsdbReadDelData(pDelFReader, pIdx, pDelData);
code = tsdbReadDelData(pReader->pDelFReader, pIdx, pDelData);
}
taosArrayDestroy(aDelIdx);
tsdbDelFReaderClose(&pDelFReader);
if (code != TSDB_CODE_SUCCESS) {
goto _err;
}
......@@ -2662,6 +2639,27 @@ static int32_t moveToNextFile(STsdbReader* pReader, SBlockNumber* pBlockNum) {
}
taosArrayDestroy(pIndexList);
SDelFile* pDelFile = pReader->pReadSnap->fs.pDelFile;
if (pReader->pDelFReader == NULL && pDelFile != NULL) {
int32_t code = tsdbDelFReaderOpen(&pReader->pDelFReader, pDelFile, pReader->pTsdb);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
pReader->pDelIdx = taosArrayInit(4, sizeof(SDelIdx));
if (pReader->pDelIdx == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
return code;
}
code = tsdbReadDelIdx(pReader->pDelFReader, pReader->pDelIdx);
if (code != TSDB_CODE_SUCCESS) {
taosArrayDestroy(pReader->pDelIdx);
return code;
}
}
return TSDB_CODE_SUCCESS;
}
......@@ -3912,6 +3910,15 @@ void tsdbReaderClose(STsdbReader* pReader) {
tsdbDataFReaderClose(&pReader->pFileReader);
}
if (pReader->pDelFReader != NULL) {
tsdbDelFReaderClose(&pReader->pDelFReader);
}
if (pReader->pDelIdx != NULL) {
taosArrayDestroy(pReader->pDelIdx);
pReader->pDelIdx = NULL;
}
tsdbUntakeReadSnap(pReader->pTsdb, pReader->pReadSnap, pReader->idStr);
taosMemoryFree(pReader->status.uidCheckInfo.tableUidList);
......
......@@ -1477,9 +1477,8 @@ int32_t tsdbDelFReaderClose(SDelFReader **ppReader) {
}
taosMemoryFree(pReader);
}
*ppReader = NULL;
_exit:
*ppReader = NULL;
return code;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册