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 8C3426EC55; Thu, 29 Jul 2021 09:48:16 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8C3426EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627541296; bh=0R+RgbumxIwv44bgKxxZxXJKOonPrbiyrmar9aWPIOQ=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=X7w9frAIS+NByIJOUsVUdzbdQ35762Zb3eqCS3JLtgEt6+Y5t80bHqHmyxISusBOE RAwhupPeO6gyn9s2rzMALqT6t6R87LXFbJWbs+D4C+4r6HwpYUaJIVviB1WmdlwbCD TdJVD6Izk7k1t/wqy7AfKARUfhFt4hxCTPkW8y0Q= 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 A95C96EC55 for ; Thu, 29 Jul 2021 09:48:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A95C96EC55 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1m8zq2-0001mj-TY; Thu, 29 Jul 2021 09:48:15 +0300 To: tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Thu, 29 Jul 2021 09:48:14 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD941C43E597735A9C34755E0A9F196FCB739C645213AB7C8E0182A05F538085040807C143265D282B0283EEC0023CD8345564B7FC2515A0E699CF80B219CD83B9C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE737AE489DBC023F2AEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637013F392EFFCDE01C8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D807F153BF2FA8F9453359918D15285F2D117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735209ECD01F8117BC8BEA471835C12D1D977C4224003CC8364762BB6847A3DEAEFB0F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C289736CE4F78F08343847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7BEA09003D200E08F54408DC79F0A4FDCE3D40E7BAD427579C2B6934AE262D3EE7EAB7254005DCEDF1D44946AC0875EC1E0A4E2319210D9B64D260DF9561598F01A9E91200F654B0F7239ED45045D1418E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D8FD11F74BDD6E8DD2F393BCA2AED106721C451D83AA66404DE6CC7738D4D60873DFC6971F3E6D391D7E09C32AA3244C9774257F085E35B5D4FEBBFACC64CC009CA7333006C390A0729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXiQpsg/f3LVYc8oFX7zVcva X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D99100AD21E16B732EC2B11E29100082183D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B 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 ...gh-5335-remove-wrong-double-to-int-cast.md | 4 ++ src/box/sql/expr.c | 13 ------- src/box/sql/vdbe.c | 17 -------- .../gh-5335-wrong-int-to-double-cast.test.lua | 39 +++++++++++++++++++ 4 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 changelogs/unreleased/gh-5335-remove-wrong-double-to-int-cast.md create mode 100755 test/sql-tap/gh-5335-wrong-int-to-double-cast.test.lua diff --git a/changelogs/unreleased/gh-5335-remove-wrong-double-to-int-cast.md b/changelogs/unreleased/gh-5335-remove-wrong-double-to-int-cast.md new file mode 100644 index 000000000..b06805a7f --- /dev/null +++ b/changelogs/unreleased/gh-5335-remove-wrong-double-to-int-cast.md @@ -0,0 +1,4 @@ +## bugfix/sql + +* Removed spontaneous conversion from INTEGER to DOUBLE in a field of type + NUMBER (gh-5335). 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..d29324a28 --- /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 there are no unnecesary INTEGER to DOUBLE implicit cast in +-- field of type NUMBER. +-- +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