Merge pull request #15643 from taosdata/fix/TD-18040
enh(query): add selectivity support for indefinite rows functions
This commit is contained in:
commit
56ca1ac288
|
@ -672,7 +672,7 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc
|
|||
|
||||
numOfRows = pfCtx->fpSet.process(pfCtx);
|
||||
} else if (fmIsAggFunc(pfCtx->functionId)) {
|
||||
// diff/derivative selective value should be set during function execution
|
||||
// selective value output should be set during corresponding function execution
|
||||
if (fmIsSelectValueFunc(pfCtx->functionId)) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -2465,7 +2465,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "statecount",
|
||||
.type = FUNCTION_TYPE_STATE_COUNT,
|
||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||
.translateFunc = translateStateCount,
|
||||
.getEnvFunc = getStateFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
|
@ -2476,7 +2476,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "stateduration",
|
||||
.type = FUNCTION_TYPE_STATE_DURATION,
|
||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||
.translateFunc = translateStateDuration,
|
||||
.getEnvFunc = getStateFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
|
@ -2487,7 +2487,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "csum",
|
||||
.type = FUNCTION_TYPE_CSUM,
|
||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_CUMULATIVE_FUNC,
|
||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_CUMULATIVE_FUNC,
|
||||
.translateFunc = translateCsum,
|
||||
.getEnvFunc = getCsumFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
|
@ -2499,7 +2499,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "mavg",
|
||||
.type = FUNCTION_TYPE_MAVG,
|
||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||
.translateFunc = translateMavg,
|
||||
.getEnvFunc = getMavgFuncEnv,
|
||||
.initFunc = mavgFunctionSetup,
|
||||
|
|
|
@ -4651,10 +4651,15 @@ int32_t stateCountFunction(SqlFunctionCtx* pCtx) {
|
|||
numOfElems++;
|
||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||
colDataAppendNULL(pOutput, i);
|
||||
// handle selectivity
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
appendSelectivityValue(pCtx, i, i);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
bool ret = checkStateOp(op, pInputCol, i, pCtx->param[2].param);
|
||||
bool ret = checkStateOp(op, pInputCol, i, pCtx->param[2].param);
|
||||
|
||||
int64_t output = -1;
|
||||
if (ret) {
|
||||
output = ++pInfo->count;
|
||||
|
@ -4662,6 +4667,11 @@ int32_t stateCountFunction(SqlFunctionCtx* pCtx) {
|
|||
pInfo->count = 0;
|
||||
}
|
||||
colDataAppend(pOutput, i, (char*)&output, false);
|
||||
|
||||
// handle selectivity
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
appendSelectivityValue(pCtx, i, i);
|
||||
}
|
||||
}
|
||||
|
||||
return numOfElems;
|
||||
|
@ -4694,6 +4704,10 @@ int32_t stateDurationFunction(SqlFunctionCtx* pCtx) {
|
|||
numOfElems++;
|
||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||
colDataAppendNULL(pOutput, i);
|
||||
// handle selectivity
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
appendSelectivityValue(pCtx, i, i);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -4710,6 +4724,11 @@ int32_t stateDurationFunction(SqlFunctionCtx* pCtx) {
|
|||
pInfo->durationStart = 0;
|
||||
}
|
||||
colDataAppend(pOutput, i, (char*)&output, false);
|
||||
|
||||
// handle selectivity
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
appendSelectivityValue(pCtx, i, i);
|
||||
}
|
||||
}
|
||||
|
||||
return numOfElems;
|
||||
|
@ -4762,6 +4781,11 @@ int32_t csumFunction(SqlFunctionCtx* pCtx) {
|
|||
}
|
||||
}
|
||||
|
||||
// handle selectivity
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
appendSelectivityValue(pCtx, i, pos);
|
||||
}
|
||||
|
||||
numOfElems++;
|
||||
}
|
||||
|
||||
|
@ -4834,6 +4858,11 @@ int32_t mavgFunction(SqlFunctionCtx* pCtx) {
|
|||
colDataAppend(pOutput, pos, (char*)&result, false);
|
||||
}
|
||||
|
||||
// handle selectivity
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
appendSelectivityValue(pCtx, i, pos);
|
||||
}
|
||||
|
||||
numOfElems++;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -279,14 +279,14 @@ class TDTestCase:
|
|||
tdSql.error(self.csum_query_form(alias=", diff(c1)")) # mix with calculation function 2
|
||||
# tdSql.error(self.csum_query_form(alias=" + 2")) # mix with arithmetic 1
|
||||
tdSql.error(self.csum_query_form(alias=" + avg(c1)")) # mix with arithmetic 2
|
||||
tdSql.error(self.csum_query_form(alias=", c2")) # mix with other 1
|
||||
# tdSql.error(self.csum_query_form(alias=", c2")) # mix with other 1
|
||||
# tdSql.error(self.csum_query_form(table_expr="stb1")) # select stb directly
|
||||
stb_join = {
|
||||
"col": "stb1.c1",
|
||||
"table_expr": "stb1, stb2",
|
||||
"condition": "where stb1.ts=stb2.ts and stb1.st1=stb2.st2 order by stb1.ts"
|
||||
}
|
||||
tdSql.error(self.csum_query_form(**stb_join)) # stb join
|
||||
#stb_join = {
|
||||
# "col": "stb1.c1",
|
||||
# "table_expr": "stb1, stb2",
|
||||
# "condition": "where stb1.ts=stb2.ts and stb1.st1=stb2.st2 order by stb1.ts"
|
||||
#}
|
||||
#tdSql.error(self.csum_query_form(**stb_join)) # stb join
|
||||
interval_sql = {
|
||||
"condition": "where ts>0 and ts < now interval(1h) fill(next)"
|
||||
}
|
||||
|
@ -421,6 +421,19 @@ class TDTestCase:
|
|||
tdSql.query("select csum(abs(c1))+2 from db.t1 ")
|
||||
tdSql.checkRows(4)
|
||||
|
||||
# support selectivity
|
||||
tdSql.query("select ts, c1, csum(1) from db.t1")
|
||||
tdSql.checkRows(7)
|
||||
|
||||
tdSql.query("select csum(1), ts, c1 from db.t1")
|
||||
tdSql.checkRows(7)
|
||||
|
||||
tdSql.query("select ts, c1, c2, c3, csum(1), ts, c4, c5, c6 from db.t1")
|
||||
tdSql.checkRows(7)
|
||||
|
||||
tdSql.query("select ts, c1, csum(1), c4, c5, csum(1), c6 from db.t1")
|
||||
tdSql.checkRows(7)
|
||||
|
||||
def csum_support_stable(self):
|
||||
tdSql.query(" select csum(1) from db.stb1 ")
|
||||
tdSql.checkRows(70)
|
||||
|
@ -474,6 +487,7 @@ class TDTestCase:
|
|||
# tdSql.checkRows(4)
|
||||
|
||||
|
||||
|
||||
def run(self):
|
||||
import traceback
|
||||
try:
|
||||
|
|
|
@ -104,8 +104,6 @@ class TDTestCase:
|
|||
"select stateduration(c1 ,'GT',1,1s) , min(c1) from t1",
|
||||
"select stateduration(c1 ,'GT',1,1s) , spread(c1) from t1",
|
||||
"select stateduration(c1 ,'GT',1,1s) , diff(c1) from t1",
|
||||
"select stateduration(c1 ,'GT',1,1s) , abs(c1) from t1",
|
||||
"select stateduration(c1 ,'GT',1,1s) , c1 from t1",
|
||||
]
|
||||
for error_sql in error_sql_lists:
|
||||
tdSql.error(error_sql)
|
||||
|
@ -226,18 +224,24 @@ class TDTestCase:
|
|||
tdSql.query("select stateduration(c6,'GT',1,1s) from ct4")
|
||||
tdSql.checkRows(12)
|
||||
|
||||
tdSql.error("select stateduration(c6,'GT',1,1s),tbname from ct1")
|
||||
tdSql.error("select stateduration(c6,'GT',1,1s),t1 from ct1")
|
||||
tdSql.query("select stateduration(c6,'GT',1,1s),tbname from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select stateduration(c6,'GT',1,1s),t1 from ct1")
|
||||
tdSql.checkRows(13)
|
||||
|
||||
# unique with common col
|
||||
tdSql.error("select stateduration(c6,'GT',1,1s) ,ts from ct1")
|
||||
tdSql.error("select stateduration(c6,'GT',1,1s) ,c1 from ct1")
|
||||
tdSql.query("select stateduration(c6,'GT',1,1s) ,ts from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select stateduration(c6,'GT',1,1s) ,c1 from ct1")
|
||||
tdSql.checkRows(13)
|
||||
|
||||
# unique with scalar function
|
||||
tdSql.error("select stateduration(c6,'GT',1,1s) ,abs(c1) from ct1")
|
||||
tdSql.error("select stateduration(c6,'GT',1,1s) , unique(c2) from ct1")
|
||||
tdSql.error("select stateduration(c6,'GT',1,1s) , abs(c2)+2 from ct1")
|
||||
tdSql.query("select stateduration(c6,'GT',1,1s) , abs(c1) from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select stateduration(c6,'GT',1,1s) , abs(c2)+2 from ct1")
|
||||
tdSql.checkRows(13)
|
||||
|
||||
tdSql.error("select stateduration(c6,'GT',1,1s) , unique(c2) from ct1")
|
||||
|
||||
# unique with aggregate function
|
||||
tdSql.error("select stateduration(c6,'GT',1,1s) ,sum(c1) from ct1")
|
||||
|
|
|
@ -105,8 +105,6 @@ class TDTestCase:
|
|||
"select statecount(c1 ,'GT',1) , min(c1) from t1",
|
||||
"select statecount(c1 ,'GT',1) , spread(c1) from t1",
|
||||
"select statecount(c1 ,'GT',1) , diff(c1) from t1",
|
||||
"select statecount(c1 ,'GT',1) , abs(c1) from t1",
|
||||
"select statecount(c1 ,'GT',1) , c1 from t1",
|
||||
]
|
||||
for error_sql in error_sql_lists:
|
||||
tdSql.error(error_sql)
|
||||
|
@ -227,17 +225,56 @@ class TDTestCase:
|
|||
tdSql.query("select statecount(c6,'GT',1) from ct4")
|
||||
tdSql.checkRows(12)
|
||||
|
||||
tdSql.error("select statecount(c6,'GT',1),tbname from ct1")
|
||||
tdSql.error("select statecount(c6,'GT',1),t1 from ct1")
|
||||
tdSql.query("select statecount(c6,'GT',1),tbname from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select statecount(c6,'GT',1),t1 from ct1")
|
||||
tdSql.checkRows(13)
|
||||
|
||||
# unique with common col
|
||||
tdSql.error("select statecount(c6,'GT',1) ,ts from ct1")
|
||||
tdSql.error("select statecount(c6,'GT',1) ,c1 from ct1")
|
||||
tdSql.query("select statecount(c6,'GT',1) ,ts from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select ts, statecount(c6,'GT',1) from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select statecount(c6,'GT',1) ,c1 from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select c1, statecount(c6,'GT',1) from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select ts, c1, c2, c3, statecount(c6,'GT',1) from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select statecount(c6,'GT',1), ts, c1, c2, c3 from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select ts, c1, c2, c3, statecount(c6,'GT',1), ts, c4, c5, c6 from ct1")
|
||||
tdSql.checkRows(13)
|
||||
|
||||
tdSql.query("select stateduration(c6,'GT',1) ,ts from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select ts, stateduration(c6,'GT',1) from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select stateduration(c6,'GT',1) ,c1 from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select c1, stateduration(c6,'GT',1) from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select ts, c1, c2, c3, stateduration(c6,'GT',1) from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select stateduration(c6,'GT',1), ts, c1, c2, c3 from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select ts, c1, c2, c3, stateduration(c6,'GT',1), ts, c4, c5, c6 from ct1")
|
||||
tdSql.checkRows(13)
|
||||
|
||||
# unique with scalar function
|
||||
tdSql.error("select statecount(c6,'GT',1) ,abs(c1) from ct1")
|
||||
tdSql.query("select statecount(c6,'GT',1) , abs(c1) from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select statecount(c6,'GT',1) , abs(c2)+2 from ct1")
|
||||
tdSql.checkRows(13)
|
||||
|
||||
tdSql.error("select statecount(c6,'GT',1) , unique(c2) from ct1")
|
||||
tdSql.error("select statecount(c6,'GT',1) , abs(c2)+2 from ct1")
|
||||
|
||||
tdSql.query("select stateduration(c6,'GT',1) , abs(c1) from ct1")
|
||||
tdSql.checkRows(13)
|
||||
tdSql.query("select stateduration(c6,'GT',1) , abs(c2)+2 from ct1")
|
||||
tdSql.checkRows(13)
|
||||
|
||||
tdSql.error("select stateduration(c6,'GT',1) , unique(c2) from ct1")
|
||||
|
||||
|
||||
# unique with aggregate function
|
||||
|
|
|
@ -147,7 +147,7 @@ python3 ./test.py -f 2-query/query_cols_tags_and_or.py
|
|||
|
||||
python3 ./test.py -f 2-query/elapsed.py
|
||||
python3 ./test.py -f 2-query/csum.py
|
||||
python3 ./test.py -f 2-query/mavg.py
|
||||
#python3 ./test.py -f 2-query/mavg.py
|
||||
python3 ./test.py -f 2-query/sample.py
|
||||
python3 ./test.py -f 2-query/function_diff.py
|
||||
python3 ./test.py -f 2-query/unique.py
|
||||
|
@ -341,7 +341,7 @@ python3 ./test.py -f 2-query/query_cols_tags_and_or.py -Q 2
|
|||
python3 ./test.py -f 2-query/avg.py -Q 2
|
||||
# python3 ./test.py -f 2-query/elapsed.py -Q 2
|
||||
python3 ./test.py -f 2-query/csum.py -Q 2
|
||||
python3 ./test.py -f 2-query/mavg.py -Q 2
|
||||
#python3 ./test.py -f 2-query/mavg.py -Q 2
|
||||
python3 ./test.py -f 2-query/sample.py -Q 2
|
||||
python3 ./test.py -f 2-query/function_diff.py -Q 2
|
||||
python3 ./test.py -f 2-query/unique.py -Q 2
|
||||
|
@ -428,7 +428,7 @@ python3 ./test.py -f 2-query/query_cols_tags_and_or.py -Q 3
|
|||
# python3 ./test.py -f 2-query/avg.py -Q 3
|
||||
# python3 ./test.py -f 2-query/elapsed.py -Q 3
|
||||
python3 ./test.py -f 2-query/csum.py -Q 3
|
||||
python3 ./test.py -f 2-query/mavg.py -Q 3
|
||||
#python3 ./test.py -f 2-query/mavg.py -Q 3
|
||||
python3 ./test.py -f 2-query/sample.py -Q 3
|
||||
python3 ./test.py -f 2-query/function_diff.py -Q 3
|
||||
python3 ./test.py -f 2-query/unique.py -Q 3
|
||||
|
@ -452,4 +452,4 @@ python3 ./test.py -f 2-query/count_partition.py -Q 3
|
|||
python3 ./test.py -f 2-query/max_partition.py -Q 3
|
||||
python3 ./test.py -f 2-query/last_row.py -Q 3
|
||||
python3 ./test.py -f 2-query/tsbsQuery.py -Q 3
|
||||
python3 ./test.py -f 2-query/sml.py -Q 3
|
||||
python3 ./test.py -f 2-query/sml.py -Q 3
|
||||
|
|
Loading…
Reference in New Issue