From b6f5f303ca28b9288e7bbe5b6d1fd4462cd35fd8 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Fri, 15 Mar 2024 17:30:05 +0100 Subject: [PATCH] stores: add index hint to ObjectEntries --- stores/metadata.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stores/metadata.go b/stores/metadata.go index c543695bd..e44cb3a63 100644 --- a/stores/metadata.go +++ b/stores/metadata.go @@ -1210,6 +1210,11 @@ func (s *SQLStore) ObjectEntries(ctx context.Context, bucket, path, prefix, sort offset = 0 } + indexHint := "" + if !isSQLite(s.db) { + indexHint = "USE INDEX (idx_object_bucket, idx_objects_created_at)" + } + onameExpr := fmt.Sprintf("CASE INSTR(SUBSTR(object_id, ?), '/') WHEN 0 THEN %s ELSE %s END", sqlConcat(s.db, "?", "SUBSTR(object_id, ?)"), sqlConcat(s.db, "?", "substr(SUBSTR(object_id, ?), 1, INSTR(SUBSTR(object_id, ?), '/'))"), @@ -1226,13 +1231,14 @@ FROM ( SUM(size) AS Size, MIN(health) as Health, ANY_VALUE(mime_type) as MimeType - FROM objects + FROM objects %s INNER JOIN buckets b ON objects.db_bucket_id = b.id WHERE object_id LIKE ? AND SUBSTR(object_id, 1, ?) = ? AND b.name = ? AND SUBSTR(%s, 1, ?) = ? AND %s != ? GROUP BY oname ) baseQuery `, onameExpr, + indexHint, onameExpr, onameExpr, )