perf(fields): create index for instance domain query (#9146)

get instance by domain cannot provide an instance id because it is not
known at that time. This causes a full table scan on the fields table
because current indexes always include the `instance_id` column.

Added a specific index for this query.

If a system has many fields and there is no cache hit for the given
domain this query can heaviuly influence database CPU usage, the newly
added resolves this problem.

(cherry picked from commit f320d18b1a)
This commit is contained in:
Silvan
2025-01-07 17:06:33 +01:00
committed by adlerhurst
parent 3f59bcfac2
commit 0d5d65e4c7
5 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
CREATE INDEX CONCURRENTLY IF NOT EXISTS fields_instance_domains_idx
ON eventstore.fields (object_id)
WHERE object_type = 'instance_domain' AND field_name = 'domain';