Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] sql: fix recursion assertion
@ 2019-12-29 12:27 Chris Sosnin
  0 siblings, 0 replies; only message in thread
From: Chris Sosnin @ 2019-12-29 12:27 UTC (permalink / raw)
  To: tarantool-patches

The assertion in the body of region_truncate can fail
because select statement does not start transaction
and thus the GC is called too early. This leads to
the corruption of fiber's region. This patch fixes
this problem.

Closes #4504
---
 src/box/sql/parse.y                           |  2 +
 test/sql/gh-4504-recursion-assertion.result   | 45 +++++++++++++++++++
 test/sql/gh-4504-recursion-assertion.test.lua | 26 +++++++++++
 3 files changed, 73 insertions(+)
 create mode 100644 test/sql/gh-4504-recursion-assertion.result
 create mode 100644 test/sql/gh-4504-recursion-assertion.test.lua

diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index 89773eb1c..53ad43f81 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -457,6 +457,8 @@ cmd ::= select(X).  {
           sqlSelect(pParse, X, &dest);
   else
           sql_expr_extract_select(pParse, X);
+  /* Instruct SQL to initate Tarantool's transaction.  */
+  pParse->initiateTTrans = true;
   sql_select_delete(pParse->db, X);
 }
 
diff --git a/test/sql/gh-4504-recursion-assertion.result b/test/sql/gh-4504-recursion-assertion.result
new file mode 100644
index 000000000..014df80ef
--- /dev/null
+++ b/test/sql/gh-4504-recursion-assertion.result
@@ -0,0 +1,45 @@
+-- test-run result file version 2
+test_run = require('test_run').new()
+ | ---
+ | ...
+engine = test_run:get_cfg('engine')
+ | ---
+ | ...
+
+--
+-- Start transaction prior to SELECT query
+-- to make sure GC is called only after
+-- the whole statement is executed
+--
+box.schema.func.create('_C', {                     \
+    language = 'LUA',                              \
+    returns = 'unsigned',                          \
+    body = [[                                      \
+        function (i)                               \
+            local m = box.space._space:select()    \
+            return 0                               \
+        end                                        \
+    ]],                                            \
+    param_list = {'integer'},                      \
+    exports = {'LUA', 'SQL'},                      \
+    is_sandboxed = false,                          \
+    is_deterministic = true})
+ | ---
+ | ...
+
+box.execute([[WITH RECURSIVE x AS (SELECT 0 AS q, 1 UNION ALL \
+    SELECT q+1, _c(q) FROM x WHERE q < 1) SELECT * FROM x;]])
+ | ---
+ | - metadata:
+ |   - name: Q
+ |     type: integer
+ |   - name: '1'
+ |     type: integer
+ |   rows:
+ |   - [0, 1]
+ |   - [1, 0]
+ | ...
+
+box.schema.func.drop("_C")
+ | ---
+ | ...
diff --git a/test/sql/gh-4504-recursion-assertion.test.lua b/test/sql/gh-4504-recursion-assertion.test.lua
new file mode 100644
index 000000000..0ea5decad
--- /dev/null
+++ b/test/sql/gh-4504-recursion-assertion.test.lua
@@ -0,0 +1,26 @@
+test_run = require('test_run').new()
+engine = test_run:get_cfg('engine')
+
+--
+-- Start transaction prior to SELECT query
+-- to make sure GC is called only after
+-- the whole statement is executed
+--
+box.schema.func.create('_C', {                     \
+    language = 'LUA',                              \
+    returns = 'unsigned',                          \
+    body = [[                                      \
+        function (i)                               \
+            local m = box.space._space:select()    \
+            return 0                               \
+        end                                        \
+    ]],                                            \
+    param_list = {'integer'},                      \
+    exports = {'LUA', 'SQL'},                      \
+    is_sandboxed = false,                          \
+    is_deterministic = true})
+
+box.execute([[WITH RECURSIVE x AS (SELECT 0 AS q, 1 UNION ALL \
+    SELECT q+1, _c(q) FROM x WHERE q < 1) SELECT * FROM x;]])
+
+box.schema.func.drop("_C")
-- 
2.21.0 (Apple Git-122.2)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-12-29 12:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-29 12:27 [Tarantool-patches] [PATCH] sql: fix recursion assertion Chris Sosnin

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