[Tarantool-patches] [PATCH v1 10/10] sql: refactor vdbe.c

Mergen Imeev imeevma at tarantool.org
Sat Feb 13 18:26:20 MSK 2021


On Tue, Feb 09, 2021 at 12:41:15PM +0300, Timur Safin wrote:
> 
> 
> : From: imeevma at tarantool.org <imeevma at 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
> 


More information about the Tarantool-patches mailing list