Tarantool development patches archive
 help / color / mirror / Atom feed
From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Timur Safin <tsafin@tarantool.org>
Cc: s.ostanevich@corp.mail.ru, tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v1 10/10] sql: refactor vdbe.c
Date: Sat, 13 Feb 2021 18:26:20 +0300	[thread overview]
Message-ID: <20210213152620.GB110441@tarantool.org> (raw)
In-Reply-To: <047f01d6fec7$b5a90bb0$20fb2310$@tarantool.org>

On Tue, Feb 09, 2021 at 12:41:15PM +0300, Timur Safin wrote:
> 
> 
> : From: imeevma@tarantool.org <imeevma@tarantool.org>
> : Subject: [PATCH v1 10/10] sql: refactor vdbe.c
> : 
> : ---
> :  src/box/sql/vdbe.c | 453 +++++++++++++++++++++------------------------
> :  1 file changed, 206 insertions(+), 247 deletions(-)
> : 
> : diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
> : index 1707c216e..7d4a0b297 100644
> : --- a/src/box/sql/vdbe.c
> : +++ b/src/box/sql/vdbe.c
> : @@ -311,17 +311,17 @@ mem_apply_numeric_type(struct Mem *record)
> :  static int
> :  mem_apply_type(struct Mem *record, enum field_type type)
> :  {
> : -	if ((record->flags & MEM_Null) != 0)
> : +	if (mem_is_null(record))
> :  		return 0;
> :  	assert(type < field_type_MAX);
> :  	switch (type) {
> :  	case FIELD_TYPE_INTEGER:
> :  	case FIELD_TYPE_UNSIGNED:
> : -		if ((record->flags & (MEM_Bool | MEM_Blob)) != 0)
> : +		if (mem_is_bool(record) || mem_is_binary(record))
> :  			return -1;
> : -		if ((record->flags & MEM_UInt) == MEM_UInt)
> : +		if (mem_is_pos_int(record))
> 
> Is it actually only about positive integers, and not (un)signed 
> integers in general? Why it's called mem_is_pos_int? Not mem_is_uint?
> 
For positive integer it is true that mem_is_uint() is actually better, however
I decided to left it as mem_is_pos_int() so it would be named in the same style
as mem_is_neg_int(). I mean, both named to this way to show that they checks
mem_type defined by implementation. The mem_is_neg_int() function is actually
checks that MEM is negative integer, not just signed integer. The MEM_Int type
is similar to MP_INT which allows only negative integers.

I wonder if it is possible to make VDBE only work with functions that check only
the field type? I mean mem_is_integer(), mem_is_unsigned(), mem_is_scalar() and
so on. In this case, we don't need implementation-defined MEM type checking
functions. I cannot say yet if this is possible.

> : @@ -337,29 +337,29 @@ mem_apply_type(struct Mem *record, enum field_type
> : type)
> :  			}
> :  			return 0;
> :  		}
> : -		if ((record->flags & MEM_Str) != 0) {
> : +		if (mem_is_string(record)) {
> :  			bool is_neg;
> :  			int64_t i;
> :  			if (sql_atoi64(record->z, &i, &is_neg, record->n) != 0)
> :  				return -1;
> :  			mem_set_int(record, i, is_neg);
> :  		}
> : -		if ((record->flags & MEM_Int) == MEM_Int) {
> : +		if (mem_is_neg_int(record)) {
> 
> The same question - why not mem_is_signed_int? Or simply mem_is_int?
> 
Answered above.

> : @@ -442,12 +432,12 @@ mem_is_type_compatible(struct Mem *mem, enum
> : field_type type)
> :  static int
> :  mem_convert_to_double(struct Mem *mem)
> :  {
> : -	if ((mem->flags & MEM_Real) != 0)
> : +	if (mem_is_double(mem))
> :  		return 0;
> : -	if ((mem->flags & (MEM_Int | MEM_UInt)) == 0)
> : +	if (!mem_is_integer(mem))
> 
> Oh, I see there is already mem_is_integer, thus subtypes better to be 
> Explicitly named mem_is_unsigned_int and mem_is_signed_int (not pos/neg)
> 
Answered above.

> 
> :  		return -1;
> :  	double d;
> : -	if ((mem->flags & MEM_Int) != 0)
> : +	if (mem_is_neg_int(mem))
> :  		d = (double)mem->u.i;
> :  	else
> :  		d = (double)mem->u.u;
> 
> Timur
> 

  parent reply	other threads:[~2021-02-13 15:26 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-01  8:14 [Tarantool-patches] [PATCH v1 00/10] Encapsulate MEM type changing and checking Mergen Imeev via Tarantool-patches
2021-02-01  8:14 ` [Tarantool-patches] [PATCH v1 01/10] sql: introduce mem_set_*() functions Mergen Imeev via Tarantool-patches
2021-02-01  8:14 ` [Tarantool-patches] [PATCH v1 02/10] sql: Initialize MEM in sqlVdbeAllocUnpackedRecord() Mergen Imeev via Tarantool-patches
2021-02-01  8:14 ` [Tarantool-patches] [PATCH v1 03/10] sql: introduce mem_is_*() functions Mergen Imeev via Tarantool-patches
2021-02-01  8:14 ` [Tarantool-patches] [PATCH v1 04/10] sql: introduce mem_convert_to_binary() Mergen Imeev via Tarantool-patches
2021-02-01  8:14 ` [Tarantool-patches] [PATCH v1 05/10] sql: refactor vdbesort.c Mergen Imeev via Tarantool-patches
2021-02-01  8:15 ` [Tarantool-patches] [PATCH v1 06/10] sql: refactor sql/func.c Mergen Imeev via Tarantool-patches
2021-02-01  8:15 ` [Tarantool-patches] [PATCH v1 07/10] sql: refactor vdbetrace.c Mergen Imeev via Tarantool-patches
2021-02-01  8:15 ` [Tarantool-patches] [PATCH v1 08/10] sql: refactor vdbeapi.c Mergen Imeev via Tarantool-patches
2021-02-01  8:15 ` [Tarantool-patches] [PATCH v1 09/10] sql: refactor vdbeaux.c Mergen Imeev via Tarantool-patches
2021-02-09  9:51   ` [Tarantool-patches] FW: " Timur Safin via Tarantool-patches
2021-02-13 15:33     ` Mergen Imeev via Tarantool-patches
2021-02-28 17:35     ` Vladislav Shpilevoy via Tarantool-patches
2021-02-01  8:15 ` [Tarantool-patches] [PATCH v1 10/10] sql: refactor vdbe.c Mergen Imeev via Tarantool-patches
     [not found]   ` <047f01d6fec7$b5a90bb0$20fb2310$@tarantool.org>
2021-02-13 15:26     ` Mergen Imeev via Tarantool-patches [this message]
2021-02-09  9:36 ` [Tarantool-patches] [PATCH v1 00/10] Encapsulate MEM type changing and checking Timur Safin via Tarantool-patches
2021-02-13 15:13   ` Mergen Imeev 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=20210213152620.GB110441@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=s.ostanevich@corp.mail.ru \
    --cc=tsafin@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v1 10/10] sql: refactor vdbe.c' \
    /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