Tarantool development patches archive
 help / color / mirror / Atom feed
From: Timur Safin via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: <imeevma@tarantool.org>
Cc: <tarantool-patches@dev.tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH v2 3/4] sql: introduce mem_cmp_scalar()
Date: Mon, 19 Jul 2021 12:17:01 +0300
Message-ID: <18a301d77c7e$d5a9af70$80fd0e50$@tarantool.org> (raw)
In-Reply-To: <c8c1c57e8637a5f4093aea687e826078010ece82.1626424203.git.imeevma@gmail.com>

LGTM, yup, it's much simpler now!

: From: imeevma@tarantool.org <imeevma@tarantool.org>
: Subject: [PATCH v2 3/4] sql: introduce mem_cmp_scalar()
: 
: This patch introduces the mem_cmp_scalar() function that compares two
: MEMs using SCALAR rules. MEMs must be scalars. Prior to this patch, there
: was a
: function that used SCALAR rules to compare two MEMs, but its design became
: overly complex as new types appeared.
: 
: Part of #6164


: @@ -2030,6 +2068,36 @@ mem_cmp_uuid(const struct Mem *a, const struct Mem
: *b, int *result)
:  	return 0;
:  }
: 
: +int
: +mem_cmp_scalar(const struct Mem *a, const struct Mem *b, int *result,
: +	       const struct coll *coll)
: +{
: +	enum mem_class class_a = mem_type_class(a->type);
: +	enum mem_class class_b = mem_type_class(b->type);
: +	if (class_a != class_b) {
: +		*result = class_a - class_b;
: +		return 0;
: +	}
: +	switch (class_a) {
: +	case MEM_CLASS_NULL:
: +		*result = 0;
: +		return 0;
: +	case MEM_CLASS_BOOL:
: +		return mem_cmp_bool(a, b, result);
: +	case MEM_CLASS_NUMBER:
: +		return mem_cmp_num(a, b, result);
: +	case MEM_CLASS_STR:
: +		return mem_cmp_str(a, b, result, coll);
: +	case MEM_CLASS_BIN:
: +		return mem_cmp_bin(a, b, result);
: +	case MEM_CLASS_UUID:
: +		return mem_cmp_uuid(a, b, result);
: +	default:
: +		unreachable();
: +	}
: +	return 0;
: +}
: +
:  /*
:   * Both *pMem1 and *pMem2 contain string values. Compare the two values
:   * using the collation sequence pColl. As usual, return a negative , zero
: @@ -2463,82 +2531,6 @@ sqlVdbeMemTooBig(Mem * p)
:  	return 0;
:  }
: 
: -/*
: - * Compare the values contained by the two memory cells, returning
: - * negative, zero or positive if pMem1 is less than, equal to, or greater
: - * than pMem2. Sorting order is NULL's first, followed by numbers (integers
: - * and reals) sorted numerically, followed by text ordered by the collating
: - * sequence pColl and finally blob's ordered by memcmp().
: - *
: - * Two NULL values are considered equal by this function.
: - */
: -int
: -sqlMemCompare(const Mem * pMem1, const Mem * pMem2, const struct coll *
: pColl)
: -{
: -	int res;
: -
: -	enum mem_type type1 = pMem1->type;
: -	enum mem_type type2 = pMem2->type;
: -
: -	/* If one value is NULL, it is less than the other. If both values
: -	 * are NULL, return 0.
: -	 */
: -	if (((type1 | type2) & MEM_TYPE_NULL) != 0)
: -		return (int)(type2 == MEM_TYPE_NULL) -
: -		       (int)(type1 == MEM_TYPE_NULL);
: -
: -	if (((type1 | type2) & MEM_TYPE_BOOL) != 0) {
: -		if ((type1 & type2 & MEM_TYPE_BOOL) != 0) {
: -			if (pMem1->u.b == pMem2->u.b)
: -				return 0;
: -			if (pMem1->u.b)
: -				return 1;
: -			return -1;
: -		}
: -		if (type2 == MEM_TYPE_BOOL)
: -			return +1;
: -		return -1;
: -	}
: -
: -	if (((type1 | type2) & MEM_TYPE_UUID) != 0) {
: -		if (mem_cmp_uuid(pMem1, pMem2, &res) == 0)
: -			return res;
: -		if (type1 != MEM_TYPE_UUID)
: -			return +1;
: -		return -1;
: -	}
: -
: -	/* At least one of the two values is a number
: -	 */
: -	if (((type1 | type2) &
: -	     (MEM_TYPE_INT | MEM_TYPE_UINT | MEM_TYPE_DOUBLE)) != 0) {
: -		if (!mem_is_num(pMem1))
: -			return +1;
: -		if (!mem_is_num(pMem2))
: -			return -1;
: -		mem_cmp_num(pMem1, pMem2, &res);
: -		return res;
: -	}
: -
: -	/* If one value is a string and the other is a blob, the string is
: less.
: -	 * If both are strings, compare using the collating functions.
: -	 */
: -	if (((type1 | type2) & MEM_TYPE_STR) != 0) {
: -		if (type1 != MEM_TYPE_STR) {
: -			return 1;
: -		}
: -		if (type2 != MEM_TYPE_STR) {
: -			return -1;
: -		}
: -		mem_cmp_str(pMem1, pMem2, &res, pColl);
: -		return res;
: -	}
: -
: -	/* Both values must be blobs.  Compare using memcmp().  */
: -	mem_cmp_bin(pMem1, pMem2, &res);
: -	return res;
: -}
: -
:  int
:  sql_vdbemem_finalize(struct Mem *mem, struct func *func)
:  {



  reply	other threads:[~2021-07-19  9:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-16  8:57 [Tarantool-patches] [PATCH v2 0/4] Follow ups for uuid introduction Mergen Imeev via Tarantool-patches
2021-07-16  8:57 ` [Tarantool-patches] [PATCH v2 1/4] sql: introduce uuid to quote() Mergen Imeev via Tarantool-patches
2021-07-19  9:16   ` Timur Safin via Tarantool-patches
2021-07-16  8:57 ` [Tarantool-patches] [PATCH v2 2/4] sql: allow to bind uuid values Mergen Imeev via Tarantool-patches
2021-07-19  9:16   ` Timur Safin 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 [this message]
2021-07-16  8:57 ` [Tarantool-patches] [PATCH v2 4/4] sql: introduce mem_cmp_msgpack() Mergen Imeev via Tarantool-patches
2021-07-19  9:16   ` Timur Safin via Tarantool-patches
2021-07-19 10:07     ` Mergen Imeev via Tarantool-patches
  -- strict thread matches above, loose matches on Subject: below --
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 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
2021-07-13  8:04         ` 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='18a301d77c7e$d5a9af70$80fd0e50$@tarantool.org' \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=tsafin@tarantool.org \
    /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

Tarantool development patches archive

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lists.tarantool.org/tarantool-patches/0 tarantool-patches/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 tarantool-patches tarantool-patches/ https://lists.tarantool.org/tarantool-patches \
		tarantool-patches@dev.tarantool.org.
	public-inbox-index tarantool-patches

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git