From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Mergen Imeev <imeevma@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH v2 3/4] sql: introduce mem_cmp_scalar() Date: Mon, 12 Jul 2021 23:06:03 +0200 [thread overview] Message-ID: <c2ac86e9-61dd-99ad-e7b3-c8a7d5997c04@tarantool.org> (raw) In-Reply-To: <20210711175110.GA99369@tarantool.org> 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++; > }
next prev parent reply other threads:[~2021-07-12 21:06 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-10 14:33 [Tarantool-patches] [PATCH v2 0/4] Follow ups for uuid introduction Mergen Imeev via Tarantool-patches 2021-07-10 14:33 ` [Tarantool-patches] [PATCH v2 1/4] sql: introduce uuid to quote() Mergen Imeev via Tarantool-patches 2021-07-10 14:33 ` [Tarantool-patches] [PATCH v2 2/4] sql: allow to bind uuid values Mergen Imeev via Tarantool-patches 2021-07-10 14:33 ` [Tarantool-patches] [PATCH v2 3/4] sql: introduce mem_cmp_scalar() Mergen Imeev via Tarantool-patches 2021-07-11 15:03 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-11 17:51 ` Mergen Imeev via Tarantool-patches 2021-07-12 21:06 ` Vladislav Shpilevoy via Tarantool-patches [this message] 2021-07-13 8:04 ` Mergen Imeev via Tarantool-patches 2021-07-10 14:33 ` [Tarantool-patches] [PATCH v2 4/4] sql: introduce mem_cmp_msgpack() Mergen Imeev via Tarantool-patches 2021-07-11 15:05 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-11 17:59 ` Mergen Imeev via Tarantool-patches 2021-07-12 21:09 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-13 8:10 ` Mergen Imeev via Tarantool-patches 2021-07-13 20:39 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-14 6:51 ` Mergen Imeev via Tarantool-patches 2021-07-14 21:53 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-15 6:58 ` Mergen Imeev via Tarantool-patches 2021-07-15 20:44 ` [Tarantool-patches] [PATCH v2 0/4] Follow ups for uuid introduction Vladislav Shpilevoy via Tarantool-patches 2021-07-16 8:57 Mergen Imeev via Tarantool-patches 2021-07-16 8:57 ` [Tarantool-patches] [PATCH v2 3/4] sql: introduce mem_cmp_scalar() Mergen Imeev via Tarantool-patches 2021-07-19 9:17 ` Timur Safin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=c2ac86e9-61dd-99ad-e7b3-c8a7d5997c04@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=imeevma@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 3/4] sql: introduce mem_cmp_scalar()' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox