diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index ae1b68f90a..c79a7c4870 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -158,7 +158,10 @@ typedef struct SJoinLogicNode { // FOR CONST JOIN bool noPrimKeyEqCond; - bool constPrimGot; + bool leftConstPrimGot; + bool rightConstPrimGot; + bool leftNoOrderedSubQuery; + bool rightNoOrderedSubQuery; // FOR HASH JOIN int32_t timeRangeTarget; // table onCond filter diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index ff0ab597ff..b93ca5eda6 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -57,11 +57,13 @@ typedef struct SExprNode { SDataType resType; char aliasName[TSDB_COL_NAME_LEN]; char userAlias[TSDB_COL_NAME_LEN]; + char srcTable[TSDB_TABLE_NAME_LEN]; SArray* pAssociation; bool asAlias; bool asParam; bool asPosition; bool joinSrc; +// bool joinConst; int32_t projIdx; int32_t relatedTo; int32_t bindExprID; @@ -293,6 +295,10 @@ typedef struct SJoinTableNode { SNode* addPrimCond; bool hasSubQuery; bool isLowLevelJoin; + bool leftNoOrderedSubQuery; + bool rightNoOrderedSubQuery; + //bool condAlwaysTrue; + //bool condAlwaysFalse; SNode* pLeft; SNode* pRight; SNode* pOnCond; diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index 313ab854bc..1f5155a689 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -102,6 +102,7 @@ static int32_t exprNodeCopy(const SExprNode* pSrc, SExprNode* pDst) { COPY_OBJECT_FIELD(resType, sizeof(SDataType)); COPY_CHAR_ARRAY_FIELD(aliasName); COPY_CHAR_ARRAY_FIELD(userAlias); + COPY_CHAR_ARRAY_FIELD(srcTable); COPY_SCALAR_FIELD(asAlias); COPY_SCALAR_FIELD(asParam); COPY_SCALAR_FIELD(asPosition); @@ -323,6 +324,10 @@ static int32_t joinTableNodeCopy(const SJoinTableNode* pSrc, SJoinTableNode* pDs CLONE_NODE_FIELD(addPrimCond); COPY_SCALAR_FIELD(hasSubQuery); COPY_SCALAR_FIELD(isLowLevelJoin); + COPY_SCALAR_FIELD(leftNoOrderedSubQuery); + COPY_SCALAR_FIELD(rightNoOrderedSubQuery); + //COPY_SCALAR_FIELD(condAlwaysTrue); + //COPY_SCALAR_FIELD(condAlwaysFalse); CLONE_NODE_FIELD(pLeft); CLONE_NODE_FIELD(pRight); CLONE_NODE_FIELD(pOnCond); @@ -545,7 +550,10 @@ static int32_t logicJoinCopy(const SJoinLogicNode* pSrc, SJoinLogicNode* pDst) { COPY_SCALAR_FIELD(hashJoinHint); COPY_SCALAR_FIELD(batchScanHint); COPY_SCALAR_FIELD(noPrimKeyEqCond); - COPY_SCALAR_FIELD(constPrimGot); + COPY_SCALAR_FIELD(leftConstPrimGot); + COPY_SCALAR_FIELD(rightConstPrimGot); + COPY_SCALAR_FIELD(leftNoOrderedSubQuery); + COPY_SCALAR_FIELD(rightNoOrderedSubQuery); CLONE_NODE_FIELD(pLeftOnCond); CLONE_NODE_FIELD(pRightOnCond); COPY_SCALAR_FIELD(timeRangeTarget); diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index a84de17438..96a0963516 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -127,13 +127,33 @@ static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTab } case QUERY_NODE_JOIN_TABLE: { SJoinTableNode* pJoin = (SJoinTableNode*)pTable; + SNode* pCond = NULL; code = rewriteConditionForFromTable(pCxt, pJoin->pLeft); if (TSDB_CODE_SUCCESS == code) { code = rewriteConditionForFromTable(pCxt, pJoin->pRight); } + if (TSDB_CODE_SUCCESS == code && NULL != pJoin->pOnCond) { + code = nodesCloneNode(pJoin->pOnCond, &pCond); + } if (TSDB_CODE_SUCCESS == code && NULL != pJoin->pOnCond) { code = calcConstCondition(pCxt, &pJoin->pOnCond); } + if (TSDB_CODE_SUCCESS == code && pJoin->pOnCond && QUERY_NODE_VALUE == nodeType(pJoin->pOnCond)) { + nodesDestroyNode(pJoin->pOnCond); + pJoin->pOnCond = pCond; + pCond = NULL; + /* TODO + SValueNode* pVal = (SValueNode*)pJoin->pOnCond; + if (TSDB_DATA_TYPE_BOOL == pVal->node.resType.type) { + if (pVal->datum.b) { + pJoin->condAlwaysTrue = true; + } else { + pJoin->condAlwaysFalse = true; + } + } + */ + } + nodesDestroyNode(pCond); // todo empty table break; } @@ -215,7 +235,7 @@ static int32_t calcConstProject(SCalcConstContext* pCxt, SNode* pProject, bool d } } - char aliasName[TSDB_COL_NAME_LEN] = {0}; + char aliasName[TSDB_COL_NAME_LEN] = {0}, srcTable[TSDB_TABLE_NAME_LEN] = {0}; int32_t code = TSDB_CODE_SUCCESS; if (dual) { code = scalarCalculateConstantsFromDual(pProject, pNew); @@ -229,11 +249,15 @@ static int32_t calcConstProject(SCalcConstContext* pCxt, SNode* pProject, bool d SAssociationNode* pAssNode = taosArrayGet(pAssociation, i); SNode** pCol = pAssNode->pPlace; if (((SExprNode*)pAssNode->pAssociationNode)->joinSrc) { +// ((SExprNode*)pAssNode->pAssociationNode)->joinConst = true; continue; } if (*pCol == pAssNode->pAssociationNode) { tstrncpy(aliasName, ((SExprNode*)*pCol)->aliasName, TSDB_COL_NAME_LEN); + if (QUERY_NODE_COLUMN == nodeType(*pCol)) { + tstrncpy(srcTable, ((SColumnNode*)*pCol)->tableAlias, TSDB_TABLE_NAME_LEN); + } SArray* pOrigAss = NULL; TSWAP(((SExprNode*)*pCol)->pAssociation, pOrigAss); nodesDestroyNode(*pCol); @@ -241,6 +265,9 @@ static int32_t calcConstProject(SCalcConstContext* pCxt, SNode* pProject, bool d code = nodesCloneNode(*pNew, pCol); if (TSDB_CODE_SUCCESS == code) { tstrncpy(((SExprNode*)*pCol)->aliasName, aliasName, TSDB_COL_NAME_LEN); + if (srcTable[0]) { + tstrncpy(((SExprNode*)*pCol)->srcTable, srcTable, TSDB_TABLE_NAME_LEN); + } TSWAP(pOrigAss, ((SExprNode*)*pCol)->pAssociation); } taosArrayDestroy(pOrigAss); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 0d8255b2d6..07d674f70c 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -4760,6 +4760,7 @@ static int32_t checkJoinTable(STranslateContext* pCxt, SJoinTableNode* pJoinTabl return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_SUPPORT_JOIN, "Join requires valid time series input"); } + pJoinTable->leftNoOrderedSubQuery = true; } if (QUERY_NODE_TEMP_TABLE == nodeType(pJoinTable->pRight) && @@ -4768,6 +4769,7 @@ static int32_t checkJoinTable(STranslateContext* pCxt, SJoinTableNode* pJoinTabl return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_SUPPORT_JOIN, "Join requires valid time series input"); } + pJoinTable->rightNoOrderedSubQuery = true; } @@ -5098,6 +5100,49 @@ static int32_t setJoinTimeLineResMode(STranslateContext* pCxt) { return TSDB_CODE_SUCCESS; } +int32_t mergeInnerJoinConds(SNode** ppDst, SNode** ppSrc) { + SNode* pNew = NULL; + int32_t code = TSDB_CODE_SUCCESS; + + while (true) { + if (QUERY_NODE_LOGIC_CONDITION == nodeType(*ppDst) && ((SLogicConditionNode*)*ppDst)->condType == LOGIC_COND_TYPE_AND) { + SLogicConditionNode* pLogic = (SLogicConditionNode*)*ppDst; + code = nodesListMakeStrictAppend(&pLogic->pParameterList, *ppSrc); + if (TSDB_CODE_SUCCESS == code) { + *ppSrc = NULL; + } + return code; + } + + if (QUERY_NODE_LOGIC_CONDITION == nodeType(*ppSrc) && ((SLogicConditionNode*)*ppSrc)->condType == LOGIC_COND_TYPE_AND) { + SNode* pTmp = *ppDst; + *ppDst = *ppSrc; + *ppSrc = pTmp; + continue; + } + + code = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, &pNew); + if (TSDB_CODE_SUCCESS == code) { + SLogicConditionNode* pLogic = (SLogicConditionNode*)pNew; + pLogic->condType = LOGIC_COND_TYPE_AND; + pLogic->node.resType.type = TSDB_DATA_TYPE_BOOL; + pLogic->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; + code = nodesListMakeStrictAppend(&pLogic->pParameterList, *ppSrc); + if (TSDB_CODE_SUCCESS == code) { + *ppSrc = *ppDst; + *ppDst = pNew; + continue; + } + } + + if (code) { + break; + } + } + + return code; +} + int32_t translateTable(STranslateContext* pCxt, SNode** pTable, bool inJoin) { SSelectStmt* pCurrSmt = (SSelectStmt*)(pCxt->pCurrStmt); int32_t code = TSDB_CODE_SUCCESS; @@ -5184,6 +5229,14 @@ int32_t translateTable(STranslateContext* pCxt, SNode** pTable, bool inJoin) { if (TSDB_CODE_SUCCESS == code) { code = checkJoinTable(pCxt, pJoinTable); } + if (TSDB_CODE_SUCCESS == code && pCurrSmt->pWhere && JOIN_TYPE_INNER == pJoinTable->joinType) { + if (pJoinTable->pOnCond) { + code = mergeInnerJoinConds(&pJoinTable->pOnCond, &pCurrSmt->pWhere); + } else { + pJoinTable->pOnCond = pCurrSmt->pWhere; + pCurrSmt->pWhere = NULL; + } + } if (TSDB_CODE_SUCCESS == code) { pJoinTable->table.precision = calcJoinTablePrecision(pJoinTable); pJoinTable->table.singleTable = joinTableIsSingleTable(pJoinTable); diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 273fd9abfc..d88bcb6f4b 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -600,6 +600,8 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect pJoin->node.requireDataOrder = pJoin->hashJoinHint ? DATA_ORDER_LEVEL_NONE : DATA_ORDER_LEVEL_GLOBAL; pJoin->node.resultDataOrder = DATA_ORDER_LEVEL_NONE; pJoin->isLowLevelJoin = pJoinTable->isLowLevelJoin; + pJoin->leftNoOrderedSubQuery = pJoinTable->leftNoOrderedSubQuery; + pJoin->rightNoOrderedSubQuery = pJoinTable->leftNoOrderedSubQuery; code = nodesCloneNode(pJoinTable->pWindowOffset, &pJoin->pWindowOffset); if (TSDB_CODE_SUCCESS == code) { diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index be1632d740..2e23a9987b 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -630,8 +630,16 @@ static bool pdcJoinColInTableColList(SNode* pNode, SNodeList* pTableCols) { } static bool pdcJoinColInTableList(SNode* pCondCol, SSHashObj* pTables) { - SColumnNode* pTableCol = (SColumnNode*)pCondCol; - if (NULL == tSimpleHashGet(pTables, pTableCol->tableAlias, strlen(pTableCol->tableAlias))) { + char* pTableAlias = NULL; + if (QUERY_NODE_COLUMN == nodeType(pCondCol)) { + SColumnNode* pTableCol = (SColumnNode*)pCondCol; + pTableAlias = pTableCol->tableAlias; + } else if (QUERY_NODE_VALUE == nodeType(pCondCol)) { + SValueNode* pVal = (SValueNode*)pCondCol; + pTableAlias = pVal->node.srcTable; + } + + if (NULL == tSimpleHashGet(pTables, pTableAlias, strlen(pTableAlias))) { return false; } return true; @@ -835,8 +843,10 @@ static bool pdcJoinIsPrim(SNode* pNode, SSHashObj* pTables, bool constAsPrim, bo if (QUERY_NODE_VALUE == nodeType(pNode)) { SValueNode* pVal = (SValueNode*)pNode; if (TSDB_DATA_TYPE_NULL != pVal->node.resType.type && !pVal->isNull) { - *constPrimGot = true; - return true; + if (pdcJoinColInTableList(pNode, pTables)) { + *constPrimGot = true; + return true; + } } return false; @@ -890,15 +900,11 @@ static bool pdcJoinIsPrimEqualCond(SJoinLogicNode* pJoin, SNode* pCond, bool con } bool res = false, constGot = false; - if (pdcJoinIsPrim(pOper->pLeft, pLeftTables, constAsPrim, &constGot)) { - res = pdcJoinIsPrim(pOper->pRight, pRightTables, constAsPrim, &constGot); - if (constGot) { - pJoin->constPrimGot = true; - } - } else if (pdcJoinIsPrim(pOper->pLeft, pRightTables, constAsPrim, &constGot)) { - res = pdcJoinIsPrim(pOper->pRight, pLeftTables, constAsPrim, &constGot); - if (constGot) { - pJoin->constPrimGot = true; + if (pdcJoinIsPrim(pOper->pLeft, pLeftTables, constAsPrim, &pJoin->leftConstPrimGot)) { + res = pdcJoinIsPrim(pOper->pRight, pRightTables, constAsPrim, &pJoin->rightConstPrimGot); + } else if (pdcJoinIsPrim(pOper->pLeft, pRightTables, constAsPrim, &pJoin->rightConstPrimGot)) { + res = pdcJoinIsPrim(pOper->pRight, pLeftTables, constAsPrim, &pJoin->leftConstPrimGot); + if (pJoin->rightConstPrimGot || pJoin->leftConstPrimGot) { TSWAP(pOper->pLeft, pOper->pRight); } } @@ -940,12 +946,14 @@ static int32_t pdcJoinSplitPrimInLogicCond(SJoinLogicNode* pJoin, SNode** ppInpu SNode* pCond = NULL; WHERE_EACH(pCond, pLogicCond->pParameterList) { SNode* pNew = NULL; - code = nodesCloneNode(pCond, &pNew); - if (TSDB_CODE_SUCCESS != code) break; if (pdcJoinIsPrimEqualCond(pJoin, pCond, constAsPrim) && (NULL == *ppPrimEqCond)) { + code = nodesCloneNode(pCond, &pNew); + if (TSDB_CODE_SUCCESS != code) break; *ppPrimEqCond = pNew; ERASE_NODE(pLogicCond->pParameterList); } else { + code = nodesCloneNode(pCond, &pNew); + if (TSDB_CODE_SUCCESS != code) break; code = nodesListMakeAppend(&pOnConds, pNew); if (TSDB_CODE_SUCCESS != code) break; WHERE_NEXT; @@ -1448,7 +1456,7 @@ static int32_t pdcJoinSplitConstPrimEqCond(SOptimizeContext* pCxt, SJoinLogicNod if (TSDB_CODE_SUCCESS == code) { pJoin->pPrimKeyEqCond = pPrimKeyEqCond; *ppCond = pJoinOnCond; - if (pJoin->constPrimGot) { + if (pJoin->rightConstPrimGot || pJoin->leftConstPrimGot) { code = scalarConvertOpValueNodeTs((SOperatorNode*)pJoin->pPrimKeyEqCond); } } else { @@ -1478,7 +1486,8 @@ static int32_t pdcJoinCheckAllCond(SOptimizeContext* pCxt, SJoinLogicNode* pJoin SNode** ppCond = pJoin->pFullOnCond ? &pJoin->pFullOnCond : &pJoin->node.pConditions; bool errCond = false; - if (!pdcJoinHasPrimEqualCond(pJoin, *ppCond, &errCond)) { + bool primCondGot = pdcJoinHasPrimEqualCond(pJoin, *ppCond, &errCond); + if (!primCondGot) { 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); @@ -1486,7 +1495,8 @@ static int32_t pdcJoinCheckAllCond(SOptimizeContext* pCxt, SJoinLogicNode* pJoin if (IS_INNER_NONE_JOIN(pJoin->joinType, pJoin->subType) && NULL != pJoin->pFullOnCond && NULL != pJoin->node.pConditions) { - if (pdcJoinHasPrimEqualCond(pJoin, pJoin->node.pConditions, &errCond)) { + primCondGot = pdcJoinHasPrimEqualCond(pJoin, pJoin->node.pConditions, &errCond); + if (primCondGot) { return TSDB_CODE_SUCCESS; } if (errCond) { @@ -1497,7 +1507,9 @@ static int32_t pdcJoinCheckAllCond(SOptimizeContext* pCxt, SJoinLogicNode* pJoin if (IS_WINDOW_JOIN(pJoin->subType) || IS_ASOF_JOIN(pJoin->subType)) { return TSDB_CODE_SUCCESS; } + } + if (pJoin->leftNoOrderedSubQuery || pJoin->rightNoOrderedSubQuery || !primCondGot) { pJoin->noPrimKeyEqCond = true; int32_t code = pdcJoinSplitConstPrimEqCond(pCxt, pJoin, ppCond); if (code || pJoin->pPrimKeyEqCond) { @@ -1515,6 +1527,10 @@ static int32_t pdcJoinCheckAllCond(SOptimizeContext* pCxt, SJoinLogicNode* pJoin return generateUsageErrMsg(pCxt->pPlanCxt->pMsg, pCxt->pPlanCxt->msgLen, TSDB_CODE_PLAN_EXPECTED_TS_EQUAL); } + //if ((pJoin->leftNoOrderedSubQuery || pJoin->rightNoOrderedSubQuery) && !primCondGot) { + // return generateUsageErrMsg(pCxt->pPlanCxt->pMsg, pCxt->pPlanCxt->msgLen, TSDB_CODE_PAR_VALID_TS_SERIOUS_REQUIRED); + //} + if (IS_ASOF_JOIN(pJoin->subType)) { nodesDestroyNode(pJoin->addPrimEqCond); pJoin->addPrimEqCond = NULL; @@ -2680,7 +2696,7 @@ static int32_t sortForJoinOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan* pL bool res = false; SOperatorNode* pOp = (SOperatorNode*)pJoin->pPrimKeyEqCond; - if (QUERY_NODE_VALUE != nodeType(pOp->pLeft) || QUERY_NODE_VALUE != nodeType(pOp->pRight)) { + if (QUERY_NODE_VALUE == nodeType(pOp->pLeft) || QUERY_NODE_VALUE == nodeType(pOp->pRight)) { return TSDB_CODE_SUCCESS; } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 108379725c..8a7d940789 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -375,7 +375,7 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) { SSetSlotIdCxt* pCxt = (SSetSlotIdCxt*)pContext; char* name = NULL; int32_t len = 0; - pCxt->errCode = getSlotKey(pNode, NULL, &name, &len, 16); + pCxt->errCode = getSlotKey(pNode, NULL, &name, &len, 64); if (TSDB_CODE_SUCCESS != pCxt->errCode) { return DEAL_RES_ERROR; } @@ -386,7 +386,10 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) { if (!pIndex) { pIndex = taosHashGet(pCxt->pRightProdIdxHash, name, strlen(name)); } - } else { + } + + if (NULL == pIndex) { + name[len] = 0; pIndex = taosHashGet(pCxt->pLeftHash, name, len); if (NULL == pIndex) { pIndex = taosHashGet(pCxt->pRightHash, name, len); @@ -948,7 +951,7 @@ static int32_t setMergeJoinPrimColEqCond(SNode* pEqCond, int32_t subType, int16_ break; } case QUERY_NODE_VALUE: { - if (pJoinLogicNode && pJoinLogicNode->constPrimGot) { + if (pJoinLogicNode && pJoinLogicNode->leftConstPrimGot) { pJoin->leftPrimExpr = NULL; code = nodesCloneNode(pOp->pLeft, &pJoin->leftPrimExpr); break; @@ -1006,7 +1009,7 @@ static int32_t setMergeJoinPrimColEqCond(SNode* pEqCond, int32_t subType, int16_ break; } case QUERY_NODE_VALUE: { - if (pJoinLogicNode && pJoinLogicNode->constPrimGot) { + if (pJoinLogicNode && pJoinLogicNode->rightConstPrimGot) { pJoin->rightPrimExpr = NULL; code = nodesCloneNode(pOp->pRight, &pJoin->rightPrimExpr); break; @@ -1054,6 +1057,33 @@ static int32_t setMergeJoinPrimColEqCond(SNode* pEqCond, int32_t subType, int16_ return code; } +static int32_t removePrimColFromJoinTargets(SNodeList* pTargets, SValueNode* pLeftPrimExpr, SColumnNode** ppRemoved) { + int32_t code = TSDB_CODE_SUCCESS; + SNode* pNode = NULL; + FOREACH(pNode, pTargets) { + SColumnNode* pCol = (SColumnNode*)pNode; + if (0 == strcmp(pCol->tableAlias, pLeftPrimExpr->node.srcTable) && 0 == strcmp(pCol->colName, pLeftPrimExpr->node.aliasName)) { + code = nodesCloneNode(pNode, (SNode**)ppRemoved); + ERASE_NODE(pTargets); + break; + } + } + + return code; +} + +static int32_t appendPrimColToJoinTargets(SSortMergeJoinPhysiNode* pJoin, SColumnNode** ppTarget, STargetNode* primExpr, int16_t blkId) { + SColumnNode* pCol = *ppTarget; + pCol->dataBlockId = blkId; + pCol->slotId = primExpr->slotId; + int32_t code = nodesListMakeStrictAppend(&pJoin->pTargets, (SNode *)pCol); + if (TSDB_CODE_SUCCESS == code) { + *ppTarget = NULL; + } + + return code; +} + static int32_t createMergeJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode, SPhysiNode** pPhyNode) { SSortMergeJoinPhysiNode* pJoin = @@ -1115,11 +1145,32 @@ static int32_t createMergeJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChi nodesDestroyNode(pPrimKeyCond); } + SValueNode* pLeftPrimExpr = NULL, *pRightPrimExpr = NULL; + SColumnNode* pLeftTarget = NULL, *pRightTarget = NULL; + if (TSDB_CODE_SUCCESS == code && pJoinLogicNode->leftConstPrimGot && pJoin->leftPrimExpr + && QUERY_NODE_VALUE == nodeType(((STargetNode*)pJoin->leftPrimExpr)->pExpr)) { + pLeftPrimExpr = (SValueNode*)((STargetNode*)pJoin->leftPrimExpr)->pExpr; + code = removePrimColFromJoinTargets(pJoinLogicNode->node.pTargets, pLeftPrimExpr, &pLeftTarget); + } + + if (TSDB_CODE_SUCCESS == code && pJoinLogicNode->rightConstPrimGot && pJoin->rightPrimExpr + && QUERY_NODE_VALUE == nodeType(((STargetNode*)pJoin->rightPrimExpr)->pExpr)) { + pRightPrimExpr = (SValueNode*)((STargetNode*)pJoin->rightPrimExpr)->pExpr; + code = removePrimColFromJoinTargets(pJoinLogicNode->node.pTargets, pRightPrimExpr, &pRightTarget); + } + if (TSDB_CODE_SUCCESS == code) { code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets, &pJoin->pTargets); } + if (TSDB_CODE_SUCCESS == code && pLeftPrimExpr && pLeftTarget) { + code = appendPrimColToJoinTargets(pJoin, &pLeftTarget, (STargetNode*)pJoin->leftPrimExpr, pLeftDesc->dataBlockId); + } + if (TSDB_CODE_SUCCESS == code && pRightPrimExpr && pRightTarget) { + code = appendPrimColToJoinTargets(pJoin, &pRightTarget, (STargetNode*)pJoin->rightPrimExpr, pRightDesc->dataBlockId); + } + if (TSDB_CODE_SUCCESS == code && NULL != pJoinLogicNode->pFullOnCond) { code = setNodeSlotId(pCxt, ((SPhysiNode*)pJoin)->pOutputDataBlockDesc->dataBlockId, -1, pJoinLogicNode->pFullOnCond, &pJoin->pFullOnCond); @@ -1171,6 +1222,8 @@ static int32_t createMergeJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChi *pPhyNode = (SPhysiNode*)pJoin; } else { nodesDestroyNode((SNode*)pJoin); + nodesDestroyNode((SNode*)pLeftTarget); + nodesDestroyNode((SNode*)pRightTarget); } return code; diff --git a/source/libs/planner/src/planUtil.c b/source/libs/planner/src/planUtil.c index a31b132cae..311116335e 100644 --- a/source/libs/planner/src/planUtil.c +++ b/source/libs/planner/src/planUtil.c @@ -26,6 +26,8 @@ static char* getUsageErrFormat(int32_t errCode) { return "not support cross join"; case TSDB_CODE_PLAN_NOT_SUPPORT_JOIN_COND: return "Not supported join conditions"; + case TSDB_CODE_PAR_VALID_TS_SERIOUS_REQUIRED: + return "Valid time series required as input"; default: break; } diff --git a/tests/army/query/joinConst/inner.in b/tests/army/query/joinConst/inner.in new file mode 100644 index 0000000000..fcd0bee97d --- /dev/null +++ b/tests/army/query/joinConst/inner.in @@ -0,0 +1,153 @@ +use test; +select * from a1 a join (select __today__ as ts, f, g, 'a' from b1) b on a.ts = b.ts; +select * from a1 a join (select __today__ as ts1, f, g, 'a' from b1) b on a.ts = b.ts1; +select a.* from a1 a join (select __today__ as ts, f, g, 'a' from b1) b on a.ts = b.ts; +select b.* from a1 a join (select __today__ as ts, f, g, 'a' from b1) b on a.ts = b.ts; +select b.* from a1 a join (select __today__ as ts1, f, g, 'a' from b1) b on a.ts = b.ts1; +select a.*, b.ts from a1 a join (select __today__ as ts1,ts, f, g, 'a' from b1) b on a.ts = b.ts1; +select b.c from a1 a join (select __today__ as ts, f, g, 'a' c from b1) b on a.ts = b.ts; +select b.ts from a1 a join (select __today__ as ts, f, g, 'a' c from b1) b on a.ts = b.ts; +select * from a1 a join (select __today__ as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts; +select a.* from a1 a join (select __today__ as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts; +select b.* from a1 a join (select __today__ as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts; +select b.c from a1 a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts; +select * from a1 a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts; +select a.* from a1 a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts; +select b.* from a1 a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts; +select b.ts1,a.ts from a1 a join (select __today__ as ts1, f, g, 'a' c from b1) b on b.ts1 = a.ts; +select * from a1 a join (select __today__ as ts1, ts, f, g, 'a' from b1) b on a.ts = b.ts; +select a.* from a1 a join (select __today__ as ts1, ts, f, g, 'a' from b1) b on a.ts = b.ts; +select b.* from a1 a join (select __today__ as ts1, ts, f, g, 'a' from b1) b on a.ts = b.ts; +select b.c from a1 a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on a.ts = b.ts; +select b.ts from a1 a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on a.ts = b.ts; +select * from a1 a join (select __today__ as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts and a.ts = b.ts; +select a.* from a1 a join (select __today__ as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts and a.ts = b.ts; +select b.* from a1 a join (select __today__ as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts and a.ts = b.ts; +select b.c from a1 a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts and a.ts = b.ts; +select b.ts from a1 a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts and a.ts = b.ts; +select * from a1 a join (select __today__ as ts1, ts, f, g, 'a' from b1) b on b.ts = a.ts and a.ts = b.ts1; +select a.* from a1 a join (select __today__ as ts1, ts, f, g, 'a' from b1) b on b.ts = a.ts and a.ts = b.ts1; +select b.* from a1 a join (select __today__ as ts1, ts, f, g, 'a' from b1) b on b.ts = a.ts and a.ts = b.ts1; +select b.c from a1 a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; +select b.ts from a1 a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from a1) a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from a1) a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts1 and a.ts = b.ts; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from a1 order by f) a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from a1 order by f) a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts1 and a.ts = b.ts; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from a1 order by f) a join (select __today__ as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from a1) a join (select now() as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; +select * from (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta join (select __today__ ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb on ta.ts=tb.ts and ta.tg1=tb.tg1; +select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta join (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb on ta.ts=tb.ts and ta.tg2=tb.tg2; +select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta join (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb on ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val; +select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta join (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=__today__ where tb.ts=__today__ order by tb.val; +select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta join (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>__today__ where tb.ts>__today__; +select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta join (select today() + 1d +3s ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb on ta.ts=tb.ts and ta.tg2=tb.tg2; + +select * from (select __today__ as ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; +select * from (select __today__ as ts1, f, g, 'a' from b1) b join a1 a on a.ts = b.ts1; +select a.* from (select __today__ as ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; +select b.* from (select __today__ as ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; +select b.* from (select __today__ as ts1, f, g, 'a' from b1) b join a1 a on a.ts = b.ts1; +select b.c from (select __today__ as ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts; +select b.ts from (select __today__ as ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts; +select * from (select __today__ as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts; +select a.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts; +select b.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts; +select b.c from (select __today__ as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts; +select b.ts1 from (select __today__ as ts1, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts; +select * from (select __today__ as ts1, ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; +select a.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; +select b.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; +select b.c from (select __today__ as ts1, ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts; +select * from (select __today__ as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; +select a.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; +select b.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; +select b.c from (select __today__ as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; +select * from (select __today__ as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; +select a.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; +select b.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; +select b.c from (select __today__ as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; +select * from (select __today__ ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb join (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta on ta.ts=tb.ts and ta.tg1=tb.tg1; +select * from (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2; +select * from (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val;; +select * from (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=__today__ where tb.ts=__today__ order by tb.val; +select * from (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>__today__ where tb.ts>__today__; + + + +select * from a1 a , (select __today__ as ts, f, g, 'a' from b1) b where a.ts = b.ts; +select * from a1 a , (select __today__ as ts1, f, g, 'a' from b1) b where a.ts = b.ts1; +select a.* from a1 a , (select __today__ as ts, f, g, 'a' from b1) b where a.ts = b.ts; +select b.* from a1 a , (select __today__ as ts, f, g, 'a' from b1) b where a.ts = b.ts; +select b.c from a1 a , (select __today__ as ts, f, g, 'a' c from b1) b where a.ts = b.ts; +select b.ts from a1 a , (select __today__ as ts, f, g, 'a' c from b1) b where a.ts = b.ts; +select b.ts1 from a1 a , (select __today__ as ts1, f, g, 'a' c from b1) b where a.ts = b.ts1; +select * from a1 a , (select __today__ as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts; +select a.* from a1 a , (select __today__ as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts; +select b.* from a1 a , (select __today__ as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts; +select b.c from a1 a , (select __today__ as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts; +select b.ts1 from a1 a , (select __today__ as ts1, f, g, 'a' c from b1) b where b.ts1 = a.ts; +select * from a1 a , (select __today__ as ts1, ts, f, g, 'a' from b1) b where a.ts = b.ts; +select a.* from a1 a , (select __today__ as ts1, ts, f, g, 'a' from b1) b where a.ts = b.ts; +select b.* from a1 a , (select __today__ as ts1, ts, f, g, 'a' from b1) b where a.ts = b.ts; +select b.c from a1 a , (select __today__ as ts1, ts, f, g, 'a' c from b1) b where a.ts = b.ts; +select b.ts from a1 a , (select __today__ as ts1, ts, f, g, 'a' c from b1) b where a.ts = b.ts; +select * from a1 a , (select __today__ as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts and a.ts = b.ts; +select a.* from a1 a , (select __today__ as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts and a.ts = b.ts; +select b.* from a1 a , (select __today__ as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts and a.ts = b.ts; +select b.c from a1 a , (select __today__ as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts and a.ts = b.ts; +select b.ts from a1 a , (select __today__ as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts and a.ts = b.ts; +select * from a1 a , (select __today__ as ts1, ts, f, g, 'a' from b1) b where b.ts = a.ts and a.ts = b.ts1; +select a.* from a1 a , (select __today__ as ts1, ts, f, g, 'a' from b1) b where b.ts = a.ts and a.ts = b.ts1; +select b.* from a1 a , (select __today__ as ts1, ts, f, g, 'a' from b1) b where b.ts = a.ts and a.ts = b.ts1; +select b.c from a1 a , (select __today__ as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; +select b.ts from a1 a , (select __today__ as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from a1) a , (select __today__ as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from a1) a , (select __today__ as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts1 and a.ts = b.ts; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from a1 order by f) a , (select __today__ as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from a1 order by f) a , (select __today__ as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts1 and a.ts = b.ts; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from a1 order by f) a , (select __today__ as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; +select * from (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta , (select __today__ ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb where ta.ts=tb.ts and ta.tg1=tb.tg1; +select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta , (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb where ta.ts=tb.ts and ta.tg2=tb.tg2; +select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta , (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb where ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val; +select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta , (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=__today__ order by tb.val; +select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta , (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>__today__ ; + +select * from (select __today__ as ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; +select * from (select __today__ as ts1, f, g, 'a' from b1) b , a1 a where a.ts = b.ts1; +select a.* from (select __today__ as ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; +select b.* from (select __today__ as ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; +select b.c from (select __today__ as ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts; +select b.ts from (select __today__ as ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts; +select b.ts1 from (select __today__ as ts1, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts1; +select * from (select __today__ as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts; +select a.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts; +select b.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts; +select b.c from (select __today__ as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts; +select b.ts1 from (select __today__ as ts1, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts; +select * from (select __today__ as ts1, ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; +select a.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; +select b.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; +select b.c from (select __today__ as ts1, ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts; +select * from (select __today__ as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; +select a.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; +select b.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; +select b.c from (select __today__ as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; +select * from (select __today__ as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; +select a.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; +select b.* from (select __today__ as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; +select b.c from (select __today__ as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; +select b.ts from (select __today__ as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; +select * from (select __today__ ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb , (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta where ta.ts=tb.ts and ta.tg1=tb.tg1; +select * from (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2; +select * from (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val; +select * from (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=__today__ order by tb.val; +select * from (select __today__ ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>__today__ ; + + + diff --git a/tests/army/query/joinConst/inner.today.csv b/tests/army/query/joinConst/inner.today.csv new file mode 100644 index 0000000000..16bc5787e2 --- /dev/null +++ b/tests/army/query/joinConst/inner.today.csv @@ -0,0 +1,969 @@ + +taos> use test; +Database changed. + +taos> select * from a1 a join (select today as ts, f, g, 'a' from b1) b on a.ts = b.ts; + ts | f | g | ts | f | g | 'a' | +================================================================================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select * from a1 a join (select today as ts1, f, g, 'a' from b1) b on a.ts = b.ts1; + ts | f | g | ts1 | f | g | 'a' | +================================================================================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select a.* from a1 a join (select today as ts, f, g, 'a' from b1) b on a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a join (select today as ts, f, g, 'a' from b1) b on a.ts = b.ts; + ts | f | g | 'a' | +============================================================ + 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select b.* from a1 a join (select today as ts1, f, g, 'a' from b1) b on a.ts = b.ts1; + ts1 | f | g | 'a' | +============================================================ + 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select a.*, b.ts from a1 a join (select today as ts1,ts, f, g, 'a' from b1) b on a.ts = b.ts1; + ts | f | g | ts | +================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:01.000 | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-04 00:00:00.000 | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-04 00:00:02.000 | + +taos> select b.c from a1 a join (select today as ts, f, g, 'a' c from b1) b on a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from a1 a join (select today as ts, f, g, 'a' c from b1) b on a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select * from a1 a join (select today as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select a.* from a1 a join (select today as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a join (select today as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from a1 a join (select today as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts; + c | +====== + a | + a | + a | + a | + +taos> select * from a1 a join (select today as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts; + ts | f | g | ts1 | ts | f | g | c | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:01.000 | 102 | 1012 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-04 00:00:00.000 | 103 | 1013 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-04 00:00:02.000 | 104 | 1014 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select a.* from a1 a join (select today as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:01.000 | 102 | 1012 | + 2025-03-04 00:00:00.000 | 103 | 1013 | + 2025-03-04 00:00:02.000 | 104 | 1014 | + +taos> select b.* from a1 a join (select today as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts; + ts1 | ts | f | g | c | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.ts1,a.ts from a1 a join (select today as ts1, f, g, 'a' c from b1) b on b.ts1 = a.ts; + ts1 | ts | +==================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | + +taos> select * from a1 a join (select today as ts1, ts, f, g, 'a' from b1) b on a.ts = b.ts; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:01.000 | 102 | 1012 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-04 00:00:00.000 | 103 | 1013 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-04 00:00:02.000 | 104 | 1014 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select a.* from a1 a join (select today as ts1, ts, f, g, 'a' from b1) b on a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:01.000 | 102 | 1012 | + 2025-03-04 00:00:00.000 | 103 | 1013 | + 2025-03-04 00:00:02.000 | 104 | 1014 | + +taos> select b.* from a1 a join (select today as ts1, ts, f, g, 'a' from b1) b on a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from a1 a join (select today as ts1, ts, f, g, 'a' c from b1) b on a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from a1 a join (select today as ts1, ts, f, g, 'a' c from b1) b on a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select * from a1 a join (select today as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts and a.ts = b.ts; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select a.* from a1 a join (select today as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts and a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a join (select today as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts and a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from a1 a join (select today as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts and a.ts = b.ts; + c | +====== + a | + +taos> select b.ts from a1 a join (select today as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select * from a1 a join (select today as ts1, ts, f, g, 'a' from b1) b on b.ts = a.ts and a.ts = b.ts1; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select a.* from a1 a join (select today as ts1, ts, f, g, 'a' from b1) b on b.ts = a.ts and a.ts = b.ts1; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a join (select today as ts1, ts, f, g, 'a' from b1) b on b.ts = a.ts and a.ts = b.ts1; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from a1 a join (select today as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; + c | +====== + a | + +taos> select b.ts from a1 a join (select today as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from a1) a join (select today as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from a1) a join (select today as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts1 and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from a1 order by f) a join (select today as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from a1 order by f) a join (select today as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts1 and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from a1 order by f) a join (select today as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from a1) a join (select now() as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta join (select today ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb on ta.ts=tb.ts and ta.tg1=tb.tg1; + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta join (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb on ta.ts=tb.ts and ta.tg2=tb.tg2; + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta join (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb on ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 301 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 302 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 303 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 304 | 1 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 401 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 402 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 403 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 404 | 2 | + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta join (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=today where tb.ts=today order by tb.val; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 301 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 302 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 303 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 304 | 1 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 401 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 402 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 403 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 404 | 2 | + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta join (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>today where tb.ts>today; + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta join (select today() + 1d +3s ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb on ta.ts=tb.ts and ta.tg2=tb.tg2; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-04 00:00:03.000 | 204 | 2 | 2025-03-04 00:00:03.000 | 404 | 2 | + +taos> select * from (select today as ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; + ts | f | g | 'a' | ts | f | g | +================================================================================================================== + 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select * from (select today as ts1, f, g, 'a' from b1) b join a1 a on a.ts = b.ts1; + ts1 | f | g | 'a' | ts | f | g | +================================================================================================================== + 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today as ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today as ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; + ts | f | g | 'a' | +============================================================ + 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select b.* from (select today as ts1, f, g, 'a' from b1) b join a1 a on a.ts = b.ts1; + ts1 | f | g | 'a' | +============================================================ + 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select b.c from (select today as ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from (select today as ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select * from (select today as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from (select today as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts1 from (select today as ts1, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts; + ts1 | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select * from (select today as ts1, ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | 2025-03-03 00:00:01.000 | 102 | 1012 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | 2025-03-04 00:00:00.000 | 103 | 1013 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | 2025-03-04 00:00:02.000 | 104 | 1014 | + +taos> select a.* from (select today as ts1, ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:01.000 | 102 | 1012 | + 2025-03-04 00:00:00.000 | 103 | 1013 | + 2025-03-04 00:00:02.000 | 104 | 1014 | + +taos> select b.* from (select today as ts1, ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from (select today as ts1, ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select * from (select today as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from (select today as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; + c | +====== + a | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select * from (select today as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from (select today as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; + c | +====== + a | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select * from (select today ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb join (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta on ta.ts=tb.ts and ta.tg1=tb.tg1; + +taos> select * from (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2; + +taos> select * from (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val;; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 301 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 302 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 303 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 304 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 401 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 402 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 403 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 404 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + +taos> select * from (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=today where tb.ts=today order by tb.val; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 301 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 302 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 303 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 304 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 401 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 402 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 403 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 404 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + +taos> select * from (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>today where tb.ts>today; + +taos> select * from a1 a , (select today as ts, f, g, 'a' from b1) b where a.ts = b.ts; + ts | f | g | ts | f | g | 'a' | +================================================================================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select * from a1 a , (select today as ts1, f, g, 'a' from b1) b where a.ts = b.ts1; + ts | f | g | ts1 | f | g | 'a' | +================================================================================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select a.* from a1 a , (select today as ts, f, g, 'a' from b1) b where a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a , (select today as ts, f, g, 'a' from b1) b where a.ts = b.ts; + ts | f | g | 'a' | +============================================================ + 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select b.c from a1 a , (select today as ts, f, g, 'a' c from b1) b where a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from a1 a , (select today as ts, f, g, 'a' c from b1) b where a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select b.ts1 from a1 a , (select today as ts1, f, g, 'a' c from b1) b where a.ts = b.ts1; + ts1 | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select * from a1 a , (select today as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select a.* from a1 a , (select today as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a , (select today as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from a1 a , (select today as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts1 from a1 a , (select today as ts1, f, g, 'a' c from b1) b where b.ts1 = a.ts; + ts1 | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select * from a1 a , (select today as ts1, ts, f, g, 'a' from b1) b where a.ts = b.ts; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:01.000 | 102 | 1012 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-04 00:00:00.000 | 103 | 1013 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-04 00:00:02.000 | 104 | 1014 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select a.* from a1 a , (select today as ts1, ts, f, g, 'a' from b1) b where a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:01.000 | 102 | 1012 | + 2025-03-04 00:00:00.000 | 103 | 1013 | + 2025-03-04 00:00:02.000 | 104 | 1014 | + +taos> select b.* from a1 a , (select today as ts1, ts, f, g, 'a' from b1) b where a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from a1 a , (select today as ts1, ts, f, g, 'a' c from b1) b where a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from a1 a , (select today as ts1, ts, f, g, 'a' c from b1) b where a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select * from a1 a , (select today as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts and a.ts = b.ts; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select a.* from a1 a , (select today as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts and a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a , (select today as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts and a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from a1 a , (select today as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts and a.ts = b.ts; + c | +====== + a | + +taos> select b.ts from a1 a , (select today as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select * from a1 a , (select today as ts1, ts, f, g, 'a' from b1) b where b.ts = a.ts and a.ts = b.ts1; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select a.* from a1 a , (select today as ts1, ts, f, g, 'a' from b1) b where b.ts = a.ts and a.ts = b.ts1; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a , (select today as ts1, ts, f, g, 'a' from b1) b where b.ts = a.ts and a.ts = b.ts1; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from a1 a , (select today as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; + c | +====== + a | + +taos> select b.ts from a1 a , (select today as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from a1) a , (select today as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from a1) a , (select today as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts1 and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from a1 order by f) a , (select today as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from a1 order by f) a , (select today as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts1 and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from a1 order by f) a , (select today as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta , (select today ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb where ta.ts=tb.ts and ta.tg1=tb.tg1; + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta , (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb where ta.ts=tb.ts and ta.tg2=tb.tg2; + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta , (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb where ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 301 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 302 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 303 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 304 | 1 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 401 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 402 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 403 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 404 | 2 | + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta , (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=today order by tb.val; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 301 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 302 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 303 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 304 | 1 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 401 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 402 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 403 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 404 | 2 | + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta , (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>today ; + +taos> select * from (select today as ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; + ts | f | g | 'a' | ts | f | g | +================================================================================================================== + 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select * from (select today as ts1, f, g, 'a' from b1) b , a1 a where a.ts = b.ts1; + ts1 | f | g | 'a' | ts | f | g | +================================================================================================================== + 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today as ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today as ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; + ts | f | g | 'a' | +============================================================ + 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select b.c from (select today as ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from (select today as ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select b.ts1 from (select today as ts1, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts1; + ts1 | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select * from (select today as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from (select today as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts1 from (select today as ts1, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts; + ts1 | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select * from (select today as ts1, ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | 2025-03-03 00:00:01.000 | 102 | 1012 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | 2025-03-04 00:00:00.000 | 103 | 1013 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | 2025-03-04 00:00:02.000 | 104 | 1014 | + +taos> select a.* from (select today as ts1, ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:01.000 | 102 | 1012 | + 2025-03-04 00:00:00.000 | 103 | 1013 | + 2025-03-04 00:00:02.000 | 104 | 1014 | + +taos> select b.* from (select today as ts1, ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from (select today as ts1, ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select * from (select today as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from (select today as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; + c | +====== + a | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select * from (select today as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from (select today as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; + c | +====== + a | + +taos> select b.ts from (select today as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select * from (select today ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb , (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta where ta.ts=tb.ts and ta.tg1=tb.tg1; + +taos> select * from (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2; + +taos> select * from (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 301 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 302 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 303 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 304 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 401 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 402 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 403 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 404 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + +taos> select * from (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=today order by tb.val; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 301 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 302 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 303 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 304 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 401 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 402 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 403 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 404 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + +taos> select * from (select today ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>today ; + diff --git a/tests/army/query/joinConst/inner.today_.csv b/tests/army/query/joinConst/inner.today_.csv new file mode 100644 index 0000000000..5f613e1b93 --- /dev/null +++ b/tests/army/query/joinConst/inner.today_.csv @@ -0,0 +1,969 @@ + +taos> use test; +Database changed. + +taos> select * from a1 a join (select today() as ts, f, g, 'a' from b1) b on a.ts = b.ts; + ts | f | g | ts | f | g | 'a' | +================================================================================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select * from a1 a join (select today() as ts1, f, g, 'a' from b1) b on a.ts = b.ts1; + ts | f | g | ts1 | f | g | 'a' | +================================================================================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select a.* from a1 a join (select today() as ts, f, g, 'a' from b1) b on a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a join (select today() as ts, f, g, 'a' from b1) b on a.ts = b.ts; + ts | f | g | 'a' | +============================================================ + 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select b.* from a1 a join (select today() as ts1, f, g, 'a' from b1) b on a.ts = b.ts1; + ts1 | f | g | 'a' | +============================================================ + 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select a.*, b.ts from a1 a join (select today() as ts1,ts, f, g, 'a' from b1) b on a.ts = b.ts1; + ts | f | g | ts | +================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:01.000 | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-04 00:00:00.000 | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-04 00:00:02.000 | + +taos> select b.c from a1 a join (select today() as ts, f, g, 'a' c from b1) b on a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from a1 a join (select today() as ts, f, g, 'a' c from b1) b on a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select * from a1 a join (select today() as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select a.* from a1 a join (select today() as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a join (select today() as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from a1 a join (select today() as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts; + c | +====== + a | + a | + a | + a | + +taos> select * from a1 a join (select today() as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts; + ts | f | g | ts1 | ts | f | g | c | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:01.000 | 102 | 1012 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-04 00:00:00.000 | 103 | 1013 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-04 00:00:02.000 | 104 | 1014 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select a.* from a1 a join (select today() as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:01.000 | 102 | 1012 | + 2025-03-04 00:00:00.000 | 103 | 1013 | + 2025-03-04 00:00:02.000 | 104 | 1014 | + +taos> select b.* from a1 a join (select today() as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts; + ts1 | ts | f | g | c | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.ts1,a.ts from a1 a join (select today() as ts1, f, g, 'a' c from b1) b on b.ts1 = a.ts; + ts1 | ts | +==================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | + +taos> select * from a1 a join (select today() as ts1, ts, f, g, 'a' from b1) b on a.ts = b.ts; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:01.000 | 102 | 1012 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-04 00:00:00.000 | 103 | 1013 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-04 00:00:02.000 | 104 | 1014 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select a.* from a1 a join (select today() as ts1, ts, f, g, 'a' from b1) b on a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:01.000 | 102 | 1012 | + 2025-03-04 00:00:00.000 | 103 | 1013 | + 2025-03-04 00:00:02.000 | 104 | 1014 | + +taos> select b.* from a1 a join (select today() as ts1, ts, f, g, 'a' from b1) b on a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from a1 a join (select today() as ts1, ts, f, g, 'a' c from b1) b on a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from a1 a join (select today() as ts1, ts, f, g, 'a' c from b1) b on a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select * from a1 a join (select today() as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts and a.ts = b.ts; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select a.* from a1 a join (select today() as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts and a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a join (select today() as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts and a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from a1 a join (select today() as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts and a.ts = b.ts; + c | +====== + a | + +taos> select b.ts from a1 a join (select today() as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select * from a1 a join (select today() as ts1, ts, f, g, 'a' from b1) b on b.ts = a.ts and a.ts = b.ts1; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select a.* from a1 a join (select today() as ts1, ts, f, g, 'a' from b1) b on b.ts = a.ts and a.ts = b.ts1; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a join (select today() as ts1, ts, f, g, 'a' from b1) b on b.ts = a.ts and a.ts = b.ts1; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from a1 a join (select today() as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; + c | +====== + a | + +taos> select b.ts from a1 a join (select today() as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from a1) a join (select today() as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from a1) a join (select today() as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts1 and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from a1 order by f) a join (select today() as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from a1 order by f) a join (select today() as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts1 and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from a1 order by f) a join (select today() as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from a1) a join (select now() as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1; + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta join (select today() ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb on ta.ts=tb.ts and ta.tg1=tb.tg1; + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta join (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb on ta.ts=tb.ts and ta.tg2=tb.tg2; + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta join (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb on ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 301 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 302 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 303 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 304 | 1 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 401 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 402 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 403 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 404 | 2 | + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta join (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=today() where tb.ts=today() order by tb.val; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 301 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 302 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 303 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 304 | 1 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 401 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 402 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 403 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 404 | 2 | + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta join (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>today() where tb.ts>today(); + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta join (select today() + 1d +3s ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb on ta.ts=tb.ts and ta.tg2=tb.tg2; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-04 00:00:03.000 | 204 | 2 | 2025-03-04 00:00:03.000 | 404 | 2 | + +taos> select * from (select today() as ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; + ts | f | g | 'a' | ts | f | g | +================================================================================================================== + 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select * from (select today() as ts1, f, g, 'a' from b1) b join a1 a on a.ts = b.ts1; + ts1 | f | g | 'a' | ts | f | g | +================================================================================================================== + 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today() as ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today() as ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; + ts | f | g | 'a' | +============================================================ + 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select b.* from (select today() as ts1, f, g, 'a' from b1) b join a1 a on a.ts = b.ts1; + ts1 | f | g | 'a' | +============================================================ + 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select b.c from (select today() as ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from (select today() as ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select * from (select today() as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today() as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today() as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from (select today() as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts1 from (select today() as ts1, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts; + ts1 | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select * from (select today() as ts1, ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | 2025-03-03 00:00:01.000 | 102 | 1012 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | 2025-03-04 00:00:00.000 | 103 | 1013 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | 2025-03-04 00:00:02.000 | 104 | 1014 | + +taos> select a.* from (select today() as ts1, ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:01.000 | 102 | 1012 | + 2025-03-04 00:00:00.000 | 103 | 1013 | + 2025-03-04 00:00:02.000 | 104 | 1014 | + +taos> select b.* from (select today() as ts1, ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from (select today() as ts1, ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select * from (select today() as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today() as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today() as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from (select today() as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; + c | +====== + a | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select * from (select today() as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today() as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today() as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from (select today() as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; + c | +====== + a | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select * from (select today() ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb join (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta on ta.ts=tb.ts and ta.tg1=tb.tg1; + +taos> select * from (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2; + +taos> select * from (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val;; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 301 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 302 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 303 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 304 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 401 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 402 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 403 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 404 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + +taos> select * from (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=today() where tb.ts=today() order by tb.val; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 301 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 302 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 303 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 304 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 401 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 402 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 403 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 404 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + +taos> select * from (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>today() where tb.ts>today(); + +taos> select * from a1 a , (select today() as ts, f, g, 'a' from b1) b where a.ts = b.ts; + ts | f | g | ts | f | g | 'a' | +================================================================================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select * from a1 a , (select today() as ts1, f, g, 'a' from b1) b where a.ts = b.ts1; + ts | f | g | ts1 | f | g | 'a' | +================================================================================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select a.* from a1 a , (select today() as ts, f, g, 'a' from b1) b where a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a , (select today() as ts, f, g, 'a' from b1) b where a.ts = b.ts; + ts | f | g | 'a' | +============================================================ + 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select b.c from a1 a , (select today() as ts, f, g, 'a' c from b1) b where a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from a1 a , (select today() as ts, f, g, 'a' c from b1) b where a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select b.ts1 from a1 a , (select today() as ts1, f, g, 'a' c from b1) b where a.ts = b.ts1; + ts1 | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select * from a1 a , (select today() as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select a.* from a1 a , (select today() as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a , (select today() as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from a1 a , (select today() as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts1 from a1 a , (select today() as ts1, f, g, 'a' c from b1) b where b.ts1 = a.ts; + ts1 | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select * from a1 a , (select today() as ts1, ts, f, g, 'a' from b1) b where a.ts = b.ts; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:01.000 | 102 | 1012 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-04 00:00:00.000 | 103 | 1013 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-04 00:00:02.000 | 104 | 1014 | 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select a.* from a1 a , (select today() as ts1, ts, f, g, 'a' from b1) b where a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:01.000 | 102 | 1012 | + 2025-03-04 00:00:00.000 | 103 | 1013 | + 2025-03-04 00:00:02.000 | 104 | 1014 | + +taos> select b.* from a1 a , (select today() as ts1, ts, f, g, 'a' from b1) b where a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from a1 a , (select today() as ts1, ts, f, g, 'a' c from b1) b where a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from a1 a , (select today() as ts1, ts, f, g, 'a' c from b1) b where a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select * from a1 a , (select today() as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts and a.ts = b.ts; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select a.* from a1 a , (select today() as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts and a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a , (select today() as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts and a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from a1 a , (select today() as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts and a.ts = b.ts; + c | +====== + a | + +taos> select b.ts from a1 a , (select today() as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select * from a1 a , (select today() as ts1, ts, f, g, 'a' from b1) b where b.ts = a.ts and a.ts = b.ts1; + ts | f | g | ts1 | ts | f | g | 'a' | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1011 | 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select a.* from a1 a , (select today() as ts1, ts, f, g, 'a' from b1) b where b.ts = a.ts and a.ts = b.ts1; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from a1 a , (select today() as ts1, ts, f, g, 'a' from b1) b where b.ts = a.ts and a.ts = b.ts1; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from a1 a , (select today() as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; + c | +====== + a | + +taos> select b.ts from a1 a , (select today() as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from a1) a , (select today() as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from a1) a , (select today() as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts1 and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from a1 order by f) a , (select today() as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from a1 order by f) a , (select today() as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts1 and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from a1 order by f) a , (select today() as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta , (select today() ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb where ta.ts=tb.ts and ta.tg1=tb.tg1; + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta , (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb where ta.ts=tb.ts and ta.tg2=tb.tg2; + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta , (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb where ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 301 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 302 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 303 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 304 | 1 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 401 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 402 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 403 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 404 | 2 | + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta , (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=today() order by tb.val; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 301 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 302 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 303 | 1 | + 2025-03-03 00:00:00.000 | 101 | 1 | 2025-03-03 00:00:00.000 | 304 | 1 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 401 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 402 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 403 | 2 | + 2025-03-03 00:00:00.000 | 201 | 2 | 2025-03-03 00:00:00.000 | 404 | 2 | + +taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta , (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>today() ; + +taos> select * from (select today() as ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; + ts | f | g | 'a' | ts | f | g | +================================================================================================================== + 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select * from (select today() as ts1, f, g, 'a' from b1) b , a1 a where a.ts = b.ts1; + ts1 | f | g | 'a' | ts | f | g | +================================================================================================================== + 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today() as ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today() as ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; + ts | f | g | 'a' | +============================================================ + 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 304 | 3014 | a | + +taos> select b.c from (select today() as ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from (select today() as ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select b.ts1 from (select today() as ts1, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts1; + ts1 | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select * from (select today() as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today() as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today() as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from (select today() as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts1 from (select today() as ts1, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts; + ts1 | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:00.000 | + +taos> select * from (select today() as ts1, ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | 2025-03-03 00:00:01.000 | 102 | 1012 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | 2025-03-04 00:00:00.000 | 103 | 1013 | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | 2025-03-04 00:00:02.000 | 104 | 1014 | + +taos> select a.* from (select today() as ts1, ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + 2025-03-03 00:00:01.000 | 102 | 1012 | + 2025-03-04 00:00:00.000 | 103 | 1013 | + 2025-03-04 00:00:02.000 | 104 | 1014 | + +taos> select b.* from (select today() as ts1, ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:01.000 | 302 | 3012 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:00.000 | 303 | 3013 | a | + 2025-03-03 00:00:00.000 | 2025-03-04 00:00:02.000 | 304 | 3014 | a | + +taos> select b.c from (select today() as ts1, ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts; + c | +====== + a | + a | + a | + a | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + 2025-03-03 00:00:01.000 | + 2025-03-04 00:00:00.000 | + 2025-03-04 00:00:02.000 | + +taos> select * from (select today() as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today() as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today() as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from (select today() as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; + c | +====== + a | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select * from (select today() as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; + ts1 | ts | f | g | 'a' | ts | f | g | +============================================================================================================================================ + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select a.* from (select today() as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; + ts | f | g | +====================================================== + 2025-03-03 00:00:00.000 | 101 | 1011 | + +taos> select b.* from (select today() as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; + ts1 | ts | f | g | 'a' | +====================================================================================== + 2025-03-03 00:00:00.000 | 2025-03-03 00:00:00.000 | 301 | 3011 | a | + +taos> select b.c from (select today() as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; + c | +====== + a | + +taos> select b.ts from (select today() as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1; + ts | +========================== + 2025-03-03 00:00:00.000 | + +taos> select * from (select today() ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb , (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta where ta.ts=tb.ts and ta.tg1=tb.tg1; + +taos> select * from (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2; + +taos> select * from (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 301 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 302 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 303 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 304 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 401 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 402 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 403 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 404 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + +taos> select * from (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=today() order by tb.val; + ts | val | tg2 | ts | val | tg2 | +============================================================================================================ + 2025-03-03 00:00:00.000 | 301 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 302 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 303 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 304 | 1 | 2025-03-03 00:00:00.000 | 101 | 1 | + 2025-03-03 00:00:00.000 | 401 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 402 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 403 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + 2025-03-03 00:00:00.000 | 404 | 2 | 2025-03-03 00:00:00.000 | 201 | 2 | + +taos> select * from (select today() ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>today() ; + diff --git a/tests/army/query/test_join_const.py b/tests/army/query/test_join_const.py new file mode 100644 index 0000000000..ab19980c68 --- /dev/null +++ b/tests/army/query/test_join_const.py @@ -0,0 +1,121 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +from frame import etool +from frame.etool import * +from frame.log import * +from frame.cases import * +from frame.sql import * +from frame.caseBase import * +from frame.common import * + +class TDTestCase(TBase): + updatecfgDict = { + "slowLogScope": "none" + } + + def insert_data(self): + tdLog.printNoPrefix("==========step1:create table") + + tdSql.execute("drop database if exists test") + tdSql.execute("create database test keep 36500") + tdSql.execute("use test") + tdSql.execute("create table sta(ts timestamp, f int, g int) tags (tg1 int, tg2 int, tg3 int);") + tdSql.execute("create table stb(ts timestamp, f int, g int) tags (tg1 int, tg2 int, tg3 int);") + tdSql.query("select today();") + today_ts = tdSql.res[0][0].strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] + tdSql.query("select today() + 1d;") + tomorrow_ts = tdSql.res[0][0].strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] + + tdLog.printNoPrefix("==========step2:insert data") + tdSql.execute(f"insert into a1 using sta tags(1, 1, 1) values('{today_ts}', 101, 1011);") + tdSql.execute(f"insert into a1 using sta tags(1, 1, 1) values('{today_ts}' + 1s, 102, 1012);") + tdSql.execute(f"insert into a1 using sta tags(1, 1, 1) values('{tomorrow_ts}', 103, 1013);") + tdSql.execute(f"insert into a1 using sta tags(1, 1, 1) values('{tomorrow_ts}' + 2s, 104, 1014);") + + tdSql.execute(f"insert into a2 using sta tags(1, 2, 2) values('{today_ts}', 201, 2011);") + tdSql.execute(f"insert into a2 using sta tags(1, 2, 2) values('{today_ts}' + 1s, 202, 2012);") + tdSql.execute(f"insert into a2 using sta tags(1, 2, 2) values('{tomorrow_ts}', 203, 2013);") + tdSql.execute(f"insert into a2 using sta tags(1, 2, 2) values('{tomorrow_ts}' + 3s, 204, 2014);") + + tdSql.execute(f"insert into b1 using stb tags(1, 1, 3) values('{today_ts}', 301, 3011);") + tdSql.execute(f"insert into b1 using stb tags(1, 1, 3) values('{today_ts}' + 1s, 302, 3012);") + tdSql.execute(f"insert into b1 using stb tags(1, 1, 3) values('{tomorrow_ts}', 303, 3013);") + tdSql.execute(f"insert into b1 using stb tags(1, 1, 3) values('{tomorrow_ts}' + 2s, 304, 3014);") + + tdSql.execute(f"insert into b2 using stb tags(1, 2, 4) values('{today_ts}', 401, 4011);") + tdSql.execute(f"insert into b2 using stb tags(1, 2, 4) values('{today_ts}' + 1s, 402, 4012);") + tdSql.execute(f"insert into b2 using stb tags(1, 2, 4) values('{tomorrow_ts}', 403, 4013);") + tdSql.execute(f"insert into b2 using stb tags(1, 2, 4) values('{tomorrow_ts}' + 3s, 404, 4014);") + + def replace_string(self, input_file, output_file, old_str, new_str): + print("当前工作目录:", os.getcwd()) + script_dir = os.path.dirname(os.path.abspath(__file__)) + with open(f"{script_dir}/joinConst/{input_file}", 'r') as f_in, open(f"{script_dir}/joinConst/{output_file}", 'w') as f_out: + for line in f_in: + modified_line = line.replace(old_str, new_str) + f_out.write(modified_line) + + def test_normal_case(self, testCase): + self.replace_string(f'{testCase}.in', f'{testCase}.in.today_', '__today__', 'today()') + # read sql from .sql file and execute + self.sqlFile = etool.curFile(__file__, f"joinConst/{testCase}.in.today_") + self.ansFile = etool.curFile(__file__, f"joinConst/{testCase}.today_.csv") + tdCom.compare_testcase_result(self.sqlFile, self.ansFile, testCase) + + self.replace_string(f'{testCase}.in', f'{testCase}.in.today', '__today__', 'today') + # read sql from .sql file and execute + self.sqlFile = etool.curFile(__file__, f"joinConst/{testCase}.in.today") + self.ansFile = etool.curFile(__file__, f"joinConst/{testCase}.today.csv") + tdCom.compare_testcase_result(self.sqlFile, self.ansFile, testCase) + +# self.replace_string(f'{testCase}.in', f'{testCase}.in.now_', '__today__', 'now()') +# # read sql from .sql file and execute +# self.sqlFile = etool.curFile(__file__, f"joinConst/{testCase}.in.now_") +# self.ansFile = etool.curFile(__file__, f"joinConst/{testCase}.now_.csv") +# tdCom.compare_testcase_result(self.sqlFile, self.ansFile, testCase) +# +# self.replace_string(f'{testCase}.in', f'{testCase}.in.now', '__today__', 'now') +# # read sql from .sql file and execute +# self.sqlFile = etool.curFile(__file__, f"joinConst/{testCase}.in.now") +# self.ansFile = etool.curFile(__file__, f"joinConst/{testCase}.now.csv") +# tdCom.compare_testcase_result(self.sqlFile, self.ansFile, testCase) +# +# self.replace_string(f'{testCase}.in', f'{testCase}.in.today_ts', '__today__', f'{today_ts}') +# # read sql from .sql file and execute +# self.sqlFile = etool.curFile(__file__, f"joinConst/{testCase}.in.today_ts") +# self.ansFile = etool.curFile(__file__, f"joinConst/{testCase}.today_ts.csv") +# tdCom.compare_testcase_result(self.sqlFile, self.ansFile, testCase) +# +# self.replace_string(f'{testCase}.in', f'{testCase}.in.tomorrow_ts', '__today__', f'{tomorrow_ts}') +# # read sql from .sql file and execute +# self.sqlFile = etool.curFile(__file__, f"joinConst/{testCase}.in.tomorrow_ts") +# self.ansFile = etool.curFile(__file__, f"joinConst/{testCase}.tomorrow_ts.csv") +# tdCom.compare_testcase_result(self.sqlFile, self.ansFile, testCase) + + def test_abnormal_case(self): + tdLog.info("test abnormal case.") + tdSql.error("select interp(c1) from test.td32727 range('2020-02-01 00:00:00.000', '2020-02-01 00:00:30.000', -1s) every(2s) fill(prev, 99);") + + def run(self): + tdLog.debug(f"start to excute {__file__}") + + self.insert_data() + self.test_normal_case("inner") + self.test_abnormal_case() + + tdLog.success(f"{__file__} successfully executed") + + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase())