fix: tag is null when table is empty
This commit is contained in:
parent
61e7ae53c8
commit
3257c7c082
|
@ -2132,6 +2132,9 @@ int32_t buildGroupIdMapForAllTables(STableListInfo* pTableListInfo, SReadHandle*
|
||||||
}
|
}
|
||||||
|
|
||||||
pTableListInfo->oneTableForEachGroup = groupByTbname;
|
pTableListInfo->oneTableForEachGroup = groupByTbname;
|
||||||
|
if (numOfTables == 1 && pTableListInfo->idInfo.tableType == TSDB_CHILD_TABLE) {
|
||||||
|
pTableListInfo->oneTableForEachGroup = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (groupSort && groupByTbname) {
|
if (groupSort && groupByTbname) {
|
||||||
taosArraySort(pTableListInfo->pTableList, orderbyGroupIdComparFn);
|
taosArraySort(pTableListInfo->pTableList, orderbyGroupIdComparFn);
|
||||||
|
|
|
@ -889,14 +889,15 @@ static SSDataBlock* doGroupedTableScan(SOperatorInfo* pOperator) {
|
||||||
|
|
||||||
if (pTableScanInfo->countState < TABLE_COUNT_STATE_END) {
|
if (pTableScanInfo->countState < TABLE_COUNT_STATE_END) {
|
||||||
STableListInfo* pTableListInfo = pTableScanInfo->base.pTableListInfo;
|
STableListInfo* pTableListInfo = pTableScanInfo->base.pTableListInfo;
|
||||||
if (pTableListInfo->oneTableForEachGroup || pTableListInfo->groupOffset) { // group by tbname, group by tag + sort
|
if (pTableListInfo->oneTableForEachGroup || pTableListInfo->groupOffset) { // group by tbname, group by tag + sort
|
||||||
if (pTableScanInfo->countState < TABLE_COUNT_STATE_PROCESSED) {
|
if (pTableScanInfo->countState < TABLE_COUNT_STATE_PROCESSED) {
|
||||||
pTableScanInfo->countState = TABLE_COUNT_STATE_PROCESSED;
|
pTableScanInfo->countState = TABLE_COUNT_STATE_PROCESSED;
|
||||||
STableKeyInfo* pStart =
|
STableKeyInfo* pStart =
|
||||||
(STableKeyInfo*)tableListGetInfo(pTableScanInfo->base.pTableListInfo, pTableScanInfo->tableStartIndex);
|
(STableKeyInfo*)tableListGetInfo(pTableScanInfo->base.pTableListInfo, pTableScanInfo->tableStartIndex);
|
||||||
|
if (NULL == pStart) return NULL;
|
||||||
return getBlockForEmptyTable(pOperator, pStart);
|
return getBlockForEmptyTable(pOperator, pStart);
|
||||||
}
|
}
|
||||||
} else { // group by tag + no sort
|
} else { // group by tag + no sort
|
||||||
int32_t numOfTables = tableListGetSize(pTableListInfo);
|
int32_t numOfTables = tableListGetSize(pTableListInfo);
|
||||||
if (pTableScanInfo->tableEndIndex + 1 >= numOfTables) {
|
if (pTableScanInfo->tableEndIndex + 1 >= numOfTables) {
|
||||||
// get empty group, mark processed & rm from hash
|
// get empty group, mark processed & rm from hash
|
||||||
|
|
|
@ -2702,6 +2702,15 @@ static bool hasTbnameFunction(SNodeList* pPartitionByList) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool fromSubtable(SNode* table) {
|
||||||
|
if (NULL == table) return false;
|
||||||
|
if (table->type == QUERY_NODE_REAL_TABLE && ((SRealTableNode*)table)->pMeta &&
|
||||||
|
((SRealTableNode*)table)->pMeta->tableType == TSDB_CHILD_TABLE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
|
static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
|
||||||
STranslateContext* pCxt = (STranslateContext*)pContext;
|
STranslateContext* pCxt = (STranslateContext*)pContext;
|
||||||
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt;
|
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt;
|
||||||
|
@ -2795,15 +2804,18 @@ static EDealRes doCheckAggColCoexist(SNode** pNode, void* pContext) {
|
||||||
return DEAL_RES_IGNORE_CHILD;
|
return DEAL_RES_IGNORE_CHILD;
|
||||||
}
|
}
|
||||||
SNode* pPartKey = NULL;
|
SNode* pPartKey = NULL;
|
||||||
bool partionByTbname = hasTbnameFunction(((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList);
|
bool partionByTbname = false;
|
||||||
|
if (fromSubtable(((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pFromTable) ||
|
||||||
|
hasTbnameFunction(((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList)) {
|
||||||
|
partionByTbname = true;
|
||||||
|
}
|
||||||
FOREACH(pPartKey, ((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList) {
|
FOREACH(pPartKey, ((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList) {
|
||||||
if (nodesEqualNode(pPartKey, *pNode)) {
|
if (nodesEqualNode(pPartKey, *pNode)) {
|
||||||
return rewriteExprToGroupKeyFunc(pCxt->pTranslateCxt, pNode);
|
return rewriteExprToGroupKeyFunc(pCxt->pTranslateCxt, pNode);
|
||||||
}
|
}
|
||||||
if (partionByTbname && QUERY_NODE_COLUMN == nodeType(*pNode) &&
|
}
|
||||||
((SColumnNode*)*pNode)->colType == COLUMN_TYPE_TAG) {
|
if (partionByTbname && QUERY_NODE_COLUMN == nodeType(*pNode) && ((SColumnNode*)*pNode)->colType == COLUMN_TYPE_TAG) {
|
||||||
return rewriteExprToGroupKeyFunc(pCxt->pTranslateCxt, pNode);
|
return rewriteExprToGroupKeyFunc(pCxt->pTranslateCxt, pNode);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (isScanPseudoColumnFunc(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode)) {
|
if (isScanPseudoColumnFunc(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode)) {
|
||||||
pCxt->existCol = true;
|
pCxt->existCol = true;
|
||||||
|
|
|
@ -494,6 +494,9 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
||||||
} else if (pSelect->pPartitionByList) {
|
} else if (pSelect->pPartitionByList) {
|
||||||
isCountByTag = !keysHasCol(pSelect->pPartitionByList);
|
isCountByTag = !keysHasCol(pSelect->pPartitionByList);
|
||||||
}
|
}
|
||||||
|
if (pScan->tableType == TSDB_CHILD_TABLE) {
|
||||||
|
isCountByTag = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pScan->isCountByTag = isCountByTag;
|
pScan->isCountByTag = isCountByTag;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue