support quick cmd
This commit is contained in:
parent
620c7627e9
commit
6ad894b356
|
@ -61,7 +61,7 @@ extern "C" {
|
|||
#define TSDB_INS_TABLE_MACHINES "ins_machines"
|
||||
#define TSDB_INS_TABLE_ENCRYPTIONS "ins_encryptions"
|
||||
#define TSDB_INS_TABLE_TSMAS "ins_tsmas"
|
||||
#define TSDB_INS_TABLE_USAGE "ins_usage"
|
||||
#define TSDB_INS_DISK_USAGE "ins_disk_usage"
|
||||
|
||||
#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema"
|
||||
#define TSDB_PERFS_TABLE_SMAS "perf_smas"
|
||||
|
|
|
@ -300,20 +300,9 @@ int32_t tSerializeBlockDistInfo(void* buf, int32_t bufLen, const STableBlockDist
|
|||
int32_t tDeserializeBlockDistInfo(void* buf, int32_t bufLen, STableBlockDistInfo* pInfo);
|
||||
|
||||
typedef struct SDBBlockUsageInfo {
|
||||
uint32_t rowSize;
|
||||
uint16_t numOfFiles;
|
||||
uint32_t numOfTables;
|
||||
uint32_t numOfBlocks;
|
||||
uint64_t totalSize;
|
||||
uint64_t totalRows;
|
||||
int32_t maxRows;
|
||||
int32_t minRows;
|
||||
int32_t defMinRows;
|
||||
int32_t defMaxRows;
|
||||
int32_t firstSeekTimeUs;
|
||||
uint32_t numOfInmemRows;
|
||||
uint32_t numOfSttRows;
|
||||
uint32_t numOfVgroups;
|
||||
uint64_t dataInDiskSize;
|
||||
uint64_t walInDiskSize;
|
||||
uint64_t rawDataSize;
|
||||
} SDBBlockUsageInfo;
|
||||
|
||||
int32_t tSerializeBlockDbUsage(void* buf, int32_t bufLen, const SDBBlockUsageInfo* pInfo);
|
||||
|
|
|
@ -22,8 +22,8 @@ extern "C" {
|
|||
|
||||
#include "nodes.h"
|
||||
#include "tmsg.h"
|
||||
#include "tvariant.h"
|
||||
#include "tsimplehash.h"
|
||||
#include "tvariant.h"
|
||||
|
||||
#define TABLE_TOTAL_COL_NUM(pMeta) ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags)
|
||||
#define TABLE_META_SIZE(pMeta) \
|
||||
|
@ -407,7 +407,6 @@ typedef struct SWindowOffsetNode {
|
|||
SNode* pEndOffset; // SValueNode
|
||||
} SWindowOffsetNode;
|
||||
|
||||
|
||||
typedef struct SSelectStmt {
|
||||
ENodeType type; // QUERY_NODE_SELECT_STMT
|
||||
bool isDistinct;
|
||||
|
@ -461,6 +460,7 @@ typedef struct SSelectStmt {
|
|||
bool groupSort;
|
||||
bool tagScan;
|
||||
bool joinContains;
|
||||
bool mixSysTableAndActualTable;
|
||||
} SSelectStmt;
|
||||
|
||||
typedef enum ESetOperatorType { SET_OP_TYPE_UNION_ALL = 1, SET_OP_TYPE_UNION } ESetOperatorType;
|
||||
|
@ -630,13 +630,15 @@ void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewrit
|
|||
typedef enum ECollectColType { COLLECT_COL_TYPE_COL = 1, COLLECT_COL_TYPE_TAG, COLLECT_COL_TYPE_ALL } ECollectColType;
|
||||
int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* pTableAlias, ECollectColType type,
|
||||
SNodeList** pCols);
|
||||
int32_t nodesCollectColumnsExt(SSelectStmt* pSelect, ESqlClause clause, SSHashObj* pMultiTableAlias, ECollectColType type,
|
||||
SNodeList** pCols);
|
||||
int32_t nodesCollectColumnsExt(SSelectStmt* pSelect, ESqlClause clause, SSHashObj* pMultiTableAlias,
|
||||
ECollectColType type, SNodeList** pCols);
|
||||
int32_t nodesCollectColumnsFromNode(SNode* node, const char* pTableAlias, ECollectColType type, SNodeList** pCols);
|
||||
|
||||
typedef bool (*FFuncClassifier)(int32_t funcId);
|
||||
int32_t nodesCollectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier, SNodeList** pFuncs);
|
||||
int32_t nodesCollectSelectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier, SNodeList* pFuncs);
|
||||
int32_t nodesCollectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier,
|
||||
SNodeList** pFuncs);
|
||||
int32_t nodesCollectSelectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier,
|
||||
SNodeList* pFuncs);
|
||||
|
||||
int32_t nodesCollectSpecialNodes(SSelectStmt* pSelect, ESqlClause clause, ENodeType type, SNodeList** pNodes);
|
||||
|
||||
|
@ -675,7 +677,6 @@ char* getJoinSTypeString(EJoinSubType type);
|
|||
char* getFullJoinTypeString(EJoinType type, EJoinSubType stype);
|
||||
int32_t mergeJoinConds(SNode** ppDst, SNode** ppSrc);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -454,13 +454,14 @@ static const SSysDbTableSchema encryptionsSchema[] = {
|
|||
static const SSysDbTableSchema usageSchema[] = {
|
||||
{.name = "db_name", .bytes = 32 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||
{.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
|
||||
{.name = "wal_size", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "mem_rows_size", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "level1_size", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "level2_size", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "level3_size", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "s3_size",.bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "estimated_row_data_size", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "wal", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "level1", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "level2", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "level3", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "cache", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "meta", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "s3",.bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "estimated_raw_data", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
};
|
||||
|
||||
static const SSysTableMeta infosMeta[] = {
|
||||
|
@ -501,7 +502,7 @@ static const SSysTableMeta infosMeta[] = {
|
|||
{TSDB_INS_TABLE_TSMAS, tsmaSchema, tListLen(tsmaSchema), false},
|
||||
{TSDB_INS_TABLE_ANODES, anodesSchema, tListLen(anodesSchema), true},
|
||||
{TSDB_INS_TABLE_ANODES_FULL, anodesFullSchema, tListLen(anodesFullSchema), true},
|
||||
{TSDB_INS_TABLE_USAGE, usageSchema, tListLen(usageSchema), false},
|
||||
{TSDB_INS_DISK_USAGE, usageSchema, tListLen(usageSchema), false},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema connectionsSchema[] = {
|
||||
|
|
|
@ -142,7 +142,7 @@ static int32_t convertToRetrieveType(char *name, int32_t len) {
|
|||
type = TSDB_MGMT_TABLE_ENCRYPTIONS;
|
||||
} else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
|
||||
type = TSDB_MGMT_TABLE_TSMAS;
|
||||
} else if (strncasecmp(name, TSDB_INS_TABLE_USAGE, len) == 0) {
|
||||
} else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
|
||||
type = TSDB_MGMT_TABLE_USAGE;
|
||||
} else {
|
||||
mError("invalid show name:%s len:%d", name, len);
|
||||
|
|
|
@ -61,6 +61,7 @@ typedef struct SSysTableScanInfo {
|
|||
bool sysInfo;
|
||||
bool showRewrite;
|
||||
bool restore;
|
||||
bool skipFilterTable;
|
||||
SNode* pCondition; // db_name filter condition, to discard data that are not in current database
|
||||
SMTbCursor* pCur; // cursor for iterate the local table meta store.
|
||||
SSysTableIndex* pIdx; // idx for local table meta
|
||||
|
@ -1457,7 +1458,7 @@ _end:
|
|||
int32_t buildSysUsageInfo(const SSysTableScanInfo* pInfo, int32_t capacity) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SSDataBlock* p = buildInfoSchemaTableMetaBlock(TSDB_INS_TABLE_USAGE);
|
||||
SSDataBlock* p = buildInfoSchemaTableMetaBlock(TSDB_INS_DISK_USAGE);
|
||||
QUERY_CHECK_NULL(p, code, lino, _end, terrno);
|
||||
|
||||
code = blockDataEnsureCapacity(p, capacity);
|
||||
|
@ -2026,14 +2027,24 @@ static int32_t buildVgDiskUsage(SOperatorInfo* pOperator, SDbSizeStatisInfo* pSt
|
|||
const char* db = NULL;
|
||||
pAPI->metaFn.getBasicInfo(pInfo->readHandle.vnode, &pStaticsInfo->dbname, &vgId, NULL, NULL);
|
||||
|
||||
SDbSizeStatisInfo staticsInfo = {0};
|
||||
pStaticsInfo->vgId = vgId;
|
||||
|
||||
staticsInfo.vgId = vgId;
|
||||
|
||||
code = pAPI->metaFn.getDBSize(pInfo->readHandle.vnode, &staticsInfo);
|
||||
code = pAPI->metaFn.getDBSize(pInfo->readHandle.vnode, pStaticsInfo);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
return vnodeEstimateRawDataSize(pOperator, &staticsInfo);
|
||||
code = vnodeEstimateRawDataSize(pOperator, pStaticsInfo);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
pStaticsInfo->memSize = pStaticsInfo->memSize >> 10;
|
||||
pStaticsInfo->l1Size = pStaticsInfo->l1Size >> 10;
|
||||
pStaticsInfo->l2Size = pStaticsInfo->l2Size >> 10;
|
||||
pStaticsInfo->l3Size = pStaticsInfo->l3Size >> 10;
|
||||
pStaticsInfo->cacheSize = pStaticsInfo->cacheSize >> 10;
|
||||
pStaticsInfo->walSize = pStaticsInfo->walSize >> 10;
|
||||
pStaticsInfo->metaSize = pStaticsInfo->metaSize >> 10;
|
||||
pStaticsInfo->rawDataSize = pStaticsInfo->rawDataSize >> 10;
|
||||
pStaticsInfo->s3Size = pStaticsInfo->s3Size >> 10;
|
||||
|
||||
_end:
|
||||
return code;
|
||||
}
|
||||
|
@ -2069,9 +2080,9 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
|
|||
SDBBlockUsageInfo usageInfo = {0};
|
||||
int32_t len = tSerializeBlockDbUsage(NULL, 0, &usageInfo);
|
||||
|
||||
usageInfo.numOfSttRows = 120;
|
||||
usageInfo.numOfInmemRows = 120;
|
||||
usageInfo.numOfBlocks = 120;
|
||||
usageInfo.dataInDiskSize = staticsInfo.l1Size + staticsInfo.l2Size + staticsInfo.l3Size;
|
||||
usageInfo.walInDiskSize = staticsInfo.walSize;
|
||||
usageInfo.rawDataSize = staticsInfo.rawDataSize;
|
||||
|
||||
char* p = taosMemoryCalloc(1, len + VARSTR_HEADER_SIZE);
|
||||
QUERY_CHECK_NULL(p, code, lino, _end, terrno);
|
||||
|
@ -2098,7 +2109,6 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
|
|||
pBlock->info.rows = 1;
|
||||
pOperator->status = OP_EXEC_DONE;
|
||||
pInfo->pRes->info.rows = pBlock->info.rows;
|
||||
// code = relocateColumnData(pInfo->pRes, pInfo->matchInfo.pList, pBlock->pDataBlock, false);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
} else {
|
||||
SName sn = {0};
|
||||
|
@ -2111,7 +2121,7 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
|
|||
|
||||
varDataSetLen(dbname, strlen(varDataVal(dbname)));
|
||||
|
||||
p = buildInfoSchemaTableMetaBlock(TSDB_INS_TABLE_USAGE);
|
||||
p = buildInfoSchemaTableMetaBlock(TSDB_INS_DISK_USAGE);
|
||||
QUERY_CHECK_NULL(p, code, lino, _end, terrno);
|
||||
|
||||
code = blockDataEnsureCapacity(p, pOperator->resultInfo.capacity);
|
||||
|
@ -2129,10 +2139,6 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
|
|||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&staticsInfo.walSize, false); // wal
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
pColInfoData = taosArrayGet(p->pDataBlock, numOfCols++);
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&staticsInfo.memSize, false); // memtable
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
pColInfoData = taosArrayGet(p->pDataBlock, numOfCols++);
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&staticsInfo.l1Size, false); // l1_size
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
@ -2145,6 +2151,14 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
|
|||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&staticsInfo.l3Size, false); // l3_size
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
pColInfoData = taosArrayGet(p->pDataBlock, numOfCols++);
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&staticsInfo.cacheSize, false); // cache_size
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
pColInfoData = taosArrayGet(p->pDataBlock, numOfCols++);
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&staticsInfo.metaSize, false); // meta_size
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
pColInfoData = taosArrayGet(p->pDataBlock, numOfCols++);
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&staticsInfo.s3Size, false); // s3_size
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
@ -2383,16 +2397,13 @@ static int32_t doSysTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes)
|
|||
} else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, TSDB_TABLE_FNAME_LEN) == 0 && pInfo->showRewrite &&
|
||||
IS_SYS_DBNAME(dbName)) {
|
||||
pBlock = sysTableScanUserSTables(pOperator);
|
||||
} else if (strncasecmp(name, TSDB_INS_TABLE_USAGE, TSDB_TABLE_FNAME_LEN) == 0) {
|
||||
if (pInfo->showRewrite) {
|
||||
filter = false;
|
||||
}
|
||||
} else if (strncasecmp(name, TSDB_INS_DISK_USAGE, TSDB_TABLE_FNAME_LEN) == 0) {
|
||||
pBlock = sysTableScanUsage(pOperator);
|
||||
} else { // load the meta from mnode of the given epset
|
||||
pBlock = sysTableScanFromMNode(pOperator, pInfo, name, pTaskInfo);
|
||||
}
|
||||
|
||||
if (filter) sysTableScanFillTbName(pOperator, pInfo, name, pBlock);
|
||||
if (!pInfo->skipFilterTable) sysTableScanFillTbName(pOperator, pInfo, name, pBlock);
|
||||
if (pBlock != NULL) {
|
||||
bool limitReached = applyLimitOffset(&pInfo->limitInfo, pBlock, pTaskInfo);
|
||||
if (limitReached) {
|
||||
|
@ -2587,7 +2598,17 @@ int32_t createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNo
|
|||
QUERY_CHECK_NULL(pInfo->pRes, code, lino, _error, terrno);
|
||||
|
||||
pInfo->pCondition = pScanNode->node.pConditions;
|
||||
|
||||
tNameAssign(&pInfo->name, &pScanNode->tableName);
|
||||
const char* name = tNameGetTableName(&pInfo->name);
|
||||
if (pInfo->showRewrite == false) {
|
||||
code = filterInitFromNode(pScanNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0);
|
||||
} else {
|
||||
if (strncasecmp(name, TSDB_INS_DISK_USAGE, TSDB_TABLE_FNAME_LEN) == 0) {
|
||||
pInfo->skipFilterTable = true;
|
||||
}
|
||||
code = filterInitFromNode(NULL, &pOperator->exprSupp.pFilterInfo, 0);
|
||||
}
|
||||
QUERY_CHECK_CODE(code, lino, _error);
|
||||
|
||||
initLimitInfo(pScanPhyNode->scan.node.pLimit, pScanPhyNode->scan.node.pSlimit, &pInfo->limitInfo);
|
||||
|
@ -2595,9 +2616,6 @@ int32_t createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNo
|
|||
code = blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
|
||||
QUERY_CHECK_CODE(code, lino, _error);
|
||||
|
||||
tNameAssign(&pInfo->name, &pScanNode->tableName);
|
||||
const char* name = tNameGetTableName(&pInfo->name);
|
||||
|
||||
if (strncasecmp(name, TSDB_INS_TABLE_TABLES, TSDB_TABLE_FNAME_LEN) == 0 ||
|
||||
strncasecmp(name, TSDB_INS_TABLE_TAGS, TSDB_TABLE_FNAME_LEN) == 0) {
|
||||
pInfo->readHandle = *(SReadHandle*)readHandle;
|
||||
|
@ -3326,13 +3344,8 @@ static int32_t vnodeEstimateDataSizeByUid(SOperatorInfo* pOperator, STableId* id
|
|||
|
||||
void* pList = tableListGetInfo(pTableListInfo, 0);
|
||||
|
||||
if (pInfo->showRewrite) {
|
||||
code = pReadHandle->api.tsdReader.tsdReaderOpen(pReadHandle->vnode, &cond, pList, num, pInfo->pRes,
|
||||
(void**)&pInfo->pHandle, pTaskInfo->id.str, NULL);
|
||||
} else {
|
||||
code = pReadHandle->api.tsdReader.tsdReaderOpen(pReadHandle->vnode, &cond, pList, num, NULL,
|
||||
(void**)&pInfo->pHandle, pTaskInfo->id.str, NULL);
|
||||
}
|
||||
code = pReadHandle->api.tsdReader.tsdReaderOpen(pReadHandle->vnode, &cond, pList, num, NULL, (void**)&pInfo->pHandle,
|
||||
pTaskInfo->id.str, NULL);
|
||||
cleanupQueryTableDataCond(&cond);
|
||||
QUERY_CHECK_CODE(code, line, _end);
|
||||
|
||||
|
|
|
@ -6480,7 +6480,6 @@ int32_t blockDBUsageSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo
|
|||
}
|
||||
|
||||
SDBBlockUsageInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
pInfo->minRows = INT32_MAX;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int32_t blockDBUsageFunction(SqlFunctionCtx* pCtx) {
|
||||
|
@ -6497,26 +6496,9 @@ int32_t blockDBUsageFunction(SqlFunctionCtx* pCtx) {
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pDistInfo->numOfBlocks += p1.numOfBlocks;
|
||||
pDistInfo->numOfTables += p1.numOfTables;
|
||||
pDistInfo->numOfInmemRows += p1.numOfInmemRows;
|
||||
pDistInfo->numOfSttRows += p1.numOfSttRows;
|
||||
pDistInfo->totalSize += p1.totalSize;
|
||||
pDistInfo->totalRows += p1.totalRows;
|
||||
pDistInfo->numOfFiles += p1.numOfFiles;
|
||||
|
||||
pDistInfo->defMinRows = p1.defMinRows;
|
||||
pDistInfo->defMaxRows = p1.defMaxRows;
|
||||
pDistInfo->rowSize = p1.rowSize;
|
||||
|
||||
if (pDistInfo->minRows > p1.minRows) {
|
||||
pDistInfo->minRows = p1.minRows;
|
||||
}
|
||||
if (pDistInfo->maxRows < p1.maxRows) {
|
||||
pDistInfo->maxRows = p1.maxRows;
|
||||
}
|
||||
pDistInfo->numOfVgroups += (p1.numOfTables != 0 ? 1 : 0);
|
||||
|
||||
pDistInfo->dataInDiskSize += p1.dataInDiskSize;
|
||||
pDistInfo->walInDiskSize += p1.walInDiskSize;
|
||||
pDistInfo->rawDataSize += p1.rawDataSize;
|
||||
pResInfo->numOfRes = BLOCK_DISK_USAGE_RESULT_ROWS; // default output rows
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -6529,21 +6511,10 @@ int32_t tSerializeBlockDbUsage(void* buf, int32_t bufLen, const SDBBlockUsageInf
|
|||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
TAOS_CHECK_EXIT(tStartEncode(&encoder));
|
||||
TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->rowSize));
|
||||
|
||||
TAOS_CHECK_EXIT(tEncodeU16(&encoder, pInfo->numOfFiles));
|
||||
TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfBlocks));
|
||||
TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfTables));
|
||||
|
||||
TAOS_CHECK_EXIT(tEncodeU64(&encoder, pInfo->totalSize));
|
||||
TAOS_CHECK_EXIT(tEncodeU64(&encoder, pInfo->totalRows));
|
||||
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pInfo->maxRows));
|
||||
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pInfo->minRows));
|
||||
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pInfo->defMaxRows));
|
||||
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pInfo->defMinRows));
|
||||
TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfInmemRows));
|
||||
TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfSttRows));
|
||||
TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfVgroups));
|
||||
TAOS_CHECK_EXIT(tEncodeU64(&encoder, pInfo->dataInDiskSize));
|
||||
TAOS_CHECK_EXIT(tEncodeU64(&encoder, pInfo->walInDiskSize));
|
||||
TAOS_CHECK_EXIT(tEncodeU64(&encoder, pInfo->rawDataSize));
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
|
@ -6563,21 +6534,9 @@ int32_t tDeserializeBlockDbUsage(void* buf, int32_t bufLen, SDBBlockUsageInfo* p
|
|||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
TAOS_CHECK_EXIT(tStartDecode(&decoder));
|
||||
TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->rowSize));
|
||||
|
||||
TAOS_CHECK_EXIT(tDecodeU16(&decoder, &pInfo->numOfFiles));
|
||||
TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfBlocks));
|
||||
TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfTables));
|
||||
|
||||
TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pInfo->totalSize));
|
||||
TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pInfo->totalRows));
|
||||
TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pInfo->maxRows));
|
||||
TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pInfo->minRows));
|
||||
TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pInfo->defMaxRows));
|
||||
TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pInfo->defMinRows));
|
||||
TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfInmemRows));
|
||||
TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfSttRows));
|
||||
TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfVgroups));
|
||||
TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pInfo->dataInDiskSize));
|
||||
TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pInfo->walInDiskSize));
|
||||
TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pInfo->rawDataSize));
|
||||
|
||||
_exit:
|
||||
tDecoderClear(&decoder);
|
||||
|
@ -6591,26 +6550,17 @@ int32_t blockDBUsageFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
if (NULL == pColInfo) {
|
||||
return TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
if (pData->totalRows == 0) {
|
||||
pData->minRows = 0;
|
||||
}
|
||||
|
||||
int32_t row = 0;
|
||||
char st[256] = {0};
|
||||
double averageSize = 0;
|
||||
if (pData->numOfBlocks != 0) {
|
||||
averageSize = ((double)pData->totalSize) / pData->numOfBlocks;
|
||||
}
|
||||
uint64_t totalRawSize = pData->totalRows * pData->rowSize;
|
||||
double compRatio = 0;
|
||||
if (totalRawSize != 0) {
|
||||
compRatio = pData->totalSize * 100 / (double)totalRawSize;
|
||||
|
||||
uint64_t totalDiskSize = pData->dataInDiskSize;
|
||||
uint64_t rawDataSize = pData->rawDataSize;
|
||||
double compressRadio = 0;
|
||||
if (rawDataSize != 0) {
|
||||
compressRadio = totalDiskSize * 100 / (double)rawDataSize;
|
||||
}
|
||||
|
||||
int32_t len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE,
|
||||
"Total_Blocks=[%d] Total_Size=[%.2f KiB] Average_size=[%.2f KiB] Compression_Ratio=[%.2f %c]",
|
||||
pData->numOfBlocks, pData->totalSize / 1024.0, averageSize / 1024.0, compRatio, '%');
|
||||
int32_t len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE, "Compress_radio: %.2f", compressRadio);
|
||||
|
||||
varDataSetLen(st, len);
|
||||
int32_t code = colDataSetVal(pColInfo, row++, st, false);
|
||||
|
@ -6618,14 +6568,8 @@ int32_t blockDBUsageFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int64_t avgRows = 0;
|
||||
if (pData->numOfBlocks > 0) {
|
||||
avgRows = pData->totalRows / pData->numOfBlocks;
|
||||
}
|
||||
|
||||
len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE,
|
||||
"Block_Rows=[%" PRId64 "] MinRows=[%d] MaxRows=[%d] AvgRows=[%" PRId64 "]", pData->totalRows,
|
||||
pData->minRows, pData->maxRows, avgRows);
|
||||
len =
|
||||
tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE, "Disk_occupied: %" PRId64 "k", pData->dataInDiskSize);
|
||||
varDataSetLen(st, len);
|
||||
code = colDataSetVal(pColInfo, row++, st, false);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "cmdnodes.h"
|
||||
#include "parToken.h"
|
||||
#include "parUtil.h"
|
||||
#include "parser.h"
|
||||
#include "cmdnodes.h"
|
||||
|
||||
typedef struct STranslateContext {
|
||||
SParseContext* pParseCxt;
|
||||
|
@ -47,13 +47,15 @@ typedef struct STranslateContext {
|
|||
SNode* pPrevRoot;
|
||||
SNode* pPostRoot;
|
||||
bool dual; // whether select stmt without from stmt, true for without.
|
||||
bool skipCheck;
|
||||
} STranslateContext;
|
||||
|
||||
int32_t biRewriteToTbnameFunc(STranslateContext* pCxt, SNode** ppNode, bool* pRet);
|
||||
int32_t biRewriteSelectStar(STranslateContext* pCxt, SSelectStmt* pSelect);
|
||||
int32_t biCheckCreateTableTbnameCol(STranslateContext* pCxt, SCreateTableStmt* pStmt);
|
||||
int32_t findTable(STranslateContext* pCxt, const char* pTableAlias, STableNode** pOutput);
|
||||
int32_t getTargetMetaImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta, bool couldBeView);
|
||||
int32_t getTargetMetaImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta,
|
||||
bool couldBeView);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -184,7 +184,7 @@ static int32_t collectMetaKeyFromRealTableImpl(SCollectMetaKeyCxt* pCxt, const c
|
|||
}
|
||||
if (TSDB_CODE_SUCCESS == code &&
|
||||
(0 == strcmp(pTable, TSDB_INS_TABLE_TAGS) || 0 == strcmp(pTable, TSDB_INS_TABLE_TABLES) ||
|
||||
0 == strcmp(pTable, TSDB_INS_TABLE_COLS) || 0 == strcmp(pTable, TSDB_INS_TABLE_USAGE)) &&
|
||||
0 == strcmp(pTable, TSDB_INS_TABLE_COLS) || 0 == strcmp(pTable, TSDB_INS_DISK_USAGE)) &&
|
||||
QUERY_NODE_SELECT_STMT == nodeType(pCxt->pStmt)) {
|
||||
code = collectMetaKeyFromInsTags(pCxt);
|
||||
}
|
||||
|
@ -933,7 +933,7 @@ static int32_t collectMetaKeyFromDropTSMAStmt(SCollectMetaKeyCxt* pCxt, SDropTSM
|
|||
}
|
||||
|
||||
static int32_t collectMetaKeyFromShowUsage(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
|
||||
int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USAGE,
|
||||
int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_DISK_USAGE,
|
||||
pCxt->pMetaCache);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
|
||||
|
|
|
@ -354,6 +354,9 @@ static int32_t calcConstSelectFrom(SCalcConstContext* pCxt, SSelectStmt* pSelect
|
|||
pSelect->isEmptyResult = true;
|
||||
return code;
|
||||
}
|
||||
if (pSelect->mixSysTableAndActualTable) {
|
||||
return code;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = calcConstProjections(pCxt, pSelect, subquery);
|
||||
}
|
||||
|
@ -612,6 +615,7 @@ int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery) {
|
|||
.msgBuf.buf = pParseCxt->pMsg,
|
||||
.msgBuf.len = pParseCxt->msgLen,
|
||||
.code = TSDB_CODE_SUCCESS};
|
||||
|
||||
int32_t code = calcConstQuery(&cxt, pQuery->pRoot, false);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
resetProjectNullType(pQuery->pRoot);
|
||||
|
|
|
@ -365,7 +365,7 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = {
|
|||
{
|
||||
.showType = QUERY_NODE_SHOW_USAGE_STMT,
|
||||
.pDbName = TSDB_INFORMATION_SCHEMA_DB,
|
||||
.pTableName = TSDB_INS_TABLE_USAGE,
|
||||
.pTableName = TSDB_INS_DISK_USAGE,
|
||||
.numOfShowCols = 1,
|
||||
.pShowCols = {"*"}
|
||||
},
|
||||
|
@ -1505,6 +1505,17 @@ static int32_t findAndSetColumn(STranslateContext* pCxt, SColumnNode** pColRef,
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pCxt->showRewrite && pMeta->tableType == TSDB_SYSTEM_TABLE) {
|
||||
if (strncmp(pCol->dbName, TSDB_INFORMATION_SCHEMA_DB, strlen(TSDB_INFORMATION_SCHEMA_DB)) == 0 &&
|
||||
strncmp(pCol->tableName, TSDB_INS_DISK_USAGE, strlen(TSDB_INS_DISK_USAGE)) == 0 &&
|
||||
strncmp(pCol->colName, "db_name", strlen("db_name")) == 0) {
|
||||
pCol->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
pCol->node.resType.bytes = 8;
|
||||
pCxt->skipCheck = true;
|
||||
((SSelectStmt*)pCxt->pCurrStmt)->mixSysTableAndActualTable = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
STempTableNode* pTempTable = (STempTableNode*)pTable;
|
||||
SNodeList* pProjectList = getProjectList(pTempTable->pSubquery);
|
||||
|
@ -4102,7 +4113,7 @@ static int32_t dnodeToVgroupsInfo(SArray* pDnodes, SVgroupsInfo** pVgsInfo) {
|
|||
|
||||
static bool sysTableFromVnode(const char* pTable) {
|
||||
return ((0 == strcmp(pTable, TSDB_INS_TABLE_TABLES)) || (0 == strcmp(pTable, TSDB_INS_TABLE_TAGS)) ||
|
||||
(0 == strcmp(pTable, TSDB_INS_TABLE_COLS)) || 0 == strcmp(pTable, TSDB_INS_TABLE_USAGE));
|
||||
(0 == strcmp(pTable, TSDB_INS_TABLE_COLS)) || 0 == strcmp(pTable, TSDB_INS_DISK_USAGE));
|
||||
}
|
||||
|
||||
static bool sysTableFromDnode(const char* pTable) { return 0 == strcmp(pTable, TSDB_INS_TABLE_DNODE_VARIABLES); }
|
||||
|
@ -4175,7 +4186,7 @@ static int32_t setVnodeSysTableVgroupList(STranslateContext* pCxt, SName* pName,
|
|||
if (TSDB_CODE_SUCCESS == code &&
|
||||
((0 == strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_TABLES) && !hasUserDbCond) ||
|
||||
0 == strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_COLS) ||
|
||||
(0 == strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USAGE) && !hasUserDbCond))) {
|
||||
(0 == strcmp(pRealTable->table.tableName, TSDB_INS_DISK_USAGE) && !hasUserDbCond))) {
|
||||
code = addMnodeToVgroupList(&pCxt->pParseCxt->mgmtEpSet, &pVgs);
|
||||
}
|
||||
|
||||
|
@ -4275,7 +4286,7 @@ static bool isSingleTable(SRealTableNode* pRealTable) {
|
|||
return 0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_TABLES) &&
|
||||
0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_TAGS) &&
|
||||
0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_COLS) &&
|
||||
0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USAGE);
|
||||
0 != strcmp(pRealTable->table.tableName, TSDB_INS_DISK_USAGE);
|
||||
}
|
||||
return (TSDB_CHILD_TABLE == tableType || TSDB_NORMAL_TABLE == tableType);
|
||||
}
|
||||
|
@ -13717,6 +13728,18 @@ static int32_t rewriteShowTableDist(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createBlockDBUsageInfoFunc(SFunctionNode** ppNode) {
|
||||
SFunctionNode* pFunc = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&pFunc);
|
||||
if (NULL == pFunc) {
|
||||
return code;
|
||||
}
|
||||
|
||||
strcpy(pFunc->functionName, "_db_usage_info");
|
||||
strcpy(pFunc->node.aliasName, "_db_usage_info");
|
||||
*ppNode = pFunc;
|
||||
return code;
|
||||
}
|
||||
static int32_t createDBUsageFunc(SFunctionNode** ppNode) {
|
||||
SFunctionNode* pFunc = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&pFunc);
|
||||
|
@ -13727,7 +13750,7 @@ static int32_t createDBUsageFunc(SFunctionNode** ppNode) {
|
|||
strcpy(pFunc->functionName, "_db_usage");
|
||||
strcpy(pFunc->node.aliasName, "_db_usage");
|
||||
SFunctionNode* pFuncNew = NULL;
|
||||
code = createBlockDistInfoFunc(&pFuncNew);
|
||||
code = createBlockDBUsageInfoFunc(&pFuncNew);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListMakeStrictAppend(&pFunc->pParameterList, (SNode*)pFuncNew);
|
||||
}
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "planInt.h"
|
||||
#include "filter.h"
|
||||
#include "functionMgt.h"
|
||||
#include "tglobal.h"
|
||||
#include "parser.h"
|
||||
#include "planInt.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
// primary key column always the second column if exists
|
||||
#define PRIMARY_COLUMN_SLOT 1
|
||||
|
@ -164,7 +164,8 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
|
|||
static int32_t rewriteExprForSelect(SNode* pExpr, SSelectStmt* pSelect, ESqlClause clause) {
|
||||
nodesWalkExpr(pExpr, doNameExpr, NULL);
|
||||
bool isPartitionBy = (pSelect->pPartitionByList && pSelect->pPartitionByList->length > 0) ? true : false;
|
||||
SRewriteExprCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pExprs = NULL, .pOutputs = NULL, .isPartitionBy = isPartitionBy};
|
||||
SRewriteExprCxt cxt = {
|
||||
.errCode = TSDB_CODE_SUCCESS, .pExprs = NULL, .pOutputs = NULL, .isPartitionBy = isPartitionBy};
|
||||
cxt.errCode = nodesListMakeAppend(&cxt.pExprs, pExpr);
|
||||
if (TSDB_CODE_SUCCESS == cxt.errCode) {
|
||||
nodesRewriteSelectStmt(pSelect, clause, doRewriteExpr, &cxt);
|
||||
|
@ -198,7 +199,8 @@ static int32_t rewriteExprsForSelect(SNodeList* pExprs, SSelectStmt* pSelect, ES
|
|||
SNodeList** pRewriteExprs) {
|
||||
nodesWalkExprs(pExprs, doNameExpr, NULL);
|
||||
bool isPartitionBy = (pSelect->pPartitionByList && pSelect->pPartitionByList->length > 0) ? true : false;
|
||||
SRewriteExprCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs, .pOutputs = NULL, .isPartitionBy = isPartitionBy};
|
||||
SRewriteExprCxt cxt = {
|
||||
.errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs, .pOutputs = NULL, .isPartitionBy = isPartitionBy};
|
||||
if (NULL != pRewriteExprs) {
|
||||
cxt.pOutputs = taosMemoryCalloc(LIST_LENGTH(pExprs), sizeof(bool));
|
||||
if (NULL == cxt.pOutputs) {
|
||||
|
@ -271,6 +273,10 @@ static EScanType getScanType(SLogicPlanContext* pCxt, SNodeList* pScanPseudoCols
|
|||
}
|
||||
|
||||
if (TSDB_SYSTEM_TABLE == tableType) {
|
||||
// if (NULL != pScanPseudoCols &&
|
||||
// FUNCTION_TYPE_DB_USAGE_INFO == ((SFunctionNode*)nodesListGetNode(pScanPseudoCols, 0))->funcType) {
|
||||
// return SCAN_TYPE_BLOCK_INFO;
|
||||
// }
|
||||
return SCAN_TYPE_SYSTEM_TABLE;
|
||||
}
|
||||
|
||||
|
@ -427,7 +433,8 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesCollectFuncs(pSelect, SQL_CLAUSE_FROM, pRealTable->table.tableAlias, fmIsScanPseudoColumnFunc, &pScan->pScanPseudoCols);
|
||||
code = nodesCollectFuncs(pSelect, SQL_CLAUSE_FROM, pRealTable->table.tableAlias, fmIsScanPseudoColumnFunc,
|
||||
&pScan->pScanPseudoCols);
|
||||
}
|
||||
|
||||
pScan->scanType = getScanType(pCxt, pScan->pScanPseudoCols, pScan->pScanCols, pScan->tableType, pSelect->tagScan);
|
||||
|
@ -555,7 +562,8 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesMakeList(&pJoin->node.pChildren);
|
||||
}
|
||||
pJoin->seqWinGroup = (JOIN_STYPE_WIN == pJoinTable->subType) && (pSelect->hasAggFuncs || pSelect->hasIndefiniteRowsFunc);
|
||||
pJoin->seqWinGroup =
|
||||
(JOIN_STYPE_WIN == pJoinTable->subType) && (pSelect->hasAggFuncs || pSelect->hasIndefiniteRowsFunc);
|
||||
|
||||
SLogicNode* pLeft = NULL;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -649,7 +657,6 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
|
||||
#endif
|
||||
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pLogicNode = (SLogicNode*)pJoin;
|
||||
} else {
|
||||
|
@ -732,11 +739,13 @@ static EGroupAction getDistinctGroupAction(SLogicPlanContext* pCxt, SSelectStmt*
|
|||
}
|
||||
|
||||
static bool isWindowJoinStmt(SSelectStmt* pSelect) {
|
||||
return (QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) && IS_WINDOW_JOIN(((SJoinTableNode*)pSelect->pFromTable)->subType));
|
||||
return (QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) &&
|
||||
IS_WINDOW_JOIN(((SJoinTableNode*)pSelect->pFromTable)->subType));
|
||||
}
|
||||
|
||||
static EGroupAction getGroupAction(SLogicPlanContext* pCxt, SSelectStmt* pSelect) {
|
||||
return ((pCxt->pPlanCxt->streamQuery || NULL != pSelect->pLimit || NULL != pSelect->pSlimit) && !pSelect->isDistinct) ? GROUP_ACTION_KEEP
|
||||
return ((pCxt->pPlanCxt->streamQuery || NULL != pSelect->pLimit || NULL != pSelect->pSlimit) && !pSelect->isDistinct)
|
||||
? GROUP_ACTION_KEEP
|
||||
: GROUP_ACTION_NONE;
|
||||
}
|
||||
|
||||
|
@ -920,7 +929,8 @@ static int32_t createIndefRowsFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt
|
|||
}
|
||||
|
||||
static bool isInterpFunc(int32_t funcId) {
|
||||
return fmIsInterpFunc(funcId) || fmIsInterpPseudoColumnFunc(funcId) || fmIsGroupKeyFunc(funcId) || fmisSelectGroupConstValueFunc(funcId);
|
||||
return fmIsInterpFunc(funcId) || fmIsInterpPseudoColumnFunc(funcId) || fmIsGroupKeyFunc(funcId) ||
|
||||
fmisSelectGroupConstValueFunc(funcId);
|
||||
}
|
||||
|
||||
static int32_t createInterpFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
|
@ -974,7 +984,8 @@ static int32_t createInterpFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* p
|
|||
}
|
||||
|
||||
static bool isForecastFunc(int32_t funcId) {
|
||||
return fmIsForecastFunc(funcId) || fmIsForecastPseudoColumnFunc(funcId) || fmIsGroupKeyFunc(funcId) || fmisSelectGroupConstValueFunc(funcId);
|
||||
return fmIsForecastFunc(funcId) || fmIsForecastPseudoColumnFunc(funcId) || fmIsGroupKeyFunc(funcId) ||
|
||||
fmisSelectGroupConstValueFunc(funcId);
|
||||
}
|
||||
|
||||
static int32_t createForecastFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
|
@ -1337,9 +1348,7 @@ static EDealRes needFillValueImpl(SNode* pNode, void* pContext) {
|
|||
return res;
|
||||
}
|
||||
|
||||
static void needFillValue(SNode* pNode, SWalkFillSubExprCtx* pCtx) {
|
||||
nodesWalkExpr(pNode, needFillValueImpl, pCtx);
|
||||
}
|
||||
static void needFillValue(SNode* pNode, SWalkFillSubExprCtx* pCtx) { nodesWalkExpr(pNode, needFillValueImpl, pCtx); }
|
||||
|
||||
static int32_t collectFillExpr(SNode* pNode, SCollectFillExprsCtx* pCollectFillCtx) {
|
||||
SNode* pNew = NULL;
|
||||
|
@ -1531,7 +1540,8 @@ static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
FOREACH(pNode, pSelect->pProjectionList) {
|
||||
SExprNode* pExpr = (SExprNode*)pNode;
|
||||
if (0 == strcmp(pCol->node.aliasName, pExpr->aliasName)) {
|
||||
pCol->projIdx = projIdx; break;
|
||||
pCol->projIdx = projIdx;
|
||||
break;
|
||||
}
|
||||
projIdx++;
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
|
||||
#include "filter.h"
|
||||
#include "functionMgt.h"
|
||||
#include "parser.h"
|
||||
#include "planInt.h"
|
||||
#include "systable.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttime.h"
|
||||
#include "parser.h"
|
||||
|
||||
#define OPTIMIZE_FLAG_MASK(n) (1 << n)
|
||||
|
||||
|
@ -86,7 +86,6 @@ typedef struct SCpdCollRewriteTableColsCxt {
|
|||
SSHashObj* pRightCols;
|
||||
} SCpdCollRewriteTableColsCxt;
|
||||
|
||||
|
||||
typedef struct SCpdCollectTableColCxt {
|
||||
SSHashObj* pTables;
|
||||
SNodeList* pResCols;
|
||||
|
@ -94,7 +93,6 @@ typedef struct SCpdCollectTableColCxt {
|
|||
int32_t errCode;
|
||||
} SCpdCollectTableColCxt;
|
||||
|
||||
|
||||
typedef enum ECondAction {
|
||||
COND_ACTION_STAY = 1,
|
||||
COND_ACTION_PUSH_JOIN,
|
||||
|
@ -128,8 +126,15 @@ static SJoinOptimizeOpt gJoinOpt[JOIN_TYPE_MAX_VALUE][JOIN_STYPE_MAX_VALUE] = {
|
|||
static SJoinOptimizeOpt gJoinWhereOpt[JOIN_TYPE_MAX_VALUE][JOIN_STYPE_MAX_VALUE] = {
|
||||
/* NONE OUTER SEMI ANTI ASOF WINDOW */
|
||||
/*INNER*/ {{PUSH_DOWN_ALL_COND}, {0}, {0}, {0}, {0}, {0}},
|
||||
/*LEFT*/ {{0}, {PUSH_DOWN_LEFT_FLT}, {PUSH_DOWN_LEFT_FLT}, {PUSH_DOWN_LEFT_FLT}, {PUSH_DOWN_LEFT_FLT}, {PUSH_DOWN_LEFT_FLT}},
|
||||
/*RIGHT*/ {{0}, {PUSH_DOWN_RIGHT_FLT}, {PUSH_DOWN_RIGHT_FLT},{PUSH_DOWN_RIGHT_FLT}, {PUSH_DOWN_RIGHT_FLT}, {PUSH_DOWN_RIGHT_FLT}},
|
||||
/*LEFT*/
|
||||
{{0}, {PUSH_DOWN_LEFT_FLT}, {PUSH_DOWN_LEFT_FLT}, {PUSH_DOWN_LEFT_FLT}, {PUSH_DOWN_LEFT_FLT}, {PUSH_DOWN_LEFT_FLT}},
|
||||
/*RIGHT*/
|
||||
{{0},
|
||||
{PUSH_DOWN_RIGHT_FLT},
|
||||
{PUSH_DOWN_RIGHT_FLT},
|
||||
{PUSH_DOWN_RIGHT_FLT},
|
||||
{PUSH_DOWN_RIGHT_FLT},
|
||||
{PUSH_DOWN_RIGHT_FLT}},
|
||||
/*FULL*/ {{0}, {0}, {0}, {0}, {0}, {0}},
|
||||
};
|
||||
|
||||
|
@ -141,7 +146,6 @@ static SJoinOptimizeOpt gJoinOnOpt[JOIN_TYPE_MAX_VALUE][JOIN_STYPE_MAX_VALUE] =
|
|||
/*FULL*/ {{0}, {0}, {0}, {0}, {0}, {0}},
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
static SLogicNode* optFindPossibleNode(SLogicNode* pNode, FMayBeOptimized func, void* pCtx) {
|
||||
|
@ -589,7 +593,8 @@ static bool pdcColBelongThisTable(SNode* pCondCol, SNodeList* pTableCols) {
|
|||
if (QUERY_NODE_COLUMN == nodeType(pCondCol) && QUERY_NODE_COLUMN == nodeType(pTableCol)) {
|
||||
SColumnNode* pCondColNode = (SColumnNode*)pCondCol;
|
||||
SColumnNode* pTblColNode = (SColumnNode*)pTableCol;
|
||||
if (0 == strcmp(pCondColNode->tableAlias, pTblColNode->tableAlias) && 0 == strcmp(pCondColNode->colName, pTblColNode->colName)) {
|
||||
if (0 == strcmp(pCondColNode->tableAlias, pTblColNode->tableAlias) &&
|
||||
0 == strcmp(pCondColNode->colName, pTblColNode->colName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -645,14 +650,16 @@ static ECondAction pdcJoinGetCondAction(SJoinLogicNode* pJoin, SSHashObj* pLeftT
|
|||
}
|
||||
return COND_ACTION_STAY;
|
||||
}
|
||||
if ((whereCond && gJoinWhereOpt[t][s].pushDownFlag & PUSH_DOWN_LEFT_FLT) || (!whereCond && gJoinOnOpt[t][s].pushDownFlag & PUSH_DOWN_LEFT_FLT)) {
|
||||
if ((whereCond && gJoinWhereOpt[t][s].pushDownFlag & PUSH_DOWN_LEFT_FLT) ||
|
||||
(!whereCond && gJoinOnOpt[t][s].pushDownFlag & PUSH_DOWN_LEFT_FLT)) {
|
||||
return COND_ACTION_PUSH_LEFT_CHILD;
|
||||
}
|
||||
return COND_ACTION_STAY;
|
||||
}
|
||||
|
||||
if (cxt.haveRightCol) {
|
||||
if ((whereCond && gJoinWhereOpt[t][s].pushDownFlag & PUSH_DOWN_RIGHT_FLT) || (!whereCond && gJoinOnOpt[t][s].pushDownFlag & PUSH_DOWN_RIGHT_FLT)) {
|
||||
if ((whereCond && gJoinWhereOpt[t][s].pushDownFlag & PUSH_DOWN_RIGHT_FLT) ||
|
||||
(!whereCond && gJoinOnOpt[t][s].pushDownFlag & PUSH_DOWN_RIGHT_FLT)) {
|
||||
return COND_ACTION_PUSH_RIGHT_CHILD;
|
||||
}
|
||||
return COND_ACTION_STAY;
|
||||
|
@ -693,7 +700,9 @@ static int32_t pdcJoinSplitLogicCond(SJoinLogicNode* pJoin, SNode** pSrcCond, SN
|
|||
ECondAction condAction = pdcJoinGetCondAction(pJoin, pLeftTables, pRightTables, pCond, whereCond);
|
||||
SNode* pNew = NULL;
|
||||
code = nodesCloneNode(pCond, &pNew);
|
||||
if (TSDB_CODE_SUCCESS != code) { break; }
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
}
|
||||
if (COND_ACTION_PUSH_JOIN == condAction && NULL != pOnCond) {
|
||||
code = nodesListMakeAppend(&pOnConds, pNew);
|
||||
} else if (COND_ACTION_PUSH_LEFT_CHILD == condAction) {
|
||||
|
@ -962,9 +971,13 @@ static int32_t pdcJoinIsEqualOnCond(SJoinLogicNode* pJoin, SNode* pCond, bool* a
|
|||
return code;
|
||||
}
|
||||
SOperatorNode* pOper = (SOperatorNode*)pCond;
|
||||
if ((QUERY_NODE_COLUMN != nodeType(pOper->pLeft) && !(QUERY_NODE_OPERATOR == nodeType(pOper->pLeft) && OP_TYPE_JSON_GET_VALUE ==((SOperatorNode*)pOper->pLeft)->opType))
|
||||
|| NULL == pOper->pRight ||
|
||||
(QUERY_NODE_COLUMN != nodeType(pOper->pRight) && !(QUERY_NODE_OPERATOR == nodeType(pOper->pRight) && OP_TYPE_JSON_GET_VALUE ==((SOperatorNode*)pOper->pRight)->opType))) {
|
||||
if ((QUERY_NODE_COLUMN != nodeType(pOper->pLeft) &&
|
||||
!(QUERY_NODE_OPERATOR == nodeType(pOper->pLeft) &&
|
||||
OP_TYPE_JSON_GET_VALUE == ((SOperatorNode*)pOper->pLeft)->opType)) ||
|
||||
NULL == pOper->pRight ||
|
||||
(QUERY_NODE_COLUMN != nodeType(pOper->pRight) &&
|
||||
!(QUERY_NODE_OPERATOR == nodeType(pOper->pRight) &&
|
||||
OP_TYPE_JSON_GET_VALUE == ((SOperatorNode*)pOper->pRight)->opType))) {
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -1191,8 +1204,7 @@ static int32_t pdcJoinCollectColsFromParent(SJoinLogicNode* pJoin, SSHashObj* pT
|
|||
.errCode = TSDB_CODE_SUCCESS,
|
||||
.pTables = pTables,
|
||||
.pResCols = pCondCols,
|
||||
.pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK)
|
||||
};
|
||||
.pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK)};
|
||||
if (NULL == cxt.pColHash) {
|
||||
return terrno;
|
||||
}
|
||||
|
@ -1280,7 +1292,6 @@ static int32_t pdcJoinAddParentOnColsToTarget(SOptimizeContext* pCxt, SJoinLogic
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t pdcJoinAddPreFilterColsToTarget(SOptimizeContext* pCxt, SJoinLogicNode* pJoin) {
|
||||
if (NULL == pJoin->pFullOnCond) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1387,7 +1398,6 @@ static int32_t pdcJoinAddFilterColsToTarget(SOptimizeContext* pCxt, SJoinLogicNo
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t pdcJoinCheckAllCond(SOptimizeContext* pCxt, SJoinLogicNode* pJoin) {
|
||||
if (NULL == pJoin->pFullOnCond) {
|
||||
if (IS_WINDOW_JOIN(pJoin->subType) || IS_ASOF_JOIN(pJoin->subType)) {
|
||||
|
@ -1406,11 +1416,13 @@ static int32_t pdcJoinCheckAllCond(SOptimizeContext* pCxt, SJoinLogicNode* pJoin
|
|||
SNode* pCond = pJoin->pFullOnCond ? pJoin->pFullOnCond : pJoin->node.pConditions;
|
||||
bool errCond = false;
|
||||
if (!pdcJoinHasPrimEqualCond(pJoin, pCond, &errCond)) {
|
||||
if (errCond && !(IS_INNER_NONE_JOIN(pJoin->joinType, pJoin->subType) && NULL != pJoin->pFullOnCond && NULL != pJoin->node.pConditions)) {
|
||||
if (errCond && !(IS_INNER_NONE_JOIN(pJoin->joinType, pJoin->subType) && NULL != pJoin->pFullOnCond &&
|
||||
NULL != pJoin->node.pConditions)) {
|
||||
return generateUsageErrMsg(pCxt->pPlanCxt->pMsg, pCxt->pPlanCxt->msgLen, TSDB_CODE_PLAN_NOT_SUPPORT_JOIN_COND);
|
||||
}
|
||||
|
||||
if (IS_INNER_NONE_JOIN(pJoin->joinType, pJoin->subType) && NULL != pJoin->pFullOnCond && NULL != pJoin->node.pConditions) {
|
||||
if (IS_INNER_NONE_JOIN(pJoin->joinType, pJoin->subType) && NULL != pJoin->pFullOnCond &&
|
||||
NULL != pJoin->node.pConditions) {
|
||||
if (pdcJoinHasPrimEqualCond(pJoin, pJoin->node.pConditions, &errCond)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1456,13 +1468,15 @@ static int32_t pdcJoinHandleGrpJoinCond(SOptimizeContext* pCxt, SJoinLogicNode*
|
|||
FOREACH(pNode, pJoin->pLeftEqNodes) {
|
||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||
if (COLUMN_TYPE_TAG != pCol->colType && PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId) {
|
||||
return generateUsageErrMsg(pCxt->pPlanCxt->pMsg, pCxt->pPlanCxt->msgLen, TSDB_CODE_PLAN_NOT_SUPPORT_JOIN_COND);
|
||||
return generateUsageErrMsg(pCxt->pPlanCxt->pMsg, pCxt->pPlanCxt->msgLen,
|
||||
TSDB_CODE_PLAN_NOT_SUPPORT_JOIN_COND);
|
||||
}
|
||||
}
|
||||
FOREACH(pNode, pJoin->pRightEqNodes) {
|
||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||
if (COLUMN_TYPE_TAG != pCol->colType && PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId) {
|
||||
return generateUsageErrMsg(pCxt->pPlanCxt->pMsg, pCxt->pPlanCxt->msgLen, TSDB_CODE_PLAN_NOT_SUPPORT_JOIN_COND);
|
||||
return generateUsageErrMsg(pCxt->pPlanCxt->pMsg, pCxt->pPlanCxt->msgLen,
|
||||
TSDB_CODE_PLAN_NOT_SUPPORT_JOIN_COND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1500,9 +1514,13 @@ static EDealRes pdcCheckTableCondType(SNode* pNode, void* pContext) {
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static int32_t pdcJoinGetOpTableCondTypes(SNode* pCond, SSHashObj* pLeftTables, SSHashObj* pRightTables, bool* tableCondTypes) {
|
||||
SCpdIsMultiTableCondCxt cxt = {
|
||||
.pLeftTbls = pLeftTables, .pRightTbls = pRightTables, .havaLeftCol = false, .haveRightCol = false, .condIsNull = false};
|
||||
static int32_t pdcJoinGetOpTableCondTypes(SNode* pCond, SSHashObj* pLeftTables, SSHashObj* pRightTables,
|
||||
bool* tableCondTypes) {
|
||||
SCpdIsMultiTableCondCxt cxt = {.pLeftTbls = pLeftTables,
|
||||
.pRightTbls = pRightTables,
|
||||
.havaLeftCol = false,
|
||||
.haveRightCol = false,
|
||||
.condIsNull = false};
|
||||
nodesWalkExpr(pCond, pdcCheckTableCondType, &cxt);
|
||||
|
||||
if (cxt.havaLeftCol) {
|
||||
|
@ -1537,9 +1555,8 @@ static int32_t pdcJoinGetOpTableCondTypes(SNode* pCond, SSHashObj* pLeftTables,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int32_t pdcJoinGetLogicTableCondTypes(SNode* pCond, SSHashObj* pLeftTables, SSHashObj* pRightTables, bool* tableCondTypes) {
|
||||
static int32_t pdcJoinGetLogicTableCondTypes(SNode* pCond, SSHashObj* pLeftTables, SSHashObj* pRightTables,
|
||||
bool* tableCondTypes) {
|
||||
SLogicConditionNode* pLogicCond = (SLogicConditionNode*)pCond;
|
||||
int32_t code = 0;
|
||||
SNode* pSCond = NULL;
|
||||
|
@ -1558,7 +1575,8 @@ static int32_t pdcJoinGetLogicTableCondTypes(SNode* pCond, SSHashObj* pLeftTable
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t pdcGetTableCondTypes(SNode* pCond, SSHashObj* pLeftTables, SSHashObj* pRightTables, bool* tableCondTypes) {
|
||||
static int32_t pdcGetTableCondTypes(SNode* pCond, SSHashObj* pLeftTables, SSHashObj* pRightTables,
|
||||
bool* tableCondTypes) {
|
||||
if (QUERY_NODE_LOGIC_CONDITION == nodeType(pCond)) {
|
||||
return pdcJoinGetLogicTableCondTypes(pCond, pLeftTables, pRightTables, tableCondTypes);
|
||||
} else {
|
||||
|
@ -1639,8 +1657,12 @@ static EDealRes pdcCheckTableResType(SNode* pNode, void* pContext) {
|
|||
break;
|
||||
case QUERY_NODE_FUNCTION: {
|
||||
SFunctionNode* pFunc = (SFunctionNode*)pNode;
|
||||
SCpdIsMultiTableResCxt cxt = {.pLeftTbls = pCxt->pLeftTbls, .pRightTbls = pCxt->pRightTbls,
|
||||
.haveLeftCol = false, .haveRightCol = false, .leftColNonNull = true, .rightColNonNull = true};
|
||||
SCpdIsMultiTableResCxt cxt = {.pLeftTbls = pCxt->pLeftTbls,
|
||||
.pRightTbls = pCxt->pRightTbls,
|
||||
.haveLeftCol = false,
|
||||
.haveRightCol = false,
|
||||
.leftColNonNull = true,
|
||||
.rightColNonNull = true};
|
||||
|
||||
nodesWalkExprs(pFunc->pParameterList, pdcCheckTableResType, &cxt);
|
||||
if (!cxt.leftColNonNull) {
|
||||
|
@ -1714,8 +1736,14 @@ static int32_t pdcRewriteTypeBasedOnJoinRes(SOptimizeContext* pCxt, SJoinLogicNo
|
|||
tableResNonNull[0] = false;
|
||||
tableResNonNull[1] = false;
|
||||
} else {
|
||||
SCpdIsMultiTableResCxt cxt = {.pLeftTbls = pLeftTables, .pRightTbls = pRightTables,
|
||||
.haveLeftCol = false, .haveRightCol = false, .leftColNonNull = true, .rightColNonNull = true, .leftColOp = false, .rightColOp = false};
|
||||
SCpdIsMultiTableResCxt cxt = {.pLeftTbls = pLeftTables,
|
||||
.pRightTbls = pRightTables,
|
||||
.haveLeftCol = false,
|
||||
.haveRightCol = false,
|
||||
.leftColNonNull = true,
|
||||
.rightColNonNull = true,
|
||||
.leftColOp = false,
|
||||
.rightColOp = false};
|
||||
|
||||
nodesWalkExprs(pAgg->pAggFuncs, pdcCheckTableResType, &cxt);
|
||||
if (!cxt.leftColNonNull) {
|
||||
|
@ -1796,7 +1824,8 @@ static int32_t pdcDealJoin(SOptimizeContext* pCxt, SJoinLogicNode* pJoin) {
|
|||
code = pdcPushDownCondToChild(pCxt, (SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0), &pLeftChildCond);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pRightChildCond) {
|
||||
code = pdcPushDownCondToChild(pCxt, (SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1), &pRightChildCond);
|
||||
code =
|
||||
pdcPushDownCondToChild(pCxt, (SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1), &pRightChildCond);
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoin->node.pConditions) {
|
||||
|
@ -1826,7 +1855,8 @@ static int32_t pdcDealJoin(SOptimizeContext* pCxt, SJoinLogicNode* pJoin) {
|
|||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoin->pFullOnCond && !IS_WINDOW_JOIN(pJoin->subType) && NULL == pJoin->addPrimEqCond) {
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoin->pFullOnCond && !IS_WINDOW_JOIN(pJoin->subType) &&
|
||||
NULL == pJoin->addPrimEqCond) {
|
||||
code = pdcJoinSplitPrimEqCond(pCxt, pJoin);
|
||||
}
|
||||
|
||||
|
@ -2144,7 +2174,6 @@ static int32_t pdcOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan)
|
|||
return pdcOptimizeImpl(pCxt, pLogicSubplan->pNode);
|
||||
}
|
||||
|
||||
|
||||
static bool eliminateNotNullCondMayBeOptimized(SLogicNode* pNode, void* pCtx) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode)) {
|
||||
return false;
|
||||
|
@ -2219,7 +2248,6 @@ static int32_t eliminateNotNullCondOptimize(SOptimizeContext* pCxt, SLogicSubpla
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static bool sortPriKeyOptIsPriKeyOrderBy(SNodeList* pSortKeys) {
|
||||
if (1 != LIST_LENGTH(pSortKeys)) {
|
||||
return false;
|
||||
|
@ -2254,7 +2282,8 @@ static bool sortPriKeyOptMayBeOptimized(SLogicNode* pNode, void* pCtx) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static int32_t sortPriKeyOptHandleLeftRightJoinSort(SJoinLogicNode* pJoin, SSortLogicNode* pSort, bool* pNotOptimize, bool* keepSort) {
|
||||
static int32_t sortPriKeyOptHandleLeftRightJoinSort(SJoinLogicNode* pJoin, SSortLogicNode* pSort, bool* pNotOptimize,
|
||||
bool* keepSort) {
|
||||
if (JOIN_STYPE_SEMI == pJoin->subType || JOIN_STYPE_NONE == pJoin->subType) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -2320,9 +2349,8 @@ static int32_t sortPriKeyOptHandleLeftRightJoinSort(SJoinLogicNode* pJoin, SSort
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int32_t sortPriKeyOptHandleJoinSort(SLogicNode* pNode, bool groupSort, SSortLogicNode* pSort,
|
||||
bool* pNotOptimize, SNodeList** pSequencingNodes, bool* keepSort) {
|
||||
static int32_t sortPriKeyOptHandleJoinSort(SLogicNode* pNode, bool groupSort, SSortLogicNode* pSort, bool* pNotOptimize,
|
||||
SNodeList** pSequencingNodes, bool* keepSort) {
|
||||
SJoinLogicNode* pJoin = (SJoinLogicNode*)pNode;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -2342,22 +2370,20 @@ static int32_t sortPriKeyOptHandleJoinSort(SLogicNode* pNode, bool groupSort, SS
|
|||
break;
|
||||
}
|
||||
|
||||
code = sortPriKeyOptGetSequencingNodesImpl((SLogicNode*)nodesListGetNode(pNode->pChildren, 0), groupSort,
|
||||
pSort, pNotOptimize, pSequencingNodes, keepSort);
|
||||
code = sortPriKeyOptGetSequencingNodesImpl((SLogicNode*)nodesListGetNode(pNode->pChildren, 0), groupSort, pSort,
|
||||
pNotOptimize, pSequencingNodes, keepSort);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = sortPriKeyOptGetSequencingNodesImpl((SLogicNode*)nodesListGetNode(pNode->pChildren, 1), groupSort,
|
||||
pSort, pNotOptimize, pSequencingNodes, keepSort);
|
||||
code = sortPriKeyOptGetSequencingNodesImpl((SLogicNode*)nodesListGetNode(pNode->pChildren, 1), groupSort, pSort,
|
||||
pNotOptimize, pSequencingNodes, keepSort);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
static EOrder sortPriKeyOptGetPriKeyOrder(SSortLogicNode* pSort) {
|
||||
return ((SOrderByExprNode*)nodesListGetNode(pSort->pSortKeys, 0))->order;
|
||||
}
|
||||
|
||||
|
||||
static bool sortPriKeyOptHasUnsupportedPkFunc(SLogicNode* pLogicNode, EOrder sortOrder) {
|
||||
if (sortOrder == ORDER_ASC) {
|
||||
return false;
|
||||
|
@ -2393,10 +2419,8 @@ static bool sortPriKeyOptHasUnsupportedPkFunc(SLogicNode* pLogicNode, EOrder sor
|
|||
}
|
||||
SFunctionNode* pFuncNode = (SFunctionNode*)pLogicNode;
|
||||
if (pFuncNode->hasPk &&
|
||||
(pFuncNode->funcType == FUNCTION_TYPE_DIFF ||
|
||||
pFuncNode->funcType == FUNCTION_TYPE_DERIVATIVE ||
|
||||
pFuncNode->funcType == FUNCTION_TYPE_IRATE ||
|
||||
pFuncNode->funcType == FUNCTION_TYPE_TWA)) {
|
||||
(pFuncNode->funcType == FUNCTION_TYPE_DIFF || pFuncNode->funcType == FUNCTION_TYPE_DERIVATIVE ||
|
||||
pFuncNode->funcType == FUNCTION_TYPE_IRATE || pFuncNode->funcType == FUNCTION_TYPE_TWA)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2459,11 +2483,10 @@ int32_t sortPriKeyOptGetSequencingNodesImpl(SLogicNode* pNode, bool groupSort, S
|
|||
pNotOptimize, pSequencingNodes, keepSort);
|
||||
}
|
||||
|
||||
|
||||
static int32_t sortPriKeyOptGetSequencingNodes(SSortLogicNode* pSort, bool groupSort, SNodeList** pSequencingNodes, bool* keepSort) {
|
||||
static int32_t sortPriKeyOptGetSequencingNodes(SSortLogicNode* pSort, bool groupSort, SNodeList** pSequencingNodes,
|
||||
bool* keepSort) {
|
||||
bool notOptimize = false;
|
||||
int32_t code =
|
||||
sortPriKeyOptGetSequencingNodesImpl((SLogicNode*)nodesListGetNode(pSort->node.pChildren, 0), groupSort,
|
||||
int32_t code = sortPriKeyOptGetSequencingNodesImpl((SLogicNode*)nodesListGetNode(pSort->node.pChildren, 0), groupSort,
|
||||
pSort, ¬Optimize, pSequencingNodes, keepSort);
|
||||
if (TSDB_CODE_SUCCESS != code || notOptimize) {
|
||||
NODES_CLEAR_LIST(*pSequencingNodes);
|
||||
|
@ -2555,12 +2578,14 @@ static int32_t sortForJoinOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan* pL
|
|||
EOrder targetOrder = 0;
|
||||
SSHashObj* pTables = NULL;
|
||||
|
||||
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pLeft) && ((SScanLogicNode*)pLeft)->node.outputTsOrder != SCAN_ORDER_BOTH) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pLeft) &&
|
||||
((SScanLogicNode*)pLeft)->node.outputTsOrder != SCAN_ORDER_BOTH) {
|
||||
pScan = (SScanLogicNode*)pLeft;
|
||||
pChild = pRight;
|
||||
pChildPos = &pJoin->node.pChildren->pTail->pNode;
|
||||
targetOrder = pScan->node.outputTsOrder;
|
||||
} else if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pRight) && ((SScanLogicNode*)pRight)->node.outputTsOrder != SCAN_ORDER_BOTH) {
|
||||
} else if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pRight) &&
|
||||
((SScanLogicNode*)pRight)->node.outputTsOrder != SCAN_ORDER_BOTH) {
|
||||
pScan = (SScanLogicNode*)pRight;
|
||||
pChild = pLeft;
|
||||
pChildPos = &pJoin->node.pChildren->pHead->pNode;
|
||||
|
@ -2587,9 +2612,11 @@ static int32_t sortForJoinOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan* pL
|
|||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
if (NULL != tSimpleHashGet(pTables, ((SColumnNode*)pOp->pLeft)->tableAlias, strlen(((SColumnNode*)pOp->pLeft)->tableAlias))) {
|
||||
if (NULL !=
|
||||
tSimpleHashGet(pTables, ((SColumnNode*)pOp->pLeft)->tableAlias, strlen(((SColumnNode*)pOp->pLeft)->tableAlias))) {
|
||||
pOrderByNode = pOp->pLeft;
|
||||
} else if (NULL != tSimpleHashGet(pTables, ((SColumnNode*)pOp->pRight)->tableAlias, strlen(((SColumnNode*)pOp->pRight)->tableAlias))) {
|
||||
} else if (NULL != tSimpleHashGet(pTables, ((SColumnNode*)pOp->pRight)->tableAlias,
|
||||
strlen(((SColumnNode*)pOp->pRight)->tableAlias))) {
|
||||
pOrderByNode = pOp->pRight;
|
||||
}
|
||||
|
||||
|
@ -2641,7 +2668,8 @@ static int32_t sortForJoinOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan* pL
|
|||
return code;
|
||||
}
|
||||
*pChildPos = (SNode*)pSort;
|
||||
pSort->node.pParent = (SLogicNode*)pJoin;;
|
||||
pSort->node.pParent = (SLogicNode*)pJoin;
|
||||
;
|
||||
|
||||
_return:
|
||||
|
||||
|
@ -2650,7 +2678,6 @@ _return:
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static bool sortForJoinOptMayBeOptimized(SLogicNode* pNode, void* pCtx) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_JOIN != nodeType(pNode)) {
|
||||
return false;
|
||||
|
@ -2678,9 +2705,9 @@ static bool sortForJoinOptMayBeOptimized(SLogicNode* pNode, void* pCtx) {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
static int32_t sortForJoinOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan) {
|
||||
SJoinLogicNode* pJoin = (SJoinLogicNode*)optFindPossibleNode(pLogicSubplan->pNode, sortForJoinOptMayBeOptimized, NULL);
|
||||
SJoinLogicNode* pJoin =
|
||||
(SJoinLogicNode*)optFindPossibleNode(pLogicSubplan->pNode, sortForJoinOptMayBeOptimized, NULL);
|
||||
if (NULL == pJoin) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -2723,14 +2750,15 @@ static int32_t joinCondGetAllScanNodes(SLogicNode* pNode, SNodeList** pList) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static bool joinCondMayBeOptimized(SLogicNode* pNode, void* pCtx) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_JOIN != nodeType(pNode) || OPTIMIZE_FLAG_TEST_MASK(pNode->optimizedFlag, OPTIMIZE_FLAG_JOIN_COND)) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_JOIN != nodeType(pNode) ||
|
||||
OPTIMIZE_FLAG_TEST_MASK(pNode->optimizedFlag, OPTIMIZE_FLAG_JOIN_COND)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SJoinLogicNode* pJoin = (SJoinLogicNode*)pNode;
|
||||
if (pNode->pChildren->length != 2 || JOIN_STYPE_ASOF == pJoin->subType || JOIN_STYPE_WIN == pJoin->subType || JOIN_TYPE_FULL == pJoin->joinType) {
|
||||
if (pNode->pChildren->length != 2 || JOIN_STYPE_ASOF == pJoin->subType || JOIN_STYPE_WIN == pJoin->subType ||
|
||||
JOIN_TYPE_FULL == pJoin->joinType) {
|
||||
OPTIMIZE_FLAG_SET_MASK(pNode->optimizedFlag, OPTIMIZE_FLAG_JOIN_COND);
|
||||
return false;
|
||||
}
|
||||
|
@ -2738,21 +2766,26 @@ static bool joinCondMayBeOptimized(SLogicNode* pNode, void* pCtx) {
|
|||
SLogicNode* pLeft = (SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0);
|
||||
SLogicNode* pRight = (SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1);
|
||||
|
||||
if ((JOIN_TYPE_LEFT == pJoin->joinType || JOIN_TYPE_RIGHT == pJoin->joinType) && (QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pLeft) || QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pRight))) {
|
||||
if ((JOIN_TYPE_LEFT == pJoin->joinType || JOIN_TYPE_RIGHT == pJoin->joinType) &&
|
||||
(QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pLeft) || QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pRight))) {
|
||||
OPTIMIZE_FLAG_SET_MASK(pNode->optimizedFlag, OPTIMIZE_FLAG_JOIN_COND);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (JOIN_TYPE_INNER == pJoin->joinType && ((QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pLeft) && QUERY_NODE_LOGIC_PLAN_JOIN != nodeType(pLeft)) || (QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pRight) && QUERY_NODE_LOGIC_PLAN_JOIN != nodeType(pRight)))) {
|
||||
if (JOIN_TYPE_INNER == pJoin->joinType &&
|
||||
((QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pLeft) && QUERY_NODE_LOGIC_PLAN_JOIN != nodeType(pLeft)) ||
|
||||
(QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pRight) && QUERY_NODE_LOGIC_PLAN_JOIN != nodeType(pRight)))) {
|
||||
OPTIMIZE_FLAG_SET_MASK(pNode->optimizedFlag, OPTIMIZE_FLAG_JOIN_COND);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (JOIN_TYPE_INNER == pJoin->joinType) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_JOIN == nodeType(pLeft) && !OPTIMIZE_FLAG_TEST_MASK(pLeft->optimizedFlag, OPTIMIZE_FLAG_JOIN_COND)) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_JOIN == nodeType(pLeft) &&
|
||||
!OPTIMIZE_FLAG_TEST_MASK(pLeft->optimizedFlag, OPTIMIZE_FLAG_JOIN_COND)) {
|
||||
return false;
|
||||
}
|
||||
if (QUERY_NODE_LOGIC_PLAN_JOIN == nodeType(pRight) && !OPTIMIZE_FLAG_TEST_MASK(pRight->optimizedFlag, OPTIMIZE_FLAG_JOIN_COND)) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_JOIN == nodeType(pRight) &&
|
||||
!OPTIMIZE_FLAG_TEST_MASK(pRight->optimizedFlag, OPTIMIZE_FLAG_JOIN_COND)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -2801,9 +2834,7 @@ static int32_t joinCondOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSub
|
|||
}
|
||||
SNode* pNode = NULL;
|
||||
STimeWindow scanRange = TSWINDOW_INITIALIZER;
|
||||
FOREACH(pNode, pScanList) {
|
||||
joinCondMergeScanRand(&scanRange, &((SScanLogicNode*)pNode)->scanRange);
|
||||
}
|
||||
FOREACH(pNode, pScanList) { joinCondMergeScanRand(&scanRange, &((SScanLogicNode*)pNode)->scanRange); }
|
||||
FOREACH(pNode, pScanList) {
|
||||
((SScanLogicNode*)pNode)->scanRange.skey = scanRange.skey;
|
||||
((SScanLogicNode*)pNode)->scanRange.ekey = scanRange.ekey;
|
||||
|
@ -3348,7 +3379,8 @@ static int32_t eliminateProjOptCheckProjColumnNames(SProjectLogicNode* pProjectN
|
|||
|
||||
static bool eliminateProjOptMayBeOptimized(SLogicNode* pNode, void* pCtx) {
|
||||
// Super table scan requires project operator to merge packets to improve performance.
|
||||
if (NULL == pNode->pParent && (QUERY_NODE_LOGIC_PLAN_PROJECT != nodeType(pNode) || 1 != LIST_LENGTH(pNode->pChildren) ||
|
||||
if (NULL == pNode->pParent &&
|
||||
(QUERY_NODE_LOGIC_PLAN_PROJECT != nodeType(pNode) || 1 != LIST_LENGTH(pNode->pChildren) ||
|
||||
(QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(nodesListGetNode(pNode->pChildren, 0)) &&
|
||||
TSDB_SUPER_TABLE == ((SScanLogicNode*)nodesListGetNode(pNode->pChildren, 0))->tableType))) {
|
||||
return false;
|
||||
|
@ -3358,8 +3390,10 @@ static bool eliminateProjOptMayBeOptimized(SLogicNode* pNode, void* pCtx) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (NULL != pNode->pParent && (QUERY_NODE_LOGIC_PLAN_PROJECT != nodeType(pNode) || 1 != LIST_LENGTH(pNode->pChildren) ||
|
||||
QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(nodesListGetNode(pNode->pChildren, 0)) || QUERY_NODE_LOGIC_PLAN_JOIN != nodeType(pNode->pParent))) {
|
||||
if (NULL != pNode->pParent &&
|
||||
(QUERY_NODE_LOGIC_PLAN_PROJECT != nodeType(pNode) || 1 != LIST_LENGTH(pNode->pChildren) ||
|
||||
QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(nodesListGetNode(pNode->pChildren, 0)) ||
|
||||
QUERY_NODE_LOGIC_PLAN_JOIN != nodeType(pNode->pParent))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -3476,7 +3510,6 @@ static EDealRes eliminateProjOptRewriteScanTableAlias(SNode* pNode, void* pConte
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
static void eliminateProjPushdownProjIdx(SNodeList* pParentProjects, SNodeList* pChildTargets) {
|
||||
SNode *pChildTarget = NULL, *pParentProject = NULL;
|
||||
FOREACH(pChildTarget, pChildTargets) {
|
||||
|
@ -4093,9 +4126,13 @@ static bool lastRowScanOptCheckColNum(int32_t lastColNum, col_id_t lastColId, in
|
|||
|
||||
static bool isNeedSplitCacheLastFunc(SFunctionNode* pFunc, SScanLogicNode* pScan) {
|
||||
int32_t funcType = pFunc->funcType;
|
||||
if ((FUNCTION_TYPE_LAST_ROW != funcType || (FUNCTION_TYPE_LAST_ROW == funcType && TSDB_CACHE_MODEL_LAST_VALUE == pScan->cacheLastMode)) &&
|
||||
(FUNCTION_TYPE_LAST != funcType || (FUNCTION_TYPE_LAST == funcType && (TSDB_CACHE_MODEL_LAST_ROW == pScan->cacheLastMode ||
|
||||
QUERY_NODE_OPERATOR == nodeType(nodesListGetNode(pFunc->pParameterList, 0)) || QUERY_NODE_VALUE == nodeType(nodesListGetNode(pFunc->pParameterList, 0)) ||
|
||||
if ((FUNCTION_TYPE_LAST_ROW != funcType ||
|
||||
(FUNCTION_TYPE_LAST_ROW == funcType && TSDB_CACHE_MODEL_LAST_VALUE == pScan->cacheLastMode)) &&
|
||||
(FUNCTION_TYPE_LAST != funcType ||
|
||||
(FUNCTION_TYPE_LAST == funcType &&
|
||||
(TSDB_CACHE_MODEL_LAST_ROW == pScan->cacheLastMode ||
|
||||
QUERY_NODE_OPERATOR == nodeType(nodesListGetNode(pFunc->pParameterList, 0)) ||
|
||||
QUERY_NODE_VALUE == nodeType(nodesListGetNode(pFunc->pParameterList, 0)) ||
|
||||
COLUMN_TYPE_COLUMN != ((SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0))->colType))) &&
|
||||
FUNCTION_TYPE_SELECT_VALUE != funcType && FUNCTION_TYPE_GROUP_KEY != funcType) {
|
||||
return true;
|
||||
|
@ -4124,8 +4161,7 @@ static bool lastRowScanOptCheckFuncList(SLogicNode* pNode, int8_t cacheLastModel
|
|||
lastColId = pCol->colId;
|
||||
lastColNum++;
|
||||
}
|
||||
}
|
||||
else if (QUERY_NODE_VALUE == nodeType(pParam) || QUERY_NODE_OPERATOR == nodeType(pParam)) {
|
||||
} else if (QUERY_NODE_VALUE == nodeType(pParam) || QUERY_NODE_OPERATOR == nodeType(pParam)) {
|
||||
needSplitFuncCount++;
|
||||
*hasOtherFunc = true;
|
||||
}
|
||||
|
@ -4171,7 +4207,8 @@ static bool lastRowScanOptCheckFuncList(SLogicNode* pNode, int8_t cacheLastModel
|
|||
}
|
||||
|
||||
static bool lastRowScanOptCheckLastCache(SAggLogicNode* pAgg, SScanLogicNode* pScan) {
|
||||
if ((pAgg->hasLastRow == pAgg->hasLast && !pAgg->hasLastRow) || (!pAgg->hasLast && !pAgg->hasLastRow) || NULL != pAgg->pGroupKeys || NULL != pScan->node.pConditions ||
|
||||
if ((pAgg->hasLastRow == pAgg->hasLast && !pAgg->hasLastRow) || (!pAgg->hasLast && !pAgg->hasLastRow) ||
|
||||
NULL != pAgg->pGroupKeys || NULL != pScan->node.pConditions ||
|
||||
!hasSuitableCache(pScan->cacheLastMode, pAgg->hasLastRow, pAgg->hasLast) ||
|
||||
IS_TSWINDOW_SPECIFIED(pScan->scanRange)) {
|
||||
return false;
|
||||
|
@ -4236,7 +4273,8 @@ static EDealRes lastRowScanOptSetColDataType(SNode* pNode, void* pContext) {
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static void lastRowScanOptSetLastTargets(SNodeList* pTargets, SNodeList* pLastCols, SNodeList* pLastRowCols, bool erase, int32_t pkBytes) {
|
||||
static void lastRowScanOptSetLastTargets(SNodeList* pTargets, SNodeList* pLastCols, SNodeList* pLastRowCols, bool erase,
|
||||
int32_t pkBytes) {
|
||||
SNode* pTarget = NULL;
|
||||
WHERE_EACH(pTarget, pTargets) {
|
||||
bool found = false;
|
||||
|
@ -4260,7 +4298,8 @@ static void lastRowScanOptSetLastTargets(SNodeList* pTargets, SNodeList* pLastCo
|
|||
}
|
||||
}
|
||||
|
||||
static void lastRowScanOptRemoveUslessTargets(SNodeList* pTargets, SNodeList* pList1, SNodeList* pList2, SNodeList* pList3) {
|
||||
static void lastRowScanOptRemoveUslessTargets(SNodeList* pTargets, SNodeList* pList1, SNodeList* pList2,
|
||||
SNodeList* pList3) {
|
||||
SNode* pTarget = NULL;
|
||||
WHERE_EACH(pTarget, pTargets) {
|
||||
bool found = false;
|
||||
|
@ -4455,7 +4494,8 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
|
|||
}
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) break;;
|
||||
if (TSDB_CODE_SUCCESS != code) break;
|
||||
;
|
||||
FOREACH(pColNode, pScan->pScanPseudoCols) {
|
||||
if (nodesEqualNode(pParamNode, pColNode)) {
|
||||
if (funcType != FUNCTION_TYPE_LAST) {
|
||||
|
@ -4472,7 +4512,8 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
|
|||
|
||||
if (TSDB_CODE_SUCCESS != code) break;
|
||||
if (pFunc->hasPk) {
|
||||
code = nodesListMakeAppend(&cxt.pOtherCols, nodesListGetNode(pFunc->pParameterList, LIST_LENGTH(pFunc->pParameterList) - 1));
|
||||
code = nodesListMakeAppend(&cxt.pOtherCols,
|
||||
nodesListGetNode(pFunc->pParameterList, LIST_LENGTH(pFunc->pParameterList) - 1));
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) break;
|
||||
} else {
|
||||
|
@ -4769,7 +4810,8 @@ static int32_t splitCacheLastFuncOptCreateMergeLogicNode(SMergeLogicNode** pNew,
|
|||
}
|
||||
|
||||
static int32_t splitCacheLastFuncOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan) {
|
||||
SAggLogicNode* pAgg = (SAggLogicNode*)optFindPossibleNode(pLogicSubplan->pNode, splitCacheLastFuncOptMayBeOptimized, NULL);
|
||||
SAggLogicNode* pAgg =
|
||||
(SAggLogicNode*)optFindPossibleNode(pLogicSubplan->pNode, splitCacheLastFuncOptMayBeOptimized, NULL);
|
||||
|
||||
if (NULL == pAgg) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -5023,7 +5065,8 @@ static bool tagScanOptShouldBeOptimized(SLogicNode* pNode, void* pCtx) {
|
|||
}
|
||||
|
||||
static int32_t tagScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan) {
|
||||
SScanLogicNode* pScanNode = (SScanLogicNode*)optFindPossibleNode(pLogicSubplan->pNode, tagScanOptShouldBeOptimized, NULL);
|
||||
SScanLogicNode* pScanNode =
|
||||
(SScanLogicNode*)optFindPossibleNode(pLogicSubplan->pNode, tagScanOptShouldBeOptimized, NULL);
|
||||
if (NULL == pScanNode) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -5189,7 +5232,8 @@ static int32_t pushDownLimitHow(SLogicNode* pNodeWithLimit, SLogicNode* pNodeLim
|
|||
return pushDownLimitTo(pNodeWithLimit, pNodeLimitPushTo, pPushed);
|
||||
case QUERY_NODE_LOGIC_PLAN_SORT: {
|
||||
SSortLogicNode* pSort = (SSortLogicNode*)pNodeWithLimit;
|
||||
if (sortPriKeyOptIsPriKeyOrderBy(pSort->pSortKeys)) return pushDownLimitTo(pNodeWithLimit, pNodeLimitPushTo, pPushed);
|
||||
if (sortPriKeyOptIsPriKeyOrderBy(pSort->pSortKeys))
|
||||
return pushDownLimitTo(pNodeWithLimit, pNodeLimitPushTo, pPushed);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
@ -5346,7 +5390,7 @@ static bool tbCntScanOptIsEligibleConds(STbCntScanOptInfo* pInfo, SNode* pCondit
|
|||
static bool tbCntScanOptIsEligibleScan(STbCntScanOptInfo* pInfo) {
|
||||
if (0 != strcmp(pInfo->pScan->tableName.dbname, TSDB_INFORMATION_SCHEMA_DB) ||
|
||||
0 != strcmp(pInfo->pScan->tableName.tname, TSDB_INS_TABLE_TABLES) || NULL != pInfo->pScan->pGroupTags ||
|
||||
0 != strcmp(pInfo->pScan->tableName.tname, TSDB_INS_TABLE_USAGE)) {
|
||||
0 != strcmp(pInfo->pScan->tableName.tname, TSDB_INS_DISK_USAGE)) {
|
||||
return false;
|
||||
}
|
||||
if (1 == pInfo->pScan->pVgroupList->numOfVgroups && MNODE_HANDLE == pInfo->pScan->pVgroupList->vgroups[0].vgId) {
|
||||
|
@ -5554,7 +5598,8 @@ static bool hashJoinOptShouldBeOptimized(SLogicNode* pNode, void* pCtx) {
|
|||
goto _return;
|
||||
}
|
||||
|
||||
if ((JOIN_STYPE_NONE != pJoin->subType && JOIN_STYPE_OUTER != pJoin->subType) || JOIN_TYPE_FULL == pJoin->joinType || pNode->pChildren->length != 2 ) {
|
||||
if ((JOIN_STYPE_NONE != pJoin->subType && JOIN_STYPE_OUTER != pJoin->subType) || JOIN_TYPE_FULL == pJoin->joinType ||
|
||||
pNode->pChildren->length != 2) {
|
||||
goto _return;
|
||||
}
|
||||
|
||||
|
@ -5623,7 +5668,6 @@ static int32_t hashJoinOptSplitPrimFromLogicCond(SNode **pCondition, SNode **pPr
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
int32_t hashJoinOptSplitPrimCond(SNode** pCondition, SNode** pPrimaryKeyCond) {
|
||||
if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pCondition)) {
|
||||
if (LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)*pCondition)->condType) {
|
||||
|
@ -5652,7 +5696,6 @@ int32_t hashJoinOptSplitPrimCond(SNode **pCondition, SNode **pPrimaryKeyCond) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int32_t hashJoinOptRewriteJoin(SOptimizeContext* pCxt, SLogicNode* pNode, SLogicSubplan* pLogicSubplan) {
|
||||
SJoinLogicNode* pJoin = (SJoinLogicNode*)pNode;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
@ -5843,7 +5886,6 @@ static int32_t hashJoinOptRewriteJoin(SOptimizeContext* pCxt, SLogicNode* pNode,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int32_t hashJoinOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan) {
|
||||
int32_t code = 0;
|
||||
SLogicNode* pNode = optFindPossibleNode(pLogicSubplan->pNode, hashJoinOptShouldBeOptimized, &code);
|
||||
|
@ -5858,7 +5900,8 @@ static int32_t hashJoinOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSub
|
|||
}
|
||||
|
||||
static bool stbJoinOptShouldBeOptimized(SLogicNode* pNode, void* pCtx) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_JOIN != nodeType(pNode) || OPTIMIZE_FLAG_TEST_MASK(pNode->optimizedFlag, OPTIMIZE_FLAG_STB_JOIN)) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_JOIN != nodeType(pNode) ||
|
||||
OPTIMIZE_FLAG_TEST_MASK(pNode->optimizedFlag, OPTIMIZE_FLAG_STB_JOIN)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -5867,8 +5910,8 @@ static bool stbJoinOptShouldBeOptimized(SLogicNode* pNode, void* pCtx) {
|
|||
pJoin->joinAlgo = JOIN_ALGO_MERGE;
|
||||
}
|
||||
|
||||
if (JOIN_STYPE_NONE != pJoin->subType || pJoin->isSingleTableJoin || NULL == pJoin->pTagEqCond || pNode->pChildren->length != 2
|
||||
|| pJoin->isLowLevelJoin) {
|
||||
if (JOIN_STYPE_NONE != pJoin->subType || pJoin->isSingleTableJoin || NULL == pJoin->pTagEqCond ||
|
||||
pNode->pChildren->length != 2 || pJoin->isLowLevelJoin) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -5922,7 +5965,8 @@ int32_t stbJoinOptRewriteToTagScan(SLogicNode* pJoin, SNode* pNode) {
|
|||
SColumnNode* pTargetCol = (SColumnNode*)pTarget;
|
||||
FOREACH(pTag, pTags) {
|
||||
SColumnNode* pTagCol = (SColumnNode*)pTag;
|
||||
if (0 == strcasecmp(pTargetCol->node.aliasName, pTagCol->colName) && 0 == strcasecmp(pTargetCol->tableAlias, pTagCol->tableAlias)) {
|
||||
if (0 == strcasecmp(pTargetCol->node.aliasName, pTagCol->colName) &&
|
||||
0 == strcasecmp(pTargetCol->tableAlias, pTagCol->tableAlias)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
@ -6335,7 +6379,8 @@ static bool grpJoinOptShouldBeOptimized(SLogicNode* pNode, void* pCtx) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static int32_t grpJoinOptCreatePartitionNode(SLogicNode* pParent, SLogicNode* pChild, bool leftChild, SLogicNode** pNew) {
|
||||
static int32_t grpJoinOptCreatePartitionNode(SLogicNode* pParent, SLogicNode* pChild, bool leftChild,
|
||||
SLogicNode** pNew) {
|
||||
SPartitionLogicNode* pPartition = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_PARTITION, (SNode**)&pPartition);
|
||||
if (NULL == pPartition) {
|
||||
|
@ -6423,7 +6468,9 @@ static int32_t grpJoinOptPartByTags(SLogicNode* pNode) {
|
|||
|
||||
static int32_t grpJoinOptRewriteGroupJoin(SOptimizeContext* pCxt, SLogicNode* pNode, SLogicSubplan* pLogicSubplan) {
|
||||
SJoinLogicNode* pJoin = (SJoinLogicNode*)pNode;
|
||||
int32_t code = (pJoin->allEqTags && !pJoin->hasSubQuery && !pJoin->batchScanHint) ? grpJoinOptPartByTags(pNode) : grpJoinOptInsertPartitionNode(pNode);
|
||||
int32_t code = (pJoin->allEqTags && !pJoin->hasSubQuery && !pJoin->batchScanHint)
|
||||
? grpJoinOptPartByTags(pNode)
|
||||
: grpJoinOptInsertPartitionNode(pNode);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pJoin->grpJoin = true;
|
||||
pCxt->optimized = true;
|
||||
|
@ -6431,7 +6478,6 @@ static int32_t grpJoinOptRewriteGroupJoin(SOptimizeContext* pCxt, SLogicNode* pN
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t groupJoinOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan) {
|
||||
SLogicNode* pNode = optFindPossibleNode(pLogicSubplan->pNode, grpJoinOptShouldBeOptimized, NULL);
|
||||
if (NULL == pNode) {
|
||||
|
@ -6816,11 +6862,13 @@ static int32_t tsmaOptFilterTsmas(STSMAOptCtx* pTsmaOptCtx) {
|
|||
}
|
||||
if (pTsmaOptCtx->pScan->tableType == TSDB_CHILD_TABLE || pTsmaOptCtx->pScan->tableType == TSDB_NORMAL_TABLE) {
|
||||
const STsmaTargetTbInfo* ptbInfo = taosArrayGet(pTsmaOptCtx->pScan->pTsmaTargetTbInfo, i);
|
||||
if (ptbInfo->uid == 0) continue; // tsma res table meta not found, skip this tsma, this is possible when there is no data in this ctb
|
||||
if (ptbInfo->uid == 0)
|
||||
continue; // tsma res table meta not found, skip this tsma, this is possible when there is no data in this ctb
|
||||
}
|
||||
|
||||
STableTSMAInfo* pTsma = taosArrayGetP(pTsmaOptCtx->pTsmas, i);
|
||||
if (!pTsma->fillHistoryFinished || tsMaxTsmaCalcDelay * 1000 < (pTsma->rspTs - pTsma->reqTs) + pTsma->delayDuration) {
|
||||
if (!pTsma->fillHistoryFinished ||
|
||||
tsMaxTsmaCalcDelay * 1000 < (pTsma->rspTs - pTsma->reqTs) + pTsma->delayDuration) {
|
||||
continue;
|
||||
}
|
||||
// filter with interval
|
||||
|
@ -6947,21 +6995,19 @@ static int32_t tsmaOptSplitWindows(STSMAOptCtx* pTsmaOptCtx, const STimeWindow*
|
|||
STSMAOptUsefulTsma usefulTsma = {.pTsma = pTsmaFound ? pTsmaFound->pTsma : NULL,
|
||||
.scanRange = scanRange,
|
||||
.pTsmaScanCols = pTsmaFound ? pTsmaFound->pTsmaScanCols : NULL};
|
||||
if (NULL == taosArrayPush(pTsmaOptCtx->pUsedTsmas, &usefulTsma))
|
||||
return terrno;
|
||||
if (NULL == taosArrayPush(pTsmaOptCtx->pUsedTsmas, &usefulTsma)) return terrno;
|
||||
}
|
||||
|
||||
// the main tsma
|
||||
if (endOfSkeyFirstWin < startOfEkeyFirstWin || (endOfSkeyFirstWin == startOfEkeyFirstWin && (isSkeyAlignedWithTsma || isEkeyAlignedWithTsma))) {
|
||||
scanRange.ekey =
|
||||
TMIN(pScanRange->ekey, isEkeyAlignedWithTsma ? pScanRange->ekey : startOfEkeyFirstWin - 1);
|
||||
if (endOfSkeyFirstWin < startOfEkeyFirstWin ||
|
||||
(endOfSkeyFirstWin == startOfEkeyFirstWin && (isSkeyAlignedWithTsma || isEkeyAlignedWithTsma))) {
|
||||
scanRange.ekey = TMIN(pScanRange->ekey, isEkeyAlignedWithTsma ? pScanRange->ekey : startOfEkeyFirstWin - 1);
|
||||
if (!isSkeyAlignedWithTsma) {
|
||||
scanRange.skey = endOfSkeyFirstWin;
|
||||
}
|
||||
STSMAOptUsefulTsma usefulTsma = {
|
||||
.pTsma = pTsma, .scanRange = scanRange, .pTsmaScanCols = pUsefulTsma->pTsmaScanCols};
|
||||
if (NULL == taosArrayPush(pTsmaOptCtx->pUsedTsmas, &usefulTsma))
|
||||
return terrno;
|
||||
if (NULL == taosArrayPush(pTsmaOptCtx->pUsedTsmas, &usefulTsma)) return terrno;
|
||||
}
|
||||
|
||||
// add tail tsma if possible
|
||||
|
@ -6974,8 +7020,7 @@ static int32_t tsmaOptSplitWindows(STSMAOptCtx* pTsmaOptCtx, const STimeWindow*
|
|||
STSMAOptUsefulTsma usefulTsma = {.pTsma = pTsmaFound ? pTsmaFound->pTsma : NULL,
|
||||
.scanRange = scanRange,
|
||||
.pTsmaScanCols = pTsmaFound ? pTsmaFound->pTsmaScanCols : NULL};
|
||||
if (NULL == taosArrayPush(pTsmaOptCtx->pUsedTsmas, &usefulTsma))
|
||||
return terrno;
|
||||
if (NULL == taosArrayPush(pTsmaOptCtx->pUsedTsmas, &usefulTsma)) return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -7124,7 +7169,8 @@ EDealRes tsmaOptNodeRewriter(SNode** ppNode, void* ctx) {
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static int32_t tsmaOptRewriteNode(SNode** pNode, STSMAOptCtx* pCtx, const STSMAOptUsefulTsma* pTsma, bool rewriteTbName, bool rewriteTag) {
|
||||
static int32_t tsmaOptRewriteNode(SNode** pNode, STSMAOptCtx* pCtx, const STSMAOptUsefulTsma* pTsma, bool rewriteTbName,
|
||||
bool rewriteTag) {
|
||||
struct TsmaOptRewriteCtx ctx = {
|
||||
.pTsmaOptCtx = pCtx, .pTsma = pTsma, .rewriteTag = rewriteTag, .rewriteTbname = rewriteTbName, .code = 0};
|
||||
SNode* pOut = *pNode;
|
||||
|
|
|
@ -820,7 +820,7 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan*
|
|||
if (0 == strcmp(pScanLogicNode->tableName.tname, TSDB_INS_TABLE_TABLES) ||
|
||||
0 == strcmp(pScanLogicNode->tableName.tname, TSDB_INS_TABLE_TAGS) ||
|
||||
0 == strcmp(pScanLogicNode->tableName.tname, TSDB_INS_TABLE_COLS) ||
|
||||
0 == strcmp(pScanLogicNode->tableName.tname, TSDB_INS_TABLE_USAGE)) {
|
||||
0 == strcmp(pScanLogicNode->tableName.tname, TSDB_INS_DISK_USAGE)) {
|
||||
if (pScanLogicNode->pVgroupList) {
|
||||
vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode);
|
||||
}
|
||||
|
|
|
@ -591,23 +591,24 @@ int taosGetDirSize(const char *path, int64_t *size) {
|
|||
return TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
int64_t subSize = 0;
|
||||
if (taosIsDir(fullPath)) {
|
||||
code = taosGetDirSize(fullPath, &totalSize);
|
||||
code = taosGetDirSize(fullPath, &subSize);
|
||||
if (code != 0) {
|
||||
taosCloseDir(&pDir);
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
int64_t fileSize = 0;
|
||||
code = taosStatFile(fullPath, &fileSize, NULL, NULL);
|
||||
code = taosStatFile(fullPath, &subSize, NULL, NULL);
|
||||
if (code != 0) {
|
||||
taosCloseDir(&pDir);
|
||||
return code;
|
||||
}
|
||||
totalSize += fileSize;
|
||||
}
|
||||
totalSize += subSize;
|
||||
fullPath[0] = 0;
|
||||
}
|
||||
|
||||
*size = totalSize;
|
||||
TAOS_UNUSED(taosCloseDir(&pDir));
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue