Class DeferredInsertGuard

java.lang.Object
dev.frostlake.executor.DeferredInsertGuard

public final class DeferredInsertGuard extends Object
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

    Constructors
    Constructor
    Description
    DeferredInsertGuard(Table table, TableStorage base, TransactionWriteSet writeSet, String fullyQualifiedName, boolean enforcePrimaryKey, boolean enforceUniqueKey)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Refuse row if 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • validate

      public void validate(Row row)
      Refuse row if 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.