[Tarantool-patches] [PATCH v1 1/1] sql: fix INSTEAD OF DELETE trigger for VIEW

Nikita Pettik korablev at tarantool.org
Thu Jan 30 01:48:21 MSK 2020


On 22 Jan 16:54, imeevma at 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.



More information about the Tarantool-patches mailing list