[tarantool-patches] [PATCH 08/10] sql: use secondary indexes to process OP_Delete

Nikita Pettik korablev at tarantool.org
Sun Aug 12 17:13:04 MSK 2018


Before this patch OP_Delete used only primary index to delete entry.
Since it already operates on cursor, which in turn can be open on
secondary index, lets pass index id to internal routine to use it.
This is required in order to remove duplicates from secondary indexes
while processing INSERT/UPDATE OR REPLACE statement.
---
 src/box/sql.c              | 17 +++++------------
 src/box/sql/tarantoolInt.h | 16 +++++++++++++++-
 src/box/sql/vdbe.c         |  2 +-
 3 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/box/sql.c b/src/box/sql.c
index a0aced27b..de617c8b0 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -542,23 +542,15 @@ int tarantoolSqlite3Delete(BtCursor *pCur, u8 flags)
 				&key_size);
 	if (key == NULL)
 		return SQL_TARANTOOL_DELETE_FAIL;
-
-	rc = sql_delete_by_key(pCur->space, key, key_size);
+	rc = sql_delete_by_key(pCur->space, pCur->index->def->iid, key,
+			       key_size);
 
 	return rc == 0 ? SQLITE_OK : SQL_TARANTOOL_DELETE_FAIL;
 }
 
-/**
- * Delete entry from space by its key.
- *
- * @param space Space which contains record to be deleted.
- * @param key Key of record to be deleted.
- * @param key_size Size of key.
- *
- * @retval SQLITE_OK on success, SQL_TARANTOOL_DELETE_FAIL otherwise.
- */
 int
-sql_delete_by_key(struct space *space, char *key, uint32_t key_size)
+sql_delete_by_key(struct space *space, uint32_t iid, char *key,
+		  uint32_t key_size)
 {
 	struct request request;
 	struct tuple *unused;
@@ -567,6 +559,7 @@ sql_delete_by_key(struct space *space, char *key, uint32_t key_size)
 	request.key = key;
 	request.key_end = key + key_size;
 	request.space_id = space->def->id;
+	request.index_id = iid;
 	int rc = box_process_rw(&request, space, &unused);
 
 	return rc == 0 ? SQLITE_OK : SQL_TARANTOOL_DELETE_FAIL;
diff --git a/src/box/sql/tarantoolInt.h b/src/box/sql/tarantoolInt.h
index 94517f608..31dc1b1bc 100644
--- a/src/box/sql/tarantoolInt.h
+++ b/src/box/sql/tarantoolInt.h
@@ -66,8 +66,22 @@ int tarantoolSqlite3Insert(struct space *space, const char *tuple,
 int tarantoolSqlite3Replace(struct space *space, const char *tuple,
 			    const char *tuple_end);
 int tarantoolSqlite3Delete(BtCursor * pCur, u8 flags);
+
+/**
+ * Delete entry from space by its key.
+ *
+ * @param space Space which contains record to be deleted.
+ * @param iid Index id.
+ * @param key Key of record to be deleted.
+ * @param key_size Size of key.
+ *
+ * @retval SQLITE_OK on success, SQL_TARANTOOL_DELETE_FAIL
+ *         otherwise.
+ */
 int
-sql_delete_by_key(struct space *space, char *key, uint32_t key_size);
+sql_delete_by_key(struct space *space, uint32_t iid, char *key,
+		  uint32_t key_size);
+
 int tarantoolSqlite3ClearTable(struct space *space);
 
 /**
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index dc5146f81..e1eaf91a4 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -4344,7 +4344,7 @@ case OP_SDelete: {
 	struct space *space = space_by_id(pOp->p1);
 	assert(space != NULL);
 	assert(space_is_system(space));
-	rc = sql_delete_by_key(space, pIn2->z, pIn2->n);
+	rc = sql_delete_by_key(space, 0, pIn2->z, pIn2->n);
 	if (rc)
 		goto abort_due_to_error;
 	if (pOp->p5 & OPFLAG_NCHANGE)
-- 
2.15.1





More information about the Tarantool-patches mailing list