Skip to content
Snippets Groups Projects
Commit f62dbb18 authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

upsert: post-merge fixes

Extract index_find() logic into space.h
parent 97b50958
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment