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

     1  // Copyright 2020-2022 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  	"math"
    19  	"time"
    20  
    21  	"github.com/dolthub/vitess/go/sqltypes"
    22  	"github.com/dolthub/vitess/go/vt/proto/query"
    23  	"gopkg.in/src-d/go-errors.v1"
    24  
    25  	"github.com/dolthub/go-mysql-server/sql"
    26  	"github.com/dolthub/go-mysql-server/sql/analyzer/analyzererrors"
    27  	"github.com/dolthub/go-mysql-server/sql/expression"
    28  	"github.com/dolthub/go-mysql-server/sql/planbuilder"
    29  	"github.com/dolthub/go-mysql-server/sql/types"
    30  )
    31  
    32  type QueryTest struct {
    33  	Query            string
    34  	Expected         []sql.Row
    35  	ExpectedColumns  sql.Schema // only Name and Type matter here, because that's what we send on the wire
    36  	Bindings         map[string]*query.BindVariable
    37  	SkipPrepared     bool
    38  	SkipServerEngine bool
    39  }
    40  
    41  type QueryPlanTest struct {
    42  	Query             string
    43  	ExpectedPlan      string
    44  	ExpectedEstimates string
    45  	ExpectedAnalysis  string
    46  	Skip              bool
    47  }
    48  
    49  // QueryPlanTODOs are queries where the query planner produces a correct (results) but suboptimal plan.
    50  var QueryPlanTODOs = []QueryPlanTest{
    51  	{
    52  		// TODO: this should use an index. Extra join condition should get moved out of the join clause into a filter
    53  		Query: `SELECT pk,i,f FROM one_pk RIGHT JOIN niltable ON pk=i and pk > 0 ORDER BY 2,3`,
    54  		ExpectedPlan: "Sort(niltable.i ASC, niltable.f ASC)\n" +
    55  			" └─ Project(one_pk.pk, niltable.i, niltable.f)\n" +
    56  			"     └─ RightJoin((one_pk.pk = niltable.i) AND (one_pk.pk > 0))\n" +
    57  			"         ├─ Projected table access on [pk]\n" +
    58  			"         │   └─ Table(one_pk)\n" +
    59  			"         └─ Projected table access on [i f]\n" +
    60  			"             └─ Table(niltable)\n" +
    61  			"",
    62  	},
    63  }
    64  
    65  var SpatialQueryTests = []QueryTest{
    66  	{
    67  		Query: `SHOW CREATE TABLE point_table`,
    68  		Expected: []sql.Row{{
    69  			"point_table",
    70  			"CREATE TABLE `point_table` (\n" +
    71  				"  `i` bigint NOT NULL,\n" +
    72  				"  `p` point NOT NULL,\n" +
    73  				"  PRIMARY KEY (`i`)\n" +
    74  				") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
    75  		}},
    76  	},
    77  	{
    78  		Query: `SHOW CREATE TABLE line_table`,
    79  		Expected: []sql.Row{{
    80  			"line_table",
    81  			"CREATE TABLE `line_table` (\n" +
    82  				"  `i` bigint NOT NULL,\n" +
    83  				"  `l` linestring NOT NULL,\n" +
    84  				"  PRIMARY KEY (`i`)\n" +
    85  				") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
    86  		}},
    87  	},
    88  	{
    89  		Query: `SHOW CREATE TABLE polygon_table`,
    90  		Expected: []sql.Row{{
    91  			"polygon_table",
    92  			"CREATE TABLE `polygon_table` (\n" +
    93  				"  `i` bigint NOT NULL,\n" +
    94  				"  `p` polygon NOT NULL,\n" +
    95  				"  PRIMARY KEY (`i`)\n" +
    96  				") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
    97  		}},
    98  	},
    99  	{
   100  		Query: `SHOW CREATE TABLE mpoint_table`,
   101  		Expected: []sql.Row{{
   102  			"mpoint_table",
   103  			"CREATE TABLE `mpoint_table` (\n" +
   104  				"  `i` bigint NOT NULL,\n" +
   105  				"  `p` multipoint NOT NULL,\n" +
   106  				"  PRIMARY KEY (`i`)\n" +
   107  				") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
   108  		}},
   109  	},
   110  	{
   111  		Query: `SHOW CREATE TABLE mline_table`,
   112  		Expected: []sql.Row{{
   113  			"mline_table",
   114  			"CREATE TABLE `mline_table` (\n" +
   115  				"  `i` bigint NOT NULL,\n" +
   116  				"  `l` multilinestring NOT NULL,\n" +
   117  				"  PRIMARY KEY (`i`)\n" +
   118  				") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
   119  		}},
   120  	},
   121  	{
   122  		Query: `SHOW CREATE TABLE mpoly_table`,
   123  		Expected: []sql.Row{{
   124  			"mpoly_table",
   125  			"CREATE TABLE `mpoly_table` (\n" +
   126  				"  `i` bigint NOT NULL,\n" +
   127  				"  `p` multipolygon NOT NULL,\n" +
   128  				"  PRIMARY KEY (`i`)\n" +
   129  				") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
   130  		}},
   131  	},
   132  	{
   133  		Query: `SHOW CREATE TABLE geometry_table`,
   134  		Expected: []sql.Row{{
   135  			"geometry_table",
   136  			"CREATE TABLE `geometry_table` (\n" +
   137  				"  `i` bigint NOT NULL,\n" +
   138  				"  `g` geometry NOT NULL,\n" +
   139  				"  PRIMARY KEY (`i`)\n" +
   140  				") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
   141  		}},
   142  	},
   143  	{
   144  		Query:    `SELECT HEX(ST_ASWKB(p)) from point_table`,
   145  		Expected: []sql.Row{{"0101000000000000000000F03F0000000000000040"}},
   146  	},
   147  	{
   148  		Query: `SELECT HEX(ST_ASWKB(l)) from line_table`,
   149  		Expected: []sql.Row{
   150  			{"010200000002000000000000000000F03F000000000000004000000000000008400000000000001040"},
   151  			{"010200000003000000000000000000F03F00000000000000400000000000000840000000000000104000000000000014400000000000001840"},
   152  		},
   153  	},
   154  	{
   155  		Query: `SELECT HEX(ST_ASWKB(p)) from polygon_table`,
   156  		Expected: []sql.Row{
   157  			{"01030000000100000004000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F00000000000000000000000000000000"},
   158  			{"01030000000200000004000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F0000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F00000000000000000000000000000000"},
   159  		},
   160  	},
   161  	{
   162  		Query:    `SELECT ST_GEOMFROMWKB(ST_ASWKB(POINT(123.45,6.78)))`,
   163  		Expected: []sql.Row{{types.Point{X: 123.45, Y: 6.78}}},
   164  	},
   165  	{
   166  		Query:    `SELECT ST_GEOMFROMWKB(ST_ASWKB(LINESTRING(POINT(1.2,3.45),point(67.8,9))))`,
   167  		Expected: []sql.Row{{types.LineString{Points: []types.Point{{X: 1.2, Y: 3.45}, {X: 67.8, Y: 9}}}}},
   168  	},
   169  	{
   170  		Query:    `SELECT ST_GEOMFROMWKB(ST_ASWKB(POLYGON(LINESTRING(POINT(0,0),POINT(2,2),POINT(1,1),POINT(0,0)))))`,
   171  		Expected: []sql.Row{{types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 2, Y: 2}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}},
   172  	},
   173  	{
   174  		Query:    `SELECT ST_ASWKT(p) from point_table`,
   175  		Expected: []sql.Row{{"POINT(1 2)"}},
   176  	},
   177  	{
   178  		Query: `SELECT ST_ASWKT(l) from line_table`,
   179  		Expected: []sql.Row{
   180  			{"LINESTRING(1 2,3 4)"},
   181  			{"LINESTRING(1 2,3 4,5 6)"},
   182  		},
   183  	},
   184  	{
   185  		Query: `SELECT ST_ASWKT(p) from polygon_table`,
   186  		Expected: []sql.Row{
   187  			{"POLYGON((0 0,0 1,1 1,0 0))"},
   188  			{"POLYGON((0 0,0 1,1 1,0 0),(0 0,0 1,1 1,0 0))"},
   189  		},
   190  	},
   191  	{
   192  		Query: `SELECT ST_ASTEXT(p) from polygon_table`,
   193  		Expected: []sql.Row{
   194  			{"POLYGON((0 0,0 1,1 1,0 0))"},
   195  			{"POLYGON((0 0,0 1,1 1,0 0),(0 0,0 1,1 1,0 0))"},
   196  		},
   197  	},
   198  	{
   199  		Query:    `SELECT ST_GEOMFROMTEXT(ST_ASWKT(POINT(1,2)))`,
   200  		Expected: []sql.Row{{types.Point{X: 1, Y: 2}}},
   201  	},
   202  	{
   203  		Query:    `SELECT ST_GEOMFROMTEXT(ST_ASWKT(LINESTRING(POINT(1.1,2.22),POINT(3.333,4.4444))))`,
   204  		Expected: []sql.Row{{types.LineString{Points: []types.Point{{X: 1.1, Y: 2.22}, {X: 3.333, Y: 4.4444}}}}},
   205  	},
   206  	{
   207  		Query:    `SELECT ST_GEOMFROMTEXT(ST_ASWKT(POLYGON(LINESTRING(POINT(1.2, 3.4),POINT(2.5, -6.7),POINT(33, 44),POINT(1.2,3.4)))))`,
   208  		Expected: []sql.Row{{types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 1.2, Y: 3.4}, {X: 2.5, Y: -6.7}, {X: 33, Y: 44}, {X: 1.2, Y: 3.4}}}}}}},
   209  	},
   210  	{
   211  		Query:    `SELECT ST_X(POINT(1,2))`,
   212  		Expected: []sql.Row{{1.0}},
   213  	},
   214  	{
   215  		Query:    `SELECT ST_Y(POINT(1,2))`,
   216  		Expected: []sql.Row{{2.0}},
   217  	},
   218  	{
   219  		Query:    `SELECT ST_X(POINT(123.45,6.789))`,
   220  		Expected: []sql.Row{{123.45}},
   221  	},
   222  	{
   223  		Query:    `SELECT ST_Y(POINT(123.45,6.789))`,
   224  		Expected: []sql.Row{{6.789}},
   225  	},
   226  	{
   227  		Query:    `SELECT ST_X(POINT(1,2),99.9)`,
   228  		Expected: []sql.Row{{types.Point{X: 99.9, Y: 2}}},
   229  	},
   230  	{
   231  		Query:    `SELECT ST_Y(POINT(1,2),99.9)`,
   232  		Expected: []sql.Row{{types.Point{X: 1, Y: 99.9}}},
   233  	},
   234  	{
   235  		Query:    `SELECT ST_X(p) from point_table`,
   236  		Expected: []sql.Row{{1.0}},
   237  	},
   238  	{
   239  		Query:    `SELECT ST_X(p) from point_table`,
   240  		Expected: []sql.Row{{1.0}},
   241  	},
   242  	{
   243  		Query:    `SELECT ST_Y(p) from point_table`,
   244  		Expected: []sql.Row{{2.0}},
   245  	},
   246  	{
   247  		Query:    `SELECT ST_SRID(p) from point_table`,
   248  		Expected: []sql.Row{{uint32(0)}},
   249  	},
   250  	{
   251  		Query:    `SELECT ST_SRID(l) from line_table`,
   252  		Expected: []sql.Row{{uint32(0)}, {uint32(0)}},
   253  	},
   254  	{
   255  		Query: `SELECT ST_SRID(p) from polygon_table`,
   256  		Expected: []sql.Row{
   257  			{uint32(0)},
   258  			{uint32(0)},
   259  		},
   260  	},
   261  	{
   262  		Query:    `SELECT ST_SRID(p, 4326) from point_table`,
   263  		Expected: []sql.Row{{types.Point{SRID: 4326, X: 1, Y: 2}}},
   264  	},
   265  	{
   266  		Query: `SELECT ST_SRID(l, 4326) from line_table ORDER BY l`,
   267  		Expected: []sql.Row{
   268  			{types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}},
   269  			{types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 5, Y: 6}}}},
   270  		},
   271  	},
   272  	{
   273  		Query: `SELECT ST_SRID(p, 4326) from polygon_table`,
   274  		Expected: []sql.Row{
   275  			{types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}},
   276  			{types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}, {SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}},
   277  		},
   278  	},
   279  	{
   280  		Query: `SELECT ST_GEOMFROMGEOJSON(s) from stringtogeojson_table`,
   281  		Expected: []sql.Row{
   282  			{types.Point{SRID: 4326, X: 1, Y: 2}},
   283  			{types.Point{SRID: 4326, X: 123.45, Y: 56.789}},
   284  			{types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}},
   285  			{types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1.23, Y: 2.345}, {SRID: 4326, X: 3.56789, Y: 4.56}}}},
   286  			{types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1.1, Y: 2.2}, {SRID: 4326, X: 3.3, Y: 4.4}, {SRID: 4326, X: 5.5, Y: 6.6}, {SRID: 4326, X: 1.1, Y: 2.2}}}}}},
   287  			{types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 2, Y: 2}, {SRID: 4326, X: 0, Y: 0}}}}}},
   288  			{types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}},
   289  			{types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1.23, Y: 2.345}, {SRID: 4326, X: 3.56789, Y: 4.56}}}},
   290  			{types.MultiLineString{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1.1, Y: 2.2}, {SRID: 4326, X: 3.3, Y: 4.4}}}, {SRID: 4326, Points: []types.Point{{SRID: 4326, X: 5.5, Y: 6.6}, {SRID: 4326, X: 7.7, Y: 8.8}}}}}},
   291  			{types.MultiPolygon{SRID: 4326, Polygons: []types.Polygon{
   292  				{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1.1, Y: 2.2}, {SRID: 4326, X: 3.3, Y: 4.4}, {SRID: 4326, X: 0, Y: 0}}}}},
   293  				{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1.1, Y: 1.1}, {SRID: 4326, X: 1.1, Y: 2.2}, {SRID: 4326, X: 3.3, Y: 4.4}, {SRID: 4326, X: 1.1, Y: 1.1}}}}},
   294  			}}},
   295  			{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{}}}}},
   296  		},
   297  	},
   298  	{
   299  		Query: `SELECT ST_ASGEOJSON(p) from point_table`,
   300  		Expected: []sql.Row{
   301  			{types.JSONDocument{Val: map[string]interface{}{"type": "Point", "coordinates": [2]float64{1, 2}}}},
   302  		},
   303  	},
   304  	{
   305  		Query: `SELECT ST_ASGEOJSON(l) from line_table`,
   306  		Expected: []sql.Row{
   307  			{types.JSONDocument{Val: map[string]interface{}{"type": "LineString", "coordinates": [][2]float64{{1, 2}, {3, 4}}}}},
   308  			{types.JSONDocument{Val: map[string]interface{}{"type": "LineString", "coordinates": [][2]float64{{1, 2}, {3, 4}, {5, 6}}}}},
   309  		},
   310  	},
   311  	{
   312  		Query: `SELECT ST_ASGEOJSON(p) from polygon_table`,
   313  		Expected: []sql.Row{
   314  			{types.JSONDocument{Val: map[string]interface{}{"type": "Polygon", "coordinates": [][][2]float64{{{0, 0}, {0, 1}, {1, 1}, {0, 0}}}}}},
   315  			{types.JSONDocument{Val: map[string]interface{}{"type": "Polygon", "coordinates": [][][2]float64{{{0, 0}, {0, 1}, {1, 1}, {0, 0}}, {{0, 0}, {0, 1}, {1, 1}, {0, 0}}}}}},
   316  		},
   317  	},
   318  	{
   319  		Query: `SELECT ST_ASGEOJSON(p) from mpoint_table`,
   320  		Expected: []sql.Row{
   321  			{types.JSONDocument{Val: map[string]interface{}{"type": "MultiPoint", "coordinates": [][2]float64{{1, 2}, {3, 4}}}}},
   322  			{types.JSONDocument{Val: map[string]interface{}{"type": "MultiPoint", "coordinates": [][2]float64{{1, 2}, {3, 4}, {5, 6}}}}},
   323  		},
   324  	},
   325  	{
   326  		Query: `SELECT ST_ASGEOJSON(l) from mline_table`,
   327  		Expected: []sql.Row{
   328  			{types.JSONDocument{Val: map[string]interface{}{"type": "MultiLineString", "coordinates": [][][2]float64{{{1, 2}, {3, 4}}}}}},
   329  			{types.JSONDocument{Val: map[string]interface{}{"type": "MultiLineString", "coordinates": [][][2]float64{{{1, 2}, {3, 4}, {5, 6}}}}}},
   330  		},
   331  	},
   332  	{
   333  		Query: `SELECT ST_ASGEOJSON(ST_GEOMFROMGEOJSON(s)) from stringtogeojson_table`,
   334  		Expected: []sql.Row{
   335  			{types.JSONDocument{Val: map[string]interface{}{"type": "Point", "coordinates": [2]float64{1, 2}}}},
   336  			{types.JSONDocument{Val: map[string]interface{}{"type": "Point", "coordinates": [2]float64{123.45, 56.789}}}},
   337  			{types.JSONDocument{Val: map[string]interface{}{"type": "LineString", "coordinates": [][2]float64{{1, 2}, {3, 4}}}}},
   338  			{types.JSONDocument{Val: map[string]interface{}{"type": "LineString", "coordinates": [][2]float64{{1.23, 2.345}, {3.56789, 4.56}}}}},
   339  			{types.JSONDocument{Val: map[string]interface{}{"type": "Polygon", "coordinates": [][][2]float64{{{1.1, 2.2}, {3.3, 4.4}, {5.5, 6.6}, {1.1, 2.2}}}}}},
   340  			{types.JSONDocument{Val: map[string]interface{}{"type": "Polygon", "coordinates": [][][2]float64{{{0, 0}, {1, 1}, {2, 2}, {0, 0}}}}}},
   341  			{types.JSONDocument{Val: map[string]interface{}{"type": "MultiPoint", "coordinates": [][2]float64{{1, 2}, {3, 4}}}}},
   342  			{types.JSONDocument{Val: map[string]interface{}{"type": "MultiPoint", "coordinates": [][2]float64{{1.23, 2.345}, {3.56789, 4.56}}}}},
   343  			{types.JSONDocument{Val: map[string]interface{}{"type": "MultiLineString", "coordinates": [][][2]float64{{{1.1, 2.2}, {3.3, 4.4}}, {{5.5, 6.6}, {7.7, 8.8}}}}}},
   344  			{types.JSONDocument{Val: map[string]interface{}{"type": "MultiPolygon", "coordinates": [][][][2]float64{{{{0, 0}, {1.1, 2.2}, {3.3, 4.4}, {0, 0}}}, {{{1.1, 1.1}, {1.1, 2.2}, {3.3, 4.4}, {1.1, 1.1}}}}}}},
   345  			{types.JSONDocument{Val: map[string]interface{}{"type": "GeometryCollection", "geometries": []interface{}{map[string]interface{}{"type": "GeometryCollection", "geometries": []interface{}{}}}}}},
   346  		},
   347  	},
   348  	{
   349  		Query: `SELECT ST_GEOMFROMGEOJSON(ST_ASGEOJSON(p)) from point_table`,
   350  		Expected: []sql.Row{
   351  			{types.Point{SRID: 4326, X: 1, Y: 2}},
   352  		},
   353  	},
   354  	{
   355  		Query: `SELECT ST_GEOMFROMGEOJSON(ST_ASGEOJSON(l)) from line_table`,
   356  		Expected: []sql.Row{
   357  			{types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}},
   358  			{types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 5, Y: 6}}}},
   359  		},
   360  	},
   361  	{
   362  		Query: `SELECT ST_GEOMFROMGEOJSON(ST_ASGEOJSON(p)) from polygon_table`,
   363  		Expected: []sql.Row{
   364  			{types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}},
   365  			{types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}, {SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}},
   366  		},
   367  	},
   368  	{
   369  		Query: `SELECT ST_GEOMFROMGEOJSON(ST_ASGEOJSON(p)) from mpoint_table`,
   370  		Expected: []sql.Row{
   371  			{types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}},
   372  			{types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 5, Y: 6}}}},
   373  		},
   374  	},
   375  	{
   376  		Query: `SELECT ST_GEOMFROMGEOJSON(ST_ASGEOJSON(l)) from mline_table`,
   377  		Expected: []sql.Row{
   378  			{types.MultiLineString{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}}},
   379  			{types.MultiLineString{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 5, Y: 6}}}}}},
   380  		},
   381  	},
   382  	{
   383  		Query: `SELECT ST_GEOMFROMGEOJSON(ST_ASGEOJSON(p)) from mpoly_table`,
   384  		Expected: []sql.Row{
   385  			{types.MultiPolygon{SRID: 4326, Polygons: []types.Polygon{{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 0, Y: 0}}}}}}}},
   386  			{types.MultiPolygon{SRID: 4326, Polygons: []types.Polygon{
   387  				{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 0, Y: 0}}}}},
   388  				{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 2, Y: 3}, {SRID: 4326, X: 4, Y: 5}, {SRID: 4326, X: 1, Y: 1}}}}}}}},
   389  		},
   390  	},
   391  	{
   392  		Query: `SELECT ST_GEOMFROMGEOJSON(ST_ASGEOJSON(g)) from geom_coll_table`,
   393  		Expected: []sql.Row{
   394  			{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{}}}}},
   395  		},
   396  	},
   397  	{
   398  		Query: `SELECT ST_DIMENSION(p) from point_table`,
   399  		Expected: []sql.Row{
   400  			{0},
   401  		},
   402  	},
   403  	{
   404  		Query: `SELECT ST_DIMENSION(l) from line_table`,
   405  		Expected: []sql.Row{
   406  			{1},
   407  			{1},
   408  		},
   409  	},
   410  	{
   411  		Query: `SELECT ST_DIMENSION(p) from polygon_table`,
   412  		Expected: []sql.Row{
   413  			{2},
   414  			{2},
   415  		},
   416  	},
   417  	{
   418  		Query: `SELECT ST_DIMENSION(p) from mpoint_table`,
   419  		Expected: []sql.Row{
   420  			{0},
   421  			{0},
   422  		},
   423  	},
   424  	{
   425  		Query: `SELECT ST_DIMENSION(l) from mline_table`,
   426  		Expected: []sql.Row{
   427  			{1},
   428  			{1},
   429  		},
   430  	},
   431  	{
   432  		Query: `SELECT ST_DIMENSION(p) from mpoly_table`,
   433  		Expected: []sql.Row{
   434  			{2},
   435  			{2},
   436  		},
   437  	},
   438  	{
   439  		Query: `SELECT ST_DIMENSION(g) from geom_coll_table`,
   440  		Expected: []sql.Row{
   441  			{nil},
   442  		},
   443  	},
   444  	{
   445  		Query: `SELECT ST_SWAPXY(p) from point_table`,
   446  		Expected: []sql.Row{
   447  			{types.Point{X: 2, Y: 1}},
   448  		},
   449  	},
   450  	{
   451  		Query: `SELECT ST_SWAPXY(l) from line_table`,
   452  		Expected: []sql.Row{
   453  			{types.LineString{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}}}},
   454  			{types.LineString{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}, {X: 6, Y: 5}}}},
   455  		},
   456  	},
   457  	{
   458  		Query: `SELECT ST_SWAPXY(p) from polygon_table`,
   459  		Expected: []sql.Row{
   460  			{types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}},
   461  			{types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}, {X: 0, Y: 0}}}, {Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}},
   462  		},
   463  	},
   464  	{
   465  		Query: `SELECT ST_ASWKT(g) from geometry_table ORDER BY i`,
   466  		Expected: []sql.Row{
   467  			{"POINT(1 2)"},
   468  			{"POINT(2 1)"},
   469  			{"LINESTRING(1 2,3 4)"},
   470  			{"LINESTRING(2 1,4 3)"},
   471  			{"POLYGON((0 0,0 1,1 1,0 0))"},
   472  			{"POLYGON((0 0,1 0,1 1,0 0))"},
   473  			{"MULTIPOINT(1 2,3 4)"},
   474  			{"MULTIPOINT(2 1,4 3)"},
   475  			{"MULTILINESTRING((1 2,3 4))"},
   476  			{"MULTILINESTRING((2 1,4 3))"},
   477  			{"MULTIPOLYGON(((0 0,1 2,3 4,0 0)))"},
   478  			{"MULTIPOLYGON(((0 0,2 1,4 3,0 0)))"},
   479  			{"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION())"},
   480  			{"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION())"},
   481  		},
   482  	},
   483  	{
   484  		Query: `SELECT ST_SWAPXY(p) from mpoint_table`,
   485  		Expected: []sql.Row{
   486  			{types.MultiPoint{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}}}},
   487  			{types.MultiPoint{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}, {X: 6, Y: 5}}}},
   488  		},
   489  	},
   490  	{
   491  		Query: `SELECT ST_SWAPXY(l) from mline_table`,
   492  		Expected: []sql.Row{
   493  			{types.MultiLineString{Lines: []types.LineString{{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}}}}}},
   494  			{types.MultiLineString{Lines: []types.LineString{{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}, {X: 6, Y: 5}}}}}},
   495  		},
   496  	},
   497  	{
   498  		Query: `SELECT ST_SWAPXY(p) from mpoly_table`,
   499  		Expected: []sql.Row{
   500  			{types.MultiPolygon{Polygons: []types.Polygon{{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 2, Y: 1}, {X: 4, Y: 3}, {X: 0, Y: 0}}}}}}}},
   501  			{types.MultiPolygon{Polygons: []types.Polygon{
   502  				{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 2, Y: 1}, {X: 4, Y: 3}, {X: 0, Y: 0}}}}},
   503  				{Lines: []types.LineString{{Points: []types.Point{{X: 1, Y: 1}, {X: 3, Y: 2}, {X: 5, Y: 4}, {X: 1, Y: 1}}}}},
   504  			}}},
   505  		},
   506  	},
   507  	{
   508  		Query: `SELECT HEX(ST_ASWKB(g)) from geometry_table ORDER BY i`,
   509  		Expected: []sql.Row{
   510  			{"0101000000000000000000F03F0000000000000040"},
   511  			{"01010000000000000000000040000000000000F03F"},
   512  			{"010200000002000000000000000000F03F000000000000004000000000000008400000000000001040"},
   513  			{"0102000000020000000000000000000040000000000000F03F00000000000010400000000000000840"},
   514  			{"01030000000100000004000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F00000000000000000000000000000000"},
   515  			{"0103000000010000000400000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000"},
   516  			{"0104000000020000000101000000000000000000F03F0000000000000040010100000000000000000008400000000000001040"},
   517  			{"01040000000200000001010000000000000000000040000000000000F03F010100000000000000000010400000000000000840"},
   518  			{"010500000001000000010200000002000000000000000000F03F000000000000004000000000000008400000000000001040"},
   519  			{"0105000000010000000102000000020000000000000000000040000000000000F03F00000000000010400000000000000840"},
   520  			{"0106000000010000000103000000010000000400000000000000000000000000000000000000000000000000F03F00000000000000400000000000000840000000000000104000000000000000000000000000000000"},
   521  			{"01060000000100000001030000000100000004000000000000000000000000000000000000000000000000000040000000000000F03F0000000000001040000000000000084000000000000000000000000000000000"},
   522  			{"010700000001000000010700000000000000"},
   523  			{"010700000001000000010700000000000000"},
   524  		},
   525  	},
   526  	{
   527  		Query: `SELECT ST_SRID(g) from geometry_table order by i`,
   528  		Expected: []sql.Row{
   529  			{uint64(0)},
   530  			{uint64(4326)},
   531  			{uint64(0)},
   532  			{uint64(4326)},
   533  			{uint64(0)},
   534  			{uint64(4326)},
   535  			{uint64(0)},
   536  			{uint64(4326)},
   537  			{uint64(0)},
   538  			{uint64(4326)},
   539  			{uint64(0)},
   540  			{uint64(4326)},
   541  			{uint64(0)},
   542  			{uint64(4326)},
   543  		},
   544  	},
   545  	{
   546  		Query: `SELECT ST_SRID(g, 0) from geometry_table order by i`,
   547  		Expected: []sql.Row{
   548  			{types.Point{X: 1, Y: 2}},
   549  			{types.Point{X: 1, Y: 2}},
   550  			{types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}},
   551  			{types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}},
   552  			{types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}},
   553  			{types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}},
   554  			{types.MultiPoint{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}},
   555  			{types.MultiPoint{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}},
   556  			{types.MultiLineString{SRID: 0, Lines: []types.LineString{{SRID: 0, Points: []types.Point{{SRID: 0, X: 1, Y: 2}, {SRID: 0, X: 3, Y: 4}}}}}},
   557  			{types.MultiLineString{SRID: 0, Lines: []types.LineString{{SRID: 0, Points: []types.Point{{SRID: 0, X: 1, Y: 2}, {SRID: 0, X: 3, Y: 4}}}}}},
   558  			{types.MultiPolygon{SRID: 0, Polygons: []types.Polygon{{SRID: 0, Lines: []types.LineString{{SRID: 0, Points: []types.Point{{SRID: 0, X: 0, Y: 0}, {SRID: 0, X: 1, Y: 2}, {SRID: 0, X: 3, Y: 4}, {SRID: 0, X: 0, Y: 0}}}}}}}},
   559  			{types.MultiPolygon{SRID: 0, Polygons: []types.Polygon{{SRID: 0, Lines: []types.LineString{{SRID: 0, Points: []types.Point{{SRID: 0, X: 0, Y: 0}, {SRID: 0, X: 1, Y: 2}, {SRID: 0, X: 3, Y: 4}, {SRID: 0, X: 0, Y: 0}}}}}}}},
   560  			{types.GeomColl{Geoms: []types.GeometryValue{types.GeomColl{Geoms: []types.GeometryValue{}}}}},
   561  			{types.GeomColl{Geoms: []types.GeometryValue{types.GeomColl{Geoms: []types.GeometryValue{}}}}},
   562  		},
   563  	},
   564  	{
   565  		Query: `SELECT ST_DIMENSION(g) from geometry_table order by i`,
   566  		Expected: []sql.Row{
   567  			{0},
   568  			{0},
   569  			{1},
   570  			{1},
   571  			{2},
   572  			{2},
   573  			{0},
   574  			{0},
   575  			{1},
   576  			{1},
   577  			{2},
   578  			{2},
   579  			{nil},
   580  			{nil},
   581  		},
   582  	},
   583  	{
   584  		Query: `SELECT ST_SWAPXY(g) from geometry_table order by i`,
   585  		Expected: []sql.Row{
   586  			{types.Point{X: 2, Y: 1}},
   587  			{types.Point{SRID: 4326, X: 2, Y: 1}},
   588  			{types.LineString{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}}}},
   589  			{types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 2, Y: 1}, {SRID: 4326, X: 4, Y: 3}}}},
   590  			{types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}},
   591  			{types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1, Y: 0}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}},
   592  			{types.MultiPoint{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}}}},
   593  			{types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 2, Y: 1}, {SRID: 4326, X: 4, Y: 3}}}},
   594  			{types.MultiLineString{SRID: 0, Lines: []types.LineString{{SRID: 0, Points: []types.Point{{SRID: 0, X: 2, Y: 1}, {SRID: 0, X: 4, Y: 3}}}}}},
   595  			{types.MultiLineString{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 2, Y: 1}, {SRID: 4326, X: 4, Y: 3}}}}}},
   596  			{types.MultiPolygon{SRID: 0, Polygons: []types.Polygon{{SRID: 0, Lines: []types.LineString{{SRID: 0, Points: []types.Point{{SRID: 0, X: 0, Y: 0}, {SRID: 0, X: 2, Y: 1}, {SRID: 0, X: 4, Y: 3}, {SRID: 0, X: 0, Y: 0}}}}}}}},
   597  			{types.MultiPolygon{SRID: 4326, Polygons: []types.Polygon{{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 2, Y: 1}, {SRID: 4326, X: 4, Y: 3}, {SRID: 4326, X: 0, Y: 0}}}}}}}},
   598  			{types.GeomColl{Geoms: []types.GeometryValue{types.GeomColl{Geoms: []types.GeometryValue{}}}}},
   599  			{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{}}}}},
   600  		},
   601  	},
   602  	{
   603  		Query: `SELECT ST_AREA(p) from polygon_table`,
   604  		Expected: []sql.Row{
   605  			{0.5},
   606  			{0.0},
   607  		},
   608  	},
   609  	{
   610  		Query: `SELECT ST_PERIMETER(p) from polygon_table`,
   611  		Expected: []sql.Row{
   612  			{3.414213562373095},
   613  			{6.82842712474619},
   614  		},
   615  	},
   616  	{
   617  		Query: `SELECT ST_LENGTH(l) from line_table`,
   618  		Expected: []sql.Row{
   619  			{2.8284271247461903},
   620  			{5.656854249492381},
   621  		},
   622  	},
   623  	{
   624  		Query: `SELECT ST_ASWKT(g) from geometry_table where g = point(1,2)`,
   625  		Expected: []sql.Row{
   626  			{"POINT(1 2)"},
   627  		},
   628  	},
   629  	{
   630  		Query: `SELECT ST_ASWKT(g) from geometry_table where g = st_srid(point(1,2),4326)`,
   631  		Expected: []sql.Row{
   632  			{"POINT(2 1)"},
   633  		},
   634  	},
   635  	{
   636  		Query: `SELECT ST_ASWKT(g) from geometry_table where g = unhex(hex(point(1,2)))`,
   637  		Expected: []sql.Row{
   638  			{"POINT(1 2)"},
   639  		},
   640  	},
   641  	{
   642  		Query: `SELECT unhex(hex(point(1,2))) < unhex(hex(point(3,4)))`,
   643  		Expected: []sql.Row{
   644  			{false},
   645  		},
   646  	},
   647  	{
   648  		Query: `SELECT ST_ASWKT(g) from geometry_table where g = st_geomfromtext('MultiPolygon(((0 0,1 2,3 4,0 0)))')`,
   649  		Expected: []sql.Row{
   650  			{"MULTIPOLYGON(((0 0,1 2,3 4,0 0)))"},
   651  		},
   652  	},
   653  	{
   654  		Query: `SELECT ST_ASWKT(g) from geometry_table ORDER BY g`,
   655  		Expected: []sql.Row{
   656  			{"POINT(1 2)"},
   657  			{"LINESTRING(1 2,3 4)"},
   658  			{"POLYGON((0 0,0 1,1 1,0 0))"},
   659  			{"MULTIPOINT(1 2,3 4)"},
   660  			{"MULTILINESTRING((1 2,3 4))"},
   661  			{"MULTIPOLYGON(((0 0,1 2,3 4,0 0)))"},
   662  			{"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION())"},
   663  			{"POINT(2 1)"},
   664  			{"LINESTRING(2 1,4 3)"},
   665  			{"POLYGON((0 0,1 0,1 1,0 0))"},
   666  			{"MULTIPOINT(2 1,4 3)"},
   667  			{"MULTILINESTRING((2 1,4 3))"},
   668  			{"MULTIPOLYGON(((0 0,2 1,4 3,0 0)))"},
   669  			{"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION())"},
   670  		},
   671  	},
   672  	{
   673  		Query: `SELECT ST_DISTANCE(st_srid(g, 0), point(0,0)) from geometry_table ORDER BY g`,
   674  		Expected: []sql.Row{
   675  			{math.Sqrt(5)},
   676  			{math.Sqrt(5)},
   677  			{0.0},
   678  			{math.Sqrt(5)},
   679  			{math.Sqrt(5)},
   680  			{0.0},
   681  			{nil},
   682  			{math.Sqrt(5)},
   683  			{math.Sqrt(5)},
   684  			{0.0},
   685  			{math.Sqrt(5)},
   686  			{math.Sqrt(5)},
   687  			{0.0},
   688  			{nil},
   689  		},
   690  	},
   691  	{
   692  		Query: `SELECT st_startpoint(g) from geometry_table ORDER BY g`,
   693  		Expected: []sql.Row{
   694  			{nil},
   695  			{types.Point{X: 1, Y: 2}},
   696  			{nil},
   697  			{nil},
   698  			{nil},
   699  			{nil},
   700  			{nil},
   701  			{nil},
   702  			{types.Point{SRID: types.GeoSpatialSRID, X: 1, Y: 2}},
   703  			{nil},
   704  			{nil},
   705  			{nil},
   706  			{nil},
   707  			{nil},
   708  		},
   709  	},
   710  	{
   711  		Query: `SELECT st_endpoint(g) from geometry_table ORDER BY g`,
   712  		Expected: []sql.Row{
   713  			{nil},
   714  			{types.Point{X: 3, Y: 4}},
   715  			{nil},
   716  			{nil},
   717  			{nil},
   718  			{nil},
   719  			{nil},
   720  			{nil},
   721  			{types.Point{SRID: types.GeoSpatialSRID, X: 3, Y: 4}},
   722  			{nil},
   723  			{nil},
   724  			{nil},
   725  			{nil},
   726  			{nil},
   727  		},
   728  	},
   729  	{
   730  		Query: `SELECT st_isclosed(g) from geometry_table ORDER BY g`,
   731  		Expected: []sql.Row{
   732  			{nil},
   733  			{false},
   734  			{nil},
   735  			{nil},
   736  			{false},
   737  			{nil},
   738  			{nil},
   739  			{nil},
   740  			{false},
   741  			{nil},
   742  			{nil},
   743  			{false},
   744  			{nil},
   745  			{nil},
   746  		},
   747  	},
   748  	{
   749  		Query: `SELECT st_intersects(st_srid(g, 0), point(1,2)) from geometry_table ORDER BY g`,
   750  		Expected: []sql.Row{
   751  			{true},
   752  			{true},
   753  			{false},
   754  			{true},
   755  			{true},
   756  			{true},
   757  			{false},
   758  			{true},
   759  			{true},
   760  			{false},
   761  			{true},
   762  			{true},
   763  			{true},
   764  			{false},
   765  		},
   766  	},
   767  }
   768  
   769  var QueryTests = []QueryTest{
   770  	{
   771  		Query: "select 0 as col1, 1 as col2, 2 as col2 group by col2 having col2 = 1",
   772  		Expected: []sql.Row{
   773  			{0, 1, 2},
   774  		},
   775  	},
   776  	{
   777  		// Assert that SYSDATE() returns different times on each call in a query (unlike NOW())
   778  		// Using the maximum precision for fractional seconds, lets us see a difference.
   779  		Query:    "select now() = sysdate(), sleep(0.1), now(6) < sysdate(6);",
   780  		Expected: []sql.Row{{true, 0, true}},
   781  	},
   782  	{
   783  		Query:    "select 1 as x from xy having AVG(x) > 0",
   784  		Expected: []sql.Row{{1}},
   785  	},
   786  	{
   787  		Query:    "select 1 as x, AVG(x) from xy group by (y) having AVG(x) > 0",
   788  		Expected: []sql.Row{{1, float64(1)}, {1, float64(2)}, {1, float64(3)}},
   789  	},
   790  	{
   791  		Query:    "select y as x from xy group by (y) having AVG(x) > 0",
   792  		Expected: []sql.Row{{0}, {1}, {3}},
   793  	},
   794  	//{
   795  	//	Query:    "select y as z from xy group by (y) having AVG(z) > 0",
   796  	//	Expected: []sql.Row{{1}, {2}, {3}},
   797  	//},
   798  	{
   799  		Query:    "SELECT * FROM mytable t0 INNER JOIN mytable t1 ON (t1.i IN (((true)%(''))));",
   800  		Expected: []sql.Row{},
   801  	},
   802  	{
   803  		Query:    "select x from xy where y in (select xy.x from xy join (select t2.y from xy t2 where exists (select t3.y from xy t3 where t3.y = xy.x)) t1) order by 1;",
   804  		Expected: []sql.Row{{0}, {1}, {2}, {3}},
   805  	},
   806  	{
   807  		Query:    "select x from xy where y in (select x from xy where x in (select y from xy)) order by 1;",
   808  		Expected: []sql.Row{{0}, {1}, {2}, {3}},
   809  	},
   810  	{
   811  		Query:    "SELECT 1 WHERE ((1 IN (NULL >= 1)) IS NULL);",
   812  		Expected: []sql.Row{{1}},
   813  	},
   814  	{
   815  		Query:    "SELECT 1 WHERE (1 IN (NULL NOT BETWEEN -1 AND 1)) IS NULL;",
   816  		Expected: []sql.Row{{1}},
   817  	},
   818  	{
   819  		Query:    "SELECT 1 WHERE ((1 IN (NULL * 1)) IS NULL);",
   820  		Expected: []sql.Row{{1}},
   821  	},
   822  	{
   823  		Query:    "SELECT count(*) from mytable WHERE ((i IN (NULL >= 1)) IS NULL);",
   824  		Expected: []sql.Row{{3}},
   825  	},
   826  	{
   827  		Query:    "SELECT count(*) from mytable WHERE (i IN (NULL NOT BETWEEN -1 AND 1)) IS NULL;",
   828  		Expected: []sql.Row{{3}},
   829  	},
   830  	{
   831  		Query:    "SELECT count(*) from mytable WHERE ((i IN (NULL * 1)) IS NULL);",
   832  		Expected: []sql.Row{{3}},
   833  	},
   834  	{
   835  		Query:    "SELECT count(*) from mytable WHERE (i IN (-''));",
   836  		Expected: []sql.Row{{0}},
   837  	},
   838  	{
   839  		Query:    "SELECT 1 % true",
   840  		Expected: []sql.Row{{"0"}},
   841  	},
   842  	{
   843  		Query:    "SELECT * from mytable where (0.000 and true)",
   844  		Expected: []sql.Row{},
   845  	},
   846  	{
   847  		Query:    "SELECT * from mytable where (-0.000 and true)",
   848  		Expected: []sql.Row{},
   849  	},
   850  	{
   851  		Query:    "SELECT 1 WHERE power(88.0447354000000000000000333333333,100) % 1;",
   852  		Expected: []sql.Row{},
   853  	},
   854  	{
   855  		SkipServerEngine: true,
   856  		Query:            "show full processlist",
   857  		Expected:         []sql.Row{},
   858  	},
   859  	{
   860  		Query: "select * from (select i, i2 from niltable) a(x,y) union select * from (select 1, NULL) b(x,y) union select * from (select i, i2 from niltable) c(x,y)",
   861  		ExpectedColumns: sql.Schema{
   862  			{
   863  				Name: "x",
   864  				Type: types.Int64,
   865  			},
   866  			{
   867  				Name: "y",
   868  				Type: types.Int64,
   869  			},
   870  		},
   871  		Expected: []sql.Row{
   872  			{1, nil},
   873  			{2, 2},
   874  			{3, nil},
   875  			{4, 4},
   876  			{5, nil},
   877  			{6, 6},
   878  		},
   879  	},
   880  	{
   881  		Query: "select * from (select 1, 1) a(x,y) union select * from (select 1, NULL) b(x,y) union select * from (select 1,1) c(x,y);",
   882  		ExpectedColumns: sql.Schema{
   883  			{
   884  				Name: "x",
   885  				Type: types.Int8,
   886  			},
   887  			{
   888  				Name: "y",
   889  				Type: types.Int64,
   890  			},
   891  		},
   892  		Expected: []sql.Row{
   893  			{1, 1},
   894  			{1, nil},
   895  		},
   896  	},
   897  	{
   898  		Query: `SELECT I,S from mytable order by 1`,
   899  		ExpectedColumns: sql.Schema{
   900  			{
   901  				Name: "I",
   902  				Type: types.Int64,
   903  			},
   904  			{
   905  				Name: "S",
   906  				Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20),
   907  			},
   908  		},
   909  		Expected: []sql.Row{
   910  			{1, "first row"},
   911  			{2, "second row"},
   912  			{3, "third row"},
   913  		},
   914  	},
   915  	{
   916  		Query: `SELECT s as i, i as i from mytable order by 1`,
   917  		Expected: []sql.Row{
   918  			{"first row", 1},
   919  			{"second row", 2},
   920  			{"third row", 3},
   921  		},
   922  	},
   923  	{
   924  		Query:    "SELECT SUM(i), i FROM mytable GROUP BY i ORDER BY 1+SUM(i) ASC",
   925  		Expected: []sql.Row{{float64(1), 1}, {float64(2), 2}, {float64(3), 3}},
   926  	},
   927  	{
   928  		Query:    "SELECT SUM(i) as sum, i FROM mytable GROUP BY i ORDER BY 1+SUM(i) ASC",
   929  		Expected: []sql.Row{{float64(1), 1}, {float64(2), 2}, {float64(3), 3}},
   930  	},
   931  	{
   932  		Query:    "select count(1)",
   933  		Expected: []sql.Row{{1}},
   934  	},
   935  	{
   936  		Query:    "select count(100)",
   937  		Expected: []sql.Row{{1}},
   938  	},
   939  	{
   940  		Query:    "select sum(1)",
   941  		Expected: []sql.Row{{float64(1)}},
   942  	},
   943  	{
   944  		Query:    "select sum(100)",
   945  		Expected: []sql.Row{{float64(100)}},
   946  	},
   947  	{
   948  		Query:    "select count(*) from mytable",
   949  		Expected: []sql.Row{{3}},
   950  	},
   951  	{
   952  		Query:    `select count(*) as cnt from mytable`,
   953  		Expected: []sql.Row{{3}},
   954  	},
   955  	{
   956  		Query:    "select count(*) from keyless",
   957  		Expected: []sql.Row{{4}},
   958  	},
   959  	{
   960  		Query:    "select count(*) from xy",
   961  		Expected: []sql.Row{{4}},
   962  	},
   963  	{
   964  		Query:    "select count(*) from xy alias",
   965  		Expected: []sql.Row{{4}},
   966  	},
   967  	{
   968  		Query:    "select count(1) from mytable",
   969  		Expected: []sql.Row{{3}},
   970  	},
   971  	{
   972  		Query:    "select count(1) from xy",
   973  		Expected: []sql.Row{{4}},
   974  	},
   975  	{
   976  		Query:    "select count(1) from xy, uv",
   977  		Expected: []sql.Row{{16}},
   978  	},
   979  	{
   980  		Query:    "select count('abc') from xy, uv",
   981  		Expected: []sql.Row{{16}},
   982  	},
   983  	{
   984  		Query:    "select sum('abc') from mytable",
   985  		Expected: []sql.Row{{float64(0)}},
   986  	},
   987  	{
   988  		Query:    "select sum(10) from mytable",
   989  		Expected: []sql.Row{{float64(30)}},
   990  	},
   991  	{
   992  		Query:    "select sum(1) from emptytable",
   993  		Expected: []sql.Row{{nil}},
   994  	},
   995  	{
   996  		Query:    "select * from (select count(*) from xy) dt",
   997  		Expected: []sql.Row{{4}},
   998  	},
   999  	{
  1000  		Query:    "select (select count(*) from xy), (select count(*) from uv)",
  1001  		Expected: []sql.Row{{4, 4}},
  1002  	},
  1003  	{
  1004  		Query:    "select (select count(*) from xy), (select count(*) from uv), count(*) from ab",
  1005  		Expected: []sql.Row{{4, 4, 4}},
  1006  	},
  1007  	{
  1008  		Query:    "select i from mytable alias where i = 1 and s = 'first row'",
  1009  		Expected: []sql.Row{{1}},
  1010  	},
  1011  	{
  1012  		Query: `
  1013  Select x
  1014  from (select * from xy) sq1
  1015  union all
  1016  select u
  1017  from (select * from uv) sq2
  1018  limit 1
  1019  offset 1;`,
  1020  		Expected: []sql.Row{{1}},
  1021  	},
  1022  	{
  1023  		Query: `
  1024  Select * from (
  1025    With recursive cte(s) as (select 1 union select x from xy join cte on x = s)
  1026    Select * from cte
  1027    Union
  1028    Select x from xy where x in (select * from cte)
  1029   ) dt;`,
  1030  		Expected: []sql.Row{{1}},
  1031  	},
  1032  	{
  1033  		// https://github.com/dolthub/dolt/issues/5642
  1034  		Query:    "SELECT count(*) FROM mytable WHERE i = 3720481604718463778705849469618542795;",
  1035  		Expected: []sql.Row{{0}},
  1036  	},
  1037  	{
  1038  		Query:    "SELECT count(*) FROM mytable WHERE i <> 3720481604718463778705849469618542795;",
  1039  		Expected: []sql.Row{{3}},
  1040  	},
  1041  	{
  1042  		Query:    "SELECT count(*) FROM mytable WHERE i < 3720481604718463778705849469618542795 AND i > 0;",
  1043  		Expected: []sql.Row{{3}},
  1044  	},
  1045  	{
  1046  		Query:    "SELECT count(*) FROM mytable WHERE i < 3720481604718463778705849469618542795 OR i > 0;",
  1047  		Expected: []sql.Row{{3}},
  1048  	},
  1049  	{
  1050  		// https://github.com/dolthub/dolt/issues/4874
  1051  		Query:    "select * from information_schema.columns where column_key in ('invalid_enum_value') and table_name = 'does_not_exist';",
  1052  		Expected: []sql.Row{},
  1053  	},
  1054  	{
  1055  		Query:    "select 0 in ('hi', 'bye'), 1 in ('hi', 'bye');",
  1056  		Expected: []sql.Row{{true, false}},
  1057  	},
  1058  	{
  1059  		Query:    "select count(*) from typestable where e1 in ('hi', 'bye');",
  1060  		Expected: []sql.Row{{0}},
  1061  	},
  1062  	{
  1063  		Query:    "select count(*) from typestable where e1 in ('', 'bye');",
  1064  		Expected: []sql.Row{{1}},
  1065  	},
  1066  	{
  1067  		Query:    "select count(*) from typestable where s1 in ('hi', 'bye');",
  1068  		Expected: []sql.Row{{0}},
  1069  	},
  1070  	{
  1071  		Query:    "select count(*) from typestable where s1 in ('', 'bye');",
  1072  		Expected: []sql.Row{{1}},
  1073  	},
  1074  	{
  1075  		Query: "SELECT * FROM mytable;",
  1076  		Expected: []sql.Row{
  1077  			{int64(1), "first row"},
  1078  			{int64(2), "second row"},
  1079  			{int64(3), "third row"},
  1080  		},
  1081  		ExpectedColumns: sql.Schema{
  1082  			{
  1083  				Name: "i",
  1084  				Type: types.Int64,
  1085  			},
  1086  			{
  1087  				Name: "s",
  1088  				Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20),
  1089  			},
  1090  		},
  1091  	},
  1092  	{
  1093  		Query: "SELECT mytable.* FROM mytable;",
  1094  		Expected: []sql.Row{
  1095  			{int64(1), "first row"},
  1096  			{int64(2), "second row"},
  1097  			{int64(3), "third row"},
  1098  		},
  1099  		ExpectedColumns: sql.Schema{
  1100  			{
  1101  				Name: "i",
  1102  				Type: types.Int64,
  1103  			},
  1104  			{
  1105  				Name: "s",
  1106  				Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20),
  1107  			},
  1108  		},
  1109  	},
  1110  	{
  1111  		Query: "SELECT `mytable`.* FROM mytable;",
  1112  		Expected: []sql.Row{
  1113  			{int64(1), "first row"},
  1114  			{int64(2), "second row"},
  1115  			{int64(3), "third row"},
  1116  		},
  1117  		ExpectedColumns: sql.Schema{
  1118  			{
  1119  				Name: "i",
  1120  				Type: types.Int64,
  1121  			},
  1122  			{
  1123  				Name: "s",
  1124  				Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20),
  1125  			},
  1126  		},
  1127  	},
  1128  	{
  1129  		Query: "SELECT `i`, `s` FROM mytable;",
  1130  		Expected: []sql.Row{
  1131  			{int64(1), "first row"},
  1132  			{int64(2), "second row"},
  1133  			{int64(3), "third row"},
  1134  		},
  1135  		ExpectedColumns: sql.Schema{
  1136  			{
  1137  				Name: "i",
  1138  				Type: types.Int64,
  1139  			},
  1140  			{
  1141  				Name: "s",
  1142  				Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20),
  1143  			},
  1144  		},
  1145  	},
  1146  	{
  1147  		Query: "SELECT * FROM mytable ORDER BY i DESC;",
  1148  		Expected: []sql.Row{
  1149  			{int64(3), "third row"},
  1150  			{int64(2), "second row"},
  1151  			{int64(1), "first row"},
  1152  		},
  1153  	},
  1154  	{
  1155  		Query: "SELECT * FROM mytable GROUP BY i,s;",
  1156  		Expected: []sql.Row{
  1157  			{int64(1), "first row"},
  1158  			{int64(2), "second row"},
  1159  			{int64(3), "third row"},
  1160  		},
  1161  	},
  1162  	{
  1163  		Query: "SELECT count(*), i, concat(i, i), 123, 'abc', concat('abc', 'def') FROM emptytable;",
  1164  		Expected: []sql.Row{
  1165  			{0, nil, nil, 123, "abc", "abcdef"},
  1166  		},
  1167  	},
  1168  	{
  1169  		Query: "SELECT count(*), i, concat(i, i), 123, 'abc', concat('abc', 'def') FROM mytable where false;",
  1170  		Expected: []sql.Row{
  1171  			{0, nil, nil, 123, "abc", "abcdef"},
  1172  		},
  1173  	},
  1174  	{
  1175  		Query: "SELECT pk, u, v FROM one_pk JOIN (SELECT count(*) AS u, 123 AS v FROM emptytable) uv WHERE pk = u;",
  1176  		Expected: []sql.Row{
  1177  			{0, 0, 123},
  1178  		},
  1179  	},
  1180  	{
  1181  		Query: "SELECT pk, u, v FROM one_pk JOIN (SELECT count(*) AS u, 123 AS v FROM mytable WHERE false) uv WHERE pk = u;",
  1182  		Expected: []sql.Row{
  1183  			{0, 0, 123},
  1184  		},
  1185  	},
  1186  	{
  1187  		Query: "SELECT pk FROM one_pk WHERE (pk, 123) IN (SELECT count(*) AS u, 123 AS v FROM emptytable);",
  1188  		Expected: []sql.Row{
  1189  			{0},
  1190  		},
  1191  	},
  1192  	{
  1193  		Query: "SELECT pk FROM one_pk WHERE (pk, 123) IN (SELECT count(*) AS u, 123 AS v FROM mytable WHERE false);",
  1194  		Expected: []sql.Row{
  1195  			{0},
  1196  		},
  1197  	},
  1198  	{
  1199  		Query: "SELECT pk FROM one_pk WHERE (pk, 123) NOT IN (SELECT count(*) AS u, 123 AS v FROM emptytable);",
  1200  		Expected: []sql.Row{
  1201  			{1},
  1202  			{2},
  1203  			{3},
  1204  		},
  1205  	},
  1206  	{
  1207  		Query: "SELECT pk FROM one_pk WHERE (pk, 123) NOT IN (SELECT count(*) AS u, 123 AS v FROM mytable WHERE false);",
  1208  		Expected: []sql.Row{
  1209  			{1},
  1210  			{2},
  1211  			{3},
  1212  		},
  1213  	},
  1214  	{
  1215  		Query: "SELECT i FROM mytable WHERE EXISTS (SELECT * FROM (SELECT count(*) as u, 123 as v FROM emptytable) uv);",
  1216  		Expected: []sql.Row{
  1217  			{1},
  1218  			{2},
  1219  			{3},
  1220  		},
  1221  	},
  1222  	{
  1223  		Query: "SELECT count(*), (SELECT i FROM mytable WHERE i = 1 group by i);",
  1224  		Expected: []sql.Row{
  1225  			{1, 1},
  1226  		},
  1227  	},
  1228  	{
  1229  		Query: "SELECT pk DIV 2, SUM(c3) FROM one_pk GROUP BY 1 ORDER BY 1",
  1230  		Expected: []sql.Row{
  1231  			{int64(0), float64(14)},
  1232  			{int64(1), float64(54)},
  1233  		},
  1234  	},
  1235  	{
  1236  		Query: "SELECT pk DIV 2, SUM(c3) as sum FROM one_pk GROUP BY 1 ORDER BY 1",
  1237  		Expected: []sql.Row{
  1238  			{int64(0), float64(14)},
  1239  			{int64(1), float64(54)},
  1240  		},
  1241  	},
  1242  	{
  1243  		Query: "SELECT pk DIV 2, SUM(c3) + sum(c3) as sum FROM one_pk GROUP BY 1 ORDER BY 1",
  1244  		Expected: []sql.Row{
  1245  			{int64(0), float64(28)},
  1246  			{int64(1), float64(108)},
  1247  		},
  1248  	},
  1249  	{
  1250  		Query: "SELECT pk DIV 2, SUM(c3) + min(c3) as sum_and_min FROM one_pk GROUP BY 1 ORDER BY 1",
  1251  		Expected: []sql.Row{
  1252  			{int64(0), float64(16)},
  1253  			{int64(1), float64(76)},
  1254  		},
  1255  		ExpectedColumns: sql.Schema{
  1256  			{
  1257  				Name: "pk DIV 2",
  1258  				Type: types.Int64,
  1259  			},
  1260  			{
  1261  				Name: "sum_and_min",
  1262  				Type: types.Float64,
  1263  			},
  1264  		},
  1265  	},
  1266  	{
  1267  		Query: "SELECT pk DIV 2, SUM(`c3`) +    min( c3 ) FROM one_pk GROUP BY 1 ORDER BY 1",
  1268  		Expected: []sql.Row{
  1269  			{int64(0), float64(16)},
  1270  			{int64(1), float64(76)},
  1271  		},
  1272  		ExpectedColumns: sql.Schema{
  1273  			{
  1274  				Name: "pk DIV 2",
  1275  				Type: types.Int64,
  1276  			},
  1277  			{
  1278  				Name: "SUM(`c3`) +    min( c3 )",
  1279  				Type: types.Float64,
  1280  			},
  1281  		},
  1282  	},
  1283  	{
  1284  		Query: "SELECT pk1, SUM(c1) FROM two_pk GROUP BY pk1 ORDER BY pk1;",
  1285  		Expected: []sql.Row{
  1286  			{0, 10.0},
  1287  			{1, 50.0},
  1288  		},
  1289  	},
  1290  	{
  1291  		Query:    "select max(pk),c1+1 from one_pk group by c1 order by 1",
  1292  		Expected: []sql.Row{{0, 1}, {1, 11}, {2, 21}, {3, 31}},
  1293  	},
  1294  	{
  1295  		Query:    "SELECT pk1, SUM(c1) FROM two_pk WHERE pk1 = 0",
  1296  		Expected: []sql.Row{{0, 10.0}},
  1297  	},
  1298  	{
  1299  		Query:    "SELECT i FROM mytable;",
  1300  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}},
  1301  	},
  1302  	{
  1303  		Query:    "SELECT i AS x FROM mytable ORDER BY i DESC",
  1304  		Expected: []sql.Row{{3}, {2}, {1}},
  1305  	},
  1306  	{
  1307  		Query: "SELECT i AS s, mt.s FROM mytable mt ORDER BY i DESC",
  1308  		Expected: []sql.Row{
  1309  			{3, "third row"},
  1310  			{2, "second row"},
  1311  			{1, "first row"},
  1312  		},
  1313  		ExpectedColumns: sql.Schema{
  1314  			{
  1315  				Name: "s",
  1316  				Type: types.Int64,
  1317  			},
  1318  			{
  1319  				Name: "s",
  1320  				Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20),
  1321  			},
  1322  		},
  1323  	},
  1324  	{
  1325  		Query: "SELECT i AS s, s FROM mytable mt ORDER BY i DESC",
  1326  		Expected: []sql.Row{
  1327  			{3, "third row"},
  1328  			{2, "second row"},
  1329  			{1, "first row"},
  1330  		},
  1331  	},
  1332  	{
  1333  		Query: "SELECT floor(i), s FROM mytable mt ORDER BY floor(i) DESC",
  1334  		Expected: []sql.Row{
  1335  			{3, "third row"},
  1336  			{2, "second row"},
  1337  			{1, "first row"},
  1338  		},
  1339  	},
  1340  	{
  1341  		Query: "SELECT floor(i), avg(char_length(s)) FROM mytable mt group by 1 ORDER BY floor(i) DESC",
  1342  		Expected: []sql.Row{
  1343  			{3, 9.0},
  1344  			{2, 10.0},
  1345  			{1, 9.0},
  1346  		},
  1347  	},
  1348  	{
  1349  		Query:    "SELECT i AS x FROM mytable ORDER BY x DESC",
  1350  		Expected: []sql.Row{{3}, {2}, {1}},
  1351  	},
  1352  	{
  1353  		Query:    "SELECT i FROM mytable AS mt;",
  1354  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}},
  1355  	},
  1356  	{
  1357  		Query: "SELECT s,i FROM mytable;",
  1358  		Expected: []sql.Row{
  1359  			{"first row", int64(1)},
  1360  			{"second row", int64(2)},
  1361  			{"third row", int64(3)}},
  1362  	},
  1363  	{
  1364  		Query: "SELECT mytable.s,i FROM mytable;",
  1365  		Expected: []sql.Row{
  1366  			{"first row", int64(1)},
  1367  			{"second row", int64(2)},
  1368  			{"third row", int64(3)}},
  1369  	},
  1370  	{
  1371  		Query: "SELECT t.s,i FROM mytable AS t;",
  1372  		Expected: []sql.Row{
  1373  			{"first row", int64(1)},
  1374  			{"second row", int64(2)},
  1375  			{"third row", int64(3)},
  1376  		},
  1377  	},
  1378  	{
  1379  		Query: "SELECT s,i FROM mytable order by i DESC;",
  1380  		Expected: []sql.Row{
  1381  			{"third row", int64(3)},
  1382  			{"second row", int64(2)},
  1383  			{"first row", int64(1)},
  1384  		},
  1385  	},
  1386  	{
  1387  		Query: "SELECT s,i FROM mytable as a order by i;",
  1388  		Expected: []sql.Row{
  1389  			{"first row", int64(1)},
  1390  			{"second row", int64(2)},
  1391  			{"third row", int64(3)}},
  1392  	},
  1393  	{
  1394  		Query: "SELECT pk1, pk2 FROM two_pk order by pk1 asc, pk2 asc;",
  1395  		Expected: []sql.Row{
  1396  			{0, 0},
  1397  			{0, 1},
  1398  			{1, 0},
  1399  			{1, 1},
  1400  		},
  1401  	},
  1402  	{
  1403  		Query: "SELECT pk1, pk2 FROM two_pk order by pk1 asc, pk2 desc;",
  1404  		Expected: []sql.Row{
  1405  			{0, 1},
  1406  			{0, 0},
  1407  			{1, 1},
  1408  			{1, 0},
  1409  		},
  1410  	},
  1411  	{
  1412  		Query: "SELECT pk1, pk2 FROM two_pk order by pk1 desc, pk2 desc;",
  1413  		Expected: []sql.Row{
  1414  			{1, 1},
  1415  			{1, 0},
  1416  			{0, 1},
  1417  			{0, 0},
  1418  		},
  1419  	},
  1420  	{
  1421  		Query: "SELECT pk1, pk2 FROM two_pk group by pk1, pk2 order by pk1, pk2",
  1422  		Expected: []sql.Row{
  1423  			{0, 0},
  1424  			{0, 1},
  1425  			{1, 0},
  1426  			{1, 1},
  1427  		},
  1428  	},
  1429  	{
  1430  		Query: "SELECT pk1, pk2 FROM two_pk group by pk1, pk2 order by pk1 desc, pk2 desc",
  1431  		Expected: []sql.Row{
  1432  			{1, 1},
  1433  			{1, 0},
  1434  			{0, 1},
  1435  			{0, 0},
  1436  		},
  1437  	},
  1438  	{
  1439  		Query: "SELECT s,i FROM (select i,s FROM mytable) mt;",
  1440  		Expected: []sql.Row{
  1441  			{"first row", int64(1)},
  1442  			{"second row", int64(2)},
  1443  			{"third row", int64(3)},
  1444  		},
  1445  	},
  1446  	{
  1447  		Query: "SELECT a,b FROM (select i,s FROM mytable) mt (a,b) order by 1;",
  1448  		Expected: []sql.Row{
  1449  			{1, "first row"},
  1450  			{2, "second row"},
  1451  			{3, "third row"},
  1452  		},
  1453  	},
  1454  	{
  1455  		Query: "SELECT a,b FROM (select i,s FROM mytable) mt (a,b) order by a desc;",
  1456  		Expected: []sql.Row{
  1457  			{3, "third row"},
  1458  			{2, "second row"},
  1459  			{1, "first row"},
  1460  		},
  1461  	},
  1462  	{
  1463  		Query: "SELECT a,b FROM (select i,s FROM mytable order by i desc) mt (a,b);",
  1464  		Expected: []sql.Row{
  1465  			{3, "third row"},
  1466  			{2, "second row"},
  1467  			{1, "first row"},
  1468  		},
  1469  		ExpectedColumns: sql.Schema{
  1470  			{
  1471  				Name: "a",
  1472  				Type: types.Int64,
  1473  			},
  1474  			{
  1475  				Name: "b",
  1476  				Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20),
  1477  			},
  1478  		},
  1479  	},
  1480  	{
  1481  		Query: "SELECT a FROM (select i,s FROM mytable) mt (a,b) order by a desc;",
  1482  		Expected: []sql.Row{
  1483  			{3},
  1484  			{2},
  1485  			{1},
  1486  		},
  1487  	},
  1488  	{
  1489  		Query: `SELECT * FROM (values row(1+1,2+2), row(floor(1.5),concat("a","b"))) a order by 1`,
  1490  		Expected: []sql.Row{
  1491  			{1, "ab"},
  1492  			{2, "4"},
  1493  		},
  1494  		ExpectedColumns: sql.Schema{
  1495  			{
  1496  				Name: "column_0",
  1497  				Type: types.Int64,
  1498  			},
  1499  			{
  1500  				Name: "column_1",
  1501  				Type: types.MustCreateStringWithDefaults(sqltypes.Text, 1073741823),
  1502  			},
  1503  		},
  1504  	},
  1505  	{
  1506  		Query: `SELECT * FROM (values row(1+1,2+2), row(floor(1.5),concat("a","b"))) a (c,d) order by 1`,
  1507  		Expected: []sql.Row{
  1508  			{1, "ab"},
  1509  			{2, "4"},
  1510  		},
  1511  		ExpectedColumns: sql.Schema{
  1512  			{
  1513  				Name: "c",
  1514  				Type: types.Int64,
  1515  			},
  1516  			{
  1517  				Name: "d",
  1518  				Type: types.MustCreateStringWithDefaults(sqltypes.Text, 1073741823),
  1519  			},
  1520  		},
  1521  	},
  1522  	{
  1523  		Query: `SELECT column_0 FROM (values row(1+1,2+2), row(floor(1.5),concat("a","b"))) a order by 1`,
  1524  		Expected: []sql.Row{
  1525  			{1},
  1526  			{2},
  1527  		},
  1528  	},
  1529  	{
  1530  		Query:    `SELECT DISTINCT val FROM (values row(1), row(1.00), row(2), row(2)) a (val);`,
  1531  		Expected: []sql.Row{{"1.00"}, {"2.00"}},
  1532  	},
  1533  	{
  1534  		Query:    `SELECT DISTINCT val FROM (values row(1.00), row(1.000), row(2), row(2)) a (val);`,
  1535  		Expected: []sql.Row{{"1.000"}, {"2.000"}},
  1536  	},
  1537  	{
  1538  		Query:    `SELECT DISTINCT val FROM (values row(1.000), row(21.00), row(2), row(2)) a (val);`,
  1539  		Expected: []sql.Row{{"1.000"}, {"21.000"}, {"2.000"}},
  1540  	},
  1541  	{
  1542  		Query:    `SELECT DISTINCT val FROM (values row(1), row(1.00), row('2'), row(2)) a (val);`,
  1543  		Expected: []sql.Row{{"1"}, {"1.00"}, {"2"}},
  1544  	},
  1545  	{
  1546  		Query:    `SELECT DISTINCT val FROM (values row(null), row(1.00), row('2'), row(2)) a (val);`,
  1547  		Expected: []sql.Row{{nil}, {"1.00"}, {"2"}},
  1548  	},
  1549  	{
  1550  		Query:    `SELECT column_0 FROM (values row(1+1.5,2+2), row(floor(1.5),concat("a","b"))) a order by 1;`,
  1551  		Expected: []sql.Row{{"1.0"}, {"2.5"}},
  1552  	},
  1553  	{
  1554  		// The SortFields does not match between prepared and non-prepared nodes.
  1555  		SkipPrepared: true,
  1556  		Query:        `SELECT column_0 FROM (values row('1.5',2+2), row(floor(1.5),concat("a","b"))) a order by 1;`,
  1557  		Expected:     []sql.Row{{"1"}, {"1.5"}},
  1558  	},
  1559  	{
  1560  		Query:    `SELECT column_0 FROM (values row(1.5,2+2), row(floor(1.5),concat("a","b"))) a order by 1;`,
  1561  		Expected: []sql.Row{{"1.0"}, {"1.5"}},
  1562  	},
  1563  	{
  1564  		Query: `SELECT FORMAT(val, 2) FROM
  1565  			(values row(4328904), row(432053.4853), row(5.93288775208e+08), row("5784029.372"), row(-4229842.122), row(-0.009)) a (val)`,
  1566  		Expected: []sql.Row{
  1567  			{"4,328,904.00"},
  1568  			{"432,053.49"},
  1569  			{"593,288,775.21"},
  1570  			{"5,784,029.37"},
  1571  			{"-4,229,842.12"},
  1572  			{"-0.01"},
  1573  		},
  1574  	},
  1575  	{
  1576  		Query: "SELECT FORMAT(i, 3) FROM mytable;",
  1577  		Expected: []sql.Row{
  1578  			{"1.000"},
  1579  			{"2.000"},
  1580  			{"3.000"},
  1581  		},
  1582  	},
  1583  	{
  1584  		Query: `SELECT FORMAT(val, 2, 'da_DK') FROM
  1585  			(values row(4328904), row(432053.4853), row(5.93288775208e+08), row("5784029.372"), row(-4229842.122), row(-0.009)) a (val)`,
  1586  		Expected: []sql.Row{
  1587  			{"4.328.904,00"},
  1588  			{"432.053,49"},
  1589  			{"593.288.775,21"},
  1590  			{"5.784.029,37"},
  1591  			{"-4.229.842,12"},
  1592  			{"-0,01"},
  1593  		},
  1594  	},
  1595  	{
  1596  		Query: "SELECT FORMAT(i, 3, 'da_DK') FROM mytable;",
  1597  		Expected: []sql.Row{
  1598  			{"1,000"},
  1599  			{"2,000"},
  1600  			{"3,000"},
  1601  		},
  1602  	},
  1603  	{
  1604  		Query: "SELECT DATEDIFF(date_col, '2019-12-28') FROM datetime_table where date_col = date('2019-12-31T12:00:00');",
  1605  		Expected: []sql.Row{
  1606  			{3},
  1607  		},
  1608  	},
  1609  	{
  1610  		Query: `SELECT DATEDIFF(val, '2019/12/28') FROM
  1611  			(values row('2017-11-30 22:59:59'), row('2020/01/02'), row('2021-11-30'), row('2020-12-31T12:00:00')) a (val)`,
  1612  		Expected: []sql.Row{
  1613  			{-758},
  1614  			{5},
  1615  			{703},
  1616  			{369},
  1617  		},
  1618  	},
  1619  	{
  1620  		Query: "SELECT TIMESTAMPDIFF(SECOND,'2007-12-31 23:59:58', '2007-12-31 00:00:00');",
  1621  		Expected: []sql.Row{
  1622  			{-86398},
  1623  		},
  1624  	},
  1625  	{
  1626  		Query: `SELECT TIMESTAMPDIFF(MINUTE, val, '2019/12/28') FROM
  1627  			(values row('2017-11-30 22:59:59'), row('2020/01/02'), row('2019-12-27 23:15:55'), row('2019-12-31T12:00:00')) a (val);`,
  1628  		Expected: []sql.Row{
  1629  			{1090140},
  1630  			{-7200},
  1631  			{44},
  1632  			{-5040},
  1633  		},
  1634  	},
  1635  	{
  1636  		Query:    "SELECT TIMEDIFF(null, '2017-11-30 22:59:59');",
  1637  		Expected: []sql.Row{{nil}},
  1638  	},
  1639  	{
  1640  		Query:    "SELECT DATEDIFF('2019/12/28', null);",
  1641  		Expected: []sql.Row{{nil}},
  1642  	},
  1643  	{
  1644  		Query:    "SELECT TIMESTAMPDIFF(SECOND, null, '2007-12-31 00:00:00');",
  1645  		Expected: []sql.Row{{nil}},
  1646  	},
  1647  	{
  1648  		Query: `SELECT JSON_MERGE_PRESERVE('{ "a": 1, "b": 2 }','{ "a": 3, "c": 4 }','{ "a": 5, "d": 6 }')`,
  1649  		Expected: []sql.Row{
  1650  			{types.MustJSON(`{"a": [1, 3, 5], "b": 2, "c": 4, "d": 6}`)},
  1651  		},
  1652  	},
  1653  	{
  1654  		Query: `SELECT JSON_MERGE_PRESERVE(val1, val2)
  1655  	              FROM (values
  1656  						 row('{ "a": 1, "b": 2 }','null'),
  1657  	                   row('{ "a": 1, "b": 2 }','"row one"'),
  1658  	                   row('{ "a": 3, "c": 4 }','4'),
  1659  	                   row('{ "a": 5, "d": 6 }','[true, true]'),
  1660  	                   row('{ "a": 5, "d": 6 }','{ "a": 3, "e": 2 }'))
  1661  	              test (val1, val2)`,
  1662  		Expected: []sql.Row{
  1663  			{types.MustJSON(`[{ "a": 1, "b": 2 }, null]`)},
  1664  			{types.MustJSON(`[{ "a": 1, "b": 2 }, "row one"]`)},
  1665  			{types.MustJSON(`[{ "a": 3, "c": 4 }, 4]`)},
  1666  			{types.MustJSON(`[{ "a": 5, "d": 6 }, true, true]`)},
  1667  			{types.MustJSON(`{ "a": [5, 3], "d": 6, "e": 2}`)},
  1668  		},
  1669  	},
  1670  	{
  1671  		Query: `SELECT JSON_ARRAY()`,
  1672  		Expected: []sql.Row{
  1673  			{types.MustJSON(`[]`)},
  1674  		},
  1675  	},
  1676  	{
  1677  		Query: `SELECT JSON_ARRAY('{"b": 2, "a": [1, 8], "c": null}', null, 4, '[true, false]', "do")`,
  1678  		Expected: []sql.Row{
  1679  			{types.MustJSON(`["{\"b\": 2, \"a\": [1, 8], \"c\": null}", null, 4, "[true, false]", "do"]`)},
  1680  		},
  1681  	},
  1682  	{
  1683  		Query: `SELECT JSON_ARRAY(1, 'say, "hi"', JSON_OBJECT("abc", 22))`,
  1684  		Expected: []sql.Row{
  1685  			{types.MustJSON(`[1, "say, \"hi\"", {"abc": 22}]`)},
  1686  		},
  1687  	},
  1688  	{
  1689  		Query: `SELECT JSON_ARRAY(JSON_OBJECT("a", JSON_ARRAY(1,2)), JSON_OBJECT("b", 22))`,
  1690  		Expected: []sql.Row{
  1691  			{types.MustJSON(`[{"a": [1, 2]}, {"b": 22}]`)},
  1692  		},
  1693  	},
  1694  	{
  1695  		Query: `SELECT JSON_ARRAY(pk, c1, c2, c3) FROM jsontable`,
  1696  		Expected: []sql.Row{
  1697  			{types.MustJSON(`[1, "row one", [1, 2], {"a": 2}]`)},
  1698  			{types.MustJSON(`[2, "row two", [3, 4], {"b": 2}]`)},
  1699  			{types.MustJSON(`[3, "row three", [5, 6], {"c": 2}]`)},
  1700  			{types.MustJSON(`[4, "row four", [7, 8], {"d": 2}]`)},
  1701  		},
  1702  	},
  1703  	{
  1704  		Query: `SELECT JSON_ARRAY(JSON_OBJECT("id", pk, "name", c1), c2, c3) FROM jsontable`,
  1705  		Expected: []sql.Row{
  1706  			{types.MustJSON(`[{"id": 1,"name": "row one"}, [1, 2], {"a": 2}]`)},
  1707  			{types.MustJSON(`[{"id": 2,"name": "row two"}, [3, 4], {"b": 2}]`)},
  1708  			{types.MustJSON(`[{"id": 3,"name": "row three"}, [5, 6], {"c": 2}]`)},
  1709  			{types.MustJSON(`[{"id": 4,"name": "row four"}, [7, 8], {"d": 2}]`)},
  1710  		},
  1711  	},
  1712  	{
  1713  		Query: `SELECT JSON_KEYS(c3) FROM jsontable`,
  1714  		Expected: []sql.Row{
  1715  			{types.MustJSON(`["a"]`)},
  1716  			{types.MustJSON(`["b"]`)},
  1717  			{types.MustJSON(`["c"]`)},
  1718  			{types.MustJSON(`["d"]`)},
  1719  		},
  1720  	},
  1721  	{
  1722  		Query: `SELECT CONCAT(JSON_OBJECT('aa', JSON_OBJECT('bb', 123, 'y', 456), 'z', JSON_OBJECT('cc', 321, 'x', 654)), "")`,
  1723  		Expected: []sql.Row{
  1724  			{`{"z": {"x": 654, "cc": 321}, "aa": {"y": 456, "bb": 123}}`},
  1725  		},
  1726  	},
  1727  	{
  1728  		Query: `SELECT CONCAT(JSON_ARRAY(JSON_OBJECT('aa', 123, 'z', 456), JSON_OBJECT('BB', 321, 'Y', 654)), "")`,
  1729  		Expected: []sql.Row{
  1730  			{`[{"z": 456, "aa": 123}, {"Y": 654, "BB": 321}]`},
  1731  		},
  1732  	},
  1733  	{
  1734  		Query: `SELECT column_0, sum(column_1) FROM
  1735  			(values row(1,1), row(1,3), row(2,2), row(2,5), row(3,9)) a
  1736  			group by 1 order by 1`,
  1737  		Expected: []sql.Row{
  1738  			{1, 4.0},
  1739  			{2, 7.0},
  1740  			{3, 9.0},
  1741  		},
  1742  	},
  1743  	{
  1744  		Query: `SELECT B, sum(C) FROM
  1745  			(values row(1,1), row(1,3), row(2,2), row(2,5), row(3,9)) a (b,c)
  1746  			group by 1 order by 1`,
  1747  		Expected: []sql.Row{
  1748  			{1, 4.0},
  1749  			{2, 7.0},
  1750  			{3, 9.0},
  1751  		},
  1752  	},
  1753  	{
  1754  		Query: `SELECT i, sum(i) FROM mytable group by 1 having avg(i) > 1 order by 1`,
  1755  		Expected: []sql.Row{
  1756  			{2, 2.0},
  1757  			{3, 3.0},
  1758  		},
  1759  	},
  1760  	{
  1761  		Query: `SELECT i, s, i2, s2 FROM MYTABLE JOIN OTHERTABLE ON i = i2 AND NOT (s2 <=> s)`,
  1762  		Expected: []sql.Row{
  1763  			{1, "first row", 1, "third"},
  1764  			{2, "second row", 2, "second"},
  1765  			{3, "third row", 3, "first"},
  1766  		},
  1767  	},
  1768  	{
  1769  		Query: `SELECT i, s, i2, s2 FROM MYTABLE JOIN OTHERTABLE ON i = i2 AND NOT (s2 = s)`,
  1770  		Expected: []sql.Row{
  1771  			{1, "first row", 1, "third"},
  1772  			{2, "second row", 2, "second"},
  1773  			{3, "third row", 3, "first"},
  1774  		},
  1775  	},
  1776  	{
  1777  		Query: `SELECT i, s, i2, s2 FROM MYTABLE JOIN OTHERTABLE ON i = i2 AND CONCAT(s, s2) IS NOT NULL`,
  1778  		Expected: []sql.Row{
  1779  			{1, "first row", 1, "third"},
  1780  			{2, "second row", 2, "second"},
  1781  			{3, "third row", 3, "first"},
  1782  		},
  1783  	},
  1784  	{
  1785  		Query: `SELECT * FROM mytable mt JOIN othertable ot ON ot.i2 = (SELECT i2 FROM othertable WHERE s2 = "second") AND mt.i = ot.i2 JOIN mytable mt2 ON mt.i = mt2.i`,
  1786  		Expected: []sql.Row{
  1787  			{2, "second row", "second", 2, 2, "second row"},
  1788  		},
  1789  	},
  1790  	{
  1791  		Query: `SELECT a.column_0, b.column_1 FROM (values row(1+1,2+2), row(floor(1.5),concat("a","b"))) a
  1792  			join (values row(2,4), row(1.0,"ab")) b on a.column_0 = b.column_0 and a.column_0 = b.column_0
  1793  			order by 1`,
  1794  		Expected: []sql.Row{
  1795  			{1, "ab"},
  1796  			{2, "4"},
  1797  		},
  1798  	},
  1799  	{
  1800  		Query: `SELECT a.column_0, mt.s from (values row(1,"1"), row(2,"2"), row(4,"4")) a
  1801  			left join mytable mt on column_0 = mt.i
  1802  			order by 1`,
  1803  		Expected: []sql.Row{
  1804  			{1, "first row"},
  1805  			{2, "second row"},
  1806  			{4, nil},
  1807  		},
  1808  	},
  1809  	{
  1810  		Query: `SELECT * FROM (select * from mytable) a
  1811  			join (select * from mytable) b on a.i = b.i
  1812  			order by 1`,
  1813  		Expected: []sql.Row{
  1814  			{1, "first row", 1, "first row"},
  1815  			{2, "second row", 2, "second row"},
  1816  			{3, "third row", 3, "third row"},
  1817  		},
  1818  	},
  1819  	{
  1820  		Query:    "select * from mytable t1 join mytable t2 on t2.i = t1.i where t2.i > 10",
  1821  		Expected: []sql.Row{},
  1822  	},
  1823  	{
  1824  		Query:    "select * from mytable t1 join mytable T2 on t2.i = t1.i where T2.i > 10",
  1825  		Expected: []sql.Row{},
  1826  	},
  1827  	{
  1828  		Query:    "select * from tabletest t1 join tabletest t2 on t2.s = t1.s where t2.i > 10",
  1829  		Expected: []sql.Row{},
  1830  	},
  1831  	{
  1832  		Query: "select * from one_pk where c1 in (select opk1.c1 from one_pk opk1 left join one_pk opk2 on opk1.c2 = opk2.c2)",
  1833  		Expected: []sql.Row{
  1834  			{0, 0, 1, 2, 3, 4},
  1835  			{1, 10, 11, 12, 13, 14},
  1836  			{2, 20, 21, 22, 23, 24},
  1837  			{3, 30, 31, 32, 33, 34},
  1838  		},
  1839  	},
  1840  	{
  1841  		Query: `select mt.i,
  1842  			((
  1843  				select count(*) from mytable
  1844  	     	where i in (
  1845  	        		select mt2.i from mytable mt2 where mt2.i > mt.i
  1846  	     	)
  1847  			)) as greater_count
  1848  			from mytable mt order by 1`,
  1849  		Expected: []sql.Row{{1, 2}, {2, 1}, {3, 0}},
  1850  	},
  1851  	{
  1852  		Query: `select mt.i,
  1853  			((
  1854  				select count(*) from mytable
  1855  	     	where i in (
  1856  	        		select mt2.i from mytable mt2 where mt2.i = mt.i
  1857  	     	)
  1858  			)) as eq_count
  1859  			from mytable mt order by 1`,
  1860  		Expected: []sql.Row{{1, 1}, {2, 1}, {3, 1}},
  1861  	},
  1862  	{
  1863  		Query: "WITH mt as (select i,s FROM mytable) SELECT s,i FROM mt;",
  1864  		Expected: []sql.Row{
  1865  			{"first row", int64(1)},
  1866  			{"second row", int64(2)},
  1867  			{"third row", int64(3)},
  1868  		},
  1869  	},
  1870  	{
  1871  		Query: "WITH mt as (select i,s FROM mytable) SELECT a.s,b.i FROM mt a join mt b on a.i = b.i order by 2;",
  1872  		Expected: []sql.Row{
  1873  			{"first row", int64(1)},
  1874  			{"second row", int64(2)},
  1875  			{"third row", int64(3)},
  1876  		},
  1877  	},
  1878  	{
  1879  		Query: `WITH mt1 as (select i,s FROM mytable), mt2 as (select i, s from mt1)
  1880  			SELECT mt1.i, concat(mt2.s, '!') FROM mt1 join mt2 on mt1.i = mt2.i + 1 order by 1;`,
  1881  		Expected: []sql.Row{
  1882  			{2, "first row!"},
  1883  			{3, "second row!"},
  1884  		},
  1885  	},
  1886  	{
  1887  		Query: `WITH mt1 as (select i,s FROM mytable order by i limit 2), mt2 as (select i, s from mt1)
  1888  			SELECT mt1.i, concat(mt2.s, '!') FROM mt1 join mt2 on mt1.i = mt2.i + 1 order by 1;`,
  1889  		Expected: []sql.Row{
  1890  			{2, "first row!"},
  1891  		},
  1892  	},
  1893  	{
  1894  		Query: `WITH mt1 as (select i,s FROM mytable), mt2 as (select i+1 as i, concat(s, '!') as s from mt1)
  1895  			SELECT mt1.i, mt2.s FROM mt1 join mt2 on mt1.i = mt2.i order by 1;`,
  1896  		Expected: []sql.Row{
  1897  			{2, "first row!"},
  1898  			{3, "second row!"},
  1899  		},
  1900  	},
  1901  	{
  1902  		Query: `WITH mt1 as (select i,s FROM mytable), mt2 as (select i+1 as i, concat(s, '!') as s from mytable)
  1903  			SELECT mt1.i, mt2.s FROM mt1 join mt2 on mt1.i = mt2.i order by 1;`,
  1904  		Expected: []sql.Row{
  1905  			{2, "first row!"},
  1906  			{3, "second row!"},
  1907  		},
  1908  	},
  1909  	{
  1910  		Query: `WITH mt1 as (select i,s FROM mytable), mt2 (i,s) as (select i+1, concat(s, '!') from mytable)
  1911  			SELECT mt1.i, mt2.s FROM mt1 join mt2 on mt1.i = mt2.i order by 1;`,
  1912  		Expected: []sql.Row{
  1913  			{2, "first row!"},
  1914  			{3, "second row!"},
  1915  		},
  1916  	},
  1917  	{
  1918  		Query: `WITH mt1 as (select i,s FROM mytable), mt2 as (select concat(s, '!') as s, i+1 as i from mytable)
  1919  			SELECT mt1.i, mt2.s FROM mt1 join mt2 on mt1.i = mt2.i order by 1;`,
  1920  		Expected: []sql.Row{
  1921  			{2, "first row!"},
  1922  			{3, "second row!"},
  1923  		},
  1924  	},
  1925  	{
  1926  		Query: "WITH mt (s,i) as (select i,s FROM mytable) SELECT s,i FROM mt;",
  1927  		Expected: []sql.Row{
  1928  			{1, "first row"},
  1929  			{2, "second row"},
  1930  			{3, "third row"},
  1931  		},
  1932  	},
  1933  	{
  1934  		Query: "WITH mt (s,i) as (select i+1, concat(s,'!') FROM mytable) SELECT s,i FROM mt order by 1",
  1935  		Expected: []sql.Row{
  1936  			{2, "first row!"},
  1937  			{3, "second row!"},
  1938  			{4, "third row!"},
  1939  		},
  1940  	},
  1941  	{
  1942  		Query: "WITH mt (s,i) as (select i+1 as x, concat(s,'!') as y FROM mytable) SELECT s,i FROM mt order by 1",
  1943  		Expected: []sql.Row{
  1944  			{2, "first row!"},
  1945  			{3, "second row!"},
  1946  			{4, "third row!"},
  1947  		},
  1948  	},
  1949  	{
  1950  		Query: "WITH mt (s,i) as (select i+1, concat(s,'!') FROM mytable order by 1 limit 1) SELECT s,i FROM mt order by 1",
  1951  		Expected: []sql.Row{
  1952  			{2, "first row!"},
  1953  		},
  1954  	},
  1955  	{
  1956  		Query: "WITH mt (s,i) as (select char_length(s), sum(i) FROM mytable group by 1) SELECT s,i FROM mt order by 1",
  1957  		Expected: []sql.Row{
  1958  			{9, 4.0},
  1959  			{10, 2.0},
  1960  		},
  1961  	},
  1962  	{
  1963  		Query: "WITH mt (s,i) as (select i, row_number() over (order by i desc) FROM mytable) SELECT s,i FROM mt order by 1",
  1964  		Expected: []sql.Row{
  1965  			{1, 3},
  1966  			{2, 2},
  1967  			{3, 1},
  1968  		},
  1969  	},
  1970  	{
  1971  		// In this case, the parser and analyzer collaborate to place the filter below the WINDOW function,
  1972  		// and the window sees the filtered rows.
  1973  		Query: "SELECT ROW_NUMBER() OVER (ORDER BY s2 ASC) idx, i2, s2 FROM othertable WHERE s2 <> 'second' ORDER BY i2 ASC",
  1974  		Expected: []sql.Row{
  1975  			{2, 1, "third"},
  1976  			{1, 3, "first"},
  1977  		},
  1978  	},
  1979  	{
  1980  		// In this case, the analyzer should not push the filter below the window function.
  1981  		Query: "SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY s2 ASC) idx, i2, s2 FROM othertable ORDER BY i2 ASC) a WHERE s2 <> 'second'",
  1982  		Expected: []sql.Row{
  1983  			{3, 1, "third"},
  1984  			{1, 3, "first"},
  1985  		},
  1986  	},
  1987  	{
  1988  		// Same as above, but with an available index access on i2
  1989  		Query: "SELECT ROW_NUMBER() OVER (ORDER BY s2 ASC) idx, i2, s2 FROM othertable WHERE i2 < 2 OR i2 > 2 ORDER BY i2 ASC",
  1990  		Expected: []sql.Row{
  1991  			{2, 1, "third"},
  1992  			{1, 3, "first"},
  1993  		},
  1994  	},
  1995  	{
  1996  		// Same as above, but with an available index access on i2
  1997  		Query: "SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY s2 ASC) idx, i2, s2 FROM othertable ORDER BY i2 ASC) a WHERE i2 < 2 OR i2 > 2",
  1998  		Expected: []sql.Row{
  1999  			{3, 1, "third"},
  2000  			{1, 3, "first"},
  2001  		},
  2002  	},
  2003  	{
  2004  		Query: "select i+0.0/(lag(i) over (order by s)) from mytable order by 1;",
  2005  		Expected: []sql.Row{
  2006  			{nil},
  2007  			{"2.00000"},
  2008  			{"3.00000"},
  2009  		},
  2010  	},
  2011  	{
  2012  		Query: "select f64/f32, f32/(lag(i) over (order by f64)) from floattable order by 1,2;",
  2013  		Expected: []sql.Row{
  2014  			{1.0, nil},
  2015  			{1.0, -1.0},
  2016  			{1.0, .5},
  2017  			{1.0, 2.5 / float64(3)},
  2018  			{1.0, 1.0},
  2019  			{1.0, 1.5},
  2020  		},
  2021  	},
  2022  	{
  2023  		Query: `WITH mt1 as (select i,s FROM mytable)
  2024  			SELECT mtouter.i, (select s from mt1 where s = mtouter.s) FROM mt1 as mtouter where mtouter.i > 1 order by 1`,
  2025  		Expected: []sql.Row{
  2026  			{2, "second row"},
  2027  			{3, "third row"},
  2028  		},
  2029  	},
  2030  	{
  2031  		// TODO: ORDER BY should apply to the union. The parser is wrong.
  2032  		Query: `SELECT s2, i2, i
  2033  			FROM (SELECT * FROM mytable) mytable
  2034  			RIGHT JOIN
  2035  				((SELECT i2, s2 FROM othertable ORDER BY i2 ASC)
  2036  				 UNION ALL
  2037  				 SELECT CAST(4 AS SIGNED) AS i2, "not found" AS s2 FROM DUAL) othertable
  2038  			ON i2 = i`,
  2039  		Expected: []sql.Row{
  2040  			{"third", 1, 1},
  2041  			{"second", 2, 2},
  2042  			{"first", 3, 3},
  2043  			{"not found", 4, nil},
  2044  		},
  2045  	},
  2046  	{
  2047  		Query: `WITH mt1 as (select i,s FROM mytable)
  2048  			SELECT mtouter.i, (select s from mt1 where i = mtouter.i+1) FROM mt1 as mtouter where mtouter.i > 1 order by 1`,
  2049  		Expected: []sql.Row{
  2050  			{2, "third row"},
  2051  			{3, nil},
  2052  		},
  2053  	},
  2054  	{
  2055  		Query: `WITH mt1 as (select i,s FROM mytable)
  2056  			SELECT mtouter.i,
  2057  				(with mt2 as (select i,s FROM mt1) select s from mt2 where i = mtouter.i+1)
  2058  			FROM mt1 as mtouter where mtouter.i > 1 order by 1`,
  2059  		Expected: []sql.Row{
  2060  			{2, "third row"},
  2061  			{3, nil},
  2062  		},
  2063  	},
  2064  	{
  2065  		Query: `WITH common_table AS (SELECT cec.id, cec.strength FROM (SELECT 1 as id, 12 as strength) cec) SELECT strength FROM common_table cte`,
  2066  		Expected: []sql.Row{
  2067  			{12},
  2068  		},
  2069  	},
  2070  	{
  2071  		Query: `WITH common_table AS (SELECT cec.id id, cec.strength FROM (SELECT 1 as id, 12 as strength) cec) SELECT strength FROM common_table cte`,
  2072  		Expected: []sql.Row{
  2073  			{12},
  2074  		},
  2075  	},
  2076  	{
  2077  		Query: `WITH common_table AS (SELECT cec.id AS id, cec.strength FROM (SELECT 1 as id, 12 as strength) cec) SELECT strength FROM common_table cte`,
  2078  		Expected: []sql.Row{
  2079  			{12},
  2080  		},
  2081  	},
  2082  	{
  2083  		Query: "WITH mt as (select i,s FROM mytable) SELECT s,i FROM mt UNION SELECT s, i FROM mt;",
  2084  		Expected: []sql.Row{
  2085  			{"first row", int64(1)},
  2086  			{"second row", int64(2)},
  2087  			{"third row", int64(3)},
  2088  		},
  2089  	},
  2090  	{
  2091  		Query: "WITH mt as (select i,s FROM mytable) SELECT s,i FROM mt UNION SELECT s, i FROM mt UNION SELECT s, i FROM mt;",
  2092  		Expected: []sql.Row{
  2093  			{"first row", int64(1)},
  2094  			{"second row", int64(2)},
  2095  			{"third row", int64(3)},
  2096  		},
  2097  	},
  2098  	{
  2099  		Query: "WITH mt as (select i,s FROM mytable) SELECT s,i FROM mt UNION ALL SELECT s, i FROM mt;",
  2100  		Expected: []sql.Row{
  2101  			{"first row", int64(1)},
  2102  			{"second row", int64(2)},
  2103  			{"third row", int64(3)},
  2104  			{"first row", int64(1)},
  2105  			{"second row", int64(2)},
  2106  			{"third row", int64(3)},
  2107  		},
  2108  	},
  2109  	{
  2110  		Query: "with a as (select * from mytable where i = 2), b as (select * from a), c as (select * from b) select * from c",
  2111  		Expected: []sql.Row{
  2112  			{int64(2), "second row"},
  2113  		},
  2114  	},
  2115  	{
  2116  		Query: "WITH mt as (select i,s FROM mytable) SELECT s,i FROM mt UNION ALL SELECT s, i FROM mt UNION ALL SELECT s, i FROM mt;",
  2117  		Expected: []sql.Row{
  2118  			{"first row", int64(1)},
  2119  			{"second row", int64(2)},
  2120  			{"third row", int64(3)},
  2121  			{"first row", int64(1)},
  2122  			{"second row", int64(2)},
  2123  			{"third row", int64(3)},
  2124  			{"first row", int64(1)},
  2125  			{"second row", int64(2)},
  2126  			{"third row", int64(3)},
  2127  		},
  2128  	},
  2129  	{
  2130  		Query: "WITH mytable as (select * FROM mytable) SELECT s,i FROM mytable;",
  2131  		Expected: []sql.Row{
  2132  			{"first row", int64(1)},
  2133  			{"second row", int64(2)},
  2134  			{"third row", int64(3)},
  2135  		},
  2136  	},
  2137  	{
  2138  		Query: "WITH mytable as (select * FROM mytable where i > 2) SELECT * FROM mytable;",
  2139  		Expected: []sql.Row{
  2140  			{int64(3), "third row"},
  2141  		},
  2142  	},
  2143  	{
  2144  		Query: "WITH mytable as (select * FROM mytable where i > 2) SELECT * FROM mytable union SELECT * from mytable;",
  2145  		Expected: []sql.Row{
  2146  			{int64(3), "third row"},
  2147  		},
  2148  	},
  2149  	{
  2150  		Query: "with recursive t (n) as (select (1) from dual union all select n + 1 from t where n < 10) select sum(n) from t;",
  2151  		Expected: []sql.Row{
  2152  			{float64(55)},
  2153  		},
  2154  	},
  2155  	{
  2156  		Query: "with recursive a as (select 1 union all select 2) select * from a union select 10 from dual;",
  2157  		Expected: []sql.Row{
  2158  			{1},
  2159  			{2},
  2160  			{10},
  2161  		},
  2162  	},
  2163  	{
  2164  		Query: "with recursive a as (select 1 union all select 2) select 10 from dual union select * from a;",
  2165  		Expected: []sql.Row{
  2166  			{10},
  2167  			{1},
  2168  			{2},
  2169  		},
  2170  	},
  2171  	{
  2172  		Query: "with recursive a as (select 1 union all select 2) select * from a union select * from a;",
  2173  		Expected: []sql.Row{
  2174  			{1},
  2175  			{2},
  2176  		},
  2177  	},
  2178  	{
  2179  		Query: "with recursive a as (select 1) select * from a union select * from a;",
  2180  		Expected: []sql.Row{
  2181  			{1},
  2182  		},
  2183  	},
  2184  	{
  2185  		Query:    "with cte(x) as (select 0) select x from cte where cte.x in (with cte(x) as (select 42) select x from cte);",
  2186  		Expected: []sql.Row{},
  2187  	},
  2188  	{
  2189  		Query:    "with cte(x) as (with cte(x) as (select 0) select x from cte) select x from cte where cte.x in (with cte(x) as (select 42) select x from cte);",
  2190  		Expected: []sql.Row{},
  2191  	},
  2192  	{
  2193  		Query: "with a as (select 1), b as (select * from a) select * from b;",
  2194  		Expected: []sql.Row{
  2195  			{1},
  2196  		},
  2197  	},
  2198  	{
  2199  		Query: "with a as (select 1) select * from (with b as (select * from a) select * from b) as c;",
  2200  		Expected: []sql.Row{
  2201  			{1},
  2202  		},
  2203  	},
  2204  	{
  2205  		Query: "with a as (select 1) select 3, 2, (select * from a);",
  2206  		Expected: []sql.Row{
  2207  			{3, 2, 1},
  2208  		},
  2209  	},
  2210  	{
  2211  		Query: "WITH a AS ( WITH b AS ( WITH recursive c AS ( SELECT 1 UNION SELECT 2 ) SELECT * from c UNION SELECT 3 ) SELECT * from b UNION SELECT 4) SELECT * from a UNION SELECT 10;",
  2212  		Expected: []sql.Row{
  2213  			{1},
  2214  			{2},
  2215  			{3},
  2216  			{4},
  2217  			{10},
  2218  		},
  2219  	},
  2220  	{
  2221  		Query: "WITH a AS ( WITH b AS ( SELECT 1 UNION SELECT 2 ), c AS ( SELECT 3 UNION SELECT 4 ) SELECT * from b UNION SELECT * from c), x AS ( WITH y AS ( SELECT 5 UNION SELECT 6 ), z AS ( SELECT 7 UNION SELECT 8 ) SELECT * from y UNION SELECT * from z) SELECT * from a UNION SELECT * from x;",
  2222  		Expected: []sql.Row{
  2223  			{1},
  2224  			{2},
  2225  			{3},
  2226  			{4},
  2227  			{5},
  2228  			{6},
  2229  			{7},
  2230  			{8},
  2231  		},
  2232  	},
  2233  	{
  2234  		Query: "with recursive t (n) as (select (1) from dual union all select n + 1 from t where n < 10) select count(*) from t as t1 join t as t2 on t1.n = t2.n;",
  2235  		Expected: []sql.Row{
  2236  			{int64(10)},
  2237  		},
  2238  	},
  2239  	{
  2240  		Query: "with recursive t (n) as (select (1) from dual union all select (2) from dual) select sum(n) from t;",
  2241  		Expected: []sql.Row{
  2242  			{float64(3)},
  2243  		},
  2244  	},
  2245  	{
  2246  		Query: `
  2247  			WITH RECURSIVE included_parts(sub_part, part, quantity) AS (
  2248  				SELECT sub_part, part, quantity FROM parts WHERE part = 'pie'
  2249  			  UNION ALL
  2250  				SELECT p.sub_part, p.part, p.quantity
  2251  				FROM included_parts AS pr, parts AS p
  2252  				WHERE p.part = pr.sub_part
  2253  			)
  2254  			SELECT sub_part, sum(quantity) as total_quantity
  2255  			FROM included_parts
  2256  			GROUP BY sub_part`,
  2257  		Expected: []sql.Row{
  2258  			{"crust", float64(1)},
  2259  			{"filling", float64(2)},
  2260  			{"flour", float64(20)},
  2261  			{"butter", float64(18)},
  2262  			{"salt", float64(18)},
  2263  			{"sugar", float64(7)},
  2264  			{"fruit", float64(9)},
  2265  		},
  2266  	},
  2267  	{
  2268  		Query: `
  2269  			WITH RECURSIVE included_parts(sub_part, part, quantity) AS (
  2270  				SELECT sub_part, part, quantity FROM parts WHERE lower(part) = 'pie'
  2271  			  UNION ALL
  2272  				SELECT p.sub_part, p.part, p.quantity
  2273  				FROM included_parts AS pr, parts AS p
  2274  				WHERE p.part = pr.sub_part
  2275  			)
  2276  			SELECT sub_part, sum(quantity) as total_quantity
  2277  			FROM included_parts
  2278  			GROUP BY sub_part`,
  2279  		Expected: []sql.Row{
  2280  			{"crust", float64(1)},
  2281  			{"filling", float64(2)},
  2282  			{"flour", float64(20)},
  2283  			{"butter", float64(18)},
  2284  			{"salt", float64(18)},
  2285  			{"sugar", float64(7)},
  2286  			{"fruit", float64(9)},
  2287  		},
  2288  	},
  2289  	{
  2290  		Query: `
  2291  			WITH RECURSIVE included_parts(sub_part, part, quantity) AS (
  2292  				SELECT sub_part, part, quantity FROM parts WHERE part = (select part from parts where part = 'pie' and sub_part = 'crust')
  2293  			  UNION ALL
  2294  				SELECT p.sub_part, p.part, p.quantity
  2295  				FROM included_parts AS pr, parts AS p
  2296  				WHERE p.part = pr.sub_part
  2297  			)
  2298  			SELECT sub_part, sum(quantity) as total_quantity
  2299  			FROM included_parts
  2300  			GROUP BY sub_part`,
  2301  		Expected: []sql.Row{
  2302  			{"crust", float64(1)},
  2303  			{"filling", float64(2)},
  2304  			{"flour", float64(20)},
  2305  			{"butter", float64(18)},
  2306  			{"salt", float64(18)},
  2307  			{"sugar", float64(7)},
  2308  			{"fruit", float64(9)},
  2309  		},
  2310  	},
  2311  	{
  2312  		Query: "with recursive t (n) as (select sum(1) from dual union all select ('2.00') from dual) select sum(n) from t;",
  2313  		Expected: []sql.Row{
  2314  			{float64(3)},
  2315  		},
  2316  	},
  2317  	{
  2318  		Query: "with recursive t (n) as (select sum(1) from dual union all select (2.00) from dual) select sum(n) from t;",
  2319  		Expected: []sql.Row{
  2320  			{"3.00"},
  2321  		},
  2322  	},
  2323  	{
  2324  		Query: "with recursive t (n) as (select sum(1) from dual union all select (2.00/3.0) from dual) select sum(n) from t;",
  2325  		Expected: []sql.Row{
  2326  			{"1.666667"},
  2327  		},
  2328  	},
  2329  	{
  2330  		Query: "with recursive t (n) as (select sum(1) from dual union all select n+1 from t where n < 10) select sum(n) from t;",
  2331  		Expected: []sql.Row{
  2332  			{float64(55)},
  2333  		},
  2334  	},
  2335  	{
  2336  		Query: `
  2337  			WITH RECURSIVE bus_dst as (
  2338  				SELECT origin as dst FROM bus_routes WHERE origin='New York'
  2339  				UNION
  2340  				SELECT bus_routes.dst FROM bus_routes JOIN bus_dst ON bus_dst.dst= bus_routes.origin
  2341  			)
  2342  			SELECT * FROM bus_dst
  2343  			ORDER BY dst`,
  2344  		Expected: []sql.Row{
  2345  			{"Boston"},
  2346  			{"New York"},
  2347  			{"Raleigh"},
  2348  			{"Washington"},
  2349  		},
  2350  	},
  2351  	{
  2352  		Query: `
  2353  			WITH RECURSIVE bus_dst as (
  2354  				SELECT origin as dst FROM bus_routes WHERE origin='New York'
  2355  				UNION
  2356  				SELECT bus_routes.dst FROM bus_routes JOIN bus_dst ON concat(bus_dst.dst, 'aa') = concat(bus_routes.origin, 'aa')
  2357  			)
  2358  			SELECT * FROM bus_dst
  2359  			ORDER BY dst`,
  2360  		Expected: []sql.Row{
  2361  			{"Boston"},
  2362  			{"New York"},
  2363  			{"Raleigh"},
  2364  			{"Washington"},
  2365  		},
  2366  	},
  2367  	{
  2368  		Query: "SELECT s, (select i from mytable mt where sub.i = mt.i) as subi FROM (select i,s,'hello' FROM mytable where s = 'first row') as sub;",
  2369  		Expected: []sql.Row{
  2370  			{"first row", int64(1)},
  2371  		},
  2372  	},
  2373  	{
  2374  		Query: "SELECT (select s from mytable mt where sub.i = mt.i) as subi FROM (select i,s,'hello' FROM mytable where i = 1) as sub;",
  2375  		Expected: []sql.Row{
  2376  			{"first row"},
  2377  		},
  2378  	},
  2379  	{
  2380  		Query: "SELECT (select s from mytable mt where sub.i = mt.i) as subi FROM (select s,i,'hello' FROM mytable where i = 1) as sub;",
  2381  		Expected: []sql.Row{
  2382  			{"first row"},
  2383  		},
  2384  	},
  2385  	{
  2386  		Query: "SELECT s, (select i from mytable mt where sub.i = mt.i) as subi FROM (select 'hello',i,s FROM mytable where s = 'first row') as sub;",
  2387  		Expected: []sql.Row{
  2388  			{"first row", int64(1)},
  2389  		},
  2390  	},
  2391  	{
  2392  		Query: "SELECT (select s from mytable mt where sub.i = mt.i) as subi FROM (select 'hello',i,s FROM mytable where i = 1) as sub;",
  2393  		Expected: []sql.Row{
  2394  			{"first row"},
  2395  		},
  2396  	},
  2397  	{
  2398  		Query: "SELECT mytable.s FROM mytable WHERE mytable.i IN (SELECT othertable.i2 FROM othertable) ORDER BY mytable.i ASC",
  2399  		Expected: []sql.Row{
  2400  			{"first row"},
  2401  			{"second row"},
  2402  			{"third row"},
  2403  		},
  2404  	},
  2405  	{
  2406  		Query: "SELECT mytable.s FROM mytable WHERE mytable.i = (SELECT othertable.i2 FROM othertable WHERE othertable.s2 = 'second')",
  2407  		Expected: []sql.Row{
  2408  			{"second row"},
  2409  		},
  2410  	},
  2411  	{
  2412  		Query: "SELECT mytable.s FROM mytable WHERE mytable.i IN (SELECT othertable.i2 FROM othertable WHERE CONCAT(othertable.s2, ' row') = mytable.s)",
  2413  		Expected: []sql.Row{
  2414  			{"second row"},
  2415  		},
  2416  	},
  2417  	{
  2418  		Query: "SELECT mytable.i, selfjoined.s FROM mytable LEFT JOIN (SELECT * FROM mytable) selfjoined ON mytable.i = selfjoined.i",
  2419  		Expected: []sql.Row{
  2420  			{1, "first row"},
  2421  			{2, "second row"},
  2422  			{3, "third row"},
  2423  		},
  2424  	},
  2425  	{
  2426  		Query: "SELECT s,i FROM MyTable ORDER BY 2",
  2427  		Expected: []sql.Row{
  2428  			{"first row", int64(1)},
  2429  			{"second row", int64(2)},
  2430  			{"third row", int64(3)}},
  2431  	},
  2432  	{
  2433  		Query: "SELECT S,I FROM MyTable ORDER BY 2",
  2434  		Expected: []sql.Row{
  2435  			{"first row", int64(1)},
  2436  			{"second row", int64(2)},
  2437  			{"third row", int64(3)}},
  2438  	},
  2439  	{
  2440  		Query: "SELECT mt.s,mt.i FROM MyTable MT ORDER BY 2;",
  2441  		Expected: []sql.Row{
  2442  			{"first row", int64(1)},
  2443  			{"second row", int64(2)},
  2444  			{"third row", int64(3)}},
  2445  	},
  2446  	{
  2447  		Query: "SELECT mT.S,Mt.I FROM MyTable MT ORDER BY 2;",
  2448  		Expected: []sql.Row{
  2449  			{"first row", int64(1)},
  2450  			{"second row", int64(2)},
  2451  			{"third row", int64(3)}},
  2452  	},
  2453  	{
  2454  		Query: "SELECT mt.* FROM MyTable MT ORDER BY mT.I;",
  2455  		Expected: []sql.Row{
  2456  			{int64(1), "first row"},
  2457  			{int64(2), "second row"},
  2458  			{int64(3), "third row"}},
  2459  	},
  2460  	{
  2461  		Query: "SELECT MyTABLE.s,myTable.i FROM MyTable ORDER BY 2;",
  2462  		Expected: []sql.Row{
  2463  			{"first row", int64(1)},
  2464  			{"second row", int64(2)},
  2465  			{"third row", int64(3)}},
  2466  	},
  2467  	{
  2468  		Query: `SELECT "Hello!", CONcat(s, "!") FROM MyTable`,
  2469  		Expected: []sql.Row{
  2470  			{"Hello!", "first row!"},
  2471  			{"Hello!", "second row!"},
  2472  			{"Hello!", "third row!"},
  2473  		},
  2474  		ExpectedColumns: sql.Schema{
  2475  			{
  2476  				Name: "Hello!",
  2477  				Type: types.LongText,
  2478  			},
  2479  			{
  2480  				Name: "CONcat(s, \"!\")",
  2481  				Type: types.LongText,
  2482  			},
  2483  		},
  2484  	},
  2485  	{
  2486  		Query: `SELECT "1" + '1'`,
  2487  		Expected: []sql.Row{
  2488  			{float64(2)},
  2489  		},
  2490  		ExpectedColumns: sql.Schema{
  2491  			{
  2492  				Name: `"1" + '1'`,
  2493  				Type: types.Float64,
  2494  			},
  2495  		},
  2496  	},
  2497  	{
  2498  		Query: "SELECT myTable.* FROM MYTABLE ORDER BY myTable.i;",
  2499  		Expected: []sql.Row{
  2500  			{int64(1), "first row"},
  2501  			{int64(2), "second row"},
  2502  			{int64(3), "third row"}},
  2503  	},
  2504  	{
  2505  		Query: "SELECT MyTABLE.S,myTable.I FROM MyTable ORDER BY mytable.i;",
  2506  		Expected: []sql.Row{
  2507  			{"first row", int64(1)},
  2508  			{"second row", int64(2)},
  2509  			{"third row", int64(3)}},
  2510  	},
  2511  	{
  2512  		Query: "SELECT MyTABLE.S as S, myTable.I as I FROM MyTable ORDER BY mytable.i;",
  2513  		Expected: []sql.Row{
  2514  			{"first row", int64(1)},
  2515  			{"second row", int64(2)},
  2516  			{"third row", int64(3)}},
  2517  	},
  2518  	{
  2519  		Query: "SELECT i, 1 AS foo, 2 AS bar FROM MyTable HAVING bar = 2 ORDER BY foo, i;",
  2520  		Expected: []sql.Row{
  2521  			{1, 1, 2},
  2522  			{2, 1, 2},
  2523  			{3, 1, 2}},
  2524  	},
  2525  	{
  2526  		Query: "SELECT i, 1 AS foo, 2 AS bar FROM (SELECT i FROM mYtABLE WHERE i = 2) AS a ORDER BY foo, i",
  2527  		Expected: []sql.Row{
  2528  			{2, 1, 2}},
  2529  	},
  2530  	{
  2531  		Query:    "SELECT i, 1 AS foo, 2 AS bar FROM MyTable HAVING bar = 1 ORDER BY foo, i;",
  2532  		Expected: []sql.Row{},
  2533  	},
  2534  	{
  2535  		Query:    "SELECT timestamp FROM reservedWordsTable;",
  2536  		Expected: []sql.Row{{"1"}},
  2537  	},
  2538  	{
  2539  		Query:    "SELECT RW.TIMESTAMP FROM reservedWordsTable rw;",
  2540  		Expected: []sql.Row{{"1"}},
  2541  	},
  2542  	{
  2543  		Query:    "SELECT `AND`, RW.`Or`, `SEleCT` FROM reservedWordsTable rw;",
  2544  		Expected: []sql.Row{{"1.1", "aaa", "create"}},
  2545  	},
  2546  	{
  2547  		Query:    "SELECT reservedWordsTable.AND, reservedWordsTABLE.Or, reservedwordstable.SEleCT FROM reservedWordsTable;",
  2548  		Expected: []sql.Row{{"1.1", "aaa", "create"}},
  2549  	},
  2550  	{
  2551  		Query:    "SELECT i + 1 FROM mytable;",
  2552  		Expected: []sql.Row{{int64(2)}, {int64(3)}, {int64(4)}},
  2553  	},
  2554  	{
  2555  		Query:    `select (1 / 3) * (1 / 3);`,
  2556  		Expected: []sql.Row{{"0.11111111"}},
  2557  	},
  2558  	{
  2559  		Query:    "SELECT i div 2 FROM mytable order by 1;",
  2560  		Expected: []sql.Row{{int64(0)}, {int64(1)}, {int64(1)}},
  2561  	},
  2562  	{
  2563  		Query:    "SELECT i DIV 2 FROM mytable order by 1;",
  2564  		Expected: []sql.Row{{int64(0)}, {int64(1)}, {int64(1)}},
  2565  	},
  2566  	{
  2567  		Query:    "SELECT -i FROM mytable;",
  2568  		Expected: []sql.Row{{int64(-1)}, {int64(-2)}, {int64(-3)}},
  2569  	},
  2570  	{
  2571  		Query:    "SELECT +i FROM mytable;",
  2572  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}},
  2573  	},
  2574  	{
  2575  		Query:    "SELECT + - i FROM mytable;",
  2576  		Expected: []sql.Row{{int64(-1)}, {int64(-2)}, {int64(-3)}},
  2577  	},
  2578  	{
  2579  		Query:    "SELECT i FROM mytable WHERE -i = -2;",
  2580  		Expected: []sql.Row{{int64(2)}},
  2581  	},
  2582  	{
  2583  		Query:    "SELECT i FROM mytable WHERE -i <=> -2;",
  2584  		Expected: []sql.Row{{int64(2)}},
  2585  	},
  2586  	{
  2587  		Query:    "SELECT i FROM mytable WHERE i = 2;",
  2588  		Expected: []sql.Row{{int64(2)}},
  2589  	},
  2590  	{
  2591  		Query:    "SELECT i FROM mytable WHERE 2 = i;",
  2592  		Expected: []sql.Row{{int64(2)}},
  2593  	},
  2594  	{
  2595  		Query:    "SELECT i FROM mytable WHERE 2 <=> i;",
  2596  		Expected: []sql.Row{{int64(2)}},
  2597  	},
  2598  	{
  2599  		Query:    "SELECT i FROM mytable WHERE i > 2;",
  2600  		Expected: []sql.Row{{int64(3)}},
  2601  	},
  2602  	{
  2603  		Query:    "SELECT i FROM mytable WHERE 2 < i;",
  2604  		Expected: []sql.Row{{int64(3)}},
  2605  	},
  2606  	{
  2607  		Query:    "SELECT i FROM mytable WHERE i < 2;",
  2608  		Expected: []sql.Row{{int64(1)}},
  2609  	},
  2610  	{
  2611  		Query:    "SELECT i FROM mytable WHERE 2 > i;",
  2612  		Expected: []sql.Row{{int64(1)}},
  2613  	},
  2614  	{
  2615  		Query:    "SELECT i FROM mytable WHERE i <> 2;",
  2616  		Expected: []sql.Row{{int64(1)}, {int64(3)}},
  2617  	},
  2618  	{
  2619  		Query:    "SELECT NULL IN (SELECT i FROM emptytable)",
  2620  		Expected: []sql.Row{{false}},
  2621  	},
  2622  	{
  2623  		Query:    "SELECT NULL NOT IN (SELECT i FROM emptytable)",
  2624  		Expected: []sql.Row{{true}},
  2625  	},
  2626  	{
  2627  		Query:    "SELECT NULL IN (SELECT i FROM mytable)",
  2628  		Expected: []sql.Row{{nil}},
  2629  	},
  2630  	{
  2631  		Query:    "SELECT NULL NOT IN (SELECT i FROM mytable)",
  2632  		Expected: []sql.Row{{nil}},
  2633  	},
  2634  	{
  2635  		Query:    "SELECT NULL IN (SELECT i2 FROM niltable)",
  2636  		Expected: []sql.Row{{nil}},
  2637  	},
  2638  	{
  2639  		Query:    "SELECT NULL NOT IN (SELECT i2 FROM niltable)",
  2640  		Expected: []sql.Row{{nil}},
  2641  	},
  2642  	{
  2643  		Query:    "SELECT 2 IN (SELECT i2 FROM niltable)",
  2644  		Expected: []sql.Row{{true}},
  2645  	},
  2646  	{
  2647  		Query:    "SELECT 2 NOT IN (SELECT i2 FROM niltable)",
  2648  		Expected: []sql.Row{{false}},
  2649  	},
  2650  	{
  2651  		Query:    "SELECT 100 IN (SELECT i2 FROM niltable)",
  2652  		Expected: []sql.Row{{nil}},
  2653  	},
  2654  	{
  2655  		Query:    "SELECT 100 NOT IN (SELECT i2 FROM niltable)",
  2656  		Expected: []sql.Row{{nil}},
  2657  	},
  2658  	{
  2659  		Query:    "SELECT 1 IN (2,3,4,null)",
  2660  		Expected: []sql.Row{{nil}},
  2661  	},
  2662  	{
  2663  		Query:    "SELECT 1 IN (2,3,4,null,1)",
  2664  		Expected: []sql.Row{{true}},
  2665  	},
  2666  	{
  2667  		Query:    "SELECT 1 IN (1,2,3)",
  2668  		Expected: []sql.Row{{true}},
  2669  	},
  2670  	{
  2671  		Query:    "SELECT 1 IN (2,3,4)",
  2672  		Expected: []sql.Row{{false}},
  2673  	},
  2674  	{
  2675  		Query:    "SELECT * FROM stringandtable WHERE v IN (NULL)",
  2676  		Expected: []sql.Row{},
  2677  	},
  2678  	{
  2679  		Query:    "SELECT * FROM stringandtable WHERE v IS NULL",
  2680  		Expected: []sql.Row{{int64(5), int64(5), nil}},
  2681  	},
  2682  	{
  2683  		Query:    "SELECT * FROM stringandtable WHERE v IN ('')",
  2684  		Expected: []sql.Row{{int64(2), int64(2), ""}},
  2685  	},
  2686  	{
  2687  		Query:    "SELECT 1 FROM DUAL WHERE 1 IN (SELECT '1' FROM DUAL)",
  2688  		Expected: []sql.Row{{1}},
  2689  	},
  2690  	{
  2691  		Query:    "SELECT 1 FROM DUAL WHERE '1' IN (SELECT '1' FROM DUAL)",
  2692  		Expected: []sql.Row{{1}},
  2693  	},
  2694  	{
  2695  		Query:    "SELECT NULL IN (2,3,4)",
  2696  		Expected: []sql.Row{{nil}},
  2697  	},
  2698  	{
  2699  		Query:    "SELECT NULL IN (2,3,4,null)",
  2700  		Expected: []sql.Row{{nil}},
  2701  	},
  2702  	{
  2703  		Query:    `SELECT 'a' IN ('b','c',null,'d')`,
  2704  		Expected: []sql.Row{{nil}},
  2705  	},
  2706  	{
  2707  		Query:    `SELECT 'a' IN ('a','b','c','d')`,
  2708  		Expected: []sql.Row{{true}},
  2709  	},
  2710  	{
  2711  		Query:    `SELECT 'a' IN ('b','c','d')`,
  2712  		Expected: []sql.Row{{false}},
  2713  	},
  2714  	{
  2715  		Query:    "SELECT 1 NOT IN (2,3,4,null)",
  2716  		Expected: []sql.Row{{nil}},
  2717  	},
  2718  	{
  2719  		Query:    "SELECT 1 NOT IN (2,3,4,null,1)",
  2720  		Expected: []sql.Row{{false}},
  2721  	},
  2722  	{
  2723  		Query:    "SELECT 1 NOT IN (1,2,3)",
  2724  		Expected: []sql.Row{{false}},
  2725  	},
  2726  	{
  2727  		Query:    "SELECT 1 NOT IN (2,3,4)",
  2728  		Expected: []sql.Row{{true}},
  2729  	},
  2730  	{
  2731  		Query:    "SELECT NULL NOT IN (2,3,4)",
  2732  		Expected: []sql.Row{{nil}},
  2733  	},
  2734  	{
  2735  		Query:    "SELECT NULL NOT IN (2,3,4,null)",
  2736  		Expected: []sql.Row{{nil}},
  2737  	},
  2738  	{
  2739  		Query:    "SELECT 'HOMER' IN (1.0)",
  2740  		Expected: []sql.Row{{false}},
  2741  	},
  2742  	{
  2743  		Query:    "select 1 / 3 * 3 in (0.999999999);",
  2744  		Expected: []sql.Row{{true}},
  2745  	},
  2746  	{
  2747  		Query:    "SELECT 99 NOT IN ( 98 + 97 / 99 );",
  2748  		Expected: []sql.Row{{true}},
  2749  	},
  2750  	{
  2751  		Query:    "SELECT 1 NOT IN ( 97 / 99 );",
  2752  		Expected: []sql.Row{{true}},
  2753  	},
  2754  	{
  2755  		Query:    `SELECT 1 NOT IN (1 / 9 * 5);`,
  2756  		Expected: []sql.Row{{true}},
  2757  	},
  2758  	{
  2759  		Query:    `SELECT 1 / 9 * 5 NOT IN (1);`,
  2760  		Expected: []sql.Row{{true}},
  2761  	},
  2762  	{
  2763  		Query:    `SELECT 1 / 9 * 5 IN (1 / 9 * 5);`,
  2764  		Expected: []sql.Row{{true}},
  2765  	},
  2766  	{
  2767  		Query:    "select 0 in (1/100000);",
  2768  		Expected: []sql.Row{{false}},
  2769  	},
  2770  	{
  2771  		Query:    `SELECT * FROM mytable WHERE i in (CAST(NULL AS SIGNED), 2, 3, 4)`,
  2772  		Expected: []sql.Row{{3, "third row"}, {2, "second row"}},
  2773  	},
  2774  	{
  2775  		Query:    `SELECT * FROM mytable WHERE i in (1+2)`,
  2776  		Expected: []sql.Row{{3, "third row"}},
  2777  	},
  2778  	{
  2779  		Query:    "SELECT * from mytable where upper(s) IN ('FIRST ROW', 'SECOND ROW')",
  2780  		Expected: []sql.Row{{1, "first row"}, {2, "second row"}},
  2781  	},
  2782  	{
  2783  		Query:    "SELECT * from mytable where cast(i as CHAR) IN ('a', 'b')",
  2784  		Expected: []sql.Row{},
  2785  	},
  2786  	{
  2787  		Query:    "SELECT * from mytable where cast(i as CHAR) IN ('1', '2')",
  2788  		Expected: []sql.Row{{1, "first row"}, {2, "second row"}},
  2789  	},
  2790  	{
  2791  		Query:    "SELECT * from mytable where (i > 2) IN (true)",
  2792  		Expected: []sql.Row{{3, "third row"}},
  2793  	},
  2794  	{
  2795  		Query:    "SELECT * from mytable where (i + 6) IN (7, 8)",
  2796  		Expected: []sql.Row{{1, "first row"}, {2, "second row"}},
  2797  	},
  2798  	{
  2799  		Query:    "SELECT * from mytable where (i + 40) IN (7, 8)",
  2800  		Expected: []sql.Row{},
  2801  	},
  2802  	{
  2803  		Query:    "SELECT * from mytable where (i = 1 | false) IN (true)",
  2804  		Expected: []sql.Row{{1, "first row"}},
  2805  	},
  2806  	{
  2807  		Query:    "SELECT * from mytable where (i = 1 & false) IN (true)",
  2808  		Expected: []sql.Row{},
  2809  	},
  2810  	{
  2811  		Query:    `SELECT * FROM mytable WHERE i in (2*i)`,
  2812  		Expected: []sql.Row{},
  2813  	},
  2814  	{
  2815  		Query:    `SELECT * FROM mytable WHERE i in (i)`,
  2816  		Expected: []sql.Row{{1, "first row"}, {2, "second row"}, {3, "third row"}},
  2817  	},
  2818  	{
  2819  		Query:    `SELECT * FROM mytable WHERE i in (1, 1, 1, 1, 1)`,
  2820  		Expected: []sql.Row{{1, "first row"}},
  2821  	},
  2822  	{
  2823  		Query:    `SELECT * FROM mytable WHERE i NOT in (1, 1)`,
  2824  		Expected: []sql.Row{{2, "second row"}, {3, "third row"}},
  2825  	},
  2826  	{
  2827  		Query:    `SELECT * FROM mytable WHERE i in (i, i)`,
  2828  		Expected: []sql.Row{{1, "first row"}, {2, "second row"}, {3, "third row"}},
  2829  	},
  2830  	{
  2831  		Query:    `SELECT * FROM (select * from mytable) sq WHERE sq.i in (1, 1)`,
  2832  		Expected: []sql.Row{{1, "first row"}},
  2833  	},
  2834  	{
  2835  		Query:    `SELECT * FROM (select a.i from mytable a cross join mytable b) sq WHERE sq.i in (1, 1)`,
  2836  		Expected: []sql.Row{{1}, {1}, {1}},
  2837  	},
  2838  	{
  2839  		Query: `SELECT * FROM mytable WHERE i in (1, 1, 1, 1, 1) and s = 'first row'`,
  2840  		Expected: []sql.Row{
  2841  			{1, "first row"},
  2842  		},
  2843  	},
  2844  	{
  2845  		Query: `SELECT * FROM mytable WHERE i in (1, 1, 1, 1, 1) or s in ('first row', 'first row', 'first row');`,
  2846  		Expected: []sql.Row{
  2847  			{1, "first row"},
  2848  		},
  2849  	},
  2850  	{
  2851  		Query: `SELECT * FROM mytable WHERE (i in (1, 1, 1, 1, 1) and s = 'first row') or s in ('first row', 'first row', 'first row');`,
  2852  		Expected: []sql.Row{
  2853  			{1, "first row"},
  2854  		},
  2855  	},
  2856  	{
  2857  		Query: `SELECT * FROM mytable WHERE i in (1, 1, 1, 1, 1) and s in ('first row', 'first row', 'first row');`,
  2858  		Expected: []sql.Row{
  2859  			{1, "first row"},
  2860  		},
  2861  	},
  2862  	{
  2863  		Query: `SELECT * FROM mytable WHERE i NOT in (1, 1, 1, 1, 1) and s != 'first row';`,
  2864  		Expected: []sql.Row{
  2865  			{2, "second row"},
  2866  			{3, "third row"},
  2867  		},
  2868  	},
  2869  	{
  2870  		Query: `SELECT * FROM mytable WHERE i NOT in (1, 1, 1, 1, 1) and s NOT in ('first row', 'first row', 'first row');`,
  2871  		Expected: []sql.Row{
  2872  			{2, "second row"},
  2873  			{3, "third row"},
  2874  		},
  2875  	},
  2876  	{
  2877  		Query:    "SELECT * from mytable WHERE 4 IN (i + 2)",
  2878  		Expected: []sql.Row{{2, "second row"}},
  2879  	},
  2880  	{
  2881  		Query:    "SELECT * from mytable WHERE s IN (cast('first row' AS CHAR))",
  2882  		Expected: []sql.Row{{1, "first row"}},
  2883  	},
  2884  	{
  2885  		Query:    "SELECT * from mytable WHERE s IN (lower('SECOND ROW'), 'FIRST ROW')",
  2886  		Expected: []sql.Row{{2, "second row"}},
  2887  	},
  2888  	{
  2889  		Query:    "SELECT * from mytable where true IN (i > 2)",
  2890  		Expected: []sql.Row{{3, "third row"}},
  2891  	},
  2892  	{
  2893  		Query:    "SELECT (1,2) in ((0,1), (1,0), (1,2))",
  2894  		Expected: []sql.Row{{true}},
  2895  	},
  2896  	{
  2897  		Query:    "SELECT (1,'i') in ((0,'a'), (1,'b'), (1,'i'))",
  2898  		Expected: []sql.Row{{true}},
  2899  	},
  2900  	{
  2901  		Query:    "SELECT 1 FROM DUAL WHERE 1 in (1)",
  2902  		Expected: []sql.Row{{1}},
  2903  	},
  2904  	{
  2905  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) in ((1, 2))",
  2906  		Expected: []sql.Row{{1}},
  2907  	},
  2908  	{
  2909  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) in ((3, 4), (5, 6), (1, 2))",
  2910  		Expected: []sql.Row{{1}},
  2911  	},
  2912  	{
  2913  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) in ((3, 4), (5, 6))",
  2914  		Expected: []sql.Row{},
  2915  	},
  2916  	{
  2917  		Query:    "SELECT * FROM one_pk where pk in (1) and c1 = 10",
  2918  		Expected: []sql.Row{{1, 10, 11, 12, 13, 14}},
  2919  	},
  2920  	{
  2921  		Query:    "SELECT * FROM one_pk where pk in (1)",
  2922  		Expected: []sql.Row{{1, 10, 11, 12, 13, 14}},
  2923  	},
  2924  	{
  2925  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) not in ((3, 4), (5, 6))",
  2926  		Expected: []sql.Row{{1}},
  2927  	},
  2928  	{
  2929  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) not in ((3, 4), (5, 6), (1, 2))",
  2930  		Expected: []sql.Row{},
  2931  	},
  2932  	{
  2933  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) not in ((1, 2))",
  2934  		Expected: []sql.Row{},
  2935  	},
  2936  	{
  2937  		Query:    "SELECT 1 FROM DUAL WHERE (true)",
  2938  		Expected: []sql.Row{{1}},
  2939  	},
  2940  	{
  2941  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) > (0, 1)",
  2942  		Expected: []sql.Row{{1}},
  2943  	},
  2944  	{
  2945  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) >= (0, 1)",
  2946  		Expected: []sql.Row{{1}},
  2947  	},
  2948  	{
  2949  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) <= (0, 1)",
  2950  		Expected: []sql.Row{},
  2951  	},
  2952  	{
  2953  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) < (0, 1)",
  2954  		Expected: []sql.Row{},
  2955  	},
  2956  	{
  2957  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) != (0, 1)",
  2958  		Expected: []sql.Row{{1}},
  2959  	},
  2960  	{
  2961  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) <=> (0, 1)",
  2962  		Expected: []sql.Row{},
  2963  	},
  2964  	{
  2965  		Query:    "SELECT 1 FROM DUAL WHERE (1, null) <=> (1, null)",
  2966  		Expected: []sql.Row{{1}},
  2967  	},
  2968  	{
  2969  		Query:    "SELECT 1 FROM DUAL WHERE (select 1, 2 from dual) in ((1, 2))",
  2970  		Expected: []sql.Row{{1}},
  2971  	},
  2972  	{
  2973  		Query:    "SELECT 1 FROM DUAL WHERE (select 3, 4 from dual) in ((1, 2), (2, 3), (3, 4))",
  2974  		Expected: []sql.Row{{1}},
  2975  	},
  2976  	{
  2977  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) = (select 3, 4 from dual where false)",
  2978  		Expected: []sql.Row{},
  2979  	},
  2980  	{
  2981  		Query:    "SELECT 1 FROM DUAL WHERE (select 3, 4 from dual where false) = ((1, 2))",
  2982  		Expected: []sql.Row{},
  2983  	},
  2984  	{
  2985  		Query:    "SELECT 1 FROM DUAL WHERE (select 3, 4 from dual where false) in ((1, 2))",
  2986  		Expected: []sql.Row{},
  2987  	},
  2988  	{
  2989  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) in (select 3, 4 from dual where false)",
  2990  		Expected: []sql.Row{},
  2991  	},
  2992  	{
  2993  		Query:    "SELECT 1 FROM DUAL WHERE null = (select 4 from dual where false)",
  2994  		Expected: []sql.Row{},
  2995  	},
  2996  	{
  2997  		Query:    "SELECT 1 FROM DUAL WHERE null <=> (select 4 from dual where false)",
  2998  		Expected: []sql.Row{{1}},
  2999  	},
  3000  	{
  3001  		Query:    "SELECT 1 FROM DUAL WHERE (null, null) <=> (select 1, 4 from dual where false)",
  3002  		Expected: []sql.Row{},
  3003  	},
  3004  	{
  3005  		Query:    "SELECT 1 FROM DUAL WHERE (null, null) <=> (select null, null from dual)",
  3006  		Expected: []sql.Row{{1}},
  3007  	},
  3008  	{
  3009  		Query:    "SELECT 1 FROM DUAL WHERE (select 1, 2 from dual) in (select 1, 2 from dual)",
  3010  		Expected: []sql.Row{{1}},
  3011  	},
  3012  	{
  3013  		Query:    "SELECT 1 FROM DUAL WHERE (select 1, 2 from dual where false) in (select 1, 2 from dual)",
  3014  		Expected: []sql.Row{},
  3015  	},
  3016  	{
  3017  		Query:    "SELECT 1 FROM DUAL WHERE (select 1, 2 from dual where false) in (select 1, 2 from dual where false)",
  3018  		Expected: []sql.Row{},
  3019  	},
  3020  	{
  3021  		Query:    "SELECT 1 FROM DUAL WHERE (select 1, 2 from dual) in (select 1, 2 from dual where false)",
  3022  		Expected: []sql.Row{},
  3023  	},
  3024  	{
  3025  		Query:    "SELECT 1 FROM DUAL WHERE (select 5, 6 from dual) in ((1, 2), (2, 3), (3, 4))",
  3026  		Expected: []sql.Row{},
  3027  	},
  3028  	{
  3029  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) in (select 5, 6 from dual)",
  3030  		Expected: []sql.Row{},
  3031  	},
  3032  	{
  3033  		Query:    "SELECT 1 FROM DUAL WHERE (1, 2) in (select 5, 6 from dual union select 1, 2 from dual)",
  3034  		Expected: []sql.Row{{1}},
  3035  	},
  3036  	{
  3037  		Query:    "SELECT (((1,2),3)) = (((1,2),3)) from dual",
  3038  		Expected: []sql.Row{{true}},
  3039  	},
  3040  	{
  3041  		Query:    "SELECT (((1,3),2)) = (((1,2),3)) from dual",
  3042  		Expected: []sql.Row{{false}},
  3043  	},
  3044  	{
  3045  		Query:    "SELECT (((1,3),2)) in (((1,2),6), ((1,2),4)) from dual",
  3046  		Expected: []sql.Row{{false}},
  3047  	},
  3048  	{
  3049  		Query:    "SELECT (((1,3),2)) in (((1,2),6), ((1,3),2)) from dual",
  3050  		Expected: []sql.Row{{true}},
  3051  	},
  3052  	{
  3053  		Query:    "SELECT (1, 2) in (select 1, 2 from dual) from dual",
  3054  		Expected: []sql.Row{{true}},
  3055  	},
  3056  	{
  3057  		Query:    "SELECT (1, 2) in (select 2, 3 from dual) from dual",
  3058  		Expected: []sql.Row{{false}},
  3059  	},
  3060  	{
  3061  		Query:    "SELECT (select 1, 2 from dual) in ((1, 2)) from dual",
  3062  		Expected: []sql.Row{{true}},
  3063  	},
  3064  	{
  3065  		Query:    "SELECT (select 2, 3 from dual) in ((1, 2)) from dual",
  3066  		Expected: []sql.Row{{false}},
  3067  	},
  3068  	{
  3069  		Query:    `SELECT 'a' NOT IN ('b','c',null,'d')`,
  3070  		Expected: []sql.Row{{nil}},
  3071  		ExpectedColumns: sql.Schema{
  3072  			{
  3073  				Name: "'a' NOT IN ('b','c',null,'d')",
  3074  				Type: types.Boolean,
  3075  			},
  3076  		},
  3077  	},
  3078  	{
  3079  		Query:    `SELECT 'a' NOT IN ('a','b','c','d')`,
  3080  		Expected: []sql.Row{{false}},
  3081  	},
  3082  	{
  3083  		Query:    `SELECT 'a' NOT IN ('b','c','d')`,
  3084  		Expected: []sql.Row{{true}},
  3085  	},
  3086  	{
  3087  		Query:    "SELECT i FROM mytable WHERE i IN (1, 3)",
  3088  		Expected: []sql.Row{{int64(1)}, {int64(3)}},
  3089  	},
  3090  	{
  3091  		Query:    "SELECT i FROM mytable WHERE i = 1 OR i = 3",
  3092  		Expected: []sql.Row{{int64(1)}, {int64(3)}},
  3093  	},
  3094  	{
  3095  		Query:    "SELECT * FROM mytable WHERE i = 1 AND i = 2",
  3096  		Expected: nil,
  3097  	},
  3098  	{
  3099  		Query:    "SELECT i FROM mytable WHERE i >= 2 ORDER BY 1",
  3100  		Expected: []sql.Row{{int64(2)}, {int64(3)}},
  3101  	},
  3102  	{
  3103  		Query:    "SELECT i FROM mytable WHERE 2 <= i ORDER BY 1",
  3104  		Expected: []sql.Row{{int64(2)}, {int64(3)}},
  3105  	},
  3106  	{
  3107  		Query:    "SELECT i FROM mytable WHERE i <= 2 ORDER BY 1",
  3108  		Expected: []sql.Row{{int64(1)}, {int64(2)}},
  3109  	},
  3110  	{
  3111  		Query:    "SELECT i FROM mytable WHERE 2 >= i ORDER BY 1",
  3112  		Expected: []sql.Row{{int64(1)}, {int64(2)}},
  3113  	},
  3114  	{
  3115  		Query:    "SELECT i FROM mytable WHERE i > 2",
  3116  		Expected: []sql.Row{{int64(3)}},
  3117  	},
  3118  	{
  3119  		Query:    "SELECT i FROM mytable WHERE i+1 > 3",
  3120  		Expected: []sql.Row{{int64(3)}},
  3121  	},
  3122  	{
  3123  		Query:    "SELECT i FROM mytable WHERE i < 2",
  3124  		Expected: []sql.Row{{int64(1)}},
  3125  	},
  3126  	{
  3127  		Query:    "SELECT i FROM mytable WHERE i >= 2 OR i = 1 ORDER BY 1",
  3128  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}},
  3129  	},
  3130  	{
  3131  		Query:    "SELECT f32 FROM floattable WHERE f64 = 2.0;",
  3132  		Expected: []sql.Row{{float32(2.0)}},
  3133  	},
  3134  	{
  3135  		Query:    "SELECT f32 FROM floattable WHERE f64 < 2.0;",
  3136  		Expected: []sql.Row{{float32(-1.0)}, {float32(-1.5)}, {float32(1.0)}, {float32(1.5)}},
  3137  	},
  3138  	{
  3139  		Query:    "SELECT f32 FROM floattable WHERE f64 > 2.0;",
  3140  		Expected: []sql.Row{{float32(2.5)}},
  3141  	},
  3142  	{
  3143  		Query:    "SELECT f32 FROM floattable WHERE f64 <> 2.0;",
  3144  		Expected: []sql.Row{{float32(-1.0)}, {float32(-1.5)}, {float32(1.0)}, {float32(1.5)}, {float32(2.5)}},
  3145  	},
  3146  	{
  3147  		Query:    "SELECT f64 FROM floattable WHERE f32 = 2.0;",
  3148  		Expected: []sql.Row{{float64(2.0)}},
  3149  	},
  3150  	{
  3151  		Query:    "SELECT f64 FROM floattable WHERE f32 = -1.5;",
  3152  		Expected: []sql.Row{{float64(-1.5)}},
  3153  	},
  3154  	{
  3155  		Query:    "SELECT f64 FROM floattable WHERE -f32 = -2.0;",
  3156  		Expected: []sql.Row{{float64(2.0)}},
  3157  	},
  3158  	{
  3159  		Query:    "SELECT f64 FROM floattable WHERE f32 < 2.0;",
  3160  		Expected: []sql.Row{{float64(-1.0)}, {float64(-1.5)}, {float64(1.0)}, {float64(1.5)}},
  3161  	},
  3162  	{
  3163  		Query:    "SELECT f64 FROM floattable WHERE f32 > 2.0;",
  3164  		Expected: []sql.Row{{float64(2.5)}},
  3165  	},
  3166  	{
  3167  		Query:    "SELECT f64 FROM floattable WHERE f32 <> 2.0;",
  3168  		Expected: []sql.Row{{float64(-1.0)}, {float64(-1.5)}, {float64(1.0)}, {float64(1.5)}, {float64(2.5)}},
  3169  	},
  3170  	{
  3171  		Query:    "SELECT f32 FROM floattable ORDER BY f64;",
  3172  		Expected: []sql.Row{{float32(-1.5)}, {float32(-1.0)}, {float32(1.0)}, {float32(1.5)}, {float32(2.0)}, {float32(2.5)}},
  3173  	},
  3174  	{
  3175  		Query:    "SELECT i FROM mytable ORDER BY i DESC;",
  3176  		Expected: []sql.Row{{int64(3)}, {int64(2)}, {int64(1)}},
  3177  	},
  3178  	{
  3179  		Query:    "SELECT i FROM mytable WHERE 'hello';",
  3180  		Expected: nil,
  3181  	},
  3182  	{
  3183  		Query:    "SELECT i FROM mytable WHERE NOT 'hello';",
  3184  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}},
  3185  	},
  3186  	{
  3187  		Query:    "SELECT i FROM mytable WHERE s = 'first row' ORDER BY i DESC;",
  3188  		Expected: []sql.Row{{int64(1)}},
  3189  	},
  3190  	{
  3191  		Query:    "SELECT * FROM mytable WHERE i = 2 AND s = 'third row'",
  3192  		Expected: nil,
  3193  	},
  3194  	{
  3195  		Query:    "SELECT i FROM mytable WHERE s = 'first row' ORDER BY i DESC LIMIT 1;",
  3196  		Expected: []sql.Row{{int64(1)}},
  3197  	},
  3198  	{
  3199  		Query:    "SELECT i FROM mytable WHERE s = 'first row' ORDER BY i DESC LIMIT 0;",
  3200  		Expected: []sql.Row{},
  3201  	},
  3202  	{
  3203  		Query:    "SELECT i FROM mytable ORDER BY i LIMIT 1 OFFSET 1;",
  3204  		Expected: []sql.Row{{int64(2)}},
  3205  	},
  3206  	{
  3207  		Query:    "SELECT i FROM (SELECT i FROM mytable LIMIT 1) sq WHERE i = 3;",
  3208  		Expected: []sql.Row{},
  3209  	},
  3210  	{
  3211  		Query:    "SELECT i FROM (SELECT i FROM (SELECT i FROM mytable LIMIT 1) sq1) sq2 WHERE i = 3;",
  3212  		Expected: []sql.Row{},
  3213  	},
  3214  	{
  3215  		Query:    "SELECT i FROM (SELECT i FROM mytable ORDER BY i DESC LIMIT 1) sq WHERE i = 3;",
  3216  		Expected: []sql.Row{{3}},
  3217  	},
  3218  	{
  3219  		Query:    "SELECT i FROM (SELECT i FROM (SELECT i FROM mytable ORDER BY i DESC  LIMIT 1) sq1) sq2 WHERE i = 3;",
  3220  		Expected: []sql.Row{{3}},
  3221  	},
  3222  	{
  3223  		Query:    "SELECT i FROM (SELECT i FROM mytable WHERE i > 1) sq LIMIT 1;",
  3224  		Expected: []sql.Row{{2}},
  3225  	},
  3226  	{
  3227  		Query:    "SELECT i FROM (SELECT i FROM (SELECT i FROM mytable WHERE i > 1) sq1) sq2 LIMIT 1;",
  3228  		Expected: []sql.Row{{2}},
  3229  	},
  3230  	{
  3231  		Query:    "SELECT i FROM (SELECT i FROM (SELECT i FROM mytable) sq1 WHERE i > 1) sq2 LIMIT 1;",
  3232  		Expected: []sql.Row{{2}},
  3233  	},
  3234  	{
  3235  		Query:    "SELECT i FROM (SELECT i FROM (SELECT i FROM mytable LIMIT 1) sq1 WHERE i > 1) sq2 LIMIT 10;",
  3236  		Expected: []sql.Row{},
  3237  	},
  3238  	{
  3239  		Query:    "SELECT i FROM mytable WHERE i NOT IN (SELECT i FROM (SELECT * FROM (SELECT i as i, s as s FROM mytable) f) s)",
  3240  		Expected: []sql.Row{},
  3241  	},
  3242  	{
  3243  		Query: "SELECT * FROM (SELECT a.pk, b.i FROM one_pk a JOIN mytable b ORDER BY a.pk ASC, b.i ASC LIMIT 1) sq WHERE i != 0",
  3244  		Expected: []sql.Row{
  3245  			{0, 1},
  3246  		},
  3247  	},
  3248  	{
  3249  		Query: "SELECT * FROM (SELECT a.pk, b.i FROM one_pk a JOIN mytable b ORDER BY a.pk DESC, b.i DESC LIMIT 1) sq WHERE i != 0",
  3250  		Expected: []sql.Row{
  3251  			{3, 3},
  3252  		},
  3253  	},
  3254  	{
  3255  		Query:    "SELECT * FROM (SELECT pk FROM one_pk WHERE pk < 2 LIMIT 1) a JOIN (SELECT i FROM mytable WHERE i > 1 LIMIT 1) b WHERE pk >= 2;",
  3256  		Expected: []sql.Row{},
  3257  	},
  3258  	{
  3259  		Query:    "SELECT i FROM (SELECT 1 AS i FROM DUAL UNION SELECT 2 AS i FROM DUAL) some_is WHERE i NOT IN (SELECT i FROM (SELECT 1 as i FROM DUAL) different_is);",
  3260  		Expected: []sql.Row{{int64(2)}},
  3261  	},
  3262  	{
  3263  		Query:    "SELECT i FROM mytable ORDER BY i LIMIT 1,1;",
  3264  		Expected: []sql.Row{{int64(2)}},
  3265  	},
  3266  	{
  3267  		Query:    "SELECT i FROM mytable ORDER BY i LIMIT 3,1;",
  3268  		Expected: nil,
  3269  	},
  3270  	{
  3271  		Query:    "SELECT i FROM mytable ORDER BY i LIMIT 2,100;",
  3272  		Expected: []sql.Row{{int64(3)}},
  3273  	},
  3274  	{
  3275  		Query:    "SELECT i FROM niltable WHERE b IS NULL",
  3276  		Expected: []sql.Row{{int64(1)}, {int64(4)}},
  3277  	},
  3278  	{
  3279  		Query:    "SELECT i FROM niltable WHERE b <=> NULL",
  3280  		Expected: []sql.Row{{int64(1)}, {int64(4)}},
  3281  	},
  3282  	{
  3283  		Query:    "SELECT i FROM niltable WHERE NULL <=> b",
  3284  		Expected: []sql.Row{{int64(1)}, {int64(4)}},
  3285  	},
  3286  	{
  3287  		Query: "SELECT i FROM niltable WHERE b IS NOT NULL",
  3288  		Expected: []sql.Row{
  3289  			{int64(2)}, {int64(3)},
  3290  			{int64(5)}, {int64(6)},
  3291  		},
  3292  	},
  3293  	{
  3294  		Query: "SELECT i FROM niltable WHERE b",
  3295  		Expected: []sql.Row{
  3296  			{int64(2)},
  3297  			{int64(5)},
  3298  		},
  3299  	},
  3300  	{
  3301  		Query: "SELECT i FROM niltable WHERE NOT b",
  3302  		Expected: []sql.Row{
  3303  			{int64(3)},
  3304  			{int64(6)},
  3305  		},
  3306  	},
  3307  	{
  3308  		Query:    "SELECT i FROM niltable WHERE b IS TRUE",
  3309  		Expected: []sql.Row{{int64(2)}, {int64(5)}},
  3310  	},
  3311  	{
  3312  		Query: "SELECT i FROM niltable WHERE b IS NOT TRUE",
  3313  		Expected: []sql.Row{
  3314  			{int64(1)}, {int64(3)},
  3315  			{int64(4)}, {int64(6)},
  3316  		},
  3317  	},
  3318  	{
  3319  		Query:    "SELECT f FROM niltable WHERE b IS FALSE",
  3320  		Expected: []sql.Row{{nil}, {6.0}},
  3321  	},
  3322  	{
  3323  		Query:    "SELECT i FROM niltable WHERE f < 5",
  3324  		Expected: []sql.Row{{int64(4)}},
  3325  	},
  3326  	{
  3327  		Query:    "SELECT i FROM niltable WHERE f > 5",
  3328  		Expected: []sql.Row{{int64(6)}},
  3329  	},
  3330  	{
  3331  		Query:    "SELECT i FROM niltable WHERE b IS NOT FALSE",
  3332  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(4)}, {int64(5)}},
  3333  	},
  3334  	{
  3335  		Query:    "SELECT i FROM niltable WHERE i2 IS NULL ORDER BY 1",
  3336  		Expected: []sql.Row{{int64(1)}, {int64(3)}, {int64(5)}},
  3337  	},
  3338  	{
  3339  		Query:    "SELECT i FROM niltable WHERE i2 IS NOT NULL ORDER BY 1",
  3340  		Expected: []sql.Row{{int64(2)}, {int64(4)}, {int64(6)}},
  3341  	},
  3342  	{
  3343  		Query:    "SELECT * FROM niltable WHERE i2 = NULL",
  3344  		Expected: []sql.Row{},
  3345  	},
  3346  	{
  3347  		Query:    "SELECT i2 FROM niltable WHERE i2 <=> NULL",
  3348  		Expected: []sql.Row{{nil}, {nil}, {nil}},
  3349  	},
  3350  	{
  3351  		Query:    "select i from datetime_table where date_col = date('2019-12-31T12:00:00')",
  3352  		Expected: []sql.Row{{1}},
  3353  	},
  3354  	{
  3355  		Query:    "select i from datetime_table where date_col = '2019-12-31T00:00:00'",
  3356  		Expected: []sql.Row{{1}},
  3357  	},
  3358  	{
  3359  		Query:    "select i from datetime_table where date_col = '2019-12-31T00:00:01'",
  3360  		Expected: []sql.Row{},
  3361  	},
  3362  	{
  3363  		Query:    "select i from datetime_table where date_col = '2019-12-31'",
  3364  		Expected: []sql.Row{{1}},
  3365  	},
  3366  	{
  3367  		Query:    "select i from datetime_table where date_col = '2019/12/31'",
  3368  		Expected: []sql.Row{{1}},
  3369  	},
  3370  	{
  3371  		Query:    "select i from datetime_table where date_col > '2019-12-31' order by 1",
  3372  		Expected: []sql.Row{{2}, {3}},
  3373  	},
  3374  	{
  3375  		Query:    "select i from datetime_table where date_col >= '2019-12-31' order by 1",
  3376  		Expected: []sql.Row{{1}, {2}, {3}},
  3377  	},
  3378  	{
  3379  		Query:    "select i from datetime_table where date_col > '2019/12/31' order by 1",
  3380  		Expected: []sql.Row{{2}, {3}},
  3381  	},
  3382  	{
  3383  		Query:    "select i from datetime_table where date_col > '2019-12-31T00:00:01' order by 1",
  3384  		Expected: []sql.Row{{2}, {3}},
  3385  	},
  3386  	{
  3387  		Query:    "select i from datetime_table where datetime_col = date('2020-01-01T12:00:00')",
  3388  		Expected: []sql.Row{},
  3389  	},
  3390  	{
  3391  		Query:    "select i from datetime_table where datetime_col = '2020-01-01T12:00:00'",
  3392  		Expected: []sql.Row{{1}},
  3393  	},
  3394  	{
  3395  		Query:    "select i from datetime_table where datetime_col = datetime('2020-01-01T12:00:00')",
  3396  		Expected: []sql.Row{{1}},
  3397  	},
  3398  	{
  3399  		Query:    "select i from datetime_table where datetime_col = '2020-01-01T12:00:01'",
  3400  		Expected: []sql.Row{},
  3401  	},
  3402  	{
  3403  		Query:    "select i from datetime_table where datetime_col > '2020-01-01T12:00:00' order by 1",
  3404  		Expected: []sql.Row{{2}, {3}},
  3405  	},
  3406  	{
  3407  		Query:    "select i from datetime_table where datetime_col > '2020-01-01' order by 1",
  3408  		Expected: []sql.Row{{1}, {2}, {3}},
  3409  	},
  3410  	{
  3411  		Query:    "select i from datetime_table where datetime_col >= '2020-01-01' order by 1",
  3412  		Expected: []sql.Row{{1}, {2}, {3}},
  3413  	},
  3414  	{
  3415  		Query:    "select i from datetime_table where datetime_col >= '2020-01-01 00:00' order by 1",
  3416  		Expected: []sql.Row{{1}, {2}, {3}},
  3417  	},
  3418  	{
  3419  		Query:    "select i from datetime_table where datetime_col >= '2020-01-01 00:00:00' order by 1",
  3420  		Expected: []sql.Row{{1}, {2}, {3}},
  3421  	},
  3422  	{
  3423  		Query:    "select i from datetime_table where datetime_col > '2020/01/01' order by 1",
  3424  		Expected: []sql.Row{{1}, {2}, {3}},
  3425  	},
  3426  	{
  3427  		Query:    "select i from datetime_table where datetime_col > datetime('2020-01-01T12:00:00') order by 1",
  3428  		Expected: []sql.Row{{2}, {3}},
  3429  	},
  3430  	{
  3431  		Query:    "select i from datetime_table where timestamp_col = date('2020-01-02T12:00:00')",
  3432  		Expected: []sql.Row{},
  3433  	},
  3434  	{
  3435  		Query:    "select i from datetime_table where timestamp_col = '2020-01-02T12:00:00'",
  3436  		Expected: []sql.Row{{1}},
  3437  	},
  3438  	{
  3439  		Query:    "select i from datetime_table where timestamp_col = datetime('2020-01-02T12:00:00')",
  3440  		Expected: []sql.Row{{1}},
  3441  	},
  3442  	{
  3443  		Query:    "select i from datetime_table where timestamp_col = timestamp('2020-01-02T12:00:00')",
  3444  		Expected: []sql.Row{{1}},
  3445  	},
  3446  	{
  3447  		Query:    "select i from datetime_table where timestamp_col = '2020-01-02T12:00:01'",
  3448  		Expected: []sql.Row{},
  3449  	},
  3450  	{
  3451  		Query:    "select i from datetime_table where timestamp_col > '2020-01-02T12:00:00' order by 1",
  3452  		Expected: []sql.Row{{2}, {3}},
  3453  	},
  3454  	{
  3455  		Query:    "select i from datetime_table where timestamp_col > '2020-01-02' order by 1",
  3456  		Expected: []sql.Row{{1}, {2}, {3}},
  3457  	},
  3458  	{
  3459  		Query:    "select i from datetime_table where timestamp_col >= '2020-01-02' order by 1",
  3460  		Expected: []sql.Row{{1}, {2}, {3}},
  3461  	},
  3462  	{
  3463  		Query:    "select i from datetime_table where timestamp_col > '2020/01/02' order by 1",
  3464  		Expected: []sql.Row{{1}, {2}, {3}},
  3465  	},
  3466  	{
  3467  		Query:    "select i from datetime_table where timestamp_col > datetime('2020-01-02T12:00:00') order by 1",
  3468  		Expected: []sql.Row{{2}, {3}},
  3469  	},
  3470  	{
  3471  		Query:    "SELECT dt1.i FROM datetime_table dt1 join datetime_table dt2 on dt1.timestamp_col = dt2.timestamp_col order by 1",
  3472  		Expected: []sql.Row{{1}, {2}, {3}},
  3473  	},
  3474  	{
  3475  		Query:    "SELECT dt1.i FROM datetime_table dt1 join datetime_table dt2 on dt1.date_col = date(date_sub(dt2.timestamp_col, interval 2 day)) order by 1",
  3476  		Expected: []sql.Row{{1}, {2}},
  3477  	},
  3478  	{
  3479  		Query:    "SELECT COUNT(*) FROM mytable;",
  3480  		Expected: []sql.Row{{int64(3)}},
  3481  	},
  3482  	{
  3483  		Query:    "SELECT COUNT(*) FROM mytable LIMIT 1;",
  3484  		Expected: []sql.Row{{int64(3)}},
  3485  	},
  3486  	{
  3487  		Query:    "SELECT COUNT(*) AS c FROM mytable;",
  3488  		Expected: []sql.Row{{int64(3)}},
  3489  	},
  3490  	{
  3491  		Query:    "SELECT substring(s, 2, 3) FROM mytable",
  3492  		Expected: []sql.Row{{"irs"}, {"eco"}, {"hir"}},
  3493  	},
  3494  	{
  3495  		Query:    `SELECT substring("foo", 2, 2)`,
  3496  		Expected: []sql.Row{{"oo"}},
  3497  	},
  3498  	{
  3499  		Query: `SELECT SUBSTRING_INDEX('a.b.c.d.e.f', '.', 2)`,
  3500  		Expected: []sql.Row{
  3501  			{"a.b"},
  3502  		},
  3503  	},
  3504  	{
  3505  		Query: `SELECT SUBSTRING_INDEX('a.b.c.d.e.f', '.', -2)`,
  3506  		Expected: []sql.Row{
  3507  			{"e.f"},
  3508  		},
  3509  	},
  3510  	{
  3511  		Query: `SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('source{d}', '{d}', 1), 'r', -1)`,
  3512  		Expected: []sql.Row{
  3513  			{"ce"},
  3514  		},
  3515  	},
  3516  	{
  3517  		Query:    `SELECT SUBSTRING_INDEX(mytable.s, "d", 1) AS s FROM mytable INNER JOIN othertable ON (SUBSTRING_INDEX(mytable.s, "d", 1) = SUBSTRING_INDEX(othertable.s2, "d", 1)) GROUP BY 1 HAVING s = 'secon';`,
  3518  		Expected: []sql.Row{{"secon"}},
  3519  	},
  3520  	{
  3521  		Query:    `SELECT SUBSTRING_INDEX(mytable.s, "d", 1) AS s FROM mytable INNER JOIN othertable ON (SUBSTRING_INDEX(mytable.s, "d", 1) = SUBSTRING_INDEX(othertable.s2, "d", 1)) GROUP BY s HAVING s = 'secon';`,
  3522  		Expected: []sql.Row{},
  3523  	},
  3524  	{
  3525  		Query:    `SELECT SUBSTRING_INDEX(mytable.s, "d", 1) AS ss FROM mytable INNER JOIN othertable ON (SUBSTRING_INDEX(mytable.s, "d", 1) = SUBSTRING_INDEX(othertable.s2, "d", 1)) GROUP BY s HAVING s = 'secon';`,
  3526  		Expected: []sql.Row{},
  3527  	},
  3528  	{
  3529  		Query: `SELECT SUBSTRING_INDEX(mytable.s, "d", 1) AS ss FROM mytable INNER JOIN othertable ON (SUBSTRING_INDEX(mytable.s, "d", 1) = SUBSTRING_INDEX(othertable.s2, "d", 1)) GROUP BY ss HAVING ss = 'secon';`,
  3530  		Expected: []sql.Row{
  3531  			{"secon"},
  3532  		},
  3533  	},
  3534  	{
  3535  		Query:    `SELECT TRIM(mytable.s) AS s FROM mytable`,
  3536  		Expected: []sql.Row{{"first row"}, {"second row"}, {"third row"}},
  3537  	},
  3538  	{
  3539  		Query:    `SELECT TRIM("row" from mytable.s) AS s FROM mytable`,
  3540  		Expected: []sql.Row{{"first "}, {"second "}, {"third "}},
  3541  	},
  3542  	{
  3543  		Query:    `SELECT TRIM(mytable.s from "first row") AS s FROM mytable`,
  3544  		Expected: []sql.Row{{""}, {"first row"}, {"first row"}},
  3545  	},
  3546  	{
  3547  		Query:    `SELECT TRIM(mytable.s from mytable.s) AS s FROM mytable`,
  3548  		Expected: []sql.Row{{""}, {""}, {""}},
  3549  	},
  3550  	{
  3551  		Query:    `SELECT TRIM("   foo   ")`,
  3552  		Expected: []sql.Row{{"foo"}},
  3553  	},
  3554  	{
  3555  		Query:    `SELECT TRIM(" " FROM "   foo   ")`,
  3556  		Expected: []sql.Row{{"foo"}},
  3557  	},
  3558  	{
  3559  		Query:    `SELECT TRIM(LEADING " " FROM "   foo   ")`,
  3560  		Expected: []sql.Row{{"foo   "}},
  3561  	},
  3562  	{
  3563  		Query:    `SELECT TRIM(TRAILING " " FROM "   foo   ")`,
  3564  		Expected: []sql.Row{{"   foo"}},
  3565  	},
  3566  	{
  3567  		Query:    `SELECT TRIM(BOTH " " FROM "   foo   ")`,
  3568  		Expected: []sql.Row{{"foo"}},
  3569  	},
  3570  	{
  3571  		Query:    `SELECT TRIM("" FROM " foo")`,
  3572  		Expected: []sql.Row{{" foo"}},
  3573  	},
  3574  	{
  3575  		Query:    `SELECT TRIM("bar" FROM "barfoobar")`,
  3576  		Expected: []sql.Row{{"foo"}},
  3577  	},
  3578  	{
  3579  		Query:    `SELECT TRIM(TRAILING "bar" FROM "barfoobar")`,
  3580  		Expected: []sql.Row{{"barfoo"}},
  3581  	},
  3582  	{
  3583  		Query:    `SELECT TRIM(TRAILING "foo" FROM "foo")`,
  3584  		Expected: []sql.Row{{""}},
  3585  	},
  3586  	{
  3587  		Query:    `SELECT TRIM(LEADING "ooo" FROM TRIM("oooo"))`,
  3588  		Expected: []sql.Row{{"o"}},
  3589  	},
  3590  	{
  3591  		Query:    `SELECT TRIM(BOTH "foo" FROM TRIM("barfoobar"))`,
  3592  		Expected: []sql.Row{{"barfoobar"}},
  3593  	},
  3594  	{
  3595  		Query:    `SELECT TRIM(LEADING "bar" FROM TRIM("foobar"))`,
  3596  		Expected: []sql.Row{{"foobar"}},
  3597  	},
  3598  	{
  3599  		Query:    `SELECT TRIM(TRAILING "oo" FROM TRIM("oof"))`,
  3600  		Expected: []sql.Row{{"oof"}},
  3601  	},
  3602  	{
  3603  		Query:    `SELECT TRIM(LEADING "test" FROM TRIM("  test  "))`,
  3604  		Expected: []sql.Row{{""}},
  3605  	},
  3606  	{
  3607  		Query:    `SELECT TRIM(LEADING CONCAT("a", "b") FROM TRIM("ababab"))`,
  3608  		Expected: []sql.Row{{""}},
  3609  	},
  3610  	{
  3611  		Query:    `SELECT TRIM(TRAILING CONCAT("a", "b") FROM CONCAT("test","ab"))`,
  3612  		Expected: []sql.Row{{"test"}},
  3613  	},
  3614  	{
  3615  		Query:    `SELECT TRIM(LEADING 1 FROM "11111112")`,
  3616  		Expected: []sql.Row{{"2"}},
  3617  	},
  3618  	{
  3619  		Query:    `SELECT TRIM(LEADING 1 FROM 11111112)`,
  3620  		Expected: []sql.Row{{"2"}},
  3621  	},
  3622  
  3623  	{
  3624  		Query:    `SELECT INET_ATON("10.0.5.10")`,
  3625  		Expected: []sql.Row{{uint64(167773450)}},
  3626  	},
  3627  	{
  3628  		Query:    `SELECT INET_NTOA(167773450)`,
  3629  		Expected: []sql.Row{{"10.0.5.10"}},
  3630  	},
  3631  	{
  3632  		Query:    `SELECT INET_ATON("10.0.5.11")`,
  3633  		Expected: []sql.Row{{uint64(167773451)}},
  3634  	},
  3635  	{
  3636  		Query:    `SELECT INET_NTOA(167773451)`,
  3637  		Expected: []sql.Row{{"10.0.5.11"}},
  3638  	},
  3639  	{
  3640  		Query:    `SELECT INET_NTOA(INET_ATON("12.34.56.78"))`,
  3641  		Expected: []sql.Row{{"12.34.56.78"}},
  3642  	},
  3643  	{
  3644  		Query:    `SELECT INET_ATON(INET_NTOA("12345678"))`,
  3645  		Expected: []sql.Row{{uint64(12345678)}},
  3646  	},
  3647  	{
  3648  		Query:    `SELECT INET_ATON("notanipaddress")`,
  3649  		Expected: []sql.Row{{nil}},
  3650  	},
  3651  	{
  3652  		Query:    `SELECT INET_NTOA("spaghetti")`,
  3653  		Expected: []sql.Row{{"0.0.0.0"}},
  3654  	},
  3655  	{
  3656  		Query:    `SELECT HEX(INET6_ATON("10.0.5.9"))`,
  3657  		Expected: []sql.Row{{"0A000509"}},
  3658  	},
  3659  	{
  3660  		Query:    `SELECT HEX(INET6_ATON("::10.0.5.9"))`,
  3661  		Expected: []sql.Row{{"0000000000000000000000000A000509"}},
  3662  	},
  3663  	{
  3664  		Query:    `SELECT HEX(INET6_ATON("1.2.3.4"))`,
  3665  		Expected: []sql.Row{{"01020304"}},
  3666  	},
  3667  	{
  3668  		Query:    `SELECT HEX(INET6_ATON("fdfe::5455:caff:fefa:9098"))`,
  3669  		Expected: []sql.Row{{"FDFE0000000000005455CAFFFEFA9098"}},
  3670  	},
  3671  	{
  3672  		Query:    `SELECT HEX(INET6_ATON("1111:2222:3333:4444:5555:6666:7777:8888"))`,
  3673  		Expected: []sql.Row{{"11112222333344445555666677778888"}},
  3674  	},
  3675  	{
  3676  		Query:    `SELECT INET6_ATON("notanipaddress")`,
  3677  		Expected: []sql.Row{{nil}},
  3678  	},
  3679  	{
  3680  		Query:    `SELECT INET6_NTOA(UNHEX("1234ffff5678ffff1234ffff5678ffff"))`,
  3681  		Expected: []sql.Row{{"1234:ffff:5678:ffff:1234:ffff:5678:ffff"}},
  3682  	},
  3683  	{
  3684  		Query:    `SELECT INET6_NTOA(UNHEX("ffffffff"))`,
  3685  		Expected: []sql.Row{{"255.255.255.255"}},
  3686  	},
  3687  	{
  3688  		Query:    `SELECT INET6_NTOA(UNHEX("000000000000000000000000ffffffff"))`,
  3689  		Expected: []sql.Row{{"::255.255.255.255"}},
  3690  	},
  3691  	{
  3692  		Query:    `SELECT INET6_NTOA(UNHEX("00000000000000000000ffffffffffff"))`,
  3693  		Expected: []sql.Row{{"::ffff:255.255.255.255"}},
  3694  	},
  3695  	{
  3696  		Query:    `SELECT INET6_NTOA(UNHEX("0000000000000000000000000000ffff"))`,
  3697  		Expected: []sql.Row{{"::ffff"}},
  3698  	},
  3699  	{
  3700  		Query:    `SELECT INET6_NTOA(UNHEX("00000000000000000000000000000000"))`,
  3701  		Expected: []sql.Row{{"::"}},
  3702  	},
  3703  	{
  3704  		Query:    `SELECT INET6_NTOA("notanipaddress")`,
  3705  		Expected: []sql.Row{{nil}},
  3706  	},
  3707  	{
  3708  		Query:    `SELECT IS_IPV4("10.0.1.10")`,
  3709  		Expected: []sql.Row{{true}},
  3710  	},
  3711  	{
  3712  		Query:    `SELECT IS_IPV4("::10.0.1.10")`,
  3713  		Expected: []sql.Row{{false}},
  3714  	},
  3715  	{
  3716  		Query:    `SELECT IS_IPV4("notanipaddress")`,
  3717  		Expected: []sql.Row{{false}},
  3718  	},
  3719  	{
  3720  		Query:    `SELECT IS_IPV6("10.0.1.10")`,
  3721  		Expected: []sql.Row{{false}},
  3722  	},
  3723  	{
  3724  		Query:    `SELECT IS_IPV6("::10.0.1.10")`,
  3725  		Expected: []sql.Row{{true}},
  3726  	},
  3727  	{
  3728  		Query:    `SELECT IS_IPV6("notanipaddress")`,
  3729  		Expected: []sql.Row{{false}},
  3730  	},
  3731  	{
  3732  		Query:    `SELECT IS_IPV4_COMPAT(INET6_ATON("10.0.1.10"))`,
  3733  		Expected: []sql.Row{{false}},
  3734  	},
  3735  	{
  3736  		Query:    `SELECT IS_IPV4_COMPAT(INET6_ATON("::10.0.1.10"))`,
  3737  		Expected: []sql.Row{{true}},
  3738  	},
  3739  	{
  3740  		Query:    `SELECT IS_IPV4_COMPAT(INET6_ATON("::ffff:10.0.1.10"))`,
  3741  		Expected: []sql.Row{{false}},
  3742  	},
  3743  	{
  3744  		Query:    `SELECT IS_IPV4_COMPAT(INET6_ATON("notanipaddress"))`,
  3745  		Expected: []sql.Row{{nil}},
  3746  	},
  3747  	{
  3748  		Query:    `SELECT IS_IPV4_MAPPED(INET6_ATON("10.0.1.10"))`,
  3749  		Expected: []sql.Row{{false}},
  3750  	},
  3751  	{
  3752  		Query:    `SELECT IS_IPV4_MAPPED(INET6_ATON("::10.0.1.10"))`,
  3753  		Expected: []sql.Row{{false}},
  3754  	},
  3755  	{
  3756  		Query:    `SELECT IS_IPV4_MAPPED(INET6_ATON("::ffff:10.0.1.10"))`,
  3757  		Expected: []sql.Row{{true}},
  3758  	},
  3759  	{
  3760  		Query:    `SELECT IS_IPV4_COMPAT(INET6_ATON("notanipaddress"))`,
  3761  		Expected: []sql.Row{{nil}},
  3762  	},
  3763  	{
  3764  		Query:    "SELECT YEAR('2007-12-11') FROM mytable",
  3765  		Expected: []sql.Row{{int32(2007)}, {int32(2007)}, {int32(2007)}},
  3766  	},
  3767  	{
  3768  		Query:    "SELECT MONTH('2007-12-11') FROM mytable",
  3769  		Expected: []sql.Row{{int32(12)}, {int32(12)}, {int32(12)}},
  3770  	},
  3771  	{
  3772  		Query:    "SELECT DAY('2007-12-11') FROM mytable",
  3773  		Expected: []sql.Row{{int32(11)}, {int32(11)}, {int32(11)}},
  3774  	},
  3775  	{
  3776  		Query:    "SELECT HOUR('2007-12-11 20:21:22') FROM mytable",
  3777  		Expected: []sql.Row{{int32(20)}, {int32(20)}, {int32(20)}},
  3778  	},
  3779  	{
  3780  		Query:    "SELECT MINUTE('2007-12-11 20:21:22') FROM mytable",
  3781  		Expected: []sql.Row{{int32(21)}, {int32(21)}, {int32(21)}},
  3782  	},
  3783  	{
  3784  		Query:    "SELECT SECOND('2007-12-11 20:21:22') FROM mytable",
  3785  		Expected: []sql.Row{{int32(22)}, {int32(22)}, {int32(22)}},
  3786  	},
  3787  	{
  3788  		Query:    "SELECT DAYOFYEAR('2007-12-11 20:21:22') FROM mytable",
  3789  		Expected: []sql.Row{{int32(345)}, {int32(345)}, {int32(345)}},
  3790  	},
  3791  	{
  3792  		Query:    "SELECT SECOND('2007-12-11T20:21:22Z') FROM mytable",
  3793  		Expected: []sql.Row{{int32(22)}, {int32(22)}, {int32(22)}},
  3794  	},
  3795  	{
  3796  		Query:    "SELECT DAYOFYEAR('2007-12-11') FROM mytable",
  3797  		Expected: []sql.Row{{int32(345)}, {int32(345)}, {int32(345)}},
  3798  	},
  3799  	{
  3800  		Query:    "SELECT DAYOFYEAR('20071211') FROM mytable",
  3801  		Expected: []sql.Row{{int32(345)}, {int32(345)}, {int32(345)}},
  3802  	},
  3803  	{
  3804  		Query:    "SELECT YEARWEEK('0000-01-01')",
  3805  		Expected: []sql.Row{{int32(1)}},
  3806  	},
  3807  	{
  3808  		Query:    "SELECT YEARWEEK('9999-12-31')",
  3809  		Expected: []sql.Row{{int32(999952)}},
  3810  	},
  3811  	{
  3812  		Query:    "SELECT YEARWEEK('2008-02-20', 1)",
  3813  		Expected: []sql.Row{{int32(200808)}},
  3814  	},
  3815  	{
  3816  		Query:    "SELECT YEARWEEK('1987-01-01')",
  3817  		Expected: []sql.Row{{int32(198652)}},
  3818  	},
  3819  	{
  3820  		Query:    "SELECT YEARWEEK('1987-01-01', 20), YEARWEEK('1987-01-01', 1), YEARWEEK('1987-01-01', 2), YEARWEEK('1987-01-01', 3), YEARWEEK('1987-01-01', 4), YEARWEEK('1987-01-01', 5), YEARWEEK('1987-01-01', 6), YEARWEEK('1987-01-01', 7)",
  3821  		Expected: []sql.Row{{int32(198653), int32(198701), int32(198652), int32(198701), int32(198653), int32(198652), int32(198653), int32(198652)}},
  3822  	},
  3823  	{
  3824  		Query:    `select 'a'+4;`,
  3825  		Expected: []sql.Row{{4.0}},
  3826  	},
  3827  	{
  3828  		Query:    `select '20a'+4;`,
  3829  		Expected: []sql.Row{{24.0}},
  3830  	},
  3831  	{
  3832  		Query:    `select '10.a'+4;`,
  3833  		Expected: []sql.Row{{14.0}},
  3834  	},
  3835  	{
  3836  		Query:    `select '.20a'+4;`,
  3837  		Expected: []sql.Row{{4.2}},
  3838  	},
  3839  	{
  3840  		Query:    `select 4+'a';`,
  3841  		Expected: []sql.Row{{4.0}},
  3842  	},
  3843  	{
  3844  		Query:    `select 'a'+'a';`,
  3845  		Expected: []sql.Row{{0.0}},
  3846  	},
  3847  	{
  3848  		Query:    "SELECT STR_TO_DATE('01,5,2013 09:30:17','%d,%m,%Y %h:%i:%s') + STR_TO_DATE('01,5,2013 09:30:17','%d,%m,%Y %h:%i:%s');",
  3849  		Expected: []sql.Row{{40261002186034}},
  3850  	},
  3851  	{
  3852  		Query:    `select 'a'-4;`,
  3853  		Expected: []sql.Row{{-4.0}},
  3854  	},
  3855  	{
  3856  		Query:    `select 4-'a';`,
  3857  		Expected: []sql.Row{{4.0}},
  3858  	},
  3859  	{
  3860  		Query:    `select 4-'2a';`,
  3861  		Expected: []sql.Row{{2.0}},
  3862  	},
  3863  	{
  3864  		Query:    `select 'a'-'a';`,
  3865  		Expected: []sql.Row{{0.0}},
  3866  	},
  3867  	{
  3868  		Query:    `select 'a'*4;`,
  3869  		Expected: []sql.Row{{0.0}},
  3870  	},
  3871  	{
  3872  		Query:    `select 4*'a';`,
  3873  		Expected: []sql.Row{{0.0}},
  3874  	},
  3875  	{
  3876  		Query:    `select 'a'*'a';`,
  3877  		Expected: []sql.Row{{0.0}},
  3878  	},
  3879  	{
  3880  		Query:    "select 1 * '2.50a';",
  3881  		Expected: []sql.Row{{2.5}},
  3882  	},
  3883  	{
  3884  		Query:    "select 1 * '2.a50a';",
  3885  		Expected: []sql.Row{{2.0}},
  3886  	},
  3887  	{
  3888  		Query:    `select 'a'/4;`,
  3889  		Expected: []sql.Row{{0.0}},
  3890  	},
  3891  	{
  3892  		Query:    `select 4/'a';`,
  3893  		Expected: []sql.Row{{nil}},
  3894  	},
  3895  	{
  3896  		Query:    `select 'a'/'a';`,
  3897  		Expected: []sql.Row{{nil}},
  3898  	},
  3899  	{
  3900  		Query:    "select 1 / '2.50a';",
  3901  		Expected: []sql.Row{{0.4}},
  3902  	},
  3903  	{
  3904  		Query:    "select 1 / '2.a50a';",
  3905  		Expected: []sql.Row{{0.5}},
  3906  	},
  3907  	{
  3908  		Query:    `select STR_TO_DATE('01,5,2013 09:30:17','%d,%m,%Y %h:%i:%s') / 1;`,
  3909  		Expected: []sql.Row{{"20130501093017.0000"}},
  3910  	},
  3911  	{
  3912  		Query:    "select 'a'&'a';",
  3913  		Expected: []sql.Row{{uint64(0)}},
  3914  	},
  3915  	{
  3916  		Query:    "select 'a'&4;",
  3917  		Expected: []sql.Row{{uint64(0)}},
  3918  	},
  3919  	{
  3920  		Query:    "select 4&'a';",
  3921  		Expected: []sql.Row{{uint64(0)}},
  3922  	},
  3923  	{
  3924  		Query:    "select date('2022-11-19 11:53:45') & date('2022-11-11 11:53:45');",
  3925  		Expected: []sql.Row{{uint64(20221111)}},
  3926  	},
  3927  	{
  3928  		Query:    "select '2022-11-19 11:53:45' & '2023-11-11 11:53:45';",
  3929  		Expected: []sql.Row{{uint64(2022)}},
  3930  	},
  3931  	{
  3932  		Query:    "SELECT STR_TO_DATE('01,5,2013 09:30:17','%d,%m,%Y %h:%i:%s') & STR_TO_DATE('01,5,2013 09:30:17','%d,%m,%Y %h:%i:%s');",
  3933  		Expected: []sql.Row{{uint64(20130501093017)}},
  3934  	},
  3935  	{
  3936  		Query:    "select 'a'|'a';",
  3937  		Expected: []sql.Row{{uint64(0)}},
  3938  	},
  3939  	{
  3940  		Query:    "select 'a'|4;",
  3941  		Expected: []sql.Row{{uint64(4)}},
  3942  	},
  3943  	{
  3944  		Query:    "select 'a'|-1;",
  3945  		Expected: []sql.Row{{uint64(18446744073709551615)}},
  3946  	},
  3947  	{
  3948  		Query:    "select 4|'a';",
  3949  		Expected: []sql.Row{{uint64(4)}},
  3950  	},
  3951  	{
  3952  		Query:    "select 'a'^'a';",
  3953  		Expected: []sql.Row{{uint64(0)}},
  3954  	},
  3955  	{
  3956  		Query:    "select 'a'^4;",
  3957  		Expected: []sql.Row{{uint64(4)}},
  3958  	},
  3959  	{
  3960  		Query:    "select 'a'^-1;",
  3961  		Expected: []sql.Row{{uint64(18446744073709551615)}},
  3962  	},
  3963  	{
  3964  		Query:    "select 4^'a';",
  3965  		Expected: []sql.Row{{uint64(4)}},
  3966  	},
  3967  	{
  3968  		Query:    "select now() ^ now();",
  3969  		Expected: []sql.Row{{uint64(0)}},
  3970  	},
  3971  	{
  3972  		Query:    "select 'a'>>'a';",
  3973  		Expected: []sql.Row{{uint64(0)}},
  3974  	},
  3975  	{
  3976  		Query:    "select 'a'>>4;",
  3977  		Expected: []sql.Row{{uint64(0)}},
  3978  	},
  3979  	{
  3980  		Query:    "select 4>>'a';",
  3981  		Expected: []sql.Row{{uint64(4)}},
  3982  	},
  3983  	{
  3984  		Query:    "select -1>>'a';",
  3985  		Expected: []sql.Row{{uint64(18446744073709551615)}},
  3986  	},
  3987  	{
  3988  		Query:    "select 'a'<<'a';",
  3989  		Expected: []sql.Row{{uint64(0)}},
  3990  	},
  3991  	{
  3992  		Query:    "select 'a'<<4;",
  3993  		Expected: []sql.Row{{uint64(0)}},
  3994  	},
  3995  	{
  3996  		Query:    "select '2a'<<4;",
  3997  		Expected: []sql.Row{{uint64(32)}},
  3998  	},
  3999  	{
  4000  		Query:    "select 4<<'a';",
  4001  		Expected: []sql.Row{{uint64(4)}},
  4002  	},
  4003  	{
  4004  		Query:    "select -1<<'a';",
  4005  		Expected: []sql.Row{{uint64(18446744073709551615)}},
  4006  	},
  4007  	{
  4008  		Query:    "select -1.00 div 2;",
  4009  		Expected: []sql.Row{{0}},
  4010  	},
  4011  	{
  4012  		Query:    "select 'a' div 'a';",
  4013  		Expected: []sql.Row{{nil}},
  4014  	},
  4015  	{
  4016  		Query:    "select 'a' div 4;",
  4017  		Expected: []sql.Row{{0}},
  4018  	},
  4019  	{
  4020  		Query:    "select 4 div 'a';",
  4021  		Expected: []sql.Row{{nil}},
  4022  	},
  4023  	{
  4024  		Query:    "select 1.2 div 0.2;",
  4025  		Expected: []sql.Row{{6}},
  4026  	},
  4027  	{
  4028  		Query:    "select 1.2 div 0.4;",
  4029  		Expected: []sql.Row{{3}},
  4030  	},
  4031  	{
  4032  		Query:    "select 1.2 div '1' ;",
  4033  		Expected: []sql.Row{{1}},
  4034  	},
  4035  	{
  4036  		Query:    "select 1.2 div 'a1' ;",
  4037  		Expected: []sql.Row{{nil}},
  4038  	},
  4039  	{
  4040  		Query:    "select '12a' div '3' ;",
  4041  		Expected: []sql.Row{{4}},
  4042  	},
  4043  	{
  4044  		Query:    "select 'a' mod 'a';",
  4045  		Expected: []sql.Row{{nil}},
  4046  	},
  4047  	{
  4048  		Query:    "select 'a' mod 4;",
  4049  		Expected: []sql.Row{{float64(0)}},
  4050  	},
  4051  	{
  4052  		Query:    "select 4 mod 'a';",
  4053  		Expected: []sql.Row{{nil}},
  4054  	},
  4055  	{
  4056  		Query:    `select STR_TO_DATE('01,5,2013 09:30:17','%d,%m,%Y %h:%i:%s') % 12345;`,
  4057  		Expected: []sql.Row{{"10487"}},
  4058  	},
  4059  	{
  4060  		Query:    "select 0.0015 / 0.0026;",
  4061  		Expected: []sql.Row{{"0.57692308"}},
  4062  	},
  4063  	{
  4064  		Query:    "select (14620 / 9432456);",
  4065  		Expected: []sql.Row{{"0.0015"}},
  4066  	},
  4067  	{
  4068  		Query:    "select (24250 / 9432456);",
  4069  		Expected: []sql.Row{{"0.0026"}},
  4070  	},
  4071  	{
  4072  		Query:    "select 5.2/3.1/1.7/1/1/1/1/1;",
  4073  		Expected: []sql.Row{{"0.98671726755218216294117647000"}},
  4074  	},
  4075  	{
  4076  		Query:    "select 5.2/3.1/1.9/1/1/1/1/1;",
  4077  		Expected: []sql.Row{{"0.88285229202037351421052631500"}},
  4078  	},
  4079  	{
  4080  		Query:    "select 1.677419354838709677/1.9;",
  4081  		Expected: []sql.Row{{"0.8828522920203735142105"}},
  4082  	},
  4083  	{
  4084  		Query:    "select 1.9/1.677419354838709677;",
  4085  		Expected: []sql.Row{{"1.13269"}},
  4086  	},
  4087  	{
  4088  		Query:    "select 1.677419354838709677/1.9/1/1/1/1/1;",
  4089  		Expected: []sql.Row{{"0.882852292020373514210526315000"}},
  4090  	},
  4091  	{
  4092  		Query:    "select (14620 / 9432456) / (24250 / 9432456);",
  4093  		Expected: []sql.Row{{"0.60288653"}},
  4094  	},
  4095  	{
  4096  		Query:    "select (14620.0 / 9432456) / (24250 / 9432456);",
  4097  		Expected: []sql.Row{{"0.602886527"}},
  4098  	},
  4099  	{
  4100  		Query:    "select (14620 / 9432456),  (24250 / 9432456), (14620 / 9432456) / (24250 / 9432456);",
  4101  		Expected: []sql.Row{{"0.0015", "0.0026", "0.60288653"}},
  4102  	},
  4103  	{
  4104  		Query:    "select 1000.0 / 20.00;",
  4105  		Expected: []sql.Row{{"50.00000"}},
  4106  	},
  4107  	{
  4108  		Query:    "select 2000.0 * (24.0 * 6.0 * 6.25 * 10.0) / 250000000.0;",
  4109  		Expected: []sql.Row{{"0.0720000000"}},
  4110  	},
  4111  	{
  4112  		Query:    "select 2000.0 / 250000000.0 * (24.0 * 6.0 * 6.25 * 10.0);",
  4113  		Expected: []sql.Row{{"0.0720000000"}},
  4114  	},
  4115  	{
  4116  		Query:    `select 100 / 35600.00 * 35600.00;`,
  4117  		Expected: []sql.Row{{"99.999973"}},
  4118  	},
  4119  	{
  4120  		Query:    `select 64 / 77 * 77;`,
  4121  		Expected: []sql.Row{{"64.0000"}},
  4122  	},
  4123  	{
  4124  		Query:    `select (1 / 3) * (1 / 3);`,
  4125  		Expected: []sql.Row{{"0.11111111"}},
  4126  	},
  4127  	{
  4128  		Query:    "select 1/2/3/4/5/6;",
  4129  		Expected: []sql.Row{{"0.00138888888888888888"}},
  4130  	},
  4131  	{
  4132  		Query:    "select 24/3/2*1/2/3;",
  4133  		Expected: []sql.Row{{"0.6666666666666667"}},
  4134  	},
  4135  	{
  4136  		Query:    "select 1/2/3%4/5/6;",
  4137  		Expected: []sql.Row{{"0.0055555555555556"}},
  4138  	},
  4139  
  4140  	// check that internal precision is preserved in comparisons
  4141  	{
  4142  		// 0 scale + 0 scale = 9 scale
  4143  		Query:    "select 1 / 3 = 0.333333333;",
  4144  		Expected: []sql.Row{{true}},
  4145  	},
  4146  	{
  4147  		// 0 scale + 1 scale = 9 scale
  4148  		Query:    "select 1 / 3.0 = 0.333333333;",
  4149  		Expected: []sql.Row{{true}},
  4150  	},
  4151  	{
  4152  		// 0 scale + 6 scale = 18 scale
  4153  		Query:    "select 1 / 3.000000 = 0.333333333333333333;",
  4154  		Expected: []sql.Row{{true}},
  4155  	},
  4156  	{
  4157  		// 0 scale + 15 scale = 27 scale
  4158  		Query:    "select 1 / 3.000000000000000 = 0.333333333333333333333333333;",
  4159  		Expected: []sql.Row{{true}},
  4160  	},
  4161  	{
  4162  		// 0 scale + 24 scale = 36 scale
  4163  		Query:    "select 1 / 3.000000000000000000000000 = 0.333333333333333333333333333333333333;",
  4164  		Expected: []sql.Row{{true}},
  4165  	},
  4166  
  4167  	{
  4168  		// 1 scale + 0 scale = 9 scale
  4169  		Query:    "select 1.0 / 3 = 0.333333333;",
  4170  		Expected: []sql.Row{{true}},
  4171  	},
  4172  	{
  4173  		// 1 scale + 1 scale = 18 scale
  4174  		Query:    "select 1.0 / 3.0 = 0.333333333333333333;",
  4175  		Expected: []sql.Row{{true}},
  4176  	},
  4177  	{
  4178  		// 1 scale + 10 scale = 27 scale
  4179  		Query:    "select 1.0 / 3.0000000000 = 0.333333333333333333333333333;",
  4180  		Expected: []sql.Row{{true}},
  4181  	},
  4182  	{
  4183  		// 1 scale + 19 scale = 36 scale
  4184  		Query:    "select 1.0 / 3.0000000000000000000 = 0.333333333333333333333333333333333333;",
  4185  		Expected: []sql.Row{{true}},
  4186  	},
  4187  
  4188  	{
  4189  		// 6 scale + 8 scale = 18 scale
  4190  		Query:    "select 1.000000 / 3.00000000 = 0.333333333333333333;",
  4191  		Expected: []sql.Row{{true}},
  4192  	},
  4193  	{
  4194  		// 6 scale + 9 scale = 27 scale
  4195  		Query:    "select 1.000000 / 3.000000000 = 0.333333333333333333333333333;",
  4196  		Expected: []sql.Row{{true}},
  4197  	},
  4198  	{
  4199  		// 6 scale + 17 scale = 27 scale
  4200  		Query:    "select 1.000000 / 3.00000000000000000 = 0.333333333333333333333333333;",
  4201  		Expected: []sql.Row{{true}},
  4202  	},
  4203  	{
  4204  		// 6 scale + 18 scale = 36 scale
  4205  		Query:    "select 1.000000 / 3.000000000000000000 = 0.333333333333333333333333333333333333;",
  4206  		Expected: []sql.Row{{true}},
  4207  	},
  4208  
  4209  	{
  4210  		// 7 scale + 7 scale = 18 scale
  4211  		Query:    "select 1.0000000 / 3.0000000 = 0.333333333333333333;",
  4212  		Expected: []sql.Row{{true}},
  4213  	},
  4214  	{
  4215  		// 7 scale + 8 scale = 27 scale
  4216  		Query:    "select 1.0000000 / 3.00000000 = 0.333333333333333333333333333;",
  4217  		Expected: []sql.Row{{true}},
  4218  	},
  4219  	{
  4220  		// 7 scale + 16 scale = 27 scale
  4221  		Query:    "select 1.0000000 / 3.0000000000000000 = 0.333333333333333333333333333;",
  4222  		Expected: []sql.Row{{true}},
  4223  	},
  4224  	{
  4225  		// 7 scale + 15 scale = 36 scale
  4226  		Query:    "select 1.0000000 / 3.00000000000000000 = 0.333333333333333333333333333333333333;",
  4227  		Expected: []sql.Row{{true}},
  4228  	},
  4229  
  4230  	{
  4231  		// 8 scale + 6 scale = 18 scale
  4232  		Query:    "select 1.00000000 / 3.000000 = 0.333333333333333333;",
  4233  		Expected: []sql.Row{{true}},
  4234  	},
  4235  	{
  4236  		// 8 scale + 7 scale = 27 scale
  4237  		Query:    "select 1.00000000 / 3.0000000 = 0.333333333333333333333333333;",
  4238  		Expected: []sql.Row{{true}},
  4239  	},
  4240  	{
  4241  		// 8 scale + 15 scale = 27 scale
  4242  		Query:    "select 1.00000000 / 3.000000000000000 = 0.333333333333333333333333333;",
  4243  		Expected: []sql.Row{{true}},
  4244  	},
  4245  	{
  4246  		// 8 scale + 14 scale = 36 scale
  4247  		Query:    "select 1.00000000 / 3.0000000000000000 = 0.333333333333333333333333333333333333;",
  4248  		Expected: []sql.Row{{true}},
  4249  	},
  4250  
  4251  	{
  4252  		// 9 scale + 5 scale = 18 scale
  4253  		Query:    "select 1.000000000 / 3.00000 = 0.333333333333333333;",
  4254  		Expected: []sql.Row{{true}},
  4255  	},
  4256  	{
  4257  		// 9 scale + 6 scale = 27 scale
  4258  		Query:    "select 1.000000000 / 3.000000 = 0.333333333333333333333333333;",
  4259  		Expected: []sql.Row{{true}},
  4260  	},
  4261  	{
  4262  		// 9 scale + 14 scale = 27 scale
  4263  		Query:    "select 1.000000000 / 3.00000000000000 = 0.333333333333333333333333333;",
  4264  		Expected: []sql.Row{{true}},
  4265  	},
  4266  	{
  4267  		// 9 scale + 13 scale = 36 scale
  4268  		Query:    "select 1.000000000 / 3.000000000000000 = 0.333333333333333333333333333333333333;",
  4269  		Expected: []sql.Row{{true}},
  4270  	},
  4271  
  4272  	{
  4273  		// 10 scale + 1 scale = 27 scale
  4274  		Query:    "select 1.0000000000 / 3.0 = 0.333333333333333333333333333;",
  4275  		Expected: []sql.Row{{true}},
  4276  	},
  4277  	{
  4278  		// 10 scale + 10 scale = 36 scale
  4279  		Query:    "select 1.0000000000 / 3.0000000000 = 0.333333333333333333333333333333333333;",
  4280  		Expected: []sql.Row{{true}},
  4281  	},
  4282  
  4283  	// check that decimal internal precision is preserved in casts
  4284  	{
  4285  		// 0 scale + 0 scale = 9 scale
  4286  		Query:    "select cast(1 / 3 as decimal(65,30));",
  4287  		Expected: []sql.Row{{"0.333333333000000000000000000000"}},
  4288  	},
  4289  	{
  4290  		// 0 scale + 1 scale = 9 scale
  4291  		Query:    "select cast(1 / 3.0 as decimal(65,30));",
  4292  		Expected: []sql.Row{{"0.333333333000000000000000000000"}},
  4293  	},
  4294  	{
  4295  		// 0 scale + 6 scale = 18 scale
  4296  		Query:    "select cast(1 / 3.000000 as decimal(65,30));",
  4297  		Expected: []sql.Row{{"0.333333333333333333000000000000"}},
  4298  	},
  4299  	{
  4300  		// 0 scale + 15 scale = 27 scale
  4301  		Query:    "select cast(1 / 3.000000000000000 as decimal(65,30));",
  4302  		Expected: []sql.Row{{"0.333333333333333333333333333000"}},
  4303  	},
  4304  	{
  4305  		// 0 scale + 24 scale = 36 scale
  4306  		Query:    "select cast(1 / 3.000000000000000000000000 as decimal(65,30));",
  4307  		Expected: []sql.Row{{"0.333333333333333333333333333333"}},
  4308  	},
  4309  
  4310  	{
  4311  		Query:    "select 0.05 % 0.024;",
  4312  		Expected: []sql.Row{{"0.002"}},
  4313  	},
  4314  	{
  4315  		Query:    "select 0.0500 % 0.05;",
  4316  		Expected: []sql.Row{{"0.0000"}},
  4317  	},
  4318  	{
  4319  		Query:    "select 0.05 % 4;",
  4320  		Expected: []sql.Row{{"0.05"}},
  4321  	},
  4322  	{
  4323  		Query:    "select 2.6 & -1.3;",
  4324  		Expected: []sql.Row{{uint64(3)}},
  4325  	},
  4326  	{
  4327  		Query:    "select -1.5 & -3.3;",
  4328  		Expected: []sql.Row{{uint64(18446744073709551612)}},
  4329  	},
  4330  	{
  4331  		Query:    "select -1.7 & 0.5;",
  4332  		Expected: []sql.Row{{uint64(0)}},
  4333  	},
  4334  	{
  4335  		Query:    "select -1.7 & 1.5;",
  4336  		Expected: []sql.Row{{uint64(2)}},
  4337  	},
  4338  	{
  4339  		Query:    "SELECT '127' | '128', '128' << 2;",
  4340  		Expected: []sql.Row{{uint64(255), uint64(512)}},
  4341  	},
  4342  	{
  4343  		Query:    "SELECT X'7F' | X'80', X'80' << 2;",
  4344  		Expected: []sql.Row{{uint64(255), uint64(512)}},
  4345  	},
  4346  	{
  4347  		Query:    "SELECT X'40' | X'01', b'11110001' & b'01001111';",
  4348  		Expected: []sql.Row{{uint64(65), uint64(65)}},
  4349  	},
  4350  	{
  4351  		Query:    "SELECT 0x12345;",
  4352  		Expected: []sql.Row{{[]uint8{0x1, 0x23, 0x45}}},
  4353  	},
  4354  	{
  4355  		Query:    "SELECT i FROM mytable WHERE i BETWEEN 1 AND 2",
  4356  		Expected: []sql.Row{{int64(1)}, {int64(2)}},
  4357  	},
  4358  	{
  4359  		Query:    "SELECT i FROM mytable WHERE i NOT BETWEEN 1 AND 2",
  4360  		Expected: []sql.Row{{int64(3)}},
  4361  	},
  4362  	{
  4363  		Query:    "SELECT 2 BETWEEN NULL AND 2",
  4364  		Expected: []sql.Row{{nil}},
  4365  	},
  4366  	{
  4367  		Query:    "SELECT NOT 2 BETWEEN NULL AND 2",
  4368  		Expected: []sql.Row{{nil}},
  4369  	},
  4370  	{
  4371  		Query: "SELECT DISTINCT CAST(i AS DECIMAL) from mytable;",
  4372  		Expected: []sql.Row{
  4373  			{"1"},
  4374  			{"2"},
  4375  			{"3"},
  4376  		},
  4377  	},
  4378  	{
  4379  		Query: "SELECT SUM( DISTINCT CAST(i AS DECIMAL)) from mytable;",
  4380  		Expected: []sql.Row{
  4381  			{"6"},
  4382  		},
  4383  	},
  4384  	{
  4385  		Query: "SELECT DISTINCT * FROM (values row(7,31,27), row(79,17,38), row(78,59,26)) a (col0, col1, col2) WHERE ( + col1 + + col2 ) NOT BETWEEN NULL AND col1",
  4386  		Expected: []sql.Row{{7, 31, 27},
  4387  			{79, 17, 38},
  4388  			{78, 59, 26}},
  4389  	},
  4390  	{
  4391  		Query: "SELECT + tab0.col2 * - tab0.col1 FROM (values row(89,91,82), row(35,97,1), row(24,86,33)) tab0 (col0, col1, col2) " +
  4392  			"WHERE NOT ( + col2 * + col2 * col1 ) BETWEEN col1 * tab0.col0 AND NULL",
  4393  		Expected: []sql.Row{{-97}},
  4394  	},
  4395  	{
  4396  		Query:    "SELECT id FROM typestable WHERE ti > '2019-12-31'",
  4397  		Expected: []sql.Row{{int64(1)}},
  4398  	},
  4399  	{
  4400  		Query:    "SELECT id FROM typestable WHERE da = '2019-12-31'",
  4401  		Expected: []sql.Row{{int64(1)}},
  4402  	},
  4403  	{
  4404  		Query:    "SELECT id FROM typestable WHERE ti < '2019-12-31'",
  4405  		Expected: nil,
  4406  	},
  4407  	{
  4408  		Query:    "SELECT id FROM typestable WHERE da < '2019-12-31'",
  4409  		Expected: nil,
  4410  	},
  4411  	{
  4412  		Query:    "SELECT id FROM typestable WHERE ti > date_add('2019-12-30', INTERVAL 1 day)",
  4413  		Expected: []sql.Row{{int64(1)}},
  4414  	},
  4415  	{
  4416  		Query:    "SELECT id FROM typestable WHERE da > date_add('2019-12-30', INTERVAL 1 DAY)",
  4417  		Expected: nil,
  4418  	},
  4419  	{
  4420  		Query:    "SELECT id FROM typestable WHERE da >= date_add('2019-12-30', INTERVAL 1 DAY)",
  4421  		Expected: []sql.Row{{int64(1)}},
  4422  	},
  4423  	{
  4424  		Query:    "SELECT id FROM typestable WHERE ti < date_add('2019-12-30', INTERVAL 1 DAY)",
  4425  		Expected: nil,
  4426  	},
  4427  	{
  4428  		Query:    "SELECT id FROM typestable WHERE da < date_add('2019-12-30', INTERVAL 1 DAY)",
  4429  		Expected: nil,
  4430  	},
  4431  	{
  4432  		Query:    "SELECT id FROM typestable WHERE ti > date_sub('2020-01-01', INTERVAL 1 DAY)",
  4433  		Expected: []sql.Row{{int64(1)}},
  4434  	},
  4435  	{
  4436  		Query:    "SELECT id FROM typestable WHERE da > date_sub('2020-01-01', INTERVAL 1 DAY)",
  4437  		Expected: nil,
  4438  	},
  4439  	{
  4440  		Query:    "SELECT id FROM typestable WHERE da >= date_sub('2020-01-01', INTERVAL 1 DAY)",
  4441  		Expected: []sql.Row{{int64(1)}},
  4442  	},
  4443  	{
  4444  		Query:    "SELECT id FROM typestable WHERE ti < date_sub('2020-01-01', INTERVAL 1 DAY)",
  4445  		Expected: nil,
  4446  	},
  4447  	{
  4448  		Query:    "SELECT id FROM typestable WHERE da < date_sub('2020-01-01', INTERVAL 1 DAY)",
  4449  		Expected: nil,
  4450  	},
  4451  	{
  4452  		Query:    "SELECT id FROM typestable WHERE da >= subdate('2020-01-01', INTERVAL 1 DAY)",
  4453  		Expected: []sql.Row{{int64(1)}},
  4454  	},
  4455  	{
  4456  		Query:    "SELECT id FROM typestable WHERE da >= subdate('2020-01-01', 1)",
  4457  		Expected: []sql.Row{{int64(1)}},
  4458  	},
  4459  	{
  4460  		Query:    "SELECT subdate(da, i32) from typestable;",
  4461  		Expected: []sql.Row{{time.Date(2019, time.December, 27, 0, 0, 0, 0, time.UTC)}},
  4462  	},
  4463  	{
  4464  		Query:    "SELECT subdate(da, concat(u32)) from typestable;",
  4465  		Expected: []sql.Row{{time.Date(2019, time.December, 23, 0, 0, 0, 0, time.UTC)}},
  4466  	},
  4467  	{
  4468  		Query:    "SELECT subdate(da, f32/10) from typestable;",
  4469  		Expected: []sql.Row{{time.Date(2019, time.December, 30, 0, 0, 0, 0, time.UTC)}},
  4470  	},
  4471  	{
  4472  		Query: `SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM othertable) othertable_one) othertable_two) othertable_three WHERE s2 = 'first'`,
  4473  		Expected: []sql.Row{
  4474  			{"first", int64(3)},
  4475  		},
  4476  	},
  4477  	{
  4478  		Query: `SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM othertable WHERE s2 = 'first') othertable_one) othertable_two) othertable_three WHERE s2 = 'first'`,
  4479  		Expected: []sql.Row{
  4480  			{"first", int64(3)},
  4481  		},
  4482  	},
  4483  	{
  4484  		Query: `SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM othertable WHERE i2 = 3) othertable_one) othertable_two) othertable_three WHERE s2 = 'first'`,
  4485  		Expected: []sql.Row{
  4486  			{"first", int64(3)},
  4487  		},
  4488  	},
  4489  	{
  4490  		Query:    `SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM othertable WHERE s2 = 'second') othertable_one) othertable_two) othertable_three WHERE s2 = 'first'`,
  4491  		Expected: nil,
  4492  	},
  4493  	{
  4494  		Query: "SELECT i,v from stringandtable WHERE i",
  4495  		Expected: []sql.Row{
  4496  			{int64(1), "1"},
  4497  			{int64(2), ""},
  4498  			{int64(3), "true"},
  4499  			{int64(4), "false"},
  4500  			{int64(5), nil},
  4501  		},
  4502  	},
  4503  	{
  4504  		Query: "SELECT i,v from stringandtable WHERE i AND i",
  4505  		Expected: []sql.Row{
  4506  			{int64(1), "1"},
  4507  			{int64(2), ""},
  4508  			{int64(3), "true"},
  4509  			{int64(4), "false"},
  4510  			{int64(5), nil},
  4511  		},
  4512  	},
  4513  	{
  4514  		Query: "SELECT i,v from stringandtable WHERE i OR i",
  4515  		Expected: []sql.Row{
  4516  			{int64(1), "1"},
  4517  			{int64(2), ""},
  4518  			{int64(3), "true"},
  4519  			{int64(4), "false"},
  4520  			{int64(5), nil},
  4521  		},
  4522  	},
  4523  	{
  4524  		Query:    "SELECT i,v from stringandtable WHERE NOT i",
  4525  		Expected: []sql.Row{{int64(0), "0"}},
  4526  	},
  4527  	{
  4528  		Query:    "SELECT i,v from stringandtable WHERE NOT i AND NOT i",
  4529  		Expected: []sql.Row{{int64(0), "0"}},
  4530  	},
  4531  	{
  4532  		Query:    "SELECT i,v from stringandtable WHERE NOT i OR NOT i",
  4533  		Expected: []sql.Row{{int64(0), "0"}},
  4534  	},
  4535  	{
  4536  		Query: "SELECT i,v from stringandtable WHERE i OR NOT i",
  4537  		Expected: []sql.Row{
  4538  			{int64(0), "0"},
  4539  			{int64(1), "1"},
  4540  			{int64(2), ""},
  4541  			{int64(3), "true"},
  4542  			{int64(4), "false"},
  4543  			{int64(5), nil},
  4544  		},
  4545  	},
  4546  	{
  4547  		Query:    "SELECT i,v from stringandtable WHERE i XOR i",
  4548  		Expected: []sql.Row{},
  4549  	},
  4550  	{
  4551  		Query:    "SELECT i,v from stringandtable WHERE NOT i XOR NOT i",
  4552  		Expected: []sql.Row{},
  4553  	},
  4554  	{
  4555  		Query: "SELECT i,v from stringandtable WHERE i XOR NOT i",
  4556  		Expected: []sql.Row{
  4557  			{int64(0), "0"},
  4558  			{int64(1), "1"},
  4559  			{int64(2), ""},
  4560  			{int64(3), "true"},
  4561  			{int64(4), "false"},
  4562  			{int64(5), nil},
  4563  		},
  4564  	},
  4565  	{
  4566  		Query: "SELECT i,v from stringandtable WHERE i XOR i XOR i",
  4567  		Expected: []sql.Row{
  4568  			{int64(1), "1"},
  4569  			{int64(2), ""},
  4570  			{int64(3), "true"},
  4571  			{int64(4), "false"},
  4572  			{int64(5), nil},
  4573  		},
  4574  	},
  4575  	{
  4576  		Query:    "SELECT i,v from stringandtable WHERE v",
  4577  		Expected: []sql.Row{{int64(1), "1"}, {nil, "2"}},
  4578  	},
  4579  	{
  4580  		Query:    "SELECT i,v from stringandtable WHERE v AND v",
  4581  		Expected: []sql.Row{{int64(1), "1"}, {nil, "2"}},
  4582  	},
  4583  	{
  4584  		Query:    "SELECT i,v from stringandtable WHERE v OR v",
  4585  		Expected: []sql.Row{{int64(1), "1"}, {nil, "2"}},
  4586  	},
  4587  	{
  4588  		Query: "SELECT i,v from stringandtable WHERE NOT v",
  4589  		Expected: []sql.Row{
  4590  			{int64(0), "0"},
  4591  			{int64(2), ""},
  4592  			{int64(3), "true"},
  4593  			{int64(4), "false"},
  4594  		},
  4595  	},
  4596  	{
  4597  		Query: "SELECT i,v from stringandtable WHERE NOT v AND NOT v",
  4598  		Expected: []sql.Row{
  4599  			{int64(0), "0"},
  4600  			{int64(2), ""},
  4601  			{int64(3), "true"},
  4602  			{int64(4), "false"},
  4603  		},
  4604  	},
  4605  	{
  4606  		Query: "SELECT i,v from stringandtable WHERE NOT v OR NOT v",
  4607  		Expected: []sql.Row{
  4608  			{int64(0), "0"},
  4609  			{int64(2), ""},
  4610  			{int64(3), "true"},
  4611  			{int64(4), "false"},
  4612  		},
  4613  	},
  4614  	{
  4615  		Query: "SELECT i,v from stringandtable WHERE v OR NOT v",
  4616  		Expected: []sql.Row{
  4617  			{int64(0), "0"},
  4618  			{int64(1), "1"},
  4619  			{int64(2), ""},
  4620  			{int64(3), "true"},
  4621  			{int64(4), "false"},
  4622  			{nil, "2"},
  4623  		},
  4624  	},
  4625  	{
  4626  		Query:    "SELECT i,v from stringandtable WHERE v XOR v",
  4627  		Expected: []sql.Row{},
  4628  	},
  4629  	{
  4630  		Query:    "SELECT i,v from stringandtable WHERE NOT v XOR NOT v",
  4631  		Expected: []sql.Row{},
  4632  	},
  4633  	{
  4634  		Query: "SELECT i,v from stringandtable WHERE v XOR NOT v",
  4635  		Expected: []sql.Row{
  4636  			{int64(0), "0"},
  4637  			{int64(1), "1"},
  4638  			{int64(2), ""},
  4639  			{int64(3), "true"},
  4640  			{int64(4), "false"},
  4641  			{nil, "2"},
  4642  		},
  4643  	},
  4644  	{
  4645  		Query: `select row_number() over (order by i desc), mytable.i as i2
  4646  				from mytable join othertable on i = i2 order by 1`,
  4647  		Expected: []sql.Row{
  4648  			{1, 3},
  4649  			{2, 2},
  4650  			{3, 1},
  4651  		},
  4652  	},
  4653  	{
  4654  		Query: `select row_number() over (order by i desc), mytable.i as i2
  4655  				from mytable join othertable on i = i2
  4656  				where mytable.i = 3 order by 1`,
  4657  		Expected: []sql.Row{
  4658  			{1, 3},
  4659  		},
  4660  	},
  4661  	{
  4662  		Query: `select pk,
  4663  					   row_number() over (order by pk desc),
  4664  					   sum(v1) over (partition by v2 order by pk),
  4665  					   percent_rank() over(partition by v2 order by pk)
  4666  				from one_pk_three_idx order by pk`,
  4667  		Expected: []sql.Row{
  4668  			{0, 8, float64(0), float64(0)},
  4669  			{1, 7, float64(0), float64(1) / float64(3)},
  4670  			{2, 6, float64(0), float64(0)},
  4671  			{3, 5, float64(0), float64(0)},
  4672  			{4, 4, float64(1), float64(2) / float64(3)},
  4673  			{5, 3, float64(3), float64(1)},
  4674  			{6, 2, float64(3), float64(0)},
  4675  			{7, 1, float64(4), float64(0)},
  4676  		},
  4677  	},
  4678  	{
  4679  		Query: `select pk,
  4680  	                  percent_rank() over(partition by v2 order by pk),
  4681  	                  dense_rank() over(partition by v2 order by pk),
  4682  	                  rank() over(partition by v2 order by pk)
  4683  				from one_pk_three_idx order by pk`,
  4684  		Expected: []sql.Row{
  4685  			{0, float64(0), uint64(1), uint64(1)},
  4686  			{1, float64(1) / float64(3), uint64(2), uint64(2)},
  4687  			{2, float64(0), uint64(1), uint64(1)},
  4688  			{3, float64(0), uint64(1), uint64(1)},
  4689  			{4, float64(2) / float64(3), uint64(3), uint64(3)},
  4690  			{5, float64(1), uint64(4), uint64(4)},
  4691  			{6, float64(0), uint64(1), uint64(1)},
  4692  			{7, float64(0), uint64(1), uint64(1)},
  4693  		},
  4694  	},
  4695  	{
  4696  		SkipPrepared: true,
  4697  		Query: `select pk,
  4698  					   first_value(pk) over (order by pk desc),
  4699  					   lag(pk, 1) over (order by pk desc),
  4700  					   count(pk) over(partition by v1 order by pk),
  4701  					   max(pk) over(partition by v1 order by pk desc),
  4702  					   avg(v2) over (partition by v1 order by pk)
  4703  				from one_pk_three_idx order by pk`,
  4704  		Expected: []sql.Row{
  4705  			{0, 7, 1, 1, 3, float64(0)},
  4706  			{1, 7, 2, 2, 3, float64(0)},
  4707  			{2, 7, 3, 3, 3, float64(1) / float64(3)},
  4708  			{3, 7, 4, 4, 3, float64(3) / float64(4)},
  4709  			{4, 7, 5, 1, 4, float64(0)},
  4710  			{5, 7, 6, 1, 5, float64(0)},
  4711  			{6, 7, 7, 1, 6, float64(3)},
  4712  			{7, 7, nil, 1, 7, float64(4)},
  4713  		},
  4714  	},
  4715  	{
  4716  		Query: `SELECT s2, i2 FROM othertable WHERE s2 >= "first" AND i2 >= 2 ORDER BY 1`,
  4717  		Expected: []sql.Row{
  4718  			{"first", int64(3)},
  4719  			{"second", int64(2)},
  4720  		},
  4721  	},
  4722  	{
  4723  		Query: `SELECT s2, i2 FROM othertable WHERE "first" <= s2 AND 2 <= i2 ORDER BY 1`,
  4724  		Expected: []sql.Row{
  4725  			{"first", int64(3)},
  4726  			{"second", int64(2)},
  4727  		},
  4728  	},
  4729  	{
  4730  		Query: `SELECT s2, i2 FROM othertable WHERE s2 <= "second" AND i2 <= 2 ORDER BY 1`,
  4731  		Expected: []sql.Row{
  4732  			{"second", int64(2)},
  4733  		},
  4734  	},
  4735  	{
  4736  		Query: `SELECT s2, i2 FROM othertable WHERE "second" >= s2 AND 2 >= i2 ORDER BY 1`,
  4737  		Expected: []sql.Row{
  4738  			{"second", int64(2)},
  4739  		},
  4740  	},
  4741  	{
  4742  		Query: "SELECT substring(s2, 1), substring(s2, 2), substring(s2, 3) FROM othertable ORDER BY i2",
  4743  		Expected: []sql.Row{
  4744  			{"third", "hird", "ird"},
  4745  			{"second", "econd", "cond"},
  4746  			{"first", "irst", "rst"},
  4747  		},
  4748  	},
  4749  	{
  4750  		Query: `SELECT substring("first", 1), substring("second", 2), substring("third", 3)`,
  4751  		Expected: []sql.Row{
  4752  			{"first", "econd", "ird"},
  4753  		},
  4754  	},
  4755  	{
  4756  		Query: "SELECT substring(s2, -1), substring(s2, -2), substring(s2, -3) FROM othertable ORDER BY i2",
  4757  		Expected: []sql.Row{
  4758  			{"d", "rd", "ird"},
  4759  			{"d", "nd", "ond"},
  4760  			{"t", "st", "rst"},
  4761  		},
  4762  	},
  4763  	{
  4764  		Query: `SELECT substring("first", -1), substring("second", -2), substring("third", -3)`,
  4765  		Expected: []sql.Row{
  4766  			{"t", "nd", "ird"},
  4767  		},
  4768  	},
  4769  	{
  4770  		Query: `SELECT COUNT(*) AS cnt, fi FROM (
  4771  			SELECT tbl.s AS fi
  4772  			FROM mytable tbl
  4773  		) t
  4774  		GROUP BY fi`,
  4775  		Expected: []sql.Row{
  4776  			{int64(1), "first row"},
  4777  			{int64(1), "second row"},
  4778  			{int64(1), "third row"},
  4779  		},
  4780  	},
  4781  	{
  4782  		Query: `SELECT fi, COUNT(*) FROM (
  4783  			SELECT tbl.s AS fi
  4784  			FROM mytable tbl
  4785  		) t
  4786  		GROUP BY fi
  4787  		ORDER BY COUNT(*) ASC, fi`,
  4788  		Expected: []sql.Row{
  4789  			{"first row", int64(1)},
  4790  			{"second row", int64(1)},
  4791  			{"third row", int64(1)},
  4792  		},
  4793  	},
  4794  	{
  4795  		Query: `SELECT COUNT(*), fi  FROM (
  4796  			SELECT tbl.s AS fi
  4797  			FROM mytable tbl
  4798  		) t
  4799  		GROUP BY fi
  4800  		ORDER BY COUNT(*) ASC, fi`,
  4801  		Expected: []sql.Row{
  4802  			{int64(1), "first row"},
  4803  			{int64(1), "second row"},
  4804  			{int64(1), "third row"},
  4805  		},
  4806  	},
  4807  	{
  4808  		Query: `SELECT COUNT(*) AS cnt, fi FROM (
  4809  			SELECT tbl.s AS fi
  4810  			FROM mytable tbl
  4811  		) t
  4812  		GROUP BY 2`,
  4813  		Expected: []sql.Row{
  4814  			{int64(1), "first row"},
  4815  			{int64(1), "second row"},
  4816  			{int64(1), "third row"},
  4817  		},
  4818  	},
  4819  	{
  4820  		Query: `SELECT COUNT(*) AS cnt, s AS fi FROM mytable GROUP BY fi`,
  4821  		Expected: []sql.Row{
  4822  			{int64(1), "first row"},
  4823  			{int64(1), "second row"},
  4824  			{int64(1), "third row"},
  4825  		},
  4826  	},
  4827  	{
  4828  		Query: `SELECT COUNT(*) AS cnt, s AS fi FROM mytable GROUP BY 2`,
  4829  		Expected: []sql.Row{
  4830  			{int64(1), "first row"},
  4831  			{int64(1), "second row"},
  4832  			{int64(1), "third row"},
  4833  		},
  4834  	},
  4835  	{
  4836  		Query: "SELECT CAST(-3 AS UNSIGNED) FROM mytable",
  4837  		Expected: []sql.Row{
  4838  			{uint64(18446744073709551613)},
  4839  			{uint64(18446744073709551613)},
  4840  			{uint64(18446744073709551613)},
  4841  		},
  4842  	},
  4843  	{
  4844  		Query:    "SELECT CAST(-3 AS DOUBLE) FROM dual",
  4845  		Expected: []sql.Row{{-3.0}},
  4846  	},
  4847  	{
  4848  		Query:    `SELECT CONVERT("-3.9876", FLOAT) FROM dual`,
  4849  		Expected: []sql.Row{{float32(-3.9876)}},
  4850  	},
  4851  	{
  4852  		Query:    "SELECT CAST(10.56789 as CHAR(3));",
  4853  		Expected: []sql.Row{{"10."}},
  4854  	},
  4855  	{
  4856  		Query:    "SELECT CAST(10.56789 as CHAR(30));",
  4857  		Expected: []sql.Row{{"10.56789"}},
  4858  	},
  4859  	{
  4860  		Query:    "SELECT CAST('abcdef' as BINARY(30));",
  4861  		Expected: []sql.Row{{[]byte("abcdef")}},
  4862  	},
  4863  	{
  4864  		Query:    `SELECT CONVERT(10.12345, DECIMAL(4,2))`,
  4865  		Expected: []sql.Row{{"10.12"}},
  4866  	},
  4867  	{
  4868  		Query:    `SELECT CONVERT(1234567893.1234567893, DECIMAL(20,10))`,
  4869  		Expected: []sql.Row{{"1234567893.1234567893"}},
  4870  	},
  4871  	{
  4872  		Query:    `SELECT CONVERT(10, DECIMAL(4,2))`,
  4873  		Expected: []sql.Row{{"10.00"}},
  4874  	},
  4875  	{
  4876  		Query: "SELECT CONVERT(-3, UNSIGNED) FROM mytable",
  4877  		Expected: []sql.Row{
  4878  			{uint64(18446744073709551613)},
  4879  			{uint64(18446744073709551613)},
  4880  			{uint64(18446744073709551613)},
  4881  		},
  4882  	},
  4883  	{
  4884  		Query:    "select 0 in (1 / 1000), 0 in (1 / 1000, 0), 0.001 in (1 / 1000, 0), 0.0001 in (1 / 1000, 0);",
  4885  		Expected: []sql.Row{{false, true, true, false}},
  4886  	},
  4887  	{
  4888  		Query:    "select 0 in (0.01 * 0.30), 1 in (1.0 * 1)",
  4889  		Expected: []sql.Row{{false, true}},
  4890  	},
  4891  	{
  4892  		Query: "SELECT MAX(CAST(NULL AS DECIMAL)) * 82",
  4893  		Expected: []sql.Row{
  4894  			{nil},
  4895  		},
  4896  	},
  4897  	{
  4898  		Query: "SELECT '3' > 2 FROM tabletest",
  4899  		Expected: []sql.Row{
  4900  			{true},
  4901  			{true},
  4902  			{true},
  4903  		},
  4904  	},
  4905  	{
  4906  		Query: "SELECT s > 2 FROM tabletest",
  4907  		Expected: []sql.Row{
  4908  			{false},
  4909  			{false},
  4910  			{false},
  4911  		},
  4912  	},
  4913  	{
  4914  		Query:    "SELECT * FROM tabletest WHERE s > 0",
  4915  		Expected: nil,
  4916  	},
  4917  	{
  4918  		Query: "SELECT * FROM tabletest WHERE s = 0",
  4919  		Expected: []sql.Row{
  4920  			{int64(1), "first row"},
  4921  			{int64(2), "second row"},
  4922  			{int64(3), "third row"},
  4923  		},
  4924  	},
  4925  	{
  4926  		Query: "SELECT * FROM tabletest WHERE s = 'first row'",
  4927  		Expected: []sql.Row{
  4928  			{int64(1), "first row"},
  4929  		},
  4930  	},
  4931  	{
  4932  		Query: "SELECT s FROM mytable WHERE i IN (1, 2, 5)",
  4933  		Expected: []sql.Row{
  4934  			{"first row"},
  4935  			{"second row"},
  4936  		},
  4937  	},
  4938  	{
  4939  		Query: "SELECT s FROM mytable WHERE i NOT IN (1, 2, 5)",
  4940  		Expected: []sql.Row{
  4941  			{"third row"},
  4942  		},
  4943  	},
  4944  	{
  4945  		Query: "SELECT 1 + 2",
  4946  		Expected: []sql.Row{
  4947  			{int64(3)},
  4948  		},
  4949  	},
  4950  	{
  4951  		Query:    `SELECT i AS foo FROM mytable HAVING foo NOT IN (1, 2, 5)`,
  4952  		Expected: []sql.Row{{int64(3)}},
  4953  	},
  4954  	{
  4955  		Query:    `SELECT SUM(i) FROM mytable`,
  4956  		Expected: []sql.Row{{float64(6)}},
  4957  	},
  4958  	{
  4959  		Query: `SELECT i AS foo FROM mytable ORDER BY i DESC`,
  4960  		Expected: []sql.Row{
  4961  			{int64(3)},
  4962  			{int64(2)},
  4963  			{int64(1)},
  4964  		},
  4965  	},
  4966  	{
  4967  		Query: `SELECT COUNT(*) c, i AS foo FROM mytable GROUP BY i ORDER BY i DESC`,
  4968  		Expected: []sql.Row{
  4969  			{int64(1), int64(3)},
  4970  			{int64(1), int64(2)},
  4971  			{int64(1), int64(1)},
  4972  		},
  4973  	},
  4974  	{
  4975  		Query: `SELECT COUNT(*) c, i AS foo FROM mytable GROUP BY 2 ORDER BY 2 DESC`,
  4976  		Expected: []sql.Row{
  4977  			{int64(1), int64(3)},
  4978  			{int64(1), int64(2)},
  4979  			{int64(1), int64(1)},
  4980  		},
  4981  	},
  4982  	{
  4983  		Query: `SELECT COUNT(*) c, i AS foo FROM mytable GROUP BY i ORDER BY foo DESC`,
  4984  		Expected: []sql.Row{
  4985  			{int64(1), int64(3)},
  4986  			{int64(1), int64(2)},
  4987  			{int64(1), int64(1)},
  4988  		},
  4989  	},
  4990  	{
  4991  		Query: `SELECT COUNT(*) c, i AS foo FROM mytable GROUP BY 2 ORDER BY foo DESC`,
  4992  		Expected: []sql.Row{
  4993  			{int64(1), int64(3)},
  4994  			{int64(1), int64(2)},
  4995  			{int64(1), int64(1)},
  4996  		},
  4997  	},
  4998  	{
  4999  		Query: `SELECT COUNT(*) c, i AS i FROM mytable GROUP BY 2`,
  5000  		Expected: []sql.Row{
  5001  			{int64(1), int64(3)},
  5002  			{int64(1), int64(2)},
  5003  			{int64(1), int64(1)},
  5004  		},
  5005  	},
  5006  	{
  5007  		Query: `SELECT i AS i FROM mytable GROUP BY 1`,
  5008  		Expected: []sql.Row{
  5009  			{int64(3)},
  5010  			{int64(2)},
  5011  			{int64(1)},
  5012  		},
  5013  	},
  5014  	{
  5015  		Query: `SELECT CONCAT("a", "b", "c")`,
  5016  		Expected: []sql.Row{
  5017  			{string("abc")},
  5018  		},
  5019  	},
  5020  	{
  5021  		Query: `SELECT COALESCE(NULL, NULL, NULL, 'example', NULL, 1234567890)`,
  5022  		Expected: []sql.Row{
  5023  			{string("example")},
  5024  		},
  5025  	},
  5026  	{
  5027  		Query: `SELECT COALESCE(NULL, NULL, NULL, COALESCE(NULL, 1234567890))`,
  5028  		Expected: []sql.Row{
  5029  			{int32(1234567890)},
  5030  		},
  5031  	},
  5032  	{
  5033  		Query:    "SELECT COALESCE (NULL, NULL)",
  5034  		Expected: []sql.Row{{nil}},
  5035  		ExpectedColumns: []*sql.Column{
  5036  			{
  5037  				Name: "COALESCE (NULL, NULL)",
  5038  				Type: types.Null,
  5039  			},
  5040  		},
  5041  	},
  5042  	{
  5043  		Query: "SELECT concat(s, i) FROM mytable",
  5044  		Expected: []sql.Row{
  5045  			{string("first row1")},
  5046  			{string("second row2")},
  5047  			{string("third row3")},
  5048  		},
  5049  	},
  5050  	{
  5051  		Query: "SELECT version()",
  5052  		Expected: []sql.Row{
  5053  			{string("8.0.11")},
  5054  		},
  5055  	},
  5056  	{
  5057  		Query: `SELECT RAND(100)`,
  5058  		Expected: []sql.Row{
  5059  			{float64(0.8165026937796166)},
  5060  		},
  5061  	},
  5062  	{
  5063  		Query:    `SELECT RAND(i) from mytable order by i`,
  5064  		Expected: []sql.Row{{0.6046602879796196}, {0.16729663442585624}, {0.7199826688373036}},
  5065  	},
  5066  	{
  5067  		Query: `SELECT RAND(100) = RAND(100)`,
  5068  		Expected: []sql.Row{
  5069  			{true},
  5070  		},
  5071  	},
  5072  	{
  5073  		Query: `SELECT RAND() = RAND()`,
  5074  		Expected: []sql.Row{
  5075  			{false},
  5076  		},
  5077  	},
  5078  	{
  5079  		Query: "SELECT MOD(i, 2) from mytable order by i limit 1",
  5080  		Expected: []sql.Row{
  5081  			{"1"},
  5082  		},
  5083  	},
  5084  	{
  5085  		Query: "SELECT SIN(i) from mytable order by i limit 1",
  5086  		Expected: []sql.Row{
  5087  			{0.8414709848078965},
  5088  		},
  5089  	},
  5090  	{
  5091  		Query: "SELECT COS(i) from mytable order by i limit 1",
  5092  		Expected: []sql.Row{
  5093  			{0.5403023058681398},
  5094  		},
  5095  	},
  5096  	{
  5097  		Query: "SELECT TAN(i) from mytable order by i limit 1",
  5098  		Expected: []sql.Row{
  5099  			{1.557407724654902},
  5100  		},
  5101  	},
  5102  	{
  5103  		Query: "SELECT ASIN(i) from mytable order by i limit 1",
  5104  		Expected: []sql.Row{
  5105  			{1.5707963267948966},
  5106  		},
  5107  	},
  5108  	{
  5109  		Query: "SELECT ACOS(i) from mytable order by i limit 1",
  5110  		Expected: []sql.Row{
  5111  			{0.0},
  5112  		},
  5113  	},
  5114  	{
  5115  		Query: "SELECT ATAN(i) from mytable order by i limit 1",
  5116  		Expected: []sql.Row{
  5117  			{0.7853981633974483},
  5118  		},
  5119  	},
  5120  	{
  5121  		Query: "SELECT COT(i) from mytable order by i limit 1",
  5122  		Expected: []sql.Row{
  5123  			{0.6420926159343308},
  5124  		},
  5125  	},
  5126  	{
  5127  		Query: "SELECT DEGREES(i) from mytable order by i limit 1",
  5128  		Expected: []sql.Row{
  5129  			{57.29577951308232},
  5130  		},
  5131  	},
  5132  	{
  5133  		Query: "SELECT RADIANS(i) from mytable order by i limit 1",
  5134  		Expected: []sql.Row{
  5135  			{0.017453292519943295},
  5136  		},
  5137  	},
  5138  	{
  5139  		Query: "SELECT CRC32(i) from mytable order by i limit 1",
  5140  		Expected: []sql.Row{
  5141  			{uint64(0x83dcefb7)},
  5142  		},
  5143  	},
  5144  	{
  5145  		Query: "SELECT SIGN(i) from mytable order by i limit 1",
  5146  		Expected: []sql.Row{
  5147  			{1},
  5148  		},
  5149  	},
  5150  	{
  5151  		Query: "SELECT ASCII(s) from mytable order by i limit 1",
  5152  		Expected: []sql.Row{
  5153  			{uint64(0x66)},
  5154  		},
  5155  	},
  5156  	{
  5157  		Query: "SELECT HEX(s) from mytable order by i limit 1",
  5158  		Expected: []sql.Row{
  5159  			{"666972737420726F77"},
  5160  		},
  5161  	},
  5162  	{
  5163  		Query: "SELECT UNHEX(s) from mytable order by i limit 1",
  5164  		Expected: []sql.Row{
  5165  			{nil},
  5166  		},
  5167  	},
  5168  	{
  5169  		Query: "SELECT BIN(i) from mytable order by i limit 1",
  5170  		Expected: []sql.Row{
  5171  			{"1"},
  5172  		},
  5173  	},
  5174  	{
  5175  		Query: "SELECT BIT_LENGTH(i) from mytable order by i limit 1",
  5176  		Expected: []sql.Row{
  5177  			{64},
  5178  		},
  5179  	},
  5180  	{
  5181  		Query: "select date_format(datetime_col, '%D') from datetime_table order by 1",
  5182  		Expected: []sql.Row{
  5183  			{"1st"},
  5184  			{"4th"},
  5185  			{"7th"},
  5186  		},
  5187  	},
  5188  	{
  5189  		Query: "select time_format(time_col, '%h%p') from datetime_table order by 1",
  5190  		Expected: []sql.Row{
  5191  			{"03AM"},
  5192  			{"03PM"},
  5193  			{"04AM"},
  5194  		},
  5195  	},
  5196  	{
  5197  		Query: "select from_unixtime(i) from mytable order by 1",
  5198  		Expected: []sql.Row{
  5199  			{time.Unix(1, 0)},
  5200  			{time.Unix(2, 0)},
  5201  			{time.Unix(3, 0)},
  5202  		},
  5203  	},
  5204  	// TODO: add additional tests for other functions. Every function needs an engine test to ensure it works correctly
  5205  	//  with the analyzer.
  5206  	{
  5207  		Query:    "SELECT * FROM mytable WHERE 1 > 5",
  5208  		Expected: nil,
  5209  	},
  5210  	{
  5211  		Query: "SELECT SUM(i) + 1, i FROM mytable GROUP BY i ORDER BY i",
  5212  		Expected: []sql.Row{
  5213  			{float64(2), int64(1)},
  5214  			{float64(3), int64(2)},
  5215  			{float64(4), int64(3)},
  5216  		},
  5217  	},
  5218  	{
  5219  		Query: "SELECT SUM(i) as sum, i FROM mytable GROUP BY i ORDER BY sum ASC",
  5220  		Expected: []sql.Row{
  5221  			{float64(1), int64(1)},
  5222  			{float64(2), int64(2)},
  5223  			{float64(3), int64(3)},
  5224  		},
  5225  	},
  5226  	{
  5227  		Query: "SELECT i, SUM(i) FROM mytable GROUP BY i ORDER BY sum(i) DESC",
  5228  		Expected: []sql.Row{
  5229  			{int64(3), float64(3)},
  5230  			{int64(2), float64(2)},
  5231  			{int64(1), float64(1)},
  5232  		},
  5233  	},
  5234  	{
  5235  		Query: "SELECT i, SUM(i) as b FROM mytable GROUP BY i ORDER BY b DESC",
  5236  		Expected: []sql.Row{
  5237  			{int64(3), float64(3)},
  5238  			{int64(2), float64(2)},
  5239  			{int64(1), float64(1)},
  5240  		},
  5241  	},
  5242  	{
  5243  		Query: "SELECT i, SUM(i) as `sum(i)` FROM mytable GROUP BY i ORDER BY sum(i) DESC",
  5244  		Expected: []sql.Row{
  5245  			{int64(3), float64(3)},
  5246  			{int64(2), float64(2)},
  5247  			{int64(1), float64(1)},
  5248  		},
  5249  	},
  5250  	{
  5251  		Query:    "SELECT i FROM mytable UNION SELECT i+10 FROM mytable;",
  5252  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}, {int64(11)}, {int64(12)}, {int64(13)}},
  5253  	},
  5254  	{
  5255  		Query:    "SELECT i FROM mytable UNION DISTINCT SELECT i+10 FROM mytable;",
  5256  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}, {int64(11)}, {int64(12)}, {int64(13)}},
  5257  	},
  5258  	{
  5259  		Query:    "SELECT i FROM mytable UNION ALL SELECT i FROM mytable;",
  5260  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}, {int64(1)}, {int64(2)}, {int64(3)}},
  5261  	},
  5262  	{
  5263  		Query:    "SELECT i FROM mytable UNION SELECT i FROM mytable;",
  5264  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}},
  5265  	},
  5266  	{
  5267  		Query:    "SELECT i FROM mytable UNION DISTINCT SELECT i FROM mytable;",
  5268  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}},
  5269  	},
  5270  	{
  5271  		Query:    "SELECT i FROM mytable UNION ALL SELECT i FROM mytable UNION DISTINCT SELECT i FROM mytable;",
  5272  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}},
  5273  	},
  5274  	{
  5275  		Query:    "SELECT i FROM mytable UNION SELECT i FROM mytable UNION ALL SELECT i FROM mytable;",
  5276  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}, {int64(1)}, {int64(2)}, {int64(3)}},
  5277  	},
  5278  	{
  5279  		Query: "SELECT i FROM mytable UNION SELECT s FROM mytable;",
  5280  		Expected: []sql.Row{
  5281  			{"1"},
  5282  			{"2"},
  5283  			{"3"},
  5284  			{"first row"},
  5285  			{"second row"},
  5286  			{"third row"},
  5287  		},
  5288  	},
  5289  	{
  5290  		SkipPrepared: true,
  5291  		Query:        "",
  5292  		Expected:     []sql.Row{},
  5293  	},
  5294  	{
  5295  		Query: "/*!40101 SET NAMES " +
  5296  			sql.Collation_Default.CharacterSet().String() +
  5297  			" */",
  5298  		Expected: []sql.Row{
  5299  			{},
  5300  		},
  5301  	},
  5302  	{
  5303  		Query: "SET collation_connection = '" +
  5304  			sql.Collation_Default.String() +
  5305  			"';",
  5306  		Expected: []sql.Row{
  5307  			{},
  5308  		},
  5309  	},
  5310  	{
  5311  		Query:    `SHOW DATABASES`,
  5312  		Expected: []sql.Row{{"mydb"}, {"foo"}, {"information_schema"}, {"mysql"}},
  5313  	},
  5314  	{
  5315  		Query:    `SHOW DATABASES LIKE 'information_schema'`,
  5316  		Expected: []sql.Row{{"information_schema"}},
  5317  	},
  5318  	{
  5319  		Query:    "SHOW DATABASES where `Database` =  'information_schema'",
  5320  		Expected: []sql.Row{{"information_schema"}},
  5321  	},
  5322  	{
  5323  		Query:    `SHOW SCHEMAS`,
  5324  		Expected: []sql.Row{{"mydb"}, {"foo"}, {"information_schema"}, {"mysql"}},
  5325  	},
  5326  	{
  5327  		Query: `SELECT SCHEMA_NAME, DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA`,
  5328  		Expected: []sql.Row{
  5329  			{"information_schema", "utf8mb4", "utf8mb4_0900_bin"},
  5330  			{"mydb", "utf8mb4", "utf8mb4_0900_bin"},
  5331  			{"foo", "utf8mb4", "utf8mb4_0900_bin"},
  5332  		},
  5333  	},
  5334  	{
  5335  		Query: `SELECT s FROM mytable WHERE s LIKE '%d row'`,
  5336  		Expected: []sql.Row{
  5337  			{"second row"},
  5338  			{"third row"},
  5339  		},
  5340  	},
  5341  	{
  5342  		Query:    `SELECT s FROM mytable WHERE s LIKE '%D ROW'`,
  5343  		Expected: []sql.Row{}, // default collation of `utf8mb4_0900_bin` is case-sensitive
  5344  	},
  5345  	{
  5346  		Query: `SELECT SUBSTRING(s, -3, 3) AS s FROM mytable WHERE s LIKE '%d row' GROUP BY 1`,
  5347  		Expected: []sql.Row{
  5348  			{"row"},
  5349  		},
  5350  	},
  5351  	{
  5352  		Query: `SELECT s FROM mytable WHERE s NOT LIKE '%d row'`,
  5353  		Expected: []sql.Row{
  5354  			{"first row"},
  5355  		},
  5356  	},
  5357  	{
  5358  		Query: `SELECT * FROM foo.othertable`,
  5359  		Expected: []sql.Row{
  5360  			{"a", int32(4)},
  5361  			{"b", int32(2)},
  5362  			{"c", int32(0)},
  5363  		},
  5364  	},
  5365  	{
  5366  		Query: `SELECT AVG(23.222000)`,
  5367  		Expected: []sql.Row{
  5368  			{"23.2220000000"},
  5369  		},
  5370  	},
  5371  	{
  5372  		Query: `SELECT AVG("23.222000")`,
  5373  		Expected: []sql.Row{
  5374  			{23.222},
  5375  		},
  5376  	},
  5377  	{
  5378  		Query: `SELECT DATABASE()`,
  5379  		Expected: []sql.Row{
  5380  			{"mydb"},
  5381  		},
  5382  	},
  5383  	{
  5384  		Query: `SELECT USER()`,
  5385  		Expected: []sql.Row{
  5386  			{"root@localhost"},
  5387  		},
  5388  	},
  5389  	{
  5390  		Query: `SELECT CURRENT_USER()`,
  5391  		Expected: []sql.Row{
  5392  			{"root@localhost"},
  5393  		},
  5394  	},
  5395  	{
  5396  		Query: `SELECT CURRENT_USER`,
  5397  		Expected: []sql.Row{
  5398  			{"root@localhost"},
  5399  		},
  5400  		ExpectedColumns: sql.Schema{
  5401  			{
  5402  				Name: "CURRENT_USER",
  5403  				Type: types.LongText,
  5404  			},
  5405  		},
  5406  	},
  5407  	{
  5408  		Query: `SELECT CURRENT_user`,
  5409  		Expected: []sql.Row{
  5410  			{"root@localhost"},
  5411  		},
  5412  		ExpectedColumns: sql.Schema{
  5413  			{
  5414  				Name: "CURRENT_user",
  5415  				Type: types.LongText,
  5416  			},
  5417  		},
  5418  	},
  5419  	{
  5420  		Query: `SHOW VARIABLES`,
  5421  	},
  5422  	{
  5423  		Query: `SHOW VARIABLES LIKE 'gtid_mode'`,
  5424  		Expected: []sql.Row{
  5425  			{"gtid_mode", "OFF"},
  5426  		},
  5427  	},
  5428  	{
  5429  		Query: `SHOW VARIABLES LIKE 'gtid%'`,
  5430  		Expected: []sql.Row{
  5431  			{"gtid_executed", ""},
  5432  			{"gtid_executed_compression_period", int64(0)},
  5433  			{"gtid_mode", "OFF"},
  5434  			{"gtid_next", "AUTOMATIC"},
  5435  			{"gtid_owned", ""},
  5436  			{"gtid_purged", ""},
  5437  		},
  5438  	},
  5439  	{
  5440  		Query: `SHOW VARIABLES WHERE Variable_name = 'version' || variable_name = 'autocommit'`,
  5441  		Expected: []sql.Row{
  5442  			{"autocommit", 1}, {"version", "8.0.11"},
  5443  		},
  5444  	},
  5445  	{
  5446  		Query: `SHOW VARIABLES WHERE Variable_name > 'version' and variable_name like '%_%'`,
  5447  		Expected: []sql.Row{
  5448  			{"version_comment", "Dolt"}, {"version_compile_machine", ""}, {"version_compile_os", ""}, {"version_compile_zlib", ""}, {"wait_timeout", 28800}, {"windowing_use_high_precision", 1},
  5449  		},
  5450  	},
  5451  	{
  5452  		Query: `SHOW VARIABLES WHERE "1" and variable_name = 'autocommit'`,
  5453  		Expected: []sql.Row{
  5454  			{"autocommit", 1},
  5455  		},
  5456  	},
  5457  	{
  5458  		Query:    `SHOW VARIABLES WHERE "0" and variable_name = 'autocommit'`,
  5459  		Expected: []sql.Row{},
  5460  	},
  5461  	{
  5462  		Query:    `SHOW VARIABLES WHERE "abc" and variable_name = 'autocommit'`,
  5463  		Expected: []sql.Row{},
  5464  	},
  5465  	{
  5466  		Query: `SHOW GLOBAL VARIABLES LIKE '%mode'`,
  5467  		Expected: []sql.Row{
  5468  			{"block_encryption_mode", "aes-128-ecb"},
  5469  			{"gtid_mode", "OFF"},
  5470  			{"offline_mode", int64(0)},
  5471  			{"pseudo_slave_mode", int64(0)},
  5472  			{"rbr_exec_mode", "STRICT"},
  5473  			{"sql_mode", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES"},
  5474  			{"ssl_fips_mode", "OFF"},
  5475  		},
  5476  	},
  5477  	{
  5478  		Query:    `SELECT JSON_EXTRACT('"foo"', "$")`,
  5479  		Expected: []sql.Row{{types.MustJSON(`"foo"`)}},
  5480  	},
  5481  	{
  5482  		Query:    `SELECT JSON_UNQUOTE('"foo"')`,
  5483  		Expected: []sql.Row{{"foo"}},
  5484  	},
  5485  	{
  5486  		Query:    `SELECT JSON_UNQUOTE('[1, 2, 3]')`,
  5487  		Expected: []sql.Row{{"[1, 2, 3]"}},
  5488  	},
  5489  	{
  5490  		Query:    `SELECT JSON_UNQUOTE('"\\t\\u0032"')`,
  5491  		Expected: []sql.Row{{"\t2"}},
  5492  	},
  5493  	{
  5494  		Query:    `SELECT JSON_UNQUOTE('"\t\\u0032"')`,
  5495  		Expected: []sql.Row{{"\t2"}},
  5496  	},
  5497  	{
  5498  		Query:    `SELECT JSON_UNQUOTE(JSON_EXTRACT('{"xid":"hello"}', '$.xid')) = "hello"`,
  5499  		Expected: []sql.Row{{true}},
  5500  	},
  5501  	{
  5502  		Query:    `SELECT JSON_EXTRACT('{"xid":"hello"}', '$.xid') = "hello"`,
  5503  		Expected: []sql.Row{{true}},
  5504  	},
  5505  	{
  5506  		Query:    `SELECT JSON_EXTRACT('{"xid":"hello"}', '$.xid') = '"hello"'`,
  5507  		Expected: []sql.Row{{false}},
  5508  	},
  5509  	{
  5510  		Query:    `SELECT JSON_UNQUOTE(JSON_EXTRACT('{"xid":null}', '$.xid'))`,
  5511  		Expected: []sql.Row{{"null"}},
  5512  	},
  5513  	{
  5514  		Query:    `select JSON_EXTRACT('{"id":234}', '$.id')-1;`,
  5515  		Expected: []sql.Row{{float64(233)}},
  5516  	},
  5517  	{
  5518  		Query:    `select JSON_EXTRACT('{"id":234}', '$.id') = 234;`,
  5519  		Expected: []sql.Row{{true}},
  5520  	},
  5521  	{
  5522  		Query:    `select JSON_EXTRACT('{"id":"abc"}', '$.id')-1;`,
  5523  		Expected: []sql.Row{{float64(-1)}},
  5524  	},
  5525  	{
  5526  		Query:    `select JSON_EXTRACT('{"id":{"a": "abc"}}', '$.id')-1;`,
  5527  		Expected: []sql.Row{{float64(-1)}},
  5528  	},
  5529  	{
  5530  		Query:    `SELECT CONNECTION_ID()`,
  5531  		Expected: []sql.Row{{uint32(1)}},
  5532  	},
  5533  	{
  5534  		Query: `SHOW CREATE DATABASE mydb`,
  5535  		Expected: []sql.Row{{
  5536  			"mydb",
  5537  			"CREATE DATABASE `mydb` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin */",
  5538  		}},
  5539  	},
  5540  	{
  5541  		Query: `SHOW CREATE TABLE two_pk`,
  5542  		Expected: []sql.Row{{
  5543  			"two_pk",
  5544  			"CREATE TABLE `two_pk` (\n" +
  5545  				"  `pk1` tinyint NOT NULL,\n" +
  5546  				"  `pk2` tinyint NOT NULL,\n" +
  5547  				"  `c1` tinyint NOT NULL,\n" +
  5548  				"  `c2` tinyint NOT NULL,\n" +
  5549  				"  `c3` tinyint NOT NULL,\n" +
  5550  				"  `c4` tinyint NOT NULL,\n" +
  5551  				"  `c5` tinyint NOT NULL,\n" +
  5552  				"  PRIMARY KEY (`pk1`,`pk2`)\n" +
  5553  				") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
  5554  		}},
  5555  	},
  5556  	{
  5557  		Query: `SHOW CREATE TABLE myview`,
  5558  		Expected: []sql.Row{{
  5559  			"myview",
  5560  			"CREATE VIEW `myview` AS SELECT * FROM mytable",
  5561  			"utf8mb4",
  5562  			"utf8mb4_0900_bin",
  5563  		}},
  5564  	},
  5565  	{
  5566  		Query: `SHOW CREATE VIEW myview`,
  5567  		Expected: []sql.Row{{
  5568  			"myview",
  5569  			"CREATE VIEW `myview` AS SELECT * FROM mytable",
  5570  			"utf8mb4",
  5571  			"utf8mb4_0900_bin",
  5572  		}},
  5573  	},
  5574  	{
  5575  		Query: `describe myview`,
  5576  		Expected: []sql.Row{
  5577  			{"i", "bigint", "NO", "", "NULL", ""},
  5578  			{"s", "varchar(20)", "NO", "", "NULL", ""},
  5579  		},
  5580  	},
  5581  	{
  5582  		Query:    `SELECT -1`,
  5583  		Expected: []sql.Row{{int8(-1)}},
  5584  	},
  5585  	{
  5586  		Query:    `SHOW WARNINGS LIMIT 0`,
  5587  		Expected: nil,
  5588  	},
  5589  	{
  5590  		Query: `SELECT NULL`,
  5591  		Expected: []sql.Row{
  5592  			{nil},
  5593  		},
  5594  	},
  5595  	{
  5596  		Query: `SELECT nullif('abc', NULL)`,
  5597  		Expected: []sql.Row{
  5598  			{"abc"},
  5599  		},
  5600  	},
  5601  	{
  5602  		Query: `SELECT nullif(NULL, NULL)`,
  5603  		Expected: []sql.Row{
  5604  			{nil},
  5605  		},
  5606  	},
  5607  	{
  5608  		Query: `SELECT nullif(NULL, 123)`,
  5609  		Expected: []sql.Row{
  5610  			{nil},
  5611  		},
  5612  	},
  5613  	{
  5614  		Query: `SELECT nullif(123, 123)`,
  5615  		Expected: []sql.Row{
  5616  			{nil},
  5617  		},
  5618  	},
  5619  	{
  5620  		Query: `SELECT nullif(123, 321)`,
  5621  		Expected: []sql.Row{
  5622  			{int8(123)},
  5623  		},
  5624  	},
  5625  	{
  5626  		Query: `SELECT ifnull(123, NULL)`,
  5627  		Expected: []sql.Row{
  5628  			{int8(123)},
  5629  		},
  5630  	},
  5631  	{
  5632  		Query: `SELECT ifnull(NULL, NULL)`,
  5633  		Expected: []sql.Row{
  5634  			{nil},
  5635  		},
  5636  	},
  5637  	{
  5638  		Query: `SELECT ifnull(NULL, 123)`,
  5639  		Expected: []sql.Row{
  5640  			{int8(123)},
  5641  		},
  5642  	},
  5643  	{
  5644  		Query: `SELECT ifnull(123, 123)`,
  5645  		Expected: []sql.Row{
  5646  			{int8(123)},
  5647  		},
  5648  	},
  5649  	{
  5650  		Query: `SELECT ifnull(123, 321)`,
  5651  		Expected: []sql.Row{
  5652  			{int8(123)},
  5653  		},
  5654  	},
  5655  	{
  5656  		Query: `SELECT if(123 = 123, "a", "b")`,
  5657  		Expected: []sql.Row{
  5658  			{"a"},
  5659  		},
  5660  	},
  5661  	{
  5662  		Query:    `SELECT if(123 = 123, NULL, "b")`,
  5663  		Expected: []sql.Row{{nil}},
  5664  		ExpectedColumns: []*sql.Column{
  5665  			{Name: "if(123 = 123, NULL, \"b\")", Type: types.LongText},
  5666  		},
  5667  	},
  5668  	{
  5669  		Query:    `SELECT if(123 = 123, NULL, NULL = 1)`,
  5670  		Expected: []sql.Row{{nil}},
  5671  		ExpectedColumns: []*sql.Column{
  5672  			{Name: "if(123 = 123, NULL, NULL = 1)", Type: types.Int64}, // TODO: this should be getting coerced to bool
  5673  		},
  5674  	},
  5675  	{
  5676  		Query:    `SELECT if(123 = 123, NULL, NULL)`,
  5677  		Expected: []sql.Row{{nil}},
  5678  		ExpectedColumns: []*sql.Column{
  5679  			{Name: "if(123 = 123, NULL, NULL)", Type: types.Null},
  5680  		},
  5681  	},
  5682  	{
  5683  		Query: `SELECT if(123 > 123, "a", "b")`,
  5684  		Expected: []sql.Row{
  5685  			{"b"},
  5686  		},
  5687  	},
  5688  	{
  5689  		Query: `SELECT if(1, 123, 456)`,
  5690  		Expected: []sql.Row{
  5691  			{123},
  5692  		},
  5693  	},
  5694  	{
  5695  		Query: `SELECT if(0, 123, 456)`,
  5696  		Expected: []sql.Row{
  5697  			{456},
  5698  		},
  5699  	},
  5700  	{
  5701  		Query: `SELECT if(0, "abc", 456)`,
  5702  		Expected: []sql.Row{
  5703  			{456},
  5704  		},
  5705  	},
  5706  	{
  5707  		Query: `SELECT if(1, "abc", 456)`,
  5708  		Expected: []sql.Row{
  5709  			{"abc"},
  5710  		},
  5711  	},
  5712  	{
  5713  		Query: `SELECT 1 as foo, if((select foo), "a", "b")`,
  5714  		Expected: []sql.Row{
  5715  			{1, "a"},
  5716  		},
  5717  	},
  5718  	{
  5719  		Query: `SELECT 0 as foo, if((select foo), "a", "b")`,
  5720  		Expected: []sql.Row{
  5721  			{0, "b"},
  5722  		},
  5723  	},
  5724  	{
  5725  		Query: `SELECT if(NULL, "a", "b")`,
  5726  		Expected: []sql.Row{
  5727  			{"b"},
  5728  		},
  5729  	},
  5730  	{
  5731  		Query: `SELECT if("a", "a", "b")`,
  5732  		Expected: []sql.Row{
  5733  			{"b"},
  5734  		},
  5735  	},
  5736  	{
  5737  		Query: `SELECT i, if(s = "first row", "first", "not first") from mytable order by i`,
  5738  		Expected: []sql.Row{
  5739  			{1, "first"},
  5740  			{2, "not first"},
  5741  			{3, "not first"},
  5742  		},
  5743  	},
  5744  	{
  5745  		Query:    "SELECT i FROM mytable WHERE NULL > 10;",
  5746  		Expected: nil,
  5747  	},
  5748  	{
  5749  		Query:    "SELECT i FROM mytable WHERE NULL IN (10);",
  5750  		Expected: nil,
  5751  	},
  5752  	{
  5753  		Query:    "SELECT i FROM mytable WHERE NULL IN (NULL, NULL);",
  5754  		Expected: nil,
  5755  	},
  5756  	{
  5757  		Query:    "SELECT i FROM mytable WHERE NOT NULL NOT IN (NULL);",
  5758  		Expected: nil,
  5759  	},
  5760  	{
  5761  		Query:    "SELECT i FROM mytable WHERE NOT (NULL) <> 10;",
  5762  		Expected: nil,
  5763  	},
  5764  	{
  5765  		Query:    "SELECT i FROM mytable WHERE NOT NULL <> NULL;",
  5766  		Expected: nil,
  5767  	},
  5768  	{
  5769  		Query: `SELECT 2/4`,
  5770  		Expected: []sql.Row{
  5771  			{"0.5000"},
  5772  		},
  5773  	},
  5774  	{
  5775  		Query: `SELECT 15728640/1024/1024`,
  5776  		Expected: []sql.Row{
  5777  			{"15.00000000"},
  5778  		},
  5779  	},
  5780  	{
  5781  		Query: `SELECT 15728640/1024/1030`,
  5782  		Expected: []sql.Row{
  5783  			{"14.91262136"},
  5784  		},
  5785  	},
  5786  	{
  5787  		Query: `SELECT 2/4/5/5`,
  5788  		Expected: []sql.Row{
  5789  			{"0.020000000000"},
  5790  		},
  5791  	},
  5792  	{
  5793  		Query: `SELECT 4/3/1`,
  5794  		Expected: []sql.Row{
  5795  			{"1.33333333"},
  5796  		},
  5797  	},
  5798  	{
  5799  		Query: `select 5/4/3/(2/1+3/1)`,
  5800  		Expected: []sql.Row{
  5801  			{"0.083333333333"},
  5802  		},
  5803  	},
  5804  	{
  5805  		Query: `select (2/1+3/1)/5/4/3`,
  5806  		Expected: []sql.Row{
  5807  			{"0.0833333333333333"},
  5808  		},
  5809  	},
  5810  	{
  5811  		Query: `select cast(X'20' as decimal)`,
  5812  		Expected: []sql.Row{
  5813  			{"32"},
  5814  		},
  5815  	},
  5816  	{
  5817  		Query: `SELECT FLOOR(15728640/1024/1030)`,
  5818  		Expected: []sql.Row{
  5819  			{"14"},
  5820  		},
  5821  	},
  5822  	{
  5823  		Query: `SELECT ROUND(15728640/1024/1030)`,
  5824  		Expected: []sql.Row{
  5825  			{"15"},
  5826  		},
  5827  	},
  5828  	{
  5829  		Query: `SELECT ROUND(15.00, 1)`,
  5830  		Expected: []sql.Row{
  5831  			{"15.0"},
  5832  		},
  5833  	},
  5834  	{
  5835  		Query: `SELECT round(15, 1)`,
  5836  		Expected: []sql.Row{
  5837  			{int8(15)},
  5838  		},
  5839  	},
  5840  	{
  5841  		Query: `SELECT CASE i WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'other' END FROM mytable`,
  5842  		Expected: []sql.Row{
  5843  			{"one"},
  5844  			{"two"},
  5845  			{"other"},
  5846  		},
  5847  	},
  5848  	{
  5849  		Query: `SELECT CASE WHEN i > 2 THEN 'more than two' WHEN i < 2 THEN 'less than two' ELSE 'two' END FROM mytable`,
  5850  		Expected: []sql.Row{
  5851  			{"less than two"},
  5852  			{"two"},
  5853  			{"more than two"},
  5854  		},
  5855  	},
  5856  	{
  5857  		Query: `SELECT CASE WHEN i > 2 THEN i WHEN i < 2 THEN i ELSE 'two' END FROM mytable`,
  5858  		Expected: []sql.Row{
  5859  			{"1"},
  5860  			{"two"},
  5861  			{"3"},
  5862  		},
  5863  	},
  5864  	{
  5865  		Query: `SELECT CASE WHEN i > 2 THEN 'more than two' WHEN i < 2 THEN 'less than two' ELSE 2 END FROM mytable`,
  5866  		Expected: []sql.Row{
  5867  			{"less than two"},
  5868  			{"2"},
  5869  			{"more than two"},
  5870  		},
  5871  	},
  5872  	{
  5873  		Query: `SELECT CASE i WHEN 1 THEN 'one' WHEN 2 THEN 'two' END FROM mytable`,
  5874  		Expected: []sql.Row{
  5875  			{"one"},
  5876  			{"two"},
  5877  			{nil},
  5878  		},
  5879  	},
  5880  	{
  5881  		Query: `SELECT CASE i WHEN 1 THEN JSON_OBJECT("a", 1) WHEN 2 THEN JSON_OBJECT("b", 2) END FROM mytable`,
  5882  		Expected: []sql.Row{
  5883  			{types.MustJSON(`{"a": 1}`)},
  5884  			{types.MustJSON(`{"b": 2}`)},
  5885  			{nil},
  5886  		},
  5887  	},
  5888  	{
  5889  		Query: `SELECT CASE i WHEN 1 THEN JSON_OBJECT("a", 1) ELSE JSON_OBJECT("b", 2) END FROM mytable`,
  5890  		Expected: []sql.Row{
  5891  			{types.MustJSON(`{"a": 1}`)},
  5892  			{types.MustJSON(`{"b": 2}`)},
  5893  			{types.MustJSON(`{"b": 2}`)},
  5894  		},
  5895  	},
  5896  	{
  5897  		Query: `SELECT CASE i WHEN 1 THEN JSON_OBJECT("a", 1) ELSE JSON_OBJECT("b", 2) END FROM mytable`,
  5898  		Expected: []sql.Row{
  5899  			{types.MustJSON(`{"a": 1}`)},
  5900  			{types.MustJSON(`{"b": 2}`)},
  5901  			{types.MustJSON(`{"b": 2}`)},
  5902  		},
  5903  	},
  5904  	{
  5905  		// NOTE: utf8_general_ci is collation of utf8mb3, which was deprecated and now removed in MySQL
  5906  		Query: "SHOW COLLATION WHERE `Collation` IN ('binary', 'utf8_general_ci', 'utf8mb4_0900_ai_ci')",
  5907  		Expected: []sql.Row{
  5908  			{
  5909  				sql.Collation_binary.String(),
  5910  				"binary",
  5911  				uint64(sql.Collation_binary),
  5912  				sql.Collation_binary.IsDefault(),
  5913  				sql.Collation_binary.IsCompiled(),
  5914  				sql.Collation_binary.SortLength(),
  5915  				sql.Collation_binary.PadAttribute(),
  5916  			},
  5917  			{
  5918  				sql.Collation_utf8_general_ci.String(),
  5919  				"utf8mb3",
  5920  				uint64(sql.Collation_utf8_general_ci),
  5921  				sql.Collation_utf8_general_ci.IsDefault(),
  5922  				sql.Collation_utf8_general_ci.IsCompiled(),
  5923  				sql.Collation_utf8_general_ci.SortLength(),
  5924  				sql.Collation_utf8_general_ci.PadAttribute(),
  5925  			},
  5926  			{
  5927  				sql.Collation_utf8mb4_0900_ai_ci.String(),
  5928  				"utf8mb4",
  5929  				uint64(sql.Collation_utf8mb4_0900_ai_ci),
  5930  				sql.Collation_utf8mb4_0900_ai_ci.IsDefault(),
  5931  				sql.Collation_utf8mb4_0900_ai_ci.IsCompiled(),
  5932  				sql.Collation_utf8mb4_0900_ai_ci.SortLength(),
  5933  				sql.Collation_utf8mb4_0900_ai_ci.PadAttribute(),
  5934  			},
  5935  		},
  5936  	},
  5937  	{
  5938  		Query:    `SHOW COLLATION LIKE 'foo'`,
  5939  		Expected: nil,
  5940  	},
  5941  	{
  5942  		Query: `SHOW COLLATION LIKE 'bin%'`,
  5943  		Expected: []sql.Row{
  5944  			{
  5945  				sql.Collation_binary.String(),
  5946  				"binary",
  5947  				uint64(sql.Collation_binary),
  5948  				sql.Collation_binary.IsDefault(),
  5949  				sql.Collation_binary.IsCompiled(),
  5950  				sql.Collation_binary.SortLength(),
  5951  				sql.Collation_binary.PadAttribute(),
  5952  			},
  5953  		},
  5954  	},
  5955  	{
  5956  		Query:    `SHOW COLLATION WHERE charset = 'foo'`,
  5957  		Expected: nil,
  5958  	},
  5959  	{
  5960  		Query: "SHOW COLLATION WHERE `Default` = 'Yes' AND `Collation` LIKE 'utf8mb4%'",
  5961  		Expected: []sql.Row{
  5962  			{
  5963  				sql.Collation_utf8mb4_0900_ai_ci.String(),
  5964  				"utf8mb4",
  5965  				uint64(sql.Collation_utf8mb4_0900_ai_ci),
  5966  				sql.Collation_utf8mb4_0900_ai_ci.IsDefault(),
  5967  				sql.Collation_utf8mb4_0900_ai_ci.IsCompiled(),
  5968  				sql.Collation_utf8mb4_0900_ai_ci.SortLength(),
  5969  				sql.Collation_utf8mb4_0900_ai_ci.PadAttribute(),
  5970  			},
  5971  		},
  5972  	},
  5973  	{
  5974  		Query:    "ROLLBACK",
  5975  		Expected: nil,
  5976  	},
  5977  	{
  5978  		Query:    "SELECT substring(s, 1, 1) FROM mytable ORDER BY substring(s, 1, 1)",
  5979  		Expected: []sql.Row{{"f"}, {"s"}, {"t"}},
  5980  	},
  5981  	{
  5982  		Query:    "SELECT substring(s, 1, 1), count(*) FROM mytable GROUP BY substring(s, 1, 1)",
  5983  		Expected: []sql.Row{{"f", int64(1)}, {"s", int64(1)}, {"t", int64(1)}},
  5984  	},
  5985  	{
  5986  		Query:    "SELECT substring(s, 1, 1) as x, count(*) FROM mytable GROUP BY X",
  5987  		Expected: []sql.Row{{"f", int64(1)}, {"s", int64(1)}, {"t", int64(1)}},
  5988  	},
  5989  	{
  5990  		Query:    "SELECT left(s, 1) as l FROM mytable ORDER BY l",
  5991  		Expected: []sql.Row{{"f"}, {"s"}, {"t"}},
  5992  	},
  5993  	{
  5994  		Query:    "SELECT left(s, 2) as l FROM mytable ORDER BY l",
  5995  		Expected: []sql.Row{{"fi"}, {"se"}, {"th"}},
  5996  	},
  5997  	{
  5998  		Query:    "SELECT left(s, 0) as l FROM mytable ORDER BY l",
  5999  		Expected: []sql.Row{{""}, {""}, {""}},
  6000  	},
  6001  	{
  6002  		Query:    "SELECT left(s, NULL) as l FROM mytable ORDER BY l",
  6003  		Expected: []sql.Row{{nil}, {nil}, {nil}},
  6004  	},
  6005  	{
  6006  		Query:    "SELECT left(s, 100) as l FROM mytable ORDER BY l",
  6007  		Expected: []sql.Row{{"first row"}, {"second row"}, {"third row"}},
  6008  	},
  6009  	{
  6010  		Query:    "SELECT instr(s, 'row') as l FROM mytable ORDER BY i",
  6011  		Expected: []sql.Row{{int64(7)}, {int64(8)}, {int64(7)}},
  6012  	},
  6013  	{
  6014  		Query:    "SELECT instr(s, 'first') as l FROM mytable ORDER BY i",
  6015  		Expected: []sql.Row{{int64(1)}, {int64(0)}, {int64(0)}},
  6016  	},
  6017  	{
  6018  		Query:    "SELECT instr(s, 'o') as l FROM mytable ORDER BY i",
  6019  		Expected: []sql.Row{{int64(8)}, {int64(4)}, {int64(8)}},
  6020  	},
  6021  	{
  6022  		Query:    "SELECT instr(s, NULL) as l FROM mytable ORDER BY l",
  6023  		Expected: []sql.Row{{nil}, {nil}, {nil}},
  6024  	},
  6025  	{
  6026  		Query:    "SELECT SLEEP(0.5)",
  6027  		Expected: []sql.Row{{int(0)}},
  6028  	},
  6029  	{
  6030  		Query:    "SELECT TO_BASE64('foo')",
  6031  		Expected: []sql.Row{{string("Zm9v")}},
  6032  	},
  6033  	{
  6034  		Query:    "SELECT FROM_BASE64('YmFy')",
  6035  		Expected: []sql.Row{{[]byte("bar")}},
  6036  	},
  6037  	{
  6038  		Query:    "SELECT DATE_ADD('2018-05-02', INTERVAL 1 day)",
  6039  		Expected: []sql.Row{{time.Date(2018, time.May, 3, 0, 0, 0, 0, time.UTC)}},
  6040  	},
  6041  	{
  6042  		Query:    "SELECT DATE_ADD(DATE('2018-05-02'), INTERVAL 1 day)",
  6043  		Expected: []sql.Row{{time.Date(2018, time.May, 3, 0, 0, 0, 0, time.UTC)}},
  6044  	},
  6045  	{
  6046  		Query:    "select date_add(time('12:13:14'), interval 1 minute);",
  6047  		Expected: []sql.Row{{types.Timespan(44054000000)}},
  6048  	},
  6049  	{
  6050  		Query:    "SELECT DATE_SUB('2018-05-02', INTERVAL 1 DAY)",
  6051  		Expected: []sql.Row{{time.Date(2018, time.May, 1, 0, 0, 0, 0, time.UTC)}},
  6052  	},
  6053  	{
  6054  		Query:    "SELECT DATE_SUB(DATE('2018-05-02'), INTERVAL 1 DAY)",
  6055  		Expected: []sql.Row{{time.Date(2018, time.May, 1, 0, 0, 0, 0, time.UTC)}},
  6056  	},
  6057  	{
  6058  		Query:    "select date_sub(time('12:13:14'), interval 1 minute);",
  6059  		Expected: []sql.Row{{types.Timespan(43934000000)}},
  6060  	},
  6061  	{
  6062  		Query:    "SELECT '2018-05-02' + INTERVAL 1 DAY",
  6063  		Expected: []sql.Row{{time.Date(2018, time.May, 3, 0, 0, 0, 0, time.UTC)}},
  6064  	},
  6065  	{
  6066  		Query:    "SELECT '2018-05-02' - INTERVAL 1 DAY",
  6067  		Expected: []sql.Row{{time.Date(2018, time.May, 1, 0, 0, 0, 0, time.UTC)}},
  6068  	},
  6069  	{
  6070  		Query:    `SELECT i AS i FROM mytable ORDER BY i`,
  6071  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}},
  6072  	},
  6073  	{
  6074  		Query:    `SELECT i AS i FROM mytable GROUP BY i, s ORDER BY 1`,
  6075  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}},
  6076  	},
  6077  	{
  6078  		Query:    `SELECT i AS x FROM mytable GROUP BY i, s ORDER BY x`,
  6079  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}},
  6080  	},
  6081  	{
  6082  		Query: `SELECT i as x, row_number() over (order by i DESC) FROM mytable ORDER BY x`,
  6083  		Expected: []sql.Row{
  6084  			{1, 3},
  6085  			{2, 2},
  6086  			{3, 1}},
  6087  	},
  6088  	{
  6089  		Query: `SELECT i as i, row_number() over (order by i DESC) FROM mytable ORDER BY 1`,
  6090  		Expected: []sql.Row{
  6091  			{1, 3},
  6092  			{2, 2},
  6093  			{3, 1}},
  6094  	},
  6095  	{
  6096  		Query: `
  6097  		SELECT
  6098  			i,
  6099  			foo
  6100  		FROM (
  6101  			SELECT
  6102  				i,
  6103  				COUNT(s) AS foo
  6104  			FROM mytable
  6105  			GROUP BY i
  6106  		) AS q
  6107  		ORDER BY foo DESC, i ASC
  6108  		`,
  6109  		Expected: []sql.Row{
  6110  			{int64(1), int64(1)},
  6111  			{int64(2), int64(1)},
  6112  			{int64(3), int64(1)},
  6113  		},
  6114  	},
  6115  	{
  6116  		Query:    "SELECT n, COUNT(n) FROM bigtable GROUP BY n HAVING COUNT(n) > 2",
  6117  		Expected: []sql.Row{{int64(1), int64(3)}, {int64(2), int64(3)}},
  6118  	},
  6119  	{
  6120  		Query:    "SELECT n, COUNT(n) as cnt FROM bigtable GROUP BY n HAVING cnt > 2",
  6121  		Expected: []sql.Row{{int64(1), int64(3)}, {int64(2), int64(3)}},
  6122  	},
  6123  	{
  6124  		Query:    "SELECT n, MAX(n) FROM bigtable GROUP BY n HAVING COUNT(n) > 2",
  6125  		Expected: []sql.Row{{int64(1), int64(1)}, {int64(2), int64(2)}},
  6126  	},
  6127  	{
  6128  		Query:    "SELECT substring(mytable.s, 1, 5) AS s FROM mytable INNER JOIN othertable ON (substring(mytable.s, 1, 5) = SUBSTRING(othertable.s2, 1, 5)) GROUP BY 1 HAVING s = \"secon\"",
  6129  		Expected: []sql.Row{{"secon"}},
  6130  	},
  6131  	{
  6132  		Query: "SELECT s, i FROM mytable GROUP BY i ORDER BY SUBSTRING(s, 1, 1) DESC",
  6133  		Expected: []sql.Row{
  6134  			{string("third row"), int64(3)},
  6135  			{string("second row"), int64(2)},
  6136  			{string("first row"), int64(1)},
  6137  		},
  6138  	},
  6139  	{
  6140  		Query: "SELECT s, i FROM mytable GROUP BY i HAVING count(*) > 0 ORDER BY SUBSTRING(s, 1, 1) DESC",
  6141  		Expected: []sql.Row{
  6142  			{string("third row"), int64(3)},
  6143  			{string("second row"), int64(2)},
  6144  			{string("first row"), int64(1)},
  6145  		},
  6146  	},
  6147  	{
  6148  		Query:    "SELECT CONVERT('9999-12-31 23:59:59', DATETIME)",
  6149  		Expected: []sql.Row{{time.Date(9999, time.December, 31, 23, 59, 59, 0, time.UTC)}},
  6150  	},
  6151  	{
  6152  		Query:    "SELECT DATETIME('9999-12-31 23:59:59')",
  6153  		Expected: []sql.Row{{time.Date(9999, time.December, 31, 23, 59, 59, 0, time.UTC)}},
  6154  	},
  6155  	{
  6156  		Query:    "SELECT TIMESTAMP('2020-12-31 23:59:59')",
  6157  		Expected: []sql.Row{{time.Date(2020, time.December, 31, 23, 59, 59, 0, time.UTC)}},
  6158  	},
  6159  	{
  6160  		Query:    "SELECT CONVERT('10000-12-31 23:59:59', DATETIME)",
  6161  		Expected: []sql.Row{{nil}},
  6162  	},
  6163  	{
  6164  		Query:    "SELECT '9999-12-31 23:59:59' + INTERVAL 1 DAY",
  6165  		Expected: []sql.Row{{nil}},
  6166  	},
  6167  	{
  6168  		Query:    "SELECT DATE_ADD('9999-12-31 23:59:59', INTERVAL 1 DAY)",
  6169  		Expected: []sql.Row{{nil}},
  6170  	},
  6171  	{
  6172  		Query:    "SELECT EXTRACT(DAY FROM '9999-12-31 23:59:59')",
  6173  		Expected: []sql.Row{{31}},
  6174  	},
  6175  	{
  6176  		Query:    `SELECT t.date_col FROM (SELECT CONVERT('2019-06-06 00:00:00', DATETIME) AS date_col) t WHERE t.date_col > '0000-01-01 00:00'`,
  6177  		Expected: []sql.Row{{time.Date(2019, time.June, 6, 0, 0, 0, 0, time.UTC)}},
  6178  	},
  6179  	{
  6180  		Query:    `SELECT t.date_col FROM (SELECT CONVERT('2019-06-06 00:00:00', DATETIME) AS date_col) t WHERE t.date_col > '0000-01-01 00:00:00'`,
  6181  		Expected: []sql.Row{{time.Date(2019, time.June, 6, 0, 0, 0, 0, time.UTC)}},
  6182  	},
  6183  	{
  6184  		Query:    `SELECT t.date_col FROM (SELECT CONVERT('2019-06-06 00:00:00', DATETIME) as date_col) t GROUP BY t.date_col`,
  6185  		Expected: []sql.Row{{time.Date(2019, time.June, 6, 0, 0, 0, 0, time.UTC)}},
  6186  	},
  6187  	{
  6188  		Query:    `SELECT t.date_col as date_col FROM (SELECT CONVERT('2019-06-06 00:00:00', DATETIME) as date_col) t GROUP BY t.date_col`,
  6189  		Expected: []sql.Row{{time.Date(2019, time.June, 6, 0, 0, 0, 0, time.UTC)}},
  6190  	},
  6191  	{
  6192  		Query:    `SELECT t.date_col FROM (SELECT CONVERT('2019-06-06 00:00:00', DATETIME) as date_col) t GROUP BY date_col`,
  6193  		Expected: []sql.Row{{time.Date(2019, time.June, 6, 0, 0, 0, 0, time.UTC)}},
  6194  	},
  6195  	{
  6196  		Query:    `SELECT t.date_col as date_col FROM (SELECT CONVERT('2019-06-06 00:00:00', DATETIME) as date_col) t GROUP BY date_col`,
  6197  		Expected: []sql.Row{{time.Date(2019, time.June, 6, 0, 0, 0, 0, time.UTC)}},
  6198  	},
  6199  	{
  6200  		Query:    `SELECT i AS foo FROM mytable ORDER BY mytable.i`,
  6201  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}},
  6202  	},
  6203  	{
  6204  		Query:    `SELECT JSON_EXTRACT('[1, 2, 3]', '$.[0]')`,
  6205  		Expected: []sql.Row{{types.MustJSON(`1`)}},
  6206  	},
  6207  	// TODO(andy)
  6208  	//{
  6209  	//	Query:    `SELECT JSON_LENGTH(JSON_EXTRACT('[1, 2, 3]', '$'))`,
  6210  	//	Expected: []sql.Row{{int32(3)}},
  6211  	//},
  6212  	//{
  6213  	//	Query:    `SELECT JSON_LENGTH(JSON_EXTRACT('[{"i":0}, {"i":1, "y":"yyy"}, {"i":2, "x":"xxx"}]', '$.i'))`,
  6214  	//	Expected: []sql.Row{{int32(3)}},
  6215  	//},
  6216  	{
  6217  		Query:    `SELECT GREATEST(@@back_log,@@auto_increment_offset)`,
  6218  		Expected: []sql.Row{{1}},
  6219  	},
  6220  	{
  6221  		Query:    `SELECT GREATEST(1, 2, "3", 4)`,
  6222  		Expected: []sql.Row{{float64(4)}},
  6223  	},
  6224  	{
  6225  		Query:    `SELECT GREATEST(1, 2, "9", "foo999")`,
  6226  		Expected: []sql.Row{{float64(9)}},
  6227  	},
  6228  	{
  6229  		Query:    `SELECT GREATEST("aaa", "bbb", "ccc")`,
  6230  		Expected: []sql.Row{{"ccc"}},
  6231  	},
  6232  	{
  6233  		Query:    `SELECT GREATEST(i, s) FROM mytable`,
  6234  		Expected: []sql.Row{{float64(1)}, {float64(2)}, {float64(3)}},
  6235  	},
  6236  	{
  6237  		Query:    `SELECT GREATEST(1, 2, 3, 4)`,
  6238  		Expected: []sql.Row{{int64(4)}},
  6239  	},
  6240  	{
  6241  		Query:    "select abs(-i) from mytable order by 1",
  6242  		Expected: []sql.Row{{1}, {2}, {3}},
  6243  	},
  6244  	{
  6245  		Query:    "select ceil(i + 0.5) from mytable order by 1",
  6246  		Expected: []sql.Row{{"2"}, {"3"}, {"4"}},
  6247  	},
  6248  	{
  6249  		Query:    "select floor(i + 0.5) from mytable order by 1",
  6250  		Expected: []sql.Row{{"1"}, {"2"}, {"3"}},
  6251  	},
  6252  	{
  6253  		Query:    "select round(i + 0.55, 1) from mytable order by 1",
  6254  		Expected: []sql.Row{{"1.6"}, {"2.6"}, {"3.6"}},
  6255  	},
  6256  	{
  6257  		Query:    "select date_format(da, '%s') from typestable order by 1",
  6258  		Expected: []sql.Row{{"00"}},
  6259  	},
  6260  	{
  6261  		Query: "select md5(i) from mytable order by 1",
  6262  		Expected: []sql.Row{
  6263  			{"c4ca4238a0b923820dcc509a6f75849b"},
  6264  			{"c81e728d9d4c2f636f067f89cc14862c"},
  6265  			{"eccbc87e4b5ce2fe28308fd9f2a7baf3"},
  6266  		},
  6267  	},
  6268  	{
  6269  		Query: "select sha1(i) from mytable order by 1",
  6270  		Expected: []sql.Row{
  6271  			{"356a192b7913b04c54574d18c28d46e6395428ab"},
  6272  			{"77de68daecd823babbb58edb1c8e14d7106e83bb"},
  6273  			{"da4b9237bacccdf19c0760cab7aec4a8359010b0"},
  6274  		},
  6275  	},
  6276  	{
  6277  		Query: "select sha2(i, 256) from mytable order by 1",
  6278  		Expected: []sql.Row{
  6279  			{"4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce"},
  6280  			{"6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b"},
  6281  			{"d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35"},
  6282  		},
  6283  	},
  6284  	{
  6285  		Query:    "select length(s) from mytable order by i",
  6286  		Expected: []sql.Row{{9}, {10}, {9}},
  6287  	},
  6288  	{
  6289  		Query:    "select octet_length(s) from mytable order by i",
  6290  		Expected: []sql.Row{{9}, {10}, {9}},
  6291  	},
  6292  	{
  6293  		Query:    "select char_length(s) from mytable order by i",
  6294  		Expected: []sql.Row{{9}, {10}, {9}},
  6295  	},
  6296  	{
  6297  		Query:    `select locate("o", s) from mytable order by i`,
  6298  		Expected: []sql.Row{{8}, {4}, {8}},
  6299  	},
  6300  	{
  6301  		Query:    `select locate("o", s, 5) from mytable order by i`,
  6302  		Expected: []sql.Row{{8}, {9}, {8}},
  6303  	},
  6304  	{
  6305  		Query:    `select locate(upper("roW"), upper(s), power(10, 0)) from mytable order by i`,
  6306  		Expected: []sql.Row{{7}, {8}, {7}},
  6307  	},
  6308  	{
  6309  		Query:    "select log2(i) from mytable order by i",
  6310  		Expected: []sql.Row{{0.0}, {1.0}, {1.5849625007211563}},
  6311  	},
  6312  	{
  6313  		Query:    "select ln(i) from mytable order by i",
  6314  		Expected: []sql.Row{{0.0}, {0.6931471805599453}, {1.0986122886681096}},
  6315  	},
  6316  	{
  6317  		Query:    "select log10(i) from mytable order by i",
  6318  		Expected: []sql.Row{{0.0}, {0.3010299956639812}, {0.4771212547196624}},
  6319  	},
  6320  	{
  6321  		Query:    "select log(3, i) from mytable order by i",
  6322  		Expected: []sql.Row{{0.0}, {0.6309297535714575}, {1.0}},
  6323  	},
  6324  	{
  6325  		Query: "select lower(s) from mytable order by i",
  6326  		Expected: []sql.Row{
  6327  			{"first row"},
  6328  			{"second row"},
  6329  			{"third row"},
  6330  		},
  6331  	},
  6332  	{
  6333  		Query: "select upper(s) from mytable order by i",
  6334  		Expected: []sql.Row{
  6335  			{"FIRST ROW"},
  6336  			{"SECOND ROW"},
  6337  			{"THIRD ROW"},
  6338  		},
  6339  	},
  6340  	{
  6341  		Query:    "select reverse(s) from mytable order by i",
  6342  		Expected: []sql.Row{{"wor tsrif"}, {"wor dnoces"}, {"wor driht"}},
  6343  	},
  6344  	{
  6345  		Query:    "select repeat(s, 2) from mytable order by i",
  6346  		Expected: []sql.Row{{"first rowfirst row"}, {"second rowsecond row"}, {"third rowthird row"}},
  6347  	},
  6348  	{
  6349  		Query:    "select replace(s, 'row', '') from mytable order by i",
  6350  		Expected: []sql.Row{{"first "}, {"second "}, {"third "}},
  6351  	},
  6352  	{
  6353  		Query:    "select rpad(s, 13, ' ') from mytable order by i",
  6354  		Expected: []sql.Row{{"first row    "}, {"second row   "}, {"third row    "}},
  6355  	},
  6356  	{
  6357  		Query:    "select lpad(s, 13, ' ') from mytable order by i",
  6358  		Expected: []sql.Row{{"    first row"}, {"   second row"}, {"    third row"}},
  6359  	},
  6360  	{
  6361  		Query:    "select sqrt(i) from mytable order by i",
  6362  		Expected: []sql.Row{{1.0}, {1.4142135623730951}, {1.7320508075688772}},
  6363  	},
  6364  	{
  6365  		Query:    "select pow(2, i) from mytable order by i",
  6366  		Expected: []sql.Row{{2.0}, {4.0}, {8.0}},
  6367  	},
  6368  	{
  6369  		Query:    "select ltrim(concat(' ', concat(s, ' '))) from mytable order by i",
  6370  		Expected: []sql.Row{{"first row "}, {"second row "}, {"third row "}},
  6371  	},
  6372  	{
  6373  		Query:    "select rtrim(concat(' ', concat(s, ' '))) from mytable order by i",
  6374  		Expected: []sql.Row{{" first row"}, {" second row"}, {" third row"}},
  6375  	},
  6376  	{
  6377  		Query:    "select trim(concat(' ', concat(s, ' '))) from mytable order by i",
  6378  		Expected: []sql.Row{{"first row"}, {"second row"}, {"third row"}},
  6379  	},
  6380  	{
  6381  		Query:    `SELECT GREATEST(CAST("1920-02-03 07:41:11" AS DATETIME), CAST("1980-06-22 14:32:56" AS DATETIME))`,
  6382  		Expected: []sql.Row{{time.Date(1980, 6, 22, 14, 32, 56, 0, time.UTC)}},
  6383  	},
  6384  	{
  6385  		Query:    `SELECT LEAST(1, 2, 3, 4)`,
  6386  		Expected: []sql.Row{{int64(1)}},
  6387  	},
  6388  	{
  6389  		Query:    `SELECT LEAST(1, 2, "3", 4)`,
  6390  		Expected: []sql.Row{{float64(1)}},
  6391  	},
  6392  	{
  6393  		Query:    `SELECT LEAST(1, 2, "9", "foo999")`,
  6394  		Expected: []sql.Row{{float64(1)}},
  6395  	},
  6396  	{
  6397  		Query:    `SELECT LEAST("aaa", "bbb", "ccc")`,
  6398  		Expected: []sql.Row{{"aaa"}},
  6399  	},
  6400  	{
  6401  		Query:    `SELECT LEAST(i, s) FROM mytable`,
  6402  		Expected: []sql.Row{{float64(1)}, {float64(2)}, {float64(3)}},
  6403  	},
  6404  	{
  6405  		Query:    `SELECT LEAST(CAST("1920-02-03 07:41:11" AS DATETIME), CAST("1980-06-22 14:32:56" AS DATETIME))`,
  6406  		Expected: []sql.Row{{time.Date(1920, 2, 3, 7, 41, 11, 0, time.UTC)}},
  6407  	},
  6408  	{
  6409  		Query:    `SELECT LEAST(@@back_log,@@auto_increment_offset)`,
  6410  		Expected: []sql.Row{{-1}},
  6411  	},
  6412  	{
  6413  		Query:    `SELECT CHAR_LENGTH('áé'), LENGTH('àè')`,
  6414  		Expected: []sql.Row{{int32(2), int32(4)}},
  6415  	},
  6416  	{
  6417  		Query:    "SELECT i, COUNT(i) AS `COUNT(i)` FROM (SELECT i FROM mytable) t GROUP BY i ORDER BY i, `COUNT(i)` DESC",
  6418  		Expected: []sql.Row{{int64(1), int64(1)}, {int64(2), int64(1)}, {int64(3), int64(1)}},
  6419  	},
  6420  	{
  6421  		Query: "SELECT i FROM mytable WHERE NOT s ORDER BY 1 DESC",
  6422  		Expected: []sql.Row{
  6423  			{int64(3)},
  6424  			{int64(2)},
  6425  			{int64(1)},
  6426  		},
  6427  	},
  6428  	{
  6429  		Query: "SELECT i FROM mytable WHERE NOT(NOT i) ORDER BY 1 DESC",
  6430  		Expected: []sql.Row{
  6431  			{int64(3)},
  6432  			{int64(2)},
  6433  			{int64(1)},
  6434  		},
  6435  	},
  6436  	{
  6437  		Query:    `SELECT NOW() - NOW()`,
  6438  		Expected: []sql.Row{{int64(0)}},
  6439  	},
  6440  	{
  6441  		Query:    `SELECT NOW() / NOW()`,
  6442  		Expected: []sql.Row{{"1.0000"}},
  6443  	},
  6444  	{
  6445  		Query:    `SELECT NOW() div NOW()`,
  6446  		Expected: []sql.Row{{1}},
  6447  	},
  6448  	{
  6449  		// TODO: Neither MySQL or MariaDB have a function called DATETIME; remove this function.
  6450  		Query:    `SELECT DATETIME(NOW()) - NOW()`,
  6451  		Expected: []sql.Row{{int64(0)}},
  6452  	},
  6453  	{
  6454  		Query:    `SELECT TIMESTAMP(NOW()) - NOW()`,
  6455  		Expected: []sql.Row{{int64(0)}},
  6456  	},
  6457  	{
  6458  		Query:    `SELECT STR_TO_DATE('01,5,2013 09:30:17','%d,%m,%Y %h:%i:%s') - (STR_TO_DATE('01,5,2013 09:30:17','%d,%m,%Y %h:%i:%s') - INTERVAL 1 SECOND)`,
  6459  		Expected: []sql.Row{{int64(1)}},
  6460  	},
  6461  	{
  6462  		Query:    `SELECT SUBSTR(SUBSTRING('0123456789ABCDEF', 1, 10), -4)`,
  6463  		Expected: []sql.Row{{"6789"}},
  6464  	},
  6465  	{
  6466  		Query:    `SELECT CASE i WHEN 1 THEN i ELSE NULL END FROM mytable`,
  6467  		Expected: []sql.Row{{int64(1)}, {nil}, {nil}},
  6468  	},
  6469  	{
  6470  		Query:    `SELECT (NULL+1)`,
  6471  		Expected: []sql.Row{{nil}},
  6472  	},
  6473  	{
  6474  		Query:    `SELECT * FROM mytable WHERE NULL AND i = 3`,
  6475  		Expected: nil,
  6476  	},
  6477  	{
  6478  		Query:    `SELECT 1 FROM mytable GROUP BY i HAVING i > 1`,
  6479  		Expected: []sql.Row{{int8(1)}, {int8(1)}},
  6480  	},
  6481  	{
  6482  		Query:    `SELECT avg(i) FROM mytable GROUP BY i HAVING avg(i) > 1`,
  6483  		Expected: []sql.Row{{float64(2)}, {float64(3)}},
  6484  	},
  6485  	{
  6486  		Query:    "SELECT avg(i) as `avg(i)` FROM mytable GROUP BY i HAVING avg(i) > 1",
  6487  		Expected: []sql.Row{{float64(2)}, {float64(3)}},
  6488  	},
  6489  	{
  6490  		Query:    "SELECT avg(i) as `AVG(i)` FROM mytable GROUP BY i HAVING AVG(i) > 1",
  6491  		Expected: []sql.Row{{float64(2)}, {float64(3)}},
  6492  	},
  6493  	{
  6494  		Query: `SELECT s AS s, COUNT(*) AS count,  AVG(i) AS ` + "`AVG(i)`" + `
  6495  		FROM  (
  6496  			SELECT * FROM mytable
  6497  		) AS expr_qry
  6498  		GROUP BY s
  6499  		HAVING ((AVG(i) > 0))
  6500  		ORDER BY count DESC, s ASC
  6501  		LIMIT 10000`,
  6502  		Expected: []sql.Row{
  6503  			{"first row", int64(1), float64(1)},
  6504  			{"second row", int64(1), float64(2)},
  6505  			{"third row", int64(1), float64(3)},
  6506  		},
  6507  	},
  6508  	{
  6509  		Query:    `SELECT FIRST(i) FROM (SELECT i FROM mytable ORDER BY i) t`,
  6510  		Expected: []sql.Row{{int64(1)}},
  6511  	},
  6512  	{
  6513  		Query:    `SELECT LAST(i) FROM (SELECT i FROM mytable ORDER BY i) t`,
  6514  		Expected: []sql.Row{{int64(3)}},
  6515  	},
  6516  	{
  6517  		Query:    `SELECT COUNT(DISTINCT t.i) FROM tabletest t, mytable t2`,
  6518  		Expected: []sql.Row{{int64(3)}},
  6519  	},
  6520  	{
  6521  		Query:    `SELECT COUNT(DISTINCT t.i, t.s) FROM tabletest t, mytable t2`,
  6522  		Expected: []sql.Row{{int64(3)}},
  6523  	},
  6524  	{
  6525  		Query:    `SELECT COUNT(DISTINCT gender) FROM people`,
  6526  		Expected: []sql.Row{{int64(3)}},
  6527  	},
  6528  	{
  6529  		Query:    `SELECT COUNT(DISTINCT height_inches, gender) FROM people`,
  6530  		Expected: []sql.Row{{int64(5)}},
  6531  	},
  6532  	{
  6533  		Query:    `SELECT COUNT(DISTINCT height_inches, gender) FROM people where gender = 0`,
  6534  		Expected: []sql.Row{{int64(2)}},
  6535  	},
  6536  	{
  6537  		Query:    `SELECT COUNT(DISTINCT height_inches - 100 < 0, gender < 0) FROM people`,
  6538  		Expected: []sql.Row{{int64(1)}},
  6539  	},
  6540  	{
  6541  		Query:    `SELECT CASE WHEN NULL THEN "yes" ELSE "no" END AS test`,
  6542  		Expected: []sql.Row{{"no"}},
  6543  	},
  6544  	{
  6545  		Query: `SELECT
  6546  			table_schema,
  6547  			table_name,
  6548  			CASE
  6549  				WHEN table_type = 'BASE TABLE' THEN
  6550  					CASE
  6551  						WHEN table_schema = 'mysql'
  6552  							OR table_schema = 'performance_schema' THEN 'SYSTEM TABLE'
  6553  						ELSE 'TABLE'
  6554  					END
  6555  				WHEN table_type = 'TEMPORARY' THEN 'LOCAL_TEMPORARY'
  6556  				ELSE table_type
  6557  			END AS TABLE_TYPE
  6558  		FROM information_schema.tables
  6559  		WHERE table_schema = 'mydb'
  6560  			AND table_name = 'mytable'
  6561  		HAVING table_type IN ('TABLE', 'VIEW')
  6562  		ORDER BY table_type, table_schema, table_name`,
  6563  		Expected: []sql.Row{{"mydb", "mytable", "TABLE"}},
  6564  	},
  6565  	{
  6566  		Query:    `SELECT i FROM mytable WHERE i = (SELECT 1)`,
  6567  		Expected: []sql.Row{{int64(1)}},
  6568  	},
  6569  	{
  6570  		Query: `SELECT i FROM mytable WHERE i IN (SELECT i FROM mytable) ORDER BY i`,
  6571  		Expected: []sql.Row{
  6572  			{int64(1)},
  6573  			{int64(2)},
  6574  			{int64(3)},
  6575  		},
  6576  	},
  6577  	{
  6578  		Query: `SELECT i FROM mytable WHERE i IN (SELECT i FROM mytable ORDER BY i ASC LIMIT 2) ORDER BY i`,
  6579  		Expected: []sql.Row{
  6580  			{int64(1)},
  6581  			{int64(2)},
  6582  		},
  6583  	},
  6584  	{
  6585  		Query: `SELECT i FROM mytable WHERE i NOT IN (SELECT i FROM mytable ORDER BY i ASC LIMIT 2)`,
  6586  		Expected: []sql.Row{
  6587  			{int64(3)},
  6588  		},
  6589  	},
  6590  	{
  6591  		Query: `SELECT i FROM mytable WHERE i NOT IN (SELECT i FROM mytable ORDER BY i ASC LIMIT 1) ORDER BY i`,
  6592  		Expected: []sql.Row{
  6593  			{2},
  6594  			{3},
  6595  		},
  6596  	},
  6597  	{
  6598  		Query: `SELECT i FROM mytable mt
  6599  						 WHERE (SELECT i FROM mytable where i = mt.i and i > 2) IS NOT NULL
  6600  						 AND (SELECT i2 FROM othertable where i2 = i) IS NOT NULL
  6601  						 ORDER BY i`,
  6602  		Expected: []sql.Row{
  6603  			{3},
  6604  		},
  6605  	},
  6606  	{
  6607  		Query: `SELECT i FROM mytable mt
  6608  						 WHERE (SELECT i FROM mytable where i = mt.i and i > 1) IS NOT NULL
  6609  						 AND (SELECT i2 FROM othertable where i2 = i and i < 3) IS NOT NULL
  6610  						 ORDER BY i`,
  6611  		Expected: []sql.Row{
  6612  			{2},
  6613  		},
  6614  	},
  6615  	{
  6616  		Query: `SELECT i FROM mytable mt
  6617  						 WHERE (SELECT i FROM mytable where i = mt.i) IS NOT NULL
  6618  						 AND (SELECT i2 FROM othertable where i2 = i) IS NOT NULL
  6619  						 ORDER BY i`,
  6620  		Expected: []sql.Row{
  6621  			{1}, {2}, {3},
  6622  		},
  6623  	},
  6624  	{
  6625  		Query: `SELECT pk,pk2, (SELECT pk from one_pk where pk = 1 limit 1) FROM one_pk t1, two_pk t2 WHERE pk=1 AND pk2=1 ORDER BY 1,2`,
  6626  		Expected: []sql.Row{
  6627  			{1, 1, 1},
  6628  			{1, 1, 1},
  6629  		},
  6630  	},
  6631  	{
  6632  		Query: `SELECT i FROM mytable
  6633  						 WHERE (SELECT i2 FROM othertable where i2 = i) IS NOT NULL
  6634  						 ORDER BY i`,
  6635  		Expected: []sql.Row{
  6636  			{1}, {2}, {3},
  6637  		},
  6638  	},
  6639  	{
  6640  		Query: `SELECT i FROM mytable mt
  6641  						 WHERE (SELECT i2 FROM othertable ot where ot.i2 = mt.i) IS NOT NULL
  6642  						 ORDER BY i`,
  6643  		Expected: []sql.Row{
  6644  			{1}, {2}, {3},
  6645  		},
  6646  	},
  6647  	{
  6648  		Query: `SELECT i FROM mytable mt
  6649  						 WHERE (SELECT row_number() over (order by ot.i2 desc) FROM othertable ot where ot.i2 = mt.i) = 2
  6650  						 ORDER BY i`,
  6651  		Expected: []sql.Row{},
  6652  	},
  6653  	{
  6654  		Query: `SELECT i FROM mytable mt
  6655  						 WHERE (SELECT row_number() over (order by ot.i2 desc) FROM othertable ot where ot.i2 = mt.i) = 1
  6656  						 ORDER BY i`,
  6657  		Expected: []sql.Row{
  6658  			{1},
  6659  			{2},
  6660  			{3},
  6661  		},
  6662  	},
  6663  	{
  6664  		Query:    `SELECT sum(i) as isum, s FROM mytable GROUP BY i ORDER BY isum ASC LIMIT 0, 200`,
  6665  		Expected: []sql.Row{{1.0, "first row"}, {2.0, "second row"}, {3.0, "third row"}},
  6666  	},
  6667  	{
  6668  		Query:    `SELECT (SELECT i FROM mytable ORDER BY i ASC LIMIT 1) AS x`,
  6669  		Expected: []sql.Row{{int64(1)}},
  6670  	},
  6671  	{
  6672  		Query:    `SELECT (SELECT s FROM mytable ORDER BY i ASC LIMIT 1) AS x`,
  6673  		Expected: []sql.Row{{"first row"}},
  6674  	},
  6675  	{
  6676  		Query: `SELECT pk, (SELECT concat(pk, pk) FROM one_pk WHERE pk < opk.pk ORDER BY 1 DESC LIMIT 1) as strpk FROM one_pk opk having strpk > "0" ORDER BY 2`,
  6677  		Expected: []sql.Row{
  6678  			{1, "00"},
  6679  			{2, "11"},
  6680  			{3, "22"},
  6681  		},
  6682  	},
  6683  	{
  6684  		Query: `SELECT pk, (SELECT c3 FROM one_pk WHERE pk < opk.pk ORDER BY 1 DESC LIMIT 1) FROM one_pk opk ORDER BY 1`,
  6685  		Expected: []sql.Row{
  6686  			{0, nil},
  6687  			{1, 2},
  6688  			{2, 12},
  6689  			{3, 22},
  6690  		},
  6691  	},
  6692  	{
  6693  		Query: `SELECT pk, (SELECT c5 FROM one_pk WHERE c5 < opk.c5 ORDER BY 1 DESC LIMIT 1) FROM one_pk opk ORDER BY 1`,
  6694  		Expected: []sql.Row{
  6695  			{0, nil},
  6696  			{1, 4},
  6697  			{2, 14},
  6698  			{3, 24},
  6699  		},
  6700  	},
  6701  	{
  6702  		Query: `SELECT pk, (SELECT pk FROM one_pk WHERE c1 < opk.c1 ORDER BY 1 DESC LIMIT 1) FROM one_pk opk ORDER BY 1;`,
  6703  		Expected: []sql.Row{
  6704  			{0, nil},
  6705  			{1, 0},
  6706  			{2, 1},
  6707  			{3, 2},
  6708  		},
  6709  	},
  6710  	{
  6711  		Query: `SELECT pk, (SELECT c3 FROM one_pk WHERE c4 < opk.c2 ORDER BY 1 DESC LIMIT 1) FROM one_pk opk ORDER BY 1;`,
  6712  		Expected: []sql.Row{
  6713  			{0, nil},
  6714  			{1, 2},
  6715  			{2, 12},
  6716  			{3, 22},
  6717  		},
  6718  	},
  6719  	{
  6720  		Query: `SELECT pk,
  6721  					(SELECT c3 FROM one_pk WHERE c4 < opk.c2 ORDER BY 1 DESC LIMIT 1),
  6722  					(SELECT c5 + 1 FROM one_pk WHERE c5 < opk.c5 ORDER BY 1 DESC LIMIT 1)
  6723  					FROM one_pk opk ORDER BY 1;`,
  6724  		Expected: []sql.Row{
  6725  			{0, nil, nil},
  6726  			{1, 2, 5},
  6727  			{2, 12, 15},
  6728  			{3, 22, 25},
  6729  		},
  6730  	},
  6731  	{
  6732  		Query: `SELECT pk,
  6733  					(SELECT max(pk) FROM one_pk WHERE pk < opk.pk),
  6734  					(SELECT min(pk) FROM one_pk WHERE pk > opk.pk)
  6735  					FROM one_pk opk ORDER BY 1;`,
  6736  		Expected: []sql.Row{
  6737  			{0, nil, 1},
  6738  			{1, 0, 2},
  6739  			{2, 1, 3},
  6740  			{3, 2, nil},
  6741  		},
  6742  	},
  6743  	{
  6744  		Query: `SELECT pk,
  6745  					(SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS max,
  6746  					(SELECT min(pk) FROM one_pk WHERE pk > opk.pk) AS min
  6747  					FROM one_pk opk
  6748  					WHERE (SELECT min(pk) FROM one_pk WHERE pk > opk.pk) IS NOT NULL
  6749  					ORDER BY max;`,
  6750  		Expected: []sql.Row{
  6751  			{0, nil, 1},
  6752  			{1, 0, 2},
  6753  			{2, 1, 3},
  6754  		},
  6755  	},
  6756  	{
  6757  		Query: `SELECT pk,
  6758  					(SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS max,
  6759  					(SELECT min(pk) FROM one_pk WHERE pk > opk.pk) AS min
  6760  					FROM one_pk opk
  6761  					WHERE (SELECT max(pk) FROM one_pk WHERE pk >= opk.pk) > 0
  6762  					ORDER BY min;`,
  6763  		Expected: []sql.Row{
  6764  			{3, 2, nil},
  6765  			{0, nil, 1},
  6766  			{1, 0, 2},
  6767  			{2, 1, 3},
  6768  		},
  6769  	},
  6770  	{
  6771  		Query: `SELECT pk,
  6772  					(SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS max,
  6773  					(SELECT min(pk) FROM one_pk WHERE pk > opk.pk) AS min
  6774  					FROM one_pk opk
  6775  					WHERE (SELECT max(pk) FROM one_pk WHERE pk > opk.pk) > 0
  6776  					ORDER BY min;`,
  6777  		Expected: []sql.Row{
  6778  			{0, nil, 1},
  6779  			{1, 0, 2},
  6780  			{2, 1, 3},
  6781  		},
  6782  	},
  6783  	{
  6784  		Query: `SELECT pk,
  6785  					(SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS max,
  6786  					(SELECT min(pk) FROM one_pk WHERE pk > opk.pk) AS min
  6787  					FROM one_pk opk
  6788  					WHERE (SELECT max(pk) FROM one_pk WHERE pk > opk.pk) > 0
  6789  					ORDER BY max;`,
  6790  		Expected: []sql.Row{
  6791  			{0, nil, 1},
  6792  			{1, 0, 2},
  6793  			{2, 1, 3},
  6794  		},
  6795  	},
  6796  	{
  6797  		Query: `SELECT pk,
  6798  					(SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS max,
  6799  					(SELECT min(pk) FROM one_pk WHERE pk > opk.pk) AS min
  6800  					FROM one_pk opk
  6801  					WHERE (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) IS NOT NULL
  6802  					ORDER BY min;`,
  6803  		Expected: []sql.Row{
  6804  			{3, 2, nil},
  6805  			{1, 0, 2},
  6806  			{2, 1, 3},
  6807  		},
  6808  	},
  6809  	{
  6810  		Query: `SELECT pk,
  6811  					(SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS max,
  6812  					(SELECT min(pk) FROM one_pk WHERE pk > opk.pk) AS min
  6813  					FROM one_pk opk ORDER BY min;`,
  6814  		Expected: []sql.Row{
  6815  			{3, 2, nil},
  6816  			{0, nil, 1},
  6817  			{1, 0, 2},
  6818  			{2, 1, 3},
  6819  		},
  6820  	},
  6821  	{
  6822  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS x FROM one_pk opk GROUP BY x ORDER BY x`,
  6823  		Expected: []sql.Row{
  6824  			{0, nil},
  6825  			{1, 0},
  6826  			{2, 1},
  6827  			{3, 2},
  6828  		},
  6829  	},
  6830  	{
  6831  		Query: `SELECT pk,
  6832  					(SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS max,
  6833  					(SELECT min(pk) FROM one_pk WHERE pk > opk.pk) AS min
  6834  					FROM one_pk opk
  6835  					WHERE (SELECT max(pk) FROM one_pk WHERE pk >= opk.pk)
  6836  					ORDER BY min;`,
  6837  		Expected: []sql.Row{
  6838  			{3, 2, nil},
  6839  			{0, nil, 1},
  6840  			{1, 0, 2},
  6841  			{2, 1, 3},
  6842  		},
  6843  	},
  6844  	{
  6845  		Query: `SELECT pk FROM one_pk
  6846  					WHERE (SELECT max(pk1) FROM two_pk WHERE pk1 >= pk) IS NOT NULL
  6847  					ORDER BY 1;`,
  6848  		Expected: []sql.Row{
  6849  			{0},
  6850  			{1},
  6851  		},
  6852  	},
  6853  	{
  6854  		Query: `SELECT pk FROM one_pk opk
  6855  					WHERE (SELECT count(*) FROM two_pk where pk1 * 10 <= opk.c1) > 2
  6856  					ORDER BY 1;`,
  6857  		Expected: []sql.Row{
  6858  			{1},
  6859  			{2},
  6860  			{3},
  6861  		},
  6862  	},
  6863  	{
  6864  		Query: `SELECT pk,
  6865  					(SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS max,
  6866  					(SELECT min(pk) FROM one_pk WHERE pk > opk.pk) AS min
  6867  					FROM one_pk opk
  6868  					WHERE (SELECT max(pk) FROM one_pk WHERE pk >= opk.pk) > 0
  6869  					ORDER BY min;`,
  6870  		Expected: []sql.Row{
  6871  			{3, 2, nil},
  6872  			{0, nil, 1},
  6873  			{1, 0, 2},
  6874  			{2, 1, 3},
  6875  		},
  6876  	},
  6877  	{
  6878  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE one_pk.pk * 10 <= opk.c1) FROM one_pk opk ORDER BY 1`,
  6879  		Expected: []sql.Row{
  6880  			{0, 0},
  6881  			{1, 1},
  6882  			{2, 2},
  6883  			{3, 3},
  6884  		},
  6885  	},
  6886  	{
  6887  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk <= opk.pk) FROM one_pk opk ORDER BY 1`,
  6888  		Expected: []sql.Row{
  6889  			{0, 0},
  6890  			{1, 1},
  6891  			{2, 2},
  6892  			{3, 3},
  6893  		},
  6894  	},
  6895  	{
  6896  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) FROM one_pk opk ORDER BY 1`,
  6897  		Expected: []sql.Row{
  6898  			{0, nil},
  6899  			{1, 0},
  6900  			{2, 1},
  6901  			{3, 2},
  6902  		},
  6903  	},
  6904  	{
  6905  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) FROM one_pk opk ORDER BY 2`,
  6906  		Expected: []sql.Row{
  6907  			{0, nil},
  6908  			{1, 0},
  6909  			{2, 1},
  6910  			{3, 2},
  6911  		},
  6912  	},
  6913  	{
  6914  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS x FROM one_pk opk ORDER BY x`,
  6915  		Expected: []sql.Row{
  6916  			{0, nil},
  6917  			{1, 0},
  6918  			{2, 1},
  6919  			{3, 2},
  6920  		},
  6921  	},
  6922  	{
  6923  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS x
  6924  						FROM one_pk opk WHERE (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) IS NOT NULL ORDER BY x`,
  6925  		Expected: []sql.Row{
  6926  			{1, 0},
  6927  			{2, 1},
  6928  			{3, 2},
  6929  		},
  6930  	},
  6931  	{
  6932  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS max
  6933  						FROM one_pk opk WHERE (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) IS NOT NULL ORDER BY max`,
  6934  		Expected: []sql.Row{
  6935  			{1, 0},
  6936  			{2, 1},
  6937  			{3, 2},
  6938  		},
  6939  	},
  6940  	{
  6941  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS x
  6942  						FROM one_pk opk WHERE (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) > 0 ORDER BY x`,
  6943  		Expected: []sql.Row{
  6944  			{2, 1},
  6945  			{3, 2},
  6946  		},
  6947  	},
  6948  	{
  6949  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS x
  6950  						FROM one_pk opk WHERE (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) > 0
  6951  						GROUP BY x ORDER BY x`,
  6952  		Expected: []sql.Row{
  6953  			{2, 1},
  6954  			{3, 2},
  6955  		},
  6956  	},
  6957  	{
  6958  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS x
  6959  						FROM one_pk opk WHERE (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) > 0
  6960  						GROUP BY (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) ORDER BY x`,
  6961  		Expected: []sql.Row{
  6962  			{2, 1},
  6963  			{3, 2},
  6964  		},
  6965  	},
  6966  	{
  6967  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS x
  6968  						FROM one_pk opk WHERE (SELECT max(pk) FROM one_pk WHERE pk > opk.pk) > 0 ORDER BY x`,
  6969  		Expected: []sql.Row{
  6970  			{0, nil},
  6971  			{1, 0},
  6972  			{2, 1},
  6973  		},
  6974  	},
  6975  	{
  6976  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS x
  6977  						FROM one_pk opk WHERE (SELECT min(pk) FROM one_pk WHERE pk < opk.pk) > 0 ORDER BY x`,
  6978  		Expected: []sql.Row{},
  6979  	},
  6980  	{
  6981  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS x
  6982  						FROM one_pk opk WHERE (SELECT min(pk) FROM one_pk WHERE pk > opk.pk) > 0 ORDER BY x`,
  6983  		Expected: []sql.Row{
  6984  			{0, nil},
  6985  			{1, 0},
  6986  			{2, 1},
  6987  		},
  6988  	},
  6989  	{
  6990  		Query: `SELECT pk,
  6991  					(SELECT max(pk1) FROM two_pk WHERE pk1 < pk) AS max,
  6992  					(SELECT min(pk2) FROM two_pk WHERE pk2 > pk) AS min
  6993  					FROM one_pk ORDER BY min, pk;`,
  6994  		Expected: []sql.Row{
  6995  			{1, 0, nil},
  6996  			{2, 1, nil},
  6997  			{3, 1, nil},
  6998  			{0, nil, 1},
  6999  		},
  7000  	},
  7001  	{
  7002  		Query: `SELECT pk,
  7003  						(SELECT max(pk1) FROM two_pk tpk WHERE pk1 IN (SELECT pk1 FROM two_pk WHERE pk1 = tpk.pk2)) AS one,
  7004  						(SELECT min(pk2) FROM two_pk tpk WHERE pk2 IN (SELECT pk2 FROM two_pk WHERE pk2 = tpk.pk1)) AS zero
  7005  						FROM one_pk ORDER BY pk;`,
  7006  		Expected: []sql.Row{
  7007  			{0, 1, 0},
  7008  			{1, 1, 0},
  7009  			{2, 1, 0},
  7010  			{3, 1, 0},
  7011  		},
  7012  	},
  7013  	{
  7014  		Query: `SELECT pk,
  7015  						(SELECT sum(pk1+pk2) FROM two_pk WHERE pk1+pk2 IN (SELECT pk1+pk2 FROM two_pk WHERE pk1+pk2 = pk)) AS sum,
  7016  						(SELECT min(pk2) FROM two_pk WHERE pk2 IN (SELECT pk2 FROM two_pk WHERE pk2 = pk)) AS equal
  7017  						FROM one_pk ORDER BY pk;`,
  7018  		Expected: []sql.Row{
  7019  			{0, 0.0, 0},
  7020  			{1, 2.0, 1},
  7021  			{2, 2.0, nil},
  7022  			{3, nil, nil},
  7023  		},
  7024  	},
  7025  	{
  7026  		Query: `SELECT pk,
  7027  						(SELECT sum(c1) FROM two_pk WHERE c1 + 3 IN (SELECT c4 FROM two_pk WHERE c3 > opk.c5)) AS sum,
  7028  						(SELECT sum(c1) FROM two_pk WHERE pk2 IN (SELECT pk2 FROM two_pk WHERE c1 + 1 < opk.c2)) AS sum2
  7029  					FROM one_pk opk ORDER BY pk`,
  7030  		Expected: []sql.Row{
  7031  			{0, 60.0, nil},
  7032  			{1, 50.0, 20.0},
  7033  			{2, 30.0, 60.0},
  7034  			{3, nil, 60.0},
  7035  		},
  7036  	},
  7037  	{
  7038  		Query: `SELECT pk, (SELECT min(pk) FROM one_pk WHERE pk > opk.pk) FROM one_pk opk ORDER BY 1`,
  7039  		Expected: []sql.Row{
  7040  			{0, 1},
  7041  			{1, 2},
  7042  			{2, 3},
  7043  			{3, nil},
  7044  		},
  7045  	},
  7046  	{
  7047  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE one_pk.pk <= one_pk.pk) FROM one_pk ORDER BY 1`,
  7048  		Expected: []sql.Row{
  7049  			{0, 3},
  7050  			{1, 3},
  7051  			{2, 3},
  7052  			{3, 3},
  7053  		},
  7054  	},
  7055  	{
  7056  		Query: `SELECT pk as a, (SELECT max(pk) FROM one_pk WHERE pk <= a) FROM one_pk ORDER BY 1`,
  7057  		Expected: []sql.Row{
  7058  			{0, 0},
  7059  			{1, 1},
  7060  			{2, 2},
  7061  			{3, 3},
  7062  		},
  7063  	},
  7064  	{
  7065  		Query: `SELECT pk as a, (SELECT max(pk) FROM one_pk WHERE pk <= a) FROM one_pk opk ORDER BY 1`,
  7066  		Expected: []sql.Row{
  7067  			{0, 0},
  7068  			{1, 1},
  7069  			{2, 2},
  7070  			{3, 3},
  7071  		},
  7072  	},
  7073  	{
  7074  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk b WHERE b.pk <= opk.pk) FROM one_pk opk ORDER BY 1`,
  7075  		Expected: []sql.Row{
  7076  			{0, 0},
  7077  			{1, 1},
  7078  			{2, 2},
  7079  			{3, 3},
  7080  		},
  7081  	},
  7082  	{
  7083  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk <= pk) FROM one_pk opk ORDER BY 1`,
  7084  		Expected: []sql.Row{
  7085  			{0, 3},
  7086  			{1, 3},
  7087  			{2, 3},
  7088  			{3, 3},
  7089  		},
  7090  	},
  7091  	{
  7092  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk b WHERE b.pk <= pk) FROM one_pk opk ORDER BY 1`,
  7093  		Expected: []sql.Row{
  7094  			{0, 3},
  7095  			{1, 3},
  7096  			{2, 3},
  7097  			{3, 3},
  7098  		},
  7099  	},
  7100  	{
  7101  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk b WHERE b.pk <= one_pk.pk) FROM one_pk ORDER BY 1`,
  7102  		Expected: []sql.Row{
  7103  			{0, 0},
  7104  			{1, 1},
  7105  			{2, 2},
  7106  			{3, 3},
  7107  		},
  7108  	},
  7109  	{
  7110  		Query: `SELECT DISTINCT n FROM bigtable ORDER BY t`,
  7111  		Expected: []sql.Row{
  7112  			{int64(1)},
  7113  			{int64(9)},
  7114  			{int64(7)},
  7115  			{int64(3)},
  7116  			{int64(2)},
  7117  			{int64(8)},
  7118  			{int64(6)},
  7119  			{int64(5)},
  7120  			{int64(4)},
  7121  		},
  7122  	},
  7123  	{
  7124  		Query: "SELECT pk,pk1,pk2 FROM one_pk, two_pk ORDER BY 1,2,3",
  7125  		Expected: []sql.Row{
  7126  			{0, 0, 0},
  7127  			{0, 0, 1},
  7128  			{0, 1, 0},
  7129  			{0, 1, 1},
  7130  			{1, 0, 0},
  7131  			{1, 0, 1},
  7132  			{1, 1, 0},
  7133  			{1, 1, 1},
  7134  			{2, 0, 0},
  7135  			{2, 0, 1},
  7136  			{2, 1, 0},
  7137  			{2, 1, 1},
  7138  			{3, 0, 0},
  7139  			{3, 0, 1},
  7140  			{3, 1, 0},
  7141  			{3, 1, 1},
  7142  		},
  7143  	},
  7144  	{
  7145  		Query: "SELECT t1.c1,t2.c2 FROM one_pk t1, two_pk t2 WHERE pk1=1 AND pk2=1 ORDER BY 1,2",
  7146  		Expected: []sql.Row{
  7147  			{0, 31},
  7148  			{10, 31},
  7149  			{20, 31},
  7150  			{30, 31},
  7151  		},
  7152  	},
  7153  	{
  7154  		Query: "SELECT t1.i, t2.i FROM mytable t1, mytable t2 WHERE t2.i=1 AND t1.s = t2.s ORDER BY 1,2",
  7155  		Expected: []sql.Row{
  7156  			{1, 1},
  7157  		},
  7158  	},
  7159  	{
  7160  		Query: "SELECT t1.c1,t2.c2 FROM one_pk t1, two_pk t2 WHERE t2.pk1=1 AND t2.pk2=1 ORDER BY 1,2",
  7161  		Expected: []sql.Row{
  7162  			{0, 31},
  7163  			{10, 31},
  7164  			{20, 31},
  7165  			{30, 31},
  7166  		},
  7167  	},
  7168  	{
  7169  		Query: "SELECT t1.c1,t2.c2 FROM one_pk t1, two_pk t2 WHERE pk1=1 OR pk2=1 ORDER BY 1,2",
  7170  		Expected: []sql.Row{
  7171  			{0, 11},
  7172  			{0, 21},
  7173  			{0, 31},
  7174  			{10, 11},
  7175  			{10, 21},
  7176  			{10, 31},
  7177  			{20, 11},
  7178  			{20, 21},
  7179  			{20, 31},
  7180  			{30, 11},
  7181  			{30, 21},
  7182  			{30, 31},
  7183  		},
  7184  	},
  7185  	{
  7186  		Query: "SELECT pk,pk2 FROM one_pk t1, two_pk t2 WHERE pk=1 AND pk2=1 ORDER BY 1,2",
  7187  		Expected: []sql.Row{
  7188  			{1, 1},
  7189  			{1, 1},
  7190  		},
  7191  	},
  7192  	{
  7193  		Query: "SELECT pk,pk1,pk2 FROM one_pk,two_pk WHERE pk=0 AND pk1=0 OR pk2=1 ORDER BY 1,2,3",
  7194  		Expected: []sql.Row{
  7195  			{0, 0, 0},
  7196  			{0, 0, 1},
  7197  			{0, 1, 1},
  7198  			{1, 0, 1},
  7199  			{1, 1, 1},
  7200  			{2, 0, 1},
  7201  			{2, 1, 1},
  7202  			{3, 0, 1},
  7203  			{3, 1, 1},
  7204  		},
  7205  	},
  7206  	{
  7207  		Query: "SELECT pk,pk1,pk2 FROM one_pk,two_pk WHERE one_pk.c1=two_pk.c1 ORDER BY 1,2,3",
  7208  		Expected: []sql.Row{
  7209  			{0, 0, 0},
  7210  			{1, 0, 1},
  7211  			{2, 1, 0},
  7212  			{3, 1, 1},
  7213  		},
  7214  	},
  7215  	{
  7216  		Query: "SELECT one_pk.c5,pk1,pk2 FROM one_pk,two_pk WHERE pk=pk1 ORDER BY 1,2,3",
  7217  		Expected: []sql.Row{
  7218  			{4, 0, 0},
  7219  			{4, 0, 1},
  7220  			{14, 1, 0},
  7221  			{14, 1, 1},
  7222  		},
  7223  	},
  7224  	{
  7225  		Query: "SELECT opk.c5,pk1,pk2 FROM one_pk opk, two_pk tpk WHERE pk=pk1 ORDER BY 1,2,3",
  7226  		Expected: []sql.Row{
  7227  			{4, 0, 0},
  7228  			{4, 0, 1},
  7229  			{14, 1, 0},
  7230  			{14, 1, 1},
  7231  		},
  7232  	},
  7233  	{
  7234  		Query: "SELECT GREATEST(CAST(i AS CHAR), CAST(b AS CHAR)) FROM niltable order by i",
  7235  		Expected: []sql.Row{
  7236  			{nil},
  7237  			{"2"},
  7238  			{"3"},
  7239  			{nil},
  7240  			{"5"},
  7241  			{"6"},
  7242  		},
  7243  	},
  7244  	{
  7245  		Query: "SELECT CASE WHEN COUNT( * ) THEN 10 * CAST(-19 AS SIGNED ) + CAST(82 AS DECIMAL) END;",
  7246  		Expected: []sql.Row{
  7247  			{"-108"},
  7248  		},
  7249  	},
  7250  	{
  7251  		Query: "SELECT CASE WHEN COUNT( * ) THEN 10.0 * CAST(2012 AS UNSIGNED) + CAST(82 AS CHAR) END;",
  7252  		Expected: []sql.Row{
  7253  			{20202.0},
  7254  		},
  7255  	},
  7256  	{
  7257  		Query: "SELECT CASE WHEN COUNT( * ) THEN 10.0 * CAST(1234 AS DATE) + CAST(82 AS CHAR) END;",
  7258  		Expected: []sql.Row{
  7259  			{nil},
  7260  		},
  7261  	},
  7262  	{
  7263  		Query:    "SELECT 2.0 + CAST(5 AS DECIMAL)",
  7264  		Expected: []sql.Row{{"7.0"}},
  7265  	},
  7266  	{
  7267  		Query:    "SELECT (CASE WHEN i THEN i ELSE 0 END) as cases_i from mytable",
  7268  		Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}},
  7269  	},
  7270  	{
  7271  		Query:    `SELECT ALL - - 20 * - CASE + AVG ( ALL + + 89 ) WHEN - 66 THEN NULL WHEN - 15 THEN 38 * COUNT( * ) * MIN( DISTINCT - + 88 ) - MIN( ALL + 0 ) - - COUNT( * ) + - 0 + - 14 * + ( 98 ) * + 70 * 14 * + 57 * 48 - 53 + + 7 END * + 78 + - 11 * + 29 + + + 46 + + 10 + + ( - 83 ) * - - 74 / - 8 + 18`,
  7272  		Expected: []sql.Row{{nil}},
  7273  	},
  7274  	{
  7275  		Query:    "SELECT 1/0 FROM dual",
  7276  		Expected: []sql.Row{{nil}},
  7277  	},
  7278  	{
  7279  		Query:    "SELECT 0/0 FROM dual",
  7280  		Expected: []sql.Row{{nil}},
  7281  	},
  7282  	{
  7283  		Query:    "SELECT 1.0/0.0 FROM dual",
  7284  		Expected: []sql.Row{{nil}},
  7285  	},
  7286  	{
  7287  		Query:    "SELECT 0.0/0.0 FROM dual",
  7288  		Expected: []sql.Row{{nil}},
  7289  	},
  7290  	{
  7291  		Query:    "SELECT 1 div 0 FROM dual",
  7292  		Expected: []sql.Row{{nil}},
  7293  	},
  7294  	{
  7295  		Query:    "SELECT 1.0 div 0.0 FROM dual",
  7296  		Expected: []sql.Row{{nil}},
  7297  	},
  7298  	{
  7299  		Query:    "SELECT 0 div 0 FROM dual",
  7300  		Expected: []sql.Row{{nil}},
  7301  	},
  7302  	{
  7303  		Query:    "SELECT 0.0 div 0.0 FROM dual",
  7304  		Expected: []sql.Row{{nil}},
  7305  	},
  7306  	{
  7307  		Query:    "SELECT NULL <=> NULL FROM dual",
  7308  		Expected: []sql.Row{{true}},
  7309  	},
  7310  	{
  7311  		Query:    "SELECT POW(2,3) FROM dual",
  7312  		Expected: []sql.Row{{float64(8)}},
  7313  	},
  7314  	{
  7315  		Query: `SELECT /*+ JOIN_ORDER(a, c, b, d) */ a.c1, b.c2, c.c3, d.c4 FROM one_pk a JOIN one_pk b ON a.pk = b.pk JOIN one_pk c ON c.pk = b.pk JOIN (select * from one_pk) d ON d.pk = c.pk`,
  7316  		Expected: []sql.Row{
  7317  			{0, 1, 2, 3},
  7318  			{10, 11, 12, 13},
  7319  			{20, 21, 22, 23},
  7320  			{30, 31, 32, 33},
  7321  		},
  7322  	},
  7323  	{
  7324  		Query: "SELECT * FROM people WHERE last_name='doe' and first_name='jane' order by dob",
  7325  		Expected: []sql.Row{
  7326  			sql.NewRow(time.Date(1990, time.Month(2), 21, 0, 0, 0, 0, time.UTC), "jane", "doe", "", int64(68), int64(1)),
  7327  			sql.NewRow(time.Date(2010, time.Month(3), 15, 0, 0, 0, 0, time.UTC), "jane", "doe", "", int64(69), int64(1)),
  7328  		},
  7329  	},
  7330  	{
  7331  		Query: "SELECT count(*) FROM people WHERE last_name='doe' and first_name='jane' order by dob",
  7332  		Expected: []sql.Row{
  7333  			sql.NewRow(2),
  7334  		},
  7335  	},
  7336  	{
  7337  		Query: "SELECT VALUES(i) FROM mytable",
  7338  		Expected: []sql.Row{
  7339  			sql.NewRow(nil),
  7340  			sql.NewRow(nil),
  7341  			sql.NewRow(nil),
  7342  		},
  7343  	},
  7344  	{
  7345  		Query: `select i, row_number() over (order by i desc),
  7346  				row_number() over (order by length(s),i) from mytable order by 1;`,
  7347  		Expected: []sql.Row{
  7348  			{1, 3, 1},
  7349  			{2, 2, 3},
  7350  			{3, 1, 2},
  7351  		},
  7352  	},
  7353  	{
  7354  		Query: `select i, row_number() over (order by i desc) from mytable where i = 2 order by 1;`,
  7355  		Expected: []sql.Row{
  7356  			{2, 1},
  7357  		},
  7358  	},
  7359  	{
  7360  		Query: `SELECT i, (SELECT row_number() over (order by ot.i2 desc) FROM othertable ot where ot.i2 = mt.i) from mytable mt order by 1;`,
  7361  		Expected: []sql.Row{
  7362  			{1, 1},
  7363  			{2, 1},
  7364  			{3, 1},
  7365  		},
  7366  	},
  7367  	{
  7368  		Query: `select row_number() over (order by i desc),
  7369  				row_number() over (order by length(s),i) from mytable order by i;`,
  7370  		Expected: []sql.Row{
  7371  			{3, 1},
  7372  			{2, 3},
  7373  			{1, 2},
  7374  		},
  7375  	},
  7376  	{
  7377  		Query: `select *, row_number() over (order by i desc),
  7378  				row_number() over (order by length(s),i) from mytable order by i;`,
  7379  		Expected: []sql.Row{
  7380  			{1, "first row", 3, 1},
  7381  			{2, "second row", 2, 3},
  7382  			{3, "third row", 1, 2},
  7383  		},
  7384  	},
  7385  	{
  7386  		Query: `select row_number() over (order by i desc),
  7387  				row_number() over (order by length(s),i)
  7388  				from mytable mt join othertable ot
  7389  				on mt.i = ot.i2
  7390  				order by mt.i;`,
  7391  		Expected: []sql.Row{
  7392  			{3, 1},
  7393  			{2, 3},
  7394  			{1, 2},
  7395  		},
  7396  	},
  7397  	{
  7398  		Query: `select i, row_number() over (order by i desc),
  7399  				row_number() over (order by length(s),i) from mytable order by 1 desc;`,
  7400  		Expected: []sql.Row{
  7401  			{3, 1, 2},
  7402  			{2, 2, 3},
  7403  			{1, 3, 1},
  7404  		},
  7405  	},
  7406  	{
  7407  		Query: `select i, row_number() over (order by i desc) as i_num,
  7408  				row_number() over (order by length(s),i) as s_num from mytable order by 1;`,
  7409  		Expected: []sql.Row{
  7410  			{1, 3, 1},
  7411  			{2, 2, 3},
  7412  			{3, 1, 2},
  7413  		},
  7414  	},
  7415  	{
  7416  		Query: `select i, row_number() over (order by i desc) + 3,
  7417  			row_number() over (order by length(s),i) as s_asc,
  7418  			row_number() over (order by length(s) desc,i desc) as s_desc
  7419  			from mytable order by 1;`,
  7420  		Expected: []sql.Row{
  7421  			{1, 6, 1, 3},
  7422  			{2, 5, 3, 1},
  7423  			{3, 4, 2, 2},
  7424  		},
  7425  	},
  7426  	{
  7427  		Query: `select i, row_number() over (order by i desc) + 3,
  7428  			row_number() over (order by length(s),i) + 0.0 / row_number() over (order by length(s) desc,i desc) + 0.0
  7429  			from mytable order by 1;`,
  7430  		Expected: []sql.Row{
  7431  			{1, 6, "1.00000"},
  7432  			{2, 5, "3.00000"},
  7433  			{3, 4, "2.00000"},
  7434  		},
  7435  	},
  7436  	{
  7437  		Query: "select pk1, pk2, row_number() over (partition by pk1 order by c1 desc) from two_pk order by 1,2;",
  7438  		Expected: []sql.Row{
  7439  			{0, 0, 2},
  7440  			{0, 1, 1},
  7441  			{1, 0, 2},
  7442  			{1, 1, 1},
  7443  		},
  7444  	},
  7445  	{
  7446  		Query: `select pk1, pk2,
  7447  			row_number() over (partition by pk1 order by c1 desc)
  7448  			from two_pk order by 1,2;`,
  7449  		Expected: []sql.Row{
  7450  			{0, 0, 2},
  7451  			{0, 1, 1},
  7452  			{1, 0, 2},
  7453  			{1, 1, 1},
  7454  		},
  7455  	},
  7456  	{
  7457  		Query: `select pk1, pk2,
  7458  			row_number() over (partition by pk1 order by c1 desc),
  7459  			row_number() over (partition by pk2 order by 10 - c1)
  7460  			from two_pk order by 1,2;`,
  7461  		Expected: []sql.Row{
  7462  			{0, 0, 2, 2},
  7463  			{0, 1, 1, 2},
  7464  			{1, 0, 2, 1},
  7465  			{1, 1, 1, 1},
  7466  		},
  7467  	},
  7468  	{
  7469  		Query: `select pk1, pk2,
  7470  			row_number() over (partition by pk1 order by c1 desc),
  7471  			row_number() over (partition by pk2 order by 10 - c1),
  7472  			max(c4) over ()
  7473  			from two_pk order by 1,2;`,
  7474  		Expected: []sql.Row{
  7475  			{0, 0, 2, 2, 33},
  7476  			{0, 1, 1, 2, 33},
  7477  			{1, 0, 2, 1, 33},
  7478  			{1, 1, 1, 1, 33},
  7479  		},
  7480  	},
  7481  	{
  7482  		Query: "SELECT pk, row_number() over (partition by v2 order by pk ), max(v3) over (partition by v2 order by pk) FROM one_pk_three_idx ORDER BY pk",
  7483  		Expected: []sql.Row{
  7484  			{0, 1, 3},
  7485  			{1, 2, 3},
  7486  			{2, 1, 0},
  7487  			{3, 1, 2},
  7488  			{4, 3, 3},
  7489  			{5, 4, 3},
  7490  			{6, 1, 0},
  7491  			{7, 1, 4},
  7492  		},
  7493  	},
  7494  	{
  7495  		Query: "SELECT pk, count(*) over (order by v2) FROM one_pk_three_idx ORDER BY pk",
  7496  		Expected: []sql.Row{
  7497  			{0, 4},
  7498  			{1, 4},
  7499  			{2, 5},
  7500  			{3, 6},
  7501  			{4, 4},
  7502  			{5, 4},
  7503  			{6, 7},
  7504  			{7, 8},
  7505  		},
  7506  	},
  7507  	{
  7508  		Query: "SELECT pk, count(*) over (partition by v2) FROM one_pk_three_idx ORDER BY pk",
  7509  		Expected: []sql.Row{
  7510  			{0, 4},
  7511  			{1, 4},
  7512  			{2, 1},
  7513  			{3, 1},
  7514  			{4, 4},
  7515  			{5, 4},
  7516  			{6, 1},
  7517  			{7, 1},
  7518  		},
  7519  	},
  7520  	{
  7521  		Query: "SELECT pk, row_number() over (order by v2, pk), max(pk) over () from one_pk_three_idx ORDER BY pk",
  7522  		Expected: []sql.Row{
  7523  			{0, 1, 7},
  7524  			{1, 2, 7},
  7525  			{2, 5, 7},
  7526  			{3, 6, 7},
  7527  			{4, 3, 7},
  7528  			{5, 4, 7},
  7529  			{6, 7, 7},
  7530  			{7, 8, 7},
  7531  		},
  7532  	},
  7533  	{
  7534  		Query: `select i,
  7535  			row_number() over (partition by case when i > 2 then "under two" else "over two" end order by i desc) as s_asc
  7536  			from mytable order by 1;`,
  7537  		Expected: []sql.Row{
  7538  			{1, 2},
  7539  			{2, 1},
  7540  			{3, 1},
  7541  		},
  7542  	},
  7543  	{
  7544  		Query: "SELECT BINARY 'hi'",
  7545  		Expected: []sql.Row{
  7546  			{[]byte("hi")},
  7547  		},
  7548  	},
  7549  	{
  7550  		Query: "SELECT BINARY 1",
  7551  		Expected: []sql.Row{
  7552  			{[]byte("1")},
  7553  		},
  7554  	},
  7555  	{
  7556  		Query: "SELECT BINARY 1 = 1",
  7557  		Expected: []sql.Row{
  7558  			{true},
  7559  		},
  7560  	},
  7561  	{
  7562  		Query: "SELECT BINARY 'hello' = 'hello'",
  7563  		Expected: []sql.Row{
  7564  			{true},
  7565  		},
  7566  	},
  7567  	{
  7568  		Query: "SELECT BINARY NULL",
  7569  		Expected: []sql.Row{
  7570  			{nil},
  7571  		},
  7572  	},
  7573  	{
  7574  		Query:    "SELECT JSON_CONTAINS(NULL, 1)",
  7575  		Expected: []sql.Row{{nil}},
  7576  	},
  7577  	{
  7578  		Query:    "SELECT JSON_CONTAINS('1', NULL)",
  7579  		Expected: []sql.Row{{nil}},
  7580  	},
  7581  	{
  7582  		Query:    "SELECT JSON_CONTAINS('1', '1')",
  7583  		Expected: []sql.Row{{true}},
  7584  	},
  7585  	{
  7586  		Query:    "SELECT JSON_CONTAINS('1', NULL, '$.a')",
  7587  		Expected: []sql.Row{{nil}},
  7588  	},
  7589  	{
  7590  		Query:    `SELECT JSON_CONTAINS('{"a": 1, "b": 2, "c": {"d": 4}}', '1', '$.a')`,
  7591  		Expected: []sql.Row{{true}},
  7592  	},
  7593  	{
  7594  		Query:    `SELECT JSON_CONTAINS('{"a": 1, "b": 2, "c": {"d": 4}}', '1', '$.b')`,
  7595  		Expected: []sql.Row{{false}},
  7596  	},
  7597  	{
  7598  		Query:    `SELECT JSON_CONTAINS('{"a": 1, "b": 2, "c": {"d": 4}}', '{"d": 4}', '$.a')`,
  7599  		Expected: []sql.Row{{false}},
  7600  	},
  7601  	{
  7602  		Query:    `SELECT JSON_CONTAINS('{"a": 1, "b": 2, "c": {"d": 4}}', '{"d": 4}', '$.c')`,
  7603  		Expected: []sql.Row{{true}},
  7604  	},
  7605  	{
  7606  		Query: "select one_pk.pk, one_pk.c1 from one_pk join two_pk on one_pk.c1 = two_pk.c1 order by two_pk.c1",
  7607  		Expected: []sql.Row{
  7608  			{0, 0},
  7609  			{1, 10},
  7610  			{2, 20},
  7611  			{3, 30},
  7612  		},
  7613  	},
  7614  	{
  7615  		Query: `SELECT JSON_OBJECT(1000000, 10);`,
  7616  		Expected: []sql.Row{
  7617  			{types.MustJSON(`{"1000000": 10}`)},
  7618  		},
  7619  	},
  7620  	{
  7621  		Query: `SELECT JSON_OBJECT(DATE('1981-02-16'), 10);`,
  7622  		Expected: []sql.Row{
  7623  			{types.MustJSON(`{"1981-02-16": 10}`)},
  7624  		},
  7625  	},
  7626  	{
  7627  		SkipServerEngine: true, // the over the wire result need the double quotes to be escaped
  7628  		Query:            `SELECT JSON_OBJECT(JSON_OBJECT("foo", "bar"), 10);`,
  7629  		Expected: []sql.Row{
  7630  			{types.MustJSON(`{"{\"foo\": \"bar\"}": 10}`)},
  7631  		},
  7632  	},
  7633  	{
  7634  		Query: `SELECT JSON_OBJECT(true, 10);`,
  7635  		Expected: []sql.Row{
  7636  			{types.MustJSON(`{"1": 10}`)},
  7637  		},
  7638  	},
  7639  	{
  7640  		Query: `SELECT JSON_OBJECT(10.1, 10);`,
  7641  		Expected: []sql.Row{
  7642  			{types.MustJSON(`{"10.1": 10}`)},
  7643  		},
  7644  	},
  7645  
  7646  	{
  7647  		Query: `SELECT JSON_OBJECT("i",i,"s",s) as js FROM mytable;`,
  7648  		Expected: []sql.Row{
  7649  			{types.MustJSON(`{"i": 1, "s": "first row"}`)},
  7650  			{types.MustJSON(`{"i": 2, "s": "second row"}`)},
  7651  			{types.MustJSON(`{"i": 3, "s": "third row"}`)},
  7652  		},
  7653  		ExpectedColumns: sql.Schema{
  7654  			{
  7655  				Name: "js",
  7656  				Type: types.JSON,
  7657  			},
  7658  		},
  7659  	},
  7660  	{
  7661  		Query: `SELECT CONVERT_TZ("2004-01-01 4:00:00", "+00:00", "+04:00")`,
  7662  		Expected: []sql.Row{
  7663  			{time.Date(2004, 1, 1, 8, 0, 0, 0, time.UTC)},
  7664  		},
  7665  	},
  7666  	{
  7667  		Query: `SELECT CONVERT_TZ(datetime_col, "+00:00", "+04:00") FROM datetime_table WHERE i = 1`,
  7668  		Expected: []sql.Row{
  7669  			{time.Date(2020, 1, 1, 16, 0, 0, 0, time.UTC)},
  7670  		},
  7671  	},
  7672  	{
  7673  		Query: `SELECT 1 from dual WHERE EXISTS (SELECT 1 from dual);`,
  7674  		Expected: []sql.Row{
  7675  			{1},
  7676  		},
  7677  	},
  7678  	{
  7679  		Query: `SELECT 1 from dual WHERE EXISTS (SELECT NULL from dual);`,
  7680  		Expected: []sql.Row{
  7681  			{1},
  7682  		},
  7683  	},
  7684  	{
  7685  		Query: `SELECT i FROM mytable WHERE EXISTS (SELECT 1 from mytable) AND i IS NOT NULL;`,
  7686  		Expected: []sql.Row{
  7687  			{1},
  7688  			{2},
  7689  			{3},
  7690  		},
  7691  	},
  7692  	{
  7693  		Query:    `SELECT * FROM two_pk WHERE EXISTS (SELECT pk FROM one_pk WHERE pk > 4)`,
  7694  		Expected: []sql.Row{},
  7695  	},
  7696  	{
  7697  		Query:    `SELECT 2 + 2 WHERE NOT EXISTS (SELECT pk FROM one_pk WHERE pk > 4)`,
  7698  		Expected: []sql.Row{{4}},
  7699  	},
  7700  	{
  7701  		Query:    `SELECT 2 + 2 WHERE NOT EXISTS (SELECT * FROM one_pk WHERE pk > 4)`,
  7702  		Expected: []sql.Row{{4}},
  7703  	},
  7704  	{
  7705  		Query:    `SELECT 2 + 2 WHERE EXISTS (SELECT * FROM one_pk WHERE pk < 4)`,
  7706  		Expected: []sql.Row{{4}},
  7707  	},
  7708  	{
  7709  		Query:    `SELECT distinct pk1 FROM two_pk WHERE EXISTS (SELECT pk from one_pk where pk <= two_pk.pk1)`,
  7710  		Expected: []sql.Row{{0}, {1}},
  7711  	},
  7712  	{
  7713  		Query:    `select pk from one_pk where exists (SELECT pk1 FROM two_pk);`,
  7714  		Expected: []sql.Row{{0}, {1}, {2}, {3}},
  7715  	},
  7716  	{
  7717  		Query:    `SELECT EXISTS (SELECT NULL from dual);`,
  7718  		Expected: []sql.Row{{true}},
  7719  	},
  7720  	{
  7721  		Query:    `SELECT NOT EXISTS (SELECT NULL FROM dual)`,
  7722  		Expected: []sql.Row{{false}},
  7723  	},
  7724  	{
  7725  		Query:    `select exists (SELECT pk1 FROM two_pk);`,
  7726  		Expected: []sql.Row{{true}},
  7727  	},
  7728  	{
  7729  		Query:    `SELECT EXISTS (SELECT pk FROM one_pk WHERE pk > 4)`,
  7730  		Expected: []sql.Row{{false}},
  7731  	},
  7732  	{
  7733  		Query:    `START TRANSACTION READ ONLY`,
  7734  		Expected: []sql.Row{},
  7735  	},
  7736  	{
  7737  		Query:    `START TRANSACTION READ WRITE`,
  7738  		Expected: []sql.Row{},
  7739  	},
  7740  	{
  7741  		Query: `SHOW STATUS LIKE 'use_secondary_engine'`,
  7742  		Expected: []sql.Row{
  7743  			{"use_secondary_engine", "ON"},
  7744  		},
  7745  	},
  7746  	{
  7747  		Query: `SHOW GLOBAL STATUS LIKE 'admin_port'`,
  7748  		Expected: []sql.Row{
  7749  			{"admin_port", 33062},
  7750  		},
  7751  	},
  7752  	{
  7753  		Query: `SHOW SESSION STATUS LIKE 'auto_increment_increment'`,
  7754  		Expected: []sql.Row{
  7755  			{"auto_increment_increment", 1},
  7756  		},
  7757  	},
  7758  	{
  7759  		Query:    `SHOW GLOBAL STATUS LIKE 'use_secondary_engine'`,
  7760  		Expected: []sql.Row{},
  7761  	},
  7762  	{
  7763  		Query:    `SHOW SESSION STATUS LIKE 'version'`,
  7764  		Expected: []sql.Row{},
  7765  	},
  7766  	{
  7767  		Query:    `SHOW SESSION STATUS LIKE 'Ssl_cipher'`,
  7768  		Expected: []sql.Row{}, // TODO: should be added at some point
  7769  	},
  7770  	{
  7771  		Query: `SHOW SESSION STATUS WHERE Value < 0`,
  7772  		Expected: []sql.Row{
  7773  			{"optimizer_trace_offset", -1},
  7774  		},
  7775  	},
  7776  	{
  7777  		Query: `SELECT a.* FROM invert_pk as a, invert_pk as b WHERE a.y = b.z`,
  7778  		Expected: []sql.Row{
  7779  			{1, 1, 0},
  7780  			{2, 0, 1},
  7781  			{0, 2, 2},
  7782  		},
  7783  	},
  7784  	{
  7785  		Query: `SELECT a.* FROM invert_pk as a, invert_pk as b WHERE a.y = b.z AND a.z = 2`,
  7786  		Expected: []sql.Row{
  7787  			{0, 2, 2},
  7788  		},
  7789  	},
  7790  	{
  7791  		Query: `SELECT * FROM invert_pk WHERE y = 0`,
  7792  		Expected: []sql.Row{
  7793  			{2, 0, 1},
  7794  		},
  7795  	},
  7796  	{
  7797  		Query: `SELECT * FROM invert_pk WHERE y >= 0`,
  7798  		Expected: []sql.Row{
  7799  			{2, 0, 1},
  7800  			{0, 2, 2},
  7801  			{1, 1, 0},
  7802  		},
  7803  	},
  7804  	{
  7805  		Query: `SELECT * FROM invert_pk WHERE y >= 0 AND z < 1`,
  7806  		Expected: []sql.Row{
  7807  			{1, 1, 0},
  7808  		},
  7809  	},
  7810  	{
  7811  		Query:    `select c1 from jsontable where c1 LIKE (('%' OR 'dsads') OR '%')`,
  7812  		Expected: []sql.Row{},
  7813  	},
  7814  	{
  7815  		Query:    `select c1 from jsontable where c1 LIKE ('%' OR NULL)`,
  7816  		Expected: []sql.Row{},
  7817  	},
  7818  	{
  7819  		Query:    `select (('%' OR 'dsads') OR '%')`,
  7820  		Expected: []sql.Row{{false}},
  7821  	},
  7822  	{
  7823  		Query:    `show function status`,
  7824  		Expected: []sql.Row{},
  7825  	},
  7826  	{
  7827  		Query:    `show function status like 'foo'`,
  7828  		Expected: []sql.Row{},
  7829  	},
  7830  	{
  7831  		Query:    `show function status where Db='mydb'`,
  7832  		Expected: []sql.Row{},
  7833  	},
  7834  	{
  7835  		Query: `select uuid() = uuid()`,
  7836  		Expected: []sql.Row{
  7837  			{false},
  7838  		},
  7839  	},
  7840  	{
  7841  		Query:    `select instr(REPLACE(CONVERT(UUID() USING utf8mb4), '-', ''), '-')`,
  7842  		Expected: []sql.Row{{0}},
  7843  	},
  7844  	{
  7845  		Query:    `select * from mytable where 1 = 0 order by i asc`,
  7846  		Expected: []sql.Row{},
  7847  	},
  7848  	{
  7849  		Query:    `select * from mytable where i not in (1)`,
  7850  		Expected: []sql.Row{{2, "second row"}, {3, "third row"}},
  7851  	},
  7852  	{
  7853  		Query:    "(SELECT '1', 'first row' FROM dual) UNION (SELECT '6', 'sixth row' FROM dual) LIMIT 1",
  7854  		Expected: []sql.Row{{"1", "first row"}},
  7855  	},
  7856  	{
  7857  		Query:    "select GET_LOCK('10', 10)",
  7858  		Expected: []sql.Row{{1}},
  7859  	},
  7860  	{
  7861  		Query:    "Select IS_FREE_LOCK('10')",
  7862  		Expected: []sql.Row{{0}},
  7863  	},
  7864  	{
  7865  		Query:    "Select IS_USED_LOCK('10')",
  7866  		Expected: []sql.Row{{uint64(1)}},
  7867  	},
  7868  	{
  7869  		Query:    "Select RELEASE_LOCK('10')",
  7870  		Expected: []sql.Row{{1}},
  7871  	},
  7872  	{
  7873  		Query:    "Select RELEASE_ALL_LOCKS()",
  7874  		Expected: []sql.Row{{0}},
  7875  	},
  7876  	{
  7877  		Query:    "SELECT CONV('a',16,2)",
  7878  		Expected: []sql.Row{{"1010"}},
  7879  	},
  7880  	{
  7881  		Query:    "SELECT CONV('6E',18,8)",
  7882  		Expected: []sql.Row{{"172"}},
  7883  	},
  7884  	{
  7885  		Query:    "SELECT CONV(-18,10,-18)",
  7886  		Expected: []sql.Row{{"-10"}},
  7887  	},
  7888  	{
  7889  		Query:    "SELECT CONV(10+'10'+'10'+X'0a', 10, 10)",
  7890  		Expected: []sql.Row{{"40"}},
  7891  	},
  7892  	{
  7893  		Query:    "SELECT CONV(HEX(SUBSTRING('127.0', 1, 3)), 16, 10)",
  7894  		Expected: []sql.Row{{"3224119"}},
  7895  	},
  7896  	{
  7897  		Query:    "SELECT CONV(i, 10, 2) FROM mytable",
  7898  		Expected: []sql.Row{{"1"}, {"10"}, {"11"}},
  7899  	},
  7900  	{
  7901  		Query:    `SELECT t1.pk from one_pk join (one_pk t1 join one_pk t2 on t1.pk = t2.pk) on t1.pk = one_pk.pk and one_pk.pk = 1 join (one_pk t3 join one_pk t4 on t3.c1 is not null) on t3.pk = one_pk.pk and one_pk.c1 = 10`,
  7902  		Expected: []sql.Row{{1}, {1}, {1}, {1}},
  7903  	},
  7904  	{
  7905  		Query:    "select i from mytable where i in (select (select i from mytable order by i limit 1) as i)",
  7906  		Expected: []sql.Row{{1}},
  7907  	},
  7908  	{
  7909  		Query:    "with recursive a as (select 1 union select 2) select * from a union select * from a limit 1;",
  7910  		Expected: []sql.Row{{1}},
  7911  	},
  7912  	{
  7913  		Query:    "with recursive a(x) as (select 1 union select 2) select * from a having x > 1 union select * from a having x > 1;",
  7914  		Expected: []sql.Row{{2}},
  7915  	},
  7916  	{
  7917  		Query:    "with recursive a(x) as (select 1 union select 2) select * from a where x > 1 union select * from a where x > 1;",
  7918  		Expected: []sql.Row{{2}},
  7919  	},
  7920  	{
  7921  		Query:    "with recursive a(x) as (select 1 union select 2) select * from a union select * from a group by x;",
  7922  		Expected: []sql.Row{{1}, {2}},
  7923  	},
  7924  	{
  7925  		Query:    "with recursive a(x) as (select 1 union select 2) select * from a union select * from a order by x desc;",
  7926  		Expected: []sql.Row{{2}, {1}},
  7927  	},
  7928  	{
  7929  		Query:    `WITH recursive n(i) as (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i+1 <= 10 LIMIT 5) SELECT count(i) FROM n;`,
  7930  		Expected: []sql.Row{{5}},
  7931  	},
  7932  	{
  7933  		Query:    `WITH recursive n(i) as (SELECT 1 UNION ALL SELECT i + 1 FROM n GROUP BY i HAVING i+1 <= 10) SELECT count(i) FROM n;`,
  7934  		Expected: []sql.Row{{10}},
  7935  	},
  7936  	{
  7937  		Query:    `WITH recursive n(i) as (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i+1 <= 10 GROUP BY i HAVING i+1 <= 10 ORDER BY 1 LIMIT 5) SELECT count(i) FROM n;`,
  7938  		Expected: []sql.Row{{5}},
  7939  	},
  7940  	{
  7941  		Query:    `WITH recursive n(i) as (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i+1 <= 10 LIMIT 1) SELECT count(i) FROM n;`,
  7942  		Expected: []sql.Row{{1}},
  7943  	},
  7944  	{
  7945  		Query:    "with recursive a as (select 1 union select 2) select * from (select 1 where 1 in (select * from a)) as `temp`",
  7946  		Expected: []sql.Row{{1}},
  7947  	},
  7948  	{
  7949  		Query:    "select 1 union select * from (select 2 union select 3) a union select 4;",
  7950  		Expected: []sql.Row{{1}, {2}, {3}, {4}},
  7951  	},
  7952  	{
  7953  		Query:    "select 1 union select * from (select 2 union select 3) a union select 4;",
  7954  		Expected: []sql.Row{{1}, {2}, {3}, {4}},
  7955  	},
  7956  	{
  7957  		Query:    "With recursive a(x) as (select 1 union select 4 union select * from (select 2 union select 3) b union select x+1 from a where x < 10) select count(*) from a;",
  7958  		Expected: []sql.Row{{10}},
  7959  	},
  7960  	{
  7961  		Query:    "with a(j) as (select 1), b(i) as (select 2) select j from a union (select i from b order by 1 desc) union select j from a;",
  7962  		Expected: []sql.Row{{1}, {2}},
  7963  	},
  7964  	{
  7965  		Query:    "with a(j) as (select 1), b(i) as (select 2) (select t1.j as k from a t1 join a t2 on t1.j = t2.j union select i from b order by k desc limit 1) union select j from a;",
  7966  		Expected: []sql.Row{{2}},
  7967  	},
  7968  	{
  7969  		Query:    "with a(j) as (select 1 union select 2 union select 3), b(i) as (select 2 union select 3) (select t1.j as k from a t1 join a t2 on t1.j = t2.j union select i from b order by k desc limit 2) union select j from a;",
  7970  		Expected: []sql.Row{{3}, {2}},
  7971  	},
  7972  	{
  7973  		Query:    "with a(j) as (select 1), b(i) as (select 2) (select j from a union select i from b order by j desc limit 1) union select j from a;",
  7974  		Expected: []sql.Row{{2}},
  7975  	},
  7976  	{
  7977  		Query:    "with a(j) as (select 1), b(i) as (select 2) (select j from a union select i from b order by 1 limit 1) union select j from a;",
  7978  		Expected: []sql.Row{{1}},
  7979  	},
  7980  	{
  7981  		Query:    "with a(j) as (select 1), b(i) as (select 1) (select j from a union all select i from b) union select j from a;",
  7982  		Expected: []sql.Row{{1}},
  7983  	},
  7984  	{
  7985  		Query: `
  7986  With c as (
  7987    select * from (
  7988      select a.s
  7989      From mytable a
  7990      Join (
  7991        Select t2.*
  7992        From mytable t2
  7993        Where t2.i in (1,2)
  7994      ) b
  7995      On a.i = b.i
  7996      Join (
  7997        select t1.*
  7998        from mytable t1
  7999        Where t1.I in (2,3)
  8000      ) e
  8001      On b.I = e.i
  8002    ) d   
  8003  ) select * from c;`,
  8004  		Expected: []sql.Row{{"second row"}},
  8005  	},
  8006  	{
  8007  		// https://github.com/dolthub/dolt/issues/4478
  8008  		Query:    "SELECT STRCMP('b', 'a');",
  8009  		Expected: []sql.Row{{1}},
  8010  	},
  8011  	{
  8012  		// https://github.com/dolthub/dolt/issues/4478
  8013  		Query:    "SELECT STRCMP((SELECT CONCAT('a', 'b')), (SELECT SUBSTRING('cab', 2, 3)));",
  8014  		Expected: []sql.Row{{0}},
  8015  	},
  8016  	{
  8017  		// https://github.com/dolthub/dolt/issues/5068 - verify that decimal parses as decimal
  8018  		Query:    "SELECT 809826404100301269648758758005707100;",
  8019  		Expected: []sql.Row{{"809826404100301269648758758005707100"}},
  8020  	},
  8021  	{
  8022  		// https://github.com/dolthub/dolt/issues/5068 - verify that decimal parses as decimal
  8023  		Query:    "SELECT 809826404100301269648758758005707100.12345;",
  8024  		Expected: []sql.Row{{"809826404100301269648758758005707100.12345"}},
  8025  	},
  8026  	{
  8027  		// https://github.com/dolthub/dolt/issues/5068 - verify that uint64 still parses as uint64
  8028  		Query:    "SELECT 4294967295;",
  8029  		Expected: []sql.Row{{uint64(4294967295)}},
  8030  	},
  8031  	{
  8032  		// https://github.com/dolthub/dolt/issues/5068 - verify that int64 still parses as int64
  8033  		Query:    "SELECT 4294967296;",
  8034  		Expected: []sql.Row{{int64(4294967296)}},
  8035  	},
  8036  	{
  8037  		// https://github.com/dolthub/dolt/issues/5522
  8038  		Query:    "select * from mytable where exists (select * from othertable where 1 = 0)",
  8039  		Expected: []sql.Row{},
  8040  	},
  8041  	// tests to verify this issue is fixed: https://github.com/dolthub/dolt/issues/5522
  8042  	{
  8043  		// original query from issue
  8044  		Query:    "select count(*) from ab where exists (select * from xy where 1 = 0);",
  8045  		Expected: []sql.Row{{0}},
  8046  	},
  8047  	{
  8048  		// false filter and a table
  8049  		Query: "select a from ab where false;",
  8050  	},
  8051  	{
  8052  		// false filter and a join
  8053  		Query: "select a, u from (ab cross join uv) where false;",
  8054  	},
  8055  	{
  8056  		// false filter and a subquery
  8057  		Query: `select a1.u
  8058  from (select * from uv) a1
  8059  where a1.u = 1 AND false;`,
  8060  	},
  8061  	{
  8062  		// false filter on a subquery
  8063  		Query: `/*h1*/select a1.u
  8064  from (select * from uv where false) a1
  8065  where a1.u = 1;`,
  8066  		Expected: []sql.Row{},
  8067  	},
  8068  	{
  8069  		// multiple false filter EXISTS clauses
  8070  		Query: `select a, b from ab where
  8071  exists (select * from xy where false)
  8072  or exists (select * from uv where false);`,
  8073  	},
  8074  	{
  8075  		// nested false filter EXISTS clauses
  8076  		Query: `select a,b from ab where
  8077  exists (select * from xy where
  8078      exists (select * from uv where false));`,
  8079  	},
  8080  	{
  8081  		// nested subqueries and aliases
  8082  		Query: `select *
  8083  	from (select * from xy where x = 1 and x in
  8084  	   (select * from (select 1 where false) a1)
  8085  	) a2;`,
  8086  		Expected: []sql.Row{},
  8087  	},
  8088  	{
  8089  		// relation is a query
  8090  		Query: "select a1.a from (select * from ab) a1 where exists (select * from xy where 1 = 0);",
  8091  	},
  8092  	{
  8093  		// relation is a group by
  8094  		Query: "select a1.a from (select * from ab group by a, b) a1 where exists (select x from xy where 1 = 0);",
  8095  	},
  8096  	{
  8097  		// relation is a window
  8098  		Query: "select a1.s from (select sum(a) over() as s from ab) a1 where exists (select * from xy where 1 = 0);",
  8099  	},
  8100  	{
  8101  		// relation is a CTE
  8102  		Query: `with cte1 as (select * from ab)
  8103  select *
  8104  from xy
  8105  where exists (select * from cte1 where 1 = 0);`,
  8106  	},
  8107  	{
  8108  		// relation is a recursive CTE
  8109  		Query: `
  8110  with recursive my_cte as
  8111  (
  8112    select 1 as f, 1 as next_f
  8113    union all
  8114    select next_f, f+next_f from my_cte where f < 50
  8115  )
  8116  select * from my_cte
  8117  where exists (select * from ab where 1 = 0);`,
  8118  		Expected: []sql.Row{},
  8119  	},
  8120  	{
  8121  		// relation is a table function
  8122  		Query: `SELECT count(*)
  8123  FROM
  8124  JSON_TABLE(
  8125  	'[{"a":1.5, "b":2.25},{"a":3.125, "b":4.0625}]',
  8126  	'$[*]' COLUMNS(x float path '$.a', y float path '$.b')
  8127  ) as t1
  8128  where exists (select * from ab where 1 = 0);`,
  8129  		Expected: []sql.Row{{0}},
  8130  	},
  8131  	{
  8132  		// false having
  8133  		Query: `select x from xy as t1 group by t1.x having exists (select * from ab where 1 = 0);`,
  8134  	},
  8135  	{
  8136  		// false having
  8137  		Query: `select * from xy where x in (select 1 having false);`,
  8138  	},
  8139  	{
  8140  		// indexed table access test
  8141  		Query: "select * from (select * from xy where false) s where s.x = 2;",
  8142  	},
  8143  	{
  8144  		// projections
  8145  		Query: "select * from xy where exists (select a, true, a*7 from ab where false);",
  8146  	},
  8147  	{
  8148  		// nested empty function calls
  8149  		Query: `select * from xy
  8150  where not exists (
  8151    select * from ab
  8152    where false and exists (
  8153      select 1 where false
  8154    )
  8155  )`,
  8156  		Expected: []sql.Row{
  8157  			{0, 2},
  8158  			{1, 0},
  8159  			{2, 1},
  8160  			{3, 3},
  8161  		},
  8162  	},
  8163  	{
  8164  		// https://github.com/dolthub/dolt/issues/5549 - verify that recursive CTE outputs are correct
  8165  		Query: `WITH RECURSIVE my_cte AS
  8166  (
  8167    SELECT 1 as f, 1 as next_f
  8168    UNION ALL
  8169    SELECT next_f, f+next_f FROM my_cte WHERE f < 1000
  8170  )
  8171  SELECT * FROM my_cte;`,
  8172  		Expected: []sql.Row{
  8173  			{1, 1},
  8174  			{1, 2},
  8175  			{2, 3},
  8176  			{3, 5},
  8177  			{5, 8},
  8178  			{8, 13},
  8179  			{13, 21},
  8180  			{21, 34},
  8181  			{34, 55},
  8182  			{55, 89},
  8183  			{89, 144},
  8184  			{144, 233},
  8185  			{233, 377},
  8186  			{377, 610},
  8187  			{610, 987},
  8188  			{987, 1597},
  8189  			{1597, 2584},
  8190  		},
  8191  		ExpectedColumns: sql.Schema{
  8192  			{
  8193  				Name: "f",
  8194  				Type: types.Int64,
  8195  			},
  8196  			{
  8197  				Name: "next_f",
  8198  				Type: types.Int64,
  8199  			},
  8200  		},
  8201  	},
  8202  	// Regression test for https://github.com/dolthub/dolt/issues/5656
  8203  	{
  8204  		Query: "select count((select * from (select pk from one_pk limit 1) as sq)) from one_pk;",
  8205  		Expected: []sql.Row{
  8206  			{4},
  8207  		},
  8208  	},
  8209  	{
  8210  		Query: "select find_in_set('second row', s) from mytable;",
  8211  		Expected: []sql.Row{
  8212  			{0},
  8213  			{1},
  8214  			{0},
  8215  		},
  8216  	},
  8217  	{
  8218  		Query: "select find_in_set(s, 'first row,second row,third row') from mytable;",
  8219  		Expected: []sql.Row{
  8220  			{1},
  8221  			{2},
  8222  			{3},
  8223  		},
  8224  	},
  8225  	{
  8226  		Query: "select i from mytable where find_in_set(s, 'first row,second row,third row') = 2;",
  8227  		Expected: []sql.Row{
  8228  			{2},
  8229  		},
  8230  	},
  8231  	{
  8232  		// Original Issue: https://github.com/dolthub/dolt/issues/5714
  8233  		Query: `
  8234  	
  8235  	SELECT COUNT(*)
  8236  	FROM keyless
  8237  	WHERE keyless.c0 IN (
  8238  	
  8239  		WITH RECURSIVE cte(depth, i, j) AS (
  8240  		    SELECT 0, T1.c0, T1.c1
  8241  		    FROM keyless T1
  8242  		    WHERE T1.c0 = 0
  8243  	
  8244  		    UNION ALL
  8245  	
  8246  		    SELECT cte.depth + 1, cte.i, T2.c1 + 1
  8247  		    FROM cte, keyless T2
  8248  		    WHERE cte.depth = T2.c0
  8249  		)
  8250  	
  8251  		SELECT U0.c0
  8252  		FROM keyless U0, cte
  8253  		WHERE cte.j = keyless.c0
  8254  	
  8255  	)
  8256      ORDER BY c0;
  8257  `,
  8258  		Expected: []sql.Row{
  8259  			{4},
  8260  		},
  8261  	},
  8262  	{
  8263  		// Original Issue: https://github.com/dolthub/dolt/issues/5714
  8264  		// Similar, but this time the subquery is on the left
  8265  		Query: `
  8266  	
  8267  	SELECT COUNT(*)
  8268  	FROM keyless
  8269  	WHERE keyless.c0 IN (
  8270  	
  8271  		WITH RECURSIVE cte(depth, i, j) AS (
  8272  		    SELECT 0, T1.c0, T1.c1
  8273  		    FROM keyless T1
  8274  		    WHERE T1.c0 = 0
  8275  	
  8276  		    UNION ALL
  8277  	
  8278  		    SELECT cte.depth + 1, cte.i, T2.c1 + 1
  8279  		    FROM cte, keyless T2
  8280  		    WHERE cte.depth = T2.c0
  8281  		)
  8282  	
  8283  		SELECT U0.c0
  8284  		FROM cte, keyless U0 
  8285  		WHERE cte.j = keyless.c0
  8286  		
  8287  	)
  8288      ORDER BY c0;
  8289  `,
  8290  		Expected: []sql.Row{
  8291  			{4},
  8292  		},
  8293  	},
  8294  	{
  8295  		Query:    `SELECT SUM(0) * -1`,
  8296  		Expected: []sql.Row{{0.0}},
  8297  	},
  8298  
  8299  	{
  8300  		Query: `WITH RECURSIVE
  8301  rt (foo) AS (
  8302   SELECT 1 as foo
  8303   UNION ALL
  8304   SELECT foo + 1 as foo FROM rt WHERE foo < 5
  8305  ),
  8306  ladder (depth, foo) AS (
  8307   SELECT 1 as depth, NULL as foo from rt
  8308   UNION ALL
  8309   SELECT ladder.depth + 1 as depth, rt.foo
  8310   FROM ladder JOIN rt WHERE ladder.foo = rt.foo
  8311  )
  8312  SELECT * FROM ladder;`,
  8313  		Expected: []sql.Row{
  8314  			{1, nil},
  8315  			{1, nil},
  8316  			{1, nil},
  8317  			{1, nil},
  8318  			{1, nil},
  8319  		},
  8320  	},
  8321  
  8322  	{
  8323  		// natural join filter columns do not hide duplicated columns
  8324  		Query: "select t2.* from mytable t1 natural join mytable t2 join othertable t3 on t2.i = t3.i2;",
  8325  		Expected: []sql.Row{
  8326  			{1, "first row"},
  8327  			{2, "second row"},
  8328  			{3, "third row"},
  8329  		},
  8330  	},
  8331  	{
  8332  		// natural join join filter columns aliased
  8333  		Query: "select t1.*, t2.*, i from mytable t1 natural join mytable t2 join othertable t3 on t2.i = t3.i2;",
  8334  		Expected: []sql.Row{
  8335  			{1, "first row", 1, "first row", 1},
  8336  			{2, "second row", 2, "second row", 2},
  8337  			{3, "third row", 3, "third row", 3},
  8338  		},
  8339  	},
  8340  	{
  8341  		// mysql overwrites outer CTEs on seeing inner CTE definition
  8342  		Query:    "with a(j) as (select 1) ( with c(k) as (select 3) select k from c union select 6) union select k from c;",
  8343  		Expected: []sql.Row{{3}, {6}},
  8344  	},
  8345  	{
  8346  		Query:    "SELECT pk1, SUM(c1) FROM two_pk",
  8347  		Expected: []sql.Row{{0, 60.0}},
  8348  	},
  8349  	{
  8350  		Query: `SELECT pk,
  8351  						(SELECT sum(c1) FROM two_pk WHERE c1 IN (SELECT c4 FROM two_pk WHERE c3 > opk.c5)) AS sum,
  8352  						(SELECT avg(c1) FROM two_pk WHERE pk2 IN (SELECT pk2 FROM two_pk WHERE c1 < opk.c2)) AS avg
  8353  					FROM one_pk opk ORDER BY pk`,
  8354  		Expected: []sql.Row{
  8355  			{0, nil, 10.0},
  8356  			{1, nil, 15.0},
  8357  			{2, nil, 15.0},
  8358  			{3, nil, 15.0},
  8359  		},
  8360  	},
  8361  	{
  8362  		Query: `SELECT column_0, sum(column_1) FROM
  8363  			(values row(1,1), row(1,3), row(2,2), row(2,5), row(3,9)) a
  8364  			group by 1 having avg(column_1) > 2 order by 1`,
  8365  		Expected: []sql.Row{
  8366  			{2, 7.0},
  8367  			{3, 9.0},
  8368  		},
  8369  	},
  8370  	{
  8371  		Query: `WITH t AS (SELECT 1) SELECT * FROM t UNION (WITH t AS (SELECT 2) SELECT * FROM t)`,
  8372  		Expected: []sql.Row{
  8373  			{1},
  8374  			{2},
  8375  		},
  8376  	},
  8377  	{
  8378  		Query: "SELECT json_array() FROM dual;",
  8379  		Expected: []sql.Row{
  8380  			{types.MustJSON(`[]`)},
  8381  		},
  8382  	},
  8383  	{
  8384  		Query: "SELECT json_object() FROM dual;",
  8385  		Expected: []sql.Row{
  8386  			{types.MustJSON(`{}`)},
  8387  		},
  8388  	},
  8389  	{
  8390  		Query: `SELECT json_depth('{"a": 1, "b": {"aa": 1, "bb": {"aaa": 1, "bbb": {"aaaa": 1}}}}') FROM dual;`,
  8391  		Expected: []sql.Row{
  8392  			{5},
  8393  		},
  8394  	},
  8395  
  8396  	{
  8397  		Query: "SELECT i, I, s, S FROM mytable;",
  8398  		Expected: []sql.Row{
  8399  			{1, 1, "first row", "first row"},
  8400  			{2, 2, "second row", "second row"},
  8401  			{3, 3, "third row", "third row"},
  8402  		},
  8403  		ExpectedColumns: sql.Schema{
  8404  			{
  8405  				Name: "i",
  8406  				Type: types.Int64,
  8407  			},
  8408  			{
  8409  				Name: "I",
  8410  				Type: types.Int64,
  8411  			},
  8412  			{
  8413  				Name: "s",
  8414  				Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20),
  8415  			},
  8416  			{
  8417  				Name: "S",
  8418  				Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20),
  8419  			},
  8420  		},
  8421  	},
  8422  	{
  8423  		Query: "SELECT `i`, `I`, `s`, `S` FROM mytable;",
  8424  		Expected: []sql.Row{
  8425  			{1, 1, "first row", "first row"},
  8426  			{2, 2, "second row", "second row"},
  8427  			{3, 3, "third row", "third row"},
  8428  		},
  8429  		ExpectedColumns: sql.Schema{
  8430  			{
  8431  				Name: "i",
  8432  				Type: types.Int64,
  8433  			},
  8434  			{
  8435  				Name: "I",
  8436  				Type: types.Int64,
  8437  			},
  8438  			{
  8439  				Name: "s",
  8440  				Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20),
  8441  			},
  8442  			{
  8443  				Name: "S",
  8444  				Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20),
  8445  			},
  8446  		},
  8447  	},
  8448  	{
  8449  		Query: "SELECT `mytable`.`i`, `mytable`.`I`, `mytable`.`s`, `mytable`.`S` FROM mytable;",
  8450  		Expected: []sql.Row{
  8451  			{1, 1, "first row", "first row"},
  8452  			{2, 2, "second row", "second row"},
  8453  			{3, 3, "third row", "third row"},
  8454  		},
  8455  		ExpectedColumns: sql.Schema{
  8456  			{
  8457  				Name: "i",
  8458  				Type: types.Int64,
  8459  			},
  8460  			{
  8461  				Name: "I",
  8462  				Type: types.Int64,
  8463  			},
  8464  			{
  8465  				Name: "s",
  8466  				Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20),
  8467  			},
  8468  			{
  8469  				Name: "S",
  8470  				Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20),
  8471  			},
  8472  		},
  8473  	},
  8474  	// https://github.com/dolthub/go-mysql-server/issues/600
  8475  	{
  8476  		Query:    `SELECT json_unquote(json_extract('{"hi":"there"}', '$.nope'))`,
  8477  		Expected: []sql.Row{{nil}}, // currently returns string "null"
  8478  	},
  8479  	{
  8480  		Query: "SELECT 1 FROM DUAL WHERE (1, null) != (0, null)",
  8481  		Expected: []sql.Row{
  8482  			{1},
  8483  		},
  8484  	},
  8485  	{
  8486  		Query: "SELECT 1 FROM DUAL WHERE ('0', 0) = (0, '0')",
  8487  		Expected: []sql.Row{
  8488  			{1},
  8489  		},
  8490  	},
  8491  	{
  8492  		Query: "SELECT c AS i_do_not_conflict, COUNT(*), MIN((SELECT COUNT(*) FROM (SELECT 1 AS d) b WHERE b.d = a.c)) FROM (SELECT 1 AS c) a GROUP BY i_do_not_conflict;",
  8493  		Expected: []sql.Row{
  8494  			{1, 1, 1},
  8495  		},
  8496  	},
  8497  	{
  8498  		Query: "SELECT c AS c, COUNT(*), MIN((SELECT COUNT(*) FROM (SELECT 1 AS d) b WHERE b.d = a.c)) FROM (SELECT 1 AS c) a GROUP BY a.c;",
  8499  		Expected: []sql.Row{
  8500  			{1, 1, 1},
  8501  		},
  8502  	},
  8503  	{
  8504  		// Results should be sorted, but they are not
  8505  		Query: `
  8506  SELECT * FROM
  8507  (SELECT * FROM mytable) t
  8508  UNION ALL
  8509  (SELECT * FROM mytable)
  8510  ORDER BY 1;`,
  8511  		Expected: []sql.Row{
  8512  			{1, "first row"},
  8513  			{1, "first row"},
  8514  			{2, "second row"},
  8515  			{2, "second row"},
  8516  			{3, "third row"},
  8517  			{3, "third row"},
  8518  		},
  8519  	},
  8520  
  8521  	{
  8522  		Query: "select x from xy where x > 0 and x <= 2 order by x",
  8523  		Expected: []sql.Row{
  8524  			{1},
  8525  			{2},
  8526  		},
  8527  	},
  8528  	{
  8529  		Query: "select * from xy where y < 1 or y > 2 order by y",
  8530  		Expected: []sql.Row{
  8531  			{1, 0},
  8532  			{3, 3},
  8533  		},
  8534  	},
  8535  	{
  8536  		Query: "select * from xy where y < 1 or y > 2 order by y desc",
  8537  		Expected: []sql.Row{
  8538  			{3, 3},
  8539  			{1, 0},
  8540  		},
  8541  	},
  8542  	{
  8543  		Query: "select * from xy where x in (3, 0, 1) order by x",
  8544  		Expected: []sql.Row{
  8545  			{0, 2},
  8546  			{1, 0},
  8547  			{3, 3},
  8548  		},
  8549  	},
  8550  	{
  8551  		Query: "select * from xy where x in (3, 0, 1) order by x desc",
  8552  		Expected: []sql.Row{
  8553  			{3, 3},
  8554  			{1, 0},
  8555  			{0, 2},
  8556  		},
  8557  	},
  8558  	{
  8559  		Query: "select * from xy where y in (3, 0, 1) order by y",
  8560  		Expected: []sql.Row{
  8561  			{1, 0},
  8562  			{2, 1},
  8563  			{3, 3},
  8564  		},
  8565  	},
  8566  	{
  8567  		Query: "select * from xy where y in (3, 0, 1) order by y desc",
  8568  		Expected: []sql.Row{
  8569  			{3, 3},
  8570  			{2, 1},
  8571  			{1, 0},
  8572  		},
  8573  	},
  8574  	{
  8575  		Query: "select * from xy_hasnull_idx order by y",
  8576  		Expected: []sql.Row{
  8577  			{3, nil},
  8578  			{1, 0},
  8579  			{2, 1},
  8580  			{0, 2},
  8581  		},
  8582  	},
  8583  	{
  8584  		Query: "select * from xy_hasnull_idx order by y desc",
  8585  		Expected: []sql.Row{
  8586  			{0, 2},
  8587  			{2, 1},
  8588  			{1, 0},
  8589  			{3, nil},
  8590  		},
  8591  	},
  8592  	{
  8593  		Query: "select * from xy_hasnull_idx where y < 1 or y > 1 order by y desc",
  8594  		Expected: []sql.Row{
  8595  			{0, 2},
  8596  			{1, 0},
  8597  		},
  8598  	},
  8599  	{
  8600  		Query: "select * from xy_hasnull_idx where y < 1 or y > 1 or y is null order by y desc",
  8601  		Expected: []sql.Row{
  8602  			{0, 2},
  8603  			{1, 0},
  8604  			{3, nil},
  8605  		},
  8606  	},
  8607  	{
  8608  		Query: "select * from xy_hasnull_idx where y in (0, 2) or y is null order by y",
  8609  		Expected: []sql.Row{
  8610  			{3, nil},
  8611  			{1, 0},
  8612  			{0, 2},
  8613  		},
  8614  	},
  8615  	{
  8616  		Query: "select x as xx, y as yy from xy_hasnull_idx order by yy desc",
  8617  		Expected: []sql.Row{
  8618  			{0, 2},
  8619  			{2, 1},
  8620  			{1, 0},
  8621  			{3, nil},
  8622  		},
  8623  	},
  8624  	{
  8625  		Query: "select x as xx, y as yy from xy_hasnull_idx order by YY desc",
  8626  		Expected: []sql.Row{
  8627  			{0, 2},
  8628  			{2, 1},
  8629  			{1, 0},
  8630  			{3, nil},
  8631  		},
  8632  	},
  8633  	{
  8634  		Query: "select * from xy_hasnull_idx order by Y desc",
  8635  		Expected: []sql.Row{
  8636  			{0, 2},
  8637  			{2, 1},
  8638  			{1, 0},
  8639  			{3, nil},
  8640  		},
  8641  	},
  8642  
  8643  	{
  8644  		Query: "select max(x) from xy",
  8645  		Expected: []sql.Row{
  8646  			{3},
  8647  		},
  8648  	},
  8649  	{
  8650  		Query: "select min(x) from xy",
  8651  		Expected: []sql.Row{
  8652  			{0},
  8653  		},
  8654  	},
  8655  	{
  8656  		Query: "select max(y) from xy",
  8657  		Expected: []sql.Row{
  8658  			{3},
  8659  		},
  8660  	},
  8661  	{
  8662  		Query: "select max(x)+100 from xy",
  8663  		Expected: []sql.Row{
  8664  			{103},
  8665  		},
  8666  	},
  8667  	{
  8668  		Query: "select max(x) as xx from xy",
  8669  		Expected: []sql.Row{
  8670  			{3},
  8671  		},
  8672  	},
  8673  	{
  8674  		Query: "select 1, 2.0, '3', max(x) from xy",
  8675  		Expected: []sql.Row{
  8676  			{1, "2.0", "3", 3},
  8677  		},
  8678  	},
  8679  	{
  8680  		Query: "select min(x) from xy where x > 0",
  8681  		Expected: []sql.Row{
  8682  			{1},
  8683  		},
  8684  	},
  8685  	{
  8686  		Query: "select max(x) from xy where x < 3",
  8687  		Expected: []sql.Row{
  8688  			{2},
  8689  		},
  8690  	},
  8691  	{
  8692  		Query: "select min(x) from xy where y > 0",
  8693  		Expected: []sql.Row{
  8694  			{0},
  8695  		},
  8696  	},
  8697  	{
  8698  		Query: "select max(x) from xy where y < 3",
  8699  		Expected: []sql.Row{
  8700  			{2},
  8701  		},
  8702  	},
  8703  	{
  8704  		Query: "select * from (select max(x) from xy) sq",
  8705  		Expected: []sql.Row{
  8706  			{3},
  8707  		},
  8708  	},
  8709  	{
  8710  		Query: "with cte(i) as (select max(x) from xy) select i + 100 from cte",
  8711  		Expected: []sql.Row{
  8712  			{103},
  8713  		},
  8714  	},
  8715  	{
  8716  		Query: "with cte(i) as (select x from xy) select max(i) from cte",
  8717  		Expected: []sql.Row{
  8718  			{3},
  8719  		},
  8720  	},
  8721  	{
  8722  		Query: "select max(x) from xy group by y",
  8723  		Expected: []sql.Row{
  8724  			{0},
  8725  			{1},
  8726  			{2},
  8727  			{3},
  8728  		},
  8729  	},
  8730  	{
  8731  		Query: "select max(x) from xy join uv where x = u",
  8732  		Expected: []sql.Row{
  8733  			{3},
  8734  		},
  8735  	},
  8736  	{
  8737  		Query: `
  8738  select * from mytable,
  8739  	lateral (
  8740  	with recursive cte(a) as (
  8741  		select y from xy
  8742  		union
  8743  		select x from cte
  8744  		join
  8745  		xy
  8746  		on x = a
  8747  		)
  8748  	select * from cte
  8749  ) sqa 
  8750  where i = a
  8751  order by i;`,
  8752  		Expected: []sql.Row{
  8753  			{1, "first row", 1},
  8754  			{2, "second row", 2},
  8755  			{3, "third row", 3},
  8756  		},
  8757  	},
  8758  	{
  8759  		Query: `
  8760  select * from mytable,
  8761  	lateral (
  8762  	with recursive cte(a) as (
  8763  		select y from xy
  8764  		union
  8765  		select x from cte
  8766  		join
  8767  		(
  8768  			select * 
  8769  			from xy
  8770  			where x = 1
  8771  		 ) sqa1
  8772  		on x = a
  8773  		limit 3
  8774  		)
  8775  	select * from cte
  8776  ) sqa2
  8777  where i = a
  8778  order by i;`,
  8779  		Expected: []sql.Row{
  8780  			{1, "first row", 1},
  8781  			{2, "second row", 2},
  8782  		},
  8783  	},
  8784  	{
  8785  		Query: `
  8786  select a, b
  8787  from ab as ab2
  8788  where exists (
  8789      select *
  8790      from ab
  8791  	where ab.b = (
  8792          select max(v)
  8793          from uv
  8794          where uv.v = ab2.a and uv.v = ab.a
  8795      )
  8796  );`,
  8797  		Expected: []sql.Row{
  8798  			{2, 2},
  8799  		},
  8800  	},
  8801  	{
  8802  		Query: `
  8803  select x, y
  8804  from xy as xy2
  8805  where exists (
  8806      select *
  8807      from xy
  8808          where xy.y = (
  8809          select max(v)
  8810          from uv
  8811          where uv.v = xy2.x and uv.v = xy.x
  8812      )
  8813  )
  8814  order by x, y;`,
  8815  		Expected: []sql.Row{},
  8816  	},
  8817  	{
  8818  		Query: `select 1 where cos(2)`,
  8819  		Expected: []sql.Row{
  8820  			{1},
  8821  		},
  8822  	},
  8823  	{
  8824  		Query: `select 1 where sin(2)`,
  8825  		Expected: []sql.Row{
  8826  			{1},
  8827  		},
  8828  	},
  8829  	{
  8830  		Query:    `select 1 where sin(0)`,
  8831  		Expected: []sql.Row{},
  8832  	},
  8833  	{
  8834  		Query: `select acos(-2)`,
  8835  		Expected: []sql.Row{
  8836  			{nil},
  8837  		},
  8838  	},
  8839  	{
  8840  		Query: `select asin(-2)`,
  8841  		Expected: []sql.Row{
  8842  			{nil},
  8843  		},
  8844  	},
  8845  	{
  8846  		Query: `select 1 % acos(-2)`,
  8847  		Expected: []sql.Row{
  8848  			{nil},
  8849  		},
  8850  	},
  8851  	{
  8852  		Query: "select dayname(123), dayname('abc')",
  8853  		Expected: []sql.Row{
  8854  			{nil, nil},
  8855  		},
  8856  	},
  8857  	{
  8858  		Query: `
  8859  select
  8860     dayname(id),
  8861     dayname(i8),
  8862     dayname(i16),
  8863     dayname(i32),
  8864     dayname(i64),
  8865     dayname(u8),
  8866     dayname(u16),
  8867     dayname(u32),
  8868     dayname(u64),
  8869     dayname(f32),
  8870     dayname(f64),
  8871     dayname(ti),
  8872     dayname(da),
  8873     dayname(te),
  8874     dayname(bo),
  8875     dayname(js),
  8876     dayname(bl),
  8877     dayname(e1),
  8878     dayname(s1)
  8879  from typestable`,
  8880  		Expected: []sql.Row{
  8881  			{
  8882  				nil,
  8883  				nil,
  8884  				nil,
  8885  				nil,
  8886  				nil,
  8887  				nil,
  8888  				nil,
  8889  				nil,
  8890  				nil,
  8891  				nil,
  8892  				nil,
  8893  				"Tuesday",
  8894  				"Tuesday",
  8895  				nil,
  8896  				nil,
  8897  				nil,
  8898  				nil,
  8899  				nil,
  8900  				nil,
  8901  			},
  8902  		},
  8903  	},
  8904  	{
  8905  		// TODO: This goes past MySQL's range
  8906  		Query: "select dayname('0000-00-00')",
  8907  		Expected: []sql.Row{
  8908  			{"Saturday"},
  8909  		},
  8910  	},
  8911  	{
  8912  		Query: "select * from mytable order by dayname(i)",
  8913  		Expected: []sql.Row{
  8914  			{1, "first row"},
  8915  			{2, "second row"},
  8916  			{3, "third row"},
  8917  		},
  8918  	},
  8919  	{
  8920  		Query: "select sqrt(-1) + 1",
  8921  		Expected: []sql.Row{
  8922  			{nil},
  8923  		},
  8924  	},
  8925  	{
  8926  		Query: "select sqrt(-1) + 1",
  8927  		Expected: []sql.Row{
  8928  			{nil},
  8929  		},
  8930  	},
  8931  	{
  8932  		Query:    "flush binary logs",
  8933  		Expected: []sql.Row{},
  8934  	},
  8935  	{
  8936  		Query:    "flush engine logs",
  8937  		Expected: []sql.Row{},
  8938  	},
  8939  	// TODO: this is the largest scale decimal we support, but it's not the largest MySQL supports
  8940  	{
  8941  		Query: "select round(5e29, -30)",
  8942  		Expected: []sql.Row{
  8943  			{1e30},
  8944  		},
  8945  	},
  8946  	{
  8947  		Query: "select 1 where (round('')) union all select 1 where (not (round(''))) union all select 1 where ((round('')) is null);",
  8948  		Expected: []sql.Row{
  8949  			{1},
  8950  		},
  8951  	},
  8952  	{
  8953  		Query: "select 1 in (null, 0.8)",
  8954  		Expected: []sql.Row{
  8955  			{nil},
  8956  		},
  8957  	},
  8958  	{
  8959  		Query: "select -1 in (null, sin(5))",
  8960  		Expected: []sql.Row{
  8961  			{nil},
  8962  		},
  8963  	},
  8964  	{
  8965  		Query:    "select 1 where (1 in (null, 0.8))",
  8966  		Expected: []sql.Row{},
  8967  	},
  8968  	{
  8969  		Query:    "select -1 where (1 in (null, sin(5)))",
  8970  		Expected: []sql.Row{},
  8971  	},
  8972  	{
  8973  		Query:    "select * from mytable where (i in (null, 0.8, 1.5, 2.999))",
  8974  		Expected: []sql.Row{},
  8975  	},
  8976  	{
  8977  		Query: "select * from mytable where (i BETWEEN (CASE 1 WHEN 2 THEN 1.0 ELSE (1||2) END) AND i)",
  8978  		Expected: []sql.Row{
  8979  			{1, "first row"},
  8980  			{2, "second row"},
  8981  			{3, "third row"},
  8982  		},
  8983  	},
  8984  	{
  8985  		Query: "select * from mytable where (i BETWEEN ('' BETWEEN '' AND ('' OR '#')) AND i)",
  8986  		Expected: []sql.Row{
  8987  			{1, "first row"},
  8988  			{2, "second row"},
  8989  			{3, "third row"},
  8990  		},
  8991  	},
  8992  	{
  8993  		Query: "select * from (select 'k' as k) sq join bigtable on t = k join xy where x between n and n;",
  8994  		Expected: []sql.Row{
  8995  			{"k", "k", 1, 1, 0},
  8996  		},
  8997  	},
  8998  	{
  8999  		Query: "select * from xy inner join uv on (xy.x in (false in ('asdf')));",
  9000  		Expected: []sql.Row{
  9001  			{1, 0, 0, 1},
  9002  			{1, 0, 1, 1},
  9003  			{1, 0, 2, 2},
  9004  			{1, 0, 3, 2},
  9005  		},
  9006  	},
  9007  	{
  9008  		Query: "select * from mytable where i > '-0.5';",
  9009  		Expected: []sql.Row{
  9010  			{1, "first row"},
  9011  			{2, "second row"},
  9012  			{3, "third row"},
  9013  		},
  9014  	},
  9015  	{
  9016  		Query: "select case when 1 then 59 + 81 / 1 end;",
  9017  		Expected: []sql.Row{
  9018  			{"140.0000"},
  9019  		},
  9020  	},
  9021  	{
  9022  		Query: "select case 1 when 2 then null else (6 * 2) / 1 end;",
  9023  		Expected: []sql.Row{
  9024  			{"12.0000"},
  9025  		},
  9026  	},
  9027  	{
  9028  		Query: "select case 1 when 1 then (6 * 2) / 1 when 2 then null else null end;",
  9029  		Expected: []sql.Row{
  9030  			{"12.0000"},
  9031  		},
  9032  	},
  9033  	{
  9034  		Query: "select * from one_pk_two_idx where v1 < 4 and v2 < 2 or v2 > 3 order by v1",
  9035  		Expected: []sql.Row{
  9036  			{0, 0, 0},
  9037  			{1, 1, 1},
  9038  			{4, 4, 4},
  9039  			{5, 5, 5},
  9040  			{6, 6, 6},
  9041  			{7, 7, 7},
  9042  		},
  9043  	},
  9044  	{
  9045  		Query: "select length(space(i)) from mytable;",
  9046  		Expected: []sql.Row{
  9047  			{1},
  9048  			{2},
  9049  			{3},
  9050  		},
  9051  	},
  9052  	{
  9053  		Query: "select concat(space(i), 'a') from mytable;",
  9054  		Expected: []sql.Row{
  9055  			{" a"},
  9056  			{"  a"},
  9057  			{"   a"},
  9058  		},
  9059  	},
  9060  	{
  9061  		Query: "select space(i * 2) from mytable;",
  9062  		Expected: []sql.Row{
  9063  			{"  "},
  9064  			{"    "},
  9065  			{"      "},
  9066  		},
  9067  	},
  9068  	{
  9069  		Query: "select i + pi() from mytable;",
  9070  		Expected: []sql.Row{
  9071  			{4.141592653589793},
  9072  			{5.141592653589793},
  9073  			{6.141592653589793},
  9074  		},
  9075  	},
  9076  	{
  9077  		Query: "select i * pi() from mytable;",
  9078  		Expected: []sql.Row{
  9079  			{3.141592653589793},
  9080  			{6.283185307179586},
  9081  			{9.42477796076938},
  9082  		},
  9083  	},
  9084  	{
  9085  		Query: "select i / pi() from mytable;",
  9086  		Expected: []sql.Row{
  9087  			{0.3183098861837907},
  9088  			{0.6366197723675814},
  9089  			{0.954929658551372},
  9090  		},
  9091  	},
  9092  	{
  9093  		Query: "select exp(i) from mytable;",
  9094  		Expected: []sql.Row{
  9095  			{math.Exp(1)},
  9096  			{math.Exp(2)},
  9097  			{math.Exp(3)},
  9098  		},
  9099  	},
  9100  	{
  9101  		Query: "select bit_count(i), bit_count(-20 * i) from mytable;",
  9102  		Expected: []sql.Row{
  9103  			{1, 61},
  9104  			{1, 60},
  9105  			{2, 59},
  9106  		},
  9107  	},
  9108  	{
  9109  		Query: "select bit_count(binary 123456878901234567890);",
  9110  		Expected: []sql.Row{
  9111  			{73},
  9112  		},
  9113  	},
  9114  	{
  9115  		Query: "select atan(i), atan2(i, i + 2) from mytable;",
  9116  		Expected: []sql.Row{
  9117  			{math.Atan2(1, 1), math.Atan2(1, 3)},
  9118  			{math.Atan2(2, 1), math.Atan2(2, 4)},
  9119  			{math.Atan2(3, 1), math.Atan2(3, 5)},
  9120  		},
  9121  	},
  9122  	{
  9123  		Query: "select elt(i, 'a', 'b') from mytable;",
  9124  		Expected: []sql.Row{
  9125  			{"a"},
  9126  			{"b"},
  9127  			{nil},
  9128  		},
  9129  	},
  9130  	{
  9131  		Query: "select field(i, '1', '2', '3') from mytable;",
  9132  		Expected: []sql.Row{
  9133  			{1},
  9134  			{2},
  9135  			{3},
  9136  		},
  9137  	},
  9138  	{
  9139  		Query: "select ord(s), ord(concat('asdf', s)) from mytable;",
  9140  		Expected: []sql.Row{
  9141  			{102, 97},
  9142  			{115, 97},
  9143  			{116, 97},
  9144  		},
  9145  	},
  9146  	{
  9147  		Query: "select char(i, i + 10, pi()) from mytable;",
  9148  		Expected: []sql.Row{
  9149  			{[]byte{0x01, 0x0B, 0x03}},
  9150  			{[]byte{0x02, 0x0C, 0x03}},
  9151  			{[]byte{0x03, 0x0D, 0x03}},
  9152  		},
  9153  	},
  9154  	{
  9155  		Query: "select char(97, 98, 99 using utf8mb4);",
  9156  		Expected: []sql.Row{
  9157  			{"abc"},
  9158  		},
  9159  	},
  9160  	{
  9161  		Query: "select count(distinct cast(i as decimal)) from mytable;",
  9162  		Expected: []sql.Row{
  9163  			{3},
  9164  		},
  9165  	},
  9166  	{
  9167  		Query: "select count(distinct null);",
  9168  		Expected: []sql.Row{
  9169  			{0},
  9170  		},
  9171  	},
  9172  	{
  9173  		Query: "select 1/2.0 + 1",
  9174  		Expected: []sql.Row{
  9175  			{"1.5000"},
  9176  		},
  9177  	},
  9178  	{
  9179  		Query: "select length(@@server_uuid)",
  9180  		Expected: []sql.Row{
  9181  			{36},
  9182  		},
  9183  	},
  9184  	{
  9185  		Query:    "select 1 where if('', 1, char(''));",
  9186  		Expected: []sql.Row{},
  9187  	},
  9188  	{
  9189  		Query: "select 1 where if('', char(''), 1);",
  9190  		Expected: []sql.Row{
  9191  			{1},
  9192  		},
  9193  	},
  9194  	{
  9195  		Query: "select 1 where if(char(''), 0, 1);",
  9196  		Expected: []sql.Row{
  9197  			{1},
  9198  		},
  9199  	},
  9200  	{
  9201  		Query: "select 1 where if(char('123'), 0, 1);",
  9202  		Expected: []sql.Row{
  9203  			{1},
  9204  		},
  9205  	},
  9206  	{
  9207  		Query: "select 1 where 0 = if('', 1, char(''));",
  9208  		Expected: []sql.Row{
  9209  			{1},
  9210  		},
  9211  	},
  9212  	{
  9213  		Query: "select if('', 1, char(''));",
  9214  		Expected: []sql.Row{
  9215  			{[]byte{0}},
  9216  		},
  9217  	},
  9218  	{
  9219  		Query: "select if(char(''), 'true', 'false');",
  9220  		Expected: []sql.Row{
  9221  			{"false"},
  9222  		},
  9223  	},
  9224  	{
  9225  		Query: "select if(char('0'), 'true', 'false');",
  9226  		Expected: []sql.Row{
  9227  			{"false"},
  9228  		},
  9229  	},
  9230  	{
  9231  		Query: "select if(char('1'), 'true', 'false');",
  9232  		Expected: []sql.Row{
  9233  			{"false"},
  9234  		},
  9235  	},
  9236  	{
  9237  		Query: "select if(cast(1 as binary), 'true', 'false');",
  9238  		Expected: []sql.Row{
  9239  			{"true"},
  9240  		},
  9241  	},
  9242  	{
  9243  		Query: "select if(cast(0 as binary), 'true', 'false');",
  9244  		Expected: []sql.Row{
  9245  			{"false"},
  9246  		},
  9247  	},
  9248  	{
  9249  		Query: "select cast(true as json) = true;",
  9250  		Expected: []sql.Row{
  9251  			{true},
  9252  		},
  9253  	},
  9254  	{
  9255  		Query: "select cast(false as json) = false;",
  9256  		Expected: []sql.Row{
  9257  			{true},
  9258  		},
  9259  	},
  9260  	{
  9261  		Query: "select cast(true as json) = 'true';",
  9262  		Expected: []sql.Row{
  9263  			{false},
  9264  		},
  9265  	},
  9266  	{
  9267  		Query: "select cast(false as json) = 'false';",
  9268  		Expected: []sql.Row{
  9269  			{false},
  9270  		},
  9271  	},
  9272  	{
  9273  		Query: "select cast(cast(true as json) as char) = 'true';",
  9274  		Expected: []sql.Row{
  9275  			{true},
  9276  		},
  9277  	},
  9278  	{
  9279  		Query: "select cast(cast(false as json) as char) = 'false';",
  9280  		Expected: []sql.Row{
  9281  			{true},
  9282  		},
  9283  	},
  9284  	{
  9285  		Query: "select cast(true as json) = 1;",
  9286  		Expected: []sql.Row{
  9287  			{false},
  9288  		},
  9289  	},
  9290  	{
  9291  		Query: "select cast(true as json) = 0;",
  9292  		Expected: []sql.Row{
  9293  			{false},
  9294  		},
  9295  	},
  9296  	{
  9297  		Query: "select cast(false as json) = 1;",
  9298  		Expected: []sql.Row{
  9299  			{false},
  9300  		},
  9301  	},
  9302  	{
  9303  		Query: "select cast(false as json) = 0;",
  9304  		Expected: []sql.Row{
  9305  			{false},
  9306  		},
  9307  	},
  9308  	{
  9309  		Query: "select cast(cast(true as json) as signed) = 1;",
  9310  		Expected: []sql.Row{
  9311  			{true},
  9312  		},
  9313  	},
  9314  	{
  9315  		Query: "select cast(cast(true as json) as signed) = 0;",
  9316  		Expected: []sql.Row{
  9317  			{false},
  9318  		},
  9319  	},
  9320  	{
  9321  		Query: "select cast(cast(false as json) as signed) = 1;",
  9322  		Expected: []sql.Row{
  9323  			{false},
  9324  		},
  9325  	},
  9326  	{
  9327  		Query: "select cast(cast(false as json) as signed) = 0;",
  9328  		Expected: []sql.Row{
  9329  			{true},
  9330  		},
  9331  	},
  9332  
  9333  	{
  9334  		Query: "select cast('true' as json) = 'true';",
  9335  		Expected: []sql.Row{
  9336  			{false},
  9337  		},
  9338  	},
  9339  	{
  9340  		Query: "select cast('true' as json) = true;",
  9341  		Expected: []sql.Row{
  9342  			{true},
  9343  		},
  9344  	},
  9345  	{
  9346  		Query: "select cast('false' as json) = false;",
  9347  		Expected: []sql.Row{
  9348  			{true},
  9349  		},
  9350  	},
  9351  	{
  9352  		Query: "select cast('false' as json) = 'false';",
  9353  		Expected: []sql.Row{
  9354  			{false},
  9355  		},
  9356  	},
  9357  }
  9358  
  9359  var KeylessQueries = []QueryTest{
  9360  	{
  9361  		Query: "SELECT * FROM keyless ORDER BY c0",
  9362  		Expected: []sql.Row{
  9363  			{0, 0},
  9364  			{1, 1},
  9365  			{1, 1},
  9366  			{2, 2},
  9367  		},
  9368  	},
  9369  	{
  9370  		Query: "SELECT * FROM keyless ORDER BY c1 DESC",
  9371  		Expected: []sql.Row{
  9372  			{2, 2},
  9373  			{1, 1},
  9374  			{1, 1},
  9375  			{0, 0},
  9376  		},
  9377  	},
  9378  	{
  9379  		Query: "SELECT * FROM keyless JOIN myTable where c0 = i",
  9380  		Expected: []sql.Row{
  9381  			{1, 1, 1, "first row"},
  9382  			{1, 1, 1, "first row"},
  9383  			{2, 2, 2, "second row"},
  9384  		},
  9385  	},
  9386  	{
  9387  		Query: "SELECT * FROM myTable JOIN keyless WHERE i = c0 ORDER BY i",
  9388  		Expected: []sql.Row{
  9389  			{1, "first row", 1, 1},
  9390  			{1, "first row", 1, 1},
  9391  			{2, "second row", 2, 2},
  9392  		},
  9393  	},
  9394  	{
  9395  		Query: "DESCRIBE keyless",
  9396  		Expected: []sql.Row{
  9397  			{"c0", "bigint", "YES", "", "NULL", ""},
  9398  			{"c1", "bigint", "YES", "", "NULL", ""},
  9399  		},
  9400  	},
  9401  	{
  9402  		Query: "SHOW COLUMNS FROM keyless",
  9403  		Expected: []sql.Row{
  9404  			{"c0", "bigint", "YES", "", "NULL", ""},
  9405  			{"c1", "bigint", "YES", "", "NULL", ""},
  9406  		},
  9407  	},
  9408  	{
  9409  		Query: "SHOW FULL COLUMNS FROM keyless",
  9410  		Expected: []sql.Row{
  9411  			{"c0", "bigint", nil, "YES", "", "NULL", "", "", ""},
  9412  			{"c1", "bigint", nil, "YES", "", "NULL", "", "", ""},
  9413  		},
  9414  	},
  9415  	{
  9416  		Query: "SHOW CREATE TABLE keyless",
  9417  		Expected: []sql.Row{
  9418  			{"keyless", "CREATE TABLE `keyless` (\n  `c0` bigint,\n  `c1` bigint\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"},
  9419  		},
  9420  	},
  9421  }
  9422  
  9423  // BrokenQueries are queries that are known to be broken in the engine.
  9424  var BrokenQueries = []QueryTest{
  9425  	// union and aggregation typing are tricky
  9426  	{
  9427  		Query: "with recursive t (n) as (select sum('1') from dual union all select (2.00) from dual) select sum(n) from t;",
  9428  		Expected: []sql.Row{
  9429  			{float64(3)},
  9430  		},
  9431  	},
  9432  	{
  9433  		Query: "with recursive t (n) as (select sum(1.0) from dual union all select n+1 from t where n < 10) select sum(n) from t;",
  9434  		Expected: []sql.Row{
  9435  			{"55.0"},
  9436  		},
  9437  	},
  9438  	{
  9439  		// mysql is case-sensitive with CTE name
  9440  		Query:    "with recursive MYTABLE(j) as (select 2 union select MYTABLE.j from MYTABLE join mytable on MYTABLE.j = mytable.i) select j from MYTABLE",
  9441  		Expected: []sql.Row{{2}},
  9442  	},
  9443  	{
  9444  		// mysql is case-sensitive with CTE name
  9445  		Query:    "with recursive MYTABLE(j) as (select 2 union select MYTABLE.j from MYTABLE join mytable on MYTABLE.j = mytable.i) select i from mytable;",
  9446  		Expected: []sql.Row{{1}, {2}, {3}},
  9447  	},
  9448  	{
  9449  		// edge case where mysql moves an orderby between scopes
  9450  		Query:    "with a(j) as (select 1), b(i) as (select 2) (select j from a union select i from b order by 1 desc) union select j from a;",
  9451  		Expected: []sql.Row{{2}, {1}},
  9452  	},
  9453  	{
  9454  		// mysql converts boolean to int8
  9455  		Query:    "with a(j) as (select 1 union select 2 union select 3), b(i) as (select 2 union select 3) select (3,4) in (select a.j, b.i+1 from a, b where a.j = b.i) as k group by k having k = 1;",
  9456  		Expected: []sql.Row{{1}},
  9457  	},
  9458  	{
  9459  		// mysql converts boolean to int8 and deduplicates with other 1
  9460  		Query:    "With recursive a(x) as (select 1 union select 2 union select x in (select t1.i from mytable t1) from a) select x from a;",
  9461  		Expected: []sql.Row{{1}, {2}},
  9462  	},
  9463  	// this doesn't parse in MySQL (can't use an alias in a where clause), panics in engine
  9464  	// AVG gives the wrong result for the first row
  9465  	{
  9466  		Query: "SELECT json_table() FROM dual;", // syntax error
  9467  	},
  9468  	{
  9469  		Query: "SELECT json_value() FROM dual;", // syntax error
  9470  	},
  9471  	// Null-safe and type conversion tuple comparison is not correctly
  9472  	// implemented yet.
  9473  	{
  9474  		Query:    "SELECT 1 FROM DUAL WHERE (1, null) in ((1, null))",
  9475  		Expected: []sql.Row{},
  9476  	},
  9477  	{
  9478  		Query:    "SELECT 1 FROM DUAL WHERE (0, null) = (0, null)",
  9479  		Expected: []sql.Row{},
  9480  	},
  9481  	{
  9482  		Query:    "SELECT 1 FROM DUAL WHERE (null, null) = (select null, null from dual)",
  9483  		Expected: []sql.Row{},
  9484  	},
  9485  	// TODO: support nested recursive CTEs
  9486  	{
  9487  		Query: `
  9488  			with recursive t1 (sub_part, part, quantity) as (
  9489  				with recursive t2 (sub_part, part, quantity) as (
  9490  					SELECT p2.sub_part, p2.part, p2.quantity FROM parts as p2
  9491  					UNION
  9492  					SELECT p1.sub_part, p1.part, p1.quantity FROM parts as p1
  9493  					JOIN t2
  9494  					ON
  9495  						p1.sub_part = t2.sub_part
  9496  					WHERE p1.part = 'pie' and t2.part = 'crust'
  9497  				) select * from t2
  9498  				UNION
  9499  				SELECT t1.sub_part, t1.part, t1.quantity
  9500  				FROM t1
  9501  				JOIN parts AS p
  9502  				ON p.part = p.part
  9503  			) SELECT t1.sub_part, sum(t1.quantity) as total_quantity FROM t1 GROUP BY t1.sub_part;`,
  9504  		Expected: []sql.Row{
  9505  			{"crust", float64(1)},
  9506  			{"filling", float64(2)},
  9507  			{"flour", float64(20)},
  9508  			{"butter", float64(18)},
  9509  			{"salt", float64(18)},
  9510  			{"sugar", float64(7)},
  9511  			{"fruit", float64(9)},
  9512  		},
  9513  	},
  9514  	{
  9515  		// TODO truncate date outputs
  9516  		Query:    "select i, date_col from datetime_table",
  9517  		Expected: []sql.Row{{1, "2019-12-31"}},
  9518  	},
  9519  	// Currently, not matching MySQL's result format. This []uint8 gets converted to '\n' instead.
  9520  	{
  9521  		Query:    "SELECT X'0a'",
  9522  		Expected: []sql.Row{{"0x0A"}},
  9523  	},
  9524  	// Parsers for u, U, v, V, w, W, x and X are not supported yet.
  9525  	{
  9526  		Query:    "SELECT STR_TO_DATE('2013 32 Tuesday', '%X %V %W')", // Tuesday of 32th week
  9527  		Expected: []sql.Row{{"2013-08-13"}},
  9528  	},
  9529  	{
  9530  		// TODO:  need to properly handle datetime precision
  9531  		Query:    `SELECT STR_TO_DATE('01,5,2013 09:30:17','%d,%m,%Y %h:%i:%s %f') - (STR_TO_DATE('01,5,2013 09:30:17','%d,%m,%Y %h:%i:%s') - INTERVAL 1 SECOND)`,
  9532  		Expected: []sql.Row{{int64(1)}},
  9533  	},
  9534  	{
  9535  		// This panics
  9536  		// The non-recursive part of the UNION ALL returns too many rows, causing index out of bounds errors
  9537  		// Without the join on mytable and cte, this error is caught
  9538  		Query: `
  9539  WITH RECURSIVE cte(i, j) AS (
  9540      SELECT 0, 1, 2
  9541      FROM mytable
  9542  
  9543      UNION ALL
  9544      
  9545      SELECT *
  9546      FROM mytable, cte
  9547      WHERE cte.i = mytable.i   
  9548  )
  9549  SELECT *
  9550  FROM mytable;`,
  9551  		Expected: []sql.Row{
  9552  			{1, "first row"},
  9553  			{2, "second row"},
  9554  			{3, "third row"},
  9555  		},
  9556  	},
  9557  	{
  9558  		// TODO: we do not return correct result in some cases. The method used: `GetIsUpdatableFromCreateView(cv *CreateView)`
  9559  		Query:    "select TABLE_NAME, IS_UPDATABLE from information_schema.views where table_schema = 'mydb'",
  9560  		Expected: []sql.Row{{"myview1", "YES"}, {"myview2", "YES"}, {"myview3", "NO"}, {"myview4", "NO"}, {"myview5", "YES"}},
  9561  	},
  9562  }
  9563  
  9564  var VersionedQueries = []QueryTest{
  9565  	{
  9566  		Query: "SELECT *  FROM myhistorytable AS OF '2019-01-01' AS foo ORDER BY i",
  9567  		Expected: []sql.Row{
  9568  			{int64(1), "first row, 1"},
  9569  			{int64(2), "second row, 1"},
  9570  			{int64(3), "third row, 1"},
  9571  		},
  9572  	},
  9573  	{
  9574  		Query: "SELECT *  FROM myhistorytable AS OF '2019-01-02' foo ORDER BY i",
  9575  		Expected: []sql.Row{
  9576  			{int64(1), "first row, 2"},
  9577  			{int64(2), "second row, 2"},
  9578  			{int64(3), "third row, 2"},
  9579  		},
  9580  	},
  9581  	// Testing support of function evaluation in AS OF
  9582  	{
  9583  		Query: "SELECT *  FROM myhistorytable AS OF GREATEST('2019-01-02','2019-01-01','') foo ORDER BY i",
  9584  		Expected: []sql.Row{
  9585  			{int64(1), "first row, 2"},
  9586  			{int64(2), "second row, 2"},
  9587  			{int64(3), "third row, 2"},
  9588  		},
  9589  	},
  9590  	{
  9591  		Query: "SELECT *  FROM myhistorytable ORDER BY i",
  9592  		Expected: []sql.Row{
  9593  			{int64(1), "first row, 3", "1"},
  9594  			{int64(2), "second row, 3", "2"},
  9595  			{int64(3), "third row, 3", "3"},
  9596  		},
  9597  	},
  9598  	{
  9599  		Query: "SHOW TABLES AS OF '2019-01-02' LIKE 'myhistorytable'",
  9600  		Expected: []sql.Row{
  9601  			{"myhistorytable"},
  9602  		},
  9603  	},
  9604  	{
  9605  		Query: "SHOW TABLES FROM mydb AS OF '2019-01-02' LIKE 'myhistorytable'",
  9606  		Expected: []sql.Row{
  9607  			{"myhistorytable"},
  9608  		},
  9609  	},
  9610  	{
  9611  		Query: "SHOW CREATE TABLE myhistorytable as of '2019-01-02'",
  9612  		Expected: []sql.Row{
  9613  			{"myhistorytable", "CREATE TABLE `myhistorytable` (\n" +
  9614  				"  `i` bigint NOT NULL,\n" +
  9615  				"  `s` text NOT NULL,\n" +
  9616  				"  PRIMARY KEY (`i`)\n" +
  9617  				") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"},
  9618  		},
  9619  	},
  9620  	{
  9621  		Query: "SHOW CREATE TABLE myhistorytable as of '2019-01-03'",
  9622  		Expected: []sql.Row{
  9623  			{"myhistorytable", "CREATE TABLE `myhistorytable` (\n" +
  9624  				"  `i` bigint NOT NULL,\n" +
  9625  				"  `s` text NOT NULL,\n" +
  9626  				"  `c` text NOT NULL,\n" +
  9627  				"  PRIMARY KEY (`i`)\n" +
  9628  				") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"},
  9629  		},
  9630  	},
  9631  }
  9632  
  9633  var VersionedScripts = []ScriptTest{
  9634  	{
  9635  		Name: "user var for AS OF expression",
  9636  		SetUpScript: []string{
  9637  			"SET @rev1 = '2019-01-01', @rev2 = '2019-01-02'",
  9638  		},
  9639  		Assertions: []ScriptTestAssertion{
  9640  			{
  9641  				Query: "SELECT *  FROM myhistorytable AS OF @rev1 AS foo ORDER BY i",
  9642  				Expected: []sql.Row{
  9643  					{int64(1), "first row, 1"},
  9644  					{int64(2), "second row, 1"},
  9645  					{int64(3), "third row, 1"},
  9646  				},
  9647  			},
  9648  			{
  9649  				Query: "SELECT *  FROM myhistorytable AS OF @rev2 AS foo ORDER BY i",
  9650  				Expected: []sql.Row{
  9651  					{int64(1), "first row, 2"},
  9652  					{int64(2), "second row, 2"},
  9653  					{int64(3), "third row, 2"},
  9654  				},
  9655  			},
  9656  			{
  9657  				Query: "SHOW TABLES AS OF @rev1 LIKE 'myhistorytable'",
  9658  				Expected: []sql.Row{
  9659  					{"myhistorytable"},
  9660  				},
  9661  			},
  9662  			{
  9663  				Query: "DESCRIBE myhistorytable AS OF '2019-01-02'",
  9664  				Expected: []sql.Row{
  9665  					{"i", "bigint", "NO", "PRI", "NULL", ""},
  9666  					{"s", "text", "NO", "", "NULL", ""},
  9667  				},
  9668  			},
  9669  			{
  9670  				Query: "DESCRIBE myhistorytable AS OF '2019-01-03'",
  9671  				Expected: []sql.Row{
  9672  					{"i", "bigint", "NO", "PRI", "NULL", ""},
  9673  					{"s", "text", "NO", "", "NULL", ""},
  9674  					{"c", "text", "NO", "", "NULL", ""},
  9675  				},
  9676  			},
  9677  		},
  9678  	},
  9679  }
  9680  
  9681  var DateParseQueries = []QueryTest{
  9682  	{
  9683  		Query:    "SELECT STR_TO_DATE('Jan 3, 2000', '%b %e, %Y')",
  9684  		Expected: []sql.Row{{"2000-01-03"}},
  9685  	},
  9686  	{
  9687  		Query:    "SELECT STR_TO_DATE('01,5,2013', '%d,%m,%Y')",
  9688  		Expected: []sql.Row{{"2013-05-01"}},
  9689  	},
  9690  	{
  9691  		Query:    "SELECT STR_TO_DATE('May 1, 2013','%M %d,%Y')",
  9692  		Expected: []sql.Row{{"2013-05-01"}},
  9693  	},
  9694  	{
  9695  		Query:    "SELECT STR_TO_DATE('a09:30:17','a%h:%i:%s')",
  9696  		Expected: []sql.Row{{"09:30:17"}},
  9697  	},
  9698  	{
  9699  		Query:    "SELECT STR_TO_DATE('a09:30:17','%h:%i:%s')",
  9700  		Expected: []sql.Row{{nil}},
  9701  	},
  9702  	{
  9703  		Query:    "SELECT STR_TO_DATE('09:30:17a','%h:%i:%s')",
  9704  		Expected: []sql.Row{{"09:30:17"}},
  9705  	},
  9706  	{
  9707  		Query:    "SELECT STR_TO_DATE('09:30:17 pm','%h:%i:%s %p')",
  9708  		Expected: []sql.Row{{"21:30:17"}},
  9709  	},
  9710  	{
  9711  		Query:    "SELECT STR_TO_DATE('9','%m')",
  9712  		Expected: []sql.Row{{"0000-09-00"}},
  9713  	},
  9714  	{
  9715  		Query:    "SELECT STR_TO_DATE('9','%s')",
  9716  		Expected: []sql.Row{{"00:00:09"}},
  9717  	},
  9718  	{
  9719  		Query:    "SELECT STR_TO_DATE('01/02/99 314', '%m/%e/%y %f')",
  9720  		Expected: []sql.Row{{"1999-01-02 00:00:00.314000"}},
  9721  	},
  9722  	{
  9723  		Query:    "SELECT STR_TO_DATE('01/02/99 0', '%m/%e/%y %f')",
  9724  		Expected: []sql.Row{{"1999-01-02 00:00:00.000000"}},
  9725  	},
  9726  	{
  9727  		Query:    "SELECT STR_TO_DATE('01/02/99 05:14:12 PM', '%m/%e/%y %r')",
  9728  		Expected: []sql.Row{{"1999-01-02 17:14:12"}},
  9729  	},
  9730  	{
  9731  		Query:    "SELECT STR_TO_DATE('May 3, 10:23:00 2000', '%b %e, %H:%i:%s %Y')",
  9732  		Expected: []sql.Row{{"2000-05-03 10:23:00"}},
  9733  	},
  9734  	{
  9735  		Query:    "SELECT STR_TO_DATE('May 3, 10:23:00 PM 2000', '%b %e, %h:%i:%s %p %Y')",
  9736  		Expected: []sql.Row{{"2000-05-03 22:23:00"}},
  9737  	},
  9738  	{
  9739  		Query:    "SELECT STR_TO_DATE('May 3, 10:23:00 PM 2000', '%b %e, %H:%i:%s %p %Y')", // cannot use 24 hour time (%H) with AM/PM (%p)
  9740  		Expected: []sql.Row{{nil}},
  9741  	},
  9742  	{
  9743  		Query:    "SELECT STR_TO_DATE('abc','abc')",
  9744  		Expected: []sql.Row{{nil}},
  9745  	},
  9746  	{
  9747  		Query:    "SELECT STR_TO_DATE('invalid', 'notvalid')",
  9748  		Expected: []sql.Row{{nil}},
  9749  	},
  9750  }
  9751  
  9752  type QueryErrorTest struct {
  9753  	Query          string
  9754  	Bindings       map[string]*query.BindVariable
  9755  	ExpectedErr    *errors.Kind
  9756  	ExpectedErrStr string
  9757  }
  9758  
  9759  var ErrorQueries = []QueryErrorTest{
  9760  	{
  9761  		Query:       "analyze table mytable update histogram on i using data 'unknown'",
  9762  		ExpectedErr: planbuilder.ErrFailedToParseStats,
  9763  	},
  9764  	{
  9765  		Query:       "select * from othertable join foo.othertable on foo.othertable.s2 = 'a'",
  9766  		ExpectedErr: sql.ErrTableColumnNotFound,
  9767  	},
  9768  	{
  9769  		Query:       "select * from foo.othertable join othertable on foo.othertable.s2 = 'a'",
  9770  		ExpectedErr: sql.ErrTableColumnNotFound,
  9771  	},
  9772  	{
  9773  		Query:       "select * from othertable join foo.othertable on mydb.othertable.text = 'third'",
  9774  		ExpectedErr: sql.ErrTableColumnNotFound,
  9775  	},
  9776  	{
  9777  		Query:       "select * from foo.othertable join othertable on mydb.othertable.text = 'third'",
  9778  		ExpectedErr: sql.ErrTableColumnNotFound,
  9779  	},
  9780  	{
  9781  		Query:       "select i from mytable a join mytable b on a.i = b.i",
  9782  		ExpectedErr: sql.ErrAmbiguousColumnName,
  9783  	},
  9784  	{
  9785  		Query:       "select i from mytable join mytable",
  9786  		ExpectedErr: sql.ErrAmbiguousColumnName,
  9787  	},
  9788  	{
  9789  		Query:       "select * from mytable join mytable",
  9790  		ExpectedErr: sql.ErrDuplicateAliasOrTable,
  9791  	},
  9792  	{
  9793  		Query:       "select * from (select * from othertable) mytable join mytable",
  9794  		ExpectedErr: sql.ErrDuplicateAliasOrTable,
  9795  	},
  9796  	{
  9797  		Query:       "select * from (select * from foo.othertable) mytable join mytable",
  9798  		ExpectedErr: sql.ErrDuplicateAliasOrTable,
  9799  	},
  9800  	{
  9801  		Query:       "select i from (select * from mytable a join mytable b on a.i = b.i) dt",
  9802  		ExpectedErr: sql.ErrAmbiguousColumnName,
  9803  	},
  9804  	{
  9805  		Query:       "select i from (select * from mytable join mytable) a join mytable b on a.i = b.i",
  9806  		ExpectedErr: sql.ErrAmbiguousColumnName,
  9807  	},
  9808  	{
  9809  		Query:       "select table_name from information_schema.statistics AS OF '2023-08-31' WHERE table_schema='mydb'",
  9810  		ExpectedErr: sql.ErrAsOfNotSupported,
  9811  	},
  9812  	{
  9813  		Query:       "with a(j) as (select 1), b(i) as (select 2) (select j from a union select i from b order by 1 desc) union select j from a order by 1 asc;",
  9814  		ExpectedErr: sql.ErrConflictingExternalQuery,
  9815  	},
  9816  	{
  9817  		// Test for: https://github.com/dolthub/dolt/issues/3247
  9818  		Query:       "select * from dual where foo() and true;",
  9819  		ExpectedErr: sql.ErrFunctionNotFound,
  9820  	},
  9821  	{
  9822  		Query:       "select * from mytable where (i = 1, i = 0 or i = 2) and (i > -1)",
  9823  		ExpectedErr: sql.ErrInvalidOperandColumns,
  9824  	},
  9825  	{
  9826  		Query:       "select * from mytable where (i = 1, i = 0 or i = 2) or (i > -1)",
  9827  		ExpectedErr: sql.ErrInvalidOperandColumns,
  9828  	},
  9829  	{
  9830  		Query:       "select * from mytable where ((i = 1, i = 0 or i = 2) or (i > -1)) and (i < 6)",
  9831  		ExpectedErr: sql.ErrInvalidOperandColumns,
  9832  	},
  9833  	{
  9834  		Query:       "select * from mytable where ((i = 1, i = 0 or i = 2) is true or (i > -1)) and (i < 6)",
  9835  		ExpectedErr: sql.ErrInvalidOperandColumns,
  9836  	},
  9837  	{
  9838  		Query:       "select foo.i from mytable as a",
  9839  		ExpectedErr: sql.ErrTableNotFound,
  9840  	},
  9841  	{
  9842  		Query:       "select foo.i from mytable",
  9843  		ExpectedErr: sql.ErrTableNotFound,
  9844  	},
  9845  	{
  9846  		Query:       "select foo.* from mytable",
  9847  		ExpectedErr: sql.ErrTableNotFound,
  9848  	},
  9849  	{
  9850  		Query:       "select foo.* from mytable as a",
  9851  		ExpectedErr: sql.ErrTableNotFound,
  9852  	},
  9853  	{
  9854  		Query:       "select x from mytable",
  9855  		ExpectedErr: sql.ErrColumnNotFound,
  9856  	},
  9857  	{
  9858  		Query:       "select mytable.x from mytable",
  9859  		ExpectedErr: sql.ErrTableColumnNotFound,
  9860  	},
  9861  	{
  9862  		Query:       "select a.x from mytable as a",
  9863  		ExpectedErr: sql.ErrTableColumnNotFound,
  9864  	},
  9865  	{
  9866  		Query:       "select a from notable",
  9867  		ExpectedErr: sql.ErrTableNotFound,
  9868  	},
  9869  	{
  9870  		Query:       "select myTable.i from mytable as mt", // alias overwrites the original table name
  9871  		ExpectedErr: sql.ErrTableNotFound,
  9872  	},
  9873  	{
  9874  		Query:       "select myTable.* from mytable as mt", // alias overwrites the original table name
  9875  		ExpectedErr: sql.ErrTableNotFound,
  9876  	},
  9877  	{
  9878  		Query:       "SELECT one_pk.c5,pk1,pk2 FROM one_pk opk JOIN two_pk tpk ON one_pk.pk=two_pk.pk1 ORDER BY 1,2,3", // alias overwrites the original table name
  9879  		ExpectedErr: sql.ErrTableNotFound,
  9880  	},
  9881  	{
  9882  		Query:       "SELECT pk,pk1,pk2 FROM one_pk opk JOIN two_pk tpk ON one_pk.pk=two_pk.pk1 AND opk.pk=tpk.pk2 ORDER BY 1,2,3", // alias overwrites the original table name
  9883  		ExpectedErr: sql.ErrTableNotFound,
  9884  	},
  9885  	{
  9886  		Query:       "SELECT t.i, myview1.s FROM myview AS t ORDER BY i", // alias overwrites the original view name
  9887  		ExpectedErr: sql.ErrTableNotFound,
  9888  	},
  9889  	{
  9890  		Query:       "SELECT * FROM mytable AS t, othertable as t", // duplicate alias
  9891  		ExpectedErr: sql.ErrDuplicateAliasOrTable,
  9892  	},
  9893  	{
  9894  		// case-insensitive duplicate
  9895  		Query:       "select * from mytable a join mytable A on a.i = A.i;",
  9896  		ExpectedErr: sql.ErrAmbiguousColumnName,
  9897  	},
  9898  	{
  9899  		Query:       "SELECT * FROM mytable AS t, othertable UNION SELECT * FROM mytable AS t, othertable AS t", // duplicate alias in union
  9900  		ExpectedErr: sql.ErrDuplicateAliasOrTable,
  9901  	},
  9902  	{
  9903  		Query:       "SELECT * FROM mytable AS OTHERTABLE, othertable", // alias / table conflict
  9904  		ExpectedErr: sql.ErrDuplicateAliasOrTable,
  9905  	},
  9906  	{
  9907  		Query:       `SELECT * FROM mytable WHERE s REGEXP("*main.go")`,
  9908  		ExpectedErr: expression.ErrInvalidRegexp,
  9909  	},
  9910  	{
  9911  		Query:       `SELECT SUBSTRING(s, 1, 10) AS sub_s, SUBSTRING(SUB_S, 2, 3) AS sub_sub_s FROM mytable`,
  9912  		ExpectedErr: sql.ErrMisusedAlias,
  9913  	},
  9914  	{
  9915  		Query:       "SELECT pk, (SELECT max(pk) FROM one_pk b WHERE b.pk <= one_pk.pk) FROM one_pk opk ORDER BY 1",
  9916  		ExpectedErr: sql.ErrTableNotFound,
  9917  	},
  9918  	{
  9919  		Query:       "SELECT pk, (SELECT max(pk) FROM one_pk WHERE b.pk <= one_pk.pk) FROM one_pk opk ORDER BY 1",
  9920  		ExpectedErr: sql.ErrTableNotFound,
  9921  	},
  9922  	{
  9923  		Query:       "SELECT pk, (SELECT max(pk) FROM one_pk WHERE b.pk <= one_pk.pk) FROM one_pk opk ORDER BY 1",
  9924  		ExpectedErr: sql.ErrTableNotFound,
  9925  	},
  9926  	{
  9927  		Query:       "SELECT pk, (SELECT max(pk) FROM two_pk WHERE pk <= one_pk.pk3) FROM one_pk ORDER BY 1",
  9928  		ExpectedErr: sql.ErrTableColumnNotFound,
  9929  	},
  9930  	{
  9931  		Query:       "SELECT pk, (SELECT max(pk) FROM dne WHERE pk <= one_pk.pk3) FROM one_pk ORDER BY 1",
  9932  		ExpectedErr: sql.ErrTableNotFound,
  9933  	},
  9934  	{
  9935  		Query:       "SELECT pk, (SELECT max(pk) FROM two_pk WHERE pk <= c6) FROM one_pk ORDER BY 1",
  9936  		ExpectedErr: sql.ErrColumnNotFound,
  9937  	},
  9938  	{
  9939  		Query:       "SELECT i FROM myhistorytable AS OF MAX(abc)",
  9940  		ExpectedErr: sql.ErrInvalidAsOfExpression,
  9941  	},
  9942  	{
  9943  		Query:       "SELECT i FROM myhistorytable AS OF MAX(i)",
  9944  		ExpectedErr: sql.ErrInvalidAsOfExpression,
  9945  	},
  9946  	{
  9947  		Query:       "SELECT pk FROM one_pk WHERE pk > ?",
  9948  		ExpectedErr: sql.ErrUnboundPreparedStatementVariable,
  9949  	},
  9950  	{
  9951  		Query:       "SELECT pk FROM one_pk WHERE pk > :pk",
  9952  		ExpectedErr: sql.ErrUnboundPreparedStatementVariable,
  9953  	},
  9954  	{
  9955  		Query: `WITH mt1 (x,y) as (select i,s FROM mytable)
  9956  			SELECT mt1.i, mt1.s FROM mt1`,
  9957  		ExpectedErr: sql.ErrTableColumnNotFound,
  9958  	},
  9959  	{
  9960  		Query: `WITH mt1 (x,y) as (select i,s FROM mytable)
  9961  			SELECT i, s FROM mt1`,
  9962  		ExpectedErr: sql.ErrColumnNotFound,
  9963  	},
  9964  	{
  9965  		Query: `WITH mt1 (x,y,z) as (select i,s FROM mytable)
  9966  			SELECT i, s FROM mt1`,
  9967  		ExpectedErr: sql.ErrColumnCountMismatch,
  9968  	},
  9969  	// TODO: this results in a stack overflow, need to check for this
  9970  	// {
  9971  	// 	Query: `WITH mt1 as (select i,s FROM mt2), mt2 as (select i,s from mt1)
  9972  	// 		SELECT i, s FROM mt1`,
  9973  	// 	ExpectedErr: sql.ErrColumnCountMismatch,
  9974  	// },
  9975  	// TODO: related to the above issue, CTEs are only allowed to mentioned previously defined CTEs (to prevent cycles).
  9976  	//  This query works, but shouldn't
  9977  	// {
  9978  	// 	Query: `WITH mt1 as (select i,s FROM mt2), mt2 as (select i,s from mytable)
  9979  	// 		SELECT i, s FROM mt1`,
  9980  	// 	ExpectedErr: sql.ErrColumnCountMismatch,
  9981  	// },
  9982  	{
  9983  		Query: `WITH mt1 as (select i,s FROM mytable), mt2 as (select i+1, concat(s, '!') from mytable)
  9984  			SELECT mt1.i, mt2.s FROM mt1 join mt2 on mt1.i = mt2.i;`,
  9985  		ExpectedErr: sql.ErrTableColumnNotFound,
  9986  	},
  9987  	// TODO: this should be an error, as every table alias (including subquery aliases) must be unique
  9988  	// {
  9989  	// 	Query: "SELECT s,i FROM (select i,s FROM mytable) mt join (select i,s FROM mytable) mt;",
  9990  	// 	ExpectedErr: sql.ErrDuplicateAliasOrTable,
  9991  	// },
  9992  	// TODO: this should be an error, as every table alias must be unique.
  9993  	// {
  9994  	// 	Query: "WITH mt as (select i,s FROM mytable) SELECT s,i FROM mt join mt;",
  9995  	// 	ExpectedErr: sql.ErrDuplicateAliasOrTable,
  9996  	// },
  9997  	// TODO: Bug: the having column must appear in the select list
  9998  	// {
  9999  	// 	Query:       "SELECT pk1, sum(c1) FROM two_pk GROUP BY 1 having c1 > 10;",
 10000  	// 	ExpectedErr: sql.ErrColumnNotFound,
 10001  	// },
 10002  	{
 10003  		Query:       `SHOW TABLE STATUS FROM baddb`,
 10004  		ExpectedErr: sql.ErrDatabaseNotFound,
 10005  	},
 10006  	{
 10007  		Query:       "SELECT C FROM (select i,s FROM mytable) mt (a,b) order by a desc;",
 10008  		ExpectedErr: sql.ErrColumnNotFound,
 10009  	},
 10010  	{
 10011  		Query:       "SELECT i FROM (select i,s FROM mytable) mt (a,b) order by a desc;",
 10012  		ExpectedErr: sql.ErrColumnNotFound,
 10013  	},
 10014  	{
 10015  		Query:       "SELECT mt.i FROM (select i,s FROM mytable) mt (a,b) order by a desc;",
 10016  		ExpectedErr: sql.ErrTableColumnNotFound,
 10017  	},
 10018  	{
 10019  		Query:       "SELECT a FROM (select i,s FROM mytable) mt (a) order by a desc;",
 10020  		ExpectedErr: sql.ErrColumnCountMismatch,
 10021  	},
 10022  	{
 10023  		Query:       "SELECT a FROM (select i,s FROM mytable) mt (a,b,c) order by a desc;",
 10024  		ExpectedErr: sql.ErrColumnCountMismatch,
 10025  	},
 10026  	{
 10027  		Query:       `SELECT name FROM specialtable t WHERE t.name LIKE '$%' ESCAPE 'abc'`,
 10028  		ExpectedErr: sql.ErrInvalidArgument,
 10029  	},
 10030  	{
 10031  		Query:       `SELECT name FROM specialtable t WHERE t.name LIKE '$%' ESCAPE '$$'`,
 10032  		ExpectedErr: sql.ErrInvalidArgument,
 10033  	},
 10034  	{
 10035  		Query:       `SELECT JSON_OBJECT("a","b","c") FROM dual`,
 10036  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10037  	},
 10038  	{
 10039  		Query:       `alter table mytable add primary key (s)`,
 10040  		ExpectedErr: sql.ErrMultiplePrimaryKeysDefined,
 10041  	},
 10042  	{
 10043  		Query:       "select ((1, 2)) from dual",
 10044  		ExpectedErr: sql.ErrInvalidOperandColumns,
 10045  	},
 10046  	{
 10047  		Query:       "select (select 1, 2 from dual) from dual",
 10048  		ExpectedErr: sql.ErrInvalidOperandColumns,
 10049  	},
 10050  	{
 10051  		Query:       "select concat((1, 2)) from dual",
 10052  		ExpectedErr: sql.ErrInvalidOperandColumns,
 10053  	},
 10054  	{
 10055  		Query:       "select (1, 2) = (1) from dual",
 10056  		ExpectedErr: sql.ErrInvalidOperandColumns,
 10057  	},
 10058  	{
 10059  		Query:       "select (1) in (select 1, 2 from dual) from dual",
 10060  		ExpectedErr: sql.ErrInvalidOperandColumns,
 10061  	},
 10062  	{
 10063  		Query:       "select (1, 2) in (select 1, 2, 3 from dual) from dual",
 10064  		ExpectedErr: sql.ErrInvalidOperandColumns,
 10065  	},
 10066  	{
 10067  		Query:       "select (select 1 from dual) in ((1, 2)) from dual",
 10068  		ExpectedErr: sql.ErrInvalidOperandColumns,
 10069  	},
 10070  	{
 10071  		Query:       "select (((1,2),3)) = (((1,2))) from dual",
 10072  		ExpectedErr: sql.ErrInvalidOperandColumns,
 10073  	},
 10074  	{
 10075  		Query:       "select (((1,2),3)) = (((1),2)) from dual",
 10076  		ExpectedErr: sql.ErrInvalidOperandColumns,
 10077  	},
 10078  	{
 10079  		Query:       "select (((1,2),3)) = (((1))) from dual",
 10080  		ExpectedErr: sql.ErrInvalidOperandColumns,
 10081  	},
 10082  	{
 10083  		Query:       "select (((1,2),3)) = (((1,2),3),(4,5)) from dual",
 10084  		ExpectedErr: sql.ErrInvalidOperandColumns,
 10085  	},
 10086  	{
 10087  		Query:       "select ((4,5),((1,2),3)) = ((1,2),(4,5)) from dual",
 10088  		ExpectedErr: sql.ErrInvalidOperandColumns,
 10089  	},
 10090  	{
 10091  		Query:       "SELECT (2, 2)=1 FROM dual where exists (SELECT 1 FROM dual)",
 10092  		ExpectedErr: sql.ErrInvalidOperandColumns,
 10093  	},
 10094  	{
 10095  		Query:       `SELECT pk, (SELECT concat(pk, pk) FROM one_pk WHERE pk < opk.pk ORDER BY 1 DESC LIMIT 1) as strpk FROM one_pk opk where strpk > "0" ORDER BY 2`,
 10096  		ExpectedErr: sql.ErrColumnNotFound,
 10097  	},
 10098  	{
 10099  		Query:       `CREATE TABLE test (pk int, primary key(pk, noexist))`,
 10100  		ExpectedErr: sql.ErrUnknownIndexColumn,
 10101  	},
 10102  	{
 10103  		Query:       `CREATE TABLE test (pk int auto_increment, pk2 int auto_increment, primary key (pk))`,
 10104  		ExpectedErr: sql.ErrInvalidAutoIncCols,
 10105  	},
 10106  	{
 10107  		Query:       `CREATE TABLE test (pk int auto_increment)`,
 10108  		ExpectedErr: sql.ErrInvalidAutoIncCols,
 10109  	},
 10110  	{
 10111  		Query:       `CREATE TABLE test (pk int primary key auto_increment default 100, col int)`,
 10112  		ExpectedErr: sql.ErrInvalidAutoIncCols,
 10113  	},
 10114  	{
 10115  		Query:       "with recursive t (n) as (select (1) from dual union all select n from t where n < 2) select sum(n) from t",
 10116  		ExpectedErr: sql.ErrCteRecursionLimitExceeded,
 10117  	},
 10118  	{
 10119  		Query:       "with recursive t (n) as (select (1) from dual union all select n + 1 from t where n < 10002) select sum(n) from t",
 10120  		ExpectedErr: sql.ErrCteRecursionLimitExceeded,
 10121  	},
 10122  	{
 10123  		Query:       `SELECT * FROM datetime_table where date_col >= 'not a valid date'`,
 10124  		ExpectedErr: types.ErrConvertingToTime,
 10125  	},
 10126  	{
 10127  		Query:       `SELECT * FROM datetime_table where datetime_col >= 'not a valid datetime'`,
 10128  		ExpectedErr: types.ErrConvertingToTime,
 10129  	},
 10130  	// this query was panicing, but should be allowed and should return error when this query is called
 10131  	{
 10132  		Query:       `CREATE PROCEDURE proc1 (OUT out_count INT) READS SQL DATA SELECT COUNT(*) FROM mytable WHERE i = 1 AND s = 'first row' AND func1(i);`,
 10133  		ExpectedErr: sql.ErrFunctionNotFound,
 10134  	},
 10135  	{
 10136  		Query:       "CREATE TABLE table_test (id int PRIMARY KEY, c float DEFAULT rand())",
 10137  		ExpectedErr: sql.ErrSyntaxError,
 10138  	},
 10139  	{
 10140  		Query:       "CREATE TABLE table_test (id int PRIMARY KEY, c float DEFAULT rand)",
 10141  		ExpectedErr: sql.ErrSyntaxError,
 10142  	},
 10143  	{
 10144  		Query:       "CREATE TABLE table_test (id int PRIMARY KEY, c float DEFAULT (select 1))",
 10145  		ExpectedErr: sql.ErrSyntaxError,
 10146  	},
 10147  	{
 10148  		Query:       "CREATE TABLE table_test (id int PRIMARY KEY, b int DEFAULT '2', c int DEFAULT `b`)",
 10149  		ExpectedErr: sql.ErrSyntaxError,
 10150  	},
 10151  	{
 10152  		Query:       "CREATE TABLE t0 (id INT PRIMARY KEY, v1 POINT DEFAULT POINT(1,2));",
 10153  		ExpectedErr: sql.ErrSyntaxError,
 10154  	},
 10155  	{
 10156  		Query:       "CREATE TABLE t0 (id INT PRIMARY KEY, v1 JSON DEFAULT JSON_ARRAY(1,2));",
 10157  		ExpectedErr: sql.ErrSyntaxError,
 10158  	},
 10159  	{
 10160  		Query:       "with a as (select * from a) select * from a",
 10161  		ExpectedErr: sql.ErrTableNotFound,
 10162  	},
 10163  	{
 10164  		Query:          "with a as (select * from c), b as (select * from a), c as (select * from b) select * from a",
 10165  		ExpectedErrStr: "table not found: c",
 10166  	},
 10167  	{
 10168  		Query:       "WITH Numbers AS ( SELECT n = 1 UNION ALL SELECT n + 1 FROM Numbers WHERE n+1 <= 10) SELECT n FROM Numbers;",
 10169  		ExpectedErr: sql.ErrColumnNotFound, // TODO: this should actually be ErrTableNotFound
 10170  	},
 10171  	{
 10172  		Query:       "WITH recursive Numbers AS ( SELECT n = 1 UNION ALL SELECT n + 1 FROM Numbers WHERE n+1 <= 10) SELECT n FROM Numbers;",
 10173  		ExpectedErr: sql.ErrColumnNotFound,
 10174  	},
 10175  	{
 10176  		Query:          "CREATE TABLE invalid_decimal (number DECIMAL(65,31));",
 10177  		ExpectedErrStr: "Too big scale 31 specified. Maximum is 30.",
 10178  	},
 10179  	{
 10180  		Query:          "CREATE TABLE invalid_decimal (number DECIMAL(66,30));",
 10181  		ExpectedErrStr: "Too big precision 66 specified. Maximum is 65.",
 10182  	},
 10183  	{
 10184  		Query:          "CREATE TABLE invalid_decimal (number DECIMAL(66,31));",
 10185  		ExpectedErrStr: "Too big scale 31 specified. Maximum is 30.",
 10186  	},
 10187  	{
 10188  		Query:       "select 18446744073709551615 div 0.1;",
 10189  		ExpectedErr: expression.ErrIntDivDataOutOfRange,
 10190  	},
 10191  	{
 10192  		Query:       "select -9223372036854775807 div 0.1;",
 10193  		ExpectedErr: expression.ErrIntDivDataOutOfRange,
 10194  	},
 10195  	{
 10196  		Query:       "select -9223372036854775808 div 0.1;",
 10197  		ExpectedErr: expression.ErrIntDivDataOutOfRange,
 10198  	},
 10199  	{
 10200  		Query:       "drop table myview;",
 10201  		ExpectedErr: sql.ErrUnknownTable,
 10202  	},
 10203  	{
 10204  		Query:       "select SUM(*) from dual;",
 10205  		ExpectedErr: sql.ErrStarUnsupported,
 10206  	},
 10207  	{
 10208  		Query:          "create table vb_tbl (vb varbinary(123456789));",
 10209  		ExpectedErrStr: "length is 123456789 but max allowed is 65535",
 10210  	},
 10211  	{
 10212  		// Note: cannot use SRID `1234` because it is created in another test,
 10213  		// which affects this test to not return error
 10214  		Query:       `SELECT ST_GEOMFROMTEXT(ST_ASWKT(POINT(1,2)), 1235)`,
 10215  		ExpectedErr: sql.ErrNoSRID,
 10216  	},
 10217  	{
 10218  		Query:       `SELECT ST_GEOMFROMTEXT(ST_ASWKT(POINT(1,2)), 4294967295)`,
 10219  		ExpectedErr: sql.ErrNoSRID,
 10220  	},
 10221  	{
 10222  		Query:       `SELECT ST_GEOMFROMTEXT(ST_ASWKT(POINT(1,2)), -1)`,
 10223  		ExpectedErr: sql.ErrInvalidSRID,
 10224  	},
 10225  	{
 10226  		Query:       `SELECT ST_GEOMFROMTEXT(ST_ASWKT(POINT(1,2)), 4294967296)`,
 10227  		ExpectedErr: sql.ErrInvalidSRID,
 10228  	},
 10229  	{
 10230  		Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS x
 10231  						FROM one_pk opk WHERE x > 0 ORDER BY x`,
 10232  		ExpectedErr: sql.ErrColumnNotFound,
 10233  	},
 10234  	{
 10235  		Query: `SELECT pk,
 10236  					(SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS min,
 10237  					(SELECT min(pk) FROM one_pk WHERE pk > opk.pk) AS max
 10238  					FROM one_pk opk
 10239  					WHERE max > 1
 10240  					ORDER BY max;`,
 10241  		ExpectedErr: sql.ErrColumnNotFound,
 10242  	},
 10243  
 10244  	{
 10245  		Query:       "SELECT json_array_append() FROM dual;",
 10246  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10247  	},
 10248  	{
 10249  		Query:       "SELECT json_array_insert() FROM dual;",
 10250  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10251  	},
 10252  	{
 10253  		Query:       "SELECT json_contains() FROM dual;",
 10254  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10255  	},
 10256  	{
 10257  		Query:       "SELECT json_contains_path() FROM dual;",
 10258  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10259  	},
 10260  	{
 10261  		Query:       "SELECT json_insert() FROM dual;",
 10262  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10263  	},
 10264  	{
 10265  		Query:       "SELECT json_merge_preserve() FROM dual;",
 10266  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10267  	},
 10268  	{
 10269  		Query:       "SELECT json_remove() FROM dual;",
 10270  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10271  	},
 10272  	{
 10273  		Query:       "SELECT json_replace() FROM dual;",
 10274  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10275  	},
 10276  	{
 10277  		Query:       "SELECT json_set() FROM dual;",
 10278  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10279  	},
 10280  	{
 10281  		Query:       "SELECT json_keys() FROM dual;",
 10282  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10283  	},
 10284  	{
 10285  		Query:       "SELECT json_length() FROM dual;",
 10286  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10287  	},
 10288  	{
 10289  		Query:       `SELECT JSON_VALID()`,
 10290  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10291  	},
 10292  	{
 10293  		Query:       `SELECT JSON_VALID('{"a": 1}','[1]')`,
 10294  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10295  	},
 10296  	// This gets an error "unable to cast "second row" of type string to int64"
 10297  	// Should throw sql.ErrAmbiguousColumnInOrderBy
 10298  	{
 10299  		Query:       `SELECT s as i, i as i from mytable order by i`,
 10300  		ExpectedErr: sql.ErrAmbiguousColumnOrAliasName,
 10301  	},
 10302  	{
 10303  		Query:          "select * from mytable order by 999",
 10304  		ExpectedErrStr: "column \"999\" could not be found in any table in scope",
 10305  	},
 10306  	{
 10307  		Query:          `select cot(0)`,
 10308  		ExpectedErrStr: "DOUBLE out of range for COT",
 10309  	},
 10310  }
 10311  
 10312  var BrokenErrorQueries = []QueryErrorTest{
 10313  	{
 10314  		Query:          `WITH recursive n(i) as (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i+1 <= 10 GROUP BY i HAVING i+1 <= 10 ORDER BY 1 LIMIT 5) SELECT count(i) FROM n;`,
 10315  		ExpectedErrStr: "Not supported: 'ORDER BY over UNION in recursive Common Table Expression'",
 10316  	},
 10317  	{
 10318  		Query:          "with a(j) as (select 1) select j from a union select x from xy order by x;",
 10319  		ExpectedErrStr: "Unknown column 'x' in 'order clause'",
 10320  	},
 10321  	{
 10322  		Query:       "WITH Numbers AS ( SELECT n = 1 UNION ALL SELECT n + 1 FROM Numbers WHERE n+1 <= 10) SELECT n FROM Numbers;",
 10323  		ExpectedErr: sql.ErrTableNotFound,
 10324  	},
 10325  
 10326  	// Our behavior in when sql_mode = ONLY_FULL_GROUP_BY is inconsistent with MySQL
 10327  	// Relevant issue: https://github.com/dolthub/dolt/issues/4998
 10328  	// Special case: If you are grouping by every field of the PK, then you can select anything
 10329  	// Otherwise, whatever you are selecting must be in the Group By (with the exception of aggregations)
 10330  	{
 10331  		Query:       "SELECT col0, floor(col1) FROM tab1 GROUP by col0;",
 10332  		ExpectedErr: analyzererrors.ErrValidationGroupBy,
 10333  	},
 10334  	{
 10335  		Query:       "SELECT floor(cor0.col1) * ceil(cor0.col0) AS col2 FROM tab1 AS cor0 GROUP BY cor0.col0",
 10336  		ExpectedErr: analyzererrors.ErrValidationGroupBy,
 10337  	},
 10338  	{
 10339  		Query: "select * from two_pk group by pk1, pk2",
 10340  		// No error
 10341  	},
 10342  	{
 10343  		Query:       "select * from two_pk group by pk1",
 10344  		ExpectedErr: analyzererrors.ErrValidationGroupBy,
 10345  	},
 10346  	{
 10347  		// Grouping over functions and math expressions over PK does not count, and must appear in select
 10348  		Query:       "select * from two_pk group by pk1 + 1, mod(pk2, 2)",
 10349  		ExpectedErr: analyzererrors.ErrValidationGroupBy,
 10350  	},
 10351  	{
 10352  		// Grouping over functions and math expressions over PK does not count, and must appear in select
 10353  		Query: "select pk1+1 from two_pk group by pk1 + 1, mod(pk2, 2)",
 10354  		// No error
 10355  	},
 10356  	{
 10357  		// Grouping over functions and math expressions over PK does not count, and must appear in select
 10358  		Query: "select mod(pk2, 2) from two_pk group by pk1 + 1, mod(pk2, 2)",
 10359  		// No error
 10360  	},
 10361  	{
 10362  		// Grouping over functions and math expressions over PK does not count, and must appear in select
 10363  		Query: "select mod(pk2, 2) from two_pk group by pk1 + 1, mod(pk2, 2)",
 10364  		// No error
 10365  	},
 10366  	{
 10367  		Query: `SELECT any_value(pk), (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS x
 10368  						FROM one_pk opk WHERE (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) > 0
 10369  						GROUP BY (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) ORDER BY x`,
 10370  		// No error, but we get opk.pk does not exist
 10371  	},
 10372  	// Unimplemented JSON functions
 10373  	{
 10374  		Query:       "SELECT json_depth() FROM dual;",
 10375  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10376  	},
 10377  	{
 10378  		Query:       "SELECT json_merge_patch() FROM dual;",
 10379  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10380  	},
 10381  	{
 10382  		Query:       "SELECT json_overlaps() FROM dual;",
 10383  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10384  	},
 10385  	{
 10386  		Query:       "SELECT json_pretty() FROM dual;",
 10387  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10388  	},
 10389  	{
 10390  		Query:       "SELECT json_quote() FROM dual;",
 10391  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10392  	},
 10393  	{
 10394  		Query:       "SELECT json_schema_valid() FROM dual;",
 10395  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10396  	},
 10397  	{
 10398  		Query:       "SELECT json_schema_validation_report() FROM dual;",
 10399  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10400  	},
 10401  	{
 10402  		Query:       "SELECT json_search() FROM dual;",
 10403  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10404  	},
 10405  	{
 10406  		Query:       "SELECT json_storage_free() FROM dual;",
 10407  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10408  	},
 10409  	{
 10410  		Query:       "SELECT json_storage_size() FROM dual;",
 10411  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10412  	},
 10413  	{
 10414  		Query:       "SELECT json_type() FROM dual;",
 10415  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10416  	},
 10417  	{
 10418  		Query:       "SELECT json_valid() FROM dual;",
 10419  		ExpectedErr: sql.ErrInvalidArgumentNumber,
 10420  	},
 10421  	{
 10422  		Query:       "select * from othertable join foo.othertable on othertable.text = 'third'",
 10423  		ExpectedErr: sql.ErrUnknownColumn,
 10424  	},
 10425  	{
 10426  		Query:       "select * from foo.othertable join othertable on othertable.text = 'third'",
 10427  		ExpectedErr: sql.ErrUnknownColumn,
 10428  	},
 10429  	{
 10430  		Query:       "select * from mydb.othertable join foo.othertable on othertable.text = 'third'",
 10431  		ExpectedErr: sql.ErrUnknownColumn,
 10432  	},
 10433  	{
 10434  		Query:       "select * from foo.othertable join mydb.othertable on othertable.text = 'third'",
 10435  		ExpectedErr: sql.ErrUnknownColumn,
 10436  	},
 10437  }
 10438  
 10439  // WriteQueryTest is a query test for INSERT, UPDATE, etc. statements. It has a query to run and a select query to
 10440  // validate the results.
 10441  type WriteQueryTest struct {
 10442  	WriteQuery          string
 10443  	ExpectedWriteResult []sql.Row
 10444  	SelectQuery         string
 10445  	ExpectedSelect      []sql.Row
 10446  	Bindings            map[string]*query.BindVariable
 10447  	SkipServerEngine    bool
 10448  }
 10449  
 10450  // GenericErrorQueryTest is a query test that is used to assert an error occurs for some query, without specifying what
 10451  // the error was.
 10452  type GenericErrorQueryTest struct {
 10453  	Name     string
 10454  	Query    string
 10455  	Bindings map[string]sql.Expression
 10456  }
 10457  
 10458  var ViewTests = []QueryTest{
 10459  	{
 10460  		Query: "SELECT * FROM myview ORDER BY i",
 10461  		Expected: []sql.Row{
 10462  			sql.NewRow(int64(1), "first row"),
 10463  			sql.NewRow(int64(2), "second row"),
 10464  			sql.NewRow(int64(3), "third row"),
 10465  		},
 10466  	},
 10467  	{
 10468  		Query: "SELECT myview.* FROM myview ORDER BY i",
 10469  		Expected: []sql.Row{
 10470  			sql.NewRow(int64(1), "first row"),
 10471  			sql.NewRow(int64(2), "second row"),
 10472  			sql.NewRow(int64(3), "third row"),
 10473  		},
 10474  	},
 10475  	{
 10476  		Query: "SELECT i FROM myview ORDER BY i",
 10477  		Expected: []sql.Row{
 10478  			sql.NewRow(int64(1)),
 10479  			sql.NewRow(int64(2)),
 10480  			sql.NewRow(int64(3)),
 10481  		},
 10482  	},
 10483  	{
 10484  		Query: "SELECT t.* FROM myview AS t ORDER BY i",
 10485  		Expected: []sql.Row{
 10486  			sql.NewRow(int64(1), "first row"),
 10487  			sql.NewRow(int64(2), "second row"),
 10488  			sql.NewRow(int64(3), "third row"),
 10489  		},
 10490  	},
 10491  	{
 10492  		Query: "SELECT t.i FROM myview AS t ORDER BY i",
 10493  		Expected: []sql.Row{
 10494  			sql.NewRow(int64(1)),
 10495  			sql.NewRow(int64(2)),
 10496  			sql.NewRow(int64(3)),
 10497  		},
 10498  	},
 10499  	{
 10500  		Query: "SELECT * FROM myview2",
 10501  		Expected: []sql.Row{
 10502  			sql.NewRow(int64(1), "first row"),
 10503  		},
 10504  	},
 10505  	{
 10506  		Query: "SELECT i FROM myview2",
 10507  		Expected: []sql.Row{
 10508  			sql.NewRow(int64(1)),
 10509  		},
 10510  	},
 10511  	{
 10512  		Query: "SELECT myview2.i FROM myview2",
 10513  		Expected: []sql.Row{
 10514  			sql.NewRow(int64(1)),
 10515  		},
 10516  	},
 10517  	{
 10518  		Query: "SELECT myview2.* FROM myview2",
 10519  		Expected: []sql.Row{
 10520  			sql.NewRow(int64(1), "first row"),
 10521  		},
 10522  	},
 10523  	{
 10524  		Query: "SELECT t.* FROM myview2 as t",
 10525  		Expected: []sql.Row{
 10526  			sql.NewRow(int64(1), "first row"),
 10527  		},
 10528  	},
 10529  	{
 10530  		Query: "SELECT t.i FROM myview2 as t",
 10531  		Expected: []sql.Row{
 10532  			sql.NewRow(int64(1)),
 10533  		},
 10534  	},
 10535  	// info schema support
 10536  	{
 10537  		Query: "select * from information_schema.views where table_schema = 'mydb' order by table_name",
 10538  		Expected: []sql.Row{
 10539  			sql.NewRow("def", "mydb", "myview", "SELECT * FROM mytable", "NONE", "YES", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"),
 10540  			sql.NewRow("def", "mydb", "myview2", "SELECT * FROM myview WHERE i = 1", "NONE", "YES", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"),
 10541  		},
 10542  	},
 10543  	{
 10544  		Query: "select table_name from information_schema.tables where table_schema = 'mydb' and table_type = 'VIEW' order by 1",
 10545  		Expected: []sql.Row{
 10546  			sql.NewRow("myview"),
 10547  			sql.NewRow("myview2"),
 10548  		},
 10549  	},
 10550  }
 10551  
 10552  var VersionedViewTests = []QueryTest{
 10553  	{
 10554  		Query: "SELECT * FROM myview1 ORDER BY i",
 10555  		Expected: []sql.Row{
 10556  			sql.NewRow(int64(1), "first row, 3", "1"),
 10557  			sql.NewRow(int64(2), "second row, 3", "2"),
 10558  			sql.NewRow(int64(3), "third row, 3", "3"),
 10559  		},
 10560  	},
 10561  	{
 10562  		Query: "SELECT t.* FROM myview1 AS t ORDER BY i",
 10563  		Expected: []sql.Row{
 10564  			sql.NewRow(int64(1), "first row, 3", "1"),
 10565  			sql.NewRow(int64(2), "second row, 3", "2"),
 10566  			sql.NewRow(int64(3), "third row, 3", "3"),
 10567  		},
 10568  	},
 10569  	{
 10570  		Query: "SELECT t.i FROM myview1 AS t ORDER BY i",
 10571  		Expected: []sql.Row{
 10572  			sql.NewRow(int64(1)),
 10573  			sql.NewRow(int64(2)),
 10574  			sql.NewRow(int64(3)),
 10575  		},
 10576  	},
 10577  	{
 10578  		Query: "SELECT * FROM myview1 AS OF '2019-01-01' ORDER BY i",
 10579  		Expected: []sql.Row{
 10580  			sql.NewRow(int64(1), "first row, 1"),
 10581  			sql.NewRow(int64(2), "second row, 1"),
 10582  			sql.NewRow(int64(3), "third row, 1"),
 10583  		},
 10584  	},
 10585  
 10586  	// Nested views
 10587  	{
 10588  		Query: "SELECT * FROM myview2",
 10589  		Expected: []sql.Row{
 10590  			sql.NewRow(int64(1), "first row, 3", "1"),
 10591  		},
 10592  	},
 10593  	{
 10594  		Query: "SELECT i FROM myview2",
 10595  		Expected: []sql.Row{
 10596  			sql.NewRow(int64(1)),
 10597  		},
 10598  	},
 10599  	{
 10600  		Query: "SELECT myview2.i FROM myview2",
 10601  		Expected: []sql.Row{
 10602  			sql.NewRow(int64(1)),
 10603  		},
 10604  	},
 10605  	{
 10606  		Query: "SELECT myview2.* FROM myview2",
 10607  		Expected: []sql.Row{
 10608  			sql.NewRow(int64(1), "first row, 3", "1"),
 10609  		},
 10610  	},
 10611  	{
 10612  		Query: "SELECT t.* FROM myview2 as t",
 10613  		Expected: []sql.Row{
 10614  			sql.NewRow(int64(1), "first row, 3", "1"),
 10615  		},
 10616  	},
 10617  	{
 10618  		Query: "SELECT t.i FROM myview2 as t",
 10619  		Expected: []sql.Row{
 10620  			sql.NewRow(int64(1)),
 10621  		},
 10622  	},
 10623  	{
 10624  		Query: "SELECT * FROM myview2 AS OF '2019-01-01'",
 10625  		Expected: []sql.Row{
 10626  			sql.NewRow(int64(1), "first row, 1"),
 10627  		},
 10628  	},
 10629  
 10630  	// Views with unions
 10631  	{
 10632  		Query: "SELECT * FROM myview3 AS OF '2019-01-01'",
 10633  		Expected: []sql.Row{
 10634  			{"1"},
 10635  			{"2"},
 10636  			{"3"},
 10637  			{"first row, 1"},
 10638  			{"second row, 1"},
 10639  			{"third row, 1"},
 10640  		},
 10641  	},
 10642  	{
 10643  		Query: "SELECT * FROM myview3 AS OF '2019-01-02'",
 10644  		Expected: []sql.Row{
 10645  			{"1"},
 10646  			{"2"},
 10647  			{"3"},
 10648  			{"first row, 2"},
 10649  			{"second row, 2"},
 10650  			{"third row, 2"},
 10651  		},
 10652  	},
 10653  	{
 10654  		Query: "SELECT * FROM myview3 AS OF '2019-01-03'",
 10655  		Expected: []sql.Row{
 10656  			{"1"},
 10657  			{"2"},
 10658  			{"3"},
 10659  			{"first row, 3"},
 10660  			{"second row, 3"},
 10661  			{"third row, 3"},
 10662  		},
 10663  	},
 10664  
 10665  	// Views with subqueries
 10666  	{
 10667  		Query: "SELECT * FROM myview4 AS OF '2019-01-01'",
 10668  		Expected: []sql.Row{
 10669  			{1, "first row, 1"},
 10670  		},
 10671  	},
 10672  	{
 10673  		Query: "SELECT * FROM myview4 AS OF '2019-01-02'",
 10674  		Expected: []sql.Row{
 10675  			{2, "second row, 2"},
 10676  		},
 10677  	},
 10678  	{
 10679  		Query: "SELECT * FROM myview4 AS OF '2019-01-03'",
 10680  		Expected: []sql.Row{
 10681  			{3, "third row, 3", "3"},
 10682  		},
 10683  	},
 10684  
 10685  	// Views with subquery aliases
 10686  	{
 10687  		Query: "SELECT * FROM myview5 AS OF '2019-01-01'",
 10688  		Expected: []sql.Row{
 10689  			{1, "first row, 1"},
 10690  		},
 10691  	},
 10692  	{
 10693  		Query: "SELECT * FROM myview5 AS OF '2019-01-02'",
 10694  		Expected: []sql.Row{
 10695  			{2, "second row, 2"},
 10696  		},
 10697  	},
 10698  	{
 10699  		Query: "SELECT * FROM myview5 AS OF '2019-01-03'",
 10700  		Expected: []sql.Row{
 10701  			{3, "third row, 3", "3"},
 10702  		},
 10703  	},
 10704  
 10705  	// info schema support
 10706  	{
 10707  		Query: "select TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, VIEW_DEFINITION, CHECK_OPTION, DEFINER, SECURITY_TYPE, " +
 10708  			"CHARACTER_SET_CLIENT, COLLATION_CONNECTION from information_schema.views where table_schema = 'mydb'",
 10709  		Expected: []sql.Row{
 10710  			sql.NewRow("def", "mydb", "myview1", "SELECT * FROM myhistorytable", "NONE", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"),
 10711  			sql.NewRow("def", "mydb", "myview2", "SELECT * FROM myview1 WHERE i = 1", "NONE", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"),
 10712  			sql.NewRow("def", "mydb", "myview3", "SELECT i from myview1 union select s from myhistorytable", "NONE", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"),
 10713  			sql.NewRow("def", "mydb", "myview4", "SELECT * FROM myhistorytable where i in (select distinct cast(RIGHT(s, 1) as signed) from myhistorytable)", "NONE", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"),
 10714  			sql.NewRow("def", "mydb", "myview5", "SELECT * FROM (select * from myhistorytable where i in (select distinct cast(RIGHT(s, 1) as signed))) as sq", "NONE", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"),
 10715  		},
 10716  	},
 10717  	{
 10718  		Query: "select table_name from information_schema.tables where table_schema = 'mydb' and table_type = 'VIEW' order by 1",
 10719  		Expected: []sql.Row{
 10720  			sql.NewRow("myview1"),
 10721  			sql.NewRow("myview2"),
 10722  			sql.NewRow("myview3"),
 10723  			sql.NewRow("myview4"),
 10724  			sql.NewRow("myview5"),
 10725  		},
 10726  	},
 10727  }
 10728  
 10729  var ShowTableStatusQueries = []QueryTest{
 10730  	{
 10731  		Query: `SHOW TABLE STATUS FROM mydb`,
 10732  		Expected: []sql.Row{
 10733  			{"mytable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil},
 10734  			{"othertable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil},
 10735  		},
 10736  	},
 10737  	{
 10738  		Query: `SHOW TABLE STATUS LIKE '%table'`,
 10739  		Expected: []sql.Row{
 10740  			{"mytable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil},
 10741  			{"othertable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil},
 10742  		},
 10743  	},
 10744  	{
 10745  		Query: `SHOW TABLE STATUS FROM mydb LIKE 'othertable'`,
 10746  		Expected: []sql.Row{
 10747  			{"othertable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil},
 10748  		},
 10749  	},
 10750  	{
 10751  		Query: `SHOW TABLE STATUS WHERE Name = 'mytable'`,
 10752  		Expected: []sql.Row{
 10753  			{"mytable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil},
 10754  		},
 10755  	},
 10756  	{
 10757  		Query: `SHOW TABLE STATUS`,
 10758  		Expected: []sql.Row{
 10759  			{"mytable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil},
 10760  			{"othertable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil},
 10761  		},
 10762  	},
 10763  	{
 10764  		Query: `SHOW TABLE STATUS FROM mydb LIKE 'othertable'`,
 10765  		Expected: []sql.Row{
 10766  			{"othertable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil},
 10767  		},
 10768  	},
 10769  }
 10770  
 10771  func MustParseTime(layout, value string) time.Time {
 10772  	parsed, err := time.Parse(layout, value)
 10773  	if err != nil {
 10774  		panic(err)
 10775  	}
 10776  	return parsed
 10777  }