From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 76EA0469719 for ; Mon, 28 Sep 2020 19:41:10 +0300 (MSK) Date: Mon, 28 Sep 2020 19:41:08 +0300 From: Mergen Imeev Message-ID: <20200928164108.GA108684@tarantool.org> References: <73779905e2350c2ecf37cfe744058e3fa61b4ded.1601129563.git.imeevma@gmail.com> <20200928155559.GB14909@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200928155559.GB14909@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH v1 1/1] sql: remove OP_Realify List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Nikita Pettik Cc: tarantool-patches@dev.tarantool.org Hi! Thank you for review! My answer below. On Mon, Sep 28, 2020 at 03:55:59PM +0000, Nikita Pettik wrote: > On 26 Sep 17:15, imeevma@tarantool.org wrote: > > This opcode was used to convert INTEGER values to REAL. It is not > > necessary in Tarantool and may cause errors. > > Add justification: what this change fixes, in which way etc. > Fixed: commit 379694944e39a3b0c33135a724f2ee246c619110 Author: Mergen Imeev Date: Sat Sep 26 12:43:18 2020 +0300 sql: remove OP_Realify This opcode was used to convert INTEGER values to REAL. It is not necessary in Tarantool and causes errors. Due to OP_Realify two type of errors appeared: 1) In some cases in trigger INTEGER may be converted to DOUBLE. For example: box.execute("CREATE TABLE t (i NUMBER PRIMARY KEY, n NUMBER);") box.execute("CREATE TRIGGER t AFTER INSERT ON t FOR EACH ROW BEGIN UPDATE t SET n = new.n; END;") box.execute("INSERT INTO t VALUES (1, 1);") box.execute("SELECT i / 2, n / 2 FROM t;") Result: tarantool> box.execute("SELECT i / 2, n / 2 FROM t;") --- - metadata: - name: COLUMN_1 type: number - name: COLUMN_2 type: number rows: - [0, 0.5] ... 2) If SELECT uses GROUP BY then it may return DOUBLE instead of INTEGER. For example: box.execute("CREATE TABLE t (i NUMBER PRIMARY KEY, n NUMBER);") box.execute("INSERT INTO t VALUES (1,1);") box.execute("SELECT i / 2, n / 2 FROM t GROUP BY n;") Result: tarantool> box.execute("SELECT i / 2, n / 2 FROM t GROUP BY n;") --- - metadata: - name: COLUMN_1 type: number - name: COLUMN_2 type: number rows: - [0.5, 0.5] ... This patch removes OP_Realify, after which these errors disappear. Closes #5335 > > Closes #5335 > > --- > > https://github.com/tarantool/tarantool/issues/5335 > > https://github.com/tarantool/tarantool/tree/imeevma/gh-5335-remove-op-realify > > > > @ChangeLog > > - Fixed a bug with unnecessary convertion from INTEGER to DOUBLE (gh-5335). > > > > src/box/sql/delete.c | 12 ----- > > src/box/sql/expr.c | 13 ----- > > src/box/sql/vdbe.c | 17 ------- > > ...-unnecessary-conversation-to-double.result | 51 +++++++++++++++++++ > > ...nnecessary-conversation-to-double.test.lua | 11 ++++ > > 5 files changed, 62 insertions(+), 42 deletions(-) > > create mode 100644 test/sql/gh-5335-unnecessary-conversation-to-double.result > > create mode 100644 test/sql/gh-5335-unnecessary-conversation-to-double.test.lua > > > > diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c > > index 68abd1f58..a78c68df6 100644 > > --- a/src/box/sql/delete.c > > +++ b/src/box/sql/delete.c > > @@ -565,18 +565,6 @@ sql_generate_index_key(struct Parse *parse, struct index *index, int cursor, > > } > > uint32_t tabl_col = index->def->key_def->parts[j].fieldno; > > sqlVdbeAddOp3(v, OP_Column, cursor, tabl_col, reg_base + j); > > - /* > > - * If the column type is NUMBER but the number > > - * is an integer, then it might be stored in the > > - * table as an integer (using a compact > > - * representation) then converted to REAL by an > > - * OP_Realify opcode. But we are getting > > - * ready to store this value back into an index, > > - * where it should be converted by to INTEGER > > - * again. So omit the OP_Realify opcode if > > - * it is present > > - */ > > - sqlVdbeDeletePriorOpcode(v, OP_Realify); > > } > > if (reg_out != 0) > > sqlVdbeAddOp3(v, OP_MakeRecord, reg_base, col_cnt, reg_out);