Tarantool development patches archive
 help / color / mirror / Atom feed
From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v1 03/13] sql: move collation to struct sql_context
Date: Tue, 21 Sep 2021 13:40:54 +0300	[thread overview]
Message-ID: <20210921104054.GA16139@tarantool.org> (raw)
In-Reply-To: <d01b3e1c-73ca-bb96-7883-1374db5d1c93@tarantool.org>

Hi! Thank you for the review! My answers below.

On Tue, Sep 14, 2021 at 11:22:39PM +0200, Vladislav Shpilevoy wrote:
> Thanks for working on this!
> 
> On 10.09.2021 18:01, imeevma@tarantool.org wrote:
> > This patch makes it easier to get a collation by a function.
> 
> You could also store the opcode pointer instead of iOp. But I
> suspect your main reason is to get rid of the vdbe pointer? If
> yes, then why?
> 
I wanted to remove unnecessary connecton between VDBE and functions. Also, this
way it will be easier for me to remove OP_CollSeq.

> > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
> > index 2ff7ce8f4..12dc9126b 100644
> > --- a/src/box/sql/vdbe.c
> > +++ b/src/box/sql/vdbe.c
> > @@ -1159,23 +1159,13 @@ case OP_Remainder: {           /* same as TK_REM, in1, in2, out3 */
> >  	break;
> >  }
> >  
> > -/* Opcode: CollSeq P1 * * P4
> > - *
> > - * P4 is a pointer to a CollSeq struct. If the next call to a user function
> > - * or aggregate calls sqlGetFuncCollSeq(), this collation sequence will
> > - * be returned. This is used by the built-in min(), max() and nullif()
> > - * functions.
> > +/* Opcode: SkipLoad P1 * * * *
> >   *
> >   * If P1 is not zero, then it is a register that a subsequent min() or
> >   * max() aggregate will set to true if the current row is not the minimum or
> >   * maximum.  The P1 register is initialized to false by this instruction.
> > - *
> > - * The interface used by the implementation of the aforementioned functions
> > - * to retrieve the collation sequence set by this opcode is not available
> > - * publicly.  Only built-in functions have access to this feature.
> >   */
> > -case OP_CollSeq: {
> > -	assert(pOp->p4type==P4_COLLSEQ || pOp->p4.pColl == NULL);
> > +case OP_SkipLoad: {
> 
> That is a very strange name. Couldn't OP_Bool somehow be reused?
> Why is this R[p1] = false even needed?
>
It is possible, for example like this:

diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 2880f8ea0..c3f36d74f 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -5636,7 +5636,8 @@ updateAccumulator(Parse * pParse, AggInfo * pAggInfo)
 			}
 			if (regHit == 0 && pAggInfo->nAccumulator)
 				regHit = ++pParse->nMem;
-			sqlVdbeAddOp1(v, OP_SkipLoad, regHit);
+			if (regHit != 0)
+				sqlVdbeAddOp2(v, OP_Bool, false, regHit);
 		}
 		struct sql_context *ctx = sql_context_new(pF->func, nArg, coll);
 		if (ctx == NULL) {
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 12dc9126b..b17179a57 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -4182,9 +4182,8 @@ case OP_AggStep: {
 		goto abort_due_to_error;
 	}
 	assert(mem_is_null(&t));
-	if (pCtx->skipFlag) {
-		assert(pOp[-1].opcode == OP_SkipLoad);
-		i = pOp[-1].p1;
+	if (pCtx->skipFlag && pOp[-1].opcode == OP_Bool) {
+		i = pOp[-1].p2;
 		if (i) mem_set_bool(&aMem[i], true);
 	}
 	break;

However, I'm not sure if this is the correct way to use OP_Bool.

This opcode is used in rather strange queries, such as the following:
SELECT a, min(b) FROM t;

As you can see, there can be multiple values for min (b) in "a". This behavior is
discussed here:
https://github.com/tarantool/tarantool/discussions/6416

Most likely, we will follow the same path as PostgreSQL and MS SQL Server,
namely to prohibit such expressions. This will naturally lead to removal of
OP_SkipLoad/OP_CollSeq.

As for the name - I though of it when read desctiption of skipFlag field in
struct sql_context.

> >  	if (pOp->p1) {
> >  		mem_set_bool(&aMem[pOp->p1], false);
> >  	}


  reply	other threads:[~2021-09-21 10:40 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10 16:01 [Tarantool-patches] [PATCH v1 00/13] sql: reworks aggregate functions Mergen Imeev via Tarantool-patches
2021-09-10 16:01 ` [Tarantool-patches] [PATCH v1 01/13] sql: use register P1 for number of arguments Mergen Imeev via Tarantool-patches
2021-09-10 16:01 ` [Tarantool-patches] [PATCH v1 02/13] sql: remove AggStep0 and OP_BuiltinFunction0 Mergen Imeev via Tarantool-patches
2021-09-10 16:27   ` Mergen Imeev via Tarantool-patches
2021-09-14 21:21   ` Vladislav Shpilevoy via Tarantool-patches
2021-09-10 16:01 ` [Tarantool-patches] [PATCH v1 03/13] sql: move collation to struct sql_context Mergen Imeev via Tarantool-patches
2021-09-14 21:22   ` Vladislav Shpilevoy via Tarantool-patches
2021-09-21 10:40     ` Mergen Imeev via Tarantool-patches [this message]
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 04/13] sql: introduce mem_append() Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 05/13] sql: remove sql_vdbemem_finalize() Mergen Imeev via Tarantool-patches
2021-09-14 21:23   ` Vladislav Shpilevoy via Tarantool-patches
2021-09-21 10:47     ` Mergen Imeev via Tarantool-patches
2021-09-22 22:47       ` Vladislav Shpilevoy via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 06/13] sql: rework SUM() Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 07/13] sql: rework TOTAL() Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 08/13] sql: rework AVG() Mergen Imeev via Tarantool-patches
2021-09-14 21:24   ` Vladislav Shpilevoy via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 09/13] sql: rework COUNT() Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 10/13] sql: rework MIN() and MAX() Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 11/13] sql: rework GROUP_CONCAT() Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 12/13] sql: remove copying of result in finalizers Mergen Imeev via Tarantool-patches
2021-09-14 21:24   ` Vladislav Shpilevoy via Tarantool-patches
2021-09-21 10:49     ` Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 13/13] sql: remove MEM_TYPE_AGG 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=20210921104054.GA16139@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v1 03/13] sql: move collation to struct sql_context' \
    /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