From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Thu, 9 Aug 2018 23:26:16 +0300 From: Konstantin Osipov Subject: Re: [RFC PATCH 08/23] vinyl: check key uniqueness before modifying tx write set Message-ID: <20180809202616.GB16449@chai> References: <34aef16e5a3dfab28c9d7e9edbd7a66d91279388.1531065648.git.vdavydov.dev@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <34aef16e5a3dfab28c9d7e9edbd7a66d91279388.1531065648.git.vdavydov.dev@gmail.com> To: Vladimir Davydov Cc: tarantool-patches@freelists.org List-ID: * Vladimir Davydov [18/07/08 22:52]: > + if (found != NULL && vy_tuple_compare(stmt, found, > + lsm->pk->key_def) == 0) { > + /* > + * If the old and new tuples are the same in > + * terms of the primary key definition, the > + * statement doesn't modify the secondary key > + * and so there's actually no conflict. > + */ > + tuple_unref(found); > + return 0; > + } In memtx, we pass old_tuple in txn_stmt around so that we can check that found == old_tuple and ignore the duplicate (please take a look at replace_check_dup). Why not do the same here, it would save us a compare? > + > + /* > + * For secondary indexes, uniqueness must be checked on both > + * INSERT and REPLACE. > + */ > + for (uint32_t i = 1; i < space->index_count; i++) { > + struct vy_lsm *lsm = vy_lsm(space->index[i]); > + if (vy_check_is_unique_secondary(env, tx, rv, space_name(space), > + index_name_by_id(space, i), > + lsm, stmt) != 0) > + return -1; > + } > + return 0; This code calls vy_get(), which in turns makes an unnecessary lookup in the primary key. -- Konstantin Osipov, Moscow, Russia, +7 903 626 22 32 http://tarantool.io - www.twitter.com/kostja_osipov