From 275863e71da36df0e2ab52b63d14d834ac399006 Mon Sep 17 00:00:00 2001
From: Sokolov Yura aka funny_falcon <funny.falcon@gmail.com>
Date: Mon, 27 Jul 2015 06:31:41 +0300
Subject: [PATCH] update and delete by secondary unique index

---
 src/box/request.cc | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/box/request.cc b/src/box/request.cc
index 719d76bdcd..57321ed88b 100644
--- a/src/box/request.cc
+++ b/src/box/request.cc
@@ -80,8 +80,10 @@ execute_update(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);
-	/* Try to find the tuple by primary key. */
+	/* 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);
 	const char *key = request->key;
 	uint32_t part_count = mp_decode_array(&key);
 	primary_key_validate(pk->key_def, key, part_count);
@@ -122,8 +124,10 @@ execute_delete(struct request *request, struct port *port)
 
 	access_check_space(space, PRIV_W);
 
-	/* Try to find tuple by primary key */
-	Index *pk = index_find(space, 0);
+	/* 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);
 	const char *key = request->key;
 	uint32_t part_count = mp_decode_array(&key);
 	primary_key_validate(pk->key_def, key, part_count);
-- 
GitLab