From: Chris Sosnin <k.sosnin@tarantool.org> To: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH] sql: fix recursion assertion Date: Sun, 29 Dec 2019 15:27:49 +0300 [thread overview] Message-ID: <20191229122749.68537-1-k.sosnin@tarantool.org> (raw) 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)
reply other threads:[~2019-12-29 12:27 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20191229122749.68537-1-k.sosnin@tarantool.org \ --to=k.sosnin@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH] sql: fix recursion assertion' \ /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