[Tarantool-patches] [PATCH v5 37/52] sql: introduce mem_set_null_clear()

imeevma at tarantool.org imeevma at tarantool.org
Fri Apr 9 23:25:53 MSK 2021


Thank you for the review! My answers and new patch below.

On 30.03.2021 02:07, Vladislav Shpilevoy wrote:
> Thanks for the patch!
>
> I propose to rename that to mem_set_null_clear(). Because
> it is a NULL, but with special semantics.
Done.


New patch:

commit 05413fe121d62c5163593436df9fc8f1a7d2c295
Author: Mergen Imeev <imeevma at gmail.com>
Date:   Tue Mar 16 15:14:32 2021 +0300

    sql: introduce mem_set_null_clear()
    
    This patch introduces mem_set_null_clear() function. This function sets
    "cleared" NULL to MEM. This NULL is used only in internal VDBE
    operations.
    
    Part of #5818

diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index af11ae1d5..2e147291f 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -629,6 +629,13 @@ mem_set_agg(struct Mem *mem, struct func *func, int size)
 	return 0;
 }
 
+void
+mem_set_null_clear(struct Mem *mem)
+{
+	mem_clear(mem);
+	mem->flags = MEM_Null | MEM_Cleared;
+}
+
 int
 mem_copy(struct Mem *to, const struct Mem *from)
 {
diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h
index cf0db62f9..f17c4bb78 100644
--- a/src/box/sql/mem.h
+++ b/src/box/sql/mem.h
@@ -371,6 +371,10 @@ mem_set_frame(struct Mem *mem, struct VdbeFrame *frame);
 int
 mem_set_agg(struct Mem *mem, struct func *func, int size);
 
+/** Clear MEM and set it to special, "cleared", NULL. */
+void
+mem_set_null_clear(struct Mem *mem);
+
 /**
  * Copy content of MEM from one MEM to another. In case source MEM contains
  * string or binary and allocation type is not STATIC, this value is copied to
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 7f1e0bcbe..4566606d7 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -855,7 +855,7 @@ case OP_String: {          /* out2 */
  * is less than P2 (typically P3 is zero) then only register P2 is
  * set to NULL.
  *
- * If the P1 value is non-zero, then also set the MEM_Cleared flag so that
+ * If the P1 value is non-zero, then also set the Cleared flag so that
  * NULL values will not compare equal even if SQL_NULLEQ is set on
  * OP_Ne or OP_Eq.
  */
@@ -865,13 +865,14 @@ case OP_Null: {           /* out2 */
 	cnt = pOp->p3-pOp->p2;
 	assert(pOp->p3<=(p->nMem+1 - p->nCursor));
 	if (pOp->p1 != 0)
-		pOut->flags = MEM_Null | MEM_Cleared;
+		mem_set_null_clear(pOut);
 	while( cnt>0) {
 		pOut++;
 		memAboutToChange(p, pOut);
-		mem_set_null(pOut);
 		if (pOp->p1 != 0)
-			pOut->flags = MEM_Null | MEM_Cleared;
+			mem_set_null_clear(pOut);
+		else
+			mem_set_null(pOut);
 		cnt--;
 	}
 	break;


More information about the Tarantool-patches mailing list