Extend set operator select mismatch warning
We use ApplicationRecord#cached_column_list
(also via ApplicationRecord#default_select_columns
) to render explicit SELECT
columns. This is especially important for UNION / EXCEPT / INTERSECT
queries where column names must align exactly.
In some cases, we generate queries where we mix ApplicationRecord#cached_column_list
with SELECT
values of Arel.star
. This creates queries of the form:
(
SELECT namespaces.*
FROM namespaces
) UNION
(
SELECT namespaces.id
... all column names from namespaces
FROM namespaces
)
which can result in SQL errors when the columns are not in sync. Examples of this problem include:
- #390206 (closed)
- gitlab-com/gl-infra/production#14470 (closed)
- gitlab-com/gl-infra/production#5171 (closed)
We require explicit column names to avoid issues around rolling deployments.
One solution is to warn in dev
and test
environment that mismatched SELECT
statements are being used. This may be similar to how the cross database query detection works.
Edited by Alex Pooley