From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 117CB6EC58; Thu, 5 Aug 2021 01:25:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 117CB6EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628115953; bh=7p7F0KYypFB9j1EiRj8F5DaRrYRH+d4Btv/YCmc9nyY=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=dSl4ynigNgIr7CZw0uIiMhvfwP9PPGWvh2plb8OUMvVynB1mNfSSENzv4PCpggiSa vah/kIgy6nwood2p581A0xtLt2wgt869M64xEn9Igbn8HsSAralr2jVEwlOzScJz3c G1uhVc83+BZPnD2zXbyuetc8h3J0IcabVuZOvW+g= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 32F2F6EC58 for ; Thu, 5 Aug 2021 01:25:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 32F2F6EC58 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1mBPKg-0005tt-Fp; Thu, 05 Aug 2021 01:25:50 +0300 To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <8722fbfce0455e13c01672793f6a5075dc0fc458.1627504973.git.imeevma@gmail.com> Message-ID: <31aa2f05-09e9-ce24-5a46-894d3d23b8f7@tarantool.org> Date: Thu, 5 Aug 2021 00:25:49 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <8722fbfce0455e13c01672793f6a5075dc0fc458.1627504973.git.imeevma@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD941C43E597735A9C30A5AB0699C09BB51E5FD76225F0C99C3182A05F5380850407D0E7833EC2403082C812AEC3AC0EC9A22260F0707E6519687DEB6A2692FD5D7 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74E9055D3307A84CAEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006372FCE560095E3DFB88638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8E7DCCDFF1792736DD44181B684A3665E117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6A45692FFBBD75A6A089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505881C34328C8F5CEEC9F45E152C65B92E X-C1DE0DAB: 0D63561A33F958A50588D2121757A9915E5E20DAB3A674777BFE2DA0AA610C55D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D348B409C2D257583DFE5092ECF1D2303A081017C09656E2B2461967BCF397021E55CA2BF2F5D6D1EBE1D7E09C32AA3244CF51516F6365E4FEDE2EF6299A6BFE2E68894E9C85370243E729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojh4v93/7HD3XxO9wtidxOvw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DCB70CCB0DBE0123E1F99BFF5213CCB833841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 3/7] sql: rework OP_Seek* opcodes X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the patch! See 3 comments below. > diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h > index 47a940c56..5d1d7592e 100644 > --- a/src/box/sql/mem.h > +++ b/src/box/sql/mem.h > @@ -1028,3 +1028,20 @@ mpstream_encode_vdbe_mem(struct mpstream *stream, struct Mem *var); > char * > sql_vdbe_mem_encode_tuple(struct Mem *fields, uint32_t field_count, > uint32_t *tuple_size, struct region *region); > + > +static inline bool > +is_mem_num_min(const struct Mem *mem) > +{ > + return (mem->field_type == FIELD_TYPE_INTEGER && > + mem->type == MEM_TYPE_INT && mem->u.i == INT64_MIN) || > + (mem->field_type == FIELD_TYPE_UNSIGNED && > + mem->type == MEM_TYPE_UINT && mem->u.u == 0); > +} > + > +static inline bool > +is_mem_num_max(const struct Mem *mem) 1. Could you please name them to mem_is_num_min() and mem_is_num_max()? Also what if they are DOUBLE? Should't these functions be called then mem_is_int_min() and mem_is_int_max()? > +{ > + return (mem->field_type == FIELD_TYPE_INTEGER || > + mem->field_type == FIELD_TYPE_UNSIGNED) && > + mem->type == MEM_TYPE_UINT && mem->u.u == 0; > +} > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c > index 62f58def9..a69402720 100644 > --- a/src/box/sql/vdbe.c > +++ b/src/box/sql/vdbe.c > @@ -2577,6 +2526,62 @@ case OP_Close: { > * > * See also: Found, NotFound, SeekGt, SeekGe, SeekLe > */ > +case OP_SeekLT: { /* jump, in3 */ > + struct VdbeCursor *cur = p->apCsr[pOp->p1]; > +#ifdef SQL_DEBUG > + cur->seekOp = pOp->opcode; > +#endif > + cur->nullRow = 0; > + cur->uc.pCursor->iter_type = ITER_LT; > + > + uint32_t len = pOp->p4.i; > + assert(pOp->p4type == P4_INT32); > + assert(len <= cur->key_def->part_count); > + struct Mem *mems = &aMem[pOp->p3]; > + bool is_le = false; > + bool is_zero = false; > + for (uint32_t i = 0; i < len; ++i) { > + enum field_type type = cur->key_def->parts[i].type; > + struct Mem *mem = &mems[i]; > + if (mem_is_field_compatible(mem, type)) > + continue; > + if (!sql_type_is_numeric(type) || !mem_is_num(mem)) { > + diag_set(ClientError, ER_SQL_TYPE_MISMATCH, > + mem_str(mem), field_type_strs[type]); > + goto abort_due_to_error; > + } > + int cmp = mem_cast_implicit_number(mem, type); > + is_le = is_le || cmp > 0; > + /* > + * If number before cast were less than min possible for given > + * field type, than there is no point to use iterator since we > + * won't find anything. > + */ > + is_zero = is_zero || (is_mem_num_min(mem) && cmp < 0); 2. Do you really need this optimization? Seems like a very rare case. The same in the other places. Also it looks like a lot of code duplication. But I see why, and again I don't see a way to reuse all this code easily. > + } > + if (is_zero) { > + assert(pOp->p2 > 0); > + VdbeBranchTaken(1, 2); > + goto jump_to_p2; > + } <...> > +case OP_SeekLE: { /* jump, in3 */ <...> > + cur->nullRow = 0; > + bool is_eq = (cur->uc.pCursor->hints & OPFLAG_SEEKEQ) != 0; > + cur->uc.pCursor->iter_type = is_eq ? ITER_REQ : ITER_LE; > + assert(!is_eq || pOp[1].opcode == OP_IdxLT); > + > + uint32_t len = pOp->p4.i; > + assert(pOp->p4type == P4_INT32); > + assert(len <= cur->key_def->part_count); > + struct Mem *mems = &aMem[pOp->p3]; > + bool is_lt = false; > + bool is_zero = false; > + for (uint32_t i = 0; i < len; ++i) { > + enum field_type type = cur->key_def->parts[i].type; > + struct Mem *mem = &mems[i]; > + if (mem_is_field_compatible(mem, type)) > + continue; > + if (!sql_type_is_numeric(type) || !mem_is_num(mem)) { > + diag_set(ClientError, ER_SQL_TYPE_MISMATCH, > + mem_str(mem), field_type_strs[type]); > + goto abort_due_to_error; > } > - iKey = i; > - > - /* If the P3 value could not be converted into an integer without > - * loss of information, then special processing is required... > + int cmp = mem_cast_implicit_number(mem, type); > + is_lt = is_lt || cmp < 0; 3. You needed to find values <= mem. The mem during cast was turned into mem2 < mem, correct? Then you need to find values <= mem2. Otherwise you skip mem2 itself. Or am I mistaken somewhere? Similar questions to all the other usages of mem_cast_implicit_number for seeking.