Tarantool development patches archive
 help / color / mirror / Atom feed
* [PATCH 0/3 v2] sql: add test for indexed char in sub subquery
@ 2018-12-04 23:47 Roman Khabibov
  2018-12-04 23:47 ` [PATCH 1/3 v2] sql: store CHAR|VARCHAR len as integer, not type_def Roman Khabibov
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Roman Khabibov @ 2018-12-04 23:47 UTC (permalink / raw)
  To: tarantool-patches; +Cc: vdavydov.dev

Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-3580-err-msg-pathjoin
Issue: https://github.com/tarantool/tarantool/issues/3580

Roman Khabibov (2):
  sql: add CHAR description without length
  sql: add test for indexed char in sub subquery

Vladislav Shpilevoy (1):
  sql: store CHAR|VARCHAR len as integer, not type_def

 src/box/sql/parse.y           | 18 +++++--
 test/sql-tap/select6.test.lua | 91 ++++++++++++++++++++++++++++++++++-
 test/sql-tap/table.test.lua   | 47 +++++++++++++++++-
 3 files changed, 151 insertions(+), 5 deletions(-)

-- 
2.19.1

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

* [PATCH 1/3 v2] sql: store CHAR|VARCHAR len as integer, not type_def
  2018-12-04 23:47 [PATCH 0/3 v2] sql: add test for indexed char in sub subquery Roman Khabibov
@ 2018-12-04 23:47 ` Roman Khabibov
  2018-12-04 23:47 ` [PATCH 2/3 v2] sql: add CHAR description without length Roman Khabibov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Roman Khabibov @ 2018-12-04 23:47 UTC (permalink / raw)
  To: tarantool-patches; +Cc: vdavydov.dev, Vladislav Shpilevoy

From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>

Length is just an integer, part of a type, not a
whole type.
---
 src/box/sql/parse.y | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index 6dfc81f70..5f64bfe8c 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -1485,13 +1485,13 @@ typedef(A) ::= DATE . { A.type = AFFINITY_REAL; }
 typedef(A) ::= TIME . { A.type = AFFINITY_REAL; }
 typedef(A) ::= DATETIME . { A.type = AFFINITY_REAL; }
 
-%type char_len_typedef {struct type_def}
-typedef(A) ::= CHAR|VARCHAR char_len_typedef(B) . {
+%type char_len {int}
+typedef(A) ::= CHAR|VARCHAR char_len(B) . {
   A.type = AFFINITY_TEXT;
   (void) B;
 }
 
-char_len_typedef(A) ::= LP INTEGER(B) RP . {
+char_len(A) ::= LP INTEGER(B) RP . {
   (void) A;
   (void) B;
 }
-- 
2.19.1

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

* [PATCH 2/3 v2] sql: add CHAR description without length
  2018-12-04 23:47 [PATCH 0/3 v2] sql: add test for indexed char in sub subquery Roman Khabibov
  2018-12-04 23:47 ` [PATCH 1/3 v2] sql: store CHAR|VARCHAR len as integer, not type_def Roman Khabibov
@ 2018-12-04 23:47 ` Roman Khabibov
  2018-12-04 23:47 ` [PATCH 3/3 v2] sql: add test for indexed char in sub subquery Roman Khabibov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Roman Khabibov @ 2018-12-04 23:47 UTC (permalink / raw)
  To: tarantool-patches; +Cc: vdavydov.dev

Fix an ability to describe CHAR without specifying the
length as it is allowed by standard. It was
accidentally broken by this commit:
7752cdfd31f9956a4d6bb0f306c561a0ac73e7ab

Needed for #3616
---
 src/box/sql/parse.y         | 16 +++++++++++--
 test/sql-tap/table.test.lua | 47 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index 5f64bfe8c..f5e86fba1 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -1486,12 +1486,24 @@ typedef(A) ::= TIME . { A.type = AFFINITY_REAL; }
 typedef(A) ::= DATETIME . { A.type = AFFINITY_REAL; }
 
 %type char_len {int}
-typedef(A) ::= CHAR|VARCHAR char_len(B) . {
+typedef(A) ::= CHAR char_len(B) . {
   A.type = AFFINITY_TEXT;
   (void) B;
 }
 
-char_len(A) ::= LP INTEGER(B) RP . {
+%type vchar_len {int}
+typedef(A) ::= VARCHAR vchar_len(B) . {
+  A.type = AFFINITY_TEXT;
+  (void) B;
+}
+
+char_len(A) ::=  . {
+  (void) A;
+}
+
+char_len(A) ::=  vchar_len(A) .
+
+vchar_len(A) ::= LP INTEGER(B) RP . {
   (void) A;
   (void) B;
 }
diff --git a/test/sql-tap/table.test.lua b/test/sql-tap/table.test.lua
index 7fd9bac9f..71645e2e2 100755
--- a/test/sql-tap/table.test.lua
+++ b/test/sql-tap/table.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(74)
+test:plan(78)
 
 --!./tcltestrunner.lua
 -- 2001 September 15
@@ -1393,4 +1393,49 @@ test:do_execsql_test(
 
         -- </check-22.cleanup>
     })
+
+-- gh-3616 Add char type without length in definitions.
+
+test:do_execsql_test(
+    "table-23.1",
+    [[
+        CREATE TABLE T23(
+           id INT PRIMARY KEY,
+           u CHAR
+        );
+    ]], {
+        -- <table-23.2>
+
+        -- </table-23.2>
+    })
+
+test:do_execsql_test(
+    "table-23.2",
+    [[
+        INSERT INTO T23 VALUES (1, 'a'), (2, 'b');
+    ]], {
+        -- <table-23.2>
+
+        -- </table-23.2>
+    })
+
+test:do_execsql_test(
+    "table-23.3",
+    [[
+        SELECT u FROM T23;
+    ]], {
+        -- <table-23.3>
+        "a","b"
+        -- </table-23.3>
+    })
+
+test:do_execsql_test(
+    "check-23.cleanup",
+    [[
+        DROP TABLE IF EXISTS t23;
+    ]], {
+        -- <check-23.cleanup>
+
+        -- </check-23.cleanup>
+    })
 test:finish_test()
-- 
2.19.1

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

* [PATCH 3/3 v2] sql: add test for indexed char in sub subquery
  2018-12-04 23:47 [PATCH 0/3 v2] sql: add test for indexed char in sub subquery Roman Khabibov
  2018-12-04 23:47 ` [PATCH 1/3 v2] sql: store CHAR|VARCHAR len as integer, not type_def Roman Khabibov
  2018-12-04 23:47 ` [PATCH 2/3 v2] sql: add CHAR description without length Roman Khabibov
@ 2018-12-04 23:47 ` Roman Khabibov
  2018-12-05 20:35 ` [tarantool-patches] [PATCH 0/3 " Vladislav Shpilevoy
  2018-12-14  5:47 ` [tarantool-patches] " Kirill Yukhin
  4 siblings, 0 replies; 12+ messages in thread
From: Roman Khabibov @ 2018-12-04 23:47 UTC (permalink / raw)
  To: tarantool-patches; +Cc: vdavydov.dev

Add test to check result for indexed char in sub subquery.

Closes #3616
---
 test/sql-tap/select6.test.lua | 91 ++++++++++++++++++++++++++++++++++-
 1 file changed, 90 insertions(+), 1 deletion(-)

diff --git a/test/sql-tap/select6.test.lua b/test/sql-tap/select6.test.lua
index 6fdb4195e..a1fadb631 100755
--- a/test/sql-tap/select6.test.lua
+++ b/test/sql-tap/select6.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(83)
+test:plan(88)
 
 --!./tcltestrunner.lua
 -- 2001 September 15
@@ -1052,5 +1052,94 @@ test:do_execsql_test(
         -- </11.100>
     })
 
+-- gh-3616 Check result for indexed char in sub subquery.
+
+test:do_execsql_test(
+    12.1,
+    [[
+        DROP TABLE t1;
+        DROP TABLE t2;
+        CREATE TABLE t1 (s1 INT PRIMARY KEY, u CHAR UNIQUE);
+        CREATE TABLE t2 (s1 INT PRIMARY KEY, u CHAR);
+        INSERT INTO t1 VALUES (1,'');
+        INSERT INTO t2 VALUES (1,'');
+        SELECT COUNT(*) FROM t1 WHERE u IN
+                (SELECT u FROM t2 WHERE u IN (SELECT u FROM t1));
+    ]], {
+        -- <12.1>
+        1
+        -- </12.1>
+    })
+
+test:do_execsql_test(
+    12.2,
+    [[
+        DROP TABLE t1;
+        DROP TABLE t2;
+        CREATE TABLE t1 (s1 INT PRIMARY KEY, u CHAR);
+        CREATE TABLE t2 (s1 INT PRIMARY KEY, u CHAR);
+        INSERT INTO t1 VALUES (1,'');
+        INSERT INTO t2 VALUES (1,'');
+        SELECT COUNT(*) FROM t1 WHERE u IN
+                (SELECT u FROM t2 WHERE u IN (SELECT u FROM t1));
+    ]], {
+        -- <12.2>
+        1
+        -- </12.2>
+    })
+
+test:do_execsql_test(
+    12.3,
+    [[
+        DROP TABLE t1;
+        DROP TABLE t2;
+        CREATE TABLE t1 (s1 INT PRIMARY KEY, u INT UNIQUE);
+        CREATE TABLE t2 (s1 INT PRIMARY KEY, u INT);
+        INSERT INTO t1 VALUES (1, 0);
+        INSERT INTO t2 VALUES (1, 0);
+        SELECT COUNT(*) FROM t1 WHERE u IN
+                (SELECT u FROM t2 WHERE u IN (SELECT u FROM t1));
+    ]], {
+        -- <12.3>
+        1
+        -- </12.3>
+    })
+
+test:do_execsql_test(
+    12.4,
+    [[
+        DROP TABLE t1;
+        DROP TABLE t2;
+        CREATE TABLE t1 (s1 INT PRIMARY KEY, u INT);
+        CREATE TABLE t2 (s1 INT PRIMARY KEY, u INT);
+        INSERT INTO t1 VALUES (1, 0);
+        INSERT INTO t2 VALUES (1, 0);
+        SELECT COUNT(*) FROM t1 WHERE u IN
+                (SELECT u FROM t2 WHERE u IN (SELECT u FROM t1));
+    ]], {
+        -- <12.4>
+        1
+        -- </12.4>
+    })
+
+test:do_execsql_test(
+    12.5,
+    [[
+        DROP TABLE t1;
+        DROP TABLE t2;
+        CREATE TABLE t1 (s1 INT PRIMARY KEY, u INT);
+        CREATE TABLE t2 (s1 INT PRIMARY KEY, u INT);
+        INSERT INTO t1 VALUES (1, 0);
+        INSERT INTO t2 VALUES (1, 1);
+        SELECT COUNT(*) FROM t1 WHERE u IN
+                (SELECT u FROM t2 WHERE u IN (SELECT u FROM t1));
+        DROP TABLE t1;
+        DROP TABLE t2;
+    ]], {
+        -- <12.5>
+        0
+        -- </12.5>
+    })
+
 test:finish_test()
 
-- 
2.19.1

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

* Re: [tarantool-patches] [PATCH 0/3 v2] sql: add test for indexed char in sub subquery
  2018-12-04 23:47 [PATCH 0/3 v2] sql: add test for indexed char in sub subquery Roman Khabibov
                   ` (2 preceding siblings ...)
  2018-12-04 23:47 ` [PATCH 3/3 v2] sql: add test for indexed char in sub subquery Roman Khabibov
@ 2018-12-05 20:35 ` Vladislav Shpilevoy
  2018-12-07 11:20   ` [tarantool-patches] " n.pettik
  2018-12-14  5:47 ` [tarantool-patches] " Kirill Yukhin
  4 siblings, 1 reply; 12+ messages in thread
From: Vladislav Shpilevoy @ 2018-12-05 20:35 UTC (permalink / raw)
  To: tarantool-patches, Roman Khabibov, Nikita Pettik; +Cc: vdavydov.dev

Vova, please, ignore. It was accidentally sent to you.

Nikita, please, review.

On 05/12/2018 02:47, Roman Khabibov wrote:
> Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-3580-err-msg-pathjoin
> Issue: https://github.com/tarantool/tarantool/issues/3580
> 
> Roman Khabibov (2):
>    sql: add CHAR description without length
>    sql: add test for indexed char in sub subquery
> 
> Vladislav Shpilevoy (1):
>    sql: store CHAR|VARCHAR len as integer, not type_def
> 
>   src/box/sql/parse.y           | 18 +++++--
>   test/sql-tap/select6.test.lua | 91 ++++++++++++++++++++++++++++++++++-
>   test/sql-tap/table.test.lua   | 47 +++++++++++++++++-
>   3 files changed, 151 insertions(+), 5 deletions(-)
> 

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

* [tarantool-patches] Re: [PATCH 0/3 v2] sql: add test for indexed char in sub subquery
  2018-12-05 20:35 ` [tarantool-patches] [PATCH 0/3 " Vladislav Shpilevoy
@ 2018-12-07 11:20   ` n.pettik
  2018-12-07 11:27     ` Vladislav Shpilevoy
                       ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: n.pettik @ 2018-12-07 11:20 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Roman Khabibov, Vladislav Shpilevoy



> On 5 Dec 2018, at 23:35, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> wrote:
> 
> Vova, please, ignore. It was accidentally sent to you.
> 
> Nikita, please, review.

I didn’t receive mail since there were issues with our mailing list,
so I looked at patch-set on GitHub.

> 
> On 05/12/2018 02:47, Roman Khabibov wrote:
>> Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-3580-err-msg-pathjoin
>> Issue: https://github.com/tarantool/tarantool/issues/3580
>> Roman Khabibov (2):
>>   sql: add CHAR description without length


>     Fix an ability to describe CHAR without specifying the

Not ‘fix’ but rather ‘add’. Otherwise, it sounds wierd.

>     length as it is allowed by standard. It was
>     accidentally broken by this commit:
>     7752cdfd31f9956a4d6bb0f306c561a0ac73e7ab
>     
>     Needed for #3616

It is not needed for #3616 - this commit and issue are not connected.
Issue disappeared after static types were introduced. It is ok that
you added test case on this issue, but these two problems are not related.

Consider refactoring:

diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index f5e86fba1..d56fce451 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -1485,26 +1485,22 @@ typedef(A) ::= DATE . { A.type = AFFINITY_REAL; }
 typedef(A) ::= TIME . { A.type = AFFINITY_REAL; }
 typedef(A) ::= DATETIME . { A.type = AFFINITY_REAL; }
 
-%type char_len {int}
-typedef(A) ::= CHAR char_len(B) . {
+typedef(A) ::= CHAR . {
   A.type = AFFINITY_TEXT;
-  (void) B;
 }
 
-%type vchar_len {int}
-typedef(A) ::= VARCHAR vchar_len(B) . {
-  A.type = AFFINITY_TEXT;
+char_len(A) ::= LP INTEGER(B) RP . {
+  (void) A;
   (void) B;
 }
 
-char_len(A) ::=  . {
-  (void) A;
+typedef(A) ::= CHAR char_len(B) . {
+  A.type = AFFINITY_TEXT;
+  (void) B;
 }
 
-char_len(A) ::=  vchar_len(A) .
-
-vchar_len(A) ::= LP INTEGER(B) RP . {
-  (void) A;
+typedef(A) ::= VARCHAR char_len(B) . {
+  A.type = AFFINITY_TEXT;
   (void) B;
 }

In this case code looks a bit more straightforward IMHO.

>>   sql: add test for indexed char in sub subquery

You don’t need to drop and re-create table t2 -
it doesn’t change in half cases. You should drop it
only when you change format of table, but in other
cases it doesn’t affect anything.

>> Vladislav Shpilevoy (1):
>>   sql: store CHAR|VARCHAR len as integer, not type_def

This is OK.

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

* [tarantool-patches] Re: [PATCH 0/3 v2] sql: add test for indexed char in sub subquery
  2018-12-07 11:20   ` [tarantool-patches] " n.pettik
@ 2018-12-07 11:27     ` Vladislav Shpilevoy
  2018-12-07 15:59       ` n.pettik
  2018-12-08 16:49     ` roman
  2018-12-08 21:21     ` roman
  2 siblings, 1 reply; 12+ messages in thread
From: Vladislav Shpilevoy @ 2018-12-07 11:27 UTC (permalink / raw)
  To: n.pettik, tarantool-patches; +Cc: Roman Khabibov



On 07/12/2018 14:20, n.pettik wrote:
> 
> 
>> On 5 Dec 2018, at 23:35, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> wrote:
>>
>> Vova, please, ignore. It was accidentally sent to you.
>>
>> Nikita, please, review.
> 
> I didn’t receive mail since there were issues with our mailing list,
> so I looked at patch-set on GitHub.
> 
>>
>> On 05/12/2018 02:47, Roman Khabibov wrote:
>>> Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-3580-err-msg-pathjoin
>>> Issue: https://github.com/tarantool/tarantool/issues/3580
>>> Roman Khabibov (2):
>>>    sql: add CHAR description without length
> 
> 
>>      Fix an ability to describe CHAR without specifying the
> 
> Not ‘fix’ but rather ‘add’. Otherwise, it sounds wierd.
> 
>>      length as it is allowed by standard. It was
>>      accidentally broken by this commit:
>>      7752cdfd31f9956a4d6bb0f306c561a0ac73e7ab
>>      
>>      Needed for #3616
> 
> It is not needed for #3616 - this commit and issue are not connected.
> Issue disappeared after static types were introduced. It is ok that
> you added test case on this issue, but these two problems are not related.
> 
> Consider refactoring:
> 
> diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
> index f5e86fba1..d56fce451 100644
> --- a/src/box/sql/parse.y
> +++ b/src/box/sql/parse.y
> @@ -1485,26 +1485,22 @@ typedef(A) ::= DATE . { A.type = AFFINITY_REAL; }
>   typedef(A) ::= TIME . { A.type = AFFINITY_REAL; }
>   typedef(A) ::= DATETIME . { A.type = AFFINITY_REAL; }
>   
> -%type char_len {int}
> -typedef(A) ::= CHAR char_len(B) . {
> +typedef(A) ::= CHAR . {
>     A.type = AFFINITY_TEXT;
> -  (void) B;
>   }
>   
> -%type vchar_len {int}
> -typedef(A) ::= VARCHAR vchar_len(B) . {
> -  A.type = AFFINITY_TEXT;
> +char_len(A) ::= LP INTEGER(B) RP . {
> +  (void) A;
>     (void) B;
>   }
>   
> -char_len(A) ::=  . {
> -  (void) A;
> +typedef(A) ::= CHAR char_len(B) . {
> +  A.type = AFFINITY_TEXT;
> +  (void) B;
>   }
>   
> -char_len(A) ::=  vchar_len(A) .
> -
> -vchar_len(A) ::= LP INTEGER(B) RP . {
> -  (void) A;
> +typedef(A) ::= VARCHAR char_len(B) . {
> +  A.type = AFFINITY_TEXT;
>     (void) B;
>   }
> 
> In this case code looks a bit more straightforward IMHO.

I've tried this refactoring too but faced with
grammar 'features'. You can not define two rules
starting with the same prefix. Did you test it? Maybe
I was wrong?

> 
>>>    sql: add test for indexed char in sub subquery
> 
> You don’t need to drop and re-create table t2 -
> it doesn’t change in half cases. You should drop it
> only when you change format of table, but in other
> cases it doesn’t affect anything.
> 
>>> Vladislav Shpilevoy (1):
>>>    sql: store CHAR|VARCHAR len as integer, not type_def
> 
> This is OK.
> 

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

* [tarantool-patches] Re: [PATCH 0/3 v2] sql: add test for indexed char in sub subquery
  2018-12-07 11:27     ` Vladislav Shpilevoy
@ 2018-12-07 15:59       ` n.pettik
  0 siblings, 0 replies; 12+ messages in thread
From: n.pettik @ 2018-12-07 15:59 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Roman Khabibov, Vladislav Shpilevoy

[-- Attachment #1: Type: text/plain, Size: 2581 bytes --]



> On 7 Dec 2018, at 14:27, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> wrote:
> On 07/12/2018 14:20, n.pettik wrote:
>>> On 5 Dec 2018, at 23:35, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> wrote:
>>> 
>>> Vova, please, ignore. It was accidentally sent to you.
>>> 
>>> Nikita, please, review.
>> I didn’t receive mail since there were issues with our mailing list,
>> so I looked at patch-set on GitHub.
>>> 
>>> On 05/12/2018 02:47, Roman Khabibov wrote:
>>>> Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-3580-err-msg-pathjoin
>>>> Issue: https://github.com/tarantool/tarantool/issues/3580
>>>> Roman Khabibov (2):
>>>>   sql: add CHAR description without length
>>>     Fix an ability to describe CHAR without specifying the
>> Not ‘fix’ but rather ‘add’. Otherwise, it sounds wierd.
>>>     length as it is allowed by standard. It was
>>>     accidentally broken by this commit:
>>>     7752cdfd31f9956a4d6bb0f306c561a0ac73e7ab
>>>          Needed for #3616
>> It is not needed for #3616 - this commit and issue are not connected.
>> Issue disappeared after static types were introduced. It is ok that
>> you added test case on this issue, but these two problems are not related.
>> Consider refactoring:
>> diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
>> index f5e86fba1..d56fce451 100644
>> --- a/src/box/sql/parse.y
>> +++ b/src/box/sql/parse.y
>> @@ -1485,26 +1485,22 @@ typedef(A) ::= DATE . { A.type = AFFINITY_REAL; }
>>  typedef(A) ::= TIME . { A.type = AFFINITY_REAL; }
>>  typedef(A) ::= DATETIME . { A.type = AFFINITY_REAL; }
>>  -%type char_len {int}
>> -typedef(A) ::= CHAR char_len(B) . {
>> +typedef(A) ::= CHAR . {
>>    A.type = AFFINITY_TEXT;
>> -  (void) B;
>>  }
>>  -%type vchar_len {int}
>> -typedef(A) ::= VARCHAR vchar_len(B) . {
>> -  A.type = AFFINITY_TEXT;
>> +char_len(A) ::= LP INTEGER(B) RP . {
>> +  (void) A;
>>    (void) B;
>>  }
>>  -char_len(A) ::=  . {
>> -  (void) A;
>> +typedef(A) ::= CHAR char_len(B) . {
>> +  A.type = AFFINITY_TEXT;
>> +  (void) B;
>>  }
>>  -char_len(A) ::=  vchar_len(A) .
>> -
>> -vchar_len(A) ::= LP INTEGER(B) RP . {
>> -  (void) A;
>> +typedef(A) ::= VARCHAR char_len(B) . {
>> +  A.type = AFFINITY_TEXT;
>>    (void) B;
>>  }
>> In this case code looks a bit more straightforward IMHO.
> 
> I've tried this refactoring too but faced with
> grammar 'features'. You can not define two rules
> starting with the same prefix. Did you test it? Maybe
> I was wrong?

Yep, I tested - it works.


[-- Attachment #2: Type: text/html, Size: 8500 bytes --]

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

* [tarantool-patches] Re: [PATCH 0/3 v2] sql: add test for indexed char in sub subquery
  2018-12-07 11:20   ` [tarantool-patches] " n.pettik
  2018-12-07 11:27     ` Vladislav Shpilevoy
@ 2018-12-08 16:49     ` roman
  2018-12-08 21:21     ` roman
  2 siblings, 0 replies; 12+ messages in thread
From: roman @ 2018-12-08 16:49 UTC (permalink / raw)
  To: tarantool-patches, n.pettik; +Cc: Vladislav Shpilevoy

Hi! Thanks for review.
>> It is not needed for #3616 - this commit and issue are not connected.
>> Issue disappeared after static types were introduced. It is ok that
>> you added test case on this issue, but these two problems are not related.
Removed.
> Consider refactoring:
>
> diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
> index f5e86fba1..d56fce451 100644
> --- a/src/box/sql/parse.y
> +++ b/src/box/sql/parse.y
> @@ -1485,26 +1485,22 @@ typedef(A) ::= DATE . { A.type = AFFINITY_REAL; }
>   typedef(A) ::= TIME . { A.type = AFFINITY_REAL; }
>   typedef(A) ::= DATETIME . { A.type = AFFINITY_REAL; }
>   
> -%type char_len {int}
> -typedef(A) ::= CHAR char_len(B) . {
> +typedef(A) ::= CHAR . {
>     A.type = AFFINITY_TEXT;
> -  (void) B;
>   }
>   
> -%type vchar_len {int}
> -typedef(A) ::= VARCHAR vchar_len(B) . {
> -  A.type = AFFINITY_TEXT;
> +char_len(A) ::= LP INTEGER(B) RP . {
> +  (void) A;
>     (void) B;
>   }
>   
> -char_len(A) ::=  . {
> -  (void) A;
> +typedef(A) ::= CHAR char_len(B) . {
> +  A.type = AFFINITY_TEXT;
> +  (void) B;
>   }
>   
> -char_len(A) ::=  vchar_len(A) .
> -
> -vchar_len(A) ::= LP INTEGER(B) RP . {
> -  (void) A;
> +typedef(A) ::= VARCHAR char_len(B) . {
> +  A.type = AFFINITY_TEXT;
>     (void) B;
>   }
>
> In this case code looks a bit more straightforward IMHO.

Refactored.


>>>    sql: add test for indexed char in sub subquery
> You don’t need to drop and re-create table t2 -
> it doesn’t change in half cases. You should drop it
> only when you change format of table, but in other
> cases it doesn’t affect anything.
Fixed.

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

* [tarantool-patches] Re: [PATCH 0/3 v2] sql: add test for indexed char in sub subquery
  2018-12-07 11:20   ` [tarantool-patches] " n.pettik
  2018-12-07 11:27     ` Vladislav Shpilevoy
  2018-12-08 16:49     ` roman
@ 2018-12-08 21:21     ` roman
  2018-12-08 21:56       ` n.pettik
  2 siblings, 1 reply; 12+ messages in thread
From: roman @ 2018-12-08 21:21 UTC (permalink / raw)
  To: tarantool-patches, n.pettik; +Cc: Vladislav Shpilevoy

Sorry. Forgot to attach diff.

diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y

index 6dfc81f70..50bb2ba01 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -1485,17 +1485,26 @@ typedef(A) ::= DATE . { A.type = AFFINITY_REAL; }
  typedef(A) ::= TIME . { A.type = AFFINITY_REAL; }
  typedef(A) ::= DATETIME . { A.type = AFFINITY_REAL; }

-%type char_len_typedef {struct type_def}
-typedef(A) ::= CHAR|VARCHAR char_len_typedef(B) . {
+%type char_len {int}
+typedef(A) ::= CHAR . {
    A.type = AFFINITY_TEXT;
-  (void) B;
  }

-char_len_typedef(A) ::= LP INTEGER(B) RP . {
+char_len(A) ::= LP INTEGER(B) RP . {
    (void) A;
    (void) B;
  }

+typedef(A) ::= CHAR char_len(B) . {
+  A.type = AFFINITY_TEXT;
+  (void) B;
+}
+
+typedef(A) ::= VARCHAR char_len(B) . {
+  A.type = AFFINITY_TEXT;
+  (void) B;
+}
+
  %type number_typedef {struct type_def}
  typedef(A) ::= number_typedef(A) .
  number_typedef(A) ::= FLOAT|REAL|DOUBLE . { A.type = AFFINITY_REAL; }
diff --git a/test/sql-tap/select6.test.lua b/test/sql-tap/select6.test.lua
index 6fdb4195e..9a0fe6efb 100755
--- a/test/sql-tap/select6.test.lua
+++ b/test/sql-tap/select6.test.lua
@@ -1,6 +1,6 @@
  #!/usr/bin/env tarantool
  test = require("sqltester")
-test:plan(83)
+test:plan(88)

  --!./tcltestrunner.lua
  -- 2001 September 15
@@ -1052,5 +1052,84 @@ test:do_execsql_test(
          -- </11.100>
      })

+-- gh-3616 Check result for indexed char in sub subquery.
+
+test:do_execsql_test(
+    12.1,
+    [[
+        DROP TABLE t1;
+        DROP TABLE t2;
+        CREATE TABLE t1 (s1 INT PRIMARY KEY, u CHAR UNIQUE);
+        CREATE TABLE t2 (s1 INT PRIMARY KEY, u CHAR);
+        INSERT INTO t1 VALUES (1,'');
+        INSERT INTO t2 VALUES (1,'');
+        SELECT COUNT(*) FROM t1 WHERE u IN
+                (SELECT u FROM t2 WHERE u IN (SELECT u FROM t1));
+    ]], {
+        -- <12.1>
+        1
+        -- </12.1>
+    })
+
+test:do_execsql_test(
+    12.2,
+    [[
+        DROP TABLE t1;
+        CREATE TABLE t1 (s1 INT PRIMARY KEY, u CHAR);
+        INSERT INTO t1 VALUES (1,'');
+        SELECT COUNT(*) FROM t1 WHERE u IN
+                (SELECT u FROM t2 WHERE u IN (SELECT u FROM t1));
+    ]], {
+        -- <12.2>
+        1
+        -- </12.2>
+    })
+
+test:do_execsql_test(
+    12.3,
+    [[
+        DROP TABLE t1;
+        DROP TABLE t2;
+        CREATE TABLE t1 (s1 INT PRIMARY KEY, u INT UNIQUE);
+        CREATE TABLE t2 (s1 INT PRIMARY KEY, u INT);
+        INSERT INTO t1 VALUES (1, 0);
+        INSERT INTO t2 VALUES (1, 0);
+        SELECT COUNT(*) FROM t1 WHERE u IN
+                (SELECT u FROM t2 WHERE u IN (SELECT u FROM t1));
+    ]], {
+        -- <12.3>
+        1
+        -- </12.3>
+    })
+
+test:do_execsql_test(
+    12.4,
+    [[
+        DROP TABLE t1;
+        CREATE TABLE t1 (s1 INT PRIMARY KEY, u INT);
+        INSERT INTO t1 VALUES (1, 0);
+        SELECT COUNT(*) FROM t1 WHERE u IN
+                (SELECT u FROM t2 WHERE u IN (SELECT u FROM t1));
+    ]], {
+        -- <12.4>
+        1
+        -- </12.4>
+    })
+
+test:do_execsql_test(
+    12.5,
+    [[
+        UPDATE t2
+          SET u = 1;
+        SELECT COUNT(*) FROM t1 WHERE u IN
+                (SELECT u FROM t2 WHERE u IN (SELECT u FROM t1));
+        DROP TABLE t1;
+        DROP TABLE t2;
+    ]], {
+        -- <12.5>
+        0
+        -- </12.5>
+    })
+
  test:finish_test()

diff --git a/test/sql-tap/table.test.lua b/test/sql-tap/table.test.lua
index 7fd9bac9f..71645e2e2 100755
--- a/test/sql-tap/table.test.lua
+++ b/test/sql-tap/table.test.lua
@@ -1,6 +1,6 @@
  #!/usr/bin/env tarantool
  test = require("sqltester")
-test:plan(74)
+test:plan(78)

  --!./tcltestrunner.lua
  -- 2001 September 15
@@ -1393,4 +1393,49 @@ test:do_execsql_test(

          -- </check-22.cleanup>
      })
+
+-- gh-3616 Add char type without length in definitions.
+
+test:do_execsql_test(
+    "table-23.1",
+    [[
+        CREATE TABLE T23(
+           id INT PRIMARY KEY,
+           u CHAR
+        );
+    ]], {
+        -- <table-23.2>
+
+        -- </table-23.2>
+    })
+
+test:do_execsql_test(
+    "table-23.2",
+    [[
+        INSERT INTO T23 VALUES (1, 'a'), (2, 'b');
+    ]], {
+        -- <table-23.2>
+
+        -- </table-23.2>
+    })
+
+test:do_execsql_test(
+    "table-23.3",
+    [[
+        SELECT u FROM T23;
+    ]], {
+        -- <table-23.3>
+        "a","b"
+        -- </table-23.3>
+    })
+
+test:do_execsql_test(
+    "check-23.cleanup",
+    [[
+        DROP TABLE IF EXISTS t23;
+    ]], {
+        -- <check-23.cleanup>
+
+        -- </check-23.cleanup>
+    })
  test:finish_test()

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

* [tarantool-patches] Re: [PATCH 0/3 v2] sql: add test for indexed char in sub subquery
  2018-12-08 21:21     ` roman
@ 2018-12-08 21:56       ` n.pettik
  0 siblings, 0 replies; 12+ messages in thread
From: n.pettik @ 2018-12-08 21:56 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Vladislav Shpilevoy, Roman Khabibov



> On 9 Dec 2018, at 00:21, roman <roman.habibov@tarantool.org> wrote:
> 
> Sorry. Forgot to attach diff.

LGTM

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

* Re: [tarantool-patches] [PATCH 0/3 v2] sql: add test for indexed char in sub subquery
  2018-12-04 23:47 [PATCH 0/3 v2] sql: add test for indexed char in sub subquery Roman Khabibov
                   ` (3 preceding siblings ...)
  2018-12-05 20:35 ` [tarantool-patches] [PATCH 0/3 " Vladislav Shpilevoy
@ 2018-12-14  5:47 ` Kirill Yukhin
  4 siblings, 0 replies; 12+ messages in thread
From: Kirill Yukhin @ 2018-12-14  5:47 UTC (permalink / raw)
  To: tarantool-patches; +Cc: vdavydov.dev

Hello,
On 05 Dec 02:47, Roman Khabibov wrote:
> Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-3580-err-msg-pathjoin
> Issue: https://github.com/tarantool/tarantool/issues/3580
> 
> Roman Khabibov (2):
>   sql: add CHAR description without length
>   sql: add test for indexed char in sub subquery
> 
> Vladislav Shpilevoy (1):
>   sql: store CHAR|VARCHAR len as integer, not type_def
> 
>  src/box/sql/parse.y           | 18 +++++--
>  test/sql-tap/select6.test.lua | 91 ++++++++++++++++++++++++++++++++++-
>  test/sql-tap/table.test.lua   | 47 +++++++++++++++++-
>  3 files changed, 151 insertions(+), 5 deletions(-)
I've checked your patchset into 2.1 branch.

--
Regards, Kirill Yukhin

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

end of thread, other threads:[~2018-12-14  5:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-04 23:47 [PATCH 0/3 v2] sql: add test for indexed char in sub subquery Roman Khabibov
2018-12-04 23:47 ` [PATCH 1/3 v2] sql: store CHAR|VARCHAR len as integer, not type_def Roman Khabibov
2018-12-04 23:47 ` [PATCH 2/3 v2] sql: add CHAR description without length Roman Khabibov
2018-12-04 23:47 ` [PATCH 3/3 v2] sql: add test for indexed char in sub subquery Roman Khabibov
2018-12-05 20:35 ` [tarantool-patches] [PATCH 0/3 " Vladislav Shpilevoy
2018-12-07 11:20   ` [tarantool-patches] " n.pettik
2018-12-07 11:27     ` Vladislav Shpilevoy
2018-12-07 15:59       ` n.pettik
2018-12-08 16:49     ` roman
2018-12-08 21:21     ` roman
2018-12-08 21:56       ` n.pettik
2018-12-14  5:47 ` [tarantool-patches] " Kirill Yukhin

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