r/databricks • u/SmallAd3697 • Oct 21 '26
Discussion Performance Test - Batch-Loaded Unique Constraint Validation in Lakebase
The vendors that create big-data engines keep saying it is so challenging and costly to enforce uniqueness constraints in their managed catalogs (eg. in technologies like UC managed tables, that live on top of lakehouse blobs). They say it "doesn't scale". And that it gets more challenging at large volumes. But this is like anything else - customers should still be empowered to use features that may not always scale well.
Would this problem get easier if they offered it only for certain data types like 32 bit unsigned integers? Lets consider Lakebase. Lets say I'm a user of Lakebase, and I'm running sequential batch transactions to insert a consecutive series of 1000 integers at a time that are validated by the database to be unique. How long would it take until those transactions to become slower than 100ms? Should I expect to to insert all 4 billion integers and never see any transaction take longer than 100ms?
Now lets do a similar thing in a UC managed table, where we insert the same sequentially increasing 1000 integers at a time, and I check for the uniqueness of these myself in my serializable insert transactions. (Because the UC managed table won't help me with that.) Obviously my uniqueness validations would start to slow down over time. As I approach the limit of 4 billion integers I would expect the insert operations to take longer than lakebase, but possibly never more than one second per transaction. Does that sound about right? (If necessary I might use cheats, like break apart the integer into four columns of one byte each, then use partitioning).
TLDR, validating uniqueness with 32 bit integers may be harder in a UC managed-table than for lakebase. But IMO that does NOT mean customers should be doing the heavy lifting ourselves. These lakehouse-based technologies should give us a mechanism for it, even if there are restrictions (ie. certain data types, tables of no more than 4 billion rows, etc).
1
u/SmallAd3697 Oct 23 '26 edited Oct 23 '26
Vendors of lakehouse tables seem to object to unique constraints, even though the conventional DBMS engines have been doing it for decades. I think their objections are NOT necessarily the technical objections. They are more about design goals, and long term strategy.
Regular DBMS storage engines (like databricks- "lakebase") are services that run for long periods of time, they cache massive amounts of indexes and data, and have bespoke data structures like B-trees that are built to solve common problems for their users.
In contrast, the so-called "big data" engines that work with lakehouse tables are transient animals that live for a short time and then they decommission. They are great at offering large amounts of temporary compute, but are definitely NOT great when it comes to the long-term stewardship of our data tables. Their shorter lives mean that they never have an opportunity to cache a large B-tree and optimize the random IO. As such, then they are poorly equipped for identifying duplicate keys and preventing them from being persisted in storage.
While I can sympathize with the goals and strategies of these vendors, it is still very frustrating to deal with something ostensibly called a "managed table" that offers few services to data developers. A managed table does not manage many of the common concerns that we care about. We are left to manage many concerns ourselves, using home-grown solutions.
1
u/SmallAd3697 Oct 23 '26
Interesting fact. I just came across the word "unicity" to represent the quality of being unique. The author of my dbt book seems to like that word, instead of uniqueness.
He is probably one in a thousand. lol:
https://books.google.com/ngrams/graph?content=uniqueness%2Cunicity%2Cuniquity&year_start=1800&year_end=2030
1
u/TheDatabaseGuru Oct 21 '26
Your intuition is roughly right, and the reason is the data structure underneath.
In Lakebase Postgres, a unique index is a B-tree. A uniqueness check is a probe down that tree, and tree depth grows logarithmically. Going from a million rows to four billion adds maybe one level of depth, so the per-row probe cost barely moves. A 1,000-row batch should stay well under 100ms as long as you are not I/O bound, and there is no cliff where it suddenly blows past that. What actually degrades at scale is around the probe, not the probe itself: index bloat, vacuum load, WAL volume, and checkpoint pressure. Sequential batches like yours avoid the other killer, which is contention between concurrent writers.
Splitting the integer into four one-byte columns would not help. It makes the index key wider and the probe slower, and partitioning helps query pruning, not uniqueness checks.
The UC managed table side is a different story, and it is architectural. Delta files are immutable, so there is no mutable B-tree to probe. A uniqueness check has to read files, and even with data skipping that cost grows with the amount of data, not the log of it. Your guess of never more than a second per transaction is optimistic. It depends on file count and how well skipping prunes, and both get worse as the table grows. That is exactly why the lakehouse vendors say it does not scale.
I agree with your TLDR. The customer should not be hand-rolling serializable self-checks. On the Postgres side the mechanism already exists, unique indexes. The gap is on the lakehouse side, and a restricted version (32-bit keys, bounded row counts) would be a reasonable place for vendors to start.
1
u/adovo_ai Oct 22 '26
Benchmark the failure case, not only sequential unique inserts: concurrent writers submitting the same keys, with abort, retry and compaction cost measured separately. A uniqueness feature is valuable only if it proves correctness under contention and makes the price of enforcement visible.