diff --git a/db/indices.c b/db/indices.c index 6332f3dca9..fe6114323f 100644 --- a/db/indices.c +++ b/db/indices.c @@ -514,13 +514,15 @@ int add_record_indices(struct ireq *iq, void *trans, blob_buffer_t *blobs, goto done; } else if (rc != 0) { *ixfailnum = ixnum; - /* If following changes, update OSQL_INSREC in osqlcomm.c */ - *opfailcode = OP_FAILED_UNIQ; /* really? */ - - // If this transaction has already added this key and adding this key again - // violates a duplicate key constraint, then this txn is uncommittable. - if (dup_txn_insert == 1) { - iq->dup_key_insert = 1; + if (rc == IX_DUP) { + *opfailcode = OP_FAILED_UNIQ; + // If this transaction has already added this key and adding this key again + // violates a duplicate key constraint, then this txn is uncommittable. + if (dup_txn_insert) { + iq->dup_key_insert = 1; + } + } else { + *opfailcode = OP_FAILED_INTERNAL; } ERR(rc, "add error", 0); diff --git a/db/osqlblockproc.c b/db/osqlblockproc.c index 42b7d30383..ad4092fe6d 100644 --- a/db/osqlblockproc.c +++ b/db/osqlblockproc.c @@ -1181,6 +1181,7 @@ static int apply_changes(struct ireq *iq, blocksql_tran_t *tran, void *iq_tran, if (iq->vfy_idx_track) { hash_clear(iq->vfy_idx_hash); + iq->dup_key_insert = 0; } /* create a cursor */