Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: imeevma@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v1 1/1] sql: fix INSTEAD OF DELETE trigger for VIEW
Date: Thu, 30 Jan 2020 01:48:21 +0300	[thread overview]
Message-ID: <20200129224821.GD1049@tarantool.org> (raw)
In-Reply-To: <fd25f57bd73d6433067d037acf85a67ed42149ea.1579701198.git.imeevma@gmail.com>

On 22 Jan 16:54, imeevma@tarantool.org wrote:
> diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c
> index 8d9ae4f..e9edbcc 100644
> --- a/src/box/sql/delete.c
> +++ b/src/box/sql/delete.c
> @@ -231,7 +231,7 @@ sql_table_delete_from(struct Parse *parse, struct SrcList *tab_list,
>  		int eph_cursor = parse->nTab++;
>  		int addr_eph_open = sqlVdbeCurrentAddr(v);
>  		if (is_view) {
> -			pk_len = space->def->field_count;
> +			pk_len = space->def->field_count + 1;
>  			parse->nMem += pk_len;
>  			sqlVdbeAddOp2(v, OP_OpenTEphemeral, reg_eph,

Please, add comments explaining what's going on here. Despite the seeming
simplicity, this change is way far from being obvious. This time I've added
comment myself:

+                       /*
+                        * At this stage SELECT is already materialized
+                        * into ephemeral table, which has one additional
+                        * tail field (except for ones specified in view
+                        * format) which contains sequential ids. These ids
+                        * are required since selected values may turn out to
+                        * be non-unique. For instance:
+                        * CREATE TABLE t (id INT PRIMARY KEY, a INT);
+                        * INSERT INTO t VALUES (1, 1), (2, 1), (3, 1);
+                        * CREATE VIEW v AS SELECT a FROM t;
+                        * Meanwhile ephemeral tables feature PK covering ALL
+                        * fields of format, so without id materialization
+                        * processing is impossible. Then, results of
+                        * materialization are transferred to the table being
+                        * created below. So to fit tuples in it we must
+                        * account that id field as well. That's why pk_len
+                        * has one field more than view format.
+                        */

Next time I'll reject such patches.

Pushed to master, 2.3 and 2.2.

      reply	other threads:[~2020-01-29 22:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-22 13:54 imeevma
2020-01-29 22:48 ` Nikita Pettik [this message]

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=20200129224821.GD1049@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v1 1/1] sql: fix INSTEAD OF DELETE trigger for VIEW' \
    /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