@@ -31,6 +31,7 @@ use databend_common_meta_app::schema::DroppedId;
3131use databend_common_meta_app:: schema:: GcDroppedTableReq ;
3232use databend_common_meta_app:: schema:: ListDroppedTableReq ;
3333use databend_common_sql:: plans:: VacuumDropTablePlan ;
34+ use databend_common_storages_view:: view_table:: VIEW_ENGINE ;
3435use databend_enterprise_vacuum_handler:: get_vacuum_handler;
3536use log:: info;
3637
@@ -156,13 +157,17 @@ impl Interpreter for VacuumDropTablesInterpreter {
156157 drop_ids
157158 ) ;
158159
159- // TODO buggy, table as catalog obj should be allowed to drop
160- // also drop ids
161- // filter out read-only tables
162- let tables = tables
160+ // Filter out read-only tables and views.
161+ // Note: The drop_ids list still includes view IDs
162+ let ( views, tables) : ( Vec < _ > , Vec < _ > ) = tables
163163 . into_iter ( )
164164 . filter ( |tbl| !tbl. as_ref ( ) . is_read_only ( ) )
165- . collect :: < Vec < _ > > ( ) ;
165+ . partition ( |tbl| tbl. get_table_info ( ) . meta . engine == VIEW_ENGINE ) ;
166+
167+ {
168+ let view_ids = views. into_iter ( ) . map ( |v| v. get_id ( ) ) . collect :: < Vec < _ > > ( ) ;
169+ info ! ( "view ids excluded from purging data: {:?}" , view_ids) ;
170+ }
166171
167172 let handler = get_vacuum_handler ( ) ;
168173 let threads_nums = self . ctx . get_settings ( ) . get_max_threads ( ) ? as usize ;
@@ -187,6 +192,8 @@ impl Interpreter for VacuumDropTablesInterpreter {
187192 // gc metadata only when not dry run
188193 if self . plan . option . dry_run . is_none ( ) {
189194 let mut success_dropped_ids = vec ! [ ] ;
195+ // Since drop_ids contains view IDs, any views (if present) will be added to
196+ // the success_dropped_id list, with removal from the meta-server attempted later.
190197 for drop_id in drop_ids {
191198 match & drop_id {
192199 DroppedId :: Db { db_id, db_name : _ } => {
@@ -205,6 +212,7 @@ impl Interpreter for VacuumDropTablesInterpreter {
205212 "failed dbs:{:?}, failed_tables:{:?}, success_drop_ids:{:?}" ,
206213 failed_db_ids, failed_tables, success_dropped_ids
207214 ) ;
215+
208216 self . gc_drop_tables ( catalog, success_dropped_ids) . await ?;
209217 }
210218
0 commit comments