@@ -31,6 +31,7 @@ use databend_common_meta_app::schema::DroppedId;
31
31
use databend_common_meta_app:: schema:: GcDroppedTableReq ;
32
32
use databend_common_meta_app:: schema:: ListDroppedTableReq ;
33
33
use databend_common_sql:: plans:: VacuumDropTablePlan ;
34
+ use databend_common_storages_view:: view_table:: VIEW_ENGINE ;
34
35
use databend_enterprise_vacuum_handler:: get_vacuum_handler;
35
36
use log:: info;
36
37
@@ -156,13 +157,17 @@ impl Interpreter for VacuumDropTablesInterpreter {
156
157
drop_ids
157
158
) ;
158
159
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
163
163
. into_iter ( )
164
164
. 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
+ }
166
171
167
172
let handler = get_vacuum_handler ( ) ;
168
173
let threads_nums = self . ctx . get_settings ( ) . get_max_threads ( ) ? as usize ;
@@ -187,6 +192,8 @@ impl Interpreter for VacuumDropTablesInterpreter {
187
192
// gc metadata only when not dry run
188
193
if self . plan . option . dry_run . is_none ( ) {
189
194
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.
190
197
for drop_id in drop_ids {
191
198
match & drop_id {
192
199
DroppedId :: Db { db_id, db_name : _ } => {
@@ -205,6 +212,7 @@ impl Interpreter for VacuumDropTablesInterpreter {
205
212
"failed dbs:{:?}, failed_tables:{:?}, success_drop_ids:{:?}" ,
206
213
failed_db_ids, failed_tables, success_dropped_ids
207
214
) ;
215
+
208
216
self . gc_drop_tables ( catalog, success_dropped_ids) . await ?;
209
217
}
210
218
0 commit comments