[SPIKE] Experiment with new `group_rollup` column on `AuditEvent` table
Background Context
We want to be able to return all audit events under a given groups via a single endpoint. We have an issue, API endpoint to retrieve all audit events under a given group, to track this feature.
We actually had already implemented that feature, but the performance was so poor in production that it functionally did not work. The database query timed out almost 100% of the time.
The proposal was to improve the existing query's performance by using the InOperatorOptimization
library.
Attempts to do this did not show a good performance boost (details here)
New Approach
We want to attempt this feature with a new approach. The Idea is that we can add a new column, group_rollup
, to the audit_events
table. This column will be the id
of the top-level group the audit event belongs to.
We can then update the Auditor to write this value at audit event creation, allowing us to implement the endpoint with a simple query:
SELECT * FROM "audit_events" WHERE "audit_events"."group_rollup_id" == @group.id
This query should be straightforward to index and paginate, giving us acceptable performance.
This Issue
We want this issue to track the validation of this approach in database lab.
We should:
- add the column in database lab
- add an index for the column in database lab
- backfill the new column in database lab
- generate the query plan
If the performance looks good in the query plan, we can move ahead with implementing the feature (using #337757 (closed) to track the implementation work)