From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 53A766EC55; Fri, 23 Jul 2021 10:54:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 53A766EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627026862; bh=pz1VGyqnj/gmrk9k1LGbeo2Dzie8WQ1zXTMmlTxkadY=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=XV9N+jVVv1EfLPC3j0lfmJOPf3SNbmgs+tYeVQTNBll4yxeSOt9t+Y67mw0CRCZa0 7zGShI/s8wsW9B8jOxYO8XyW/2l2TJbyYAk5qImmRtTqhLWvTE0LoHmG+EMuAqBmoh LD4JoPM9nRpthupgSg/iCPAX3T52Lq9lhxsqXpTw= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 A6F4C6EC55 for ; Fri, 23 Jul 2021 10:54:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A6F4C6EC55 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1m6q0h-0000cv-Vo; Fri, 23 Jul 2021 10:54:20 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 23 Jul 2021 10:54:19 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C30288BCF456A452EC92BAB6D044D5CCDE182A05F538085040D4FDD75A358D5EE42F6EF513AF7D76C433D33F67CFF9CB4405125E322ED0A617 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70EEC24FFE855BCBBC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7B9115C1E69829868EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F2E8FDA1522565557AACAD74AE01785B69CC7F00164DA146DAFE8445B8C89999728AA50765F7900637F924B32C592EA89F389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC82FFDA4F57982C5F4F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B953A8A48A05D51F175ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C16CF367659D795C09711F8108C30952E8D68B61A2AA5F5DF9C2B6934AE262D3EE7EAB7254005DCEDF1D44946AC0875EC1E0A4E2319210D9B64D260DF9561598F01A9E91200F654B02CB9166B85A600698E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34BC3EEE75EF3BACCF81A6D9EC29FDE0E8CE3A88862998A121B675381E367AFE04AC53F59206E5B4481D7E09C32AA3244C54A44E8F2A12E5F7061EF0B0A938B176C3B3ADDA61883BB5729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojtKXY6NTIXk0pV5EKRy0szQ== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DB0A8F97F30E9866EF55BE29DEC7D6EB783D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 1/1] sql: remove OP_Realify X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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 --- https://github.com/tarantool/tarantool/issues/5335 https://github.com/tarantool/tarantool/tree/imeevma/gh-5335-remove-op-realify src/box/sql/expr.c | 13 ------- src/box/sql/vdbe.c | 17 -------- .../gh-5335-wrong-int-to-double-cast.test.lua | 39 +++++++++++++++++++ 3 files changed, 39 insertions(+), 30 deletions(-) create mode 100755 test/sql-tap/gh-5335-wrong-int-to-double-cast.test.lua diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c index 3772596d6..d2624516c 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -3700,11 +3700,6 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target) sqlVdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab, pCol->iSorterColumn, target); - if (pCol->space_def->fields[pExpr->iAgg].type == - FIELD_TYPE_NUMBER) { - sqlVdbeAddOp1(v, OP_Realify, - target); - } return target; } /* @@ -4260,14 +4255,6 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target) (pExpr->iTable ? "new" : "old"), pExpr->space_def->fields[ pExpr->iColumn].name, target)); - - /* If the column has type NUMBER, it may currently be stored as an - * integer. Use OP_Realify to make sure it is really real. - */ - if (pExpr->iColumn >= 0 && def->fields[ - pExpr->iColumn].type == FIELD_TYPE_NUMBER) { - sqlVdbeAddOp1(v, OP_Realify, target); - } break; } diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 9e763ed85..0a3c904b1 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -1445,23 +1445,6 @@ case OP_MustBeInt: { /* jump, in1 */ break; } -/* Opcode: Realify P1 * * * * - * - * If register P1 holds an integer convert it to a real value. - * - * This opcode is used when extracting information from a column that - * has float type. Such column values may still be stored as - * integers, for space efficiency, but after extraction we want them - * to have only a real value. - */ -case OP_Realify: { /* in1 */ - pIn1 = &aMem[pOp->p1]; - if (mem_is_int(pIn1)) { - mem_to_double(pIn1); - } - break; -} - /* Opcode: Cast P1 P2 * * * * Synopsis: type(r[P1]) * diff --git a/test/sql-tap/gh-5335-wrong-int-to-double-cast.test.lua b/test/sql-tap/gh-5335-wrong-int-to-double-cast.test.lua new file mode 100755 index 000000000..efcae911c --- /dev/null +++ b/test/sql-tap/gh-5335-wrong-int-to-double-cast.test.lua @@ -0,0 +1,39 @@ +#!/usr/bin/env tarantool +local test = require("sqltester") +test:plan(2) + +test:execsql([[ + CREATE TABLE t1 (i NUMBER PRIMARY KEY, n NUMBER); + CREATE TABLE t2 (i NUMBER PRIMARY KEY, n NUMBER); + CREATE TRIGGER r AFTER INSERT ON t1 FOR EACH ROW BEGIN UPDATE t1 SET n = new.n; END; + INSERT INTO t1 VALUES (1, 1); + INSERT INTO t2 VALUES (1, 1); +]]) + +-- +-- Make sure that implicit cast from string to integer works correctly in +-- arithmetic operations. +-- +test:do_execsql_test( + "gh-5335-1", + [[ + SELECT i / 2, n / 2 FROM t1; + ]], { + 0, 0 + }) + +test:do_execsql_test( + "gh-5335-2", + [[ + SELECT i / 2, n / 2 FROM t2 GROUP BY n; + ]], { + 0, 0 + }) + +test:execsql([[ + DROP TRIGGER r; + DROP TABLE t1; + DROP TABLE t2; +]]) + +test:finish_test() -- 2.25.1