Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] sql: fix assert in sql_type_result()
@ 2020-01-15 15:01 Nikita Pettik
  2020-01-20 22:25 ` Nikita Pettik
  0 siblings, 1 reply; 2+ messages in thread
From: Nikita Pettik @ 2020-01-15 15:01 UTC (permalink / raw)
  To: tarantool-patches

Accidentally, assert in sql_type_result() checking argument types was
changed in 64745b10c, so that now it may fail even on correct values.
Let's revert this change.

Closes #4728
---
Branch: https://github.com/tarantool/tarantool/tree/np/gh-4728-fix-assert-in-sql_type_result
Issue: https://github.com/tarantool/tarantool/issues/4728

 src/box/sql/expr.c      |  2 +-
 test/sql/types.result   | 27 +++++++++++++++++++++++++++
 test/sql/types.test.lua | 13 +++++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index 63808941d..bc2182446 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -392,7 +392,7 @@ sql_type_result(enum field_type lhs, enum field_type rhs)
 			return FIELD_TYPE_DOUBLE;
 		if (lhs == FIELD_TYPE_INTEGER || rhs == FIELD_TYPE_INTEGER)
 			return FIELD_TYPE_INTEGER;
-		assert(lhs == FIELD_TYPE_UNSIGNED &&
+		assert(lhs == FIELD_TYPE_UNSIGNED ||
 		       rhs == FIELD_TYPE_UNSIGNED);
 		return FIELD_TYPE_UNSIGNED;
 	}
diff --git a/test/sql/types.result b/test/sql/types.result
index ac4c91e32..f0c34b6fa 100644
--- a/test/sql/types.result
+++ b/test/sql/types.result
@@ -2133,3 +2133,30 @@ box.execute("SELECT d, TYPEOF(d) FROM t5;")
   - [5.5, 'double']
   - [6000000, 'double']
 ...
+-- gh-4728: make sure that given query doesn't result in
+-- assertion fault.
+--
+s = box.schema.space.create('s')
+---
+...
+_ = s:create_index('pk')
+---
+...
+s:format({ \
+    [1] = {name = 'id', type = 'unsigned'}, \
+    [2] = {name = 'v', type = 'string', is_nullable = true}, \
+})
+---
+...
+box.execute([[SELECT * FROM "s" WHERE "id" = ?;]])
+---
+- metadata:
+  - name: id
+    type: unsigned
+  - name: v
+    type: string
+  rows: []
+...
+s:drop()
+---
+...
diff --git a/test/sql/types.test.lua b/test/sql/types.test.lua
index c677b27cb..bd14b342d 100644
--- a/test/sql/types.test.lua
+++ b/test/sql/types.test.lua
@@ -474,3 +474,16 @@ box.execute("SELECT 3e3, typeof(3e3);")
 box.execute("CREATE TABLE t5 (d DOUBLE PRIMARY KEY);")
 box.execute("INSERT INTO t5 VALUES (4), (5.5), (6e6);")
 box.execute("SELECT d, TYPEOF(d) FROM t5;")
+
+-- gh-4728: make sure that given query doesn't result in
+-- assertion fault.
+--
+s = box.schema.space.create('s')
+_ = s:create_index('pk')
+s:format({ \
+    [1] = {name = 'id', type = 'unsigned'}, \
+    [2] = {name = 'v', type = 'string', is_nullable = true}, \
+})
+
+box.execute([[SELECT * FROM "s" WHERE "id" = ?;]])
+s:drop()
-- 
2.15.1

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

* Re: [Tarantool-patches] [PATCH] sql: fix assert in sql_type_result()
  2020-01-15 15:01 [Tarantool-patches] [PATCH] sql: fix assert in sql_type_result() Nikita Pettik
@ 2020-01-20 22:25 ` Nikita Pettik
  0 siblings, 0 replies; 2+ messages in thread
From: Nikita Pettik @ 2020-01-20 22:25 UTC (permalink / raw)
  To: tarantool-patches

On 15 Jan 18:01, Nikita Pettik wrote:
> Accidentally, assert in sql_type_result() checking argument types was
> changed in 64745b10c, so that now it may fail even on correct values.
> Let's revert this change.
> 
> Closes #4728
> ---
> Branch: https://github.com/tarantool/tarantool/tree/np/gh-4728-fix-assert-in-sql_type_result
> Issue: https://github.com/tarantool/tarantool/issues/4728

Pushed to master and 2.2 as trivial
 
>  src/box/sql/expr.c      |  2 +-
>  test/sql/types.result   | 27 +++++++++++++++++++++++++++
>  test/sql/types.test.lua | 13 +++++++++++++
>  3 files changed, 41 insertions(+), 1 deletion(-)
> 
> diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
> index 63808941d..bc2182446 100644
> --- a/src/box/sql/expr.c
> +++ b/src/box/sql/expr.c
> @@ -392,7 +392,7 @@ sql_type_result(enum field_type lhs, enum field_type rhs)
>  			return FIELD_TYPE_DOUBLE;
>  		if (lhs == FIELD_TYPE_INTEGER || rhs == FIELD_TYPE_INTEGER)
>  			return FIELD_TYPE_INTEGER;
> -		assert(lhs == FIELD_TYPE_UNSIGNED &&
> +		assert(lhs == FIELD_TYPE_UNSIGNED ||
>  		       rhs == FIELD_TYPE_UNSIGNED);
>  		return FIELD_TYPE_UNSIGNED;
>  	}
> diff --git a/test/sql/types.result b/test/sql/types.result
> index ac4c91e32..f0c34b6fa 100644
> --- a/test/sql/types.result
> +++ b/test/sql/types.result
> @@ -2133,3 +2133,30 @@ box.execute("SELECT d, TYPEOF(d) FROM t5;")
>    - [5.5, 'double']
>    - [6000000, 'double']
>  ...
> +-- gh-4728: make sure that given query doesn't result in
> +-- assertion fault.
> +--
> +s = box.schema.space.create('s')
> +---
> +...
> +_ = s:create_index('pk')
> +---
> +...
> +s:format({ \
> +    [1] = {name = 'id', type = 'unsigned'}, \
> +    [2] = {name = 'v', type = 'string', is_nullable = true}, \
> +})
> +---
> +...
> +box.execute([[SELECT * FROM "s" WHERE "id" = ?;]])
> +---
> +- metadata:
> +  - name: id
> +    type: unsigned
> +  - name: v
> +    type: string
> +  rows: []
> +...
> +s:drop()
> +---
> +...
> diff --git a/test/sql/types.test.lua b/test/sql/types.test.lua
> index c677b27cb..bd14b342d 100644
> --- a/test/sql/types.test.lua
> +++ b/test/sql/types.test.lua
> @@ -474,3 +474,16 @@ box.execute("SELECT 3e3, typeof(3e3);")
>  box.execute("CREATE TABLE t5 (d DOUBLE PRIMARY KEY);")
>  box.execute("INSERT INTO t5 VALUES (4), (5.5), (6e6);")
>  box.execute("SELECT d, TYPEOF(d) FROM t5;")
> +
> +-- gh-4728: make sure that given query doesn't result in
> +-- assertion fault.
> +--
> +s = box.schema.space.create('s')
> +_ = s:create_index('pk')
> +s:format({ \
> +    [1] = {name = 'id', type = 'unsigned'}, \
> +    [2] = {name = 'v', type = 'string', is_nullable = true}, \
> +})
> +
> +box.execute([[SELECT * FROM "s" WHERE "id" = ?;]])
> +s:drop()
> -- 
> 2.15.1
> 

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

end of thread, other threads:[~2020-01-20 22:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15 15:01 [Tarantool-patches] [PATCH] sql: fix assert in sql_type_result() Nikita Pettik
2020-01-20 22:25 ` Nikita Pettik

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