Package dev.frostlake.executor
Class DeferredInsertGuard
java.lang.Object
dev.frostlake.executor.DeferredInsertGuard
Statement-scoped duplicate-key guard for deferred-apply INSERTs. The former per-row checks
re-copied the transaction's pending inserts for every row (O(k²) over a k-row statement) and, for
each UNIQUE column, re-copied the ENTIRE committed table per row. This guard prefetches both once
— pending primary keys and each UNIQUE column's existing values into hash sets — and then adds
every accepted row's values, so validating n rows costs O(n) set probes.
PRIMARY KEY enforcement applies when the engine-level constraints.enforce.primaryKey
flag is on and the table declares a key; UNIQUE enforcement only under the opt-in
constraints.enforce.uniqueKey flag (off by default — UNIQUE is otherwise informational,
matching Snowflake). UNIQUE is modeled per column, so a composite UNIQUE is enforced column by
column; PK columns are covered by the primary-key check and NULLs are unconstrained. Pending
UPDATEs are deliberately not consulted, and the committed base is walked by position — resolution
prefetch over a scan, unique indexes are intentionally not implemented.
-
Constructor Summary
ConstructorsConstructorDescriptionDeferredInsertGuard(Table table, TableStorage base, TransactionWriteSet writeSet, String fullyQualifiedName, boolean enforcePrimaryKey, boolean enforceUniqueKey) -
Method Summary
Modifier and TypeMethodDescriptionvoidRefuserowif it duplicates a primary key (in the committed base or this transaction's pending inserts) or a guarded UNIQUE column's non-null value; an accepted row's values join the seen sets so later rows of the same statement are checked against it too.
-
Constructor Details
-
DeferredInsertGuard
public DeferredInsertGuard(Table table, TableStorage base, TransactionWriteSet writeSet, String fullyQualifiedName, boolean enforcePrimaryKey, boolean enforceUniqueKey)
-
-
Method Details
-
validate
Refuserowif it duplicates a primary key (in the committed base or this transaction's pending inserts) or a guarded UNIQUE column's non-null value; an accepted row's values join the seen sets so later rows of the same statement are checked against it too.
-