diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 2957752b27326fe349f2e2c29557e203db991a8a..3d96231715d37b21f6768f028a2524f05cb82049 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1808,11 +1808,17 @@ static bool functionNeedToExecute(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx } if (functionId == TSDB_FUNC_FIRST_DST || functionId == TSDB_FUNC_FIRST) { + // if param[2] is set value, input data come from client, order is no relation with pQueryAttr->order , so always return true + if(pCtx->param[2].nType == TSDB_DATA_TYPE_INT) + return true; return QUERY_IS_ASC_QUERY(pQueryAttr); } // denote the order type if ((functionId == TSDB_FUNC_LAST_DST || functionId == TSDB_FUNC_LAST)) { + // if param[2] is set value, input data come from client, order is no relation with pQueryAttr->order , so always return true + if(pCtx->param[2].nType == TSDB_DATA_TYPE_INT) + return true; return pCtx->param[0].i64 == pQueryAttr->order.order; } diff --git a/tests/pytest/query/queryBase.py b/tests/pytest/query/queryBase.py index af174eea11202923abdabd98a3deea33d43eb2f8..4544fab3adcb6e760dcbc05ab56cd22edd35b3e2 100644 --- a/tests/pytest/query/queryBase.py +++ b/tests/pytest/query/queryBase.py @@ -154,7 +154,22 @@ class TDTestCase: sql = "select last(*) from ( select sum(i1) from st where ts>='2017-07-14 11:40:00' and ts<'2017-07-14 12:40:00' interval(10m) order by ts desc );" # desc tdSql.waitedQuery(sql, 1, WAITS) tdSql.checkData(0, 1, 192419100) - + + # add parent query order by + # first + sql = "select first(*) from (select first(i1) from st interval(10m) order by ts asc) order by ts desc;" + tdSql.waitedQuery(sql, 1, WAITS) + tdSql.checkData(0, 1, 0) + sql = "select first(*) from (select first(i1) from st interval(10m) order by ts desc) order by ts asc;" + tdSql.waitedQuery(sql, 1, WAITS) + tdSql.checkData(0, 1, 0) + # last + sql = "select last(*) from (select first(i1) from st interval(10m) order by ts asc) order by ts desc;" + tdSql.waitedQuery(sql, 1, WAITS) + tdSql.checkData(0, 1, 229400) + sql = "select last(*) from (select first(i1) from st interval(10m) order by ts desc) order by ts asc;" + tdSql.waitedQuery(sql, 1, WAITS) + tdSql.checkData(0, 1, 229400) # # add case with filename