Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH v1 1/1] sql: fix segfault with check referencing new table
@ 2018-08-06 15:58 Kirill Shcherbatov
  2018-08-06 16:29 ` [tarantool-patches] " n.pettik
  2018-08-07 17:39 ` Kirill Yukhin
  0 siblings, 2 replies; 5+ messages in thread
From: Kirill Shcherbatov @ 2018-08-06 15:58 UTC (permalink / raw)
  To: tarantool-patches; +Cc: korablev, Kirill Shcherbatov

Starting with 9a54320 on tuple insertion in _space we
make sql_checks_resolve_space_def_reference for checks
if any. During executing on_replace_dd_space trigger
box_space_id_by_name that takes a look to _space space
returnes not-nullable value, but the same time space
object doesn't present in space chache and could not be
found with space_by_id.
Before 1.10 path 0ecabde merged to 2.0 as a part of 13df2b1
box_space_id_by_name returned BOX_ID_NIL because of
"multi-engine transaction error" that is not rased in same
situation now.

Closes #3611.
---
Branch: http://github.com/tarantool/tarantool/tree/kshch/gh-3611-subquery-with-self-reference-check
Issue: https://github.com/tarantool/tarantool/issues/3611

 src/box/sql/select.c     | 5 ++---
 test/sql/checks.result   | 8 ++++++++
 test/sql/checks.test.lua | 4 ++++
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index d824b8b..6738ba5 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -4817,14 +4817,13 @@ selectExpander(Walker * pWalker, Select * p)
 				int space_id =
 					box_space_id_by_name(t_name,
 							     strlen(t_name));
-				if (space_id == BOX_ID_NIL) {
+				struct space *space = space_by_id(space_id);
+				if (space == NULL) {
 					sqlite3ErrorMsg(pParse,
 							"no such table: %s",
 							t_name);
 					return WRC_Abort;
 				}
-				struct space *space = space_by_id(space_id);
-
 				if (space->def->field_count <= 0) {
 					sqlite3ErrorMsg(pParse, "no format for"\
 							" space: %s", t_name);
diff --git a/test/sql/checks.result b/test/sql/checks.result
index 2a31b01..094367a 100644
--- a/test/sql/checks.result
+++ b/test/sql/checks.result
@@ -105,6 +105,14 @@ s = box.space._space:insert(t)
 ---
 - error: 'Wrong space options (field 5): invalid MsgPack map field ''name'' type'
 ...
+box.sql.execute("CREATE TABLE w2 (s1 INT PRIMARY KEY, CHECK ((SELECT COUNT(*) FROM w2) = 0));")
+---
+- error: 'Failed to create space ''W2'': SQL error: no such table: W2'
+...
+box.sql.execute("DROP TABLE w2;")
+---
+- error: 'no such table: W2'
+...
 test_run:cmd("clear filter")
 ---
 - true
diff --git a/test/sql/checks.test.lua b/test/sql/checks.test.lua
index 7ff78fe..bbd6747 100644
--- a/test/sql/checks.test.lua
+++ b/test/sql/checks.test.lua
@@ -43,4 +43,8 @@ format = {{name = 'X', type = 'unsigned'}}
 t = {513, 1, 'test', 'memtx', 0, opts, format}
 s = box.space._space:insert(t)
 
+
+box.sql.execute("CREATE TABLE w2 (s1 INT PRIMARY KEY, CHECK ((SELECT COUNT(*) FROM w2) = 0));")
+box.sql.execute("DROP TABLE w2;")
+
 test_run:cmd("clear filter")
-- 
2.7.4

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

* [tarantool-patches] Re: [PATCH v1 1/1] sql: fix segfault with check referencing new table
  2018-08-06 15:58 [tarantool-patches] [PATCH v1 1/1] sql: fix segfault with check referencing new table Kirill Shcherbatov
@ 2018-08-06 16:29 ` n.pettik
  2018-08-07  7:22   ` Kirill Shcherbatov
  2018-08-07 17:39 ` Kirill Yukhin
  1 sibling, 1 reply; 5+ messages in thread
From: n.pettik @ 2018-08-06 16:29 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Kirill Shcherbatov


> Starting with 9a54320 on tuple insertion in _space we

Starting from.

> make sql_checks_resolve_space_def_reference for checks

Not make, but execute I guess. 

> if any. During executing on_replace_dd_space trigger
> box_space_id_by_name that takes a look to _space space
> returnes not-nullable value, but the same time space

Typos: at the same time, returns, non-nullable
(but I guess not-null is likely to be more suitable).

> object doesn't present in space chache and could not be

Typos: isn't presented, cache, can’t be found by. 

> found with space_by_id.
> Before 1.10 path 0ecabde merged to 2.0 as a part of 13df2b1

Typo: patch, was merged.

> box_space_id_by_name returned BOX_ID_NIL because of

Used to return, due to.

> "multi-engine transaction error" that is not rased in same

Typo: is not raised.

> situation now.
> 
> diff --git a/test/sql/checks.test.lua b/test/sql/checks.test.lua
> index 7ff78fe..bbd6747 100644
> --- a/test/sql/checks.test.lua
> +++ b/test/sql/checks.test.lua
> @@ -43,4 +43,8 @@ format = {{name = 'X', type = 'unsigned'}}
> t = {513, 1, 'test', 'memtx', 0, opts, format}
> s = box.space._space:insert(t)
> 
> +

It would be better if you put reference to issue here
(sort of gh-xxxx: short description).

> +box.sql.execute("CREATE TABLE w2 (s1 INT PRIMARY KEY, CHECK ((SELECT COUNT(*) FROM w2) = 0));")
> +box.sql.execute("DROP TABLE w2;")
> +
> test_run:cmd("clear filter")
> -- 

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

* [tarantool-patches] Re: [PATCH v1 1/1] sql: fix segfault with check referencing new table
  2018-08-06 16:29 ` [tarantool-patches] " n.pettik
@ 2018-08-07  7:22   ` Kirill Shcherbatov
  2018-08-07 12:41     ` n.pettik
  0 siblings, 1 reply; 5+ messages in thread
From: Kirill Shcherbatov @ 2018-08-07  7:22 UTC (permalink / raw)
  To: tarantool-patches, Nikita Pettik

Hi! Thank you for comments. I've fixed spell mistakes.

======================================

Starting from 9a54320 on tuple insertion in _space we
execute sql_checks_resolve_space_def_reference for checks
if any on executing on_replace_dd_space trigger. Routine
box_space_id_by_name that takes a look to _space space
returns not-null value, at the same time space object
doesn't present in space cache and can't be found by
space_by_id.
Before 1.10 patch 0ecabde was merged to 2.0 as a part of
13df2b1 box_space_id_by_name used to return BOX_ID_NIL
due to "multi-engine transaction error" that is not raised
in same situation now.

Closes #3611.
---
 src/box/sql/select.c     |  5 ++---
 test/sql/checks.result   | 11 +++++++++++
 test/sql/checks.test.lua |  7 +++++++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index d824b8b..6738ba5 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -4817,14 +4817,13 @@ selectExpander(Walker * pWalker, Select * p)
 				int space_id =
 					box_space_id_by_name(t_name,
 							     strlen(t_name));
-				if (space_id == BOX_ID_NIL) {
+				struct space *space = space_by_id(space_id);
+				if (space == NULL) {
 					sqlite3ErrorMsg(pParse,
 							"no such table: %s",
 							t_name);
 					return WRC_Abort;
 				}
-				struct space *space = space_by_id(space_id);
-
 				if (space->def->field_count <= 0) {
 					sqlite3ErrorMsg(pParse, "no format for"\
 							" space: %s", t_name);
diff --git a/test/sql/checks.result b/test/sql/checks.result
index 2a31b01..3084d89 100644
--- a/test/sql/checks.result
+++ b/test/sql/checks.result
@@ -105,6 +105,17 @@ s = box.space._space:insert(t)
 ---
 - error: 'Wrong space options (field 5): invalid MsgPack map field ''name'' type'
 ...
+--
+-- gh-3611: Segfault on table creation with check referencing this table
+--
+box.sql.execute("CREATE TABLE w2 (s1 INT PRIMARY KEY, CHECK ((SELECT COUNT(*) FROM w2) = 0));")
+---
+- error: 'Failed to create space ''W2'': SQL error: no such table: W2'
+...
+box.sql.execute("DROP TABLE w2;")
+---
+- error: 'no such table: W2'
+...
 test_run:cmd("clear filter")
 ---
 - true
diff --git a/test/sql/checks.test.lua b/test/sql/checks.test.lua
index 7ff78fe..fb95809 100644
--- a/test/sql/checks.test.lua
+++ b/test/sql/checks.test.lua
@@ -43,4 +43,11 @@ format = {{name = 'X', type = 'unsigned'}}
 t = {513, 1, 'test', 'memtx', 0, opts, format}
 s = box.space._space:insert(t)
 
+
+--
+-- gh-3611: Segfault on table creation with check referencing this table
+--
+box.sql.execute("CREATE TABLE w2 (s1 INT PRIMARY KEY, CHECK ((SELECT COUNT(*) FROM w2) = 0));")
+box.sql.execute("DROP TABLE w2;")
+
 test_run:cmd("clear filter")
-- 
2.7.4

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

* [tarantool-patches] Re: [PATCH v1 1/1] sql: fix segfault with check referencing new table
  2018-08-07  7:22   ` Kirill Shcherbatov
@ 2018-08-07 12:41     ` n.pettik
  0 siblings, 0 replies; 5+ messages in thread
From: n.pettik @ 2018-08-07 12:41 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Kirill Shcherbatov

Ok, LGTM.

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

* [tarantool-patches] Re: [PATCH v1 1/1] sql: fix segfault with check referencing new table
  2018-08-06 15:58 [tarantool-patches] [PATCH v1 1/1] sql: fix segfault with check referencing new table Kirill Shcherbatov
  2018-08-06 16:29 ` [tarantool-patches] " n.pettik
@ 2018-08-07 17:39 ` Kirill Yukhin
  1 sibling, 0 replies; 5+ messages in thread
From: Kirill Yukhin @ 2018-08-07 17:39 UTC (permalink / raw)
  To: tarantool-patches; +Cc: korablev, Kirill Shcherbatov

Hello,
On 06 авг 18:58, Kirill Shcherbatov wrote:
> Starting with 9a54320 on tuple insertion in _space we
> make sql_checks_resolve_space_def_reference for checks
> if any. During executing on_replace_dd_space trigger
> box_space_id_by_name that takes a look to _space space
> returnes not-nullable value, but the same time space
> object doesn't present in space chache and could not be
> found with space_by_id.
> Before 1.10 path 0ecabde merged to 2.0 as a part of 13df2b1
> box_space_id_by_name returned BOX_ID_NIL because of
> "multi-engine transaction error" that is not rased in same
> situation now.
> 
> Closes #3611.
> ---
> Branch: http://github.com/tarantool/tarantool/tree/kshch/gh-3611-subquery-with-self-reference-check
> Issue: https://github.com/tarantool/tarantool/issues/3611
I've checked your patch into 2.0 branch.

--
Regards, Kirill Yukhin

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

end of thread, other threads:[~2018-08-07 17:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-06 15:58 [tarantool-patches] [PATCH v1 1/1] sql: fix segfault with check referencing new table Kirill Shcherbatov
2018-08-06 16:29 ` [tarantool-patches] " n.pettik
2018-08-07  7:22   ` Kirill Shcherbatov
2018-08-07 12:41     ` n.pettik
2018-08-07 17:39 ` Kirill Yukhin

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