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:
@@ -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']);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user