youtube image
From YouTube: 2019-08-09 - Database query optimization techniques: UNION push down and TOP-K with index

Description

We optimize a query to retrieve TOP-100 projects for a user, bringing down query runtime from 7s to less than 20ms.

Context: https://gitlab.com/gitlab-org/gitlab-ce/issues/65854

The tricks applied are:
1. UNION push down instead of OR
2. ORDER BY, LIMIT push down into UNION branches
3. Partial index to efficiently retrieve TOP-K by ORDER BY criteria