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 C48336EC40; Tue, 17 Aug 2021 15:18:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C48336EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629202690; bh=hNoDAjswuHAp0ovJeSzyZqOnJRQsUvm4z0grhdVGp/w=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=GjTLZaiqwN6qzpByn+E8pzfe/j2/Vozm7us87rVsh9Ytiv78S8wcPkU93mtOuGh8B 6pV350U1GE6Ty9XqwEJtvHraiMH9r8uhs5KUufVeW7thvn7g86qbEU9EEqcy5H/d5c x1Q6DkGXv5tj+v5+HDwnJ1MwJttYv4Wdx+qQhePg= Received: from smtp44.i.mail.ru (smtp44.i.mail.ru [94.100.177.104]) (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 8F5F56EC5B for ; Tue, 17 Aug 2021 15:16:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8F5F56EC5B Received: by smtp44.i.mail.ru with esmtpa (envelope-from ) id 1mFy0s-0001YP-F4; Tue, 17 Aug 2021 15:16:14 +0300 To: Timur Safin References: <906cfac8b66b70eb982b5c7fe4878da39712a305.1629071531.git.tsafin@tarantool.org> Message-ID: <7baf64ec-6033-8c96-c57e-eb3394ec0b07@tarantool.org> Date: Tue, 17 Aug 2021 15:16:14 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <906cfac8b66b70eb982b5c7fe4878da39712a305.1629071531.git.tsafin@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9BCE6B93DE0C6C3914462CDB1732D383C182A05F5380850403246F727FF7FC79234D7ADC286110C15C53E19D70CD3465C68B95B0DFAA8DCFE X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7747FD4AFDBA6C67AEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637C218CA8E848E3B7A8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D85117C796A92387E4554536C47FF38D97117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD182CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B67ECBC18655D52CDF089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5494384AD499DA059D9B7450A69B5A8AB0E2A093F34176C67D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7567C209D01CC1E34B410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34A150564C13026C18C9E256896A1C63506A446B7A10B64B2CD3ACA9BB3A3766BCF51ED4089A90FCF01D7E09C32AA3244C861CFD2F7DC51F105F6405EC566D7BD37101BF96129E401183B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojuRQ/H5n28too5eSJTBsy9Q== X-Mailru-Sender: 3B9A0136629DC9125D61937A2360A446536073F9A9F7FACECD241928CD4057B83DE6208C9299893F424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v5 5/8] 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: Serge Petrenko via Tarantool-patches Reply-To: Serge Petrenko Cc: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 16.08.2021 02:59, Timur Safin via Tarantool-patches пишет: > * storage hints implemented for datetime_t values; > * proper comparison for indices of datetime type. > > Part of #5941 > Part of #5946 Please, add a docbot request stating that it's now possible to store datetime values in spaces and create indexed datetime fields. > --- > src/box/field_def.c | 18 ++++++++ > src/box/field_def.h | 3 ++ > src/box/memtx_space.c | 3 +- > src/box/tuple_compare.cc | 57 ++++++++++++++++++++++++++ > src/box/vinyl.c | 3 +- > test/engine/datetime.result | 77 +++++++++++++++++++++++++++++++++++ > test/engine/datetime.test.lua | 35 ++++++++++++++++ > 7 files changed, 192 insertions(+), 4 deletions(-) > create mode 100644 test/engine/datetime.result > create mode 100644 test/engine/datetime.test.lua > > diff --git a/src/box/field_def.c b/src/box/field_def.c > index 2682a42ee..97033d0bb 100644 > --- a/src/box/field_def.c > +++ b/src/box/field_def.c > @@ -194,3 +194,21 @@ field_type_by_name(const char *name, size_t len) > return FIELD_TYPE_ANY; > return field_type_MAX; > } > + > +const bool field_type_index_allowed[] = > + { > + /* [FIELD_TYPE_ANY] = */ false, > + /* [FIELD_TYPE_UNSIGNED] = */ true, > + /* [FIELD_TYPE_STRING] = */ true, > + /* [FIELD_TYPE_NUMBER] = */ true, > + /* [FIELD_TYPE_DOUBLE] = */ true, > + /* [FIELD_TYPE_INTEGER] = */ true, > + /* [FIELD_TYPE_BOOLEAN] = */ true, > + /* [FIELD_TYPE_VARBINARY]= */ true, > + /* [FIELD_TYPE_SCALAR] = */ true, > + /* [FIELD_TYPE_DECIMAL] = */ true, > + /* [FIELD_TYPE_UUID] = */ true, > + /* [FIELD_TYPE_ARRAY] = */ false, > + /* [FIELD_TYPE_MAP] = */ false, > + /* [FIELD_TYPE_DATETIME] = */ true, > +}; You wouldn't need that array if you moved FIELD_TYPE_DATETIME above FIELD_TYPE_ARRAY in the previous commit. Please, do so. > diff --git a/src/box/field_def.h b/src/box/field_def.h > index 120b2a93d..bd02418df 100644 > --- a/src/box/field_def.h > +++ b/src/box/field_def.h > @@ -120,6 +120,9 @@ extern const uint32_t field_ext_type[]; > extern const struct opt_def field_def_reg[]; > extern const struct field_def field_def_default; > > +/** helper table for checking allowed indices for types */ > +extern const bool field_type_index_allowed[]; > + > /** > * @brief Field definition > * Contains information about of one tuple field. > diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c > index b71318d24..1ab16122e 100644 > --- a/src/box/memtx_space.c > +++ b/src/box/memtx_space.c > @@ -748,8 +748,7 @@ memtx_space_check_index_def(struct space *space, struct index_def *index_def) > /* Check that there are no ANY, ARRAY, MAP parts */ > for (uint32_t i = 0; i < key_def->part_count; i++) { > struct key_part *part = &key_def->parts[i]; > - if (part->type <= FIELD_TYPE_ANY || > - part->type >= FIELD_TYPE_ARRAY) { > + if (!field_type_index_allowed[part->type]) { > diag_set(ClientError, ER_MODIFY_INDEX, > index_def->name, space_name(space), > tt_sprintf("field type '%s' is not supported", > diff --git a/src/box/tuple_compare.cc b/src/box/tuple_compare.cc > index 9a69f2a72..110017853 100644 > --- a/src/box/tuple_compare.cc > +++ b/src/box/tuple_compare.cc > @@ -538,6 +538,8 @@ tuple_compare_field_with_type(const char *field_a, enum mp_type a_type, > field_b, b_type); > case FIELD_TYPE_UUID: > return mp_compare_uuid(field_a, field_b); > + case FIELD_TYPE_DATETIME: > + return mp_compare_datetime(field_a, field_b); > default: > unreachable(); > return 0; > @@ -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) Am I missing something? n bits may store values from (-2^(n-1)) to 2^(n-1)-1 should be (1LL << (HINT_VALUE_SECS_BITS -1))  - 1 ? > +#define HINT_VALUE_SECS_MIN (-(1LL << HINT_VALUE_SECS_BITS)) should be #define HINT_VALUE_SECS_MIN (-(1LL << (HINT_VALUE_SECS_BITS - 1))) ? > +#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,25 @@ hint_uuid_raw(const char *data) > return hint_create(MP_CLASS_UUID, val); > } > > +static inline hint_t > +hint_datetime(struct datetime *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 = date->secs; > + int32_t nsec = date->nsec; > + uint64_t val = secs <= HINT_VALUE_SECS_MIN ? 0 : > + secs - HINT_VALUE_SECS_MIN; > + if (val >= HINT_VALUE_SECS_MAX) > + val = HINT_VALUE_SECS_MAX; > + val <<= HINT_VALUE_NSEC_BITS; > + val |= (nsec >> HINT_VALUE_NSEC_SHIFT) & HINT_VALUE_NSEC_MAX; > + return hint_create(MP_CLASS_DATETIME, val); > +} > + -- Serge Petrenko