github.com/dolthub/go-mysql-server@v0.18.0/enginetest/queries/logic_test_scripts.go (about)

     1  // Copyright 2023 Dolthub, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package queries
    16  
    17  import (
    18  	"github.com/dolthub/go-mysql-server/sql"
    19  	"github.com/dolthub/go-mysql-server/sql/types"
    20  )
    21  
    22  // SQLLogicJoinTests is a list of all the logic tests that are run against the sql engine.
    23  var SQLLogicJoinTests = []ScriptTest{
    24  	{
    25  		Name: "joining on different types panics",
    26  		SetUpScript: []string{
    27  			"CREATE TABLE foo (a INT, b INT, c FLOAT, d FLOAT);",
    28  			"INSERT INTO foo VALUES  (1, 1, 1, 1), (2, 2, 2, 2), (3, 3, 3, 3);",
    29  			"CREATE TABLE bar (a INT, b FLOAT, c FLOAT, d INT);",
    30  			"INSERT INTO bar VALUES (1, 1, 1, 1), (2, 2, 2, 2), (3, 3, 3, 3);",
    31  		},
    32  		Assertions: []ScriptTestAssertion{
    33  			{
    34  				// This panics somewhere in the memo
    35  				Skip:           true,
    36  				Query:          "SELECT * FROM foo JOIN bar ON max(foo.c) < 2",
    37  				ExpectedErrStr: "invalid use of group function",
    38  			},
    39  			{
    40  				// SQLLogicTests incorrectly reports this as an error
    41  				Query: "SELECT * FROM foo NATURAL JOIN bar",
    42  				Expected: []sql.Row{
    43  					{1, 1, 1.0, 1.0},
    44  					{2, 2, 2.0, 2.0},
    45  					{3, 3, 3.0, 3.0},
    46  				},
    47  			},
    48  			{
    49  				Query: "SELECT * FROM foo JOIN bar USING (b);",
    50  				Expected: []sql.Row{
    51  					{1, 1, 1.0, 1.0, 1, 1.0, 1},
    52  					{2, 2, 2.0, 2.0, 2, 2.0, 2},
    53  					{3, 3, 3.0, 3.0, 3, 3.0, 3},
    54  				},
    55  			},
    56  			{
    57  				Query: "SELECT * FROM foo JOIN bar USING (a, b);",
    58  				Expected: []sql.Row{
    59  					{1, 1, 1.0, 1.0, 1.0, 1},
    60  					{2, 2, 2.0, 2.0, 2.0, 2},
    61  					{3, 3, 3.0, 3.0, 3.0, 3},
    62  				},
    63  			},
    64  			{
    65  				Query: "SELECT * FROM foo JOIN bar USING (a, b, c);",
    66  				Expected: []sql.Row{
    67  					{1, 1, 1.0, 1.0, 1},
    68  					{2, 2, 2.0, 2.0, 2},
    69  					{3, 3, 3.0, 3.0, 3},
    70  				},
    71  			},
    72  			{
    73  				Query: "SELECT * FROM foo JOIN bar ON foo.b = bar.b;",
    74  				Expected: []sql.Row{
    75  					{1, 1, 1.0, 1.0, 1, 1.0, 1.0, 1},
    76  					{2, 2, 2.0, 2.0, 2, 2.0, 2.0, 2},
    77  					{3, 3, 3.0, 3.0, 3, 3.0, 3.0, 3},
    78  				},
    79  			},
    80  			{
    81  				Query: "SELECT * FROM foo JOIN bar ON foo.a = bar.a AND foo.b = bar.b;",
    82  				Expected: []sql.Row{
    83  					{1, 1, 1.0, 1.0, 1, 1.0, 1.0, 1},
    84  					{2, 2, 2.0, 2.0, 2, 2.0, 2.0, 2},
    85  					{3, 3, 3.0, 3.0, 3, 3.0, 3.0, 3},
    86  				},
    87  			},
    88  			{
    89  				Query: "SELECT * FROM foo, bar WHERE foo.b = bar.b;",
    90  				Expected: []sql.Row{
    91  					{1, 1, 1.0, 1.0, 1, 1.0, 1.0, 1},
    92  					{2, 2, 2.0, 2.0, 2, 2.0, 2.0, 2},
    93  					{3, 3, 3.0, 3.0, 3, 3.0, 3.0, 3},
    94  				},
    95  			},
    96  			{
    97  				Query: "SELECT * FROM foo, bar WHERE foo.a = bar.a AND foo.b = bar.b;",
    98  				Expected: []sql.Row{
    99  					{1, 1, 1.0, 1.0, 1, 1.0, 1.0, 1},
   100  					{2, 2, 2.0, 2.0, 2, 2.0, 2.0, 2},
   101  					{3, 3, 3.0, 3.0, 3, 3.0, 3.0, 3},
   102  				},
   103  			},
   104  		},
   105  	},
   106  	{
   107  		Name: "case insensitive join with using clause",
   108  		SetUpScript: []string{
   109  			"CREATE TABLE str1 (a INT PRIMARY KEY, s TEXT COLLATE utf8mb4_0900_ai_ci)",
   110  			"INSERT INTO str1 VALUES (1, 'a' COLLATE utf8mb4_0900_ai_ci), (2, 'A' COLLATE utf8mb4_0900_ai_ci), (3, 'c' COLLATE utf8mb4_0900_ai_ci), (4, 'D' COLLATE utf8mb4_0900_ai_ci)",
   111  			"CREATE TABLE str2 (a INT PRIMARY KEY, s TEXT COLLATE utf8mb4_0900_ai_ci)",
   112  			"INSERT INTO str2 VALUES (1, 'A' COLLATE utf8mb4_0900_ai_ci), (2, 'B' COLLATE utf8mb4_0900_ai_ci), (3, 'C' COLLATE utf8mb4_0900_ai_ci), (4, 'E' COLLATE utf8mb4_0900_ai_ci)",
   113  		},
   114  		Assertions: []ScriptTestAssertion{
   115  			{
   116  				Skip:  true,
   117  				Query: "SELECT s, str1.s, str2.s FROM str1 INNER JOIN str2 USING(s)",
   118  				Expected: []sql.Row{
   119  					{"A", "A", "A"},
   120  					{"a", "a", "A"},
   121  					{"c", "c", "C"},
   122  				},
   123  			},
   124  			{
   125  				Skip:  true,
   126  				Query: "SELECT s, str1.s, str2.s FROM str1 LEFT OUTER JOIN str2 USING(s)",
   127  				Expected: []sql.Row{
   128  					{"a", "a", "A"},
   129  					{"A", "A", "A"},
   130  					{"c", "c", "C"},
   131  					{"D", "D", nil},
   132  				},
   133  			},
   134  			{
   135  				Skip:  true,
   136  				Query: "SELECT s, str1.s, str2.s FROM str1 RIGHT OUTER JOIN str2 USING(s)",
   137  				Expected: []sql.Row{
   138  					{"A", "A", "A"},
   139  					{"A", "a", "A"},
   140  					{"B", nil, "B"},
   141  					{"C", "c", "C"},
   142  					{"E", nil, "E"},
   143  				},
   144  			},
   145  		},
   146  	},
   147  	{
   148  		Name: "values and rows",
   149  		SetUpScript: []string{
   150  			"CREATE TABLE xy (x INT PRIMARY KEY, y INT)",
   151  		},
   152  		Assertions: []ScriptTestAssertion{
   153  			{
   154  				// Syntax error
   155  				Skip:  true,
   156  				Query: "INSERT INTO xy (VALUES ROW(1, 1))",
   157  				Expected: []sql.Row{
   158  					{types.NewOkResult(1)},
   159  				},
   160  			},
   161  		},
   162  	},
   163  	{
   164  		Name: "using join",
   165  		SetUpScript: []string{
   166  			"CREATE TABLE abcd (a INT, b INT, c INT, d INT);",
   167  			"INSERT INTO abcd VALUES (1, 1, 1, 1), (2, 2, 2, 2);",
   168  			"CREATE TABLE dxby (d INT, x INT, b INT, y INT);",
   169  			"INSERT INTO dxby VALUES (2, 2, 2, 2), (3, 3, 3, 3);",
   170  		},
   171  		Assertions: []ScriptTestAssertion{
   172  			{
   173  				Query: "SELECT abcd.*, dxby.* FROM abcd INNER JOIN dxby USING (d, b);",
   174  				Expected: []sql.Row{
   175  					{2, 2, 2, 2, 2, 2, 2, 2},
   176  				},
   177  			},
   178  		},
   179  	},
   180  }
   181  
   182  // SQLLogicSubqueryTests is a list of all the logic tests that are run against the sql engine.
   183  var SQLLogicSubqueryTests = []ScriptTest{
   184  	{
   185  		Name: "exists, in, all, any subquery",
   186  		SetUpScript: []string{
   187  			"CREATE TABLE c (c_id INT PRIMARY KEY, bill TEXT);",
   188  			"CREATE TABLE o (o_id INT PRIMARY KEY, c_id INT, ship TEXT);",
   189  			"INSERT INTO c VALUES (1, 'CA'), (2, 'TX'), (3, 'MA'), (4, 'TX'), (5, NULL), (6, 'FL');",
   190  			"INSERT INTO o VALUES (10, 1, 'CA'), (20, 1, 'CA'), (30, 1, 'CA'), (40, 2, 'CA'), (50, 2, 'TX'), (60, 2, NULL), (70, 4, 'WY'), (80, 4, NULL), (90, 6, 'WA');",
   191  		},
   192  		Assertions: []ScriptTestAssertion{
   193  			{
   194  				Query: "SELECT * FROM c WHERE EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id);",
   195  				Expected: []sql.Row{
   196  					{1, "CA"},
   197  					{2, "TX"},
   198  					{4, "TX"},
   199  					{6, "FL"},
   200  				},
   201  			},
   202  			{
   203  				Query: "SELECT * FROM c WHERE NOT EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id);",
   204  				Expected: []sql.Row{
   205  					{3, "MA"},
   206  					{5, nil},
   207  				},
   208  			},
   209  			{
   210  				Query: "SELECT * FROM c WHERE EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) OR NOT EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id);",
   211  				Expected: []sql.Row{
   212  					{1, "CA"},
   213  					{2, "TX"},
   214  					{3, "MA"},
   215  					{4, "TX"},
   216  					{5, nil},
   217  					{6, "FL"},
   218  				},
   219  			},
   220  			{
   221  				Query: "SELECT * FROM c WHERE EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id AND c.bill='TX');",
   222  				Expected: []sql.Row{
   223  					{2, "TX"},
   224  					{4, "TX"},
   225  				},
   226  			},
   227  			{
   228  				Query: "SELECT * FROM c WHERE 'WY' IN (SELECT ship FROM o WHERE o.c_id=c.c_id);",
   229  				Expected: []sql.Row{
   230  					{4, "TX"},
   231  				},
   232  			},
   233  			{
   234  				Query: "SELECT * FROM c WHERE 'WY' IN (SELECT ship FROM o WHERE o.c_id=c.c_id) OR 'WA' IN (SELECT ship FROM o WHERE o.c_id=c.c_id);",
   235  				Expected: []sql.Row{
   236  					{4, "TX"},
   237  					{6, "FL"},
   238  				},
   239  			},
   240  			{
   241  				Query: "SELECT * FROM c WHERE 'CA' IN (SELECT ship FROM o WHERE o.c_id=c.c_id) AND 'TX' NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id);",
   242  				Expected: []sql.Row{
   243  					{1, "CA"},
   244  				},
   245  			},
   246  			{
   247  				Query: "SELECT * FROM c WHERE bill IN (SELECT ship FROM o WHERE o.c_id=c.c_id);",
   248  				Expected: []sql.Row{
   249  					{1, "CA"},
   250  					{2, "TX"},
   251  				},
   252  			},
   253  			{
   254  				Skip:  true,
   255  				Query: "SELECT * FROM c WHERE bill = ALL(SELECT ship FROM o WHERE o.c_id=c.c_id);",
   256  				Expected: []sql.Row{
   257  					{1, "CA"},
   258  					{3, "MA"},
   259  					{5, nil},
   260  				},
   261  			},
   262  			{
   263  				Query: "SELECT * FROM c WHERE bill NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id);",
   264  				Expected: []sql.Row{
   265  					{3, "MA"},
   266  					{5, nil},
   267  					{6, "FL"},
   268  				},
   269  			},
   270  			{
   271  				Query: "SELECT * FROM c WHERE bill NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL);",
   272  				Expected: []sql.Row{
   273  					{3, "MA"},
   274  					{4, "TX"},
   275  					{5, nil},
   276  					{6, "FL"},
   277  				},
   278  			},
   279  			{
   280  				Query: "SELECT * FROM c WHERE bill NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NULL);",
   281  				Expected: []sql.Row{
   282  					{1, "CA"},
   283  					{3, "MA"},
   284  					{5, nil},
   285  					{6, "FL"},
   286  				},
   287  			},
   288  			{
   289  				Skip:  true,
   290  				Query: "SELECT * FROM c WHERE bill < ANY(SELECT ship FROM o WHERE o.c_id=c.c_id);",
   291  				Expected: []sql.Row{
   292  					{4, "TX"},
   293  					{6, "FL"},
   294  				},
   295  			},
   296  			{
   297  				Skip:  true,
   298  				Query: "SELECT * FROM c WHERE bill < SOME(SELECT ship FROM o WHERE o.c_id=c.c_id);",
   299  				Expected: []sql.Row{
   300  					{4, "TX"},
   301  					{6, "FL"},
   302  				},
   303  			},
   304  			{
   305  				Skip:  true,
   306  				Query: "SELECT * FROM c WHERE (bill < ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NULL;",
   307  				Expected: []sql.Row{
   308  					{2, "TX"},
   309  				},
   310  			},
   311  			{
   312  				Skip:  true,
   313  				Query: "SELECT * FROM c WHERE (bill < ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL;",
   314  				Expected: []sql.Row{
   315  					{1, "CA"},
   316  					{3, "MA"},
   317  					{4, "TX"},
   318  					{5, nil},
   319  					{6, "FL"},
   320  				},
   321  			},
   322  			{
   323  				Skip:  true,
   324  				Query: "SELECT * FROM c WHERE bill > ANY(SELECT ship FROM o WHERE o.c_id=c.c_id);",
   325  				Expected: []sql.Row{
   326  					{2, "TX"},
   327  				},
   328  			},
   329  			{
   330  				Skip:  true,
   331  				Query: "SELECT * FROM c WHERE (bill > ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NULL;",
   332  				Expected: []sql.Row{
   333  					{4, "TX"},
   334  				},
   335  			},
   336  			{
   337  				Skip:  true,
   338  				Query: "SELECT * FROM c WHERE (bill > ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL;",
   339  				Expected: []sql.Row{
   340  					{1, "CA"},
   341  					{3, "MA"},
   342  					{4, "TX"},
   343  					{5, nil},
   344  					{6, "FL"},
   345  				},
   346  			},
   347  			{
   348  				Skip:  true,
   349  				Query: "SELECT * FROM c WHERE bill = ANY(SELECT ship FROM o);",
   350  				Expected: []sql.Row{
   351  					{1, "CA"},
   352  					{3, "MA"},
   353  					{4, "TX"},
   354  					{5, nil},
   355  					{6, "FL"},
   356  				},
   357  			},
   358  			{
   359  				Skip:  true,
   360  				Query: "SELECT * FROM c WHERE bill = ANY(SELECT ship FROM o) OR bill IS NULL;",
   361  				Expected: []sql.Row{
   362  					{1, "CA"},
   363  					{3, "MA"},
   364  					{4, "TX"},
   365  					{5, nil},
   366  				},
   367  			},
   368  			{
   369  				Query: "SELECT * FROM c WHERE (NULL IN (SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL;",
   370  				Expected: []sql.Row{
   371  					{3, "MA"},
   372  					{5, nil},
   373  				},
   374  			},
   375  			{
   376  				Query: "SELECT * FROM c WHERE (NULL NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL;",
   377  				Expected: []sql.Row{
   378  					{3, "MA"},
   379  					{5, nil},
   380  				},
   381  			},
   382  			{
   383  				Query: "SELECT * FROM c WHERE (replace(bill, 'TX', 'WY') IN (SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NULL;",
   384  				Expected: []sql.Row{
   385  					{2, "TX"},
   386  				},
   387  			},
   388  			{
   389  				Skip:  true,
   390  				Query: "SELECT * FROM c WHERE bill = ALL(SELECT ship FROM o WHERE o.c_id=c.c_id) OR EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id AND ship='WY');",
   391  				Expected: []sql.Row{
   392  					{1, "CA"},
   393  					{3, "MA"},
   394  					{4, "TX"},
   395  					{5, nil},
   396  				},
   397  			},
   398  			{
   399  				Skip:  true,
   400  				Query: "SELECT * FROM c WHERE bill = ALL(SELECT ship FROM o WHERE o.c_id=c.c_id) AND EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id);",
   401  				Expected: []sql.Row{
   402  					{1, "CA"},
   403  				},
   404  			},
   405  			{
   406  				Query: "SELECT * FROM c WHERE (SELECT count(*) FROM o WHERE o.c_id=c.c_id) > 1;",
   407  				Expected: []sql.Row{
   408  					{1, "CA"},
   409  					{2, "TX"},
   410  					{4, "TX"},
   411  				},
   412  			},
   413  			{
   414  				Query: "SELECT * FROM c WHERE (SELECT count(ship) FROM o WHERE o.c_id=c.c_id) > 1;",
   415  				Expected: []sql.Row{
   416  					{1, "CA"},
   417  					{2, "TX"},
   418  				},
   419  			},
   420  			{
   421  				Query: "SELECT c.c_id, o.o_id, o.ship FROM c INNER JOIN o ON o.ship = (SELECT min(o.ship) FROM o WHERE o.c_id=c.c_id) ORDER BY c.c_id, o.o_id, o.ship;",
   422  				Expected: []sql.Row{
   423  					{1, 10, "CA"},
   424  					{1, 20, "CA"},
   425  					{1, 30, "CA"},
   426  					{1, 40, "CA"},
   427  					{2, 10, "CA"},
   428  					{2, 20, "CA"},
   429  					{2, 30, "CA"},
   430  					{2, 40, "CA"},
   431  					{4, 70, "WY"},
   432  					{6, 90, "WA"},
   433  				},
   434  			},
   435  			{
   436  				Query: "SELECT c.c_id, o.o_id, o.ship FROM c INNER JOIN o ON c.c_id=o.c_id AND o.ship = (SELECT min(o.ship) FROM o WHERE o.c_id=c.c_id) ORDER BY c.c_id, o.o_id, o.ship;",
   437  				Expected: []sql.Row{
   438  					{1, 10, "CA"},
   439  					{1, 20, "CA"},
   440  					{1, 30, "CA"},
   441  					{2, 40, "CA"},
   442  					{4, 70, "WY"},
   443  					{6, 90, "WA"},
   444  				},
   445  			},
   446  			{
   447  				Query: "SELECT c.c_id, o.ship, count(*) FROM c INNER JOIN o ON c.c_id=o.c_id WHERE (SELECT count(*) FROM o AS o2 WHERE o2.ship = o.ship AND o2.c_id = o.c_id) > (SELECT count(*) FROM o AS o2 WHERE o2.ship = o.ship AND o2.c_id <> o.c_id) GROUP BY c.c_id, o.ship;",
   448  				Expected: []sql.Row{
   449  					{1, "CA", 3},
   450  					{2, "TX", 1},
   451  					{4, "WY", 1},
   452  					{6, "WA", 1},
   453  				},
   454  			},
   455  			{
   456  				Query: "SELECT * FROM c WHERE (SELECT count(*) FROM o WHERE o.c_id=c.c_id) > 1 AND (SELECT max(ship) FROM o WHERE o.c_id=c.c_id) = 'CA';",
   457  				Expected: []sql.Row{
   458  					{1, "CA"},
   459  				},
   460  			},
   461  			{
   462  				Query: "SELECT * FROM c WHERE (SELECT count(*) FROM o WHERE o.c_id=c.c_id) > 1 OR EXISTS(SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NULL);",
   463  				Expected: []sql.Row{
   464  					{1, "CA"},
   465  					{2, "TX"},
   466  					{4, "TX"},
   467  				},
   468  			},
   469  			{
   470  				Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT * FROM c WHERE bill=(SELECT max(ship) FROM o WHERE c_id=c2.c_id AND c_id=c.c_id));",
   471  				Expected: []sql.Row{
   472  					{1, "CA"},
   473  					{2, "TX"},
   474  				},
   475  			},
   476  			{
   477  				Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT * FROM c WHERE bill=(SELECT min(ship) FROM o WHERE c_id=c2.c_id AND c_id=c.c_id));",
   478  				Expected: []sql.Row{
   479  					{1, "CA"},
   480  				},
   481  			},
   482  			{
   483  				Skip:  true,
   484  				Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT * FROM c WHERE bill=(SELECT coalesce(min(ship), bill) FROM o WHERE c_id=c2.c_id AND c_id=c.c_id));",
   485  				Expected: []sql.Row{
   486  					{1, "CA"},
   487  					{2, "TX"},
   488  					{3, "MA"},
   489  					{4, "TX"},
   490  					{5, nil},
   491  					{6, "FL"},
   492  				},
   493  			},
   494  			{
   495  				Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT * FROM (SELECT c_id, coalesce(ship, bill) AS state FROM o WHERE c_id=c2.c_id) AS o WHERE state=bill);",
   496  				Expected: []sql.Row{
   497  					{1, "CA"},
   498  					{2, "TX"},
   499  					{4, "TX"},
   500  				},
   501  			},
   502  			{
   503  				Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT * FROM (SELECT c_id, coalesce(ship, bill) AS state FROM o) AS o WHERE c_id = c2.c_id AND state = bill);",
   504  				Expected: []sql.Row{
   505  					{1, "CA"},
   506  					{2, "TX"},
   507  					{4, "TX"},
   508  				},
   509  			},
   510  			{
   511  				Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT * FROM (SELECT c_id, ship AS state FROM o) AS o WHERE c_id = c2.c_id AND coalesce(state, bill) = bill);",
   512  				Expected: []sql.Row{
   513  					{1, "CA"},
   514  					{2, "TX"},
   515  					{4, "TX"},
   516  				},
   517  			},
   518  			{
   519  				Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT c_id, ship FROM o WHERE c_id = c2.c_id AND coalesce(ship, bill) = bill);",
   520  				Expected: []sql.Row{
   521  					{1, "CA"},
   522  					{2, "TX"},
   523  					{4, "TX"},
   524  				},
   525  			},
   526  			{
   527  				Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT * FROM (SELECT c_id, ship AS state FROM o) AS o WHERE c_id = c2.c_id AND coalesce(state, bill) = bill);",
   528  				Expected: []sql.Row{
   529  					{1, "CA"},
   530  					{2, "TX"},
   531  					{4, "TX"},
   532  				},
   533  			},
   534  			{
   535  				Query: "SELECT * FROM c WHERE (SELECT ship FROM o WHERE o.c_id=c.c_id ORDER BY ship LIMIT 1) IS NOT NULL",
   536  				Expected: []sql.Row{
   537  					{1, "CA"},
   538  					{6, "FL"},
   539  				},
   540  			},
   541  			{
   542  				Query: "SELECT * FROM c WHERE (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL ORDER BY ship LIMIT 1)='CA' OR (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL ORDER BY ship LIMIT 1)='WY' ORDER BY c_id",
   543  				Expected: []sql.Row{
   544  					{1, "CA"},
   545  					{2, "TX"},
   546  					{4, "TX"},
   547  				},
   548  			},
   549  			{
   550  				Query:    "SELECT * FROM c WHERE (SELECT o_id FROM o WHERE o.c_id=c.c_id AND ship='WY')=4;",
   551  				Expected: []sql.Row{},
   552  			},
   553  			{
   554  				Query: "SELECT * FROM c WHERE c_id=(SELECT c_id FROM o WHERE ship='CA' AND c_id<>1 AND bill='TX');",
   555  				Expected: []sql.Row{
   556  					{2, "TX"},
   557  				},
   558  			},
   559  			{
   560  				Query: "SELECT * FROM c WHERE c_id=(SELECT c_id FROM o WHERE ship='WA' AND bill='FL')",
   561  				Expected: []sql.Row{
   562  					{6, "FL"},
   563  				},
   564  			},
   565  			{
   566  				Query: "SELECT * FROM c WHERE (SELECT ship  FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL AND (SELECT count(*) FROM o WHERE o.c_id=c.c_id)<=1)='WA';",
   567  				Expected: []sql.Row{
   568  					{6, "FL"},
   569  				},
   570  			},
   571  			{
   572  				Query: "SELECT c_id, EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;",
   573  				Expected: []sql.Row{
   574  					{1, true},
   575  					{2, true},
   576  					{3, false},
   577  					{4, true},
   578  					{5, false},
   579  					{6, true},
   580  				},
   581  			},
   582  			{
   583  				Query: "SELECT c_id, NOT EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;",
   584  				Expected: []sql.Row{
   585  					{1, false},
   586  					{2, false},
   587  					{3, true},
   588  					{4, false},
   589  					{5, true},
   590  					{6, false},
   591  				},
   592  			},
   593  			{
   594  				Query: "SELECT c_id, EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) OR NOT EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;",
   595  				Expected: []sql.Row{
   596  					{1, true},
   597  					{2, true},
   598  					{3, true},
   599  					{4, true},
   600  					{5, true},
   601  					{6, true},
   602  				},
   603  			},
   604  			{
   605  				Query: "SELECT c_id, EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id AND c.bill='TX') FROM c ORDER BY c_id;",
   606  				Expected: []sql.Row{
   607  					{1, false},
   608  					{2, true},
   609  					{3, false},
   610  					{4, true},
   611  					{5, false},
   612  					{6, false},
   613  				},
   614  			},
   615  			{
   616  				Query: "SELECT c_id, 'WY' IN (SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;",
   617  				Expected: []sql.Row{
   618  					{1, false},
   619  					{2, nil},
   620  					{3, false},
   621  					{4, true},
   622  					{5, false},
   623  					{6, false},
   624  				},
   625  			},
   626  			{
   627  				Query: "SELECT c_id, 'WY' IN (SELECT ship FROM o WHERE o.c_id=c.c_id) OR 'WA' IN (SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;",
   628  				Expected: []sql.Row{
   629  					{1, false},
   630  					{2, nil},
   631  					{3, false},
   632  					{4, true},
   633  					{5, false},
   634  					{6, true},
   635  				},
   636  			},
   637  			{
   638  				Query: "SELECT c_id, 'CA' IN (SELECT ship FROM o WHERE o.c_id=c.c_id) AND 'TX' NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;",
   639  				Expected: []sql.Row{
   640  					{1, true},
   641  					{2, false},
   642  					{3, false},
   643  					{4, nil},
   644  					{5, false},
   645  					{6, false},
   646  				},
   647  			},
   648  			{
   649  				Query: "SELECT c_id, bill IN (SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;",
   650  				Expected: []sql.Row{
   651  					{1, true},
   652  					{2, true},
   653  					{3, false},
   654  					{4, nil},
   655  					{5, false},
   656  					{6, false},
   657  				},
   658  			},
   659  			{
   660  				Skip:  true,
   661  				Query: "SELECT c_id, bill = ALL(SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;",
   662  				Expected: []sql.Row{
   663  					{1, 1},
   664  					{2, 0},
   665  					{3, 1},
   666  					{4, 0},
   667  					{5, true},
   668  					{6, 0},
   669  				},
   670  			},
   671  			{
   672  				Query: "SELECT c_id, bill NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;",
   673  				Expected: []sql.Row{
   674  					{1, false},
   675  					{2, false},
   676  					{3, true},
   677  					{4, nil},
   678  					{5, true},
   679  					{6, true},
   680  				},
   681  			},
   682  			{
   683  				Query: "SELECT c_id, bill NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL) FROM c ORDER BY c_id;",
   684  				Expected: []sql.Row{
   685  					{1, false},
   686  					{2, false},
   687  					{3, true},
   688  					{4, true},
   689  					{5, true},
   690  					{6, true},
   691  				},
   692  			},
   693  			{
   694  				Query: "SELECT c_id, bill NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NULL) FROM c ORDER BY c_id;",
   695  				Expected: []sql.Row{
   696  					{1, true},
   697  					{2, nil},
   698  					{3, true},
   699  					{4, nil},
   700  					{5, true},
   701  					{6, true},
   702  				},
   703  			},
   704  			{
   705  				Skip:  true,
   706  				Query: "SELECT c_id, bill < ANY(SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;",
   707  				Expected: []sql.Row{
   708  					{1, false},
   709  					{2, nil},
   710  					{3, false},
   711  					{4, true},
   712  					{5, false},
   713  					{6, true},
   714  				},
   715  			},
   716  			{
   717  				Skip:  true,
   718  				Query: "SELECT c_id, (bill < ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NULL FROM c ORDER BY c_id;",
   719  				Expected: []sql.Row{
   720  					{1, false},
   721  					{2, true},
   722  					{3, false},
   723  					{4, false},
   724  					{5, false},
   725  					{6, false},
   726  				},
   727  			},
   728  			{
   729  				Skip:  true,
   730  				Query: "SELECT c_id, (bill < ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL FROM c ORDER BY c_id;",
   731  				Expected: []sql.Row{
   732  					{1, true},
   733  					{2, false},
   734  					{3, true},
   735  					{4, true},
   736  					{5, true},
   737  					{6, true},
   738  				},
   739  			},
   740  			{
   741  				Skip:  true,
   742  				Query: "SELECT c_id, bill > ANY(SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;",
   743  				Expected: []sql.Row{
   744  					{1, false},
   745  					{2, true},
   746  					{3, false},
   747  					{4, nil},
   748  					{5, false},
   749  					{6, false},
   750  				},
   751  			},
   752  			{
   753  				Skip:  true,
   754  				Query: "SELECT c_id, (bill > ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NULL FROM c ORDER BY c_id;",
   755  				Expected: []sql.Row{
   756  					{1, false},
   757  					{2, false},
   758  					{3, false},
   759  					{4, true},
   760  					{5, false},
   761  					{6, false},
   762  				},
   763  			},
   764  			{
   765  				Skip:  true,
   766  				Query: "SELECT c_id, (bill > ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL FROM c ORDER BY c_id;",
   767  				Expected: []sql.Row{
   768  					{1, true},
   769  					{2, true},
   770  					{3, true},
   771  					{4, false},
   772  					{5, true},
   773  					{6, true},
   774  				},
   775  			},
   776  			{
   777  				Skip:  true,
   778  				Query: "SELECT c_id, bill = ANY(SELECT ship FROM o WHERE ship IS NOT NULL) FROM c;",
   779  				Expected: []sql.Row{
   780  					{1, true},
   781  					{2, true},
   782  					{3, false},
   783  					{4, true},
   784  					{5, nil},
   785  					{6, false},
   786  				},
   787  			},
   788  			{
   789  				Skip:  true,
   790  				Query: "SELECT c_id, bill = ANY(SELECT ship FROM o WHERE ship IS NOT NULL) OR bill IS NULL FROM c;",
   791  				Expected: []sql.Row{
   792  					{1, true},
   793  					{2, true},
   794  					{3, false},
   795  					{4, true},
   796  					{5, true},
   797  					{6, false},
   798  				},
   799  			},
   800  			{
   801  				Query: "SELECT c_id, (NULL IN (SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL FROM c ORDER BY c_id;",
   802  				Expected: []sql.Row{
   803  					{1, false},
   804  					{2, false},
   805  					{3, true},
   806  					{4, false},
   807  					{5, true},
   808  					{6, false},
   809  				},
   810  			},
   811  			{
   812  				Query: "SELECT c_id, (NULL NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL FROM c ORDER BY c_id;",
   813  				Expected: []sql.Row{
   814  					{1, false},
   815  					{2, false},
   816  					{3, true},
   817  					{4, false},
   818  					{5, true},
   819  					{6, false},
   820  				},
   821  			},
   822  			{
   823  				Query: "SELECT c_id, (replace(bill, 'TX', 'WY') IN (SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NULL FROM c ORDER BY c_id;",
   824  				Expected: []sql.Row{
   825  					{1, false},
   826  					{2, true},
   827  					{3, false},
   828  					{4, false},
   829  					{5, false},
   830  					{6, false},
   831  				},
   832  			},
   833  			{
   834  				Skip:  true,
   835  				Query: "SELECT c_id, bill = ALL(SELECT ship FROM o WHERE o.c_id=c.c_id) OR EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id AND ship='WY') FROM c ORDER BY c_id;",
   836  				Expected: []sql.Row{
   837  					{1, true},
   838  					{2, false},
   839  					{3, true},
   840  					{4, true},
   841  					{5, true},
   842  					{6, false},
   843  				},
   844  			},
   845  			{
   846  				Skip:  true,
   847  				Query: "SELECT c_id, bill = ALL(SELECT ship FROM o WHERE o.c_id=c.c_id) AND EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;",
   848  				Expected: []sql.Row{
   849  					{1, true},
   850  					{2, false},
   851  					{3, false},
   852  					{4, false},
   853  					{5, false},
   854  					{6, false},
   855  				},
   856  			},
   857  			{
   858  				Query: "SELECT * FROM c WHERE (SELECT min(ship) FROM o WHERE o.c_id=c.c_id) IN (SELECT ship FROM o WHERE o.c_id=c.c_id);",
   859  				Expected: []sql.Row{
   860  					{1, "CA"},
   861  					{2, "TX"},
   862  					{4, "TX"},
   863  					{6, "FL"},
   864  				},
   865  			},
   866  			{
   867  				Query: "SELECT c_id, (SELECT min(ship) FROM o WHERE o.c_id=c.c_id) IN (SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;",
   868  				Expected: []sql.Row{
   869  					{1, true},
   870  					{2, true},
   871  					{3, false},
   872  					{4, true},
   873  					{5, false},
   874  					{6, true},
   875  				},
   876  			},
   877  			{
   878  				Query: "SELECT max((SELECT count(*) FROM o WHERE o.c_id=c.c_id)) FROM c;",
   879  				Expected: []sql.Row{
   880  					{3},
   881  				},
   882  			},
   883  			{
   884  				Query: "SELECT c_id, (SELECT count(*) FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;",
   885  				Expected: []sql.Row{
   886  					{1, 3},
   887  					{2, 3},
   888  					{3, 0},
   889  					{4, 2},
   890  					{5, 0},
   891  					{6, 1},
   892  				},
   893  			},
   894  			{
   895  				Query: "SELECT s.st, (SELECT count(*) FROM c WHERE c.bill=s.st) + (SELECT count(*) FROM o WHERE o.ship=s.st) FROM (SELECT c.bill AS st FROM c UNION SELECT o.ship AS st FROM o) s ORDER BY s.st;",
   896  				Expected: []sql.Row{
   897  					{nil, 0},
   898  					{"CA", 5},
   899  					{"FL", 1},
   900  					{"MA", 1},
   901  					{"TX", 3},
   902  					{"WA", 1},
   903  					{"WY", 1},
   904  				},
   905  			},
   906  			{
   907  				Query: "SELECT c.c_id, o.ship, count(*) AS cust, (SELECT count(*) FROM o AS o2 WHERE o2.ship = o.ship AND o2.c_id <> c.c_id) AS other  FROM c INNER JOIN o ON c.c_id=o.c_id GROUP BY c.c_id, o.ship;",
   908  				Expected: []sql.Row{
   909  					{1, "CA", 3, 1},
   910  					{2, "CA", 1, 3},
   911  					{2, "TX", 1, 0},
   912  					{2, nil, 1, 0},
   913  					{4, "WY", 1, 0},
   914  					{4, nil, 1, 0},
   915  					{6, "WA", 1, 0},
   916  				},
   917  			},
   918  			{
   919  				Query: "SELECT c.c_id, o.o_id, (SELECT max(CASE WHEN c2.bill > o2.ship THEN c2.bill ELSE o2.ship END) FROM c AS c2, o AS o2 WHERE c2.c_id=o2.c_id AND c2.c_id=c.c_id)  FROM c LEFT JOIN o ON c.c_id=o.c_id ORDER BY c.c_id, o.o_id;",
   920  				Expected: []sql.Row{
   921  					{1, 10, "CA"},
   922  					{1, 20, "CA"},
   923  					{1, 30, "CA"},
   924  					{2, 40, "TX"},
   925  					{2, 50, "TX"},
   926  					{2, 60, "TX"},
   927  					{3, nil, nil},
   928  					{4, 70, "WY"},
   929  					{4, 80, "WY"},
   930  					{5, nil, nil},
   931  					{6, 90, "WA"},
   932  				},
   933  			},
   934  			{
   935  				Query: "SELECT c.c_id, (SELECT ship FROM o WHERE o.c_id=c.c_id ORDER BY ship LIMIT 1) IS NOT NULL  FROM c ORDER BY c.c_id;",
   936  				Expected: []sql.Row{
   937  					{1, true},
   938  					{2, false},
   939  					{3, false},
   940  					{4, false},
   941  					{5, false},
   942  					{6, true},
   943  				},
   944  			},
   945  			{
   946  				Query: "SELECT c.c_id, (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL ORDER BY ship LIMIT 1)='CA' OR (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL ORDER BY ship LIMIT 1)='WY' FROM c ORDER BY c_id;",
   947  				Expected: []sql.Row{
   948  					{1, true},
   949  					{2, true},
   950  					{3, nil},
   951  					{4, true},
   952  					{5, nil},
   953  					{6, false},
   954  				},
   955  			},
   956  			{
   957  				Skip:  true,
   958  				Query: "SELECT * FROM (SELECT c_id AS c_c_id, bill FROM c) sq1, LATERAL (SELECT row_number() OVER () AS rownum FROM o WHERE c_id = c_c_id) sq2 ORDER BY c_c_id, bill, rownum;",
   959  				Expected: []sql.Row{
   960  					{1, "CA", 1},
   961  					{1, "CA", 2},
   962  					{1, "CA", 3},
   963  					{2, "TX", 1},
   964  					{2, "TX", 2},
   965  					{2, "TX", 3},
   966  					{4, "TX", 1},
   967  					{4, "TX", 2},
   968  					{6, "FL", 1},
   969  				},
   970  			},
   971  			{
   972  				Query: "SELECT *  FROM (SELECT bill FROM c) sq1, LATERAL (SELECT row_number() OVER (PARTITION BY bill) AS rownum FROM o WHERE ship = bill) sq2 ORDER BY bill, rownum;",
   973  				Expected: []sql.Row{
   974  					{"CA", 1},
   975  					{"CA", 2},
   976  					{"CA", 3},
   977  					{"CA", 4},
   978  					{"TX", 1},
   979  					{"TX", 1},
   980  				},
   981  			},
   982  			{
   983  				Skip:  true,
   984  				Query: "SELECT (SELECT count(*) FROM o WHERE o.c_id=c.c_id) AS order_cnt, count(*) AS cust_cnt  FROM c GROUP BY (SELECT count(*) FROM o WHERE o.c_id=c.c_id) ORDER BY (SELECT count(*) FROM o WHERE o.c_id=c.c_id) DESC;",
   985  				Expected: []sql.Row{
   986  					{3, 2},
   987  					{2, 1},
   988  					{1, 1},
   989  					{0, 2},
   990  				},
   991  			},
   992  			{
   993  				Query: "SELECT c_cnt, o_cnt, c_cnt + o_cnt AS total  FROM (VALUES ROW((SELECT count(*) FROM c), (SELECT count(*) FROM o))) AS v(c_cnt, o_cnt)  WHERE c_cnt > 0 AND o_cnt > 0;",
   994  				Expected: []sql.Row{
   995  					{6, 9, 15},
   996  				},
   997  			},
   998  			{
   999  				Query: "SELECT c.c_id, o.o_id  FROM c INNER JOIN o ON c.c_id=o.c_id AND EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id AND ship IS NULL);",
  1000  				Expected: []sql.Row{
  1001  					{2, 40},
  1002  					{2, 50},
  1003  					{2, 60},
  1004  					{4, 70},
  1005  					{4, 80},
  1006  				},
  1007  			},
  1008  		},
  1009  	},
  1010  	//{
  1011  	//	Name: "multiple nested subquery",
  1012  	//	SetUpScript: []string{
  1013  	//		"CREATE TABLE `groups`(id SERIAL PRIMARY KEY, data JSON);",
  1014  	//		"INSERT INTO `groups`(data) VALUES('{\"name\": \"Group 1\", \"members\": [{\"name\": \"admin\", \"type\": \"USER\"}, {\"name\": \"user\", \"type\": \"USER\"}]}');",
  1015  	//		"INSERT INTO `groups`(data) VALUES('{\"name\": \"Group 2\", \"members\": [{\"name\": \"admin2\", \"type\": \"USER\"}]}');",
  1016  	//		"CREATE TABLE t32786 (id VARCHAR(36) PRIMARY KEY, parent_id VARCHAR(36), parent_path text);",
  1017  	//		"INSERT INTO t32786 VALUES ('3AAA2577-DBC3-47E7-9E85-9CC7E19CF48A', null, null);",
  1018  	//		"INSERT INTO t32786 VALUES ('5AE7EAFD-8277-4F41-83DE-0FD4B4482169', '3AAA2577-DBC3-47E7-9E85-9CC7E19CF48A', null);",
  1019  	//		"CREATE TABLE users (id INT8 NOT NULL, name VARCHAR(50), PRIMARY KEY (id));",
  1020  	//		"INSERT INTO users(id, name) VALUES (1, 'user1');",
  1021  	//		"INSERT INTO users(id, name) VALUES (2, 'user2');",
  1022  	//        "INSERT INTO users(id, name) VALUES (3, 'user3');",
  1023  	//        "CREATE TABLE stuff(id INT8 NOT NULL, date DATE, user_id INT8, PRIMARY KEY (id), FOREIGN KEY (user_id) REFERENCES users (id));",
  1024  	//        "INSERT INTO stuff(id, date, user_id) VALUES (1, '2007-10-15', 1);",
  1025  	//        "INSERT INTO stuff(id, date, user_id) VALUES (2, '2007-12-15', 1);",
  1026  	//        "INSERT INTO stuff(id, date, user_id) VALUES (3, '2007-11-15', 1);",
  1027  	//        "INSERT INTO stuff(id, date, user_id) VALUES (4, '2008-01-15', 2);",
  1028  	//        "INSERT INTO stuff(id, date, user_id) VALUES (5, '2007-06-15', 3);",
  1029  	//        "INSERT INTO stuff(id, date, user_id) VALUES (6, '2007-03-15', 3);",
  1030  	//	},
  1031  	//	Assertions: []ScriptTestAssertion{
  1032  	//		{
  1033  	//			Skip: true,
  1034  	//			Query: "SELECT users.id AS users_id, users.name AS users_name, stuff_1.id AS stuff_1_id, stuff_1.date AS stuff_1_date, stuff_1.user_id AS stuff_1_user_id FROM users LEFT JOIN stuff AS stuff_1 ON users.id = stuff_1.user_id AND stuff_1.id = (SELECT stuff_2.id FROM stuff AS stuff_2 WHERE stuff_2.user_id = users.id ORDER BY stuff_2.date DESC LIMIT 1) ORDER BY users.name;",
  1035  	//			Expected: []sql.Row{
  1036  	//				{1, "user1", 2, 2007-12-15, 1},
  1037  	//				{2, "user2", 4, 2008-01-15, 2},
  1038  	//				{3, "user3", 5, 2007-06-15, 3},
  1039  	//			},
  1040  	//		},
  1041  	//	},
  1042  	//},
  1043  	{
  1044  		Name: "multiple nested subquery again",
  1045  		SetUpScript: []string{
  1046  			"CREATE TABLE IF NOT EXISTS t_48638 (`key` INT NOT NULL, `value` INTEGER NOT NULL, PRIMARY KEY (`key`, `value`));",
  1047  			"INSERT INTO t_48638 values (1, 4);",
  1048  			"INSERT INTO t_48638 values (4, 3);",
  1049  			"INSERT INTO t_48638 values (3, 2);",
  1050  			"INSERT INTO t_48638 values (4, 1);",
  1051  			"INSERT INTO t_48638 values (1, 2);",
  1052  			"INSERT INTO t_48638 values (6, 5);",
  1053  			"INSERT INTO t_48638 values (7, 8);",
  1054  		},
  1055  		Assertions: []ScriptTestAssertion{
  1056  			{
  1057  				Query: "SELECT *  FROM t_48638  WHERE `key` IN (WITH v AS (SELECT level1.`value` AS `value`, level1.`key`AS level1, level2.`key` AS level2, level3.`key` AS level3 FROM t_48638 AS level2 RIGHT JOIN (SELECT * FROM t_48638 WHERE `value` = 4) AS level1 ON level1.`value` = level2.`key`      LEFT JOIN (SELECT * FROM t_48638) AS level3 ON level3.`key` = level2.`value`  )  SELECT v.level1 FROM v WHERE v.level1 IS NOT NULL  UNION ALL SELECT v.level2 FROM v WHERE v.level2 IS NOT NULL  UNION ALL SELECT v.level3 FROM v WHERE v.level3 IS NOT NULL);",
  1058  				Expected: []sql.Row{
  1059  					{1, 2},
  1060  					{1, 4},
  1061  					{3, 2},
  1062  					{4, 1},
  1063  					{4, 3},
  1064  				},
  1065  			},
  1066  		},
  1067  	},
  1068  }