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 149E16EC55; Tue, 13 Jul 2021 00:06:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 149E16EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626123966; bh=ZXYCiydZlv64Znb1/P8+RwV3daal1dkWsadftlp18j8=; 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=KT0Uk3ZTXWnKOA73bZlGmiAVFrcVq//ymhE5q4CRMS+J2hhAdVrISOsTBPgQ6vNpH kU8NTnu+DQQ0p54O/5zQssBN9CdmBnCHRE4+Lb+Y67IrERgMO8JIrcAQlcejvTKhuB jMaaHuQGamYqkS58GoeptsBeHa0F/u5wsDvy7KqI= 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 05AF46EC55 for ; Tue, 13 Jul 2021 00:06:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 05AF46EC55 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1m337s-0007BD-4P; Tue, 13 Jul 2021 00:06:04 +0300 To: Mergen Imeev Cc: tarantool-patches@dev.tarantool.org References: <20210711175110.GA99369@tarantool.org> Message-ID: Date: Mon, 12 Jul 2021 23:06:03 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210711175110.GA99369@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD97BB0EF39AD2B33D5F2EB549EE938DAF5BD6C597CA890F198182A05F5380850408C1A11D0BE7776E0ED88819D2E824E4F074905CCCEE0EE94FF887870AEEAEE28 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D6964C9E324ABA58EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006377A06FA5CCF78F9BC8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8D4E22901EB4968E91966C8D0A811A5E8117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD186FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6A45692FFBBD75A6A089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5908512608ED1AB01171E9285A9A1002D7B6354D828F99DDBD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA753753CEE10E4ED4A7410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34682FD2D2951524C5C9A9973C083C473AE34A320619BD6C27C89116DB7A045F0404EC25DC46C9CAB01D7E09C32AA3244C5EF6845D4759F4D3853B7D274E2CEBDB51E887DA02A9F7BF729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojAZDAgpmGsvbrBAI9O6/SGA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DEF98ED14B3241FCC283306D5AEA6B6493841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 3/4] sql: introduce mem_cmp_scalar() 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" Hi! Thanks for the fixes! >>> +static inline enum mem_class >>> +mem_type_class(enum mem_type type) >>> +{ >>> + switch (type) { >>> + case MEM_TYPE_NULL: >>> + return MEM_CLASS_NULL; >>> + case MEM_TYPE_UINT: >>> + case MEM_TYPE_INT: >>> + case MEM_TYPE_DOUBLE: >>> + return MEM_CLASS_NUMBER; >>> + case MEM_TYPE_STR: >>> + return MEM_CLASS_STR; >>> + case MEM_TYPE_BIN: >>> + return MEM_CLASS_BIN; >>> + case MEM_TYPE_BOOL: >>> + return MEM_CLASS_BOOL; >>> + case MEM_TYPE_UUID: >>> + return MEM_CLASS_UUID; >> >> 3. It might work faster without branching if done like >> 'static enum mp_class mp_classes[]' - would allow to take >> the class for any type as simple as an array access >> operation. > This cannot be done directly in current design since value in enum mem_type are > not sequential numbers. However, this can be done using something like this: Ok, I see now. This is because I asked to make them bit fields before, shame on me. There is another option - use `32 - bit_ctz_u32()` to get a number from [1, 13] range and use it as an index in a small array. The problem here is that this is a bit crazy and I can't be sure if it works faster than this switch-case on all platforms. Hence, lets leave it as is now then. > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c > index 32d02d96e..220e8b269 100644 > --- a/src/box/sql/vdbe.c > +++ b/src/box/sql/vdbe.c > @@ -1828,7 +1828,7 @@ case OP_Compare: { > assert(i < (int)def->part_count); > struct coll *coll = def->parts[i].coll; > bool is_rev = def->parts[i].sort_order == SORT_ORDER_DESC; > - iCompare = sqlMemCompare(&aMem[p1+idx], &aMem[p2+idx], coll); > + mem_cmp_scalar(&aMem[p1+idx], &aMem[p2+idx], &iCompare, coll); Why don't you check the result here? AFAIU, previously sqlMemCompare() never returned something undefined. Now iCompare might be left garbage leading to unstable behaviour. The same below. > if (iCompare) { > if (is_rev) > iCompare = -iCompare; > diff --git a/src/box/sql/where.c b/src/box/sql/where.c > index e5f35fbf8..dadc6d4a2 100644 > --- a/src/box/sql/where.c > +++ b/src/box/sql/where.c > @@ -1272,12 +1272,14 @@ whereRangeSkipScanEst(Parse * pParse, /* Parsing & code generating context */ > rc = sql_stat4_column(db, samples[i].sample_key, nEq, > &pVal); > if (rc == 0 && p1 != NULL) { > - int res = sqlMemCompare(p1, pVal, coll); > + int res; > + mem_cmp_scalar(p1, pVal, &res, coll); > if (res >= 0) > nLower++; > } > if (rc == 0 && p2 != NULL) { > - int res = sqlMemCompare(p2, pVal, coll); > + int res; > + mem_cmp_scalar(p2, pVal, &res, coll); > if (res >= 0) > nUpper++; > }