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 8EDD96EC58; Tue, 3 Aug 2021 15:59:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8EDD96EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627995591; bh=M2fpQsEzpsdelSaLEROYdlrNNtl8hPTj4GMK+fP5ZDg=; h=To:Cc:References:In-Reply-To:Date:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=jSteu04tciZdKO+8gj8IHbzmVFTYPI8ERHM7Yu4fGc4ZcQuUUao/V1DrAS1B0qGJ1 +px2NddC4F2iPt1DhFmlRldz8wM4Pd1ZybLodjiRziuo1ya7iN6eVf/T2z524TOlVR 2Vuh3kbR9uzECx20ZrIM6oBmfBsW0fdAnSb/wZZs= Received: from smtp59.i.mail.ru (smtp59.i.mail.ru [217.69.128.39]) (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 039996EC58 for ; Tue, 3 Aug 2021 15:59:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 039996EC58 Received: by smtp59.i.mail.ru with esmtpa (envelope-from ) id 1mAu1L-0006co-PU; Tue, 03 Aug 2021 15:59:48 +0300 To: "'Serge Petrenko'" , , Cc: References: <726aea88a704e2eb11257d5de49fd03818a573ed.1627864075.git.tsafin@tarantool.org> <588cd867-94bf-f470-c99a-593ae589247b@tarantool.org> In-Reply-To: <588cd867-94bf-f470-c99a-593ae589247b@tarantool.org> Date: Tue, 3 Aug 2021 15:59:44 +0300 Message-ID: <0e7001d78867$6eb23220$4c169660$@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQKU0cwvkTasfMq0ugtyZVj5je82UAMXJz2rAn8mP++punUpUA== Content-Language: ru X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C33D83595CA30D6DC5179D1C9A908C47E5182A05F5380850405E855C7C827A68FA03366E25234FAD81D47000BECEF4EF2B0900660E2518563C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7FEAC828D2BF6EC3CEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637103BD9D8542B9C568638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D89508D9E8157F773C85A5503CF30C8114117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC60CDF180582EB8FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10FF04B652EEC242312D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE1B544F03EFBC4D57C43C4D2AE8146675D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE3AC7A5202D916A59B6136E347CC761E07C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637A7EFCB0EB5ACB161EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B5055E566A997EBE30270C2B0C63846EF7F5 X-C1DE0DAB: 0D63561A33F958A5ECF45E3E63362637B5DCC45C41B5B9AEEF830F5447CB01CBD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA751B940EDA0DFB0535410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34060C3C6DE316ECE48155C023B7E728F00E29D9115EE7100E81E64A21CB6B43487E4985A6BB051B5B1D7E09C32AA3244C21A84B94A88E9CDB686FF270BFC0F2D1408A6A02710B7304927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj9N286KAyvN5b9EoyNVGwoA== X-Mailru-Sender: 6CA451E36783D721CBEA96CEA26D325D040B9F4AAF91919B979F3AF6AA262F0BB7CBEF92542CD7C82F97C478340294DCC77752E0C033A69E0F0C7111264B8915FF1320A92A5534336C18EFA0BB12DBB0 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v3 6/9] box, datetime: datetime comparison for indices 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: Timur Safin via Tarantool-patches Reply-To: Timur Safin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" > From: Serge Petrenko > Subject: Re: [Tarantool-patches] [PATCH v3 6/9] box, datetime: = datetime > comparison for indices >=20 >=20 >=20 > 02.08.2021 03:41, Timur Safin via Tarantool-patches = =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > > * storage hints implemented for datetime_t values; > > * proper comparison for indices of datetime type. > > > > Part of #5941 > > Part of #5946 >=20 > Hi! Thanks for the patch! >=20 > Please find 2 comments below. >=20 ... > > @@ -1538,6 +1540,21 @@ func_index_compare_with_key(struct tuple = *tuple, > hint_t tuple_hint, > > #define HINT_VALUE_DOUBLE_MAX (exp2(HINT_VALUE_BITS - 1) - 1) > > #define HINT_VALUE_DOUBLE_MIN (-exp2(HINT_VALUE_BITS - 1)) > > > > +/** > > + * We need to squeeze 64 bits of seconds and 32 bits of nanoseconds > > + * into 60 bits of hint value. The idea is to represent wide enough > > + * years range, and leave the rest of bits occupied from = nanoseconds > part: > > + * - 36 bits is enough for time range of [208BC..4147] > > + * - for nanoseconds there is left 24 bits, which are MSB part of > > + * 32-bit value > > + */ > > +#define HINT_VALUE_SECS_BITS 36 > > +#define HINT_VALUE_NSEC_BITS (HINT_VALUE_BITS - = HINT_VALUE_SECS_BITS) > > +#define HINT_VALUE_SECS_MAX ((1LL << HINT_VALUE_SECS_BITS) - 1) > > +#define HINT_VALUE_SECS_MIN (-(1LL << HINT_VALUE_SECS_BITS)) > > +#define HINT_VALUE_NSEC_SHIFT (sizeof(int) * CHAR_BIT - > HINT_VALUE_NSEC_BITS) > > +#define HINT_VALUE_NSEC_MAX ((1ULL << HINT_VALUE_NSEC_BITS) - 1) > > + > > /* > > * HINT_CLASS_BITS should be big enough to store any mp_class = value. > > * Note, ((1 << HINT_CLASS_BITS) - 1) is reserved for HINT_NONE. > > @@ -1630,6 +1647,24 @@ hint_uuid_raw(const char *data) > > return hint_create(MP_CLASS_UUID, val); > > } > > > > +static inline hint_t > > +hint_datetime(struct datetime_t *date) > > +{ > > + /* > > + * Use at most HINT_VALUE_SECS_BITS from datetime > > + * seconds field as a hint value, and at MSB part > > + * of HINT_VALUE_NSEC_BITS from nanoseconds. > > + */ > > + int64_t secs =3D date->secs; > > + int32_t nsec =3D date->nsec; > > + uint64_t val =3D secs <=3D HINT_VALUE_SECS_MIN ? 0 : > > + secs - HINT_VALUE_SECS_MIN; > > + val &=3D HINT_VALUE_SECS_MAX; > > + val <<=3D HINT_VALUE_NSEC_BITS; > > + val |=3D (nsec >> HINT_VALUE_NSEC_SHIFT) & HINT_VALUE_NSEC_MAX; > > + return hint_create(MP_CLASS_DATETIME, val); > > +} > > + > I like the idea with having hints for some "near" dates. >=20 > You just need to assign the same HINT_VALUE_MAX hint to every datetime = value > with date->secs >=3D HINT_VALUE_SECS_MAX. Otherwise the comparison = would > make mistakes (judging by hint values only) for such far away dates. Yes, thanks for the note, will make sure that values which exceed = selected 36-bit will stick to the maximum value. >=20 > > static inline uint64_t > > hint_str_raw(const char *s, uint32_t len) > > { > > @@ -1812,6 +1858,11 @@ field_hint_scalar(const char *field, struct = coll > *coll) > > } > > case MP_UUID: > > return hint_uuid_raw(field); > > + case MP_DATETIME: > > + { > > + struct datetime_t date; > > + return hint_datetime(datetime_unpack(&field, len, &date)); > > + } >=20 > But you don't allow datetime in SCALAR fields, as I see in the = previous > commit. > So you don't need to account for datetime in scalar hints. That's bug - every type is scalar type, unless it's collection (map or = array) so datetime should be considered as scalar. That was oversight if not.=20 Thanks! >=20 > > default: > > unreachable(); > > } =20 > -- > Serge Petrenko Thanks, Timur