Support covering indexes in migration helpers
We've picked up using covering indexes, but we don't yet have support for that in migration helpers, e.g. add_concurrent_index
doesn't support it.
When doing this manually (crafting SQL), one has to remember to also disable the statement timeout and check if the index exists already. If one should forget (like I did), this is guaranteed to result in a timeout like gitlab-com/gl-infra/production#4485 (closed).
A covering index includes other columns "on the sides", typically to allow for index-only scans:
CREATE INDEX ON table (col1, col2) INCLUDE (col3, col4)
That supports an index only scan, e.g. for SELECT col3, col4 FROM table WHERE col1 = ? AND col2 = ?
or similar.
Ideally, our two helpers add_concurrent_index, remove_concurrent_index
would additionally support a include: [:col3, :col4]
parameter.
Rails support
Rails does not seem to support this yet though.
There is a Rails PR for this: https://github.com/rails/rails/pull/37515 This is closed, new PR: https://github.com/rails/rails/pull/44803