From c8ae8f8c838f7e388df48b3df074b2db0cfaeeff Mon Sep 17 00:00:00 2001 From: HuangWei Date: Tue, 2 Jul 2024 11:03:57 +0800 Subject: [PATCH] fix: drop aggr tables in drop table (#3908) * fix: drop aggr tables in drop table * fix * fix test * fix * fix --------- Co-authored-by: Huang Wei --- src/cmd/sql_cmd_test.cc | 198 ++++++++-------------------------- src/sdk/sql_cluster_router.cc | 77 ++++++------- 2 files changed, 77 insertions(+), 198 deletions(-) diff --git a/src/cmd/sql_cmd_test.cc b/src/cmd/sql_cmd_test.cc index 0b29ae449cd..63acf9f70bf 100644 --- a/src/cmd/sql_cmd_test.cc +++ b/src/cmd/sql_cmd_test.cc @@ -1628,19 +1628,18 @@ TEST_P(DBSDKTest, DeployLongWindows) { rs = sr->ExecuteSQL("", result_sql, &status); ASSERT_EQ(3, rs->Size()); - std::string msg; - auto ok = sr->ExecuteDDL(openmldb::nameserver::PRE_AGG_DB, "drop table pre_test2_demo1_w1_sum_c4;", &status); - ASSERT_TRUE(ok); - ok = sr->ExecuteDDL(openmldb::nameserver::PRE_AGG_DB, "drop table pre_test2_demo1_w2_max_c5;", &status); - ASSERT_TRUE(ok); - ok = sr->ExecuteDDL(openmldb::nameserver::PRE_AGG_DB, "drop table pre_test2_demo3_w1_count_where_c4_c3;", &status); - ASSERT_TRUE(ok); - ASSERT_FALSE(cs->GetNsClient()->DropTable("test2", "trans", msg)); - ASSERT_TRUE(cs->GetNsClient()->DropProcedure("test2", "demo1", msg)); - ASSERT_TRUE(cs->GetNsClient()->DropProcedure("test2", "demo2", msg)); - ASSERT_TRUE(cs->GetNsClient()->DropProcedure("test2", "demo3", msg)); - ASSERT_TRUE(cs->GetNsClient()->DropTable("test2", "trans", msg)); - ASSERT_TRUE(cs->GetNsClient()->DropDatabase("test2", msg)); + // drop deployment + sr->ExecuteSQL("test2", "drop deployment demo1;", &status); + ASSERT_TRUE(status.IsOK()) << status.ToString(); + rs = sr->ExecuteSQL("test2", "drop deployment demo2;", &status); + ASSERT_TRUE(status.IsOK()) << status.ToString(); + rs = sr->ExecuteSQL("test2", "drop deployment demo3;", &status); + ASSERT_TRUE(status.IsOK()) << status.ToString(); + + sr->ExecuteSQL("test2", "drop table trans", &status); + ASSERT_TRUE(status.IsOK()) << status.ToString(); + sr->ExecuteSQL("drop database test2;", &status); + ASSERT_TRUE(status.IsOK()) << status.ToString(); } void CreateDBTableForLongWindow(const std::string& base_db, const std::string& base_table) { @@ -1711,6 +1710,7 @@ void PrepareRequestRowForLongWindow(const std::string& base_db, const std::strin } // TODO(ace): create instance of DeployLongWindowEnv with template +static absl::BitGen gen; // reseed may segfault, use one for all env class DeployLongWindowEnv { public: explicit DeployLongWindowEnv(sdk::SQLClusterRouter* sr) : sr_(sr) {} @@ -1718,9 +1718,9 @@ class DeployLongWindowEnv { virtual ~DeployLongWindowEnv() {} void SetUp() { - db_ = absl::StrCat("db_", absl::Uniform(gen_, 0, std::numeric_limits::max())); - table_ = absl::StrCat("tb_", absl::Uniform(gen_, 0, std::numeric_limits::max())); - dp_ = absl::StrCat("dp_", absl::Uniform(gen_, 0, std::numeric_limits::max())); + db_ = absl::StrCat("db_", absl::Uniform(gen, 0, std::numeric_limits::max())); + table_ = absl::StrCat("tb_", absl::Uniform(gen, 0, std::numeric_limits::max())); + dp_ = absl::StrCat("dp_", absl::Uniform(gen, 0, std::numeric_limits::max())); PrepareSchema(); @@ -1732,7 +1732,7 @@ class DeployLongWindowEnv { } void TearDown() { - TearDownPreAggTables(); + TearDownDeployment(); ProcessSQLs(sr_, { absl::StrCat("drop table ", table_), absl::StrCat("drop database ", db_), @@ -1788,7 +1788,12 @@ class DeployLongWindowEnv { virtual void Deploy() = 0; - virtual void TearDownPreAggTables() = 0; + virtual void TearDownDeployment() { + ProcessSQLs(sr_, { + absl::StrCat("use ", db_), + absl::StrCat("drop deployment ", dp_), + }); + } void GetRequestRow(std::shared_ptr* rs, const std::string& name) { // NOLINT ::hybridse::sdk::Status status; @@ -1814,7 +1819,6 @@ class DeployLongWindowEnv { protected: sdk::SQLClusterRouter* sr_; - absl::BitGen gen_; std::string db_; std::string table_; std::string dp_; @@ -1843,14 +1847,14 @@ TEST_P(DBSDKTest, DeployLongWindowsWithDataFail) { ".col2 ORDER BY col3" " ROWS_RANGE BETWEEN 5 PRECEDING AND CURRENT ROW);"; sr->ExecuteSQL(base_db, "use " + base_db + ";", &status); - ASSERT_TRUE(status.IsOK()) << status.msg; + ASSERT_TRUE(status.IsOK()) << status.ToString(); sr->ExecuteSQL(base_db, deploy_sql, &status); ASSERT_TRUE(!status.IsOK()); ok = sr->ExecuteDDL(base_db, "drop table " + base_table + ";", &status); - ASSERT_TRUE(ok) << status.msg; + ASSERT_TRUE(ok) << status.ToString(); ok = sr->DropDB(base_db, &status); - ASSERT_TRUE(ok); + ASSERT_TRUE(ok) << status.ToString(); } TEST_P(DBSDKTest, DeployLongWindowsEmpty) { @@ -2871,25 +2875,6 @@ TEST_P(DBSDKTest, DeployLongWindowsExecuteCountWhere2) { w1 AS (PARTITION BY col1,col2 ORDER BY col3 ROWS_RANGE BETWEEN 6s PRECEDING AND CURRENT ROW);)", dp_, table_)}); } - - void TearDownPreAggTables() override { - absl::string_view pre_agg_db = openmldb::nameserver::PRE_AGG_DB; - ProcessSQLs(sr_, { - absl::StrCat("use ", pre_agg_db), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_i64_col_i64_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_i64_col_i16_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_i16_col_i32_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_i32_col_f_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_f_col_d_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_d_col_d_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_s_col_col1"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_date_col_s_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where__i64_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_filter_i64_col"), - absl::StrCat("use ", db_), - absl::StrCat("drop deployment ", dp_), - }); - } }; // request window [5s, 11s] @@ -2948,24 +2933,6 @@ TEST_P(DBSDKTest, DeployLongWindowsExecuteCountWhere3) { w2 AS (PARTITION BY col1,col2 ORDER BY i64_col ROWS BETWEEN 6 PRECEDING AND CURRENT ROW);)", dp_, table_)}); } - - void TearDownPreAggTables() override { - absl::string_view pre_agg_db = openmldb::nameserver::PRE_AGG_DB; - ProcessSQLs(sr_, { - absl::StrCat("use ", pre_agg_db), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_i64_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_i64_col_col1"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_i16_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_i32_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_f_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_d_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_t_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_s_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_count_where_date_col_filter"), - absl::StrCat("use ", db_), - absl::StrCat("drop deployment ", dp_), - }); - } }; // request window [4s, 11s] @@ -3023,26 +2990,6 @@ TEST_P(DBSDKTest, LongWindowMinMaxWhere) { w1 AS (PARTITION BY col1,col2 ORDER BY col3 ROWS_RANGE BETWEEN 7s PRECEDING AND CURRENT ROW))s", dp_, table_)}); } - - void TearDownPreAggTables() override { - absl::string_view pre_agg_db = openmldb::nameserver::PRE_AGG_DB; - ProcessSQLs(sr_, { - absl::StrCat("use ", pre_agg_db), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_max_where_i64_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_max_where_i64_col_col1"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_max_where_i16_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_max_where_i32_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_max_where_f_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_max_where_d_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_min_where_i64_col_i16_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_min_where_i16_col_i32_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_min_where_i32_col_f_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_min_where_f_col_d_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_min_where_d_col_d_col"), - absl::StrCat("use ", db_), - absl::StrCat("drop deployment ", dp_), - }); - } }; // request window [4s, 11s] @@ -3100,25 +3047,6 @@ TEST_P(DBSDKTest, LongWindowSumWhere) { w1 AS (PARTITION BY col1,col2 ORDER BY col3 ROWS_RANGE BETWEEN 7s PRECEDING AND CURRENT ROW))s", dp_, table_)}); } - - void TearDownPreAggTables() override { - absl::string_view pre_agg_db = openmldb::nameserver::PRE_AGG_DB; - ProcessSQLs(sr_, { - absl::StrCat("use ", pre_agg_db), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_sum_where_i64_col_col1"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_sum_where_i16_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_sum_where_i32_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_sum_where_f_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_sum_where_d_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_sum_where_i64_col_i16_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_sum_where_i16_col_i32_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_sum_where_i32_col_f_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_sum_where_f_col_d_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_sum_where_d_col_d_col"), - absl::StrCat("use ", db_), - absl::StrCat("drop deployment ", dp_), - }); - } }; // request window [4s, 11s] @@ -3175,25 +3103,6 @@ TEST_P(DBSDKTest, LongWindowAvgWhere) { w1 AS (PARTITION BY col1,col2 ORDER BY col3 ROWS_RANGE BETWEEN 7s PRECEDING AND CURRENT ROW))s", dp_, table_)}); } - - void TearDownPreAggTables() override { - absl::string_view pre_agg_db = openmldb::nameserver::PRE_AGG_DB; - ProcessSQLs(sr_, { - absl::StrCat("use ", pre_agg_db), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_i64_col_col1"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_i16_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_i32_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_f_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_d_col_f_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_i64_col_i16_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_i16_col_i32_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_i32_col_f_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_f_col_d_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_d_col_d_col"), - absl::StrCat("use ", db_), - absl::StrCat("drop deployment ", dp_), - }); - } }; // request window [4s, 11s] @@ -3273,25 +3182,6 @@ TEST_P(DBSDKTest, LongWindowAnyWhereWithDataOutOfOrder) { ASSERT_TRUE(ok && s.IsOK()) << s.msg << "\n" << s.trace; } } - - void TearDownPreAggTables() override { - absl::string_view pre_agg_db = openmldb::nameserver::PRE_AGG_DB; - ProcessSQLs(sr_, { - absl::StrCat("use ", pre_agg_db), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_i64_col_col1"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_i16_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_i32_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_f_col_filter"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_d_col_f_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_i64_col_i16_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_i16_col_i32_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_i32_col_f_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_f_col_d_col"), - absl::StrCat("drop table pre_", db_, "_", dp_, "_w1_avg_where_d_col_d_col"), - absl::StrCat("use ", db_), - absl::StrCat("drop deployment ", dp_), - }); - } }; // request window [4s, 11s] @@ -3354,8 +3244,7 @@ TEST_P(DBSDKTest, LongWindowAnyWhereUnsupportRowsBucket) { << "code=" << status.code << ", msg=" << status.msg << "\n" << status.trace; } - - void TearDownPreAggTables() override {} + void TearDownDeployment() override {} }; // unsupport: deploy any_where with rows bucket @@ -3390,8 +3279,7 @@ TEST_P(DBSDKTest, LongWindowAnyWhereUnsupportTimeFilter) { << "code=" << status.code << ", msg=" << status.msg << "\n" << status.trace; } - - void TearDownPreAggTables() override {} + void TearDownDeployment() override {} }; DeployLongWindowAnyWhereEnv env(sr); @@ -3420,8 +3308,7 @@ TEST_P(DBSDKTest, LongWindowAnyWhereUnsupportTimeFilter) { << "code=" << status.code << ", msg=" << status.msg << "\n" << status.trace; } - - void TearDownPreAggTables() override {} + void TearDownDeployment() override {} }; DeployLongWindowAnyWhereEnv env(sr); @@ -3481,8 +3368,7 @@ TEST_P(DBSDKTest, LongWindowAnyWhereUnsupportHDDTable) { << "code=" << status.code << ", msg=" << status.msg << "\n" << status.trace; } - - void TearDownPreAggTables() override {} + void TearDownDeployment() override {} }; DeployLongWindowAnyWhereEnv env(sr); @@ -3504,26 +3390,35 @@ TEST_P(DBSDKTest, LongWindowsCleanup) { " max(c5) over w2 as w2_max_c5 FROM trans" " WINDOW w1 AS (PARTITION BY trans.c1 ORDER BY trans.c7 ROWS BETWEEN 2 PRECEDING AND CURRENT ROW)," " w2 AS (PARTITION BY trans.c1 ORDER BY trans.c4 ROWS BETWEEN 3 PRECEDING AND CURRENT ROW);"; + for (int i = 0; i < 10; i++) { HandleSQL("create database test2;"); HandleSQL("use test2;"); HandleSQL(create_sql); + LOG(INFO) << "before deploy " << i; + HandleSQL("select * from __INTERNAL_DB.PRE_AGG_META_INFO;"); sr->ExecuteSQL(deploy_sql, &status); ASSERT_TRUE(status.IsOK()); + absl::SleepFor(absl::Seconds(3)); + LOG(INFO) << "after deploy " << i; + HandleSQL("select * from __INTERNAL_DB.PRE_AGG_META_INFO;"); std::string msg; std::string result_sql = "select * from __INTERNAL_DB.PRE_AGG_META_INFO;"; auto rs = sr->ExecuteSQL("", result_sql, &status); + ASSERT_TRUE(status.IsOK()) << status.ToString(); ASSERT_EQ(2, rs->Size()); - auto ok = sr->ExecuteDDL(openmldb::nameserver::PRE_AGG_DB, "drop table pre_test2_demo1_w1_sum_c4;", &status); - ASSERT_TRUE(ok); - ok = sr->ExecuteDDL(openmldb::nameserver::PRE_AGG_DB, "drop table pre_test2_demo1_w2_max_c5;", &status); - ASSERT_TRUE(ok); + sr->ExecuteSQL("test2", "drop table trans;", &status); + ASSERT_FALSE(status.IsOK()); + sr->ExecuteSQL("drop procedure demo1;", &status); + ASSERT_TRUE(status.IsOK()) << status.ToString(); + sr->ExecuteSQL("test2", "drop table trans;", &status); + ASSERT_TRUE(status.IsOK()) << status.ToString(); + result_sql = "select * from __INTERNAL_DB.PRE_AGG_META_INFO;"; + HandleSQL(result_sql); rs = sr->ExecuteSQL("", result_sql, &status); + ASSERT_TRUE(status.IsOK()) << status.ToString(); ASSERT_EQ(0, rs->Size()); - ASSERT_FALSE(cs->GetNsClient()->DropTable("test2", "trans", msg)); - ASSERT_TRUE(cs->GetNsClient()->DropProcedure("test2", "demo1", msg)) << msg; - ASSERT_TRUE(cs->GetNsClient()->DropTable("test2", "trans", msg)) << msg; // helpful for debug HandleSQL("show tables;"); HandleSQL("show deployments;"); @@ -4151,6 +4046,7 @@ TEST_F(SqlCmdTest, SelectWithAddNewIndex) { hybridse::sdk::Status status; auto res = sr->ExecuteSQL(absl::StrCat("use ", db1_name, ";"), &status); res = sr->ExecuteSQL(absl::StrCat("select id,c1,c2,c3 from ", tb1_name), &status); + ASSERT_TRUE(status.IsOK()) << status.ToString(); ASSERT_EQ(res->Size(), 4); res = sr->ExecuteSQL(absl::StrCat("select id,c1,c2,c3 from ", tb1_name, " where c1='aa';"), &status); ASSERT_EQ(res->Size(), 3); diff --git a/src/sdk/sql_cluster_router.cc b/src/sdk/sql_cluster_router.cc index 8ef74f8ac2d..0a77681668d 100644 --- a/src/sdk/sql_cluster_router.cc +++ b/src/sdk/sql_cluster_router.cc @@ -880,54 +880,38 @@ bool SQLClusterRouter::DropTable(const std::string& db, const std::string& table } } - // delete pre-aggr meta info if need - if (table_info->base_table_tid() > 0) { - std::string meta_db = openmldb::nameserver::INTERNAL_DB; - std::string meta_table = openmldb::nameserver::PRE_AGG_META_NAME; - std::string select_aggr_info = - absl::StrCat("select base_db,base_table,aggr_func,aggr_col,partition_cols,order_by_col,filter_col from ", - meta_db, ".", meta_table, " where aggr_table = '", table_info->name(), "';"); - auto rs = ExecuteSQL("", select_aggr_info, true, true, 0, status); - WARN_NOT_OK_AND_RET(status, "get aggr info failed", false); - if (rs->Size() != 1) { - SET_STATUS_AND_WARN(status, StatusCode::kCmdError, - "duplicate records generate with aggr table name: " + table_info->name()); - return false; - } - std::string idx_key; - if (rs->Next()) { - for (int i = 0; i < rs->GetSchema()->GetColumnCnt(); i++) { - if (!idx_key.empty()) { - idx_key += "|"; - } - auto k = rs->GetAsStringUnsafe(i); - if (k.empty()) { - idx_key += hybridse::codec::EMPTY_STRING; - } else { - idx_key += k; - } + // delete related pre-aggr tables first + std::string meta_db = openmldb::nameserver::INTERNAL_DB; + std::string meta_table = openmldb::nameserver::PRE_AGG_META_NAME; + std::string select_aggr_info = + absl::StrCat("select aggr_db, aggr_table from ", meta_db, ".", meta_table, " where base_table = '", + table_info->name(), "' and base_db='", table_info->db(), "';"); + auto rs = ExecuteSQL("", select_aggr_info, true, true, 0, status); + WARN_NOT_OK_AND_RET(status, "get aggr info failed", false); + if (rs->Size() > 0) { + // drop aggr-table and meta info one by one, if failed, plz delete manually + while (rs->Next()) { + std::string aggr_db = rs->GetStringUnsafe(0); + std::string aggr_table = rs->GetStringUnsafe(1); + + if (aggr_db.empty() || aggr_table.empty()) { + WARN_NOT_OK_AND_RET( + status, absl::StrCat("aggr table ", aggr_db, " or ", aggr_table, " is empty, can't delete"), false); } - } else { - SET_STATUS_AND_WARN(status, StatusCode::kCmdError, "access ResultSet failed"); - return false; - } - auto tablet_accessor = cluster_sdk_->GetTablet(meta_db, meta_table, (uint32_t)0); - if (!tablet_accessor) { - SET_STATUS_AND_WARN(status, StatusCode::kCmdError, "get tablet accessor failed"); - return false; - } - auto tablet_client = tablet_accessor->GetClient(); - if (!tablet_client) { - SET_STATUS_AND_WARN(status, StatusCode::kCmdError, "get tablet client failed"); - return false; - } - auto tid = cluster_sdk_->GetTableId(meta_db, meta_table); - std::string msg; - if (!tablet_client->Delete(tid, 0, table_info->name(), "aggr_table", msg) || - !tablet_client->Delete(tid, 0, idx_key, "unique_key", msg)) { - SET_STATUS_AND_WARN(status, StatusCode::kCmdError, "delete aggr meta failed"); - return false; + if (!DropTable(aggr_db, aggr_table, true, status)) { + WARN_NOT_OK_AND_RET(status, absl::StrCat("drop aggr table ", aggr_db, ".", aggr_table, " failed"), + false); + } + LOG(INFO) << "drop aggr meta " << aggr_db << "." << aggr_table << "by table name"; + // Ref CheckPreAggrTableExist, checking existence of aggr table uses the unique_key index, ignore bucket_size. + // But for deleting, we don't need to consider the unique_key. Just delete the table, aggr_table is unique. + std::string delete_aggr_info = + absl::StrCat("delete from ", meta_db, ".", meta_table, " where aggr_table='", aggr_table, "';"); + auto rs = ExecuteSQL("", delete_aggr_info, true, true, 0, status); + WARN_NOT_OK_AND_RET(status, "delete aggr info failed", false); } + } else { + LOG(INFO) << "no related pre-aggr tables"; } // Check offline table info first @@ -3046,7 +3030,6 @@ std::shared_ptr SQLClusterRouter::ExecuteSQL( case hybridse::node::kPlanTypeCreateUser: { auto create_node = dynamic_cast(node); UserInfo user_info; - auto result = GetUser(create_node->Name(), &user_info); if (!result.ok()) { *status = {StatusCode::kCmdError, result.status().message()};