diff --git a/src/box/request.cc b/src/box/request.cc index 3b0e35cf03fa5c59d5b0a6db029cd0c2e6a3fc4f..307232777e032d68013b614a1c104680a865eeb9 100644 --- a/src/box/request.cc +++ b/src/box/request.cc @@ -81,9 +81,7 @@ execute_update(struct request *request, struct port *port) access_check_space(space, PRIV_W); /* Try to find the tuple by unique key. */ - Index *pk = index_find(space, request->index_id); - if (!pk->key_def->is_unique) - tnt_raise(ClientError, ER_MORE_THAN_ONE_TUPLE); + Index *pk = index_find_unique(space, request->index_id); const char *key = request->key; uint32_t part_count = mp_decode_array(&key); primary_key_validate(pk->key_def, key, part_count); @@ -123,7 +121,7 @@ execute_upsert(struct request *request, struct port * /* port */) struct txn *txn = txn_begin_stmt(request, space); access_check_space(space, PRIV_W); - Index *pk = index_find(space, 0); + Index *pk = index_find_unique(space, request->index_id); /* Try to find the tuple by primary key. */ const char *key = request->key; uint32_t part_count = mp_decode_array(&key); @@ -168,9 +166,7 @@ execute_delete(struct request *request, struct port *port) access_check_space(space, PRIV_W); /* Try to find the tuple by unique key. */ - Index *pk = index_find(space, request->index_id); - if (!pk->key_def->is_unique) - tnt_raise(ClientError, ER_MORE_THAN_ONE_TUPLE); + Index *pk = index_find_unique(space, request->index_id); const char *key = request->key; uint32_t part_count = mp_decode_array(&key); primary_key_validate(pk->key_def, key, part_count); diff --git a/src/box/space.h b/src/box/space.h index 71b5ad47b63d01dd6756ab00f261f7421b58d7ff..e3a59fd7d9c8b1b74f32d9547e4a1cc1dc0805ee 100644 --- a/src/box/space.h +++ b/src/box/space.h @@ -176,6 +176,15 @@ index_find(struct space *space, uint32_t index_id) return index; } +static inline Index * +index_find_unique(struct space *space, uint32_t index_id) +{ + Index *index = index_find(space, index_id); + if (!index->key_def->is_unique) + tnt_raise(ClientError, ER_MORE_THAN_ONE_TUPLE); + return index; +} + extern "C" void space_run_triggers(struct space *space, bool yesno);