btree index (12)

_bt_check_unique

unique indexのとき登録するアイテムがユニークかチェックする。ユニークなときはInvalidTransactionIdを返す。別のトランザクションが更新中のタプルと重複している場合は、更新中のトランザクションがcommitするかabortするまでwaitするために、そのTransactionIdを返す。アイテムが重複する場合は、ereportでERRORにする。

_bt_do_insert

_bt_check_uniqueでTransactionIdが返された場合は、XactLockTableWaitでトランザクションの終了を待ってから、再度ユニークチェックを実行する。

    if (index_is_unique)
    {
        TransactionId xwait;

        xwait = _bt_check_unique(rel, btitem, heapRel, buf, itup_scankey);

        if (TransactionIdIsValid(xwait))
        {
            /* Have to wait for the other guy ... */
            _bt_relbuf(rel, buf);
            XactLockTableWait(xwait);
            /* start over... */
            _bt_freestack(stack);
            goto top;
        }
    }