Skip to content

Commit be3f0c8

Browse files
authored
fix: remove incorrect assertion in collecting dropped table ids (#18780)
* fix: remove incorrect assertion in collecting dropped table ids The last table id in the TableIdHistoryIdent KV pair, is NOT necessarily to be the largest one. * Add logic test
1 parent e04066e commit be3f0c8

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

src/meta/api/src/garbage_collection_api.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -211,34 +211,26 @@ pub async fn get_history_tables_for_gc(
211211

212212
let mut args = vec![];
213213

214-
// For table ids of each table with the same name, we keep the largest one, e.g.
214+
// For table ids of each table with the same name, we keep the last one, e.g.
215215
// ```
216-
// create or replace table t ... ; -- table_id 1
217-
// create or replace table t ... ; -- table_id 2
216+
// create or replace table t ... ; -- table_id a
217+
// create or replace table t ... ; -- table_id b
218218
// ```
219-
// table_id 2 will be kept for table t (we do not care about the table name though),
219+
// table_id `b` will be kept for table t,
220220
//
221-
// Please note that the largest table id might be "invisible", e.g.
221+
// Please note that the largest table id might be dropped, e.g.
222222
// ```
223223
// create or replace table t ... ; -- table_id 1
224-
// create or replace table t ... ; -- table_id 2
224+
// ...
225225
// drop table t ... ;
226226
// ```
227-
// In this case, table_id 2 is marked as dropped.
228227

229228
let mut latest_table_ids = HashSet::with_capacity(table_history_kvs.len());
230229

231230
for (ident, table_history) in table_history_kvs {
232231
let id_list = &table_history.id_list;
233-
if !id_list.is_empty() {
234-
// Make sure that the last table id is also the max one (of each table name).
235-
let last_id = id_list.last().unwrap();
236-
{
237-
let max_id = id_list.iter().max().unwrap();
238-
assert_eq!(max_id, last_id);
239-
}
232+
if let Some(last_id) = id_list.last() {
240233
latest_table_ids.insert(*last_id);
241-
242234
for table_id in id_list.iter() {
243235
args.push((TableId::new(*table_id), ident.table_name.clone()));
244236
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
statement ok
2+
create or replace database issue_18794;
3+
4+
statement ok
5+
use issue_18794;
6+
7+
statement ok
8+
create or replace table t (c int);
9+
10+
statement ok
11+
create or replace table t (c int);
12+
13+
statement ok
14+
create or replace table t (c int);
15+
16+
statement ok
17+
alter table t rename to t1;
18+
19+
statement ok
20+
create or replace table t (c int);
21+
22+
statement ok
23+
drop table t;
24+
25+
statement ok
26+
alter table t1 rename to t;
27+
28+
statement ok
29+
drop table t;
30+
31+
statement ok
32+
set data_retention_time_in_days = 0;
33+
34+
statement ok
35+
vacuum drop table;

0 commit comments

Comments
 (0)