2022-06-21 08:29:19 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can use, redistribute, and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3
|
|
|
|
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-01-14 05:44:40 +00:00
|
|
|
#include "functionMgt.h"
|
2022-06-21 08:29:19 +00:00
|
|
|
#include "taoserror.h"
|
|
|
|
|
#include "tarray.h"
|
|
|
|
|
#include "tcommon.h"
|
|
|
|
|
#include "tsdb.h"
|
2023-07-20 01:11:26 +00:00
|
|
|
#include "tsdbDataFileRW.h"
|
2023-08-01 10:56:10 +00:00
|
|
|
#include "tsdbReadUtil.h"
|
2022-06-21 08:29:19 +00:00
|
|
|
|
2022-10-25 02:36:30 +00:00
|
|
|
#define HASTYPE(_type, _t) (((_type) & (_t)) == (_t))
|
2022-10-19 07:43:58 +00:00
|
|
|
|
2024-07-23 06:47:29 +00:00
|
|
|
static int32_t setFirstLastResColToNull(SColumnInfoData* pCol, int32_t row) {
|
|
|
|
|
char* buf = taosMemoryCalloc(1, pCol->info.bytes);
|
|
|
|
|
if (buf == NULL) {
|
2024-08-27 09:37:01 +00:00
|
|
|
return terrno;
|
2024-07-23 06:47:29 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-05 06:16:01 +00:00
|
|
|
SFirstLastRes* pRes = (SFirstLastRes*)((char*)buf + VARSTR_HEADER_SIZE);
|
|
|
|
|
pRes->bytes = 0;
|
|
|
|
|
pRes->hasResult = true;
|
|
|
|
|
pRes->isNull = true;
|
|
|
|
|
varDataSetLen(buf, pCol->info.bytes - VARSTR_HEADER_SIZE);
|
2024-07-23 06:47:29 +00:00
|
|
|
int32_t code = colDataSetVal(pCol, row, buf, false);
|
2023-12-05 06:16:01 +00:00
|
|
|
taosMemoryFree(buf);
|
2024-07-23 06:47:29 +00:00
|
|
|
|
|
|
|
|
return code;
|
2023-12-05 06:16:01 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-23 06:47:29 +00:00
|
|
|
static int32_t saveOneRowForLastRaw(SLastCol* pColVal, SCacheRowsReader* pReader, const int32_t slotId,
|
2024-01-14 05:44:40 +00:00
|
|
|
SColumnInfoData* pColInfoData, int32_t numOfRows) {
|
2024-03-08 05:14:54 +00:00
|
|
|
SColVal* pVal = &pColVal->colVal;
|
2024-07-23 06:47:29 +00:00
|
|
|
int32_t code = 0;
|
2024-01-14 05:44:40 +00:00
|
|
|
|
|
|
|
|
// allNullRow = false;
|
2024-02-21 06:29:10 +00:00
|
|
|
if (IS_VAR_DATA_TYPE(pColVal->colVal.value.type)) {
|
2024-01-14 05:44:40 +00:00
|
|
|
if (!COL_VAL_IS_VALUE(&pColVal->colVal)) {
|
|
|
|
|
colDataSetNULL(pColInfoData, numOfRows);
|
|
|
|
|
} else {
|
|
|
|
|
varDataSetLen(pReader->transferBuf[slotId], pVal->value.nData);
|
|
|
|
|
|
|
|
|
|
memcpy(varDataVal(pReader->transferBuf[slotId]), pVal->value.pData, pVal->value.nData);
|
2024-07-23 06:47:29 +00:00
|
|
|
code = colDataSetVal(pColInfoData, numOfRows, pReader->transferBuf[slotId], false);
|
2024-01-14 05:44:40 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2024-07-23 06:47:29 +00:00
|
|
|
code = colDataSetVal(pColInfoData, numOfRows, (const char*)&pVal->value.val, !COL_VAL_IS_VALUE(pVal));
|
2024-01-14 05:44:40 +00:00
|
|
|
}
|
2024-07-23 06:47:29 +00:00
|
|
|
|
|
|
|
|
return code;
|
2024-01-14 05:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-23 09:45:12 +00:00
|
|
|
static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* pReader, const int32_t* slotIds,
|
2023-04-20 08:26:27 +00:00
|
|
|
const int32_t* dstSlotIds, void** pRes, const char* idStr) {
|
2022-06-28 15:24:20 +00:00
|
|
|
int32_t numOfRows = pBlock->info.rows;
|
2024-07-23 06:47:29 +00:00
|
|
|
int32_t code = 0;
|
2022-06-28 15:24:20 +00:00
|
|
|
|
2022-10-19 07:43:58 +00:00
|
|
|
if (HASTYPE(pReader->type, CACHESCAN_RETRIEVE_LAST)) {
|
2024-03-08 05:14:54 +00:00
|
|
|
uint64_t ts = TSKEY_MIN;
|
2023-12-05 06:16:01 +00:00
|
|
|
SFirstLastRes* p = NULL;
|
2024-03-08 05:14:54 +00:00
|
|
|
col_id_t colId = -1;
|
2024-01-14 05:44:40 +00:00
|
|
|
|
|
|
|
|
SArray* funcTypeBlockArray = taosArrayInit(pReader->numOfCols, sizeof(int32_t));
|
2024-07-23 06:47:29 +00:00
|
|
|
if (funcTypeBlockArray == NULL) {
|
|
|
|
|
return TSDB_CODE_OUT_OF_MEMORY;
|
|
|
|
|
}
|
2024-04-25 15:25:24 +00:00
|
|
|
|
2022-10-18 09:39:28 +00:00
|
|
|
for (int32_t i = 0; i < pReader->numOfCols; ++i) {
|
2023-04-20 08:26:27 +00:00
|
|
|
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotIds[i]);
|
2024-07-23 06:47:29 +00:00
|
|
|
if (pColInfoData == NULL) {
|
|
|
|
|
return TSDB_CODE_INVALID_PARA;
|
|
|
|
|
}
|
2024-04-25 15:25:24 +00:00
|
|
|
|
2024-07-23 06:47:29 +00:00
|
|
|
int32_t funcType = FUNCTION_TYPE_CACHE_LAST;
|
2024-01-14 05:44:40 +00:00
|
|
|
if (pReader->pFuncTypeList != NULL && taosArrayGetSize(pReader->pFuncTypeList) > i) {
|
2024-07-23 06:47:29 +00:00
|
|
|
void* pVal = taosArrayGet(pReader->pFuncTypeList, i);
|
|
|
|
|
if (pVal == NULL) {
|
|
|
|
|
return TSDB_CODE_INVALID_PARA;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 11:16:06 +00:00
|
|
|
funcType = *(int32_t*) pVal;
|
2024-07-23 06:47:29 +00:00
|
|
|
pVal = taosArrayGet(pReader->pFuncTypeList, i);
|
|
|
|
|
if (pVal == NULL) {
|
|
|
|
|
return TSDB_CODE_INVALID_PARA;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void* px = taosArrayInsert(funcTypeBlockArray, dstSlotIds[i], pVal);
|
|
|
|
|
if (px == NULL) {
|
|
|
|
|
return TSDB_CODE_OUT_OF_MEMORY;
|
|
|
|
|
}
|
2024-01-14 05:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-05 06:16:01 +00:00
|
|
|
if (slotIds[i] == -1) {
|
2024-01-14 05:44:40 +00:00
|
|
|
if (FUNCTION_TYPE_CACHE_LAST_ROW == funcType) {
|
|
|
|
|
colDataSetNULL(pColInfoData, numOfRows);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-07-23 06:47:29 +00:00
|
|
|
|
|
|
|
|
code = setFirstLastResColToNull(pColInfoData, numOfRows);
|
|
|
|
|
if (code) {
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2023-12-05 06:16:01 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2024-07-23 06:47:29 +00:00
|
|
|
|
2023-12-05 06:16:01 +00:00
|
|
|
int32_t slotId = slotIds[i];
|
|
|
|
|
SLastCol* pColVal = (SLastCol*)taosArrayGet(pRow, i);
|
2024-07-23 06:47:29 +00:00
|
|
|
if (pColVal == NULL) {
|
|
|
|
|
return TSDB_CODE_INVALID_PARA;
|
|
|
|
|
}
|
2024-01-14 05:44:40 +00:00
|
|
|
|
2024-07-23 06:47:29 +00:00
|
|
|
colId = pColVal->colVal.cid;
|
2024-01-14 05:44:40 +00:00
|
|
|
if (FUNCTION_TYPE_CACHE_LAST_ROW == funcType) {
|
2024-07-23 06:47:29 +00:00
|
|
|
code = saveOneRowForLastRaw(pColVal, pReader, slotId, pColInfoData, numOfRows);
|
|
|
|
|
if (code) {
|
|
|
|
|
return code;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-14 05:44:40 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-03 08:22:09 +00:00
|
|
|
p = (SFirstLastRes*)varDataVal(pRes[i]);
|
2022-06-21 08:29:19 +00:00
|
|
|
|
2024-04-03 01:38:04 +00:00
|
|
|
p->ts = pColVal->rowKey.ts;
|
2023-11-03 08:22:09 +00:00
|
|
|
ts = p->ts;
|
2023-04-20 08:26:27 +00:00
|
|
|
p->isNull = !COL_VAL_IS_VALUE(&pColVal->colVal);
|
2023-08-29 08:15:00 +00:00
|
|
|
// allNullRow = p->isNull & allNullRow;
|
2023-04-20 08:26:27 +00:00
|
|
|
if (!p->isNull) {
|
2024-02-21 06:29:10 +00:00
|
|
|
if (IS_VAR_DATA_TYPE(pColVal->colVal.value.type)) {
|
2023-04-20 08:26:27 +00:00
|
|
|
varDataSetLen(p->buf, pColVal->colVal.value.nData);
|
2022-10-24 05:26:54 +00:00
|
|
|
|
2023-04-20 08:26:27 +00:00
|
|
|
memcpy(varDataVal(p->buf), pColVal->colVal.value.pData, pColVal->colVal.value.nData);
|
|
|
|
|
p->bytes = pColVal->colVal.value.nData + VARSTR_HEADER_SIZE; // binary needs to plus the header size
|
|
|
|
|
} else {
|
2024-03-08 05:14:54 +00:00
|
|
|
memcpy(p->buf, &pColVal->colVal.value.val, pReader->pSchema->columns[slotId].bytes);
|
2023-04-20 08:26:27 +00:00
|
|
|
p->bytes = pReader->pSchema->columns[slotId].bytes;
|
2022-10-18 09:39:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-07-12 09:59:25 +00:00
|
|
|
|
2024-04-10 03:18:08 +00:00
|
|
|
// pColInfoData->info.bytes includes the VARSTR_HEADER_SIZE, need to subtract it
|
2022-10-18 09:39:28 +00:00
|
|
|
p->hasResult = true;
|
2022-10-19 07:43:58 +00:00
|
|
|
varDataSetLen(pRes[i], pColInfoData->info.bytes - VARSTR_HEADER_SIZE);
|
2024-07-23 06:47:29 +00:00
|
|
|
code = colDataSetVal(pColInfoData, numOfRows, (const char*)pRes[i], false);
|
|
|
|
|
if (code) {
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2022-10-18 09:39:28 +00:00
|
|
|
}
|
2024-04-10 03:18:08 +00:00
|
|
|
|
2023-11-03 08:22:09 +00:00
|
|
|
for (int32_t idx = 0; idx < taosArrayGetSize(pBlock->pDataBlock); ++idx) {
|
|
|
|
|
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, idx);
|
2024-07-23 06:47:29 +00:00
|
|
|
if (pCol == NULL) {
|
|
|
|
|
return TSDB_CODE_INVALID_PARA;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-14 05:44:40 +00:00
|
|
|
if (idx < funcTypeBlockArray->size) {
|
2024-07-23 06:47:29 +00:00
|
|
|
void* pVal = taosArrayGet(funcTypeBlockArray, idx);
|
|
|
|
|
if (pVal == NULL) {
|
|
|
|
|
return TSDB_CODE_INVALID_PARA;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t funcType = *(int32_t*)pVal;
|
2024-01-14 05:44:40 +00:00
|
|
|
if (FUNCTION_TYPE_CACHE_LAST_ROW == funcType) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-07 07:53:30 +00:00
|
|
|
if (pCol->info.colId == PRIMARYKEY_TIMESTAMP_COL_ID && pCol->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
|
2023-12-05 06:16:01 +00:00
|
|
|
if (ts == TSKEY_MIN) {
|
|
|
|
|
colDataSetNULL(pCol, numOfRows);
|
|
|
|
|
} else {
|
2024-07-23 06:47:29 +00:00
|
|
|
code = colDataSetVal(pCol, numOfRows, (const char*)&ts, false);
|
|
|
|
|
if (code) {
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2023-12-05 06:16:01 +00:00
|
|
|
}
|
2023-11-03 08:22:09 +00:00
|
|
|
continue;
|
2023-12-05 06:16:01 +00:00
|
|
|
} else if (pReader->numOfCols == 1 && idx != dstSlotIds[0] && (pCol->info.colId == colId || colId == -1)) {
|
|
|
|
|
if (p && !p->isNull) {
|
2024-07-23 06:47:29 +00:00
|
|
|
code = colDataSetVal(pCol, numOfRows, p->buf, false);
|
|
|
|
|
if (code) {
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2023-11-03 08:22:09 +00:00
|
|
|
} else {
|
|
|
|
|
colDataSetNULL(pCol, numOfRows);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-24 05:26:54 +00:00
|
|
|
|
2023-08-29 08:15:00 +00:00
|
|
|
// pBlock->info.rows += allNullRow ? 0 : 1;
|
|
|
|
|
++pBlock->info.rows;
|
2024-01-14 05:44:40 +00:00
|
|
|
taosArrayDestroy(funcTypeBlockArray);
|
2022-12-23 09:45:12 +00:00
|
|
|
} else if (HASTYPE(pReader->type, CACHESCAN_RETRIEVE_LAST_ROW)) {
|
2022-10-18 09:39:28 +00:00
|
|
|
for (int32_t i = 0; i < pReader->numOfCols; ++i) {
|
2023-04-21 06:18:04 +00:00
|
|
|
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotIds[i]);
|
2024-07-23 06:47:29 +00:00
|
|
|
if (pColInfoData == NULL) {
|
|
|
|
|
return TSDB_CODE_INVALID_PARA;
|
|
|
|
|
}
|
2022-10-18 09:39:28 +00:00
|
|
|
|
2024-03-08 05:14:54 +00:00
|
|
|
int32_t slotId = slotIds[i];
|
2023-12-05 06:16:01 +00:00
|
|
|
if (slotId == -1) {
|
|
|
|
|
colDataSetNULL(pColInfoData, numOfRows);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-07-23 06:47:29 +00:00
|
|
|
|
2023-04-21 06:18:04 +00:00
|
|
|
SLastCol* pColVal = (SLastCol*)taosArrayGet(pRow, i);
|
2024-07-23 06:47:29 +00:00
|
|
|
if (pColVal == NULL) {
|
|
|
|
|
return TSDB_CODE_INVALID_PARA;
|
|
|
|
|
}
|
2023-04-26 00:17:08 +00:00
|
|
|
|
2024-07-23 06:47:29 +00:00
|
|
|
code = saveOneRowForLastRaw(pColVal, pReader, slotId, pColInfoData, numOfRows);
|
|
|
|
|
if (code) {
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2022-06-28 15:24:20 +00:00
|
|
|
}
|
2022-06-21 08:29:19 +00:00
|
|
|
|
2023-08-29 08:15:00 +00:00
|
|
|
// pBlock->info.rows += allNullRow ? 0 : 1;
|
|
|
|
|
++pBlock->info.rows;
|
2022-12-23 09:45:12 +00:00
|
|
|
} else {
|
|
|
|
|
tsdbError("invalid retrieve type:%d, %s", pReader->type, idStr);
|
|
|
|
|
return TSDB_CODE_INVALID_PARA;
|
2022-10-24 05:26:54 +00:00
|
|
|
}
|
2022-12-23 09:45:12 +00:00
|
|
|
|
2024-07-23 06:47:29 +00:00
|
|
|
return code;
|
2022-06-21 08:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-10 11:06:23 +00:00
|
|
|
static int32_t setTableSchema(SCacheRowsReader* p, uint64_t suid, const char* idstr) {
|
|
|
|
|
int32_t numOfTables = p->numOfTables;
|
2024-09-06 06:16:58 +00:00
|
|
|
int32_t code = TSDB_CODE_SUCCESS;
|
2023-02-10 11:06:23 +00:00
|
|
|
|
|
|
|
|
if (suid != 0) {
|
2024-09-06 06:16:58 +00:00
|
|
|
code = metaGetTbTSchemaNotNull(p->pVnode->pMeta, suid, -1, 1, &p->pSchema);
|
|
|
|
|
if (TSDB_CODE_SUCCESS != code) {
|
2023-02-10 11:06:23 +00:00
|
|
|
tsdbWarn("stable:%" PRIu64 " has been dropped, failed to retrieve cached rows, %s", suid, idstr);
|
2024-09-09 02:21:57 +00:00
|
|
|
if(code != TSDB_CODE_OUT_OF_MEMORY) {
|
|
|
|
|
return TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
|
|
|
|
} else {
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2023-02-10 11:06:23 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (int32_t i = 0; i < numOfTables; ++i) {
|
|
|
|
|
uint64_t uid = p->pTableList[i].uid;
|
2024-09-06 06:16:58 +00:00
|
|
|
code = metaGetTbTSchemaMaybeNull(p->pVnode->pMeta, uid, -1, 1, &p->pSchema);
|
|
|
|
|
if(code != TSDB_CODE_SUCCESS) {
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2023-02-10 11:06:23 +00:00
|
|
|
if (p->pSchema != NULL) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tsdbWarn("table:%" PRIu64 " has been dropped, failed to retrieve cached rows, %s", uid, idstr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// all queried tables have been dropped already, return immediately.
|
|
|
|
|
if (p->pSchema == NULL) {
|
|
|
|
|
tsdbWarn("all queried tables has been dropped, try next group, %s", idstr);
|
|
|
|
|
return TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TSDB_CODE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-14 06:30:20 +00:00
|
|
|
int32_t tsdbReuseCacherowsReader(void* reader, void* pTableIdList, int32_t numOfTables) {
|
|
|
|
|
SCacheRowsReader* pReader = (SCacheRowsReader*)reader;
|
|
|
|
|
|
|
|
|
|
pReader->pTableList = pTableIdList;
|
|
|
|
|
pReader->numOfTables = numOfTables;
|
|
|
|
|
pReader->lastTs = INT64_MIN;
|
2024-07-15 15:53:12 +00:00
|
|
|
destroySttBlockReader(pReader->pLDataIterArray, NULL);
|
2023-07-17 00:50:54 +00:00
|
|
|
pReader->pLDataIterArray = taosArrayInit(4, POINTER_BYTES);
|
2023-04-14 06:30:20 +00:00
|
|
|
|
2024-07-23 06:47:29 +00:00
|
|
|
return (pReader->pLDataIterArray != NULL) ? TSDB_CODE_SUCCESS : TSDB_CODE_OUT_OF_MEMORY;
|
2023-04-14 06:30:20 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-28 11:56:32 +00:00
|
|
|
int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, void* pTableIdList, int32_t numOfTables, int32_t numOfCols,
|
2024-01-14 05:44:40 +00:00
|
|
|
SArray* pCidList, int32_t* pSlotIds, uint64_t suid, void** pReader, const char* idstr,
|
2024-03-26 09:34:30 +00:00
|
|
|
SArray* pFuncTypeList, SColumnInfo* pPkCol, int32_t numOfPks) {
|
2022-08-26 07:27:19 +00:00
|
|
|
*pReader = NULL;
|
|
|
|
|
SCacheRowsReader* p = taosMemoryCalloc(1, sizeof(SCacheRowsReader));
|
2022-06-28 15:24:20 +00:00
|
|
|
if (p == NULL) {
|
2024-08-27 09:37:01 +00:00
|
|
|
return terrno;
|
2022-06-28 15:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-29 10:10:25 +00:00
|
|
|
p->type = type;
|
|
|
|
|
p->pVnode = pVnode;
|
2022-11-01 08:38:35 +00:00
|
|
|
p->pTsdb = p->pVnode->pTsdb;
|
2023-11-06 07:34:28 +00:00
|
|
|
p->info.verRange = (SVersionRange){.minVer = 0, .maxVer = INT64_MAX};
|
2023-07-17 11:10:33 +00:00
|
|
|
p->info.suid = suid;
|
2022-06-29 10:10:25 +00:00
|
|
|
p->numOfCols = numOfCols;
|
2023-04-19 02:04:48 +00:00
|
|
|
p->pCidList = pCidList;
|
2023-04-25 08:17:58 +00:00
|
|
|
p->pSlotIds = pSlotIds;
|
2024-01-14 05:44:40 +00:00
|
|
|
p->pFuncTypeList = pFuncTypeList;
|
2022-06-28 15:24:20 +00:00
|
|
|
|
2024-03-26 09:34:30 +00:00
|
|
|
p->rowKey.numOfPKs = numOfPks;
|
|
|
|
|
if (numOfPks > 0) {
|
|
|
|
|
p->rowKey.pks[0].type = pPkCol->type;
|
|
|
|
|
if (IS_VAR_DATA_TYPE(pPkCol->type)) {
|
|
|
|
|
p->rowKey.pks[0].pData = taosMemoryCalloc(1, pPkCol->bytes);
|
|
|
|
|
}
|
2024-04-10 03:18:08 +00:00
|
|
|
|
|
|
|
|
p->pkColumn = *pPkCol;
|
2024-03-26 09:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-28 11:56:32 +00:00
|
|
|
if (numOfTables == 0) {
|
2022-07-12 08:30:34 +00:00
|
|
|
*pReader = p;
|
|
|
|
|
return TSDB_CODE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-29 10:10:25 +00:00
|
|
|
p->pTableList = pTableIdList;
|
2022-10-28 11:56:32 +00:00
|
|
|
p->numOfTables = numOfTables;
|
2022-06-28 15:24:20 +00:00
|
|
|
|
2023-02-10 11:06:23 +00:00
|
|
|
int32_t code = setTableSchema(p, suid, idstr);
|
|
|
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
|
|
|
tsdbCacherowsReaderClose(p);
|
|
|
|
|
return code;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-12 13:07:12 +00:00
|
|
|
p->transferBuf = taosMemoryCalloc(p->pSchema->numOfCols, POINTER_BYTES);
|
2022-08-26 07:27:19 +00:00
|
|
|
if (p->transferBuf == NULL) {
|
2022-10-19 05:38:01 +00:00
|
|
|
tsdbCacherowsReaderClose(p);
|
2024-08-27 09:37:01 +00:00
|
|
|
return terrno;
|
2022-08-26 07:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-12 09:59:25 +00:00
|
|
|
for (int32_t i = 0; i < p->pSchema->numOfCols; ++i) {
|
2022-07-06 09:56:05 +00:00
|
|
|
if (IS_VAR_DATA_TYPE(p->pSchema->columns[i].type)) {
|
2022-07-06 05:33:21 +00:00
|
|
|
p->transferBuf[i] = taosMemoryMalloc(p->pSchema->columns[i].bytes);
|
2022-08-26 07:27:19 +00:00
|
|
|
if (p->transferBuf[i] == NULL) {
|
|
|
|
|
tsdbCacherowsReaderClose(p);
|
|
|
|
|
return TSDB_CODE_OUT_OF_MEMORY;
|
|
|
|
|
}
|
2022-06-28 15:24:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-07-06 05:33:21 +00:00
|
|
|
|
2023-02-24 03:38:54 +00:00
|
|
|
p->idstr = taosStrdup(idstr);
|
2024-07-23 06:47:29 +00:00
|
|
|
code = taosThreadMutexInit(&p->readerMutex, NULL);
|
|
|
|
|
if (code) {
|
|
|
|
|
tsdbCacherowsReaderClose(p);
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2022-11-01 08:38:35 +00:00
|
|
|
|
2023-03-09 10:54:15 +00:00
|
|
|
p->lastTs = INT64_MIN;
|
|
|
|
|
|
2022-06-28 15:24:20 +00:00
|
|
|
*pReader = p;
|
2024-07-23 06:47:29 +00:00
|
|
|
return code;
|
2022-06-28 15:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-23 06:47:29 +00:00
|
|
|
void tsdbCacherowsReaderClose(void* pReader) {
|
2022-08-26 07:27:19 +00:00
|
|
|
SCacheRowsReader* p = pReader;
|
2023-05-19 07:54:46 +00:00
|
|
|
if (p == NULL) {
|
2024-07-23 06:47:29 +00:00
|
|
|
return;
|
2023-05-19 07:54:46 +00:00
|
|
|
}
|
2022-06-28 15:24:20 +00:00
|
|
|
|
2024-08-06 08:46:40 +00:00
|
|
|
if (p->pSchema != NULL && p->transferBuf != NULL) {
|
2022-07-13 07:28:21 +00:00
|
|
|
for (int32_t i = 0; i < p->pSchema->numOfCols; ++i) {
|
|
|
|
|
taosMemoryFreeClear(p->transferBuf[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
taosMemoryFree(p->transferBuf);
|
|
|
|
|
taosMemoryFree(p->pSchema);
|
2022-06-28 15:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-02 10:22:42 +00:00
|
|
|
taosMemoryFree(p->pCurrSchema);
|
|
|
|
|
|
2024-07-22 08:58:13 +00:00
|
|
|
if (p->rowKey.numOfPKs > 0) {
|
|
|
|
|
for (int32_t i = 0; i < p->rowKey.numOfPKs; i++) {
|
|
|
|
|
if (IS_VAR_DATA_TYPE(p->rowKey.pks[i].type)) {
|
|
|
|
|
taosMemoryFree(p->rowKey.pks[i].pData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 01:49:41 +00:00
|
|
|
if (p->pLDataIterArray) {
|
2023-08-16 02:55:07 +00:00
|
|
|
destroySttBlockReader(p->pLDataIterArray, NULL);
|
2023-08-02 01:49:41 +00:00
|
|
|
}
|
2022-10-25 02:36:30 +00:00
|
|
|
|
2023-07-20 01:11:26 +00:00
|
|
|
if (p->pFileReader) {
|
2024-09-10 05:12:05 +00:00
|
|
|
tsdbDataFileReaderClose(&p->pFileReader);
|
2023-07-20 01:11:26 +00:00
|
|
|
p->pFileReader = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-29 09:43:51 +00:00
|
|
|
taosMemoryFree((void*)p->idstr);
|
2024-07-23 06:47:29 +00:00
|
|
|
(void) taosThreadMutexDestroy(&p->readerMutex);
|
2022-11-01 08:38:35 +00:00
|
|
|
|
2023-07-18 09:17:06 +00:00
|
|
|
if (p->pTableMap) {
|
|
|
|
|
void* pe = NULL;
|
|
|
|
|
int32_t iter = 0;
|
|
|
|
|
while ((pe = tSimpleHashIterate(p->pTableMap, pe, &iter)) != NULL) {
|
|
|
|
|
STableLoadInfo* pInfo = *(STableLoadInfo**)pe;
|
2024-07-15 11:37:52 +00:00
|
|
|
taosArrayDestroy(pInfo->pTombData);
|
|
|
|
|
pInfo->pTombData = NULL;
|
2023-07-18 09:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tSimpleHashCleanup(p->pTableMap);
|
|
|
|
|
}
|
|
|
|
|
if (p->uidList) {
|
|
|
|
|
taosMemoryFree(p->uidList);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-28 15:24:20 +00:00
|
|
|
taosMemoryFree(pReader);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-27 08:48:33 +00:00
|
|
|
static int32_t tsdbCacheQueryReseek(void* pQHandle) {
|
2022-11-01 08:38:35 +00:00
|
|
|
int32_t code = 0;
|
|
|
|
|
SCacheRowsReader* pReader = pQHandle;
|
|
|
|
|
|
2023-01-10 02:11:17 +00:00
|
|
|
code = taosThreadMutexTryLock(&pReader->readerMutex);
|
|
|
|
|
if (code == 0) {
|
|
|
|
|
// pause current reader's state if not paused, save ts & version for resuming
|
|
|
|
|
// just wait for the big all tables' snapshot untaking for now
|
2022-11-01 08:38:35 +00:00
|
|
|
|
2023-01-10 02:11:17 +00:00
|
|
|
code = TSDB_CODE_VND_QUERY_BUSY;
|
2024-07-23 06:47:29 +00:00
|
|
|
(void)taosThreadMutexUnlock(&pReader->readerMutex);
|
2023-01-10 02:11:17 +00:00
|
|
|
|
|
|
|
|
return code;
|
|
|
|
|
} else if (code == EBUSY) {
|
|
|
|
|
return TSDB_CODE_VND_QUERY_BUSY;
|
|
|
|
|
} else {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2022-10-27 08:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-20 08:26:27 +00:00
|
|
|
int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32_t* slotIds, const int32_t* dstSlotIds,
|
|
|
|
|
SArray* pTableUidList) {
|
2022-06-28 15:24:20 +00:00
|
|
|
if (pReader == NULL || pResBlock == NULL) {
|
2022-06-21 08:29:19 +00:00
|
|
|
return TSDB_CODE_INVALID_PARA;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-06 08:46:40 +00:00
|
|
|
int32_t code = TSDB_CODE_SUCCESS;
|
|
|
|
|
bool hasRes = false;
|
2024-08-06 09:48:28 +00:00
|
|
|
SArray* pRow = NULL;
|
|
|
|
|
void** pRes = NULL;
|
2022-08-26 07:27:19 +00:00
|
|
|
SCacheRowsReader* pr = pReader;
|
2024-08-06 09:48:28 +00:00
|
|
|
int32_t pkBufLen = 0;
|
2024-07-23 06:47:29 +00:00
|
|
|
|
2024-08-06 09:48:28 +00:00
|
|
|
pr->pReadSnap = NULL;
|
|
|
|
|
pRow = taosArrayInit(TARRAY_SIZE(pr->pCidList), sizeof(SLastCol));
|
2024-07-23 06:47:29 +00:00
|
|
|
if (pRow == NULL) {
|
|
|
|
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
|
|
|
goto _end;
|
|
|
|
|
}
|
2022-06-21 08:29:19 +00:00
|
|
|
|
2024-08-06 09:48:28 +00:00
|
|
|
pRes = taosMemoryCalloc(pr->numOfCols, POINTER_BYTES);
|
2022-10-19 01:33:54 +00:00
|
|
|
if (pRes == NULL) {
|
2024-08-27 09:37:01 +00:00
|
|
|
code = terrno;
|
2022-10-19 01:33:54 +00:00
|
|
|
goto _end;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-06 09:48:28 +00:00
|
|
|
pkBufLen = (pr->rowKey.numOfPKs > 0) ? pr->pkColumn.bytes : 0;
|
2022-10-17 11:14:06 +00:00
|
|
|
for (int32_t j = 0; j < pr->numOfCols; ++j) {
|
2024-04-10 03:18:08 +00:00
|
|
|
int32_t bytes = (slotIds[j] == -1) ? 1 : pr->pSchema->columns[slotIds[j]].bytes;
|
2023-12-05 06:16:01 +00:00
|
|
|
|
2024-04-10 03:18:08 +00:00
|
|
|
pRes[j] = taosMemoryCalloc(1, sizeof(SFirstLastRes) + bytes + pkBufLen + VARSTR_HEADER_SIZE);
|
2024-07-23 11:16:06 +00:00
|
|
|
if (pRes[j] == NULL) {
|
2024-08-27 09:37:01 +00:00
|
|
|
code = terrno;
|
2024-07-23 11:16:06 +00:00
|
|
|
goto _end;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 09:39:28 +00:00
|
|
|
SFirstLastRes* p = (SFirstLastRes*)varDataVal(pRes[j]);
|
|
|
|
|
p->ts = INT64_MIN;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 06:47:29 +00:00
|
|
|
(void)taosThreadMutexLock(&pr->readerMutex);
|
2024-09-11 11:09:17 +00:00
|
|
|
code = tsdbTakeReadSnap2((STsdbReader*)pr, tsdbCacheQueryReseek, &pr->pReadSnap, pr->idstr);
|
2023-01-17 07:11:11 +00:00
|
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
|
|
|
goto _end;
|
|
|
|
|
}
|
2022-10-25 02:36:30 +00:00
|
|
|
|
2024-04-23 11:25:51 +00:00
|
|
|
int8_t ltype = (pr->type & CACHESCAN_RETRIEVE_LAST) >> 3;
|
|
|
|
|
|
2023-08-02 02:48:55 +00:00
|
|
|
STableKeyInfo* pTableList = pr->pTableList;
|
2023-04-21 08:07:22 +00:00
|
|
|
|
2022-06-21 08:29:19 +00:00
|
|
|
// retrieve the only one last row of all tables in the uid list.
|
2022-10-19 09:43:23 +00:00
|
|
|
if (HASTYPE(pr->type, CACHESCAN_RETRIEVE_TYPE_SINGLE)) {
|
2023-08-02 03:10:12 +00:00
|
|
|
SArray* pLastCols = taosArrayInit(pr->numOfCols, sizeof(SLastCol));
|
|
|
|
|
if (pLastCols == NULL) {
|
|
|
|
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
|
|
|
goto _end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int32_t i = 0; i < pr->numOfCols; ++i) {
|
2024-03-08 05:14:54 +00:00
|
|
|
int32_t slotId = slotIds[i];
|
2023-12-05 06:16:01 +00:00
|
|
|
if (slotId == -1) {
|
2024-04-03 01:38:04 +00:00
|
|
|
SLastCol p = {.rowKey.ts = INT64_MIN, .colVal.value.type = TSDB_DATA_TYPE_BOOL, .colVal.flag = CV_FLAG_NULL};
|
2024-07-23 06:47:29 +00:00
|
|
|
void* px = taosArrayPush(pLastCols, &p);
|
|
|
|
|
if (px == NULL) {
|
|
|
|
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
|
|
|
goto _end;
|
|
|
|
|
}
|
2023-12-05 06:16:01 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2023-08-02 03:10:12 +00:00
|
|
|
struct STColumn* pCol = &pr->pSchema->columns[slotId];
|
2024-04-03 01:38:04 +00:00
|
|
|
SLastCol p = {.rowKey.ts = INT64_MIN, .colVal.value.type = pCol->type, .colVal.flag = CV_FLAG_NULL};
|
2023-08-02 03:10:12 +00:00
|
|
|
|
2024-07-22 08:58:13 +00:00
|
|
|
if (pr->rowKey.numOfPKs > 0) {
|
|
|
|
|
p.rowKey.numOfPKs = pr->rowKey.numOfPKs;
|
|
|
|
|
for (int32_t j = 0; j < pr->rowKey.numOfPKs; j++) {
|
|
|
|
|
p.rowKey.pks[j].type = pr->pkColumn.type;
|
|
|
|
|
if (IS_VAR_DATA_TYPE(pr->pkColumn.type)) {
|
2024-07-23 11:16:06 +00:00
|
|
|
|
2024-07-22 08:58:13 +00:00
|
|
|
p.rowKey.pks[j].pData = taosMemoryCalloc(1, pr->pkColumn.bytes);
|
2024-07-23 11:16:06 +00:00
|
|
|
if (p.rowKey.pks[j].pData == NULL) {
|
2024-08-27 09:37:01 +00:00
|
|
|
code = terrno;
|
2024-07-23 11:16:06 +00:00
|
|
|
goto _end;
|
|
|
|
|
}
|
2024-07-22 08:58:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 03:10:12 +00:00
|
|
|
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
|
|
|
|
p.colVal.value.pData = taosMemoryCalloc(pCol->bytes, sizeof(char));
|
2024-07-23 06:47:29 +00:00
|
|
|
if (p.colVal.value.pData == NULL) {
|
2024-08-27 09:37:01 +00:00
|
|
|
code = terrno;
|
2024-07-23 06:47:29 +00:00
|
|
|
goto _end;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void* px = taosArrayPush(pLastCols, &p);
|
|
|
|
|
if (px == NULL) {
|
|
|
|
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
|
|
|
goto _end;
|
2023-08-02 03:10:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 02:48:55 +00:00
|
|
|
int64_t st = taosGetTimestampUs();
|
|
|
|
|
int64_t totalLastTs = INT64_MAX;
|
2022-10-28 11:56:32 +00:00
|
|
|
for (int32_t i = 0; i < pr->numOfTables; ++i) {
|
2023-08-02 02:28:13 +00:00
|
|
|
tb_uid_t uid = pTableList[i].uid;
|
2022-06-29 10:10:25 +00:00
|
|
|
|
2024-07-23 06:47:29 +00:00
|
|
|
code = tsdbCacheGetBatch(pr->pTsdb, uid, pRow, pr, ltype);
|
2024-07-23 11:16:06 +00:00
|
|
|
if (code == -1) {// fix the invalid return code
|
|
|
|
|
code = 0;
|
|
|
|
|
} else if (code != 0) {
|
2024-07-23 06:47:29 +00:00
|
|
|
goto _end;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 04:43:57 +00:00
|
|
|
if (TARRAY_SIZE(pRow) <= 0 || COL_VAL_IS_NONE(&((SLastCol*)TARRAY_DATA(pRow))[0].colVal)) {
|
2024-08-22 07:44:27 +00:00
|
|
|
taosArrayClearEx(pRow, tsdbCacheFreeSLastColItem);
|
2022-06-21 08:29:19 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-17 09:59:43 +00:00
|
|
|
{
|
2023-03-09 10:54:15 +00:00
|
|
|
bool hasNotNullRow = true;
|
2023-03-19 05:41:32 +00:00
|
|
|
int64_t singleTableLastTs = INT64_MAX;
|
2022-10-17 09:59:43 +00:00
|
|
|
for (int32_t k = 0; k < pr->numOfCols; ++k) {
|
2023-12-05 06:16:01 +00:00
|
|
|
if (slotIds[k] == -1) continue;
|
2023-04-21 08:07:22 +00:00
|
|
|
SLastCol* p = taosArrayGet(pLastCols, k);
|
2024-07-23 06:47:29 +00:00
|
|
|
if (p == NULL) {
|
|
|
|
|
return TSDB_CODE_INVALID_PARA;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-21 08:07:22 +00:00
|
|
|
SLastCol* pColVal = (SLastCol*)taosArrayGet(pRow, k);
|
2024-07-23 06:47:29 +00:00
|
|
|
if (pColVal == NULL) {
|
|
|
|
|
return TSDB_CODE_INVALID_PARA;
|
|
|
|
|
}
|
2022-10-19 07:43:58 +00:00
|
|
|
|
2024-07-22 08:58:13 +00:00
|
|
|
if (tRowKeyCompare(&pColVal->rowKey, &p->rowKey) > 0) {
|
2023-04-21 08:07:22 +00:00
|
|
|
if (!COL_VAL_IS_VALUE(&pColVal->colVal) && HASTYPE(pr->type, CACHESCAN_RETRIEVE_LAST)) {
|
|
|
|
|
if (!COL_VAL_IS_VALUE(&p->colVal)) {
|
|
|
|
|
hasNotNullRow = false;
|
2022-10-19 09:43:23 +00:00
|
|
|
}
|
2024-03-08 05:14:54 +00:00
|
|
|
// For all of cols is null, the last null col of last table will be save
|
2024-01-15 10:29:41 +00:00
|
|
|
if (i != pr->numOfTables - 1 || k != pr->numOfCols - 1 || hasRes) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-10-17 09:59:43 +00:00
|
|
|
}
|
2022-10-19 07:43:58 +00:00
|
|
|
|
2023-04-21 08:07:22 +00:00
|
|
|
hasRes = true;
|
2024-04-03 01:38:04 +00:00
|
|
|
p->rowKey.ts = pColVal->rowKey.ts;
|
2024-07-22 08:58:13 +00:00
|
|
|
for (int32_t j = 0; j < p->rowKey.numOfPKs; j++) {
|
|
|
|
|
if (IS_VAR_DATA_TYPE(p->rowKey.pks[j].type)) {
|
|
|
|
|
memcpy(p->rowKey.pks[j].pData, pColVal->rowKey.pks[j].pData, pColVal->rowKey.pks[j].nData);
|
|
|
|
|
p->rowKey.pks[j].nData = pColVal->rowKey.pks[j].nData;
|
|
|
|
|
} else {
|
|
|
|
|
p->rowKey.pks[j].val = pColVal->rowKey.pks[j].val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-24 03:01:47 +00:00
|
|
|
if (k == 0) {
|
|
|
|
|
if (TARRAY_SIZE(pTableUidList) == 0) {
|
2024-07-23 06:47:29 +00:00
|
|
|
void* px = taosArrayPush(pTableUidList, &uid);
|
|
|
|
|
if (px == NULL) {
|
|
|
|
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
|
|
|
goto _end;
|
|
|
|
|
}
|
2023-05-24 03:01:47 +00:00
|
|
|
} else {
|
2023-08-02 02:28:13 +00:00
|
|
|
taosArraySet(pTableUidList, 0, &uid);
|
2023-03-09 10:54:15 +00:00
|
|
|
}
|
2023-05-24 03:01:47 +00:00
|
|
|
}
|
2022-10-17 09:59:43 +00:00
|
|
|
|
2024-04-03 01:38:04 +00:00
|
|
|
if (pColVal->rowKey.ts < singleTableLastTs && HASTYPE(pr->type, CACHESCAN_RETRIEVE_LAST)) {
|
|
|
|
|
singleTableLastTs = pColVal->rowKey.ts;
|
2023-04-21 08:07:22 +00:00
|
|
|
}
|
2022-10-17 09:59:43 +00:00
|
|
|
|
2024-02-21 06:29:10 +00:00
|
|
|
if (!IS_VAR_DATA_TYPE(pColVal->colVal.value.type)) {
|
2023-04-21 08:07:22 +00:00
|
|
|
p->colVal = pColVal->colVal;
|
|
|
|
|
} else {
|
|
|
|
|
if (COL_VAL_IS_VALUE(&pColVal->colVal)) {
|
|
|
|
|
memcpy(p->colVal.value.pData, pColVal->colVal.value.pData, pColVal->colVal.value.nData);
|
2022-10-17 09:59:43 +00:00
|
|
|
}
|
2023-04-21 08:07:22 +00:00
|
|
|
|
|
|
|
|
p->colVal.value.nData = pColVal->colVal.value.nData;
|
2024-02-21 06:29:10 +00:00
|
|
|
p->colVal.value.type = pColVal->colVal.value.type;
|
2023-04-21 08:07:22 +00:00
|
|
|
p->colVal.flag = pColVal->colVal.flag;
|
|
|
|
|
p->colVal.cid = pColVal->colVal.cid;
|
2022-10-17 09:59:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-06-21 08:29:19 +00:00
|
|
|
}
|
2023-03-09 10:54:15 +00:00
|
|
|
|
|
|
|
|
if (hasNotNullRow) {
|
2023-03-19 06:40:16 +00:00
|
|
|
if (INT64_MAX == totalLastTs || (INT64_MAX != singleTableLastTs && totalLastTs < singleTableLastTs)) {
|
2023-03-19 05:41:32 +00:00
|
|
|
totalLastTs = singleTableLastTs;
|
2023-03-19 03:01:39 +00:00
|
|
|
}
|
2023-03-13 09:21:32 +00:00
|
|
|
double cost = (taosGetTimestampUs() - st) / 1000.0;
|
|
|
|
|
if (cost > tsCacheLazyLoadThreshold) {
|
2024-09-13 01:54:26 +00:00
|
|
|
// pr->lastTs = totalLastTs;
|
2023-03-13 09:21:32 +00:00
|
|
|
}
|
2023-03-09 10:54:15 +00:00
|
|
|
}
|
2022-06-21 08:29:19 +00:00
|
|
|
}
|
2022-06-29 10:10:25 +00:00
|
|
|
|
2024-08-22 07:44:27 +00:00
|
|
|
taosArrayClearEx(pRow, tsdbCacheFreeSLastColItem);
|
2022-06-21 08:29:19 +00:00
|
|
|
}
|
2022-10-17 11:14:06 +00:00
|
|
|
|
|
|
|
|
if (hasRes) {
|
2024-07-23 06:47:29 +00:00
|
|
|
code = saveOneRow(pLastCols, pResBlock, pr, slotIds, dstSlotIds, pRes, pr->idstr);
|
|
|
|
|
if (code) {
|
|
|
|
|
goto _end;
|
|
|
|
|
}
|
2022-10-17 11:14:06 +00:00
|
|
|
}
|
2023-08-02 03:10:12 +00:00
|
|
|
|
2024-08-22 07:44:27 +00:00
|
|
|
taosArrayDestroyEx(pLastCols, tsdbCacheFreeSLastColItem);
|
2022-10-19 09:43:23 +00:00
|
|
|
} else if (HASTYPE(pr->type, CACHESCAN_RETRIEVE_TYPE_ALL)) {
|
2022-10-28 11:56:32 +00:00
|
|
|
for (int32_t i = pr->tableIndex; i < pr->numOfTables; ++i) {
|
2023-08-02 02:48:55 +00:00
|
|
|
tb_uid_t uid = pTableList[i].uid;
|
2022-06-21 08:29:19 +00:00
|
|
|
|
2024-07-23 06:47:29 +00:00
|
|
|
if ((code = tsdbCacheGetBatch(pr->pTsdb, uid, pRow, pr, ltype)) != 0) {
|
2024-07-23 11:16:06 +00:00
|
|
|
if (code == -1) {// fix the invalid return code
|
|
|
|
|
code = 0;
|
|
|
|
|
} else if (code != 0) {
|
|
|
|
|
goto _end;
|
|
|
|
|
}
|
2024-07-23 06:47:29 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-02 04:43:57 +00:00
|
|
|
if (TARRAY_SIZE(pRow) <= 0 || COL_VAL_IS_NONE(&((SLastCol*)TARRAY_DATA(pRow))[0].colVal)) {
|
2024-08-22 07:44:27 +00:00
|
|
|
taosArrayClearEx(pRow, tsdbCacheFreeSLastColItem);
|
2022-06-21 08:29:19 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 06:47:29 +00:00
|
|
|
code = saveOneRow(pRow, pResBlock, pr, slotIds, dstSlotIds, pRes, pr->idstr);
|
|
|
|
|
if (code) {
|
|
|
|
|
goto _end;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-22 07:44:27 +00:00
|
|
|
taosArrayClearEx(pRow, tsdbCacheFreeSLastColItem);
|
2022-06-28 15:24:20 +00:00
|
|
|
|
2024-07-23 06:47:29 +00:00
|
|
|
void* px = taosArrayPush(pTableUidList, &uid);
|
|
|
|
|
if (px == NULL) {
|
|
|
|
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
|
|
|
goto _end;
|
|
|
|
|
}
|
2022-06-29 10:10:25 +00:00
|
|
|
|
2023-05-16 10:56:05 +00:00
|
|
|
++pr->tableIndex;
|
2022-06-28 15:24:20 +00:00
|
|
|
if (pResBlock->info.rows >= pResBlock->info.capacity) {
|
2022-10-19 01:33:54 +00:00
|
|
|
goto _end;
|
2022-06-28 15:24:20 +00:00
|
|
|
}
|
2022-06-21 08:29:19 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2022-10-19 01:33:54 +00:00
|
|
|
code = TSDB_CODE_INVALID_PARA;
|
2022-06-21 08:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
2022-11-03 01:08:36 +00:00
|
|
|
_end:
|
2023-07-18 07:30:31 +00:00
|
|
|
tsdbUntakeReadSnap2((STsdbReader*)pr, pr->pReadSnap, true);
|
2024-08-06 08:46:40 +00:00
|
|
|
pr->pReadSnap = NULL;
|
|
|
|
|
|
2023-10-09 07:06:03 +00:00
|
|
|
if (pr->pCurFileSet) {
|
|
|
|
|
pr->pCurFileSet = NULL;
|
|
|
|
|
}
|
2022-10-25 02:36:30 +00:00
|
|
|
|
2024-07-23 06:47:29 +00:00
|
|
|
(void)taosThreadMutexUnlock(&pr->readerMutex);
|
2022-10-25 02:36:30 +00:00
|
|
|
|
2023-02-24 01:48:34 +00:00
|
|
|
if (pRes != NULL) {
|
|
|
|
|
for (int32_t j = 0; j < pr->numOfCols; ++j) {
|
|
|
|
|
taosMemoryFree(pRes[j]);
|
|
|
|
|
}
|
2022-10-19 01:33:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
taosMemoryFree(pRes);
|
2023-05-17 06:05:28 +00:00
|
|
|
taosArrayDestroy(pRow);
|
2023-05-16 10:56:05 +00:00
|
|
|
|
2022-10-19 01:33:54 +00:00
|
|
|
return code;
|
2022-06-21 08:29:19 +00:00
|
|
|
}
|