[tarantool-patches] Re: [PATCH 0/3 v2] sql: add test for indexed char in sub subquery

roman roman.habibov at tarantool.org
Sun Dec 9 00:21:01 MSK 2018


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()




More information about the Tarantool-patches mailing list