Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org, Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] [PATCH 1/2] sql: fix OP_MakeRecord argument of ANALYZE bytecode
Date: Tue, 19 Mar 2019 02:51:20 +0300	[thread overview]
Message-ID: <adb4c0549ccc610812f665bca217f71254a308e3.1552943281.git.korablev@tarantool.org> (raw)
In-Reply-To: <cover.1552943281.git.korablev@tarantool.org>
In-Reply-To: <cover.1552943281.git.korablev@tarantool.org>

Accidentally, wrong number of fields was passed to OP_MakeRecord opcode
which encodes tuple to be inserted to _sql_stat1 space: instead of three
fields (as format of space says), four were specified. Since this system
space doesn't feature exact field count, this insertion was successfully
processed. What is more, this additional field was invisible for SQL
means since it is out of space format (so it didn't get to resulting set
of SELECT * FROM _sql_stat1; queries). This patch fixes number of fields
to be encoded of this particular OP_MakeRecord.
---
 src/box/sql/analyze.c                                   |  2 +-
 .../sql/{sql-statN-index-drop.result => analyze.result} | 17 +++++++++++++++++
 .../{sql-statN-index-drop.test.lua => analyze.test.lua} |  6 ++++++
 3 files changed, 24 insertions(+), 1 deletion(-)
 rename test/sql/{sql-statN-index-drop.result => analyze.result} (86%)
 rename test/sql/{sql-statN-index-drop.test.lua => analyze.test.lua} (91%)

diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c
index ea5cbc39b..9d3df8a15 100644
--- a/src/box/sql/analyze.c
+++ b/src/box/sql/analyze.c
@@ -996,7 +996,7 @@ vdbe_emit_analyze_space(struct Parse *parse, struct space *space)
 					     FIELD_TYPE_STRING,
 					     FIELD_TYPE_STRING,
 					     field_type_MAX };
-		sqlVdbeAddOp4(v, OP_MakeRecord, tab_name_reg, 4, tmp_reg,
+		sqlVdbeAddOp4(v, OP_MakeRecord, tab_name_reg, 3, tmp_reg,
 				  (char *)types, sizeof(types));
 		sqlVdbeAddOp4(v, OP_IdxInsert, tmp_reg, 0, 0,
 				  (char *)stat1, P4_SPACEPTR);
diff --git a/test/sql/sql-statN-index-drop.result b/test/sql/analyze.result
similarity index 86%
rename from test/sql/sql-statN-index-drop.result
rename to test/sql/analyze.result
index 760595188..42210ea13 100644
--- a/test/sql/sql-statN-index-drop.result
+++ b/test/sql/analyze.result
@@ -45,6 +45,23 @@ box.sql.execute("SELECT * FROM \"_sql_stat1\";")
   - ['T2', 'I1', '1 1']
   - ['T2', 'T2', '1 1']
 ...
+-- Make sure that tuples in spaces with statistics don't
+-- containt fields out of format.
+--
+box.space._sql_stat1:select()
+---
+- - ['T1', 'I1', '1 1']
+  - ['T1', 'T1', '1 1']
+  - ['T2', 'I1', '1 1']
+  - ['T2', 'T2', '1 1']
+...
+box.space._sql_stat4:select()
+---
+- - ['T1', 'I1', '1', '0', '0', !!binary kQI=]
+  - ['T1', 'T1', '1', '0', '0', !!binary kQE=]
+  - ['T2', 'I1', '1', '0', '0', !!binary kQI=]
+  - ['T2', 'T2', '1', '0', '0', !!binary kQE=]
+...
 -- Dropping an index.
 box.sql.execute("DROP INDEX i1 ON t1;")
 ---
diff --git a/test/sql/sql-statN-index-drop.test.lua b/test/sql/analyze.test.lua
similarity index 91%
rename from test/sql/sql-statN-index-drop.test.lua
rename to test/sql/analyze.test.lua
index 35f22910c..ba31d5fbc 100644
--- a/test/sql/sql-statN-index-drop.test.lua
+++ b/test/sql/analyze.test.lua
@@ -17,6 +17,12 @@ box.sql.execute("ANALYZE;")
 box.sql.execute("SELECT * FROM \"_sql_stat4\";")
 box.sql.execute("SELECT * FROM \"_sql_stat1\";")
 
+-- Make sure that tuples in spaces with statistics don't
+-- containt fields out of format.
+--
+box.space._sql_stat1:select()
+box.space._sql_stat4:select()
+
 -- Dropping an index.
 box.sql.execute("DROP INDEX i1 ON t1;")
 
-- 
2.15.1

  reply	other threads:[~2019-03-18 23:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-18 23:51 [tarantool-patches] [PATCH 0/2] Fix wrong field count in bytecode for ANALYZE Nikita Pettik
2019-03-18 23:51 ` Nikita Pettik [this message]
2019-03-18 23:51 ` [tarantool-patches] [PATCH 2/2] schema: add exact field count to SQL stat spaces Nikita Pettik
2019-03-21 13:31   ` [tarantool-patches] " Vladislav Shpilevoy
2019-03-21 15:22     ` n.pettik
2019-03-21 15:39       ` Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=adb4c0549ccc610812f665bca217f71254a308e3.1552943281.git.korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH 1/2] sql: fix OP_MakeRecord argument of ANALYZE bytecode' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox