# Declare and optimize with UNIQUE constraints on Databricks

DevFeed: [Declare and optimize with UNIQUE constraints on Databricks](<https://devfeed.tech/articles/declare-and-optimize-with-unique-constraints-on-databricks-115579.md>)

Original publisher: [Read original article](<https://www.databricks.com/blog/declare-and-optimize-unique-constraints-databricks>)

Author: Yan Yan; Yuchuan Huang; Xinyi Yu; Gengliang Wang

Published: 2026-11-03T21:00:00Z

Content type: article

Language: en

Sources: [Databricks](<https://devfeed.tech/sources/databricks.md>)

Topics: [databricks](<https://devfeed.tech/topics/databricks.md>), [schema design](<https://devfeed.tech/topics/schema-design.md>), [Data Quality](<https://devfeed.tech/topics/data-quality.md>), [database-consistency](<https://devfeed.tech/topics/database-consistency.md>)

Tags: [aggregation](<https://devfeed.tech/tags/aggregation.md>), [anti-join](<https://devfeed.tech/tags/anti-join.md>), [bi-tools](<https://devfeed.tech/tags/bi-tools.md>), [cascade](<https://devfeed.tech/tags/cascade.md>), [catalog](<https://devfeed.tech/tags/catalog.md>), [column](<https://devfeed.tech/tags/column.md>), [compute](<https://devfeed.tech/tags/compute.md>), [constraint](<https://devfeed.tech/tags/constraint.md>), [dashboard](<https://devfeed.tech/tags/dashboard.md>), [dashboards](<https://devfeed.tech/tags/dashboards.md>), [data-quality](<https://devfeed.tech/tags/data-quality.md>), [data-teams](<https://devfeed.tech/tags/data-teams.md>), [data-warehousing](<https://devfeed.tech/tags/data-warehousing.md>), [databricks](<https://devfeed.tech/tags/databricks.md>), [dataset](<https://devfeed.tech/tags/dataset.md>), [delta](<https://devfeed.tech/tags/delta.md>), [engine](<https://devfeed.tech/tags/engine.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [guarantees](<https://devfeed.tech/tags/guarantees.md>), [optimize](<https://devfeed.tech/tags/optimize.md>), [pipelines](<https://devfeed.tech/tags/pipelines.md>), [unique](<https://devfeed.tech/tags/unique.md>)

## AI overview

Databricks UNIQUE constraints let Unity Catalog Delta tables record multiple single-column or composite uniqueness guarantees, including on nullable columns; foreign keys can reference them. Constraints are informational and do not validate or enforce writes. After verifying and continuously maintaining the data guarantees, set RELY so Photon-enabled compute can use them for eligible join elimination and DISTINCT aggregation removal. Rewrites depend on the query's other guarantees: for example, nullable UNIQUE columns may need an IS NOT NULL filter, and inner join removal may also require a valid foreign key. Incorrect RELY assumptions can produce incorrect results. The excerpt reports TPC-DS benchmarks with 7.9x faster join and 12.0x faster DISTINCT cases, each removing over 99.99% of shuffle.

## Source excerpt

Data teams often maintain uniqueness guarantees in their pipelines, but without a...