DML and CTAS commands: Potential for wrong results when the RELY property is set (Preview)¶
Attention
This behavior change is in the 2025_03 bundle.
For the current status of the bundle, refer to Bundle History.
When this behavior change bundle is enabled, an optimization on certain DML and CTAS statements might produce wrong results when the RELY property is set on the target table:
- Before the change:
DML and CTAS statements on tables with UNIQUE and PRIMARY KEY constraints do not qualify for an optimization that is applied to DISTINCT and GROUP BY operations. (The optimizer prunes redundant grouping columns.)
Because the optimization in question is currently applied to SELECT statements only, the optimization presents no risk that incorrect data might be inserted if the RELY property is set for a constraint and a violation of referential integrity occurs.
- After the change:
DML and CTAS statements on tables with UNIQUE and PRIMARY KEY constraints now qualify for the same optimization that is applied to SELECT statements.
If the RELY property is set for a constraint and a violation of referential integrity occurs, incorrect data might be inserted.
Background information¶
Snowflake does not enforce referential integrity on standard tables, regardless of the constraints and properties that you define. (The exception to this rule is hybrid tables, where certain constraints are required and enforced.)
The RELY constraint property declares that you believe your table data has referential integrity (or that another application is enforcing it before the data is loaded into Snowflake). The RELY property must be set explicitly and is not enabled by default. It is already documented that setting this property might lead to unintended behavior and/or unexpected results.
Identifying tables with the RELY constraint property¶
To find out which tables have the RELY property set for PRIMARY KEY or UNIQUE constraints, run this query:
SELECT table_schema, table_name
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE RELY ='YES'
AND (constraint_type = 'PRIMARY KEY' OR constraint_type = 'UNIQUE');
Consider dropping constraints or not setting the RELY property if you anticipate any issues when the optimization takes effect.
Ref: 1902