|
|
|
@ -376,9 +376,7 @@ void initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow
|
|
|
|
|
colDataAppendInt64(pColData, 4, &pQueryWindow->ekey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cleanupExecTimeWindowInfo(SColumnInfoData* pColData) {
|
|
|
|
|
colDataDestroy(pColData);
|
|
|
|
|
}
|
|
|
|
|
void cleanupExecTimeWindowInfo(SColumnInfoData* pColData) { colDataDestroy(pColData); }
|
|
|
|
|
|
|
|
|
|
void doApplyFunctions(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, STimeWindow* pWin,
|
|
|
|
|
SColumnInfoData* pTimeWindowData, int32_t offset, int32_t forwardStep, TSKEY* tsCol,
|
|
|
|
@ -524,8 +522,8 @@ static int32_t doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCt
|
|
|
|
|
// NOTE: the last parameter is the primary timestamp column
|
|
|
|
|
// todo: refactor this
|
|
|
|
|
if (fmIsTimelineFunc(pCtx[i].functionId) && (j == pOneExpr->base.numOfParams - 1)) {
|
|
|
|
|
pInput->pPTS = pInput->pData[j]; // in case of merge function, this is not always the ts column data.
|
|
|
|
|
// ASSERT(pInput->pPTS->info.type == TSDB_DATA_TYPE_TIMESTAMP);
|
|
|
|
|
pInput->pPTS = pInput->pData[j]; // in case of merge function, this is not always the ts column data.
|
|
|
|
|
// ASSERT(pInput->pPTS->info.type == TSDB_DATA_TYPE_TIMESTAMP);
|
|
|
|
|
}
|
|
|
|
|
ASSERT(pInput->pData[j] != NULL);
|
|
|
|
|
} else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
|
|
|
|
@ -835,7 +833,7 @@ void setTaskKilled(SExecTaskInfo* pTaskInfo) { pTaskInfo->code = TSDB_CODE_TSC_Q
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
STimeWindow getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key) {
|
|
|
|
|
STimeWindow win = {0};
|
|
|
|
|
STimeWindow win = {0};
|
|
|
|
|
win.skey = taosTimeTruncate(key, pInterval, precision);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -2378,7 +2376,7 @@ static SSDataBlock* doLoadRemoteData(SOperatorInfo* pOperator) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
while (1) {
|
|
|
|
|
SSDataBlock* pBlock = doLoadRemoteDataImpl(pOperator);
|
|
|
|
|
if (pBlock == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
@ -3431,13 +3429,13 @@ static SSDataBlock* doFillImpl(SOperatorInfo* pOperator) {
|
|
|
|
|
blockDataUpdateTsWindow(pBlock, pInfo->primaryTsCol);
|
|
|
|
|
|
|
|
|
|
if (pInfo->curGroupId == 0 || pInfo->curGroupId == pBlock->info.groupId) {
|
|
|
|
|
pInfo->curGroupId = pBlock->info.groupId; // the first data block
|
|
|
|
|
pInfo->curGroupId = pBlock->info.groupId; // the first data block
|
|
|
|
|
|
|
|
|
|
pInfo->totalInputRows += pBlock->info.rows;
|
|
|
|
|
|
|
|
|
|
taosFillSetStartInfo(pInfo->pFillInfo, pBlock->info.rows, pBlock->info.window.ekey);
|
|
|
|
|
taosFillSetInputDataBlock(pInfo->pFillInfo, pBlock);
|
|
|
|
|
} else if (pInfo->curGroupId != pBlock->info.groupId) { // the new group data block
|
|
|
|
|
} else if (pInfo->curGroupId != pBlock->info.groupId) { // the new group data block
|
|
|
|
|
pInfo->existNewGroupBlock = pBlock;
|
|
|
|
|
|
|
|
|
|
// Fill the previous group data block, before handle the data block of new group.
|
|
|
|
@ -3511,7 +3509,7 @@ static SSDataBlock* doFill(SOperatorInfo* pOperator) {
|
|
|
|
|
static void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
|
|
|
|
|
for (int32_t i = 0; i < numOfExprs; ++i) {
|
|
|
|
|
SExprInfo* pExprInfo = &pExpr[i];
|
|
|
|
|
for(int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
|
|
|
|
|
for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
|
|
|
|
|
if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
|
|
|
|
|
taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
|
|
|
|
|
}
|
|
|
|
@ -3604,7 +3602,7 @@ int32_t initAggInfo(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInf
|
|
|
|
|
return TSDB_CODE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void initResultSizeInfo(SResultInfo * pResultInfo, int32_t numOfRows) {
|
|
|
|
|
void initResultSizeInfo(SResultInfo* pResultInfo, int32_t numOfRows) {
|
|
|
|
|
ASSERT(numOfRows != 0);
|
|
|
|
|
pResultInfo->capacity = numOfRows;
|
|
|
|
|
pResultInfo->threshold = numOfRows * 0.75;
|
|
|
|
@ -3724,7 +3722,6 @@ void destroyBasicOperatorInfo(void* param, int32_t numOfOutput) {
|
|
|
|
|
taosMemoryFreeClear(param);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void freeItem(void* pItem) {
|
|
|
|
|
void** p = pItem;
|
|
|
|
|
if (*p != NULL) {
|
|
|
|
@ -4051,8 +4048,8 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t
|
|
|
|
|
w = getFirstQualifiedTimeWindow(win.skey, &w, pInterval, TSDB_ORDER_ASC);
|
|
|
|
|
|
|
|
|
|
int32_t order = TSDB_ORDER_ASC;
|
|
|
|
|
pInfo->pFillInfo = taosCreateFillInfo(order, w.skey, 0, capacity, numOfCols, pInterval,
|
|
|
|
|
fillType, pColInfo, pInfo->primaryTsCol, id);
|
|
|
|
|
pInfo->pFillInfo =
|
|
|
|
|
taosCreateFillInfo(order, w.skey, 0, capacity, numOfCols, pInterval, fillType, pColInfo, pInfo->primaryTsCol, id);
|
|
|
|
|
|
|
|
|
|
pInfo->win = win;
|
|
|
|
|
pInfo->p = taosMemoryCalloc(numOfCols, POINTER_BYTES);
|
|
|
|
@ -4066,7 +4063,8 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pPhyFillNode, SExecTaskInfo* pTaskInfo) {
|
|
|
|
|
SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pPhyFillNode,
|
|
|
|
|
SExecTaskInfo* pTaskInfo) {
|
|
|
|
|
SFillOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SFillOperatorInfo));
|
|
|
|
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
|
|
|
|
if (pInfo == NULL || pOperator == NULL) {
|
|
|
|
@ -4149,8 +4147,8 @@ int32_t extractTableSchemaInfo(SReadHandle* pHandle, SScanPhysiNode* pScanNode,
|
|
|
|
|
metaReaderInit(&mr, pHandle->meta, 0);
|
|
|
|
|
int32_t code = metaGetTableEntryByUid(&mr, pScanNode->uid);
|
|
|
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
|
|
|
qError("failed to get the table meta, uid:0x%"PRIx64", suid:0x%"PRIx64 ", %s", pScanNode->uid, pScanNode->suid,
|
|
|
|
|
GET_TASKID(pTaskInfo));
|
|
|
|
|
qError("failed to get the table meta, uid:0x%" PRIx64 ", suid:0x%" PRIx64 ", %s", pScanNode->uid, pScanNode->suid,
|
|
|
|
|
GET_TASKID(pTaskInfo));
|
|
|
|
|
|
|
|
|
|
metaReaderClear(&mr);
|
|
|
|
|
return terrno;
|
|
|
|
@ -4180,11 +4178,11 @@ int32_t extractTableSchemaInfo(SReadHandle* pHandle, SScanPhysiNode* pScanNode,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SSchemaWrapper* extractQueriedColumnSchema(SScanPhysiNode* pScanNode) {
|
|
|
|
|
int32_t numOfCols = LIST_LENGTH(pScanNode->pScanCols);
|
|
|
|
|
int32_t numOfCols = LIST_LENGTH(pScanNode->pScanCols);
|
|
|
|
|
SSchemaWrapper* pqSw = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
|
|
|
|
|
pqSw->pSchema = taosMemoryCalloc(numOfCols, sizeof(SSchema));
|
|
|
|
|
|
|
|
|
|
for(int32_t i = 0; i < numOfCols; ++i) {
|
|
|
|
|
for (int32_t i = 0; i < numOfCols; ++i) {
|
|
|
|
|
STargetNode* pNode = (STargetNode*)nodesListGetNode(pScanNode->pScanCols, i);
|
|
|
|
|
SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
|
|
|
|
|
|
|
|
|
@ -4387,21 +4385,23 @@ static int32_t initTableblockDistQueryCond(uint64_t uid, SQueryTableDataCond* pC
|
|
|
|
|
pCond->suid = uid;
|
|
|
|
|
pCond->type = BLOCK_LOAD_OFFSET_ORDER;
|
|
|
|
|
pCond->startVersion = -1;
|
|
|
|
|
pCond->endVersion = -1;
|
|
|
|
|
pCond->endVersion = -1;
|
|
|
|
|
|
|
|
|
|
return TSDB_CODE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle,
|
|
|
|
|
STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond, const char* pUser) {
|
|
|
|
|
STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond,
|
|
|
|
|
const char* pUser) {
|
|
|
|
|
int32_t type = nodeType(pPhyNode);
|
|
|
|
|
|
|
|
|
|
if (pPhyNode->pChildren == NULL || LIST_LENGTH(pPhyNode->pChildren) == 0) {
|
|
|
|
|
if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == type) {
|
|
|
|
|
STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
|
|
|
|
|
|
|
|
|
|
int32_t code = createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags,
|
|
|
|
|
pTableScanNode->groupSort, pHandle, pTableListInfo, pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo));
|
|
|
|
|
int32_t code =
|
|
|
|
|
createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort, pHandle,
|
|
|
|
|
pTableListInfo, pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo));
|
|
|
|
|
if (code) {
|
|
|
|
|
pTaskInfo->code = code;
|
|
|
|
|
return NULL;
|
|
|
|
@ -4420,8 +4420,9 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|
|
|
|
|
|
|
|
|
} else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == type) {
|
|
|
|
|
STableMergeScanPhysiNode* pTableScanNode = (STableMergeScanPhysiNode*)pPhyNode;
|
|
|
|
|
int32_t code = createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags,
|
|
|
|
|
pTableScanNode->groupSort, pHandle, pTableListInfo, pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo));
|
|
|
|
|
int32_t code =
|
|
|
|
|
createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort, pHandle,
|
|
|
|
|
pTableListInfo, pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo));
|
|
|
|
|
if (code) {
|
|
|
|
|
pTaskInfo->code = code;
|
|
|
|
|
return NULL;
|
|
|
|
@ -4433,8 +4434,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SOperatorInfo* pOperator =
|
|
|
|
|
createTableMergeScanOperatorInfo(pTableScanNode, pTableListInfo, pHandle, pTaskInfo);
|
|
|
|
|
SOperatorInfo* pOperator = createTableMergeScanOperatorInfo(pTableScanNode, pTableListInfo, pHandle, pTaskInfo);
|
|
|
|
|
|
|
|
|
|
STableScanInfo* pScanInfo = pOperator->info;
|
|
|
|
|
pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder;
|
|
|
|
@ -4445,13 +4445,22 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|
|
|
|
} else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN == type) {
|
|
|
|
|
STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
|
|
|
|
|
if (pHandle->vnode) {
|
|
|
|
|
int32_t code = createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags,
|
|
|
|
|
pTableScanNode->groupSort, pHandle, pTableListInfo, pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo));
|
|
|
|
|
int32_t code =
|
|
|
|
|
createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort,
|
|
|
|
|
pHandle, pTableListInfo, pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo));
|
|
|
|
|
if (code) {
|
|
|
|
|
pTaskInfo->code = code;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
int32_t sz = taosArrayGetSize(pTableListInfo->pTableList);
|
|
|
|
|
for (int32_t i = 0; i < sz; i++) {
|
|
|
|
|
STableKeyInfo* pKeyInfo = taosArrayGet(pTableListInfo->pTableList, i);
|
|
|
|
|
qDebug("creating stream task: add table %ld", pKeyInfo->uid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
pTaskInfo->schemaInfo.qsw = extractQueriedColumnSchema(&pTableScanNode->scan);
|
|
|
|
|
SOperatorInfo* pOperator = createStreamScanOperatorInfo(pHandle, pTableScanNode, pTagCond, pTaskInfo);
|
|
|
|
@ -4486,7 +4495,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SQueryTableDataCond cond = {0};
|
|
|
|
|
int32_t code = initTableblockDistQueryCond(pBlockNode->suid, &cond);
|
|
|
|
|
int32_t code = initTableblockDistQueryCond(pBlockNode->suid, &cond);
|
|
|
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
@ -4499,7 +4508,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|
|
|
|
} else if (QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN == type) {
|
|
|
|
|
SLastRowScanPhysiNode* pScanNode = (SLastRowScanPhysiNode*)pPhyNode;
|
|
|
|
|
|
|
|
|
|
int32_t code = createScanTableListInfo(&pScanNode->scan, pScanNode->pGroupTags, true, pHandle, pTableListInfo, pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo));
|
|
|
|
|
int32_t code = createScanTableListInfo(&pScanNode->scan, pScanNode->pGroupTags, true, pHandle, pTableListInfo,
|
|
|
|
|
pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo));
|
|
|
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
|
|
|
pTaskInfo->code = code;
|
|
|
|
|
return NULL;
|
|
|
|
@ -4961,7 +4971,8 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead
|
|
|
|
|
|
|
|
|
|
(*pTaskInfo)->sql = sql;
|
|
|
|
|
(*pTaskInfo)->pSubplan = pPlan;
|
|
|
|
|
(*pTaskInfo)->pRoot = createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, &(*pTaskInfo)->tableqinfoList, pPlan->pTagCond, pPlan->pTagIndexCond, pPlan->user);
|
|
|
|
|
(*pTaskInfo)->pRoot = createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, &(*pTaskInfo)->tableqinfoList,
|
|
|
|
|
pPlan->pTagCond, pPlan->pTagIndexCond, pPlan->user);
|
|
|
|
|
|
|
|
|
|
if (NULL == (*pTaskInfo)->pRoot) {
|
|
|
|
|
code = (*pTaskInfo)->code;
|
|
|
|
|