From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id A5F7B281BC for ; Sun, 12 Aug 2018 10:13:25 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pZrpHWwQIAve for ; Sun, 12 Aug 2018 10:13:25 -0400 (EDT) Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [217.69.128.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 0E43F2807B for ; Sun, 12 Aug 2018 10:13:25 -0400 (EDT) From: Nikita Pettik Subject: [tarantool-patches] [PATCH 08/10] sql: use secondary indexes to process OP_Delete Date: Sun, 12 Aug 2018 17:13:04 +0300 Message-Id: <2cb98faa8403229595d38b55ca6c8bd790bd9c81.1534001739.git.korablev@tarantool.org> In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, Nikita Pettik 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