Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] sql: fix assertion fail when selecting from _vfunc
@ 2020-01-10  7:40 Chris Sosnin
  2020-01-15 17:29 ` Nikita Pettik
  0 siblings, 1 reply; 7+ messages in thread
From: Chris Sosnin @ 2020-01-10  7:40 UTC (permalink / raw)
  To: tarantool-patches

This patch already has LGTM from Vlad. However, I moved changes to
the 2.3.2 upgrade, as long as the patch was no longer valid.

The assertion mentioned #4666 fails because it was forgotten to update
_vfunc format along with _func in 2.2.1. This leads to bad allocation
of vdbe cursor and setting wrong memory to 0.

Closes #4666
---
branch: https://github.com/tarantool/tarantool/tree/ksosnin/gh-4666-select-from-vfunc
issue: https://github.com/tarantool/tarantool/issues/4666

 src/box/bootstrap.snap                        | Bin 5976 -> 5978 bytes
 src/box/lua/upgrade.lua                       |  15 +++++++++++++++
 test/box-py/bootstrap.result                  |  11 +++++++++--
 test/sql/engine.cfg                           |   1 +
 test/sql/gh-4666-sql-select-from-vfunc.result |  11 +++++++++++
 .../gh-4666-sql-select-from-vfunc.test.lua    |   4 ++++
 6 files changed, 40 insertions(+), 2 deletions(-)
 create mode 100644 test/sql/gh-4666-sql-select-from-vfunc.result
 create mode 100644 test/sql/gh-4666-sql-select-from-vfunc.test.lua

diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua
index c69b6b543..4a7316ac0 100644
--- a/src/box/lua/upgrade.lua
+++ b/src/box/lua/upgrade.lua
@@ -970,6 +970,20 @@ local function upgrade_to_2_3_1()
     create_session_settings_space()
 end
 
+--------------------------------------------------------------------------------
+-- Tarantool 2.3.2
+--------------------------------------------------------------------------------
+
+local function update_vfunc_format()
+    local _func = box.space[box.schema.FUNC_ID]
+    local _vfunc = box.space[box.schema.VFUNC_ID]
+    _vfunc:format(_func:format())
+end
+
+local function upgrade_to_2_3_2()
+    update_vfunc_format()
+end
+
 --------------------------------------------------------------------------------
 
 local function get_version()
@@ -1006,6 +1020,7 @@ local function upgrade(options)
         {version = mkversion(2, 2, 1), func = upgrade_to_2_2_1, auto = true},
         {version = mkversion(2, 3, 0), func = upgrade_to_2_3_0, auto = true},
         {version = mkversion(2, 3, 1), func = upgrade_to_2_3_1, auto = true},
+        {version = mkversion(2, 3, 2), func = upgrade_to_2_3_2, auto = true},
     }
 
     for _, handler in ipairs(handlers) do
diff --git a/test/box-py/bootstrap.result b/test/box-py/bootstrap.result
index 0876e77a6..1e7c40ce7 100644
--- a/test/box-py/bootstrap.result
+++ b/test/box-py/bootstrap.result
@@ -4,7 +4,7 @@ box.internal.bootstrap()
 box.space._schema:select{}
 ---
 - - ['max_id', 511]
-  - ['version', 2, 3, 1]
+  - ['version', 2, 3, 2]
 ...
 box.space._cluster:select{}
 ---
@@ -63,7 +63,14 @@ box.space._space:select{}
         'type': 'string'}, {'name': 'last_altered', 'type': 'string'}]]
   - [297, 1, '_vfunc', 'sysview', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'owner',
         'type': 'unsigned'}, {'name': 'name', 'type': 'string'}, {'name': 'setuid',
-        'type': 'unsigned'}]]
+        'type': 'unsigned'}, {'name': 'language', 'type': 'string'}, {'name': 'body',
+        'type': 'string'}, {'name': 'routine_type', 'type': 'string'}, {'name': 'param_list',
+        'type': 'array'}, {'name': 'returns', 'type': 'string'}, {'name': 'aggregate',
+        'type': 'string'}, {'name': 'sql_data_access', 'type': 'string'}, {'name': 'is_deterministic',
+        'type': 'boolean'}, {'name': 'is_sandboxed', 'type': 'boolean'}, {'name': 'is_null_call',
+        'type': 'boolean'}, {'name': 'exports', 'type': 'array'}, {'name': 'opts',
+        'type': 'map'}, {'name': 'comment', 'type': 'string'}, {'name': 'created',
+        'type': 'string'}, {'name': 'last_altered', 'type': 'string'}]]
   - [304, 1, '_user', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'owner',
         'type': 'unsigned'}, {'name': 'name', 'type': 'string'}, {'name': 'type',
         'type': 'string'}, {'name': 'auth', 'type': 'map'}]]
diff --git a/test/sql/engine.cfg b/test/sql/engine.cfg
index 1e9f08c6a..22ea90043 100644
--- a/test/sql/engine.cfg
+++ b/test/sql/engine.cfg
@@ -2,6 +2,7 @@
     "vinyl-opts.test.lua" : {
         "vinyl": {"engine": "vinyl"}
     },
+    "gh-4666-sql-select-from-vfunc.test.lua": { },
     "bind.test.lua": {
         "remote": {"remote": "true"},
         "local": {"remote": "false"}
diff --git a/test/sql/gh-4666-sql-select-from-vfunc.result b/test/sql/gh-4666-sql-select-from-vfunc.result
new file mode 100644
index 000000000..d57c66867
--- /dev/null
+++ b/test/sql/gh-4666-sql-select-from-vfunc.result
@@ -0,0 +1,11 @@
+--
+-- Make sure assertion does not fail.
+--
+box.execute([[select "id" from "_vfunc" where "id" = 1;]])
+---
+- metadata:
+  - name: id
+    type: unsigned
+  rows:
+  - [1]
+...
diff --git a/test/sql/gh-4666-sql-select-from-vfunc.test.lua b/test/sql/gh-4666-sql-select-from-vfunc.test.lua
new file mode 100644
index 000000000..fa296e1e1
--- /dev/null
+++ b/test/sql/gh-4666-sql-select-from-vfunc.test.lua
@@ -0,0 +1,4 @@
+--
+-- Make sure assertion does not fail.
+--
+box.execute([[select "id" from "_vfunc" where "id" = 1;]])
-- 
2.21.0 (Apple Git-122.2)

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [Tarantool-patches] [PATCH] sql: fix assertion fail when selecting from _vfunc
@ 2019-12-17 10:26 Chris Sosnin
  2019-12-20 21:10 ` Vladislav Shpilevoy
  0 siblings, 1 reply; 7+ messages in thread
From: Chris Sosnin @ 2019-12-17 10:26 UTC (permalink / raw)
  To: tarantool-patches

The assertion mentioned #4666 fails because it was forgotten to update
_vfunc format along with _func in 2.2.1. This leads to bad allocation
of vdbe cursor and setting wrong memory to 0.

Closes #4666
---
branch: https://github.com/tarantool/tarantool/tree/ksosnin/gh-4666-select-from-vfunc
issue: https://github.com/tarantool/tarantool/issues/4666

 src/box/bootstrap.snap                        | Bin 5921 -> 5916 bytes
 src/box/lua/upgrade.lua                       |   7 +++++++
 test/box-py/bootstrap.result                  |   9 ++++++++-
 test/sql/gh-4666-sql-select-from-vfunc.result |  19 ++++++++++++++++++
 .../gh-4666-sql-select-from-vfunc.test.lua    |   7 +++++++
 5 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 test/sql/gh-4666-sql-select-from-vfunc.result
 create mode 100644 test/sql/gh-4666-sql-select-from-vfunc.test.lua

diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua
index 07f1e0317..e57c23547 100644
--- a/src/box/lua/upgrade.lua
+++ b/src/box/lua/upgrade.lua
@@ -951,8 +951,15 @@ local function drop_func_collation()
     _func.index.name:alter({parts = {{'name', 'string'}}})
 end

+local function update_vfunc_format()
+    local _func = box.space[box.schema.FUNC_ID]
+    local _vfunc = box.space[box.schema.VFUNC_ID]
+    _vfunc:format(_func:format())
+end
+
 local function upgrade_to_2_3_1()
     drop_func_collation()
+    update_vfunc_format()
 end

 --------------------------------------------------------------------------------
diff --git a/test/box-py/bootstrap.result b/test/box-py/bootstrap.result
index 938a7631e..56bb43872 100644
--- a/test/box-py/bootstrap.result
+++ b/test/box-py/bootstrap.result
@@ -63,7 +63,14 @@ box.space._space:select{}
         'type': 'string'}, {'name': 'last_altered', 'type': 'string'}]]
   - [297, 1, '_vfunc', 'sysview', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'owner',
         'type': 'unsigned'}, {'name': 'name', 'type': 'string'}, {'name': 'setuid',
-        'type': 'unsigned'}]]
+        'type': 'unsigned'}, {'name': 'language', 'type': 'string'}, {'name': 'body',
+        'type': 'string'}, {'name': 'routine_type', 'type': 'string'}, {'name': 'param_list',
+        'type': 'array'}, {'name': 'returns', 'type': 'string'}, {'name': 'aggregate',
+        'type': 'string'}, {'name': 'sql_data_access', 'type': 'string'}, {'name': 'is_deterministic',
+        'type': 'boolean'}, {'name': 'is_sandboxed', 'type': 'boolean'}, {'name': 'is_null_call',
+        'type': 'boolean'}, {'name': 'exports', 'type': 'array'}, {'name': 'opts',
+        'type': 'map'}, {'name': 'comment', 'type': 'string'}, {'name': 'created',
+        'type': 'string'}, {'name': 'last_altered', 'type': 'string'}]]
   - [304, 1, '_user', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'owner',
         'type': 'unsigned'}, {'name': 'name', 'type': 'string'}, {'name': 'type',
         'type': 'string'}, {'name': 'auth', 'type': 'map'}]]
diff --git a/test/sql/gh-4666-sql-select-from-vfunc.result b/test/sql/gh-4666-sql-select-from-vfunc.result
new file mode 100644
index 000000000..16876e740
--- /dev/null
+++ b/test/sql/gh-4666-sql-select-from-vfunc.result
@@ -0,0 +1,19 @@
+test_run = require('test_run').new()
+---
+...
+engine = test_run:get_cfg('engine')
+---
+...
+box.execute('pragma sql_default_engine=\''..engine..'\'')
+---
+- row_count: 0
+...
+-- Make sure assertion does not fail
+box.execute([[select count(*)&0 from "_vfunc";]])
+---
+- metadata:
+  - name: count(*)&0
+    type: integer
+  rows:
+  - [0]
+...
diff --git a/test/sql/gh-4666-sql-select-from-vfunc.test.lua b/test/sql/gh-4666-sql-select-from-vfunc.test.lua
new file mode 100644
index 000000000..be227d119
--- /dev/null
+++ b/test/sql/gh-4666-sql-select-from-vfunc.test.lua
@@ -0,0 +1,7 @@
+test_run = require('test_run').new()
+engine = test_run:get_cfg('engine')
+box.execute('pragma sql_default_engine=\''..engine..'\'')
+
+-- Make sure assertion does not fail
+
+box.execute([[select count(*)&0 from "_vfunc";]])
--
2.21.0 (Apple Git-122.2)

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-01-16  8:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-10  7:40 [Tarantool-patches] [PATCH] sql: fix assertion fail when selecting from _vfunc Chris Sosnin
2020-01-15 17:29 ` Nikita Pettik
2020-01-16  8:10   ` Chris Sosnin
  -- strict thread matches above, loose matches on Subject: below --
2019-12-17 10:26 Chris Sosnin
2019-12-20 21:10 ` Vladislav Shpilevoy
2019-12-21 18:57   ` Chris Sosnin
2019-12-22 15:00     ` Vladislav Shpilevoy

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