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 AAEDA6EC58; Mon, 2 Aug 2021 21:09:43 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AAEDA6EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627927783; bh=iUOFOy53wehEBKKEopP9Ek5UCL84EBjjFVrpWKKMDNk=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=OP5r7L3Q5/oXw/73fk+pqYsLs8vC0Mzn2MFBpCGxT2jddebZLm+q9PSvaaf5OxROT FdnAw60oIdVPZAzCrqOaHdgdj1zAxfy0aYYG/VfrN6GFJCkoNG2+ZOe825gVlvKfwN mdZVo7tgczzW35JRsZpSsBR0S+32Zf2aKK/hBboE= Received: from smtp45.i.mail.ru (smtp45.i.mail.ru [94.100.177.105]) (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 040486EC58 for ; Mon, 2 Aug 2021 21:09:42 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 040486EC58 Received: by smtp45.i.mail.ru with esmtpa (envelope-from ) id 1mAcNh-00075z-UA; Mon, 02 Aug 2021 21:09:42 +0300 To: imun@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Mon, 2 Aug 2021 21:09:40 +0300 Message-Id: <338bac2c7895313225198b6ed585c2327eafdd53.1627927714.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD941C43E597735A9C354866C15C72ED952BE56FFA0EFAF5B8C182A05F5380850409610BE2C272A9FF1DAF1D0277FC867DC589CA968AB7221B6AAF118C6538B0C36 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70EEC24FFE855BCBBC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7E044D6BF4785D596EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F2F16C348ECD94F6F37B0FD79BF0E3C089CC7F00164DA146DAFE8445B8C89999728AA50765F7900637F924B32C592EA89F389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8EDCF5861DED71B2F389733CBF5DBD5E9B5C8C57E37DE458BD9DD9810294C998ED8FC6C240DEA76428AA50765F790063737251E6EF601DCFAD32BA5DBAC0009BE395957E7521B51C20BC6067A898B09E4090A508E0FED62991661749BA6B97735C4D20244F7083972CD04E86FAF290E2D7E9C4E3C761E06A71DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B66F6A3E018CF4DC80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79DB53CE84373687089F947DCA5E4940A51 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C85811CA530B5049172063B9676EE379636C818060C710E499C2B6934AE262D3EE7EAB7254005DCED5EFA11C3473D072F9510FB958DCE06DB6ED91DBE5ABE359AC8952F428387DEC0B936CB490224F2464EEA7BD89490CAC0EDDA962BC3F61961 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34EE19B6E2433CA093A3DB19FB50897FDA97B744260B3354E492C9AA0DC50C8716E82CD31F75D04A991D7E09C32AA3244C2CFA49B41152B67EC694DAB80D11483FA90944CA99CF22E3729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj9N286KAyvN4m28TYi/pOgA== X-Mailru-Sender: 83DC58D0E026EF5214980281B38C4557ACD62BA95AA83EFADAF1D0277FC867DC7962F9E9328436E15105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 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 | 40 +++++++++++++++++++ 4 files changed, 44 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..76daa45e9 --- /dev/null +++ b/test/sql-tap/gh-5335-wrong-int-to-double-cast.test.lua @@ -0,0 +1,40 @@ +#!/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); + -- This trigger is only needed to reproduce the error. + 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