Skip to content

Commit ba90fd5

Browse files
authored
enh: support no from subquery (#34119)
1 parent 82fb050 commit ba90fd5

16 files changed

+16815
-10501
lines changed

source/libs/nodes/src/nodesTraverseFuncs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ void nodesWalkSelectStmtImpl(SSelectStmt* pSelect, ESqlClause clause, FNodeWalke
564564
nodesWalkExprs(pSelect->pPartitionByList, walker, pContext);
565565
case SQL_CLAUSE_PARTITION_BY:
566566
nodesWalkExpr(pSelect->pWindow, walker, pContext);
567+
nodesWalkExpr(pSelect->pFill, walker, pContext);
567568
case SQL_CLAUSE_WINDOW:
568569
if (NULL != pSelect->pWindow) {
569570
if (QUERY_NODE_INTERVAL_WINDOW == nodeType(pSelect->pWindow)) {

source/libs/parser/src/parAstParser.c

Lines changed: 264 additions & 130 deletions
Large diffs are not rendered by default.

source/libs/parser/src/parTranslater.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19317,11 +19317,13 @@ static int32_t translateTableSubquery(STranslateContext* pCxt, SNode* pNode) {
1931719317
ESqlClause currClause = pCxt->currClause;
1931819318
SNode* pCurrStmt = pCxt->pCurrStmt;
1931919319
int32_t currLevel = pCxt->currLevel;
19320+
bool dual = pCxt->dual;
1932019321
pCxt->currLevel = ++(pCxt->levelNo);
1932119322
code = translateQuery(pCxt, pNode);
1932219323
pCxt->currClause = currClause;
1932319324
pCxt->pCurrStmt = pCurrStmt;
1932419325
pCxt->currLevel = currLevel;
19326+
pCxt->dual = dual;
1932519327

1932619328
return code;
1932719329
}
@@ -19357,11 +19359,13 @@ static int32_t translateExprSubqueryImpl(STranslateContext* pCxt, SNode* pNode)
1935719359
parserError("Correlated subQuery not supported now");
1935819360
code = TSDB_CODE_PAR_INVALID_SCALAR_SUBQ;
1935919361
}
19362+
/*
1936019363
if (pCxt->hasLocalSubQ) {
1936119364
parserError("Only query with FROM supported now");
1936219365
code = TSDB_CODE_PAR_INVALID_SCALAR_SUBQ;
1936319366
}
19364-
19367+
*/
19368+
1936519369
return code;
1936619370
}
1936719371

source/libs/planner/src/planner.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ static void dumpLogicPlan(SLogicSubplan* pLogicSubplan, int32_t level) {
7373
return;
7474
}
7575

76+
static void initSubQueryPlanContext(SPlanContext* pDst, SPlanContext* pSrc, SNode* pRoot) {
77+
memcpy(pDst, pSrc, sizeof(*pSrc));
78+
79+
pDst->withExtWindow = false;
80+
pDst->hasScan = false;
81+
82+
pDst->pAstRoot = pRoot;
83+
}
7684

7785
static int32_t createSubQueryPlans(SPlanContext* pSrc, SQueryPlan* pParent, SArray* pExecNodeList) {
7886
int32_t code = TSDB_CODE_SUCCESS, lino = 0;
@@ -110,8 +118,7 @@ static int32_t createSubQueryPlans(SPlanContext* pSrc, SQueryPlan* pParent, SArr
110118
}
111119

112120
FOREACH(pNode, pSubQueries) {
113-
memcpy(&ctx, pSrc, sizeof(*pSrc));
114-
ctx.pAstRoot = pNode;
121+
initSubQueryPlanContext(&ctx, pSrc, pNode);
115122
TAOS_CHECK_EXIT(qCreateQueryPlan(&ctx, &pPlan, pExecNodeList));
116123
TAOS_CHECK_EXIT(nodesListMakeStrictAppend(&pParent->pChildren, (SNode*)pPlan));
117124
pParent->numOfSubplans += pPlan->numOfSubplans;

test/cases/09-DataQuerying/08-SubQuery/ans/test_scalar_sub_query1.0.csv

Lines changed: 1028 additions & 350 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)