From 952305e09645e4cd90218f32a8b85590a296f824 Mon Sep 17 00:00:00 2001 From: Peter Matseykanets Date: Thu, 26 Jun 2025 12:22:40 -0400 Subject: [PATCH] vai: Rework events garbage collection delete query (#682) --- pkg/sqlcache/informer/listoption_indexer.go | 7 ++++--- pkg/sqlcache/informer/listoption_indexer_test.go | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/sqlcache/informer/listoption_indexer.go b/pkg/sqlcache/informer/listoption_indexer.go index 81e00db4..6d39792e 100644 --- a/pkg/sqlcache/informer/listoption_indexer.go +++ b/pkg/sqlcache/informer/listoption_indexer.go @@ -98,9 +98,10 @@ const ( WHERE rv = ? ` deleteEventsByCountFmt = `DELETE FROM "%s_events" - WHERE rowid - NOT IN ( - SELECT rowid FROM "%s_events" ORDER BY rowid DESC LIMIT ? + WHERE rowid < ( + SELECT MIN(rowid) FROM ( + SELECT rowid FROM "%s_events" ORDER BY rowid DESC LIMIT ? + ) q )` createFieldsTableFmt = `CREATE TABLE "%s_fields" ( diff --git a/pkg/sqlcache/informer/listoption_indexer_test.go b/pkg/sqlcache/informer/listoption_indexer_test.go index 79a08fe8..a6000b66 100644 --- a/pkg/sqlcache/informer/listoption_indexer_test.go +++ b/pkg/sqlcache/informer/listoption_indexer_test.go @@ -348,8 +348,6 @@ func TestNewListOptionIndexerEasy(t *testing.T) { partitions []partition.Partition ns string - items []*unstructured.Unstructured - extraIndexedFields [][]string expectedList *unstructured.UnstructuredList expectedTotal int