Audit events query causes large temp file write on database replicas
The query with fingerprint 5105f57baacafa1f
, SELECT "audit_events".* FROM "audit_events" WHERE "audit_events"."entity_type" = $1 AND "audit_events"."entity_id" = $2 AND "audit_events"."created_at" >= $3 ORDER BY "audit_events"."id" DESC LIMIT $4 OFFSET $5
, is responsible for a large number of temp file writes on replica databases.
Below shows top queries writing temp data across the database, this query is the large outlier in pink. (source)
Statement timeouts for this query: https://log.gprd.gitlab.net/app/r/s/ZNXt0
We should change this query so that it doesn't need to spill sorts to disk.