2022-04-24 10:05:28 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can use, redistribute, and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3
|
|
|
|
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "planTestUtil.h"
|
|
|
|
|
#include "planner.h"
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
2022-04-26 03:50:35 +00:00
|
|
|
class PlanOptimizeTest : public PlannerTestBase {};
|
2022-04-24 10:05:28 +00:00
|
|
|
|
2022-06-27 13:30:20 +00:00
|
|
|
TEST_F(PlanOptimizeTest, scanPath) {
|
2022-05-06 09:52:59 +00:00
|
|
|
useDb("root", "test");
|
|
|
|
|
|
|
|
|
|
run("SELECT COUNT(*) FROM t1");
|
|
|
|
|
|
|
|
|
|
run("SELECT COUNT(c1) FROM t1");
|
|
|
|
|
|
|
|
|
|
run("SELECT COUNT(CAST(c1 AS BIGINT)) FROM t1");
|
2022-05-12 09:17:02 +00:00
|
|
|
|
|
|
|
|
run("SELECT PERCENTILE(c1, 40), COUNT(*) FROM t1");
|
2022-05-06 09:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-27 13:30:20 +00:00
|
|
|
TEST_F(PlanOptimizeTest, pushDownCondition) {
|
2022-05-23 11:50:08 +00:00
|
|
|
useDb("root", "test");
|
|
|
|
|
|
|
|
|
|
run("SELECT ts, c1 FROM st1 WHERE tag1 > 4");
|
2022-06-04 11:54:55 +00:00
|
|
|
|
|
|
|
|
run("SELECT ts, c1 FROM st1 WHERE tag1 > 4 or tag1 < 2");
|
|
|
|
|
|
|
|
|
|
run("SELECT ts, c1 FROM st1 WHERE tag1 > 4 AND tag2 = 'hello'");
|
2022-06-18 12:15:47 +00:00
|
|
|
|
|
|
|
|
run("SELECT ts, c1 FROM st1 WHERE tag1 > 4 AND tag2 = 'hello' AND c1 > 10");
|
2022-06-28 05:45:20 +00:00
|
|
|
|
|
|
|
|
run("SELECT ts, c1 FROM (SELECT * FROM st1) WHERE tag1 > 4");
|
2022-05-23 11:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-27 13:30:20 +00:00
|
|
|
TEST_F(PlanOptimizeTest, sortPrimaryKey) {
|
2022-04-24 10:05:28 +00:00
|
|
|
useDb("root", "test");
|
|
|
|
|
|
2022-05-06 09:52:59 +00:00
|
|
|
run("SELECT c1 FROM t1 ORDER BY ts");
|
2022-06-20 07:42:31 +00:00
|
|
|
|
2022-05-06 09:52:59 +00:00
|
|
|
run("SELECT c1 FROM t1 ORDER BY ts DESC");
|
2022-05-09 12:20:05 +00:00
|
|
|
|
|
|
|
|
run("SELECT COUNT(*) FROM t1 INTERVAL(10S) ORDER BY _WSTARTTS DESC");
|
2022-04-24 10:05:28 +00:00
|
|
|
}
|
2022-06-20 07:42:31 +00:00
|
|
|
|
|
|
|
|
TEST_F(PlanOptimizeTest, PartitionTags) {
|
|
|
|
|
useDb("root", "test");
|
|
|
|
|
|
2022-06-24 13:07:12 +00:00
|
|
|
run("SELECT c1, tag1 FROM st1 PARTITION BY tag1");
|
2022-06-20 07:42:31 +00:00
|
|
|
|
2022-06-24 13:07:12 +00:00
|
|
|
run("SELECT SUM(c1), tag1 FROM st1 PARTITION BY tag1");
|
|
|
|
|
|
|
|
|
|
run("SELECT SUM(c1), tag1 + 10 FROM st1 PARTITION BY tag1 + 10");
|
|
|
|
|
|
|
|
|
|
run("SELECT SUM(c1), tag1 FROM st1 GROUP BY tag1");
|
|
|
|
|
|
|
|
|
|
run("SELECT SUM(c1), tag1 + 10 FROM st1 GROUP BY tag1 + 10");
|
2022-07-01 13:06:08 +00:00
|
|
|
|
|
|
|
|
run("SELECT SUM(c1), tbname FROM st1 GROUP BY tbname");
|
2022-06-20 07:42:31 +00:00
|
|
|
}
|
2022-06-20 12:38:08 +00:00
|
|
|
|
2022-06-18 07:20:30 +00:00
|
|
|
TEST_F(PlanOptimizeTest, eliminateProjection) {
|
|
|
|
|
useDb("root", "test");
|
|
|
|
|
|
|
|
|
|
run("SELECT c1, sum(c3) FROM t1 GROUP BY c1");
|
2022-06-18 08:24:29 +00:00
|
|
|
run("SELECT c1 FROM t1");
|
|
|
|
|
run("SELECT * FROM st1");
|
2022-06-18 09:58:15 +00:00
|
|
|
run("SELECT c1 FROM st1s3");
|
2022-06-20 12:38:08 +00:00
|
|
|
// run("select 1-abs(c1) from (select unique(c1) c1 from st1s3) order by 1 nulls first");
|
2022-06-18 07:20:30 +00:00
|
|
|
}
|
2022-07-05 11:08:08 +00:00
|
|
|
|
|
|
|
|
TEST_F(PlanOptimizeTest, pushDownProjectCond) {
|
|
|
|
|
useDb("root", "test");
|
|
|
|
|
run("select 1-abs(c1) from (select unique(c1) c1 from st1s3) where 1-c1>5 order by 1 nulls first");
|
|
|
|
|
}
|