fix(catalog-backend): simplify facets COUNT(DISTINCT) to COUNT(*)

The UNIQUE constraint on (entity_id, key, value) from the search
indices migration guarantees each entity appears at most once per
(key, original_value) group, making DISTINCT unnecessary. Removing
it lets the database use a simpler aggregation plan.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2026-05-11 22:06:55 +02:00
parent 3be2ee90b6
commit 387ea7dd75
2 changed files with 6 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': patch
---
Simplified the entity facets aggregation from `COUNT(DISTINCT entity_id)` to `COUNT(*)`. The unique constraint on `(entity_id, key, value)` guarantees each entity appears at most once per search row group, making the `DISTINCT` unnecessary. This allows the database to use a simpler aggregation plan.
@@ -685,7 +685,7 @@ export class DefaultEntitiesCatalog implements EntitiesCatalog {
.select({
facet: 'search.key',
value: 'search.original_value',
count: this.database.raw('count(DISTINCT search.entity_id)'),
count: this.database.raw('count(*)'),
})
.groupBy(['search.key', 'search.original_value']);