提交 873ff96b 编写于 作者: X Xiaoyu Wang

fix: a problem of last_row function plan

上级 590f7c4c
...@@ -159,8 +159,8 @@ void generatePerformanceSchema(MockCatalogService* mcs) { ...@@ -159,8 +159,8 @@ void generatePerformanceSchema(MockCatalogService* mcs) {
* c4 | column | DOUBLE | 8 | * c4 | column | DOUBLE | 8 |
* c5 | column | DOUBLE | 8 | * c5 | column | DOUBLE | 8 |
*/ */
void generateTestTables(MockCatalogService* mcs) { void generateTestTables(MockCatalogService* mcs, const std::string& db) {
ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 6) ITableBuilder& builder = mcs->createTableBuilder(db, "t1", TSDB_NORMAL_TABLE, 6)
.setPrecision(TSDB_TIME_PRECISION_MILLI) .setPrecision(TSDB_TIME_PRECISION_MILLI)
.setVgid(1) .setVgid(1)
.addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP) .addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
...@@ -193,9 +193,9 @@ void generateTestTables(MockCatalogService* mcs) { ...@@ -193,9 +193,9 @@ void generateTestTables(MockCatalogService* mcs) {
* jtag | tag | json | -- | * jtag | tag | json | -- |
* Child Table: st2s1, st2s2 * Child Table: st2s1, st2s2
*/ */
void generateTestStables(MockCatalogService* mcs) { void generateTestStables(MockCatalogService* mcs, const std::string& db) {
{ {
ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 3) ITableBuilder& builder = mcs->createTableBuilder(db, "st1", TSDB_SUPER_TABLE, 3, 3)
.setPrecision(TSDB_TIME_PRECISION_MILLI) .setPrecision(TSDB_TIME_PRECISION_MILLI)
.addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP) .addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
.addColumn("c1", TSDB_DATA_TYPE_INT) .addColumn("c1", TSDB_DATA_TYPE_INT)
...@@ -204,20 +204,20 @@ void generateTestStables(MockCatalogService* mcs) { ...@@ -204,20 +204,20 @@ void generateTestStables(MockCatalogService* mcs) {
.addTag("tag2", TSDB_DATA_TYPE_BINARY, 20) .addTag("tag2", TSDB_DATA_TYPE_BINARY, 20)
.addTag("tag3", TSDB_DATA_TYPE_TIMESTAMP); .addTag("tag3", TSDB_DATA_TYPE_TIMESTAMP);
builder.done(); builder.done();
mcs->createSubTable("test", "st1", "st1s1", 1); mcs->createSubTable(db, "st1", "st1s1", 1);
mcs->createSubTable("test", "st1", "st1s2", 2); mcs->createSubTable(db, "st1", "st1s2", 2);
mcs->createSubTable("test", "st1", "st1s3", 1); mcs->createSubTable(db, "st1", "st1s3", 1);
} }
{ {
ITableBuilder& builder = mcs->createTableBuilder("test", "st2", TSDB_SUPER_TABLE, 3, 1) ITableBuilder& builder = mcs->createTableBuilder(db, "st2", TSDB_SUPER_TABLE, 3, 1)
.setPrecision(TSDB_TIME_PRECISION_MILLI) .setPrecision(TSDB_TIME_PRECISION_MILLI)
.addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP) .addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
.addColumn("c1", TSDB_DATA_TYPE_INT) .addColumn("c1", TSDB_DATA_TYPE_INT)
.addColumn("c2", TSDB_DATA_TYPE_BINARY, 20) .addColumn("c2", TSDB_DATA_TYPE_BINARY, 20)
.addTag("jtag", TSDB_DATA_TYPE_JSON); .addTag("jtag", TSDB_DATA_TYPE_JSON);
builder.done(); builder.done();
mcs->createSubTable("test", "st2", "st2s1", 1); mcs->createSubTable(db, "st2", "st2s1", 1);
mcs->createSubTable("test", "st2", "st2s2", 2); mcs->createSubTable(db, "st2", "st2s2", 2);
} }
} }
...@@ -237,6 +237,11 @@ void generateDatabases(MockCatalogService* mcs) { ...@@ -237,6 +237,11 @@ void generateDatabases(MockCatalogService* mcs) {
mcs->createDatabase(TSDB_INFORMATION_SCHEMA_DB); mcs->createDatabase(TSDB_INFORMATION_SCHEMA_DB);
mcs->createDatabase(TSDB_PERFORMANCE_SCHEMA_DB); mcs->createDatabase(TSDB_PERFORMANCE_SCHEMA_DB);
mcs->createDatabase("test"); mcs->createDatabase("test");
generateTestTables(g_mockCatalogService.get(), "test");
generateTestStables(g_mockCatalogService.get(), "test");
mcs->createDatabase("cache_db", false, 1);
generateTestTables(g_mockCatalogService.get(), "cache_db");
generateTestStables(g_mockCatalogService.get(), "cache_db");
mcs->createDatabase("rollup_db", true); mcs->createDatabase("rollup_db", true);
} }
...@@ -369,11 +374,8 @@ void generateMetaData() { ...@@ -369,11 +374,8 @@ void generateMetaData() {
generateDatabases(g_mockCatalogService.get()); generateDatabases(g_mockCatalogService.get());
generateInformationSchema(g_mockCatalogService.get()); generateInformationSchema(g_mockCatalogService.get());
generatePerformanceSchema(g_mockCatalogService.get()); generatePerformanceSchema(g_mockCatalogService.get());
generateTestTables(g_mockCatalogService.get());
generateTestStables(g_mockCatalogService.get());
generateFunctions(g_mockCatalogService.get()); generateFunctions(g_mockCatalogService.get());
generateDnodes(g_mockCatalogService.get()); generateDnodes(g_mockCatalogService.get());
g_mockCatalogService->showTables();
} }
void destroyMetaDataEnv() { g_mockCatalogService.reset(); } void destroyMetaDataEnv() { g_mockCatalogService.reset(); }
...@@ -334,11 +334,12 @@ class MockCatalogServiceImpl { ...@@ -334,11 +334,12 @@ class MockCatalogServiceImpl {
dnode_.insert(std::make_pair(dnodeId, epSet)); dnode_.insert(std::make_pair(dnodeId, epSet));
} }
void createDatabase(const std::string& db, bool rollup) { void createDatabase(const std::string& db, bool rollup, int8_t cacheLast) {
SDbCfgInfo cfg = {0}; SDbCfgInfo cfg = {0};
if (rollup) { if (rollup) {
cfg.pRetensions = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SRetention)); cfg.pRetensions = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SRetention));
} }
cfg.cacheLast = cacheLast;
dbCfg_.insert(std::make_pair(db, cfg)); dbCfg_.insert(std::make_pair(db, cfg));
} }
...@@ -627,7 +628,9 @@ void MockCatalogService::createDnode(int32_t dnodeId, const std::string& host, i ...@@ -627,7 +628,9 @@ void MockCatalogService::createDnode(int32_t dnodeId, const std::string& host, i
impl_->createDnode(dnodeId, host, port); impl_->createDnode(dnodeId, host, port);
} }
void MockCatalogService::createDatabase(const std::string& db, bool rollup) { impl_->createDatabase(db, rollup); } void MockCatalogService::createDatabase(const std::string& db, bool rollup, int8_t cacheLast) {
impl_->createDatabase(db, rollup, cacheLast);
}
int32_t MockCatalogService::catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const { int32_t MockCatalogService::catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const {
return impl_->catalogGetTableMeta(pTableName, pTableMeta); return impl_->catalogGetTableMeta(pTableName, pTableMeta);
......
...@@ -63,7 +63,7 @@ class MockCatalogService { ...@@ -63,7 +63,7 @@ class MockCatalogService {
void createFunction(const std::string& func, int8_t funcType, int8_t outputType, int32_t outputLen, int32_t bufSize); void createFunction(const std::string& func, int8_t funcType, int8_t outputType, int32_t outputLen, int32_t bufSize);
void createSmaIndex(const SMCreateSmaReq* pReq); void createSmaIndex(const SMCreateSmaReq* pReq);
void createDnode(int32_t dnodeId, const std::string& host, int16_t port); void createDnode(int32_t dnodeId, const std::string& host, int16_t port);
void createDatabase(const std::string& db, bool rollup = false); void createDatabase(const std::string& db, bool rollup = false, int8_t cacheLast = 0);
int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const; int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const;
int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const; int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const;
......
...@@ -2011,11 +2011,13 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic ...@@ -2011,11 +2011,13 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
SNode* pNode = NULL; SNode* pNode = NULL;
FOREACH(pNode, pAgg->pAggFuncs) { FOREACH(pNode, pAgg->pAggFuncs) {
SFunctionNode* pFunc = (SFunctionNode*)pNode; SFunctionNode* pFunc = (SFunctionNode*)pNode;
int32_t len = snprintf(pFunc->functionName, sizeof(pFunc->functionName), "_cache_last_row"); if (FUNCTION_TYPE_LAST_ROW == pFunc->funcType) {
pFunc->functionName[len] = '\0'; int32_t len = snprintf(pFunc->functionName, sizeof(pFunc->functionName), "_cache_last_row");
int32_t code = fmGetFuncInfo(pFunc, NULL, 0); pFunc->functionName[len] = '\0';
if (TSDB_CODE_SUCCESS != code) { int32_t code = fmGetFuncInfo(pFunc, NULL, 0);
return code; if (TSDB_CODE_SUCCESS != code) {
return code;
}
} }
} }
pAgg->hasLastRow = false; pAgg->hasLastRow = false;
......
...@@ -198,8 +198,7 @@ static bool stbSplHasGatherExecFunc(const SNodeList* pFuncs) { ...@@ -198,8 +198,7 @@ static bool stbSplHasGatherExecFunc(const SNodeList* pFuncs) {
} }
static bool stbSplIsMultiTbScan(bool streamQuery, SScanLogicNode* pScan) { static bool stbSplIsMultiTbScan(bool streamQuery, SScanLogicNode* pScan) {
return (NULL != pScan->pVgroupList && pScan->pVgroupList->numOfVgroups > 1) || return (NULL != pScan->pVgroupList && pScan->pVgroupList->numOfVgroups > 1);
(streamQuery && TSDB_SUPER_TABLE == pScan->tableType);
} }
static bool stbSplHasMultiTbScan(bool streamQuery, SLogicNode* pNode) { static bool stbSplHasMultiTbScan(bool streamQuery, SLogicNode* pNode) {
......
...@@ -98,6 +98,24 @@ TEST_F(PlanBasicTest, interpFunc) { ...@@ -98,6 +98,24 @@ TEST_F(PlanBasicTest, interpFunc) {
} }
TEST_F(PlanBasicTest, lastRowFunc) { TEST_F(PlanBasicTest, lastRowFunc) {
useDb("root", "cache_db");
run("SELECT LAST_ROW(c1) FROM t1");
run("SELECT LAST_ROW(*) FROM t1");
run("SELECT LAST_ROW(c1, c2) FROM t1");
run("SELECT LAST_ROW(c1), c2 FROM t1");
run("SELECT LAST_ROW(c1) FROM st1");
run("SELECT LAST_ROW(c1) FROM st1 PARTITION BY TBNAME");
run("SELECT LAST_ROW(c1), SUM(c3) FROM t1");
}
TEST_F(PlanBasicTest, lastRowFuncWithoutCache) {
useDb("root", "test"); useDb("root", "test");
run("SELECT LAST_ROW(c1) FROM t1"); run("SELECT LAST_ROW(c1) FROM t1");
......
...@@ -85,7 +85,7 @@ class TDTestCase: ...@@ -85,7 +85,7 @@ class TDTestCase:
# tdSql.checkRows(10) # tdSql.checkRows(10)
# test partition interval Pseudo time-column # test partition interval Pseudo time-column
tdSql.query("SELECT count(ms1)/144 FROM (SELECT _wstartts as ts1,model, fleet,avg(status) AS ms1 FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m)) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1;") tdSql.query("SELECT count(ms1)/144 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m)) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1;")
# test # test
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册