提交 6185c3d2 编写于 作者: D dapan1121

support invertal+group by tag in subquery

上级 6c4dd103
......@@ -143,6 +143,7 @@ bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo);
bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo);
bool tsIsArithmeticQueryOnAggResult(SQueryInfo* pQueryInfo);
bool tscGroupbyColumn(SQueryInfo* pQueryInfo);
bool tscGroupbyTag(SQueryInfo* pQueryInfo);
int32_t tscGetTopBotQueryExprIndex(SQueryInfo* pQueryInfo);
bool tscIsTopBotQuery(SQueryInfo* pQueryInfo);
bool hasTagValOutput(SQueryInfo* pQueryInfo);
......
......@@ -8895,6 +8895,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
pQueryInfo->simpleAgg = isSimpleAggregateRv(pQueryInfo);
pQueryInfo->onlyTagQuery = onlyTagPrjFunction(pQueryInfo);
pQueryInfo->groupbyColumn = tscGroupbyColumn(pQueryInfo);
pQueryInfo->groupbyTag = tscGroupbyTag(pQueryInfo);
pQueryInfo->arithmeticOnAgg = tsIsArithmeticQueryOnAggResult(pQueryInfo);
pQueryInfo->orderProjectQuery = tscOrderedProjectionQueryOnSTable(pQueryInfo, 0);
......
......@@ -3736,6 +3736,25 @@ static UNUSED_FUNC bool tscHasRemainDataInSubqueryResultSet(SSqlObj *pSql) {
return hasData;
}
void tscSetQuerySort(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAttr) {
if (pQueryInfo->interval.interval <= 0) {
return;
}
if (pQueryInfo->pUpstream != NULL && taosArrayGetSize(pQueryInfo->pUpstream) > 0) {
size_t size = taosArrayGetSize(pQueryInfo->pUpstream);
for(int32_t i = 0; i < size; ++i) {
SQueryInfo* pq = taosArrayGetP(pQueryInfo->pUpstream, i);
if (pq->groupbyTag && pq->interval.interval > 0) {
pQueryAttr->needSort = true;
return;
}
}
}
}
void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGroupInfo, SOperatorInfo* pSourceOperator,
char* sql, void* merger, int32_t stage, uint64_t qId) {
assert(pQueryInfo != NULL);
......@@ -3838,6 +3857,7 @@ void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGr
SArray* pa = NULL;
if (stage == MASTER_SCAN) {
pQueryAttr->createFilterOperator = false; // no need for parent query
tscSetQuerySort(pQueryInfo, pQueryAttr);
pa = createExecOperatorPlan(pQueryAttr);
} else {
pa = createGlobalMergePlan(pQueryAttr);
......
......@@ -385,6 +385,19 @@ bool tscGroupbyColumn(SQueryInfo* pQueryInfo) {
return false;
}
bool tscGroupbyTag(SQueryInfo* pQueryInfo) {
SGroupbyExpr* pGroupbyExpr = &pQueryInfo->groupbyExpr;
for (int32_t k = 0; k < pGroupbyExpr->numOfGroupCols; ++k) {
SColIndex* pIndex = taosArrayGet(pGroupbyExpr->columnInfo, k);
if (TSDB_COL_IS_TAG(pIndex->flag)) { // group by tag
return true;
}
}
return false;
}
int32_t tscGetTopBotQueryExprIndex(SQueryInfo* pQueryInfo) {
size_t numOfExprs = tscNumOfExprs(pQueryInfo);
......@@ -1217,6 +1230,7 @@ static void createInputDataFilterInfo(SQueryInfo* px, int32_t numOfCol1, int32_t
tfree(tableCols);
}
void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQueryInfo* px, SSqlObj* pSql) {
SSqlRes* pOutput = &pSql->res;
......
......@@ -227,6 +227,7 @@ typedef struct SQueryAttr {
bool stateWindow; // window State on sub/normal table
bool createFilterOperator; // if filter operator is needed
bool multigroupResult; // multigroup result can exist in one SSDataBlock
bool needSort; // need sort rowRes
int32_t interBufSize; // intermediate buffer sizse
int32_t havingNum; // having expr number
......
......@@ -142,7 +142,8 @@ typedef struct SQueryInfo {
struct SQueryInfo *pDownstream;
int32_t havingFieldNum;
bool stableQuery;
bool groupbyColumn;
bool groupbyColumn;
bool groupbyTag;
bool simpleAgg;
bool arithmeticOnAgg;
bool projectionQuery;
......
......@@ -5917,6 +5917,18 @@ static SSDataBlock* doFilter(void* param, bool* newgroup) {
return NULL;
}
static int32_t resRowCompare(const void *r1, const void *r2) {
SResultRow *res1 = *(SResultRow **)r1;
SResultRow *res2 = *(SResultRow **)r2;
if (res1->win.skey == res2->win.skey) {
return 0;
} else {
return res1->win.skey > res2->win.skey ? 1 : -1;
}
}
static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
SOperatorInfo* pOperator = (SOperatorInfo*) param;
if (pOperator->status == OP_EXEC_DONE) {
......@@ -5962,6 +5974,10 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
pQueryAttr->window = win;
pOperator->status = OP_RES_TO_RETURN;
if (pIntervalInfo->resultRowInfo.size > 0 && pQueryAttr->needSort) {
qsort(pIntervalInfo->resultRowInfo.pResult, pIntervalInfo->resultRowInfo.size, POINTER_BYTES, resRowCompare);
}
closeAllResultRows(&pIntervalInfo->resultRowInfo);
setQueryStatus(pRuntimeEnv, QUERY_COMPLETED);
finalizeQueryResult(pOperator, pIntervalInfo->pCtx, &pIntervalInfo->resultRowInfo, pIntervalInfo->rowCellInfoOffset);
......
......@@ -508,4 +508,381 @@ if $data11 != 2.000000000 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
sql create database test2;
sql use test2;
sql create table meters (ts TIMESTAMP,a INT,b INT) TAGS (area INT);
sql CREATE TABLE t0 USING meters TAGS (0);
sql CREATE TABLE t1 USING meters TAGS (1);
sql CREATE TABLE t2 USING meters TAGS (1);
sql CREATE TABLE t3 USING meters TAGS (0);
sql insert into t0 values ('2021-09-30 15:00:00.00',0,0);
sql insert into t0 values ('2021-09-30 15:00:01.00',1,1);
sql insert into t0 values ('2021-09-30 15:00:03.00',3,3);
sql insert into t0 values ('2021-09-30 15:00:05.00',5,5);
sql insert into t0 values ('2021-09-30 15:00:07.00',7,7);
sql insert into t0 values ('2021-09-30 15:00:09.00',9,9);
sql insert into t1 values ('2021-09-30 15:00:00.00',0,0);
sql insert into t1 values ('2021-09-30 15:00:02.00',2,2);
sql insert into t1 values ('2021-09-30 15:00:04.00',4,4);
sql insert into t1 values ('2021-09-30 15:00:06.00',6,6);
sql insert into t1 values ('2021-09-30 15:00:08.00',8,8);
sql insert into t1 values ('2021-09-30 15:00:10.00',10,10);
sql insert into t2 values ('2021-09-30 15:00:00.00',0,0);
sql insert into t2 values ('2021-09-30 15:00:01.00',11,11);
sql insert into t2 values ('2021-09-30 15:00:02.00',22,22);
sql insert into t2 values ('2021-09-30 15:00:03.00',33,33);
sql insert into t2 values ('2021-09-30 15:00:04.00',44,44);
sql insert into t2 values ('2021-09-30 15:00:05.00',55,55);
sql insert into t3 values ('2021-09-30 15:00:00.00',0,0);
sql insert into t3 values ('2021-09-30 15:00:01.00',11,11);
sql insert into t3 values ('2021-09-30 15:00:02.00',22,22);
sql insert into t3 values ('2021-09-30 15:00:03.00',33,33);
sql insert into t3 values ('2021-09-30 15:00:04.00',44,44);
sql insert into t3 values ('2021-09-30 15:00:05.00',55,55);
sql select count(*) from meters interval(1s) group by tbname;
if $rows != 24 then
return -1
endi
sql select count(*) from (select count(*) from meters interval(1s) group by tbname) interval(1s);
if $rows != 11 then
return -1
endi
if $data00 != @21-09-30 15:00:00.000@ then
return -1
endi
if $data01 != 4 then
return -1
endi
if $data10 != @21-09-30 15:00:01.000@ then
return -1
endi
if $data11 != 3 then
return -1
endi
if $data20 != @21-09-30 15:00:02.000@ then
return -1
endi
if $data21 != 3 then
return -1
endi
if $data30 != @21-09-30 15:00:03.000@ then
return -1
endi
if $data31 != 3 then
return -1
endi
if $data40 != @21-09-30 15:00:04.000@ then
return -1
endi
if $data41 != 3 then
return -1
endi
if $data50 != @21-09-30 15:00:05.000@ then
return -1
endi
if $data51 != 3 then
return -1
endi
if $data60 != @21-09-30 15:00:06.000@ then
return -1
endi
if $data61 != 1 then
return -1
endi
if $data70 != @21-09-30 15:00:07.000@ then
return -1
endi
if $data71 != 1 then
return -1
endi
if $data80 != @21-09-30 15:00:08.000@ then
return -1
endi
if $data81 != 1 then
return -1
endi
if $data90 != @21-09-30 15:00:09.000@ then
return -1
endi
if $data91 != 1 then
return -1
endi
sql select count(*) from (select count(*) from meters interval(1s) group by area) interval(1s);
if $rows != 11 then
return -1
endi
if $data00 != @21-09-30 15:00:00.000@ then
return -1
endi
if $data01 != 2 then
return -1
endi
if $data10 != @21-09-30 15:00:01.000@ then
return -1
endi
if $data11 != 2 then
return -1
endi
if $data20 != @21-09-30 15:00:02.000@ then
return -1
endi
if $data21 != 2 then
return -1
endi
if $data30 != @21-09-30 15:00:03.000@ then
return -1
endi
if $data31 != 2 then
return -1
endi
if $data40 != @21-09-30 15:00:04.000@ then
return -1
endi
if $data41 != 2 then
return -1
endi
if $data50 != @21-09-30 15:00:05.000@ then
return -1
endi
if $data51 != 2 then
return -1
endi
if $data60 != @21-09-30 15:00:06.000@ then
return -1
endi
if $data61 != 1 then
return -1
endi
if $data70 != @21-09-30 15:00:07.000@ then
return -1
endi
if $data71 != 1 then
return -1
endi
if $data80 != @21-09-30 15:00:08.000@ then
return -1
endi
if $data81 != 1 then
return -1
endi
if $data90 != @21-09-30 15:00:09.000@ then
return -1
endi
if $data91 != 1 then
return -1
endi
sql select sum(sa) from (select sum(a) as sa from meters interval(1s) group by tbname) interval(1s);
if $rows != 11 then
return -1
endi
if $data00 != @21-09-30 15:00:00.000@ then
return -1
endi
if $data01 != 0 then
return -1
endi
if $data10 != @21-09-30 15:00:01.000@ then
return -1
endi
if $data11 != 23 then
return -1
endi
if $data20 != @21-09-30 15:00:02.000@ then
return -1
endi
if $data21 != 46 then
return -1
endi
if $data30 != @21-09-30 15:00:03.000@ then
return -1
endi
if $data31 != 69 then
return -1
endi
if $data40 != @21-09-30 15:00:04.000@ then
return -1
endi
if $data41 != 92 then
return -1
endi
if $data50 != @21-09-30 15:00:05.000@ then
return -1
endi
if $data51 != 115 then
return -1
endi
if $data60 != @21-09-30 15:00:06.000@ then
return -1
endi
if $data61 != 6 then
return -1
endi
if $data70 != @21-09-30 15:00:07.000@ then
return -1
endi
if $data71 != 7 then
return -1
endi
if $data80 != @21-09-30 15:00:08.000@ then
return -1
endi
if $data81 != 8 then
return -1
endi
if $data90 != @21-09-30 15:00:09.000@ then
return -1
endi
if $data91 != 9 then
return -1
endi
sql select sum(sa) from (select sum(a) as sa from meters interval(1s) group by area) interval(1s);
if $rows != 11 then
return -1
endi
if $data00 != @21-09-30 15:00:00.000@ then
return -1
endi
if $data01 != 0 then
return -1
endi
if $data10 != @21-09-30 15:00:01.000@ then
return -1
endi
if $data11 != 23 then
return -1
endi
if $data20 != @21-09-30 15:00:02.000@ then
return -1
endi
if $data21 != 46 then
return -1
endi
if $data30 != @21-09-30 15:00:03.000@ then
return -1
endi
if $data31 != 69 then
return -1
endi
if $data40 != @21-09-30 15:00:04.000@ then
return -1
endi
if $data41 != 92 then
return -1
endi
if $data50 != @21-09-30 15:00:05.000@ then
return -1
endi
if $data51 != 115 then
return -1
endi
if $data60 != @21-09-30 15:00:06.000@ then
return -1
endi
if $data61 != 6 then
return -1
endi
if $data70 != @21-09-30 15:00:07.000@ then
return -1
endi
if $data71 != 7 then
return -1
endi
if $data80 != @21-09-30 15:00:08.000@ then
return -1
endi
if $data81 != 8 then
return -1
endi
if $data90 != @21-09-30 15:00:09.000@ then
return -1
endi
if $data91 != 9 then
return -1
endi
sql select count(*) from (select count(*) from meters interval(1s)) interval(1s);
if $rows != 11 then
return -1
endi
if $data00 != @21-09-30 15:00:00.000@ then
return -1
endi
if $data01 != 1 then
return -1
endi
if $data10 != @21-09-30 15:00:01.000@ then
return -1
endi
if $data11 != 1 then
return -1
endi
if $data20 != @21-09-30 15:00:02.000@ then
return -1
endi
if $data21 != 1 then
return -1
endi
if $data30 != @21-09-30 15:00:03.000@ then
return -1
endi
if $data31 != 1 then
return -1
endi
if $data40 != @21-09-30 15:00:04.000@ then
return -1
endi
if $data41 != 1 then
return -1
endi
if $data50 != @21-09-30 15:00:05.000@ then
return -1
endi
if $data51 != 1 then
return -1
endi
if $data60 != @21-09-30 15:00:06.000@ then
return -1
endi
if $data61 != 1 then
return -1
endi
if $data70 != @21-09-30 15:00:07.000@ then
return -1
endi
if $data71 != 1 then
return -1
endi
if $data80 != @21-09-30 15:00:08.000@ then
return -1
endi
if $data81 != 1 then
return -1
endi
if $data90 != @21-09-30 15:00:09.000@ then
return -1
endi
if $data91 != 1 then
return -1
endi
sql select count(*) from (select count(*) from meters interval(1s) group by tbname);
if $rows != 1 then
return -1
endi
if $data00 != 24 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册