Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Use indexed stub_id for task query instead of external id (#754)
Resolve BE-2086 With these changes the query from the `listTaskWithRelatedQueryBuilder` should come out looking like this: ```sql SELECT t.*, w.external_id AS "workspace.external_id", w.name AS "workspace.name", s.external_id AS "stub.external_id", s.name AS "stub.name", s.config AS "stub.config", s.type AS "stub.type", d.external_id AS "deployment.external_id", d.name AS "deployment.name", d.version AS "deployment.version" FROM task t JOIN workspace w ON t.workspace_id = w.id JOIN stub s ON t.stub_id = s.id LEFT JOIN deployment d ON s.id = d.stub_id WHERE t.workspace_id = $1 AND t.stub_id IN (SELECT id FROM stub WHERE external_id IN ($2)) ``` instead of looking like this ```sql SELECT t.*, w.external_id AS "workspace.external_id", w.name AS "workspace.name", s.external_id AS "stub.external_id", s.name AS "stub.name", s.config AS "stub.config", s.type AS "stub.type", d.external_id AS "deployment.external_id", d.name AS "deployment.name", d.version AS "deployment.version" FROM task t JOIN workspace w ON t.workspace_id = w.id JOIN stub s ON t.stub_id = s.id LEFT JOIN deployment d ON s.id = d.stub_id WHERE t.workspace_id = $1 AND s.external_id IN ($2) ``` The difference is in how we are adding the filter for stub ids. The combination of using a subquery to de-reference external ids into stub ids and indexing the task table on stub id yields a large performance improvement (13s -> ~0.02s on my machine).
- Loading branch information