vitess.io/vitess@v0.16.2/go/vt/vtgate/planbuilder/testdata/postprocess_cases.json (about)

     1  [
     2    {
     3      "comment": "HAVING implicitly references table col",
     4      "query": "select user.col1 from user having col2 = 2",
     5      "v3-plan": {
     6        "QueryType": "SELECT",
     7        "Original": "select user.col1 from user having col2 = 2",
     8        "Instructions": {
     9          "OperatorType": "Route",
    10          "Variant": "Scatter",
    11          "Keyspace": {
    12            "Name": "user",
    13            "Sharded": true
    14          },
    15          "FieldQuery": "select `user`.col1 from `user` where 1 != 1",
    16          "Query": "select `user`.col1 from `user` having col2 = 2",
    17          "Table": "`user`"
    18        }
    19      },
    20      "gen4-plan": {
    21        "QueryType": "SELECT",
    22        "Original": "select user.col1 from user having col2 = 2",
    23        "Instructions": {
    24          "OperatorType": "Route",
    25          "Variant": "Scatter",
    26          "Keyspace": {
    27            "Name": "user",
    28            "Sharded": true
    29          },
    30          "FieldQuery": "select `user`.col1 from `user` where 1 != 1",
    31          "Query": "select `user`.col1 from `user` where col2 = 2",
    32          "Table": "`user`"
    33        },
    34        "TablesUsed": [
    35          "user.user"
    36        ]
    37      }
    38    },
    39    {
    40      "comment": "ambiguous symbol reference",
    41      "query": "select user.col1, user_extra.col1 from user join user_extra having col1 = 2",
    42      "v3-plan": "VT03021: ambiguous symbol reference: col1",
    43      "gen4-plan": "Column 'col1' in field list is ambiguous"
    44    },
    45    {
    46      "comment": "TODO: this should be 'Column 'col1' in having clause is ambiguous'\n# non-ambiguous symbol reference",
    47      "query": "select user.col1, user_extra.col1 from user join user_extra having user_extra.col1 = 2",
    48      "v3-plan": {
    49        "QueryType": "SELECT",
    50        "Original": "select user.col1, user_extra.col1 from user join user_extra having user_extra.col1 = 2",
    51        "Instructions": {
    52          "OperatorType": "Join",
    53          "Variant": "Join",
    54          "JoinColumnIndexes": "L:0,R:0",
    55          "TableName": "`user`_user_extra",
    56          "Inputs": [
    57            {
    58              "OperatorType": "Route",
    59              "Variant": "Scatter",
    60              "Keyspace": {
    61                "Name": "user",
    62                "Sharded": true
    63              },
    64              "FieldQuery": "select `user`.col1 from `user` where 1 != 1",
    65              "Query": "select `user`.col1 from `user`",
    66              "Table": "`user`"
    67            },
    68            {
    69              "OperatorType": "Route",
    70              "Variant": "Scatter",
    71              "Keyspace": {
    72                "Name": "user",
    73                "Sharded": true
    74              },
    75              "FieldQuery": "select user_extra.col1 from user_extra where 1 != 1",
    76              "Query": "select user_extra.col1 from user_extra having user_extra.col1 = 2",
    77              "Table": "user_extra"
    78            }
    79          ]
    80        }
    81      },
    82      "gen4-plan": {
    83        "QueryType": "SELECT",
    84        "Original": "select user.col1, user_extra.col1 from user join user_extra having user_extra.col1 = 2",
    85        "Instructions": {
    86          "OperatorType": "Join",
    87          "Variant": "Join",
    88          "JoinColumnIndexes": "L:0,R:0",
    89          "TableName": "`user`_user_extra",
    90          "Inputs": [
    91            {
    92              "OperatorType": "Route",
    93              "Variant": "Scatter",
    94              "Keyspace": {
    95                "Name": "user",
    96                "Sharded": true
    97              },
    98              "FieldQuery": "select `user`.col1 from `user` where 1 != 1",
    99              "Query": "select `user`.col1 from `user`",
   100              "Table": "`user`"
   101            },
   102            {
   103              "OperatorType": "Route",
   104              "Variant": "Scatter",
   105              "Keyspace": {
   106                "Name": "user",
   107                "Sharded": true
   108              },
   109              "FieldQuery": "select user_extra.col1 from user_extra where 1 != 1",
   110              "Query": "select user_extra.col1 from user_extra where user_extra.col1 = 2",
   111              "Table": "user_extra"
   112            }
   113          ]
   114        },
   115        "TablesUsed": [
   116          "user.user",
   117          "user.user_extra"
   118        ]
   119      }
   120    },
   121    {
   122      "comment": "HAVING multi-route",
   123      "query": "select user.col1 as a, user.col2, user_extra.col3 from user join user_extra having 1 = 1 and a = 1 and a = user.col2 and user_extra.col3 = 1",
   124      "v3-plan": {
   125        "QueryType": "SELECT",
   126        "Original": "select user.col1 as a, user.col2, user_extra.col3 from user join user_extra having 1 = 1 and a = 1 and a = user.col2 and user_extra.col3 = 1",
   127        "Instructions": {
   128          "OperatorType": "Join",
   129          "Variant": "Join",
   130          "JoinColumnIndexes": "L:0,L:1,R:0",
   131          "TableName": "`user`_user_extra",
   132          "Inputs": [
   133            {
   134              "OperatorType": "Route",
   135              "Variant": "Scatter",
   136              "Keyspace": {
   137                "Name": "user",
   138                "Sharded": true
   139              },
   140              "FieldQuery": "select `user`.col1 as a, `user`.col2 from `user` where 1 != 1",
   141              "Query": "select `user`.col1 as a, `user`.col2 from `user` having 1 = 1 and a = 1 and a = `user`.col2",
   142              "Table": "`user`"
   143            },
   144            {
   145              "OperatorType": "Route",
   146              "Variant": "Scatter",
   147              "Keyspace": {
   148                "Name": "user",
   149                "Sharded": true
   150              },
   151              "FieldQuery": "select user_extra.col3 from user_extra where 1 != 1",
   152              "Query": "select user_extra.col3 from user_extra having user_extra.col3 = 1",
   153              "Table": "user_extra"
   154            }
   155          ]
   156        }
   157      },
   158      "gen4-plan": {
   159        "QueryType": "SELECT",
   160        "Original": "select user.col1 as a, user.col2, user_extra.col3 from user join user_extra having 1 = 1 and a = 1 and a = user.col2 and user_extra.col3 = 1",
   161        "Instructions": {
   162          "OperatorType": "Join",
   163          "Variant": "Join",
   164          "JoinColumnIndexes": "L:0,L:1,R:0",
   165          "TableName": "`user`_user_extra",
   166          "Inputs": [
   167            {
   168              "OperatorType": "Route",
   169              "Variant": "Scatter",
   170              "Keyspace": {
   171                "Name": "user",
   172                "Sharded": true
   173              },
   174              "FieldQuery": "select `user`.col1 as a, `user`.col2 from `user` where 1 != 1",
   175              "Query": "select `user`.col1 as a, `user`.col2 from `user` where `user`.col1 = 1 and `user`.col1 = `user`.col2 and 1 = 1",
   176              "Table": "`user`"
   177            },
   178            {
   179              "OperatorType": "Route",
   180              "Variant": "Scatter",
   181              "Keyspace": {
   182                "Name": "user",
   183                "Sharded": true
   184              },
   185              "FieldQuery": "select user_extra.col3 from user_extra where 1 != 1",
   186              "Query": "select user_extra.col3 from user_extra where user_extra.col3 = 1 and 1 = 1",
   187              "Table": "user_extra"
   188            }
   189          ]
   190        },
   191        "TablesUsed": [
   192          "user.user",
   193          "user.user_extra"
   194        ]
   195      }
   196    },
   197    {
   198      "comment": "HAVING uses subquery",
   199      "query": "select id from user having id in (select col from user)",
   200      "v3-plan": {
   201        "QueryType": "SELECT",
   202        "Original": "select id from user having id in (select col from user)",
   203        "Instructions": {
   204          "OperatorType": "Subquery",
   205          "Variant": "PulloutIn",
   206          "PulloutVars": [
   207            "__sq_has_values1",
   208            "__sq1"
   209          ],
   210          "Inputs": [
   211            {
   212              "OperatorType": "Route",
   213              "Variant": "Scatter",
   214              "Keyspace": {
   215                "Name": "user",
   216                "Sharded": true
   217              },
   218              "FieldQuery": "select col from `user` where 1 != 1",
   219              "Query": "select col from `user`",
   220              "Table": "`user`"
   221            },
   222            {
   223              "OperatorType": "Route",
   224              "Variant": "IN",
   225              "Keyspace": {
   226                "Name": "user",
   227                "Sharded": true
   228              },
   229              "FieldQuery": "select id from `user` where 1 != 1",
   230              "Query": "select id from `user` having :__sq_has_values1 = 1 and id in ::__vals",
   231              "Table": "`user`",
   232              "Values": [
   233                ":__sq1"
   234              ],
   235              "Vindex": "user_index"
   236            }
   237          ]
   238        }
   239      },
   240      "gen4-plan": {
   241        "QueryType": "SELECT",
   242        "Original": "select id from user having id in (select col from user)",
   243        "Instructions": {
   244          "OperatorType": "Subquery",
   245          "Variant": "PulloutIn",
   246          "PulloutVars": [
   247            "__sq_has_values1",
   248            "__sq1"
   249          ],
   250          "Inputs": [
   251            {
   252              "OperatorType": "Route",
   253              "Variant": "Scatter",
   254              "Keyspace": {
   255                "Name": "user",
   256                "Sharded": true
   257              },
   258              "FieldQuery": "select col from `user` where 1 != 1",
   259              "Query": "select col from `user`",
   260              "Table": "`user`"
   261            },
   262            {
   263              "OperatorType": "Route",
   264              "Variant": "IN",
   265              "Keyspace": {
   266                "Name": "user",
   267                "Sharded": true
   268              },
   269              "FieldQuery": "select id from `user` where 1 != 1",
   270              "Query": "select id from `user` where :__sq_has_values1 = 1 and id in ::__vals",
   271              "Table": "`user`",
   272              "Values": [
   273                ":__sq1"
   274              ],
   275              "Vindex": "user_index"
   276            }
   277          ]
   278        },
   279        "TablesUsed": [
   280          "user.user"
   281        ]
   282      }
   283    },
   284    {
   285      "comment": "ORDER BY, reference col from local table.",
   286      "query": "select col from user where id = 5 order by aa",
   287      "v3-plan": {
   288        "QueryType": "SELECT",
   289        "Original": "select col from user where id = 5 order by aa",
   290        "Instructions": {
   291          "OperatorType": "Route",
   292          "Variant": "EqualUnique",
   293          "Keyspace": {
   294            "Name": "user",
   295            "Sharded": true
   296          },
   297          "FieldQuery": "select col from `user` where 1 != 1",
   298          "Query": "select col from `user` where id = 5 order by aa asc",
   299          "Table": "`user`",
   300          "Values": [
   301            "INT64(5)"
   302          ],
   303          "Vindex": "user_index"
   304        }
   305      },
   306      "gen4-plan": {
   307        "QueryType": "SELECT",
   308        "Original": "select col from user where id = 5 order by aa",
   309        "Instructions": {
   310          "OperatorType": "Route",
   311          "Variant": "EqualUnique",
   312          "Keyspace": {
   313            "Name": "user",
   314            "Sharded": true
   315          },
   316          "FieldQuery": "select col from `user` where 1 != 1",
   317          "Query": "select col from `user` where id = 5 order by aa asc",
   318          "Table": "`user`",
   319          "Values": [
   320            "INT64(5)"
   321          ],
   322          "Vindex": "user_index"
   323        },
   324        "TablesUsed": [
   325          "user.user"
   326        ]
   327      }
   328    },
   329    {
   330      "comment": "ORDER BY uses column numbers",
   331      "query": "select col from user where id = 1 order by 1",
   332      "v3-plan": {
   333        "QueryType": "SELECT",
   334        "Original": "select col from user where id = 1 order by 1",
   335        "Instructions": {
   336          "OperatorType": "Route",
   337          "Variant": "EqualUnique",
   338          "Keyspace": {
   339            "Name": "user",
   340            "Sharded": true
   341          },
   342          "FieldQuery": "select col from `user` where 1 != 1",
   343          "Query": "select col from `user` where id = 1 order by 1 asc",
   344          "Table": "`user`",
   345          "Values": [
   346            "INT64(1)"
   347          ],
   348          "Vindex": "user_index"
   349        }
   350      },
   351      "gen4-plan": {
   352        "QueryType": "SELECT",
   353        "Original": "select col from user where id = 1 order by 1",
   354        "Instructions": {
   355          "OperatorType": "Route",
   356          "Variant": "EqualUnique",
   357          "Keyspace": {
   358            "Name": "user",
   359            "Sharded": true
   360          },
   361          "FieldQuery": "select col from `user` where 1 != 1",
   362          "Query": "select col from `user` where id = 1 order by col asc",
   363          "Table": "`user`",
   364          "Values": [
   365            "INT64(1)"
   366          ],
   367          "Vindex": "user_index"
   368        },
   369        "TablesUsed": [
   370          "user.user"
   371        ]
   372      }
   373    },
   374    {
   375      "comment": "ORDER BY on scatter",
   376      "query": "select col from user order by col",
   377      "v3-plan": {
   378        "QueryType": "SELECT",
   379        "Original": "select col from user order by col",
   380        "Instructions": {
   381          "OperatorType": "Route",
   382          "Variant": "Scatter",
   383          "Keyspace": {
   384            "Name": "user",
   385            "Sharded": true
   386          },
   387          "FieldQuery": "select col from `user` where 1 != 1",
   388          "OrderBy": "0 ASC",
   389          "Query": "select col from `user` order by col asc",
   390          "Table": "`user`"
   391        }
   392      },
   393      "gen4-plan": {
   394        "QueryType": "SELECT",
   395        "Original": "select col from user order by col",
   396        "Instructions": {
   397          "OperatorType": "Route",
   398          "Variant": "Scatter",
   399          "Keyspace": {
   400            "Name": "user",
   401            "Sharded": true
   402          },
   403          "FieldQuery": "select col from `user` where 1 != 1",
   404          "OrderBy": "0 ASC",
   405          "Query": "select col from `user` order by col asc",
   406          "Table": "`user`"
   407        },
   408        "TablesUsed": [
   409          "user.user"
   410        ]
   411      }
   412    },
   413    {
   414      "comment": "ORDER BY on select t.*",
   415      "query": "select t.*, t.col from user t order by t.col",
   416      "v3-plan": "VT12001: unsupported: in scatter query, cannot ORDER BY a column that comes after `*` expressions in the SELECT list",
   417      "gen4-plan": "VT12001: unsupported: '*' expression in cross-shard query"
   418    },
   419    {
   420      "comment": "ORDER BY on select *",
   421      "query": "select *, col from user order by col",
   422      "v3-plan": "VT12001: unsupported: in scatter query, cannot ORDER BY a column that comes after `*` expressions in the SELECT list",
   423      "gen4-plan": "VT12001: unsupported: '*' expression in cross-shard query"
   424    },
   425    {
   426      "comment": "ORDER BY on select multi t.*",
   427      "query": "select t.*, t.name, t.*, t.col from user t order by t.col",
   428      "v3-plan": "VT12001: unsupported: in scatter query, cannot ORDER BY a column that comes after `*` expressions in the SELECT list",
   429      "gen4-plan": "VT12001: unsupported: '*' expression in cross-shard query"
   430    },
   431    {
   432      "comment": "ORDER BY on select multi *",
   433      "query": "select *, name, *, col from user order by col",
   434      "v3-plan": "VT12001: unsupported: in scatter query, cannot ORDER BY a column that comes after `*` expressions in the SELECT list",
   435      "gen4-plan": "VT12001: unsupported: '*' expression in cross-shard query"
   436    },
   437    {
   438      "comment": "ORDER BY works for select * from authoritative table",
   439      "query": "select * from authoritative order by user_id",
   440      "v3-plan": {
   441        "QueryType": "SELECT",
   442        "Original": "select * from authoritative order by user_id",
   443        "Instructions": {
   444          "OperatorType": "Route",
   445          "Variant": "Scatter",
   446          "Keyspace": {
   447            "Name": "user",
   448            "Sharded": true
   449          },
   450          "FieldQuery": "select user_id, col1, col2, weight_string(user_id) from authoritative where 1 != 1",
   451          "OrderBy": "(0|3) ASC",
   452          "Query": "select user_id, col1, col2, weight_string(user_id) from authoritative order by user_id asc",
   453          "ResultColumns": 3,
   454          "Table": "authoritative"
   455        }
   456      },
   457      "gen4-plan": {
   458        "QueryType": "SELECT",
   459        "Original": "select * from authoritative order by user_id",
   460        "Instructions": {
   461          "OperatorType": "Route",
   462          "Variant": "Scatter",
   463          "Keyspace": {
   464            "Name": "user",
   465            "Sharded": true
   466          },
   467          "FieldQuery": "select user_id, col1, col2, weight_string(user_id) from authoritative where 1 != 1",
   468          "OrderBy": "(0|3) ASC",
   469          "Query": "select user_id, col1, col2, weight_string(user_id) from authoritative order by user_id asc",
   470          "ResultColumns": 3,
   471          "Table": "authoritative"
   472        },
   473        "TablesUsed": [
   474          "user.authoritative"
   475        ]
   476      }
   477    },
   478    {
   479      "comment": "ORDER BY works for select * from authoritative table",
   480      "query": "select * from authoritative order by col1",
   481      "v3-plan": {
   482        "QueryType": "SELECT",
   483        "Original": "select * from authoritative order by col1",
   484        "Instructions": {
   485          "OperatorType": "Route",
   486          "Variant": "Scatter",
   487          "Keyspace": {
   488            "Name": "user",
   489            "Sharded": true
   490          },
   491          "FieldQuery": "select user_id, col1, col2, weight_string(col1) from authoritative where 1 != 1",
   492          "OrderBy": "(1|3) ASC",
   493          "Query": "select user_id, col1, col2, weight_string(col1) from authoritative order by col1 asc",
   494          "ResultColumns": 3,
   495          "Table": "authoritative"
   496        }
   497      },
   498      "gen4-plan": {
   499        "QueryType": "SELECT",
   500        "Original": "select * from authoritative order by col1",
   501        "Instructions": {
   502          "OperatorType": "Route",
   503          "Variant": "Scatter",
   504          "Keyspace": {
   505            "Name": "user",
   506            "Sharded": true
   507          },
   508          "FieldQuery": "select user_id, col1, col2 from authoritative where 1 != 1",
   509          "OrderBy": "1 ASC COLLATE latin1_swedish_ci",
   510          "Query": "select user_id, col1, col2 from authoritative order by col1 asc",
   511          "Table": "authoritative"
   512        },
   513        "TablesUsed": [
   514          "user.authoritative"
   515        ]
   516      }
   517    },
   518    {
   519      "comment": "ORDER BY on scatter with text column",
   520      "query": "select a, textcol1, b from user order by a, textcol1, b",
   521      "v3-plan": {
   522        "QueryType": "SELECT",
   523        "Original": "select a, textcol1, b from user order by a, textcol1, b",
   524        "Instructions": {
   525          "OperatorType": "Route",
   526          "Variant": "Scatter",
   527          "Keyspace": {
   528            "Name": "user",
   529            "Sharded": true
   530          },
   531          "FieldQuery": "select a, textcol1, b, weight_string(a), weight_string(textcol1), weight_string(b) from `user` where 1 != 1",
   532          "OrderBy": "(0|3) ASC, (1|4) ASC, (2|5) ASC",
   533          "Query": "select a, textcol1, b, weight_string(a), weight_string(textcol1), weight_string(b) from `user` order by a asc, textcol1 asc, b asc",
   534          "ResultColumns": 3,
   535          "Table": "`user`"
   536        }
   537      },
   538      "gen4-plan": {
   539        "QueryType": "SELECT",
   540        "Original": "select a, textcol1, b from user order by a, textcol1, b",
   541        "Instructions": {
   542          "OperatorType": "Route",
   543          "Variant": "Scatter",
   544          "Keyspace": {
   545            "Name": "user",
   546            "Sharded": true
   547          },
   548          "FieldQuery": "select a, textcol1, b, weight_string(a), weight_string(b) from `user` where 1 != 1",
   549          "OrderBy": "(0|3) ASC, 1 ASC COLLATE latin1_swedish_ci, (2|4) ASC",
   550          "Query": "select a, textcol1, b, weight_string(a), weight_string(b) from `user` order by a asc, textcol1 asc, b asc",
   551          "ResultColumns": 3,
   552          "Table": "`user`"
   553        },
   554        "TablesUsed": [
   555          "user.user"
   556        ]
   557      }
   558    },
   559    {
   560      "comment": "ORDER BY on scatter with text column, qualified name TODO: can plan better",
   561      "query": "select a, user.textcol1, b from user order by a, textcol1, b",
   562      "v3-plan": {
   563        "QueryType": "SELECT",
   564        "Original": "select a, user.textcol1, b from user order by a, textcol1, b",
   565        "Instructions": {
   566          "OperatorType": "Route",
   567          "Variant": "Scatter",
   568          "Keyspace": {
   569            "Name": "user",
   570            "Sharded": true
   571          },
   572          "FieldQuery": "select a, `user`.textcol1, b, weight_string(a), weight_string(`user`.textcol1), weight_string(b) from `user` where 1 != 1",
   573          "OrderBy": "(0|3) ASC, (1|4) ASC, (2|5) ASC",
   574          "Query": "select a, `user`.textcol1, b, weight_string(a), weight_string(`user`.textcol1), weight_string(b) from `user` order by a asc, textcol1 asc, b asc",
   575          "ResultColumns": 3,
   576          "Table": "`user`"
   577        }
   578      },
   579      "gen4-plan": {
   580        "QueryType": "SELECT",
   581        "Original": "select a, user.textcol1, b from user order by a, textcol1, b",
   582        "Instructions": {
   583          "OperatorType": "Route",
   584          "Variant": "Scatter",
   585          "Keyspace": {
   586            "Name": "user",
   587            "Sharded": true
   588          },
   589          "FieldQuery": "select a, `user`.textcol1, b, weight_string(a), weight_string(b) from `user` where 1 != 1",
   590          "OrderBy": "(0|3) ASC, 1 ASC COLLATE latin1_swedish_ci, (2|4) ASC",
   591          "Query": "select a, `user`.textcol1, b, weight_string(a), weight_string(b) from `user` order by a asc, textcol1 asc, b asc",
   592          "ResultColumns": 3,
   593          "Table": "`user`"
   594        },
   595        "TablesUsed": [
   596          "user.user"
   597        ]
   598      }
   599    },
   600    {
   601      "comment": "ORDER BY on scatter with multiple text columns",
   602      "query": "select a, textcol1, b, textcol2 from user order by a, textcol1, b, textcol2",
   603      "v3-plan": {
   604        "QueryType": "SELECT",
   605        "Original": "select a, textcol1, b, textcol2 from user order by a, textcol1, b, textcol2",
   606        "Instructions": {
   607          "OperatorType": "Route",
   608          "Variant": "Scatter",
   609          "Keyspace": {
   610            "Name": "user",
   611            "Sharded": true
   612          },
   613          "FieldQuery": "select a, textcol1, b, textcol2, weight_string(a), weight_string(textcol1), weight_string(b), weight_string(textcol2) from `user` where 1 != 1",
   614          "OrderBy": "(0|4) ASC, (1|5) ASC, (2|6) ASC, (3|7) ASC",
   615          "Query": "select a, textcol1, b, textcol2, weight_string(a), weight_string(textcol1), weight_string(b), weight_string(textcol2) from `user` order by a asc, textcol1 asc, b asc, textcol2 asc",
   616          "ResultColumns": 4,
   617          "Table": "`user`"
   618        }
   619      },
   620      "gen4-plan": {
   621        "QueryType": "SELECT",
   622        "Original": "select a, textcol1, b, textcol2 from user order by a, textcol1, b, textcol2",
   623        "Instructions": {
   624          "OperatorType": "Route",
   625          "Variant": "Scatter",
   626          "Keyspace": {
   627            "Name": "user",
   628            "Sharded": true
   629          },
   630          "FieldQuery": "select a, textcol1, b, textcol2, weight_string(a), weight_string(b) from `user` where 1 != 1",
   631          "OrderBy": "(0|4) ASC, 1 ASC COLLATE latin1_swedish_ci, (2|5) ASC, 3 ASC COLLATE latin1_swedish_ci",
   632          "Query": "select a, textcol1, b, textcol2, weight_string(a), weight_string(b) from `user` order by a asc, textcol1 asc, b asc, textcol2 asc",
   633          "ResultColumns": 4,
   634          "Table": "`user`"
   635        },
   636        "TablesUsed": [
   637          "user.user"
   638        ]
   639      }
   640    },
   641    {
   642      "comment": "ORDER BY invalid col number on scatter",
   643      "query": "select col from user order by 2",
   644      "v3-plan": "VT03014: unknown column '2' in 'order clause'",
   645      "gen4-plan": "Unknown column '2' in 'order clause'"
   646    },
   647    {
   648      "comment": "ORDER BY column offset",
   649      "query": "select id as foo from music order by 1",
   650      "v3-plan": {
   651        "QueryType": "SELECT",
   652        "Original": "select id as foo from music order by 1",
   653        "Instructions": {
   654          "OperatorType": "Route",
   655          "Variant": "Scatter",
   656          "Keyspace": {
   657            "Name": "user",
   658            "Sharded": true
   659          },
   660          "FieldQuery": "select id as foo, weight_string(id) from music where 1 != 1",
   661          "OrderBy": "(0|1) ASC",
   662          "Query": "select id as foo, weight_string(id) from music order by 1 asc",
   663          "ResultColumns": 1,
   664          "Table": "music"
   665        }
   666      },
   667      "gen4-plan": {
   668        "QueryType": "SELECT",
   669        "Original": "select id as foo from music order by 1",
   670        "Instructions": {
   671          "OperatorType": "Route",
   672          "Variant": "Scatter",
   673          "Keyspace": {
   674            "Name": "user",
   675            "Sharded": true
   676          },
   677          "FieldQuery": "select id as foo, weight_string(id) from music where 1 != 1",
   678          "OrderBy": "(0|1) ASC",
   679          "Query": "select id as foo, weight_string(id) from music order by foo asc",
   680          "ResultColumns": 1,
   681          "Table": "music"
   682        },
   683        "TablesUsed": [
   684          "user.music"
   685        ]
   686      }
   687    },
   688    {
   689      "comment": "ORDER BY NULL",
   690      "query": "select col from user order by null",
   691      "v3-plan": {
   692        "QueryType": "SELECT",
   693        "Original": "select col from user order by null",
   694        "Instructions": {
   695          "OperatorType": "Route",
   696          "Variant": "Scatter",
   697          "Keyspace": {
   698            "Name": "user",
   699            "Sharded": true
   700          },
   701          "FieldQuery": "select col from `user` where 1 != 1",
   702          "Query": "select col from `user` order by null",
   703          "Table": "`user`"
   704        }
   705      },
   706      "gen4-plan": {
   707        "QueryType": "SELECT",
   708        "Original": "select col from user order by null",
   709        "Instructions": {
   710          "OperatorType": "Route",
   711          "Variant": "Scatter",
   712          "Keyspace": {
   713            "Name": "user",
   714            "Sharded": true
   715          },
   716          "FieldQuery": "select col from `user` where 1 != 1",
   717          "Query": "select col from `user` order by null",
   718          "Table": "`user`"
   719        },
   720        "TablesUsed": [
   721          "user.user"
   722        ]
   723      }
   724    },
   725    {
   726      "comment": "ORDER BY after pull-out subquery",
   727      "query": "select col from user where col in (select col2 from user) order by col",
   728      "v3-plan": {
   729        "QueryType": "SELECT",
   730        "Original": "select col from user where col in (select col2 from user) order by col",
   731        "Instructions": {
   732          "OperatorType": "Subquery",
   733          "Variant": "PulloutIn",
   734          "PulloutVars": [
   735            "__sq_has_values1",
   736            "__sq1"
   737          ],
   738          "Inputs": [
   739            {
   740              "OperatorType": "Route",
   741              "Variant": "Scatter",
   742              "Keyspace": {
   743                "Name": "user",
   744                "Sharded": true
   745              },
   746              "FieldQuery": "select col2 from `user` where 1 != 1",
   747              "Query": "select col2 from `user`",
   748              "Table": "`user`"
   749            },
   750            {
   751              "OperatorType": "Route",
   752              "Variant": "Scatter",
   753              "Keyspace": {
   754                "Name": "user",
   755                "Sharded": true
   756              },
   757              "FieldQuery": "select col from `user` where 1 != 1",
   758              "OrderBy": "0 ASC",
   759              "Query": "select col from `user` where :__sq_has_values1 = 1 and col in ::__sq1 order by col asc",
   760              "Table": "`user`"
   761            }
   762          ]
   763        }
   764      },
   765      "gen4-plan": {
   766        "QueryType": "SELECT",
   767        "Original": "select col from user where col in (select col2 from user) order by col",
   768        "Instructions": {
   769          "OperatorType": "Subquery",
   770          "Variant": "PulloutIn",
   771          "PulloutVars": [
   772            "__sq_has_values1",
   773            "__sq1"
   774          ],
   775          "Inputs": [
   776            {
   777              "OperatorType": "Route",
   778              "Variant": "Scatter",
   779              "Keyspace": {
   780                "Name": "user",
   781                "Sharded": true
   782              },
   783              "FieldQuery": "select col2 from `user` where 1 != 1",
   784              "Query": "select col2 from `user`",
   785              "Table": "`user`"
   786            },
   787            {
   788              "OperatorType": "Route",
   789              "Variant": "Scatter",
   790              "Keyspace": {
   791                "Name": "user",
   792                "Sharded": true
   793              },
   794              "FieldQuery": "select col from `user` where 1 != 1",
   795              "OrderBy": "0 ASC",
   796              "Query": "select col from `user` where :__sq_has_values1 = 1 and col in ::__sq1 order by col asc",
   797              "Table": "`user`"
   798            }
   799          ]
   800        },
   801        "TablesUsed": [
   802          "user.user"
   803        ]
   804      }
   805    },
   806    {
   807      "comment": "ORDER BY NULL for join",
   808      "query": "select user.col1 as a, user.col2, music.col3 from user join music on user.id = music.id where user.id = 1 order by null",
   809      "v3-plan": {
   810        "QueryType": "SELECT",
   811        "Original": "select user.col1 as a, user.col2, music.col3 from user join music on user.id = music.id where user.id = 1 order by null",
   812        "Instructions": {
   813          "OperatorType": "Join",
   814          "Variant": "Join",
   815          "JoinColumnIndexes": "L:0,L:1,R:0",
   816          "JoinVars": {
   817            "user_id": 2
   818          },
   819          "TableName": "`user`_music",
   820          "Inputs": [
   821            {
   822              "OperatorType": "Route",
   823              "Variant": "EqualUnique",
   824              "Keyspace": {
   825                "Name": "user",
   826                "Sharded": true
   827              },
   828              "FieldQuery": "select `user`.col1 as a, `user`.col2, `user`.id from `user` where 1 != 1",
   829              "Query": "select `user`.col1 as a, `user`.col2, `user`.id from `user` where `user`.id = 1 order by null",
   830              "Table": "`user`",
   831              "Values": [
   832                "INT64(1)"
   833              ],
   834              "Vindex": "user_index"
   835            },
   836            {
   837              "OperatorType": "Route",
   838              "Variant": "EqualUnique",
   839              "Keyspace": {
   840                "Name": "user",
   841                "Sharded": true
   842              },
   843              "FieldQuery": "select music.col3 from music where 1 != 1",
   844              "Query": "select music.col3 from music where music.id = :user_id order by null",
   845              "Table": "music",
   846              "Values": [
   847                ":user_id"
   848              ],
   849              "Vindex": "music_user_map"
   850            }
   851          ]
   852        }
   853      },
   854      "gen4-plan": {
   855        "QueryType": "SELECT",
   856        "Original": "select user.col1 as a, user.col2, music.col3 from user join music on user.id = music.id where user.id = 1 order by null",
   857        "Instructions": {
   858          "OperatorType": "Join",
   859          "Variant": "Join",
   860          "JoinColumnIndexes": "L:1,L:2,R:0",
   861          "JoinVars": {
   862            "user_id": 0
   863          },
   864          "TableName": "`user`_music",
   865          "Inputs": [
   866            {
   867              "OperatorType": "Route",
   868              "Variant": "EqualUnique",
   869              "Keyspace": {
   870                "Name": "user",
   871                "Sharded": true
   872              },
   873              "FieldQuery": "select `user`.id, `user`.col1 as a, `user`.col2 from `user` where 1 != 1",
   874              "Query": "select `user`.id, `user`.col1 as a, `user`.col2 from `user` where `user`.id = 1",
   875              "Table": "`user`",
   876              "Values": [
   877                "INT64(1)"
   878              ],
   879              "Vindex": "user_index"
   880            },
   881            {
   882              "OperatorType": "Route",
   883              "Variant": "EqualUnique",
   884              "Keyspace": {
   885                "Name": "user",
   886                "Sharded": true
   887              },
   888              "FieldQuery": "select music.col3 from music where 1 != 1",
   889              "Query": "select music.col3 from music where music.id = :user_id",
   890              "Table": "music",
   891              "Values": [
   892                ":user_id"
   893              ],
   894              "Vindex": "music_user_map"
   895            }
   896          ]
   897        },
   898        "TablesUsed": [
   899          "user.music",
   900          "user.user"
   901        ]
   902      }
   903    },
   904    {
   905      "comment": "ORDER BY non-key column for join",
   906      "query": "select user.col1 as a, user.col2, music.col3 from user join music on user.id = music.id where user.id = 1 order by a",
   907      "v3-plan": {
   908        "QueryType": "SELECT",
   909        "Original": "select user.col1 as a, user.col2, music.col3 from user join music on user.id = music.id where user.id = 1 order by a",
   910        "Instructions": {
   911          "OperatorType": "Join",
   912          "Variant": "Join",
   913          "JoinColumnIndexes": "L:0,L:1,R:0",
   914          "JoinVars": {
   915            "user_id": 2
   916          },
   917          "TableName": "`user`_music",
   918          "Inputs": [
   919            {
   920              "OperatorType": "Route",
   921              "Variant": "EqualUnique",
   922              "Keyspace": {
   923                "Name": "user",
   924                "Sharded": true
   925              },
   926              "FieldQuery": "select `user`.col1 as a, `user`.col2, `user`.id from `user` where 1 != 1",
   927              "Query": "select `user`.col1 as a, `user`.col2, `user`.id from `user` where `user`.id = 1 order by a asc",
   928              "Table": "`user`",
   929              "Values": [
   930                "INT64(1)"
   931              ],
   932              "Vindex": "user_index"
   933            },
   934            {
   935              "OperatorType": "Route",
   936              "Variant": "EqualUnique",
   937              "Keyspace": {
   938                "Name": "user",
   939                "Sharded": true
   940              },
   941              "FieldQuery": "select music.col3 from music where 1 != 1",
   942              "Query": "select music.col3 from music where music.id = :user_id",
   943              "Table": "music",
   944              "Values": [
   945                ":user_id"
   946              ],
   947              "Vindex": "music_user_map"
   948            }
   949          ]
   950        }
   951      },
   952      "gen4-plan": {
   953        "QueryType": "SELECT",
   954        "Original": "select user.col1 as a, user.col2, music.col3 from user join music on user.id = music.id where user.id = 1 order by a",
   955        "Instructions": {
   956          "OperatorType": "Join",
   957          "Variant": "Join",
   958          "JoinColumnIndexes": "L:1,L:2,R:0",
   959          "JoinVars": {
   960            "user_id": 0
   961          },
   962          "TableName": "`user`_music",
   963          "Inputs": [
   964            {
   965              "OperatorType": "Route",
   966              "Variant": "EqualUnique",
   967              "Keyspace": {
   968                "Name": "user",
   969                "Sharded": true
   970              },
   971              "FieldQuery": "select `user`.id, `user`.col1 as a, `user`.col2, weight_string(`user`.col1) from `user` where 1 != 1",
   972              "OrderBy": "(1|3) ASC",
   973              "Query": "select `user`.id, `user`.col1 as a, `user`.col2, weight_string(`user`.col1) from `user` where `user`.id = 1 order by a asc",
   974              "Table": "`user`",
   975              "Values": [
   976                "INT64(1)"
   977              ],
   978              "Vindex": "user_index"
   979            },
   980            {
   981              "OperatorType": "Route",
   982              "Variant": "EqualUnique",
   983              "Keyspace": {
   984                "Name": "user",
   985                "Sharded": true
   986              },
   987              "FieldQuery": "select music.col3 from music where 1 != 1",
   988              "Query": "select music.col3 from music where music.id = :user_id",
   989              "Table": "music",
   990              "Values": [
   991                ":user_id"
   992              ],
   993              "Vindex": "music_user_map"
   994            }
   995          ]
   996        },
   997        "TablesUsed": [
   998          "user.music",
   999          "user.user"
  1000        ]
  1001      }
  1002    },
  1003    {
  1004      "comment": "ORDER BY non-key column for implicit join",
  1005      "query": "select user.col1 as a, user.col2, music.col3 from user, music where user.id = music.id and user.id = 1 order by a",
  1006      "v3-plan": {
  1007        "QueryType": "SELECT",
  1008        "Original": "select user.col1 as a, user.col2, music.col3 from user, music where user.id = music.id and user.id = 1 order by a",
  1009        "Instructions": {
  1010          "OperatorType": "Join",
  1011          "Variant": "Join",
  1012          "JoinColumnIndexes": "L:0,L:1,R:0",
  1013          "JoinVars": {
  1014            "user_id": 2
  1015          },
  1016          "TableName": "`user`_music",
  1017          "Inputs": [
  1018            {
  1019              "OperatorType": "Route",
  1020              "Variant": "EqualUnique",
  1021              "Keyspace": {
  1022                "Name": "user",
  1023                "Sharded": true
  1024              },
  1025              "FieldQuery": "select `user`.col1 as a, `user`.col2, `user`.id from `user` where 1 != 1",
  1026              "Query": "select `user`.col1 as a, `user`.col2, `user`.id from `user` where `user`.id = 1 order by a asc",
  1027              "Table": "`user`",
  1028              "Values": [
  1029                "INT64(1)"
  1030              ],
  1031              "Vindex": "user_index"
  1032            },
  1033            {
  1034              "OperatorType": "Route",
  1035              "Variant": "EqualUnique",
  1036              "Keyspace": {
  1037                "Name": "user",
  1038                "Sharded": true
  1039              },
  1040              "FieldQuery": "select music.col3 from music where 1 != 1",
  1041              "Query": "select music.col3 from music where music.id = :user_id",
  1042              "Table": "music",
  1043              "Values": [
  1044                ":user_id"
  1045              ],
  1046              "Vindex": "music_user_map"
  1047            }
  1048          ]
  1049        }
  1050      },
  1051      "gen4-plan": {
  1052        "QueryType": "SELECT",
  1053        "Original": "select user.col1 as a, user.col2, music.col3 from user, music where user.id = music.id and user.id = 1 order by a",
  1054        "Instructions": {
  1055          "OperatorType": "Join",
  1056          "Variant": "Join",
  1057          "JoinColumnIndexes": "L:1,L:2,R:0",
  1058          "JoinVars": {
  1059            "user_id": 0
  1060          },
  1061          "TableName": "`user`_music",
  1062          "Inputs": [
  1063            {
  1064              "OperatorType": "Route",
  1065              "Variant": "EqualUnique",
  1066              "Keyspace": {
  1067                "Name": "user",
  1068                "Sharded": true
  1069              },
  1070              "FieldQuery": "select `user`.id, `user`.col1 as a, `user`.col2, weight_string(`user`.col1) from `user` where 1 != 1",
  1071              "OrderBy": "(1|3) ASC",
  1072              "Query": "select `user`.id, `user`.col1 as a, `user`.col2, weight_string(`user`.col1) from `user` where `user`.id = 1 order by a asc",
  1073              "Table": "`user`",
  1074              "Values": [
  1075                "INT64(1)"
  1076              ],
  1077              "Vindex": "user_index"
  1078            },
  1079            {
  1080              "OperatorType": "Route",
  1081              "Variant": "EqualUnique",
  1082              "Keyspace": {
  1083                "Name": "user",
  1084                "Sharded": true
  1085              },
  1086              "FieldQuery": "select music.col3 from music where 1 != 1",
  1087              "Query": "select music.col3 from music where music.id = :user_id",
  1088              "Table": "music",
  1089              "Values": [
  1090                ":user_id"
  1091              ],
  1092              "Vindex": "music_user_map"
  1093            }
  1094          ]
  1095        },
  1096        "TablesUsed": [
  1097          "user.music",
  1098          "user.user"
  1099        ]
  1100      }
  1101    },
  1102    {
  1103      "comment": "ORDER BY NULL after pull-out subquery",
  1104      "query": "select col from user where col in (select col2 from user) order by null",
  1105      "v3-plan": {
  1106        "QueryType": "SELECT",
  1107        "Original": "select col from user where col in (select col2 from user) order by null",
  1108        "Instructions": {
  1109          "OperatorType": "Subquery",
  1110          "Variant": "PulloutIn",
  1111          "PulloutVars": [
  1112            "__sq_has_values1",
  1113            "__sq1"
  1114          ],
  1115          "Inputs": [
  1116            {
  1117              "OperatorType": "Route",
  1118              "Variant": "Scatter",
  1119              "Keyspace": {
  1120                "Name": "user",
  1121                "Sharded": true
  1122              },
  1123              "FieldQuery": "select col2 from `user` where 1 != 1",
  1124              "Query": "select col2 from `user`",
  1125              "Table": "`user`"
  1126            },
  1127            {
  1128              "OperatorType": "Route",
  1129              "Variant": "Scatter",
  1130              "Keyspace": {
  1131                "Name": "user",
  1132                "Sharded": true
  1133              },
  1134              "FieldQuery": "select col from `user` where 1 != 1",
  1135              "Query": "select col from `user` where :__sq_has_values1 = 1 and col in ::__sq1 order by null",
  1136              "Table": "`user`"
  1137            }
  1138          ]
  1139        }
  1140      },
  1141      "gen4-plan": {
  1142        "QueryType": "SELECT",
  1143        "Original": "select col from user where col in (select col2 from user) order by null",
  1144        "Instructions": {
  1145          "OperatorType": "Subquery",
  1146          "Variant": "PulloutIn",
  1147          "PulloutVars": [
  1148            "__sq_has_values1",
  1149            "__sq1"
  1150          ],
  1151          "Inputs": [
  1152            {
  1153              "OperatorType": "Route",
  1154              "Variant": "Scatter",
  1155              "Keyspace": {
  1156                "Name": "user",
  1157                "Sharded": true
  1158              },
  1159              "FieldQuery": "select col2 from `user` where 1 != 1",
  1160              "Query": "select col2 from `user`",
  1161              "Table": "`user`"
  1162            },
  1163            {
  1164              "OperatorType": "Route",
  1165              "Variant": "Scatter",
  1166              "Keyspace": {
  1167                "Name": "user",
  1168                "Sharded": true
  1169              },
  1170              "FieldQuery": "select col from `user` where 1 != 1",
  1171              "Query": "select col from `user` where :__sq_has_values1 = 1 and col in ::__sq1",
  1172              "Table": "`user`"
  1173            }
  1174          ]
  1175        },
  1176        "TablesUsed": [
  1177          "user.user"
  1178        ]
  1179      }
  1180    },
  1181    {
  1182      "comment": "ORDER BY RAND()",
  1183      "query": "select col from user order by RAND()",
  1184      "v3-plan": {
  1185        "QueryType": "SELECT",
  1186        "Original": "select col from user order by RAND()",
  1187        "Instructions": {
  1188          "OperatorType": "Route",
  1189          "Variant": "Scatter",
  1190          "Keyspace": {
  1191            "Name": "user",
  1192            "Sharded": true
  1193          },
  1194          "FieldQuery": "select col from `user` where 1 != 1",
  1195          "Query": "select col from `user` order by RAND()",
  1196          "Table": "`user`"
  1197        }
  1198      },
  1199      "gen4-plan": {
  1200        "QueryType": "SELECT",
  1201        "Original": "select col from user order by RAND()",
  1202        "Instructions": {
  1203          "OperatorType": "Route",
  1204          "Variant": "Scatter",
  1205          "Keyspace": {
  1206            "Name": "user",
  1207            "Sharded": true
  1208          },
  1209          "FieldQuery": "select col from `user` where 1 != 1",
  1210          "Query": "select col from `user` order by RAND()",
  1211          "Table": "`user`"
  1212        },
  1213        "TablesUsed": [
  1214          "user.user"
  1215        ]
  1216      }
  1217    },
  1218    {
  1219      "comment": "ORDER BY RAND() for join",
  1220      "query": "select user.col1 as a, user.col2, music.col3 from user join music on user.id = music.id where user.id = 1 order by RAND()",
  1221      "v3-plan": {
  1222        "QueryType": "SELECT",
  1223        "Original": "select user.col1 as a, user.col2, music.col3 from user join music on user.id = music.id where user.id = 1 order by RAND()",
  1224        "Instructions": {
  1225          "OperatorType": "Join",
  1226          "Variant": "Join",
  1227          "JoinColumnIndexes": "L:0,L:1,R:0",
  1228          "JoinVars": {
  1229            "user_id": 2
  1230          },
  1231          "TableName": "`user`_music",
  1232          "Inputs": [
  1233            {
  1234              "OperatorType": "Route",
  1235              "Variant": "EqualUnique",
  1236              "Keyspace": {
  1237                "Name": "user",
  1238                "Sharded": true
  1239              },
  1240              "FieldQuery": "select `user`.col1 as a, `user`.col2, `user`.id from `user` where 1 != 1",
  1241              "Query": "select `user`.col1 as a, `user`.col2, `user`.id from `user` where `user`.id = 1 order by RAND()",
  1242              "Table": "`user`",
  1243              "Values": [
  1244                "INT64(1)"
  1245              ],
  1246              "Vindex": "user_index"
  1247            },
  1248            {
  1249              "OperatorType": "Route",
  1250              "Variant": "EqualUnique",
  1251              "Keyspace": {
  1252                "Name": "user",
  1253                "Sharded": true
  1254              },
  1255              "FieldQuery": "select music.col3 from music where 1 != 1",
  1256              "Query": "select music.col3 from music where music.id = :user_id order by RAND()",
  1257              "Table": "music",
  1258              "Values": [
  1259                ":user_id"
  1260              ],
  1261              "Vindex": "music_user_map"
  1262            }
  1263          ]
  1264        }
  1265      },
  1266      "gen4-plan": {
  1267        "QueryType": "SELECT",
  1268        "Original": "select user.col1 as a, user.col2, music.col3 from user join music on user.id = music.id where user.id = 1 order by RAND()",
  1269        "Instructions": {
  1270          "OperatorType": "Join",
  1271          "Variant": "Join",
  1272          "JoinColumnIndexes": "L:1,L:2,R:0",
  1273          "JoinVars": {
  1274            "user_id": 0
  1275          },
  1276          "TableName": "`user`_music",
  1277          "Inputs": [
  1278            {
  1279              "OperatorType": "Route",
  1280              "Variant": "EqualUnique",
  1281              "Keyspace": {
  1282                "Name": "user",
  1283                "Sharded": true
  1284              },
  1285              "FieldQuery": "select `user`.id, `user`.col1 as a, `user`.col2 from `user` where 1 != 1",
  1286              "Query": "select `user`.id, `user`.col1 as a, `user`.col2 from `user` where `user`.id = 1 order by RAND()",
  1287              "Table": "`user`",
  1288              "Values": [
  1289                "INT64(1)"
  1290              ],
  1291              "Vindex": "user_index"
  1292            },
  1293            {
  1294              "OperatorType": "Route",
  1295              "Variant": "EqualUnique",
  1296              "Keyspace": {
  1297                "Name": "user",
  1298                "Sharded": true
  1299              },
  1300              "FieldQuery": "select music.col3 from music where 1 != 1",
  1301              "Query": "select music.col3 from music where music.id = :user_id order by RAND()",
  1302              "Table": "music",
  1303              "Values": [
  1304                ":user_id"
  1305              ],
  1306              "Vindex": "music_user_map"
  1307            }
  1308          ]
  1309        },
  1310        "TablesUsed": [
  1311          "user.music",
  1312          "user.user"
  1313        ]
  1314      }
  1315    },
  1316    {
  1317      "comment": "ORDER BY RAND() after pull-out subquery",
  1318      "query": "select col from user where col in (select col2 from user) order by rand()",
  1319      "v3-plan": {
  1320        "QueryType": "SELECT",
  1321        "Original": "select col from user where col in (select col2 from user) order by rand()",
  1322        "Instructions": {
  1323          "OperatorType": "Subquery",
  1324          "Variant": "PulloutIn",
  1325          "PulloutVars": [
  1326            "__sq_has_values1",
  1327            "__sq1"
  1328          ],
  1329          "Inputs": [
  1330            {
  1331              "OperatorType": "Route",
  1332              "Variant": "Scatter",
  1333              "Keyspace": {
  1334                "Name": "user",
  1335                "Sharded": true
  1336              },
  1337              "FieldQuery": "select col2 from `user` where 1 != 1",
  1338              "Query": "select col2 from `user`",
  1339              "Table": "`user`"
  1340            },
  1341            {
  1342              "OperatorType": "Route",
  1343              "Variant": "Scatter",
  1344              "Keyspace": {
  1345                "Name": "user",
  1346                "Sharded": true
  1347              },
  1348              "FieldQuery": "select col from `user` where 1 != 1",
  1349              "Query": "select col from `user` where :__sq_has_values1 = 1 and col in ::__sq1 order by rand()",
  1350              "Table": "`user`"
  1351            }
  1352          ]
  1353        }
  1354      },
  1355      "gen4-plan": {
  1356        "QueryType": "SELECT",
  1357        "Original": "select col from user where col in (select col2 from user) order by rand()",
  1358        "Instructions": {
  1359          "OperatorType": "Subquery",
  1360          "Variant": "PulloutIn",
  1361          "PulloutVars": [
  1362            "__sq_has_values1",
  1363            "__sq1"
  1364          ],
  1365          "Inputs": [
  1366            {
  1367              "OperatorType": "Route",
  1368              "Variant": "Scatter",
  1369              "Keyspace": {
  1370                "Name": "user",
  1371                "Sharded": true
  1372              },
  1373              "FieldQuery": "select col2 from `user` where 1 != 1",
  1374              "Query": "select col2 from `user`",
  1375              "Table": "`user`"
  1376            },
  1377            {
  1378              "OperatorType": "Route",
  1379              "Variant": "Scatter",
  1380              "Keyspace": {
  1381                "Name": "user",
  1382                "Sharded": true
  1383              },
  1384              "FieldQuery": "select col from `user` where 1 != 1",
  1385              "Query": "select col from `user` where :__sq_has_values1 = 1 and col in ::__sq1 order by rand()",
  1386              "Table": "`user`"
  1387            }
  1388          ]
  1389        },
  1390        "TablesUsed": [
  1391          "user.user"
  1392        ]
  1393      }
  1394    },
  1395    {
  1396      "comment": "Order by, '*' expression",
  1397      "query": "select * from user where id = 5 order by col",
  1398      "v3-plan": {
  1399        "QueryType": "SELECT",
  1400        "Original": "select * from user where id = 5 order by col",
  1401        "Instructions": {
  1402          "OperatorType": "Route",
  1403          "Variant": "EqualUnique",
  1404          "Keyspace": {
  1405            "Name": "user",
  1406            "Sharded": true
  1407          },
  1408          "FieldQuery": "select * from `user` where 1 != 1",
  1409          "Query": "select * from `user` where id = 5 order by col asc",
  1410          "Table": "`user`",
  1411          "Values": [
  1412            "INT64(5)"
  1413          ],
  1414          "Vindex": "user_index"
  1415        }
  1416      },
  1417      "gen4-plan": {
  1418        "QueryType": "SELECT",
  1419        "Original": "select * from user where id = 5 order by col",
  1420        "Instructions": {
  1421          "OperatorType": "Route",
  1422          "Variant": "EqualUnique",
  1423          "Keyspace": {
  1424            "Name": "user",
  1425            "Sharded": true
  1426          },
  1427          "FieldQuery": "select * from `user` where 1 != 1",
  1428          "Query": "select * from `user` where id = 5 order by col asc",
  1429          "Table": "`user`",
  1430          "Values": [
  1431            "INT64(5)"
  1432          ],
  1433          "Vindex": "user_index"
  1434        },
  1435        "TablesUsed": [
  1436          "user.user"
  1437        ]
  1438      }
  1439    },
  1440    {
  1441      "comment": "Order by, qualified '*' expression",
  1442      "query": "select user.* from user where id = 5 order by user.col",
  1443      "v3-plan": {
  1444        "QueryType": "SELECT",
  1445        "Original": "select user.* from user where id = 5 order by user.col",
  1446        "Instructions": {
  1447          "OperatorType": "Route",
  1448          "Variant": "EqualUnique",
  1449          "Keyspace": {
  1450            "Name": "user",
  1451            "Sharded": true
  1452          },
  1453          "FieldQuery": "select `user`.* from `user` where 1 != 1",
  1454          "Query": "select `user`.* from `user` where id = 5 order by `user`.col asc",
  1455          "Table": "`user`",
  1456          "Values": [
  1457            "INT64(5)"
  1458          ],
  1459          "Vindex": "user_index"
  1460        }
  1461      },
  1462      "gen4-plan": {
  1463        "QueryType": "SELECT",
  1464        "Original": "select user.* from user where id = 5 order by user.col",
  1465        "Instructions": {
  1466          "OperatorType": "Route",
  1467          "Variant": "EqualUnique",
  1468          "Keyspace": {
  1469            "Name": "user",
  1470            "Sharded": true
  1471          },
  1472          "FieldQuery": "select `user`.* from `user` where 1 != 1",
  1473          "Query": "select `user`.* from `user` where id = 5 order by `user`.col asc",
  1474          "Table": "`user`",
  1475          "Values": [
  1476            "INT64(5)"
  1477          ],
  1478          "Vindex": "user_index"
  1479        },
  1480        "TablesUsed": [
  1481          "user.user"
  1482        ]
  1483      }
  1484    },
  1485    {
  1486      "comment": "Order by, '*' expression with qualified reference",
  1487      "query": "select * from user where id = 5 order by user.col",
  1488      "v3-plan": {
  1489        "QueryType": "SELECT",
  1490        "Original": "select * from user where id = 5 order by user.col",
  1491        "Instructions": {
  1492          "OperatorType": "Route",
  1493          "Variant": "EqualUnique",
  1494          "Keyspace": {
  1495            "Name": "user",
  1496            "Sharded": true
  1497          },
  1498          "FieldQuery": "select * from `user` where 1 != 1",
  1499          "Query": "select * from `user` where id = 5 order by `user`.col asc",
  1500          "Table": "`user`",
  1501          "Values": [
  1502            "INT64(5)"
  1503          ],
  1504          "Vindex": "user_index"
  1505        }
  1506      },
  1507      "gen4-plan": {
  1508        "QueryType": "SELECT",
  1509        "Original": "select * from user where id = 5 order by user.col",
  1510        "Instructions": {
  1511          "OperatorType": "Route",
  1512          "Variant": "EqualUnique",
  1513          "Keyspace": {
  1514            "Name": "user",
  1515            "Sharded": true
  1516          },
  1517          "FieldQuery": "select * from `user` where 1 != 1",
  1518          "Query": "select * from `user` where id = 5 order by `user`.col asc",
  1519          "Table": "`user`",
  1520          "Values": [
  1521            "INT64(5)"
  1522          ],
  1523          "Vindex": "user_index"
  1524        },
  1525        "TablesUsed": [
  1526          "user.user"
  1527        ]
  1528      }
  1529    },
  1530    {
  1531      "comment": "Order by, '*' expression in a subquery",
  1532      "query": "select u.id, e.id from user u join user_extra e where u.col = e.col and u.col in (select * from user where user.id = u.id order by col)",
  1533      "v3-plan": {
  1534        "QueryType": "SELECT",
  1535        "Original": "select u.id, e.id from user u join user_extra e where u.col = e.col and u.col in (select * from user where user.id = u.id order by col)",
  1536        "Instructions": {
  1537          "OperatorType": "Join",
  1538          "Variant": "Join",
  1539          "JoinColumnIndexes": "L:0,R:0",
  1540          "JoinVars": {
  1541            "u_col": 1
  1542          },
  1543          "TableName": "`user`_user_extra",
  1544          "Inputs": [
  1545            {
  1546              "OperatorType": "Route",
  1547              "Variant": "Scatter",
  1548              "Keyspace": {
  1549                "Name": "user",
  1550                "Sharded": true
  1551              },
  1552              "FieldQuery": "select u.id, u.col from `user` as u where 1 != 1",
  1553              "Query": "select u.id, u.col from `user` as u where u.col in (select * from `user` where `user`.id = u.id order by col asc)",
  1554              "Table": "`user`"
  1555            },
  1556            {
  1557              "OperatorType": "Route",
  1558              "Variant": "Scatter",
  1559              "Keyspace": {
  1560                "Name": "user",
  1561                "Sharded": true
  1562              },
  1563              "FieldQuery": "select e.id from user_extra as e where 1 != 1",
  1564              "Query": "select e.id from user_extra as e where e.col = :u_col",
  1565              "Table": "user_extra"
  1566            }
  1567          ]
  1568        }
  1569      },
  1570      "gen4-plan": {
  1571        "QueryType": "SELECT",
  1572        "Original": "select u.id, e.id from user u join user_extra e where u.col = e.col and u.col in (select * from user where user.id = u.id order by col)",
  1573        "Instructions": {
  1574          "OperatorType": "Join",
  1575          "Variant": "Join",
  1576          "JoinColumnIndexes": "L:1,R:0",
  1577          "JoinVars": {
  1578            "u_col": 0
  1579          },
  1580          "TableName": "`user`_user_extra",
  1581          "Inputs": [
  1582            {
  1583              "OperatorType": "Route",
  1584              "Variant": "Scatter",
  1585              "Keyspace": {
  1586                "Name": "user",
  1587                "Sharded": true
  1588              },
  1589              "FieldQuery": "select u.col, u.id from `user` as u where 1 != 1",
  1590              "Query": "select u.col, u.id from `user` as u where u.col in (select * from `user` where `user`.id = u.id order by col asc)",
  1591              "Table": "`user`"
  1592            },
  1593            {
  1594              "OperatorType": "Route",
  1595              "Variant": "Scatter",
  1596              "Keyspace": {
  1597                "Name": "user",
  1598                "Sharded": true
  1599              },
  1600              "FieldQuery": "select e.id from user_extra as e where 1 != 1",
  1601              "Query": "select e.id from user_extra as e where e.col = :u_col",
  1602              "Table": "user_extra"
  1603            }
  1604          ]
  1605        },
  1606        "TablesUsed": [
  1607          "user.user",
  1608          "user.user_extra"
  1609        ]
  1610      }
  1611    },
  1612    {
  1613      "comment": "Order by, verify outer symtab is searched according to its own context.",
  1614      "query": "select u.id from user u having u.id in (select col2 from user where user.id = u.id order by u.col)",
  1615      "v3-plan": "VT03020: symbol u.col not found in subquery",
  1616      "gen4-plan": {
  1617        "QueryType": "SELECT",
  1618        "Original": "select u.id from user u having u.id in (select col2 from user where user.id = u.id order by u.col)",
  1619        "Instructions": {
  1620          "OperatorType": "Route",
  1621          "Variant": "Scatter",
  1622          "Keyspace": {
  1623            "Name": "user",
  1624            "Sharded": true
  1625          },
  1626          "FieldQuery": "select u.id from `user` as u where 1 != 1",
  1627          "Query": "select u.id from `user` as u where u.id in (select col2 from `user` where `user`.id = u.id order by u.col asc)",
  1628          "Table": "`user`"
  1629        },
  1630        "TablesUsed": [
  1631          "user.user"
  1632        ]
  1633      }
  1634    },
  1635    {
  1636      "comment": "Order by, qualified '*' expression, name mismatched.",
  1637      "query": "select user.* from user where id = 5 order by e.col",
  1638      "v3-plan": "VT03019: symbol e.col not found",
  1639      "gen4-plan": "symbol e.col not found"
  1640    },
  1641    {
  1642      "comment": "Order by, invalid column number",
  1643      "query": "select col from user order by 18446744073709551616",
  1644      "v3-plan": "VT13001: [BUG] error parsing column number: 18446744073709551616",
  1645      "gen4-plan": "error parsing column number: 18446744073709551616"
  1646    },
  1647    {
  1648      "comment": "Order by, out of range column number",
  1649      "query": "select col from user order by 2",
  1650      "v3-plan": "VT03014: unknown column '2' in 'order clause'",
  1651      "gen4-plan": "Unknown column '2' in 'order clause'"
  1652    },
  1653    {
  1654      "comment": "Order by, '*' expression with qualified reference and using collate",
  1655      "query": "select * from user where id = 5 order by user.col collate utf8_general_ci",
  1656      "v3-plan": {
  1657        "QueryType": "SELECT",
  1658        "Original": "select * from user where id = 5 order by user.col collate utf8_general_ci",
  1659        "Instructions": {
  1660          "OperatorType": "Route",
  1661          "Variant": "EqualUnique",
  1662          "Keyspace": {
  1663            "Name": "user",
  1664            "Sharded": true
  1665          },
  1666          "FieldQuery": "select * from `user` where 1 != 1",
  1667          "Query": "select * from `user` where id = 5 order by `user`.col collate utf8_general_ci asc",
  1668          "Table": "`user`",
  1669          "Values": [
  1670            "INT64(5)"
  1671          ],
  1672          "Vindex": "user_index"
  1673        }
  1674      },
  1675      "gen4-plan": {
  1676        "QueryType": "SELECT",
  1677        "Original": "select * from user where id = 5 order by user.col collate utf8_general_ci",
  1678        "Instructions": {
  1679          "OperatorType": "Route",
  1680          "Variant": "EqualUnique",
  1681          "Keyspace": {
  1682            "Name": "user",
  1683            "Sharded": true
  1684          },
  1685          "FieldQuery": "select * from `user` where 1 != 1",
  1686          "Query": "select * from `user` where id = 5 order by `user`.col collate utf8_general_ci asc",
  1687          "Table": "`user`",
  1688          "Values": [
  1689            "INT64(5)"
  1690          ],
  1691          "Vindex": "user_index"
  1692        },
  1693        "TablesUsed": [
  1694          "user.user"
  1695        ]
  1696      }
  1697    },
  1698    {
  1699      "comment": "Order by with math functions",
  1700      "query": "select * from user where id = 5 order by -col1",
  1701      "v3-plan": {
  1702        "QueryType": "SELECT",
  1703        "Original": "select * from user where id = 5 order by -col1",
  1704        "Instructions": {
  1705          "OperatorType": "Route",
  1706          "Variant": "EqualUnique",
  1707          "Keyspace": {
  1708            "Name": "user",
  1709            "Sharded": true
  1710          },
  1711          "FieldQuery": "select * from `user` where 1 != 1",
  1712          "Query": "select * from `user` where id = 5 order by -col1 asc",
  1713          "Table": "`user`",
  1714          "Values": [
  1715            "INT64(5)"
  1716          ],
  1717          "Vindex": "user_index"
  1718        }
  1719      },
  1720      "gen4-plan": {
  1721        "QueryType": "SELECT",
  1722        "Original": "select * from user where id = 5 order by -col1",
  1723        "Instructions": {
  1724          "OperatorType": "Route",
  1725          "Variant": "EqualUnique",
  1726          "Keyspace": {
  1727            "Name": "user",
  1728            "Sharded": true
  1729          },
  1730          "FieldQuery": "select * from `user` where 1 != 1",
  1731          "Query": "select * from `user` where id = 5 order by -col1 asc",
  1732          "Table": "`user`",
  1733          "Values": [
  1734            "INT64(5)"
  1735          ],
  1736          "Vindex": "user_index"
  1737        },
  1738        "TablesUsed": [
  1739          "user.user"
  1740        ]
  1741      }
  1742    },
  1743    {
  1744      "comment": "Order by with string operations",
  1745      "query": "select * from user where id = 5 order by concat(col,col1) collate utf8_general_ci desc",
  1746      "v3-plan": {
  1747        "QueryType": "SELECT",
  1748        "Original": "select * from user where id = 5 order by concat(col,col1) collate utf8_general_ci desc",
  1749        "Instructions": {
  1750          "OperatorType": "Route",
  1751          "Variant": "EqualUnique",
  1752          "Keyspace": {
  1753            "Name": "user",
  1754            "Sharded": true
  1755          },
  1756          "FieldQuery": "select * from `user` where 1 != 1",
  1757          "Query": "select * from `user` where id = 5 order by concat(col, col1) collate utf8_general_ci desc",
  1758          "Table": "`user`",
  1759          "Values": [
  1760            "INT64(5)"
  1761          ],
  1762          "Vindex": "user_index"
  1763        }
  1764      },
  1765      "gen4-plan": {
  1766        "QueryType": "SELECT",
  1767        "Original": "select * from user where id = 5 order by concat(col,col1) collate utf8_general_ci desc",
  1768        "Instructions": {
  1769          "OperatorType": "Route",
  1770          "Variant": "EqualUnique",
  1771          "Keyspace": {
  1772            "Name": "user",
  1773            "Sharded": true
  1774          },
  1775          "FieldQuery": "select * from `user` where 1 != 1",
  1776          "Query": "select * from `user` where id = 5 order by concat(col, col1) collate utf8_general_ci desc",
  1777          "Table": "`user`",
  1778          "Values": [
  1779            "INT64(5)"
  1780          ],
  1781          "Vindex": "user_index"
  1782        },
  1783        "TablesUsed": [
  1784          "user.user"
  1785        ]
  1786      }
  1787    },
  1788    {
  1789      "comment": "Order by with math operations",
  1790      "query": "select * from user where id = 5 order by id+col collate utf8_general_ci desc",
  1791      "v3-plan": {
  1792        "QueryType": "SELECT",
  1793        "Original": "select * from user where id = 5 order by id+col collate utf8_general_ci desc",
  1794        "Instructions": {
  1795          "OperatorType": "Route",
  1796          "Variant": "EqualUnique",
  1797          "Keyspace": {
  1798            "Name": "user",
  1799            "Sharded": true
  1800          },
  1801          "FieldQuery": "select * from `user` where 1 != 1",
  1802          "Query": "select * from `user` where id = 5 order by id + col collate utf8_general_ci desc",
  1803          "Table": "`user`",
  1804          "Values": [
  1805            "INT64(5)"
  1806          ],
  1807          "Vindex": "user_index"
  1808        }
  1809      },
  1810      "gen4-plan": {
  1811        "QueryType": "SELECT",
  1812        "Original": "select * from user where id = 5 order by id+col collate utf8_general_ci desc",
  1813        "Instructions": {
  1814          "OperatorType": "Route",
  1815          "Variant": "EqualUnique",
  1816          "Keyspace": {
  1817            "Name": "user",
  1818            "Sharded": true
  1819          },
  1820          "FieldQuery": "select * from `user` where 1 != 1",
  1821          "Query": "select * from `user` where id = 5 order by id + col collate utf8_general_ci desc",
  1822          "Table": "`user`",
  1823          "Values": [
  1824            "INT64(5)"
  1825          ],
  1826          "Vindex": "user_index"
  1827        },
  1828        "TablesUsed": [
  1829          "user.user"
  1830        ]
  1831      }
  1832    },
  1833    {
  1834      "comment": "Order by derived table column",
  1835      "query": "select * from user u join (select user_id from user_extra where user_id = 5) eu on u.id = eu.user_id where u.id = 5 order by eu.user_id",
  1836      "v3-plan": {
  1837        "QueryType": "SELECT",
  1838        "Original": "select * from user u join (select user_id from user_extra where user_id = 5) eu on u.id = eu.user_id where u.id = 5 order by eu.user_id",
  1839        "Instructions": {
  1840          "OperatorType": "Route",
  1841          "Variant": "EqualUnique",
  1842          "Keyspace": {
  1843            "Name": "user",
  1844            "Sharded": true
  1845          },
  1846          "FieldQuery": "select * from `user` as u join (select user_id from user_extra where 1 != 1) as eu on u.id = eu.user_id where 1 != 1",
  1847          "Query": "select * from `user` as u join (select user_id from user_extra where user_id = 5) as eu on u.id = eu.user_id where u.id = 5 order by eu.user_id asc",
  1848          "Table": "`user`, user_extra",
  1849          "Values": [
  1850            "INT64(5)"
  1851          ],
  1852          "Vindex": "user_index"
  1853        }
  1854      },
  1855      "gen4-plan": {
  1856        "QueryType": "SELECT",
  1857        "Original": "select * from user u join (select user_id from user_extra where user_id = 5) eu on u.id = eu.user_id where u.id = 5 order by eu.user_id",
  1858        "Instructions": {
  1859          "OperatorType": "Route",
  1860          "Variant": "EqualUnique",
  1861          "Keyspace": {
  1862            "Name": "user",
  1863            "Sharded": true
  1864          },
  1865          "FieldQuery": "select * from `user` as u, (select user_id from user_extra where 1 != 1) as eu where 1 != 1",
  1866          "Query": "select * from `user` as u, (select user_id from user_extra where user_id = 5) as eu where u.id = 5 and u.id = eu.user_id order by eu.user_id asc",
  1867          "Table": "`user`, user_extra",
  1868          "Values": [
  1869            "INT64(5)"
  1870          ],
  1871          "Vindex": "user_index"
  1872        },
  1873        "TablesUsed": [
  1874          "user.user",
  1875          "user.user_extra"
  1876        ]
  1877      }
  1878    },
  1879    {
  1880      "comment": "routing rules: order by gets pushed for routes",
  1881      "query": "select col from route1 where id = 1 order by col",
  1882      "v3-plan": {
  1883        "QueryType": "SELECT",
  1884        "Original": "select col from route1 where id = 1 order by col",
  1885        "Instructions": {
  1886          "OperatorType": "Route",
  1887          "Variant": "EqualUnique",
  1888          "Keyspace": {
  1889            "Name": "user",
  1890            "Sharded": true
  1891          },
  1892          "FieldQuery": "select col from `user` as route1 where 1 != 1",
  1893          "Query": "select col from `user` as route1 where id = 1 order by col asc",
  1894          "Table": "`user`",
  1895          "Values": [
  1896            "INT64(1)"
  1897          ],
  1898          "Vindex": "user_index"
  1899        }
  1900      },
  1901      "gen4-plan": {
  1902        "QueryType": "SELECT",
  1903        "Original": "select col from route1 where id = 1 order by col",
  1904        "Instructions": {
  1905          "OperatorType": "Route",
  1906          "Variant": "EqualUnique",
  1907          "Keyspace": {
  1908            "Name": "user",
  1909            "Sharded": true
  1910          },
  1911          "FieldQuery": "select col from `user` as route1 where 1 != 1",
  1912          "Query": "select col from `user` as route1 where id = 1 order by col asc",
  1913          "Table": "`user`",
  1914          "Values": [
  1915            "INT64(1)"
  1916          ],
  1917          "Vindex": "user_index"
  1918        },
  1919        "TablesUsed": [
  1920          "user.user"
  1921        ]
  1922      }
  1923    },
  1924    {
  1925      "comment": "LIMIT",
  1926      "query": "select col1 from user where id = 1 limit 1",
  1927      "v3-plan": {
  1928        "QueryType": "SELECT",
  1929        "Original": "select col1 from user where id = 1 limit 1",
  1930        "Instructions": {
  1931          "OperatorType": "Route",
  1932          "Variant": "EqualUnique",
  1933          "Keyspace": {
  1934            "Name": "user",
  1935            "Sharded": true
  1936          },
  1937          "FieldQuery": "select col1 from `user` where 1 != 1",
  1938          "Query": "select col1 from `user` where id = 1 limit 1",
  1939          "Table": "`user`",
  1940          "Values": [
  1941            "INT64(1)"
  1942          ],
  1943          "Vindex": "user_index"
  1944        }
  1945      },
  1946      "gen4-plan": {
  1947        "QueryType": "SELECT",
  1948        "Original": "select col1 from user where id = 1 limit 1",
  1949        "Instructions": {
  1950          "OperatorType": "Route",
  1951          "Variant": "EqualUnique",
  1952          "Keyspace": {
  1953            "Name": "user",
  1954            "Sharded": true
  1955          },
  1956          "FieldQuery": "select col1 from `user` where 1 != 1",
  1957          "Query": "select col1 from `user` where id = 1 limit 1",
  1958          "Table": "`user`",
  1959          "Values": [
  1960            "INT64(1)"
  1961          ],
  1962          "Vindex": "user_index"
  1963        },
  1964        "TablesUsed": [
  1965          "user.user"
  1966        ]
  1967      }
  1968    },
  1969    {
  1970      "comment": "limit for joins. Can't push down the limit because result\n# counts get multiplied by join operations.",
  1971      "query": "select user.col from user join user_extra limit 1",
  1972      "v3-plan": {
  1973        "QueryType": "SELECT",
  1974        "Original": "select user.col from user join user_extra limit 1",
  1975        "Instructions": {
  1976          "OperatorType": "Limit",
  1977          "Count": "INT64(1)",
  1978          "Inputs": [
  1979            {
  1980              "OperatorType": "Join",
  1981              "Variant": "Join",
  1982              "JoinColumnIndexes": "L:0",
  1983              "TableName": "`user`_user_extra",
  1984              "Inputs": [
  1985                {
  1986                  "OperatorType": "Route",
  1987                  "Variant": "Scatter",
  1988                  "Keyspace": {
  1989                    "Name": "user",
  1990                    "Sharded": true
  1991                  },
  1992                  "FieldQuery": "select `user`.col from `user` where 1 != 1",
  1993                  "Query": "select `user`.col from `user`",
  1994                  "Table": "`user`"
  1995                },
  1996                {
  1997                  "OperatorType": "Route",
  1998                  "Variant": "Scatter",
  1999                  "Keyspace": {
  2000                    "Name": "user",
  2001                    "Sharded": true
  2002                  },
  2003                  "FieldQuery": "select 1 from user_extra where 1 != 1",
  2004                  "Query": "select 1 from user_extra",
  2005                  "Table": "user_extra"
  2006                }
  2007              ]
  2008            }
  2009          ]
  2010        }
  2011      },
  2012      "gen4-plan": {
  2013        "QueryType": "SELECT",
  2014        "Original": "select user.col from user join user_extra limit 1",
  2015        "Instructions": {
  2016          "OperatorType": "Limit",
  2017          "Count": "INT64(1)",
  2018          "Inputs": [
  2019            {
  2020              "OperatorType": "Join",
  2021              "Variant": "Join",
  2022              "JoinColumnIndexes": "L:0",
  2023              "TableName": "`user`_user_extra",
  2024              "Inputs": [
  2025                {
  2026                  "OperatorType": "Route",
  2027                  "Variant": "Scatter",
  2028                  "Keyspace": {
  2029                    "Name": "user",
  2030                    "Sharded": true
  2031                  },
  2032                  "FieldQuery": "select `user`.col from `user` where 1 != 1",
  2033                  "Query": "select `user`.col from `user`",
  2034                  "Table": "`user`"
  2035                },
  2036                {
  2037                  "OperatorType": "Route",
  2038                  "Variant": "Scatter",
  2039                  "Keyspace": {
  2040                    "Name": "user",
  2041                    "Sharded": true
  2042                  },
  2043                  "FieldQuery": "select 1 from user_extra where 1 != 1",
  2044                  "Query": "select 1 from user_extra",
  2045                  "Table": "user_extra"
  2046                }
  2047              ]
  2048            }
  2049          ]
  2050        },
  2051        "TablesUsed": [
  2052          "user.user",
  2053          "user.user_extra"
  2054        ]
  2055      }
  2056    },
  2057    {
  2058      "comment": "limit for scatter",
  2059      "query": "select col from user limit 1",
  2060      "v3-plan": {
  2061        "QueryType": "SELECT",
  2062        "Original": "select col from user limit 1",
  2063        "Instructions": {
  2064          "OperatorType": "Limit",
  2065          "Count": "INT64(1)",
  2066          "Inputs": [
  2067            {
  2068              "OperatorType": "Route",
  2069              "Variant": "Scatter",
  2070              "Keyspace": {
  2071                "Name": "user",
  2072                "Sharded": true
  2073              },
  2074              "FieldQuery": "select col from `user` where 1 != 1",
  2075              "Query": "select col from `user` limit :__upper_limit",
  2076              "Table": "`user`"
  2077            }
  2078          ]
  2079        }
  2080      },
  2081      "gen4-plan": {
  2082        "QueryType": "SELECT",
  2083        "Original": "select col from user limit 1",
  2084        "Instructions": {
  2085          "OperatorType": "Limit",
  2086          "Count": "INT64(1)",
  2087          "Inputs": [
  2088            {
  2089              "OperatorType": "Route",
  2090              "Variant": "Scatter",
  2091              "Keyspace": {
  2092                "Name": "user",
  2093                "Sharded": true
  2094              },
  2095              "FieldQuery": "select col from `user` where 1 != 1",
  2096              "Query": "select col from `user` limit :__upper_limit",
  2097              "Table": "`user`"
  2098            }
  2099          ]
  2100        },
  2101        "TablesUsed": [
  2102          "user.user"
  2103        ]
  2104      }
  2105    },
  2106    {
  2107      "comment": "limit for scatter with bind var",
  2108      "query": "select col from user limit :a",
  2109      "v3-plan": {
  2110        "QueryType": "SELECT",
  2111        "Original": "select col from user limit :a",
  2112        "Instructions": {
  2113          "OperatorType": "Limit",
  2114          "Count": ":a",
  2115          "Inputs": [
  2116            {
  2117              "OperatorType": "Route",
  2118              "Variant": "Scatter",
  2119              "Keyspace": {
  2120                "Name": "user",
  2121                "Sharded": true
  2122              },
  2123              "FieldQuery": "select col from `user` where 1 != 1",
  2124              "Query": "select col from `user` limit :__upper_limit",
  2125              "Table": "`user`"
  2126            }
  2127          ]
  2128        }
  2129      },
  2130      "gen4-plan": {
  2131        "QueryType": "SELECT",
  2132        "Original": "select col from user limit :a",
  2133        "Instructions": {
  2134          "OperatorType": "Limit",
  2135          "Count": ":a",
  2136          "Inputs": [
  2137            {
  2138              "OperatorType": "Route",
  2139              "Variant": "Scatter",
  2140              "Keyspace": {
  2141                "Name": "user",
  2142                "Sharded": true
  2143              },
  2144              "FieldQuery": "select col from `user` where 1 != 1",
  2145              "Query": "select col from `user` limit :__upper_limit",
  2146              "Table": "`user`"
  2147            }
  2148          ]
  2149        },
  2150        "TablesUsed": [
  2151          "user.user"
  2152        ]
  2153      }
  2154    },
  2155    {
  2156      "comment": "cross-shard expression in parenthesis with limit",
  2157      "query": "select * from user where (id1 = 4 AND name1 ='abc') limit 5",
  2158      "v3-plan": {
  2159        "QueryType": "SELECT",
  2160        "Original": "select * from user where (id1 = 4 AND name1 ='abc') limit 5",
  2161        "Instructions": {
  2162          "OperatorType": "Limit",
  2163          "Count": "INT64(5)",
  2164          "Inputs": [
  2165            {
  2166              "OperatorType": "Route",
  2167              "Variant": "Scatter",
  2168              "Keyspace": {
  2169                "Name": "user",
  2170                "Sharded": true
  2171              },
  2172              "FieldQuery": "select * from `user` where 1 != 1",
  2173              "Query": "select * from `user` where id1 = 4 and name1 = 'abc' limit :__upper_limit",
  2174              "Table": "`user`"
  2175            }
  2176          ]
  2177        }
  2178      },
  2179      "gen4-plan": {
  2180        "QueryType": "SELECT",
  2181        "Original": "select * from user where (id1 = 4 AND name1 ='abc') limit 5",
  2182        "Instructions": {
  2183          "OperatorType": "Limit",
  2184          "Count": "INT64(5)",
  2185          "Inputs": [
  2186            {
  2187              "OperatorType": "Route",
  2188              "Variant": "Scatter",
  2189              "Keyspace": {
  2190                "Name": "user",
  2191                "Sharded": true
  2192              },
  2193              "FieldQuery": "select * from `user` where 1 != 1",
  2194              "Query": "select * from `user` where id1 = 4 and name1 = 'abc' limit :__upper_limit",
  2195              "Table": "`user`"
  2196            }
  2197          ]
  2198        },
  2199        "TablesUsed": [
  2200          "user.user"
  2201        ]
  2202      }
  2203    },
  2204    {
  2205      "comment": "scatter limit after pullout subquery",
  2206      "query": "select col from user where col in (select col1 from user) limit 1",
  2207      "v3-plan": {
  2208        "QueryType": "SELECT",
  2209        "Original": "select col from user where col in (select col1 from user) limit 1",
  2210        "Instructions": {
  2211          "OperatorType": "Limit",
  2212          "Count": "INT64(1)",
  2213          "Inputs": [
  2214            {
  2215              "OperatorType": "Subquery",
  2216              "Variant": "PulloutIn",
  2217              "PulloutVars": [
  2218                "__sq_has_values1",
  2219                "__sq1"
  2220              ],
  2221              "Inputs": [
  2222                {
  2223                  "OperatorType": "Route",
  2224                  "Variant": "Scatter",
  2225                  "Keyspace": {
  2226                    "Name": "user",
  2227                    "Sharded": true
  2228                  },
  2229                  "FieldQuery": "select col1 from `user` where 1 != 1",
  2230                  "Query": "select col1 from `user`",
  2231                  "Table": "`user`"
  2232                },
  2233                {
  2234                  "OperatorType": "Route",
  2235                  "Variant": "Scatter",
  2236                  "Keyspace": {
  2237                    "Name": "user",
  2238                    "Sharded": true
  2239                  },
  2240                  "FieldQuery": "select col from `user` where 1 != 1",
  2241                  "Query": "select col from `user` where :__sq_has_values1 = 1 and col in ::__sq1 limit :__upper_limit",
  2242                  "Table": "`user`"
  2243                }
  2244              ]
  2245            }
  2246          ]
  2247        }
  2248      },
  2249      "gen4-plan": {
  2250        "QueryType": "SELECT",
  2251        "Original": "select col from user where col in (select col1 from user) limit 1",
  2252        "Instructions": {
  2253          "OperatorType": "Limit",
  2254          "Count": "INT64(1)",
  2255          "Inputs": [
  2256            {
  2257              "OperatorType": "Subquery",
  2258              "Variant": "PulloutIn",
  2259              "PulloutVars": [
  2260                "__sq_has_values1",
  2261                "__sq1"
  2262              ],
  2263              "Inputs": [
  2264                {
  2265                  "OperatorType": "Route",
  2266                  "Variant": "Scatter",
  2267                  "Keyspace": {
  2268                    "Name": "user",
  2269                    "Sharded": true
  2270                  },
  2271                  "FieldQuery": "select col1 from `user` where 1 != 1",
  2272                  "Query": "select col1 from `user`",
  2273                  "Table": "`user`"
  2274                },
  2275                {
  2276                  "OperatorType": "Route",
  2277                  "Variant": "Scatter",
  2278                  "Keyspace": {
  2279                    "Name": "user",
  2280                    "Sharded": true
  2281                  },
  2282                  "FieldQuery": "select col from `user` where 1 != 1",
  2283                  "Query": "select col from `user` where :__sq_has_values1 = 1 and col in ::__sq1 limit :__upper_limit",
  2284                  "Table": "`user`"
  2285                }
  2286              ]
  2287            }
  2288          ]
  2289        },
  2290        "TablesUsed": [
  2291          "user.user"
  2292        ]
  2293      }
  2294    },
  2295    {
  2296      "comment": "limit on reference table",
  2297      "query": "select col from ref limit 1",
  2298      "v3-plan": {
  2299        "QueryType": "SELECT",
  2300        "Original": "select col from ref limit 1",
  2301        "Instructions": {
  2302          "OperatorType": "Route",
  2303          "Variant": "Reference",
  2304          "Keyspace": {
  2305            "Name": "user",
  2306            "Sharded": true
  2307          },
  2308          "FieldQuery": "select col from ref where 1 != 1",
  2309          "Query": "select col from ref limit 1",
  2310          "Table": "ref"
  2311        }
  2312      },
  2313      "gen4-plan": {
  2314        "QueryType": "SELECT",
  2315        "Original": "select col from ref limit 1",
  2316        "Instructions": {
  2317          "OperatorType": "Route",
  2318          "Variant": "Reference",
  2319          "Keyspace": {
  2320            "Name": "user",
  2321            "Sharded": true
  2322          },
  2323          "FieldQuery": "select col from ref where 1 != 1",
  2324          "Query": "select col from ref limit 1",
  2325          "Table": "ref"
  2326        },
  2327        "TablesUsed": [
  2328          "user.ref"
  2329        ]
  2330      }
  2331    },
  2332    {
  2333      "comment": "arithmetic limit",
  2334      "query": "select id from user limit 1+1",
  2335      "v3-plan": {
  2336        "QueryType": "SELECT",
  2337        "Original": "select id from user limit 1+1",
  2338        "Instructions": {
  2339          "OperatorType": "Limit",
  2340          "Count": "INT64(2)",
  2341          "Inputs": [
  2342            {
  2343              "OperatorType": "Route",
  2344              "Variant": "Scatter",
  2345              "Keyspace": {
  2346                "Name": "user",
  2347                "Sharded": true
  2348              },
  2349              "FieldQuery": "select id from `user` where 1 != 1",
  2350              "Query": "select id from `user` limit :__upper_limit",
  2351              "Table": "`user`"
  2352            }
  2353          ]
  2354        }
  2355      },
  2356      "gen4-plan": {
  2357        "QueryType": "SELECT",
  2358        "Original": "select id from user limit 1+1",
  2359        "Instructions": {
  2360          "OperatorType": "Limit",
  2361          "Count": "INT64(2)",
  2362          "Inputs": [
  2363            {
  2364              "OperatorType": "Route",
  2365              "Variant": "Scatter",
  2366              "Keyspace": {
  2367                "Name": "user",
  2368                "Sharded": true
  2369              },
  2370              "FieldQuery": "select id from `user` where 1 != 1",
  2371              "Query": "select id from `user` limit :__upper_limit",
  2372              "Table": "`user`"
  2373            }
  2374          ]
  2375        },
  2376        "TablesUsed": [
  2377          "user.user"
  2378        ]
  2379      }
  2380    },
  2381    {
  2382      "comment": "order by column alias",
  2383      "query": "select id as foo from music order by foo",
  2384      "v3-plan": {
  2385        "QueryType": "SELECT",
  2386        "Original": "select id as foo from music order by foo",
  2387        "Instructions": {
  2388          "OperatorType": "Route",
  2389          "Variant": "Scatter",
  2390          "Keyspace": {
  2391            "Name": "user",
  2392            "Sharded": true
  2393          },
  2394          "FieldQuery": "select id as foo, weight_string(id) from music where 1 != 1",
  2395          "OrderBy": "(0|1) ASC",
  2396          "Query": "select id as foo, weight_string(id) from music order by foo asc",
  2397          "ResultColumns": 1,
  2398          "Table": "music"
  2399        }
  2400      },
  2401      "gen4-plan": {
  2402        "QueryType": "SELECT",
  2403        "Original": "select id as foo from music order by foo",
  2404        "Instructions": {
  2405          "OperatorType": "Route",
  2406          "Variant": "Scatter",
  2407          "Keyspace": {
  2408            "Name": "user",
  2409            "Sharded": true
  2410          },
  2411          "FieldQuery": "select id as foo, weight_string(id) from music where 1 != 1",
  2412          "OrderBy": "(0|1) ASC",
  2413          "Query": "select id as foo, weight_string(id) from music order by foo asc",
  2414          "ResultColumns": 1,
  2415          "Table": "music"
  2416        },
  2417        "TablesUsed": [
  2418          "user.music"
  2419        ]
  2420      }
  2421    },
  2422    {
  2423      "comment": "column alias for a table column in order by",
  2424      "query": "select id as foo, id2 as id from music order by id",
  2425      "v3-plan": {
  2426        "QueryType": "SELECT",
  2427        "Original": "select id as foo, id2 as id from music order by id",
  2428        "Instructions": {
  2429          "OperatorType": "Route",
  2430          "Variant": "Scatter",
  2431          "Keyspace": {
  2432            "Name": "user",
  2433            "Sharded": true
  2434          },
  2435          "FieldQuery": "select id as foo, id2 as id, weight_string(id2) from music where 1 != 1",
  2436          "OrderBy": "(1|2) ASC",
  2437          "Query": "select id as foo, id2 as id, weight_string(id2) from music order by id asc",
  2438          "ResultColumns": 2,
  2439          "Table": "music"
  2440        }
  2441      },
  2442      "gen4-plan": {
  2443        "QueryType": "SELECT",
  2444        "Original": "select id as foo, id2 as id from music order by id",
  2445        "Instructions": {
  2446          "OperatorType": "Route",
  2447          "Variant": "Scatter",
  2448          "Keyspace": {
  2449            "Name": "user",
  2450            "Sharded": true
  2451          },
  2452          "FieldQuery": "select id as foo, id2 as id, weight_string(id2) from music where 1 != 1",
  2453          "OrderBy": "(1|2) ASC",
  2454          "Query": "select id as foo, id2 as id, weight_string(id2) from music order by id asc",
  2455          "ResultColumns": 2,
  2456          "Table": "music"
  2457        },
  2458        "TablesUsed": [
  2459          "user.music"
  2460        ]
  2461      }
  2462    },
  2463    {
  2464      "comment": "ordering on the left side of the join",
  2465      "query": "select name from user, music order by name",
  2466      "v3-plan": {
  2467        "QueryType": "SELECT",
  2468        "Original": "select name from user, music order by name",
  2469        "Instructions": {
  2470          "OperatorType": "Join",
  2471          "Variant": "Join",
  2472          "JoinColumnIndexes": "L:0",
  2473          "TableName": "`user`_music",
  2474          "Inputs": [
  2475            {
  2476              "OperatorType": "Route",
  2477              "Variant": "Scatter",
  2478              "Keyspace": {
  2479                "Name": "user",
  2480                "Sharded": true
  2481              },
  2482              "FieldQuery": "select `name`, weight_string(`name`) from `user` where 1 != 1",
  2483              "OrderBy": "(0|1) ASC",
  2484              "Query": "select `name`, weight_string(`name`) from `user` order by `name` asc",
  2485              "ResultColumns": 1,
  2486              "Table": "`user`"
  2487            },
  2488            {
  2489              "OperatorType": "Route",
  2490              "Variant": "Scatter",
  2491              "Keyspace": {
  2492                "Name": "user",
  2493                "Sharded": true
  2494              },
  2495              "FieldQuery": "select 1 from music where 1 != 1",
  2496              "Query": "select 1 from music",
  2497              "Table": "music"
  2498            }
  2499          ]
  2500        }
  2501      },
  2502      "gen4-plan": {
  2503        "QueryType": "SELECT",
  2504        "Original": "select name from user, music order by name",
  2505        "Instructions": {
  2506          "OperatorType": "Join",
  2507          "Variant": "Join",
  2508          "JoinColumnIndexes": "L:0",
  2509          "TableName": "`user`_music",
  2510          "Inputs": [
  2511            {
  2512              "OperatorType": "Route",
  2513              "Variant": "Scatter",
  2514              "Keyspace": {
  2515                "Name": "user",
  2516                "Sharded": true
  2517              },
  2518              "FieldQuery": "select `name`, weight_string(`name`) from `user` where 1 != 1",
  2519              "OrderBy": "(0|1) ASC",
  2520              "Query": "select `name`, weight_string(`name`) from `user` order by `name` asc",
  2521              "Table": "`user`"
  2522            },
  2523            {
  2524              "OperatorType": "Route",
  2525              "Variant": "Scatter",
  2526              "Keyspace": {
  2527                "Name": "user",
  2528                "Sharded": true
  2529              },
  2530              "FieldQuery": "select 1 from music where 1 != 1",
  2531              "Query": "select 1 from music",
  2532              "Table": "music"
  2533            }
  2534          ]
  2535        },
  2536        "TablesUsed": [
  2537          "user.music",
  2538          "user.user"
  2539        ]
  2540      }
  2541    },
  2542    {
  2543      "comment": "aggregation and non-aggregations column without group by",
  2544      "query": "select count(id), num from user",
  2545      "v3-plan": {
  2546        "QueryType": "SELECT",
  2547        "Original": "select count(id), num from user",
  2548        "Instructions": {
  2549          "OperatorType": "Aggregate",
  2550          "Variant": "Scalar",
  2551          "Aggregates": "sum_count(0) AS count",
  2552          "Inputs": [
  2553            {
  2554              "OperatorType": "Route",
  2555              "Variant": "Scatter",
  2556              "Keyspace": {
  2557                "Name": "user",
  2558                "Sharded": true
  2559              },
  2560              "FieldQuery": "select count(id), num from `user` where 1 != 1",
  2561              "Query": "select count(id), num from `user`",
  2562              "Table": "`user`"
  2563            }
  2564          ]
  2565        }
  2566      },
  2567      "gen4-plan": {
  2568        "QueryType": "SELECT",
  2569        "Original": "select count(id), num from user",
  2570        "Instructions": {
  2571          "OperatorType": "Aggregate",
  2572          "Variant": "Scalar",
  2573          "Aggregates": "sum_count(0) AS count(id), random(1) AS num",
  2574          "Inputs": [
  2575            {
  2576              "OperatorType": "Route",
  2577              "Variant": "Scatter",
  2578              "Keyspace": {
  2579                "Name": "user",
  2580                "Sharded": true
  2581              },
  2582              "FieldQuery": "select count(id), num from `user` where 1 != 1",
  2583              "Query": "select count(id), num from `user`",
  2584              "Table": "`user`"
  2585            }
  2586          ]
  2587        },
  2588        "TablesUsed": [
  2589          "user.user"
  2590        ]
  2591      }
  2592    },
  2593    {
  2594      "comment": "aggregation and non-aggregations column with order by",
  2595      "query": "select count(id), num from user order by 2",
  2596      "v3-plan": {
  2597        "QueryType": "SELECT",
  2598        "Original": "select count(id), num from user order by 2",
  2599        "Instructions": {
  2600          "OperatorType": "Sort",
  2601          "Variant": "Memory",
  2602          "OrderBy": "(1|2) ASC",
  2603          "ResultColumns": 2,
  2604          "Inputs": [
  2605            {
  2606              "OperatorType": "Aggregate",
  2607              "Variant": "Scalar",
  2608              "Aggregates": "sum_count(0) AS count",
  2609              "ResultColumns": 3,
  2610              "Inputs": [
  2611                {
  2612                  "OperatorType": "Route",
  2613                  "Variant": "Scatter",
  2614                  "Keyspace": {
  2615                    "Name": "user",
  2616                    "Sharded": true
  2617                  },
  2618                  "FieldQuery": "select count(id), num, weight_string(num) from `user` where 1 != 1",
  2619                  "Query": "select count(id), num, weight_string(num) from `user`",
  2620                  "Table": "`user`"
  2621                }
  2622              ]
  2623            }
  2624          ]
  2625        }
  2626      },
  2627      "gen4-plan": {
  2628        "QueryType": "SELECT",
  2629        "Original": "select count(id), num from user order by 2",
  2630        "Instructions": {
  2631          "OperatorType": "Aggregate",
  2632          "Variant": "Scalar",
  2633          "Aggregates": "sum_count(0) AS count(id), random(1) AS num",
  2634          "ResultColumns": 2,
  2635          "Inputs": [
  2636            {
  2637              "OperatorType": "Route",
  2638              "Variant": "Scatter",
  2639              "Keyspace": {
  2640                "Name": "user",
  2641                "Sharded": true
  2642              },
  2643              "FieldQuery": "select count(id), num, weight_string(num) from `user` where 1 != 1",
  2644              "OrderBy": "(1|2) ASC",
  2645              "Query": "select count(id), num, weight_string(num) from `user` order by num asc",
  2646              "Table": "`user`"
  2647            }
  2648          ]
  2649        },
  2650        "TablesUsed": [
  2651          "user.user"
  2652        ]
  2653      }
  2654    },
  2655    {
  2656      "comment": "aggregation and non-aggregations column with group by",
  2657      "query": "select count(id), num from user group by 2",
  2658      "v3-plan": {
  2659        "QueryType": "SELECT",
  2660        "Original": "select count(id), num from user group by 2",
  2661        "Instructions": {
  2662          "OperatorType": "Aggregate",
  2663          "Variant": "Ordered",
  2664          "Aggregates": "sum_count(0) AS count",
  2665          "GroupBy": "1",
  2666          "Inputs": [
  2667            {
  2668              "OperatorType": "Route",
  2669              "Variant": "Scatter",
  2670              "Keyspace": {
  2671                "Name": "user",
  2672                "Sharded": true
  2673              },
  2674              "FieldQuery": "select count(id), num, weight_string(num) from `user` where 1 != 1 group by 2, weight_string(num)",
  2675              "OrderBy": "(1|2) ASC",
  2676              "Query": "select count(id), num, weight_string(num) from `user` group by 2, weight_string(num) order by num asc",
  2677              "ResultColumns": 2,
  2678              "Table": "`user`"
  2679            }
  2680          ]
  2681        }
  2682      },
  2683      "gen4-plan": {
  2684        "QueryType": "SELECT",
  2685        "Original": "select count(id), num from user group by 2",
  2686        "Instructions": {
  2687          "OperatorType": "Aggregate",
  2688          "Variant": "Ordered",
  2689          "Aggregates": "sum_count(0) AS count(id)",
  2690          "GroupBy": "(1|2)",
  2691          "ResultColumns": 2,
  2692          "Inputs": [
  2693            {
  2694              "OperatorType": "Route",
  2695              "Variant": "Scatter",
  2696              "Keyspace": {
  2697                "Name": "user",
  2698                "Sharded": true
  2699              },
  2700              "FieldQuery": "select count(id), num, weight_string(num) from `user` where 1 != 1 group by num, weight_string(num)",
  2701              "OrderBy": "(1|2) ASC",
  2702              "Query": "select count(id), num, weight_string(num) from `user` group by num, weight_string(num) order by num asc",
  2703              "Table": "`user`"
  2704            }
  2705          ]
  2706        },
  2707        "TablesUsed": [
  2708          "user.user"
  2709        ]
  2710      }
  2711    },
  2712    {
  2713      "comment": "aggregation and non-aggregations column with group by and order by",
  2714      "query": "select count(id), num from user group by 2 order by 1",
  2715      "v3-plan": {
  2716        "QueryType": "SELECT",
  2717        "Original": "select count(id), num from user group by 2 order by 1",
  2718        "Instructions": {
  2719          "OperatorType": "Sort",
  2720          "Variant": "Memory",
  2721          "OrderBy": "0 ASC",
  2722          "Inputs": [
  2723            {
  2724              "OperatorType": "Aggregate",
  2725              "Variant": "Ordered",
  2726              "Aggregates": "sum_count(0) AS count",
  2727              "GroupBy": "1",
  2728              "Inputs": [
  2729                {
  2730                  "OperatorType": "Route",
  2731                  "Variant": "Scatter",
  2732                  "Keyspace": {
  2733                    "Name": "user",
  2734                    "Sharded": true
  2735                  },
  2736                  "FieldQuery": "select count(id), num, weight_string(num) from `user` where 1 != 1 group by 2, weight_string(num)",
  2737                  "OrderBy": "(1|2) ASC",
  2738                  "Query": "select count(id), num, weight_string(num) from `user` group by 2, weight_string(num) order by num asc",
  2739                  "ResultColumns": 2,
  2740                  "Table": "`user`"
  2741                }
  2742              ]
  2743            }
  2744          ]
  2745        }
  2746      },
  2747      "gen4-plan": {
  2748        "QueryType": "SELECT",
  2749        "Original": "select count(id), num from user group by 2 order by 1",
  2750        "Instructions": {
  2751          "OperatorType": "Sort",
  2752          "Variant": "Memory",
  2753          "OrderBy": "0 ASC",
  2754          "ResultColumns": 2,
  2755          "Inputs": [
  2756            {
  2757              "OperatorType": "Aggregate",
  2758              "Variant": "Ordered",
  2759              "Aggregates": "sum_count(0) AS count(id)",
  2760              "GroupBy": "(1|2)",
  2761              "Inputs": [
  2762                {
  2763                  "OperatorType": "Route",
  2764                  "Variant": "Scatter",
  2765                  "Keyspace": {
  2766                    "Name": "user",
  2767                    "Sharded": true
  2768                  },
  2769                  "FieldQuery": "select count(id), num, weight_string(num) from `user` where 1 != 1 group by num, weight_string(num)",
  2770                  "OrderBy": "(1|2) ASC",
  2771                  "Query": "select count(id), num, weight_string(num) from `user` group by num, weight_string(num) order by num asc",
  2772                  "Table": "`user`"
  2773                }
  2774              ]
  2775            }
  2776          ]
  2777        },
  2778        "TablesUsed": [
  2779          "user.user"
  2780        ]
  2781      }
  2782    },
  2783    {
  2784      "comment": "join order by with ambiguous column reference ; valid in MySQL",
  2785      "query": "select name, name from user, music order by name",
  2786      "v3-plan": "VT03021: ambiguous symbol reference: `name`",
  2787      "gen4-plan": {
  2788        "QueryType": "SELECT",
  2789        "Original": "select name, name from user, music order by name",
  2790        "Instructions": {
  2791          "OperatorType": "Join",
  2792          "Variant": "Join",
  2793          "JoinColumnIndexes": "L:0,L:0",
  2794          "TableName": "`user`_music",
  2795          "Inputs": [
  2796            {
  2797              "OperatorType": "Route",
  2798              "Variant": "Scatter",
  2799              "Keyspace": {
  2800                "Name": "user",
  2801                "Sharded": true
  2802              },
  2803              "FieldQuery": "select `name`, weight_string(`name`) from `user` where 1 != 1",
  2804              "OrderBy": "(0|1) ASC",
  2805              "Query": "select `name`, weight_string(`name`) from `user` order by `name` asc",
  2806              "Table": "`user`"
  2807            },
  2808            {
  2809              "OperatorType": "Route",
  2810              "Variant": "Scatter",
  2811              "Keyspace": {
  2812                "Name": "user",
  2813                "Sharded": true
  2814              },
  2815              "FieldQuery": "select 1 from music where 1 != 1",
  2816              "Query": "select 1 from music",
  2817              "Table": "music"
  2818            }
  2819          ]
  2820        },
  2821        "TablesUsed": [
  2822          "user.music",
  2823          "user.user"
  2824        ]
  2825      }
  2826    },
  2827    {
  2828      "comment": "order by with ambiguous column reference ; valid in MySQL",
  2829      "query": "select id, id from user order by id",
  2830      "v3-plan": "VT03021: ambiguous symbol reference: id",
  2831      "gen4-plan": {
  2832        "QueryType": "SELECT",
  2833        "Original": "select id, id from user order by id",
  2834        "Instructions": {
  2835          "OperatorType": "Route",
  2836          "Variant": "Scatter",
  2837          "Keyspace": {
  2838            "Name": "user",
  2839            "Sharded": true
  2840          },
  2841          "FieldQuery": "select id, id, weight_string(id) from `user` where 1 != 1",
  2842          "OrderBy": "(0|2) ASC",
  2843          "Query": "select id, id, weight_string(id) from `user` order by id asc",
  2844          "ResultColumns": 2,
  2845          "Table": "`user`"
  2846        },
  2847        "TablesUsed": [
  2848          "user.user"
  2849        ]
  2850      }
  2851    },
  2852    {
  2853      "comment": "Scatter order by and aggregation: order by column must reference column from select list",
  2854      "query": "select col, count(*) from user group by col order by c1",
  2855      "v3-plan": "VT12001: unsupported: memory sort: ORDER BY must reference a column in the SELECT list: c1 asc",
  2856      "gen4-plan": {
  2857        "QueryType": "SELECT",
  2858        "Original": "select col, count(*) from user group by col order by c1",
  2859        "Instructions": {
  2860          "OperatorType": "Aggregate",
  2861          "Variant": "Ordered",
  2862          "Aggregates": "sum_count_star(1) AS count(*), random(2) AS c1",
  2863          "GroupBy": "0",
  2864          "ResultColumns": 2,
  2865          "Inputs": [
  2866            {
  2867              "OperatorType": "Route",
  2868              "Variant": "Scatter",
  2869              "Keyspace": {
  2870                "Name": "user",
  2871                "Sharded": true
  2872              },
  2873              "FieldQuery": "select col, count(*), c1, weight_string(c1) from `user` where 1 != 1 group by col",
  2874              "OrderBy": "(2|3) ASC, 0 ASC",
  2875              "Query": "select col, count(*), c1, weight_string(c1) from `user` group by col order by c1 asc, col asc",
  2876              "Table": "`user`"
  2877            }
  2878          ]
  2879        },
  2880        "TablesUsed": [
  2881          "user.user"
  2882        ]
  2883      }
  2884    },
  2885    {
  2886      "comment": "Distinct with cross shard query",
  2887      "query": "select distinct user.a from user join user_extra",
  2888      "v3-plan": {
  2889        "QueryType": "SELECT",
  2890        "Original": "select distinct user.a from user join user_extra",
  2891        "Instructions": {
  2892          "OperatorType": "Distinct",
  2893          "Inputs": [
  2894            {
  2895              "OperatorType": "Join",
  2896              "Variant": "Join",
  2897              "JoinColumnIndexes": "L:0",
  2898              "TableName": "`user`_user_extra",
  2899              "Inputs": [
  2900                {
  2901                  "OperatorType": "Route",
  2902                  "Variant": "Scatter",
  2903                  "Keyspace": {
  2904                    "Name": "user",
  2905                    "Sharded": true
  2906                  },
  2907                  "FieldQuery": "select `user`.a from `user` where 1 != 1",
  2908                  "Query": "select `user`.a from `user`",
  2909                  "Table": "`user`"
  2910                },
  2911                {
  2912                  "OperatorType": "Route",
  2913                  "Variant": "Scatter",
  2914                  "Keyspace": {
  2915                    "Name": "user",
  2916                    "Sharded": true
  2917                  },
  2918                  "FieldQuery": "select 1 from user_extra where 1 != 1",
  2919                  "Query": "select 1 from user_extra",
  2920                  "Table": "user_extra"
  2921                }
  2922              ]
  2923            }
  2924          ]
  2925        }
  2926      },
  2927      "gen4-plan": {
  2928        "QueryType": "SELECT",
  2929        "Original": "select distinct user.a from user join user_extra",
  2930        "Instructions": {
  2931          "OperatorType": "Aggregate",
  2932          "Variant": "Ordered",
  2933          "GroupBy": "(0|1)",
  2934          "ResultColumns": 1,
  2935          "Inputs": [
  2936            {
  2937              "OperatorType": "Join",
  2938              "Variant": "Join",
  2939              "JoinColumnIndexes": "L:0,L:1",
  2940              "TableName": "`user`_user_extra",
  2941              "Inputs": [
  2942                {
  2943                  "OperatorType": "Route",
  2944                  "Variant": "Scatter",
  2945                  "Keyspace": {
  2946                    "Name": "user",
  2947                    "Sharded": true
  2948                  },
  2949                  "FieldQuery": "select `user`.a, weight_string(`user`.a) from `user` where 1 != 1",
  2950                  "OrderBy": "(0|1) ASC",
  2951                  "Query": "select `user`.a, weight_string(`user`.a) from `user` order by `user`.a asc",
  2952                  "Table": "`user`"
  2953                },
  2954                {
  2955                  "OperatorType": "Route",
  2956                  "Variant": "Scatter",
  2957                  "Keyspace": {
  2958                    "Name": "user",
  2959                    "Sharded": true
  2960                  },
  2961                  "FieldQuery": "select 1 from user_extra where 1 != 1",
  2962                  "Query": "select 1 from user_extra",
  2963                  "Table": "user_extra"
  2964                }
  2965              ]
  2966            }
  2967          ]
  2968        },
  2969        "TablesUsed": [
  2970          "user.user",
  2971          "user.user_extra"
  2972        ]
  2973      }
  2974    },
  2975    {
  2976      "comment": "Distinct with column alias",
  2977      "query": "select distinct a as c, a from user",
  2978      "v3-plan": {
  2979        "QueryType": "SELECT",
  2980        "Original": "select distinct a as c, a from user",
  2981        "Instructions": {
  2982          "OperatorType": "Aggregate",
  2983          "Variant": "Ordered",
  2984          "GroupBy": "0, 1",
  2985          "Inputs": [
  2986            {
  2987              "OperatorType": "Route",
  2988              "Variant": "Scatter",
  2989              "Keyspace": {
  2990                "Name": "user",
  2991                "Sharded": true
  2992              },
  2993              "FieldQuery": "select a as c, a, weight_string(a) from `user` where 1 != 1",
  2994              "OrderBy": "(0|2) ASC, (0|2) ASC",
  2995              "Query": "select distinct a as c, a, weight_string(a) from `user` order by c asc, a asc",
  2996              "ResultColumns": 2,
  2997              "Table": "`user`"
  2998            }
  2999          ]
  3000        }
  3001      },
  3002      "gen4-plan": {
  3003        "QueryType": "SELECT",
  3004        "Original": "select distinct a as c, a from user",
  3005        "Instructions": {
  3006          "OperatorType": "Aggregate",
  3007          "Variant": "Ordered",
  3008          "GroupBy": "(0|2), (1|2)",
  3009          "ResultColumns": 2,
  3010          "Inputs": [
  3011            {
  3012              "OperatorType": "Route",
  3013              "Variant": "Scatter",
  3014              "Keyspace": {
  3015                "Name": "user",
  3016                "Sharded": true
  3017              },
  3018              "FieldQuery": "select a as c, a, weight_string(a) from `user` where 1 != 1",
  3019              "OrderBy": "(0|2) ASC, (0|2) ASC",
  3020              "Query": "select distinct a as c, a, weight_string(a) from `user` order by c asc, a asc",
  3021              "Table": "`user`"
  3022            }
  3023          ]
  3024        },
  3025        "TablesUsed": [
  3026          "user.user"
  3027        ]
  3028      }
  3029    },
  3030    {
  3031      "comment": "Distinct with same column",
  3032      "query": "select distinct a, a from user",
  3033      "v3-plan": "generating ORDER BY clause: VT03021: ambiguous symbol reference: a",
  3034      "gen4-plan": {
  3035        "QueryType": "SELECT",
  3036        "Original": "select distinct a, a from user",
  3037        "Instructions": {
  3038          "OperatorType": "Aggregate",
  3039          "Variant": "Ordered",
  3040          "GroupBy": "(0|2), (1|2)",
  3041          "ResultColumns": 2,
  3042          "Inputs": [
  3043            {
  3044              "OperatorType": "Route",
  3045              "Variant": "Scatter",
  3046              "Keyspace": {
  3047                "Name": "user",
  3048                "Sharded": true
  3049              },
  3050              "FieldQuery": "select a, a, weight_string(a) from `user` where 1 != 1",
  3051              "OrderBy": "(0|2) ASC, (0|2) ASC",
  3052              "Query": "select distinct a, a, weight_string(a) from `user` order by a asc, a asc",
  3053              "Table": "`user`"
  3054            }
  3055          ]
  3056        },
  3057        "TablesUsed": [
  3058          "user.user"
  3059        ]
  3060      }
  3061    },
  3062    {
  3063      "comment": "Order by has subqueries",
  3064      "query": "select id from unsharded order by (select id from unsharded)",
  3065      "v3-plan": "VT12001: unsupported: subqueries disallowed in sqlparser.OrderBy",
  3066      "gen4-plan": {
  3067        "QueryType": "SELECT",
  3068        "Original": "select id from unsharded order by (select id from unsharded)",
  3069        "Instructions": {
  3070          "OperatorType": "Route",
  3071          "Variant": "Unsharded",
  3072          "Keyspace": {
  3073            "Name": "main",
  3074            "Sharded": false
  3075          },
  3076          "FieldQuery": "select id from unsharded where 1 != 1",
  3077          "Query": "select id from unsharded order by (select id from unsharded) asc",
  3078          "Table": "unsharded"
  3079        },
  3080        "TablesUsed": [
  3081          "main.unsharded"
  3082        ]
  3083      }
  3084    },
  3085    {
  3086      "comment": "Equal filter with hexadecimal value",
  3087      "query": "select count(*) a from user having a = 0x01",
  3088      "v3-plan": "VT12001: unsupported: filtering on results of aggregates",
  3089      "gen4-plan": {
  3090        "QueryType": "SELECT",
  3091        "Original": "select count(*) a from user having a = 0x01",
  3092        "Instructions": {
  3093          "OperatorType": "Filter",
  3094          "Predicate": ":0 = 0x01",
  3095          "Inputs": [
  3096            {
  3097              "OperatorType": "Aggregate",
  3098              "Variant": "Scalar",
  3099              "Aggregates": "sum_count_star(0) AS a",
  3100              "Inputs": [
  3101                {
  3102                  "OperatorType": "Route",
  3103                  "Variant": "Scatter",
  3104                  "Keyspace": {
  3105                    "Name": "user",
  3106                    "Sharded": true
  3107                  },
  3108                  "FieldQuery": "select count(*) as a from `user` where 1 != 1",
  3109                  "Query": "select count(*) as a from `user`",
  3110                  "Table": "`user`"
  3111                }
  3112              ]
  3113            }
  3114          ]
  3115        },
  3116        "TablesUsed": [
  3117          "user.user"
  3118        ]
  3119      }
  3120    }
  3121  ]