[Tarantool-patches] [PATCH v1 1/1] sql: remove OP_Realify
imeevma at tarantool.org
imeevma at tarantool.org
Sat Sep 26 17:15:10 MSK 2020
This opcode was used to convert INTEGER values to REAL. It is not
necessary in Tarantool and may cause errors.
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);
diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index bc2182446..09a2d3ef9 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;
}
/* Otherwise, fall thru into the TK_COLUMN case */
@@ -4257,14 +4252,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 14ddb5160..a86461c4c 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -2105,23 +2105,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 ((pIn1->flags & (MEM_Int | MEM_UInt)) != 0) {
- sqlVdbeMemRealify(pIn1);
- }
- break;
-}
-
/* Opcode: Cast P1 P2 * * *
* Synopsis: type(r[P1])
*
diff --git a/test/sql/gh-5335-unnecessary-conversation-to-double.result b/test/sql/gh-5335-unnecessary-conversation-to-double.result
new file mode 100644
index 000000000..e3f0f0b0b
--- /dev/null
+++ b/test/sql/gh-5335-unnecessary-conversation-to-double.result
@@ -0,0 +1,51 @@
+-- test-run result file version 2
+-- Make sure that INTEGER is not converted to DOUBLE in cases below.
+box.execute("CREATE TABLE t (i NUMBER PRIMARY KEY, n NUMBER);")
+ | ---
+ | - row_count: 1
+ | ...
+box.execute("CREATE TRIGGER t AFTER INSERT ON t FOR EACH ROW BEGIN UPDATE t SET n = new.n; END;")
+ | ---
+ | - row_count: 1
+ | ...
+box.execute("INSERT INTO t VALUES (1, 1);")
+ | ---
+ | - row_count: 1
+ | ...
+box.execute("SELECT i / 2, n / 2 FROM t;")
+ | ---
+ | - metadata:
+ | - name: COLUMN_1
+ | type: number
+ | - name: COLUMN_2
+ | type: number
+ | rows:
+ | - [0, 0]
+ | ...
+box.execute("DROP TABLE t;")
+ | ---
+ | - row_count: 1
+ | ...
+
+box.execute("CREATE TABLE t (i NUMBER PRIMARY KEY, n NUMBER);")
+ | ---
+ | - row_count: 1
+ | ...
+box.execute("INSERT INTO t VALUES (1,1);")
+ | ---
+ | - row_count: 1
+ | ...
+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, 0]
+ | ...
+box.execute("DROP TABLE t;")
+ | ---
+ | - row_count: 1
+ | ...
diff --git a/test/sql/gh-5335-unnecessary-conversation-to-double.test.lua b/test/sql/gh-5335-unnecessary-conversation-to-double.test.lua
new file mode 100644
index 000000000..1663d054a
--- /dev/null
+++ b/test/sql/gh-5335-unnecessary-conversation-to-double.test.lua
@@ -0,0 +1,11 @@
+-- Make sure that INTEGER is not converted to DOUBLE in cases below.
+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;")
+box.execute("DROP TABLE t;")
+
+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;")
+box.execute("DROP TABLE t;")
--
2.25.1
More information about the Tarantool-patches
mailing list