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

     1  [
     2    {
     3      "comment": "union all between two scatter selects",
     4      "query": "select id from user union all select id from music",
     5      "v3-plan": {
     6        "QueryType": "SELECT",
     7        "Original": "select id from user union all select id from music",
     8        "Instructions": {
     9          "OperatorType": "Route",
    10          "Variant": "Scatter",
    11          "Keyspace": {
    12            "Name": "user",
    13            "Sharded": true
    14          },
    15          "FieldQuery": "select id from `user` where 1 != 1 union all select id from music where 1 != 1",
    16          "Query": "select id from `user` union all select id from music",
    17          "Table": "`user`"
    18        }
    19      },
    20      "gen4-plan": {
    21        "QueryType": "SELECT",
    22        "Original": "select id from user union all select id from music",
    23        "Instructions": {
    24          "OperatorType": "Route",
    25          "Variant": "Scatter",
    26          "Keyspace": {
    27            "Name": "user",
    28            "Sharded": true
    29          },
    30          "FieldQuery": "select id from `user` where 1 != 1 union all select id from music where 1 != 1",
    31          "Query": "select id from `user` union all select id from music",
    32          "Table": "`user`"
    33        },
    34        "TablesUsed": [
    35          "user.music",
    36          "user.user"
    37        ]
    38      }
    39    },
    40    {
    41      "comment": "union distinct between two scatter selects",
    42      "query": "select id from user union select id from music",
    43      "v3-plan": {
    44        "QueryType": "SELECT",
    45        "Original": "select id from user union select id from music",
    46        "Instructions": {
    47          "OperatorType": "Distinct",
    48          "Inputs": [
    49            {
    50              "OperatorType": "Concatenate",
    51              "Inputs": [
    52                {
    53                  "OperatorType": "Route",
    54                  "Variant": "Scatter",
    55                  "Keyspace": {
    56                    "Name": "user",
    57                    "Sharded": true
    58                  },
    59                  "FieldQuery": "select id from `user` where 1 != 1",
    60                  "Query": "select id from `user`",
    61                  "Table": "`user`"
    62                },
    63                {
    64                  "OperatorType": "Route",
    65                  "Variant": "Scatter",
    66                  "Keyspace": {
    67                    "Name": "user",
    68                    "Sharded": true
    69                  },
    70                  "FieldQuery": "select id from music where 1 != 1",
    71                  "Query": "select id from music",
    72                  "Table": "music"
    73                }
    74              ]
    75            }
    76          ]
    77        }
    78      },
    79      "gen4-plan": {
    80        "QueryType": "SELECT",
    81        "Original": "select id from user union select id from music",
    82        "Instructions": {
    83          "OperatorType": "Distinct",
    84          "Collations": [
    85            "(0:1)"
    86          ],
    87          "ResultColumns": 1,
    88          "Inputs": [
    89            {
    90              "OperatorType": "Route",
    91              "Variant": "Scatter",
    92              "Keyspace": {
    93                "Name": "user",
    94                "Sharded": true
    95              },
    96              "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1 union select id, weight_string(id) from music where 1 != 1",
    97              "Query": "select id, weight_string(id) from `user` union select id, weight_string(id) from music",
    98              "Table": "`user`"
    99            }
   100          ]
   101        },
   102        "TablesUsed": [
   103          "user.music",
   104          "user.user"
   105        ]
   106      }
   107    },
   108    {
   109      "comment": "union all between two SelectEqualUnique",
   110      "query": "select id from user where id = 1 union all select id from user where id = 5",
   111      "v3-plan": {
   112        "QueryType": "SELECT",
   113        "Original": "select id from user where id = 1 union all select id from user where id = 5",
   114        "Instructions": {
   115          "OperatorType": "Concatenate",
   116          "Inputs": [
   117            {
   118              "OperatorType": "Route",
   119              "Variant": "EqualUnique",
   120              "Keyspace": {
   121                "Name": "user",
   122                "Sharded": true
   123              },
   124              "FieldQuery": "select id from `user` where 1 != 1",
   125              "Query": "select id from `user` where id = 1",
   126              "Table": "`user`",
   127              "Values": [
   128                "INT64(1)"
   129              ],
   130              "Vindex": "user_index"
   131            },
   132            {
   133              "OperatorType": "Route",
   134              "Variant": "EqualUnique",
   135              "Keyspace": {
   136                "Name": "user",
   137                "Sharded": true
   138              },
   139              "FieldQuery": "select id from `user` where 1 != 1",
   140              "Query": "select id from `user` where id = 5",
   141              "Table": "`user`",
   142              "Values": [
   143                "INT64(5)"
   144              ],
   145              "Vindex": "user_index"
   146            }
   147          ]
   148        }
   149      },
   150      "gen4-plan": {
   151        "QueryType": "SELECT",
   152        "Original": "select id from user where id = 1 union all select id from user where id = 5",
   153        "Instructions": {
   154          "OperatorType": "Concatenate",
   155          "Inputs": [
   156            {
   157              "OperatorType": "Route",
   158              "Variant": "EqualUnique",
   159              "Keyspace": {
   160                "Name": "user",
   161                "Sharded": true
   162              },
   163              "FieldQuery": "select id from `user` where 1 != 1",
   164              "Query": "select id from `user` where id = 1",
   165              "Table": "`user`",
   166              "Values": [
   167                "INT64(1)"
   168              ],
   169              "Vindex": "user_index"
   170            },
   171            {
   172              "OperatorType": "Route",
   173              "Variant": "EqualUnique",
   174              "Keyspace": {
   175                "Name": "user",
   176                "Sharded": true
   177              },
   178              "FieldQuery": "select id from `user` where 1 != 1",
   179              "Query": "select id from `user` where id = 5",
   180              "Table": "`user`",
   181              "Values": [
   182                "INT64(5)"
   183              ],
   184              "Vindex": "user_index"
   185            }
   186          ]
   187        },
   188        "TablesUsed": [
   189          "user.user"
   190        ]
   191      }
   192    },
   193    {
   194      "comment": "almost dereks query - two queries with order by and limit being scattered to two different sets of tablets",
   195      "query": "(SELECT id FROM user ORDER BY id DESC LIMIT 1) UNION ALL (SELECT id FROM music ORDER BY id DESC LIMIT 1)",
   196      "v3-plan": {
   197        "QueryType": "SELECT",
   198        "Original": "(SELECT id FROM user ORDER BY id DESC LIMIT 1) UNION ALL (SELECT id FROM music ORDER BY id DESC LIMIT 1)",
   199        "Instructions": {
   200          "OperatorType": "Concatenate",
   201          "Inputs": [
   202            {
   203              "OperatorType": "Limit",
   204              "Count": "INT64(1)",
   205              "Inputs": [
   206                {
   207                  "OperatorType": "Route",
   208                  "Variant": "Scatter",
   209                  "Keyspace": {
   210                    "Name": "user",
   211                    "Sharded": true
   212                  },
   213                  "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1",
   214                  "OrderBy": "(0|1) DESC",
   215                  "Query": "select id, weight_string(id) from `user` order by id desc limit :__upper_limit",
   216                  "ResultColumns": 1,
   217                  "Table": "`user`"
   218                }
   219              ]
   220            },
   221            {
   222              "OperatorType": "Limit",
   223              "Count": "INT64(1)",
   224              "Inputs": [
   225                {
   226                  "OperatorType": "Route",
   227                  "Variant": "Scatter",
   228                  "Keyspace": {
   229                    "Name": "user",
   230                    "Sharded": true
   231                  },
   232                  "FieldQuery": "select id, weight_string(id) from music where 1 != 1",
   233                  "OrderBy": "(0|1) DESC",
   234                  "Query": "select id, weight_string(id) from music order by id desc limit :__upper_limit",
   235                  "ResultColumns": 1,
   236                  "Table": "music"
   237                }
   238              ]
   239            }
   240          ]
   241        }
   242      },
   243      "gen4-plan": {
   244        "QueryType": "SELECT",
   245        "Original": "(SELECT id FROM user ORDER BY id DESC LIMIT 1) UNION ALL (SELECT id FROM music ORDER BY id DESC LIMIT 1)",
   246        "Instructions": {
   247          "OperatorType": "Concatenate",
   248          "Inputs": [
   249            {
   250              "OperatorType": "Limit",
   251              "Count": "INT64(1)",
   252              "Inputs": [
   253                {
   254                  "OperatorType": "Route",
   255                  "Variant": "Scatter",
   256                  "Keyspace": {
   257                    "Name": "user",
   258                    "Sharded": true
   259                  },
   260                  "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1",
   261                  "OrderBy": "(0|1) DESC",
   262                  "Query": "select id, weight_string(id) from `user` order by id desc limit :__upper_limit",
   263                  "ResultColumns": 1,
   264                  "Table": "`user`"
   265                }
   266              ]
   267            },
   268            {
   269              "OperatorType": "Limit",
   270              "Count": "INT64(1)",
   271              "Inputs": [
   272                {
   273                  "OperatorType": "Route",
   274                  "Variant": "Scatter",
   275                  "Keyspace": {
   276                    "Name": "user",
   277                    "Sharded": true
   278                  },
   279                  "FieldQuery": "select id, weight_string(id) from music where 1 != 1",
   280                  "OrderBy": "(0|1) DESC",
   281                  "Query": "select id, weight_string(id) from music order by id desc limit :__upper_limit",
   282                  "ResultColumns": 1,
   283                  "Table": "music"
   284                }
   285              ]
   286            }
   287          ]
   288        },
   289        "TablesUsed": [
   290          "user.music",
   291          "user.user"
   292        ]
   293      }
   294    },
   295    {
   296      "comment": "Union all",
   297      "query": "select col1, col2 from user union all select col1, col2 from user_extra",
   298      "v3-plan": {
   299        "QueryType": "SELECT",
   300        "Original": "select col1, col2 from user union all select col1, col2 from user_extra",
   301        "Instructions": {
   302          "OperatorType": "Route",
   303          "Variant": "Scatter",
   304          "Keyspace": {
   305            "Name": "user",
   306            "Sharded": true
   307          },
   308          "FieldQuery": "select col1, col2 from `user` where 1 != 1 union all select col1, col2 from user_extra where 1 != 1",
   309          "Query": "select col1, col2 from `user` union all select col1, col2 from user_extra",
   310          "Table": "`user`"
   311        }
   312      },
   313      "gen4-plan": {
   314        "QueryType": "SELECT",
   315        "Original": "select col1, col2 from user union all select col1, col2 from user_extra",
   316        "Instructions": {
   317          "OperatorType": "Route",
   318          "Variant": "Scatter",
   319          "Keyspace": {
   320            "Name": "user",
   321            "Sharded": true
   322          },
   323          "FieldQuery": "select col1, col2 from `user` where 1 != 1 union all select col1, col2 from user_extra where 1 != 1",
   324          "Query": "select col1, col2 from `user` union all select col1, col2 from user_extra",
   325          "Table": "`user`"
   326        },
   327        "TablesUsed": [
   328          "user.user",
   329          "user.user_extra"
   330        ]
   331      }
   332    },
   333    {
   334      "comment": "union operations in subqueries (FROM)",
   335      "query": "select * from (select * from user union all select * from user_extra) as t",
   336      "v3-plan": {
   337        "QueryType": "SELECT",
   338        "Original": "select * from (select * from user union all select * from user_extra) as t",
   339        "Instructions": {
   340          "OperatorType": "Route",
   341          "Variant": "Scatter",
   342          "Keyspace": {
   343            "Name": "user",
   344            "Sharded": true
   345          },
   346          "FieldQuery": "select * from (select * from `user` where 1 != 1 union all select * from user_extra where 1 != 1) as t where 1 != 1",
   347          "Query": "select * from (select * from `user` union all select * from user_extra) as t",
   348          "Table": "`user`"
   349        }
   350      },
   351      "gen4-plan": {
   352        "QueryType": "SELECT",
   353        "Original": "select * from (select * from user union all select * from user_extra) as t",
   354        "Instructions": {
   355          "OperatorType": "Route",
   356          "Variant": "Scatter",
   357          "Keyspace": {
   358            "Name": "user",
   359            "Sharded": true
   360          },
   361          "FieldQuery": "select * from (select * from `user` where 1 != 1 union all select * from user_extra where 1 != 1) as t where 1 != 1",
   362          "Query": "select * from (select * from `user` union all select * from user_extra) as t",
   363          "Table": "`user`"
   364        },
   365        "TablesUsed": [
   366          "user.user",
   367          "user.user_extra"
   368        ]
   369      }
   370    },
   371    {
   372      "comment": "union operations in derived table, without star expression (FROM)ยก",
   373      "query": "select col1,col2 from (select col1, col2 from user union all select col1, col2 from user_extra) as t",
   374      "v3-plan": {
   375        "QueryType": "SELECT",
   376        "Original": "select col1,col2 from (select col1, col2 from user union all select col1, col2 from user_extra) as t",
   377        "Instructions": {
   378          "OperatorType": "Route",
   379          "Variant": "Scatter",
   380          "Keyspace": {
   381            "Name": "user",
   382            "Sharded": true
   383          },
   384          "FieldQuery": "select col1, col2 from (select col1, col2 from `user` where 1 != 1 union all select col1, col2 from user_extra where 1 != 1) as t where 1 != 1",
   385          "Query": "select col1, col2 from (select col1, col2 from `user` union all select col1, col2 from user_extra) as t",
   386          "Table": "`user`"
   387        }
   388      },
   389      "gen4-plan": {
   390        "QueryType": "SELECT",
   391        "Original": "select col1,col2 from (select col1, col2 from user union all select col1, col2 from user_extra) as t",
   392        "Instructions": {
   393          "OperatorType": "Route",
   394          "Variant": "Scatter",
   395          "Keyspace": {
   396            "Name": "user",
   397            "Sharded": true
   398          },
   399          "FieldQuery": "select col1, col2 from (select col1, col2 from `user` where 1 != 1 union all select col1, col2 from user_extra where 1 != 1) as t where 1 != 1",
   400          "Query": "select col1, col2 from (select col1, col2 from `user` union all select col1, col2 from user_extra) as t",
   401          "Table": "`user`"
   402        },
   403        "TablesUsed": [
   404          "user.user",
   405          "user.user_extra"
   406        ]
   407      }
   408    },
   409    {
   410      "comment": "union all between two scatter selects, with order by",
   411      "query": "(select id from user order by id limit 5) union all (select id from music order by id desc limit 5)",
   412      "v3-plan": {
   413        "QueryType": "SELECT",
   414        "Original": "(select id from user order by id limit 5) union all (select id from music order by id desc limit 5)",
   415        "Instructions": {
   416          "OperatorType": "Concatenate",
   417          "Inputs": [
   418            {
   419              "OperatorType": "Limit",
   420              "Count": "INT64(5)",
   421              "Inputs": [
   422                {
   423                  "OperatorType": "Route",
   424                  "Variant": "Scatter",
   425                  "Keyspace": {
   426                    "Name": "user",
   427                    "Sharded": true
   428                  },
   429                  "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1",
   430                  "OrderBy": "(0|1) ASC",
   431                  "Query": "select id, weight_string(id) from `user` order by id asc limit :__upper_limit",
   432                  "ResultColumns": 1,
   433                  "Table": "`user`"
   434                }
   435              ]
   436            },
   437            {
   438              "OperatorType": "Limit",
   439              "Count": "INT64(5)",
   440              "Inputs": [
   441                {
   442                  "OperatorType": "Route",
   443                  "Variant": "Scatter",
   444                  "Keyspace": {
   445                    "Name": "user",
   446                    "Sharded": true
   447                  },
   448                  "FieldQuery": "select id, weight_string(id) from music where 1 != 1",
   449                  "OrderBy": "(0|1) DESC",
   450                  "Query": "select id, weight_string(id) from music order by id desc limit :__upper_limit",
   451                  "ResultColumns": 1,
   452                  "Table": "music"
   453                }
   454              ]
   455            }
   456          ]
   457        }
   458      },
   459      "gen4-plan": {
   460        "QueryType": "SELECT",
   461        "Original": "(select id from user order by id limit 5) union all (select id from music order by id desc limit 5)",
   462        "Instructions": {
   463          "OperatorType": "Concatenate",
   464          "Inputs": [
   465            {
   466              "OperatorType": "Limit",
   467              "Count": "INT64(5)",
   468              "Inputs": [
   469                {
   470                  "OperatorType": "Route",
   471                  "Variant": "Scatter",
   472                  "Keyspace": {
   473                    "Name": "user",
   474                    "Sharded": true
   475                  },
   476                  "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1",
   477                  "OrderBy": "(0|1) ASC",
   478                  "Query": "select id, weight_string(id) from `user` order by id asc limit :__upper_limit",
   479                  "ResultColumns": 1,
   480                  "Table": "`user`"
   481                }
   482              ]
   483            },
   484            {
   485              "OperatorType": "Limit",
   486              "Count": "INT64(5)",
   487              "Inputs": [
   488                {
   489                  "OperatorType": "Route",
   490                  "Variant": "Scatter",
   491                  "Keyspace": {
   492                    "Name": "user",
   493                    "Sharded": true
   494                  },
   495                  "FieldQuery": "select id, weight_string(id) from music where 1 != 1",
   496                  "OrderBy": "(0|1) DESC",
   497                  "Query": "select id, weight_string(id) from music order by id desc limit :__upper_limit",
   498                  "ResultColumns": 1,
   499                  "Table": "music"
   500                }
   501              ]
   502            }
   503          ]
   504        },
   505        "TablesUsed": [
   506          "user.music",
   507          "user.user"
   508        ]
   509      }
   510    },
   511    {
   512      "comment": "union all on scatter and single route",
   513      "query": "select id from user where id = 1 union select id from user where id = 1  union all select id from user",
   514      "v3-plan": {
   515        "QueryType": "SELECT",
   516        "Original": "select id from user where id = 1 union select id from user where id = 1  union all select id from user",
   517        "Instructions": {
   518          "OperatorType": "Concatenate",
   519          "Inputs": [
   520            {
   521              "OperatorType": "Route",
   522              "Variant": "EqualUnique",
   523              "Keyspace": {
   524                "Name": "user",
   525                "Sharded": true
   526              },
   527              "FieldQuery": "select id from `user` where 1 != 1 union select id from `user` where 1 != 1",
   528              "Query": "select id from `user` where id = 1 union select id from `user` where id = 1",
   529              "Table": "`user`",
   530              "Values": [
   531                "INT64(1)"
   532              ],
   533              "Vindex": "user_index"
   534            },
   535            {
   536              "OperatorType": "Route",
   537              "Variant": "Scatter",
   538              "Keyspace": {
   539                "Name": "user",
   540                "Sharded": true
   541              },
   542              "FieldQuery": "select id from `user` where 1 != 1",
   543              "Query": "select id from `user`",
   544              "Table": "`user`"
   545            }
   546          ]
   547        }
   548      },
   549      "gen4-plan": {
   550        "QueryType": "SELECT",
   551        "Original": "select id from user where id = 1 union select id from user where id = 1  union all select id from user",
   552        "Instructions": {
   553          "OperatorType": "Concatenate",
   554          "Inputs": [
   555            {
   556              "OperatorType": "Route",
   557              "Variant": "EqualUnique",
   558              "Keyspace": {
   559                "Name": "user",
   560                "Sharded": true
   561              },
   562              "FieldQuery": "select id from `user` where 1 != 1 union select id from `user` where 1 != 1",
   563              "Query": "select id from `user` where id = 1 union select id from `user` where id = 1",
   564              "Table": "`user`",
   565              "Values": [
   566                "INT64(1)"
   567              ],
   568              "Vindex": "user_index"
   569            },
   570            {
   571              "OperatorType": "Route",
   572              "Variant": "Scatter",
   573              "Keyspace": {
   574                "Name": "user",
   575                "Sharded": true
   576              },
   577              "FieldQuery": "select id from `user` where 1 != 1",
   578              "Query": "select id from `user`",
   579              "Table": "`user`"
   580            }
   581          ]
   582        },
   583        "TablesUsed": [
   584          "user.user"
   585        ]
   586      }
   587    },
   588    {
   589      "comment": "union of information_schema with normal table",
   590      "query": "select CHARACTER_SET_NAME from information_schema.CHARACTER_SETS union select user_name from unsharded",
   591      "v3-plan": {
   592        "QueryType": "SELECT",
   593        "Original": "select CHARACTER_SET_NAME from information_schema.CHARACTER_SETS union select user_name from unsharded",
   594        "Instructions": {
   595          "OperatorType": "Distinct",
   596          "Inputs": [
   597            {
   598              "OperatorType": "Concatenate",
   599              "Inputs": [
   600                {
   601                  "OperatorType": "Route",
   602                  "Variant": "DBA",
   603                  "Keyspace": {
   604                    "Name": "main",
   605                    "Sharded": false
   606                  },
   607                  "FieldQuery": "select CHARACTER_SET_NAME from information_schema.CHARACTER_SETS where 1 != 1",
   608                  "Query": "select CHARACTER_SET_NAME from information_schema.CHARACTER_SETS",
   609                  "Table": "information_schema.CHARACTER_SETS"
   610                },
   611                {
   612                  "OperatorType": "Route",
   613                  "Variant": "Unsharded",
   614                  "Keyspace": {
   615                    "Name": "main",
   616                    "Sharded": false
   617                  },
   618                  "FieldQuery": "select user_name from unsharded where 1 != 1",
   619                  "Query": "select user_name from unsharded",
   620                  "Table": "unsharded"
   621                }
   622              ]
   623            }
   624          ]
   625        }
   626      },
   627      "gen4-plan": {
   628        "QueryType": "SELECT",
   629        "Original": "select CHARACTER_SET_NAME from information_schema.CHARACTER_SETS union select user_name from unsharded",
   630        "Instructions": {
   631          "OperatorType": "Distinct",
   632          "Collations": [
   633            "(0:1)"
   634          ],
   635          "ResultColumns": 1,
   636          "Inputs": [
   637            {
   638              "OperatorType": "Concatenate",
   639              "Inputs": [
   640                {
   641                  "OperatorType": "Route",
   642                  "Variant": "DBA",
   643                  "Keyspace": {
   644                    "Name": "main",
   645                    "Sharded": false
   646                  },
   647                  "FieldQuery": "select CHARACTER_SET_NAME, weight_string(CHARACTER_SET_NAME) from information_schema.CHARACTER_SETS where 1 != 1",
   648                  "Query": "select distinct CHARACTER_SET_NAME, weight_string(CHARACTER_SET_NAME) from information_schema.CHARACTER_SETS",
   649                  "Table": "information_schema.CHARACTER_SETS"
   650                },
   651                {
   652                  "OperatorType": "Route",
   653                  "Variant": "Unsharded",
   654                  "Keyspace": {
   655                    "Name": "main",
   656                    "Sharded": false
   657                  },
   658                  "FieldQuery": "select user_name, weight_string(user_name) from unsharded where 1 != 1",
   659                  "Query": "select distinct user_name, weight_string(user_name) from unsharded",
   660                  "Table": "unsharded"
   661                }
   662              ]
   663            }
   664          ]
   665        },
   666        "TablesUsed": [
   667          "main.unsharded"
   668        ]
   669      }
   670    },
   671    {
   672      "comment": "union of information_schema with normal table",
   673      "query": "select * from unsharded union select * from information_schema.CHARACTER_SETS",
   674      "v3-plan": {
   675        "QueryType": "SELECT",
   676        "Original": "select * from unsharded union select * from information_schema.CHARACTER_SETS",
   677        "Instructions": {
   678          "OperatorType": "Distinct",
   679          "Inputs": [
   680            {
   681              "OperatorType": "Concatenate",
   682              "Inputs": [
   683                {
   684                  "OperatorType": "Route",
   685                  "Variant": "Unsharded",
   686                  "Keyspace": {
   687                    "Name": "main",
   688                    "Sharded": false
   689                  },
   690                  "FieldQuery": "select * from unsharded where 1 != 1",
   691                  "Query": "select * from unsharded",
   692                  "Table": "unsharded"
   693                },
   694                {
   695                  "OperatorType": "Route",
   696                  "Variant": "DBA",
   697                  "Keyspace": {
   698                    "Name": "main",
   699                    "Sharded": false
   700                  },
   701                  "FieldQuery": "select * from information_schema.CHARACTER_SETS where 1 != 1",
   702                  "Query": "select * from information_schema.CHARACTER_SETS",
   703                  "Table": "information_schema.CHARACTER_SETS"
   704                }
   705              ]
   706            }
   707          ]
   708        }
   709      },
   710      "gen4-plan": {
   711        "QueryType": "SELECT",
   712        "Original": "select * from unsharded union select * from information_schema.CHARACTER_SETS",
   713        "Instructions": {
   714          "OperatorType": "Distinct",
   715          "Inputs": [
   716            {
   717              "OperatorType": "Concatenate",
   718              "Inputs": [
   719                {
   720                  "OperatorType": "Route",
   721                  "Variant": "Unsharded",
   722                  "Keyspace": {
   723                    "Name": "main",
   724                    "Sharded": false
   725                  },
   726                  "FieldQuery": "select * from unsharded where 1 != 1",
   727                  "Query": "select distinct * from unsharded",
   728                  "Table": "unsharded"
   729                },
   730                {
   731                  "OperatorType": "Route",
   732                  "Variant": "DBA",
   733                  "Keyspace": {
   734                    "Name": "main",
   735                    "Sharded": false
   736                  },
   737                  "FieldQuery": "select CHARACTER_SET_NAME, DEFAULT_COLLATE_NAME, DESCRIPTION, MAXLEN from information_schema.CHARACTER_SETS where 1 != 1",
   738                  "Query": "select distinct CHARACTER_SET_NAME, DEFAULT_COLLATE_NAME, DESCRIPTION, MAXLEN from information_schema.CHARACTER_SETS",
   739                  "Table": "information_schema.CHARACTER_SETS"
   740                }
   741              ]
   742            }
   743          ]
   744        },
   745        "TablesUsed": [
   746          "main.unsharded"
   747        ]
   748      }
   749    },
   750    {
   751      "comment": "multi-shard union",
   752      "query": "(select id from user union select id from music) union select 1 from dual",
   753      "v3-plan": {
   754        "QueryType": "SELECT",
   755        "Original": "(select id from user union select id from music) union select 1 from dual",
   756        "Instructions": {
   757          "OperatorType": "Distinct",
   758          "Inputs": [
   759            {
   760              "OperatorType": "Concatenate",
   761              "Inputs": [
   762                {
   763                  "OperatorType": "Distinct",
   764                  "Inputs": [
   765                    {
   766                      "OperatorType": "Concatenate",
   767                      "Inputs": [
   768                        {
   769                          "OperatorType": "Route",
   770                          "Variant": "Scatter",
   771                          "Keyspace": {
   772                            "Name": "user",
   773                            "Sharded": true
   774                          },
   775                          "FieldQuery": "select id from `user` where 1 != 1",
   776                          "Query": "select id from `user`",
   777                          "Table": "`user`"
   778                        },
   779                        {
   780                          "OperatorType": "Route",
   781                          "Variant": "Scatter",
   782                          "Keyspace": {
   783                            "Name": "user",
   784                            "Sharded": true
   785                          },
   786                          "FieldQuery": "select id from music where 1 != 1",
   787                          "Query": "select id from music",
   788                          "Table": "music"
   789                        }
   790                      ]
   791                    }
   792                  ]
   793                },
   794                {
   795                  "OperatorType": "Route",
   796                  "Variant": "Reference",
   797                  "Keyspace": {
   798                    "Name": "main",
   799                    "Sharded": false
   800                  },
   801                  "FieldQuery": "select 1 from dual where 1 != 1",
   802                  "Query": "select 1 from dual",
   803                  "Table": "dual"
   804                }
   805              ]
   806            }
   807          ]
   808        }
   809      },
   810      "gen4-plan": {
   811        "QueryType": "SELECT",
   812        "Original": "(select id from user union select id from music) union select 1 from dual",
   813        "Instructions": {
   814          "OperatorType": "Distinct",
   815          "Collations": [
   816            "(0:1)"
   817          ],
   818          "ResultColumns": 1,
   819          "Inputs": [
   820            {
   821              "OperatorType": "Concatenate",
   822              "Inputs": [
   823                {
   824                  "OperatorType": "Route",
   825                  "Variant": "Scatter",
   826                  "Keyspace": {
   827                    "Name": "user",
   828                    "Sharded": true
   829                  },
   830                  "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1 union select id, weight_string(id) from music where 1 != 1",
   831                  "Query": "select id, weight_string(id) from `user` union select id, weight_string(id) from music",
   832                  "Table": "`user`"
   833                },
   834                {
   835                  "OperatorType": "Route",
   836                  "Variant": "Reference",
   837                  "Keyspace": {
   838                    "Name": "main",
   839                    "Sharded": false
   840                  },
   841                  "FieldQuery": "select 1, weight_string(1) from dual where 1 != 1",
   842                  "Query": "select distinct 1, weight_string(1) from dual",
   843                  "Table": "dual"
   844                }
   845              ]
   846            }
   847          ]
   848        },
   849        "TablesUsed": [
   850          "main.dual",
   851          "user.music",
   852          "user.user"
   853        ]
   854      }
   855    },
   856    {
   857      "comment": "multi-shard union",
   858      "query": "select 1 from music union (select id from user union all select name from unsharded)",
   859      "v3-plan": {
   860        "QueryType": "SELECT",
   861        "Original": "select 1 from music union (select id from user union all select name from unsharded)",
   862        "Instructions": {
   863          "OperatorType": "Distinct",
   864          "Inputs": [
   865            {
   866              "OperatorType": "Concatenate",
   867              "Inputs": [
   868                {
   869                  "OperatorType": "Route",
   870                  "Variant": "Scatter",
   871                  "Keyspace": {
   872                    "Name": "user",
   873                    "Sharded": true
   874                  },
   875                  "FieldQuery": "select 1 from music where 1 != 1",
   876                  "Query": "select 1 from music",
   877                  "Table": "music"
   878                },
   879                {
   880                  "OperatorType": "Concatenate",
   881                  "Inputs": [
   882                    {
   883                      "OperatorType": "Route",
   884                      "Variant": "Scatter",
   885                      "Keyspace": {
   886                        "Name": "user",
   887                        "Sharded": true
   888                      },
   889                      "FieldQuery": "select id from `user` where 1 != 1",
   890                      "Query": "select id from `user`",
   891                      "Table": "`user`"
   892                    },
   893                    {
   894                      "OperatorType": "Route",
   895                      "Variant": "Unsharded",
   896                      "Keyspace": {
   897                        "Name": "main",
   898                        "Sharded": false
   899                      },
   900                      "FieldQuery": "select `name` from unsharded where 1 != 1",
   901                      "Query": "select `name` from unsharded",
   902                      "Table": "unsharded"
   903                    }
   904                  ]
   905                }
   906              ]
   907            }
   908          ]
   909        }
   910      },
   911      "gen4-plan": "VT12001: unsupported: nesting of UNIONs on the right-hand side"
   912    },
   913    {
   914      "comment": "multi-shard union",
   915      "query": "select 1 from music union (select id from user union select name from unsharded)",
   916      "v3-plan": {
   917        "QueryType": "SELECT",
   918        "Original": "select 1 from music union (select id from user union select name from unsharded)",
   919        "Instructions": {
   920          "OperatorType": "Distinct",
   921          "Inputs": [
   922            {
   923              "OperatorType": "Concatenate",
   924              "Inputs": [
   925                {
   926                  "OperatorType": "Route",
   927                  "Variant": "Scatter",
   928                  "Keyspace": {
   929                    "Name": "user",
   930                    "Sharded": true
   931                  },
   932                  "FieldQuery": "select 1 from music where 1 != 1",
   933                  "Query": "select 1 from music",
   934                  "Table": "music"
   935                },
   936                {
   937                  "OperatorType": "Distinct",
   938                  "Inputs": [
   939                    {
   940                      "OperatorType": "Concatenate",
   941                      "Inputs": [
   942                        {
   943                          "OperatorType": "Route",
   944                          "Variant": "Scatter",
   945                          "Keyspace": {
   946                            "Name": "user",
   947                            "Sharded": true
   948                          },
   949                          "FieldQuery": "select id from `user` where 1 != 1",
   950                          "Query": "select id from `user`",
   951                          "Table": "`user`"
   952                        },
   953                        {
   954                          "OperatorType": "Route",
   955                          "Variant": "Unsharded",
   956                          "Keyspace": {
   957                            "Name": "main",
   958                            "Sharded": false
   959                          },
   960                          "FieldQuery": "select `name` from unsharded where 1 != 1",
   961                          "Query": "select `name` from unsharded",
   962                          "Table": "unsharded"
   963                        }
   964                      ]
   965                    }
   966                  ]
   967                }
   968              ]
   969            }
   970          ]
   971        }
   972      },
   973      "gen4-plan": "VT12001: unsupported: nesting of UNIONs on the right-hand side"
   974    },
   975    {
   976      "comment": "union with the same target shard because of vindex",
   977      "query": "select * from music where id = 1 union select * from user where id = 1",
   978      "v3-plan": {
   979        "QueryType": "SELECT",
   980        "Original": "select * from music where id = 1 union select * from user where id = 1",
   981        "Instructions": {
   982          "OperatorType": "Distinct",
   983          "Inputs": [
   984            {
   985              "OperatorType": "Concatenate",
   986              "Inputs": [
   987                {
   988                  "OperatorType": "Route",
   989                  "Variant": "EqualUnique",
   990                  "Keyspace": {
   991                    "Name": "user",
   992                    "Sharded": true
   993                  },
   994                  "FieldQuery": "select * from music where 1 != 1",
   995                  "Query": "select * from music where id = 1",
   996                  "Table": "music",
   997                  "Values": [
   998                    "INT64(1)"
   999                  ],
  1000                  "Vindex": "music_user_map"
  1001                },
  1002                {
  1003                  "OperatorType": "Route",
  1004                  "Variant": "EqualUnique",
  1005                  "Keyspace": {
  1006                    "Name": "user",
  1007                    "Sharded": true
  1008                  },
  1009                  "FieldQuery": "select * from `user` where 1 != 1",
  1010                  "Query": "select * from `user` where id = 1",
  1011                  "Table": "`user`",
  1012                  "Values": [
  1013                    "INT64(1)"
  1014                  ],
  1015                  "Vindex": "user_index"
  1016                }
  1017              ]
  1018            }
  1019          ]
  1020        }
  1021      },
  1022      "gen4-plan": {
  1023        "QueryType": "SELECT",
  1024        "Original": "select * from music where id = 1 union select * from user where id = 1",
  1025        "Instructions": {
  1026          "OperatorType": "Distinct",
  1027          "Inputs": [
  1028            {
  1029              "OperatorType": "Concatenate",
  1030              "Inputs": [
  1031                {
  1032                  "OperatorType": "Route",
  1033                  "Variant": "EqualUnique",
  1034                  "Keyspace": {
  1035                    "Name": "user",
  1036                    "Sharded": true
  1037                  },
  1038                  "FieldQuery": "select * from music where 1 != 1",
  1039                  "Query": "select distinct * from music where id = 1",
  1040                  "Table": "music",
  1041                  "Values": [
  1042                    "INT64(1)"
  1043                  ],
  1044                  "Vindex": "music_user_map"
  1045                },
  1046                {
  1047                  "OperatorType": "Route",
  1048                  "Variant": "EqualUnique",
  1049                  "Keyspace": {
  1050                    "Name": "user",
  1051                    "Sharded": true
  1052                  },
  1053                  "FieldQuery": "select * from `user` where 1 != 1",
  1054                  "Query": "select distinct * from `user` where id = 1",
  1055                  "Table": "`user`",
  1056                  "Values": [
  1057                    "INT64(1)"
  1058                  ],
  1059                  "Vindex": "user_index"
  1060                }
  1061              ]
  1062            }
  1063          ]
  1064        },
  1065        "TablesUsed": [
  1066          "user.music",
  1067          "user.user"
  1068        ]
  1069      }
  1070    },
  1071    {
  1072      "comment": "union with different target shards",
  1073      "query": "select 1 from music where id = 1 union select 1 from music where id = 2",
  1074      "v3-plan": {
  1075        "QueryType": "SELECT",
  1076        "Original": "select 1 from music where id = 1 union select 1 from music where id = 2",
  1077        "Instructions": {
  1078          "OperatorType": "Distinct",
  1079          "Inputs": [
  1080            {
  1081              "OperatorType": "Concatenate",
  1082              "Inputs": [
  1083                {
  1084                  "OperatorType": "Route",
  1085                  "Variant": "EqualUnique",
  1086                  "Keyspace": {
  1087                    "Name": "user",
  1088                    "Sharded": true
  1089                  },
  1090                  "FieldQuery": "select 1 from music where 1 != 1",
  1091                  "Query": "select 1 from music where id = 1",
  1092                  "Table": "music",
  1093                  "Values": [
  1094                    "INT64(1)"
  1095                  ],
  1096                  "Vindex": "music_user_map"
  1097                },
  1098                {
  1099                  "OperatorType": "Route",
  1100                  "Variant": "EqualUnique",
  1101                  "Keyspace": {
  1102                    "Name": "user",
  1103                    "Sharded": true
  1104                  },
  1105                  "FieldQuery": "select 1 from music where 1 != 1",
  1106                  "Query": "select 1 from music where id = 2",
  1107                  "Table": "music",
  1108                  "Values": [
  1109                    "INT64(2)"
  1110                  ],
  1111                  "Vindex": "music_user_map"
  1112                }
  1113              ]
  1114            }
  1115          ]
  1116        }
  1117      },
  1118      "gen4-plan": {
  1119        "QueryType": "SELECT",
  1120        "Original": "select 1 from music where id = 1 union select 1 from music where id = 2",
  1121        "Instructions": {
  1122          "OperatorType": "Distinct",
  1123          "Collations": [
  1124            "0: binary"
  1125          ],
  1126          "Inputs": [
  1127            {
  1128              "OperatorType": "Concatenate",
  1129              "Inputs": [
  1130                {
  1131                  "OperatorType": "Route",
  1132                  "Variant": "EqualUnique",
  1133                  "Keyspace": {
  1134                    "Name": "user",
  1135                    "Sharded": true
  1136                  },
  1137                  "FieldQuery": "select 1 from music where 1 != 1",
  1138                  "Query": "select distinct 1 from music where id = 1",
  1139                  "Table": "music",
  1140                  "Values": [
  1141                    "INT64(1)"
  1142                  ],
  1143                  "Vindex": "music_user_map"
  1144                },
  1145                {
  1146                  "OperatorType": "Route",
  1147                  "Variant": "EqualUnique",
  1148                  "Keyspace": {
  1149                    "Name": "user",
  1150                    "Sharded": true
  1151                  },
  1152                  "FieldQuery": "select 1 from music where 1 != 1",
  1153                  "Query": "select distinct 1 from music where id = 2",
  1154                  "Table": "music",
  1155                  "Values": [
  1156                    "INT64(2)"
  1157                  ],
  1158                  "Vindex": "music_user_map"
  1159                }
  1160              ]
  1161            }
  1162          ]
  1163        },
  1164        "TablesUsed": [
  1165          "user.music"
  1166        ]
  1167      }
  1168    },
  1169    {
  1170      "comment": "multiple select statement have inner order by with union - TODO (systay) no need to send down ORDER BY if we are going to loose it with UNION DISTINCT",
  1171      "query": "(select id from user order by 1 desc) union (select id from user order by 1 asc)",
  1172      "v3-plan": {
  1173        "QueryType": "SELECT",
  1174        "Original": "(select id from user order by 1 desc) union (select id from user order by 1 asc)",
  1175        "Instructions": {
  1176          "OperatorType": "Distinct",
  1177          "Inputs": [
  1178            {
  1179              "OperatorType": "Concatenate",
  1180              "Inputs": [
  1181                {
  1182                  "OperatorType": "Route",
  1183                  "Variant": "Scatter",
  1184                  "Keyspace": {
  1185                    "Name": "user",
  1186                    "Sharded": true
  1187                  },
  1188                  "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1",
  1189                  "OrderBy": "(0|1) DESC",
  1190                  "Query": "select id, weight_string(id) from `user` order by 1 desc",
  1191                  "ResultColumns": 1,
  1192                  "Table": "`user`"
  1193                },
  1194                {
  1195                  "OperatorType": "Route",
  1196                  "Variant": "Scatter",
  1197                  "Keyspace": {
  1198                    "Name": "user",
  1199                    "Sharded": true
  1200                  },
  1201                  "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1",
  1202                  "OrderBy": "(0|1) ASC",
  1203                  "Query": "select id, weight_string(id) from `user` order by 1 asc",
  1204                  "ResultColumns": 1,
  1205                  "Table": "`user`"
  1206                }
  1207              ]
  1208            }
  1209          ]
  1210        }
  1211      },
  1212      "gen4-plan": {
  1213        "QueryType": "SELECT",
  1214        "Original": "(select id from user order by 1 desc) union (select id from user order by 1 asc)",
  1215        "Instructions": {
  1216          "OperatorType": "Distinct",
  1217          "Collations": [
  1218            "(0:1)"
  1219          ],
  1220          "ResultColumns": 1,
  1221          "Inputs": [
  1222            {
  1223              "OperatorType": "Route",
  1224              "Variant": "Scatter",
  1225              "Keyspace": {
  1226                "Name": "user",
  1227                "Sharded": true
  1228              },
  1229              "FieldQuery": "(select id, weight_string(id) from `user` where 1 != 1) union (select id, weight_string(id) from `user` where 1 != 1)",
  1230              "OrderBy": "(0|1) DESC",
  1231              "Query": "(select id, weight_string(id) from `user` order by id desc) union (select id, weight_string(id) from `user` order by id asc)",
  1232              "ResultColumns": 1,
  1233              "Table": "`user`"
  1234            }
  1235          ]
  1236        },
  1237        "TablesUsed": [
  1238          "user.user"
  1239        ]
  1240      }
  1241    },
  1242    {
  1243      "comment": "multiple unions",
  1244      "query": "select 1 union select null union select 1.0 union select '1' union select 2 union select 2.0 from user",
  1245      "v3-plan": {
  1246        "QueryType": "SELECT",
  1247        "Original": "select 1 union select null union select 1.0 union select '1' union select 2 union select 2.0 from user",
  1248        "Instructions": {
  1249          "OperatorType": "Distinct",
  1250          "Inputs": [
  1251            {
  1252              "OperatorType": "Concatenate",
  1253              "Inputs": [
  1254                {
  1255                  "OperatorType": "Route",
  1256                  "Variant": "Reference",
  1257                  "Keyspace": {
  1258                    "Name": "main",
  1259                    "Sharded": false
  1260                  },
  1261                  "FieldQuery": "select 1 from dual where 1 != 1 union select null from dual where 1 != 1 union select 1.0 from dual where 1 != 1 union select '1' from dual where 1 != 1 union select 2 from dual where 1 != 1",
  1262                  "Query": "select 1 from dual union select null from dual union select 1.0 from dual union select '1' from dual union select 2 from dual",
  1263                  "Table": "dual"
  1264                },
  1265                {
  1266                  "OperatorType": "Route",
  1267                  "Variant": "Scatter",
  1268                  "Keyspace": {
  1269                    "Name": "user",
  1270                    "Sharded": true
  1271                  },
  1272                  "FieldQuery": "select 2.0 from `user` where 1 != 1",
  1273                  "Query": "select 2.0 from `user`",
  1274                  "Table": "`user`"
  1275                }
  1276              ]
  1277            }
  1278          ]
  1279        }
  1280      },
  1281      "gen4-plan": {
  1282        "QueryType": "SELECT",
  1283        "Original": "select 1 union select null union select 1.0 union select '1' union select 2 union select 2.0 from user",
  1284        "Instructions": {
  1285          "OperatorType": "Distinct",
  1286          "Collations": [
  1287            "0: binary"
  1288          ],
  1289          "Inputs": [
  1290            {
  1291              "OperatorType": "Concatenate",
  1292              "Inputs": [
  1293                {
  1294                  "OperatorType": "Route",
  1295                  "Variant": "Reference",
  1296                  "Keyspace": {
  1297                    "Name": "main",
  1298                    "Sharded": false
  1299                  },
  1300                  "FieldQuery": "select 1 from dual where 1 != 1 union all select null from dual where 1 != 1 union all select 1.0 from dual where 1 != 1 union all select '1' from dual where 1 != 1 union select 2 from dual where 1 != 1",
  1301                  "Query": "select 1 from dual union all select null from dual union all select 1.0 from dual union all select '1' from dual union select 2 from dual",
  1302                  "Table": "dual"
  1303                },
  1304                {
  1305                  "OperatorType": "Route",
  1306                  "Variant": "Scatter",
  1307                  "Keyspace": {
  1308                    "Name": "user",
  1309                    "Sharded": true
  1310                  },
  1311                  "FieldQuery": "select 2.0 from `user` where 1 != 1",
  1312                  "Query": "select distinct 2.0 from `user`",
  1313                  "Table": "`user`"
  1314                }
  1315              ]
  1316            }
  1317          ]
  1318        },
  1319        "TablesUsed": [
  1320          "main.dual",
  1321          "user.user"
  1322        ]
  1323      }
  1324    },
  1325    {
  1326      "comment": "union distinct between a scatter query and a join (other side)",
  1327      "query": "(select user.id, user.name from user join user_extra where user_extra.extra = 'asdf') union select 'b','c' from user",
  1328      "v3-plan": {
  1329        "QueryType": "SELECT",
  1330        "Original": "(select user.id, user.name from user join user_extra where user_extra.extra = 'asdf') union select 'b','c' from user",
  1331        "Instructions": {
  1332          "OperatorType": "Distinct",
  1333          "Inputs": [
  1334            {
  1335              "OperatorType": "Concatenate",
  1336              "Inputs": [
  1337                {
  1338                  "OperatorType": "Join",
  1339                  "Variant": "Join",
  1340                  "JoinColumnIndexes": "L:0,L:1",
  1341                  "TableName": "`user`_user_extra",
  1342                  "Inputs": [
  1343                    {
  1344                      "OperatorType": "Route",
  1345                      "Variant": "Scatter",
  1346                      "Keyspace": {
  1347                        "Name": "user",
  1348                        "Sharded": true
  1349                      },
  1350                      "FieldQuery": "select `user`.id, `user`.`name` from `user` where 1 != 1",
  1351                      "Query": "select `user`.id, `user`.`name` from `user`",
  1352                      "Table": "`user`"
  1353                    },
  1354                    {
  1355                      "OperatorType": "Route",
  1356                      "Variant": "Scatter",
  1357                      "Keyspace": {
  1358                        "Name": "user",
  1359                        "Sharded": true
  1360                      },
  1361                      "FieldQuery": "select 1 from user_extra where 1 != 1",
  1362                      "Query": "select 1 from user_extra where user_extra.extra = 'asdf'",
  1363                      "Table": "user_extra"
  1364                    }
  1365                  ]
  1366                },
  1367                {
  1368                  "OperatorType": "Route",
  1369                  "Variant": "Scatter",
  1370                  "Keyspace": {
  1371                    "Name": "user",
  1372                    "Sharded": true
  1373                  },
  1374                  "FieldQuery": "select 'b', 'c' from `user` where 1 != 1",
  1375                  "Query": "select 'b', 'c' from `user`",
  1376                  "Table": "`user`"
  1377                }
  1378              ]
  1379            }
  1380          ]
  1381        }
  1382      },
  1383      "gen4-plan": {
  1384        "QueryType": "SELECT",
  1385        "Original": "(select user.id, user.name from user join user_extra where user_extra.extra = 'asdf') union select 'b','c' from user",
  1386        "Instructions": {
  1387          "OperatorType": "Distinct",
  1388          "Collations": [
  1389            "(0:2)",
  1390            "(1:3)"
  1391          ],
  1392          "ResultColumns": 2,
  1393          "Inputs": [
  1394            {
  1395              "OperatorType": "Concatenate",
  1396              "Inputs": [
  1397                {
  1398                  "OperatorType": "Join",
  1399                  "Variant": "Join",
  1400                  "JoinColumnIndexes": "L:0,L:1,L:2,L:3",
  1401                  "TableName": "`user`_user_extra",
  1402                  "Inputs": [
  1403                    {
  1404                      "OperatorType": "Route",
  1405                      "Variant": "Scatter",
  1406                      "Keyspace": {
  1407                        "Name": "user",
  1408                        "Sharded": true
  1409                      },
  1410                      "FieldQuery": "select `user`.id, `user`.`name`, weight_string(`user`.id), weight_string(`user`.`name`) from `user` where 1 != 1",
  1411                      "Query": "select `user`.id, `user`.`name`, weight_string(`user`.id), weight_string(`user`.`name`) from `user`",
  1412                      "Table": "`user`"
  1413                    },
  1414                    {
  1415                      "OperatorType": "Route",
  1416                      "Variant": "Scatter",
  1417                      "Keyspace": {
  1418                        "Name": "user",
  1419                        "Sharded": true
  1420                      },
  1421                      "FieldQuery": "select 1 from user_extra where 1 != 1",
  1422                      "Query": "select 1 from user_extra where user_extra.extra = 'asdf'",
  1423                      "Table": "user_extra"
  1424                    }
  1425                  ]
  1426                },
  1427                {
  1428                  "OperatorType": "Route",
  1429                  "Variant": "Scatter",
  1430                  "Keyspace": {
  1431                    "Name": "user",
  1432                    "Sharded": true
  1433                  },
  1434                  "FieldQuery": "select 'b', 'c', weight_string('b'), weight_string('c') from `user` where 1 != 1",
  1435                  "Query": "select distinct 'b', 'c', weight_string('b'), weight_string('c') from `user`",
  1436                  "Table": "`user`"
  1437                }
  1438              ]
  1439            }
  1440          ]
  1441        },
  1442        "TablesUsed": [
  1443          "user.user",
  1444          "user.user_extra"
  1445        ]
  1446      }
  1447    },
  1448    {
  1449      "comment": "union distinct between a scatter query and a join (other side)",
  1450      "query": "select 'b','c' from user union (select user.id, user.name from user join user_extra where user_extra.extra = 'asdf')",
  1451      "v3-plan": {
  1452        "QueryType": "SELECT",
  1453        "Original": "select 'b','c' from user union (select user.id, user.name from user join user_extra where user_extra.extra = 'asdf')",
  1454        "Instructions": {
  1455          "OperatorType": "Distinct",
  1456          "Inputs": [
  1457            {
  1458              "OperatorType": "Concatenate",
  1459              "Inputs": [
  1460                {
  1461                  "OperatorType": "Route",
  1462                  "Variant": "Scatter",
  1463                  "Keyspace": {
  1464                    "Name": "user",
  1465                    "Sharded": true
  1466                  },
  1467                  "FieldQuery": "select 'b', 'c' from `user` where 1 != 1",
  1468                  "Query": "select 'b', 'c' from `user`",
  1469                  "Table": "`user`"
  1470                },
  1471                {
  1472                  "OperatorType": "Join",
  1473                  "Variant": "Join",
  1474                  "JoinColumnIndexes": "L:0,L:1",
  1475                  "TableName": "`user`_user_extra",
  1476                  "Inputs": [
  1477                    {
  1478                      "OperatorType": "Route",
  1479                      "Variant": "Scatter",
  1480                      "Keyspace": {
  1481                        "Name": "user",
  1482                        "Sharded": true
  1483                      },
  1484                      "FieldQuery": "select `user`.id, `user`.`name` from `user` where 1 != 1",
  1485                      "Query": "select `user`.id, `user`.`name` from `user`",
  1486                      "Table": "`user`"
  1487                    },
  1488                    {
  1489                      "OperatorType": "Route",
  1490                      "Variant": "Scatter",
  1491                      "Keyspace": {
  1492                        "Name": "user",
  1493                        "Sharded": true
  1494                      },
  1495                      "FieldQuery": "select 1 from user_extra where 1 != 1",
  1496                      "Query": "select 1 from user_extra where user_extra.extra = 'asdf'",
  1497                      "Table": "user_extra"
  1498                    }
  1499                  ]
  1500                }
  1501              ]
  1502            }
  1503          ]
  1504        }
  1505      },
  1506      "gen4-plan": {
  1507        "QueryType": "SELECT",
  1508        "Original": "select 'b','c' from user union (select user.id, user.name from user join user_extra where user_extra.extra = 'asdf')",
  1509        "Instructions": {
  1510          "OperatorType": "Distinct",
  1511          "Collations": [
  1512            "(0:2)",
  1513            "(1:3)"
  1514          ],
  1515          "ResultColumns": 2,
  1516          "Inputs": [
  1517            {
  1518              "OperatorType": "Concatenate",
  1519              "Inputs": [
  1520                {
  1521                  "OperatorType": "Route",
  1522                  "Variant": "Scatter",
  1523                  "Keyspace": {
  1524                    "Name": "user",
  1525                    "Sharded": true
  1526                  },
  1527                  "FieldQuery": "select 'b', 'c', weight_string('b'), weight_string('c') from `user` where 1 != 1",
  1528                  "Query": "select distinct 'b', 'c', weight_string('b'), weight_string('c') from `user`",
  1529                  "Table": "`user`"
  1530                },
  1531                {
  1532                  "OperatorType": "Join",
  1533                  "Variant": "Join",
  1534                  "JoinColumnIndexes": "L:0,L:1,L:2,L:3",
  1535                  "TableName": "`user`_user_extra",
  1536                  "Inputs": [
  1537                    {
  1538                      "OperatorType": "Route",
  1539                      "Variant": "Scatter",
  1540                      "Keyspace": {
  1541                        "Name": "user",
  1542                        "Sharded": true
  1543                      },
  1544                      "FieldQuery": "select `user`.id, `user`.`name`, weight_string(`user`.id), weight_string(`user`.`name`) from `user` where 1 != 1",
  1545                      "Query": "select `user`.id, `user`.`name`, weight_string(`user`.id), weight_string(`user`.`name`) from `user`",
  1546                      "Table": "`user`"
  1547                    },
  1548                    {
  1549                      "OperatorType": "Route",
  1550                      "Variant": "Scatter",
  1551                      "Keyspace": {
  1552                        "Name": "user",
  1553                        "Sharded": true
  1554                      },
  1555                      "FieldQuery": "select 1 from user_extra where 1 != 1",
  1556                      "Query": "select 1 from user_extra where user_extra.extra = 'asdf'",
  1557                      "Table": "user_extra"
  1558                    }
  1559                  ]
  1560                }
  1561              ]
  1562            }
  1563          ]
  1564        },
  1565        "TablesUsed": [
  1566          "user.user",
  1567          "user.user_extra"
  1568        ]
  1569      }
  1570    },
  1571    {
  1572      "comment": "unmergable because we are using aggregation",
  1573      "query": "select count(*) as s from user union select count(*) as s from music",
  1574      "v3-plan": {
  1575        "QueryType": "SELECT",
  1576        "Original": "select count(*) as s from user union select count(*) as s from music",
  1577        "Instructions": {
  1578          "OperatorType": "Distinct",
  1579          "Inputs": [
  1580            {
  1581              "OperatorType": "Concatenate",
  1582              "Inputs": [
  1583                {
  1584                  "OperatorType": "Aggregate",
  1585                  "Variant": "Scalar",
  1586                  "Aggregates": "sum_count(0) AS count",
  1587                  "Inputs": [
  1588                    {
  1589                      "OperatorType": "Route",
  1590                      "Variant": "Scatter",
  1591                      "Keyspace": {
  1592                        "Name": "user",
  1593                        "Sharded": true
  1594                      },
  1595                      "FieldQuery": "select count(*) as s from `user` where 1 != 1",
  1596                      "Query": "select count(*) as s from `user`",
  1597                      "Table": "`user`"
  1598                    }
  1599                  ]
  1600                },
  1601                {
  1602                  "OperatorType": "Aggregate",
  1603                  "Variant": "Scalar",
  1604                  "Aggregates": "sum_count(0) AS count",
  1605                  "Inputs": [
  1606                    {
  1607                      "OperatorType": "Route",
  1608                      "Variant": "Scatter",
  1609                      "Keyspace": {
  1610                        "Name": "user",
  1611                        "Sharded": true
  1612                      },
  1613                      "FieldQuery": "select count(*) as s from music where 1 != 1",
  1614                      "Query": "select count(*) as s from music",
  1615                      "Table": "music"
  1616                    }
  1617                  ]
  1618                }
  1619              ]
  1620            }
  1621          ]
  1622        }
  1623      },
  1624      "gen4-plan": {
  1625        "QueryType": "SELECT",
  1626        "Original": "select count(*) as s from user union select count(*) as s from music",
  1627        "Instructions": {
  1628          "OperatorType": "Distinct",
  1629          "Collations": [
  1630            "0: binary"
  1631          ],
  1632          "Inputs": [
  1633            {
  1634              "OperatorType": "Concatenate",
  1635              "Inputs": [
  1636                {
  1637                  "OperatorType": "Aggregate",
  1638                  "Variant": "Scalar",
  1639                  "Aggregates": "sum_count_star(0) AS s",
  1640                  "Inputs": [
  1641                    {
  1642                      "OperatorType": "Route",
  1643                      "Variant": "Scatter",
  1644                      "Keyspace": {
  1645                        "Name": "user",
  1646                        "Sharded": true
  1647                      },
  1648                      "FieldQuery": "select count(*) as s from `user` where 1 != 1",
  1649                      "Query": "select count(*) as s from `user`",
  1650                      "Table": "`user`"
  1651                    }
  1652                  ]
  1653                },
  1654                {
  1655                  "OperatorType": "Aggregate",
  1656                  "Variant": "Scalar",
  1657                  "Aggregates": "sum_count_star(0) AS s",
  1658                  "Inputs": [
  1659                    {
  1660                      "OperatorType": "Route",
  1661                      "Variant": "Scatter",
  1662                      "Keyspace": {
  1663                        "Name": "user",
  1664                        "Sharded": true
  1665                      },
  1666                      "FieldQuery": "select count(*) as s from music where 1 != 1",
  1667                      "Query": "select count(*) as s from music",
  1668                      "Table": "music"
  1669                    }
  1670                  ]
  1671                }
  1672              ]
  1673            }
  1674          ]
  1675        },
  1676        "TablesUsed": [
  1677          "user.music",
  1678          "user.user"
  1679        ]
  1680      }
  1681    },
  1682    {
  1683      "comment": "Union in derived table with first SELECT being an UNION",
  1684      "query": "select * from ((select id from user union select id+1 from user) union select user_id from user_extra) as t",
  1685      "v3-plan": {
  1686        "QueryType": "SELECT",
  1687        "Original": "select * from ((select id from user union select id+1 from user) union select user_id from user_extra) as t",
  1688        "Instructions": {
  1689          "OperatorType": "SimpleProjection",
  1690          "Columns": [
  1691            0
  1692          ],
  1693          "Inputs": [
  1694            {
  1695              "OperatorType": "Distinct",
  1696              "Inputs": [
  1697                {
  1698                  "OperatorType": "Concatenate",
  1699                  "Inputs": [
  1700                    {
  1701                      "OperatorType": "Distinct",
  1702                      "Inputs": [
  1703                        {
  1704                          "OperatorType": "Concatenate",
  1705                          "Inputs": [
  1706                            {
  1707                              "OperatorType": "Route",
  1708                              "Variant": "Scatter",
  1709                              "Keyspace": {
  1710                                "Name": "user",
  1711                                "Sharded": true
  1712                              },
  1713                              "FieldQuery": "select id from `user` where 1 != 1",
  1714                              "Query": "select id from `user`",
  1715                              "Table": "`user`"
  1716                            },
  1717                            {
  1718                              "OperatorType": "Route",
  1719                              "Variant": "Scatter",
  1720                              "Keyspace": {
  1721                                "Name": "user",
  1722                                "Sharded": true
  1723                              },
  1724                              "FieldQuery": "select id + 1 from `user` where 1 != 1",
  1725                              "Query": "select id + 1 from `user`",
  1726                              "Table": "`user`"
  1727                            }
  1728                          ]
  1729                        }
  1730                      ]
  1731                    },
  1732                    {
  1733                      "OperatorType": "Route",
  1734                      "Variant": "Scatter",
  1735                      "Keyspace": {
  1736                        "Name": "user",
  1737                        "Sharded": true
  1738                      },
  1739                      "FieldQuery": "select user_id from user_extra where 1 != 1",
  1740                      "Query": "select user_id from user_extra",
  1741                      "Table": "user_extra"
  1742                    }
  1743                  ]
  1744                }
  1745              ]
  1746            }
  1747          ]
  1748        }
  1749      },
  1750      "gen4-plan": {
  1751        "QueryType": "SELECT",
  1752        "Original": "select * from ((select id from user union select id+1 from user) union select user_id from user_extra) as t",
  1753        "Instructions": {
  1754          "OperatorType": "SimpleProjection",
  1755          "Columns": [
  1756            0
  1757          ],
  1758          "Inputs": [
  1759            {
  1760              "OperatorType": "Distinct",
  1761              "Collations": [
  1762                "(0:1)"
  1763              ],
  1764              "Inputs": [
  1765                {
  1766                  "OperatorType": "Route",
  1767                  "Variant": "Scatter",
  1768                  "Keyspace": {
  1769                    "Name": "user",
  1770                    "Sharded": true
  1771                  },
  1772                  "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1 union all select id + 1, weight_string(id + 1) from `user` where 1 != 1 union select user_id, weight_string(user_id) from user_extra where 1 != 1",
  1773                  "Query": "select id, weight_string(id) from `user` union all select id + 1, weight_string(id + 1) from `user` union select user_id, weight_string(user_id) from user_extra",
  1774                  "Table": "`user`"
  1775                }
  1776              ]
  1777            }
  1778          ]
  1779        },
  1780        "TablesUsed": [
  1781          "user.user",
  1782          "user.user_extra"
  1783        ]
  1784      }
  1785    },
  1786    {
  1787      "comment": "gen4 optimises away ORDER BY when it's safe to do",
  1788      "query": "(select id from user union select id from music order by id) union select 1 from unsharded",
  1789      "v3-plan": "VT12001: unsupported: ORDER BY on top of UNION",
  1790      "gen4-plan": {
  1791        "QueryType": "SELECT",
  1792        "Original": "(select id from user union select id from music order by id) union select 1 from unsharded",
  1793        "Instructions": {
  1794          "OperatorType": "Distinct",
  1795          "Collations": [
  1796            "(0:1)"
  1797          ],
  1798          "ResultColumns": 1,
  1799          "Inputs": [
  1800            {
  1801              "OperatorType": "Concatenate",
  1802              "Inputs": [
  1803                {
  1804                  "OperatorType": "Route",
  1805                  "Variant": "Scatter",
  1806                  "Keyspace": {
  1807                    "Name": "user",
  1808                    "Sharded": true
  1809                  },
  1810                  "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1 union select id, weight_string(id) from music where 1 != 1",
  1811                  "Query": "select id, weight_string(id) from `user` union select id, weight_string(id) from music",
  1812                  "Table": "`user`"
  1813                },
  1814                {
  1815                  "OperatorType": "Route",
  1816                  "Variant": "Unsharded",
  1817                  "Keyspace": {
  1818                    "Name": "main",
  1819                    "Sharded": false
  1820                  },
  1821                  "FieldQuery": "select 1, weight_string(1) from unsharded where 1 != 1",
  1822                  "Query": "select distinct 1, weight_string(1) from unsharded",
  1823                  "Table": "unsharded"
  1824                }
  1825              ]
  1826            }
  1827          ]
  1828        },
  1829        "TablesUsed": [
  1830          "main.unsharded",
  1831          "user.music",
  1832          "user.user"
  1833        ]
  1834      }
  1835    },
  1836    {
  1837      "comment": "push down the ::upper_limit to the sources, since we are doing DISTINCT on them, it's safe",
  1838      "query": "select id from user union select 3 limit 10",
  1839      "v3-plan": {
  1840        "QueryType": "SELECT",
  1841        "Original": "select id from user union select 3 limit 10",
  1842        "Instructions": {
  1843          "OperatorType": "Limit",
  1844          "Count": "INT64(10)",
  1845          "Inputs": [
  1846            {
  1847              "OperatorType": "Distinct",
  1848              "Inputs": [
  1849                {
  1850                  "OperatorType": "Concatenate",
  1851                  "Inputs": [
  1852                    {
  1853                      "OperatorType": "Route",
  1854                      "Variant": "Scatter",
  1855                      "Keyspace": {
  1856                        "Name": "user",
  1857                        "Sharded": true
  1858                      },
  1859                      "FieldQuery": "select id from `user` where 1 != 1",
  1860                      "Query": "select id from `user`",
  1861                      "Table": "`user`"
  1862                    },
  1863                    {
  1864                      "OperatorType": "Route",
  1865                      "Variant": "Reference",
  1866                      "Keyspace": {
  1867                        "Name": "main",
  1868                        "Sharded": false
  1869                      },
  1870                      "FieldQuery": "select 3 from dual where 1 != 1",
  1871                      "Query": "select 3 from dual",
  1872                      "Table": "dual"
  1873                    }
  1874                  ]
  1875                }
  1876              ]
  1877            }
  1878          ]
  1879        }
  1880      },
  1881      "gen4-plan": {
  1882        "QueryType": "SELECT",
  1883        "Original": "select id from user union select 3 limit 10",
  1884        "Instructions": {
  1885          "OperatorType": "Limit",
  1886          "Count": "INT64(10)",
  1887          "Inputs": [
  1888            {
  1889              "OperatorType": "Distinct",
  1890              "Collations": [
  1891                "(0:1)"
  1892              ],
  1893              "ResultColumns": 1,
  1894              "Inputs": [
  1895                {
  1896                  "OperatorType": "Concatenate",
  1897                  "Inputs": [
  1898                    {
  1899                      "OperatorType": "Route",
  1900                      "Variant": "Scatter",
  1901                      "Keyspace": {
  1902                        "Name": "user",
  1903                        "Sharded": true
  1904                      },
  1905                      "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1",
  1906                      "Query": "select distinct id, weight_string(id) from `user` limit :__upper_limit",
  1907                      "Table": "`user`"
  1908                    },
  1909                    {
  1910                      "OperatorType": "Route",
  1911                      "Variant": "Reference",
  1912                      "Keyspace": {
  1913                        "Name": "main",
  1914                        "Sharded": false
  1915                      },
  1916                      "FieldQuery": "select 3, weight_string(3) from dual where 1 != 1",
  1917                      "Query": "select distinct 3, weight_string(3) from dual limit :__upper_limit",
  1918                      "Table": "dual"
  1919                    }
  1920                  ]
  1921                }
  1922              ]
  1923            }
  1924          ]
  1925        },
  1926        "TablesUsed": [
  1927          "main.dual",
  1928          "user.user"
  1929        ]
  1930      }
  1931    },
  1932    {
  1933      "comment": "silly query that should be collapsed into a single unsharded UNION route",
  1934      "query": "(select 1 from unsharded union select 1 from unsharded union all select 1 from unsharded order by 1) union select 1 from unsharded union all select 1 from unsharded order by 1",
  1935      "v3-plan": {
  1936        "QueryType": "SELECT",
  1937        "Original": "(select 1 from unsharded union select 1 from unsharded union all select 1 from unsharded order by 1) union select 1 from unsharded union all select 1 from unsharded order by 1",
  1938        "Instructions": {
  1939          "OperatorType": "Route",
  1940          "Variant": "Unsharded",
  1941          "Keyspace": {
  1942            "Name": "main",
  1943            "Sharded": false
  1944          },
  1945          "FieldQuery": "(select 1 from unsharded where 1 != 1 union select 1 from unsharded where 1 != 1 union all select 1 from unsharded where 1 != 1) union select 1 from unsharded where 1 != 1 union all select 1 from unsharded where 1 != 1",
  1946          "Query": "(select 1 from unsharded union select 1 from unsharded union all select 1 from unsharded order by 1 asc) union select 1 from unsharded union all select 1 from unsharded order by 1 asc",
  1947          "Table": "unsharded"
  1948        }
  1949      },
  1950      "gen4-plan": {
  1951        "QueryType": "SELECT",
  1952        "Original": "(select 1 from unsharded union select 1 from unsharded union all select 1 from unsharded order by 1) union select 1 from unsharded union all select 1 from unsharded order by 1",
  1953        "Instructions": {
  1954          "OperatorType": "Route",
  1955          "Variant": "Unsharded",
  1956          "Keyspace": {
  1957            "Name": "main",
  1958            "Sharded": false
  1959          },
  1960          "FieldQuery": "(select 1 from unsharded where 1 != 1 union select 1 from unsharded where 1 != 1 union all select 1 from unsharded where 1 != 1) union select 1 from unsharded where 1 != 1 union all select 1 from unsharded where 1 != 1",
  1961          "Query": "(select 1 from unsharded union select 1 from unsharded union all select 1 from unsharded order by 1 asc) union select 1 from unsharded union all select 1 from unsharded order by 1 asc",
  1962          "Table": "unsharded"
  1963        },
  1964        "TablesUsed": [
  1965          "main.unsharded"
  1966        ]
  1967      }
  1968    },
  1969    {
  1970      "comment": "UNION that needs to be reordered to be merged more aggressively. Gen4 is able to get it down to 2 routes",
  1971      "query": "select col from unsharded union select id from user union select col2 from unsharded union select col from user_extra",
  1972      "v3-plan": {
  1973        "QueryType": "SELECT",
  1974        "Original": "select col from unsharded union select id from user union select col2 from unsharded union select col from user_extra",
  1975        "Instructions": {
  1976          "OperatorType": "Distinct",
  1977          "Inputs": [
  1978            {
  1979              "OperatorType": "Concatenate",
  1980              "Inputs": [
  1981                {
  1982                  "OperatorType": "Distinct",
  1983                  "Inputs": [
  1984                    {
  1985                      "OperatorType": "Concatenate",
  1986                      "Inputs": [
  1987                        {
  1988                          "OperatorType": "Distinct",
  1989                          "Inputs": [
  1990                            {
  1991                              "OperatorType": "Concatenate",
  1992                              "Inputs": [
  1993                                {
  1994                                  "OperatorType": "Route",
  1995                                  "Variant": "Unsharded",
  1996                                  "Keyspace": {
  1997                                    "Name": "main",
  1998                                    "Sharded": false
  1999                                  },
  2000                                  "FieldQuery": "select col from unsharded where 1 != 1",
  2001                                  "Query": "select col from unsharded",
  2002                                  "Table": "unsharded"
  2003                                },
  2004                                {
  2005                                  "OperatorType": "Route",
  2006                                  "Variant": "Scatter",
  2007                                  "Keyspace": {
  2008                                    "Name": "user",
  2009                                    "Sharded": true
  2010                                  },
  2011                                  "FieldQuery": "select id from `user` where 1 != 1",
  2012                                  "Query": "select id from `user`",
  2013                                  "Table": "`user`"
  2014                                }
  2015                              ]
  2016                            }
  2017                          ]
  2018                        },
  2019                        {
  2020                          "OperatorType": "Route",
  2021                          "Variant": "Unsharded",
  2022                          "Keyspace": {
  2023                            "Name": "main",
  2024                            "Sharded": false
  2025                          },
  2026                          "FieldQuery": "select col2 from unsharded where 1 != 1",
  2027                          "Query": "select col2 from unsharded",
  2028                          "Table": "unsharded"
  2029                        }
  2030                      ]
  2031                    }
  2032                  ]
  2033                },
  2034                {
  2035                  "OperatorType": "Route",
  2036                  "Variant": "Scatter",
  2037                  "Keyspace": {
  2038                    "Name": "user",
  2039                    "Sharded": true
  2040                  },
  2041                  "FieldQuery": "select col from user_extra where 1 != 1",
  2042                  "Query": "select col from user_extra",
  2043                  "Table": "user_extra"
  2044                }
  2045              ]
  2046            }
  2047          ]
  2048        }
  2049      },
  2050      "gen4-plan": {
  2051        "QueryType": "SELECT",
  2052        "Original": "select col from unsharded union select id from user union select col2 from unsharded union select col from user_extra",
  2053        "Instructions": {
  2054          "OperatorType": "Distinct",
  2055          "Collations": [
  2056            "(0:1)"
  2057          ],
  2058          "ResultColumns": 1,
  2059          "Inputs": [
  2060            {
  2061              "OperatorType": "Concatenate",
  2062              "Inputs": [
  2063                {
  2064                  "OperatorType": "Route",
  2065                  "Variant": "Unsharded",
  2066                  "Keyspace": {
  2067                    "Name": "main",
  2068                    "Sharded": false
  2069                  },
  2070                  "FieldQuery": "select col, weight_string(col) from unsharded where 1 != 1 union select col2, weight_string(col2) from unsharded where 1 != 1",
  2071                  "Query": "select col, weight_string(col) from unsharded union select col2, weight_string(col2) from unsharded",
  2072                  "Table": "unsharded"
  2073                },
  2074                {
  2075                  "OperatorType": "Route",
  2076                  "Variant": "Scatter",
  2077                  "Keyspace": {
  2078                    "Name": "user",
  2079                    "Sharded": true
  2080                  },
  2081                  "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1 union select col, weight_string(col) from user_extra where 1 != 1",
  2082                  "Query": "select id, weight_string(id) from `user` union select col, weight_string(col) from user_extra",
  2083                  "Table": "`user`"
  2084                }
  2085              ]
  2086            }
  2087          ]
  2088        },
  2089        "TablesUsed": [
  2090          "main.unsharded",
  2091          "user.user",
  2092          "user.user_extra"
  2093        ]
  2094      }
  2095    },
  2096    {
  2097      "comment": "derived table with union",
  2098      "query": "select tbl2.id FROM ((select id from user order by id limit 5) union all (select id from user order by id desc limit 5)) as tbl1 INNER JOIN user as tbl2  ON tbl1.id = tbl2.id",
  2099      "v3-plan": {
  2100        "QueryType": "SELECT",
  2101        "Original": "select tbl2.id FROM ((select id from user order by id limit 5) union all (select id from user order by id desc limit 5)) as tbl1 INNER JOIN user as tbl2  ON tbl1.id = tbl2.id",
  2102        "Instructions": {
  2103          "OperatorType": "Join",
  2104          "Variant": "Join",
  2105          "JoinColumnIndexes": "R:0",
  2106          "JoinVars": {
  2107            "tbl1_id": 0
  2108          },
  2109          "TableName": "`user`_`user`",
  2110          "Inputs": [
  2111            {
  2112              "OperatorType": "SimpleProjection",
  2113              "Columns": [
  2114                0
  2115              ],
  2116              "Inputs": [
  2117                {
  2118                  "OperatorType": "Concatenate",
  2119                  "Inputs": [
  2120                    {
  2121                      "OperatorType": "Limit",
  2122                      "Count": "INT64(5)",
  2123                      "Inputs": [
  2124                        {
  2125                          "OperatorType": "Route",
  2126                          "Variant": "Scatter",
  2127                          "Keyspace": {
  2128                            "Name": "user",
  2129                            "Sharded": true
  2130                          },
  2131                          "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1",
  2132                          "OrderBy": "(0|1) ASC",
  2133                          "Query": "select id, weight_string(id) from `user` order by id asc limit :__upper_limit",
  2134                          "ResultColumns": 1,
  2135                          "Table": "`user`"
  2136                        }
  2137                      ]
  2138                    },
  2139                    {
  2140                      "OperatorType": "Limit",
  2141                      "Count": "INT64(5)",
  2142                      "Inputs": [
  2143                        {
  2144                          "OperatorType": "Route",
  2145                          "Variant": "Scatter",
  2146                          "Keyspace": {
  2147                            "Name": "user",
  2148                            "Sharded": true
  2149                          },
  2150                          "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1",
  2151                          "OrderBy": "(0|1) DESC",
  2152                          "Query": "select id, weight_string(id) from `user` order by id desc limit :__upper_limit",
  2153                          "ResultColumns": 1,
  2154                          "Table": "`user`"
  2155                        }
  2156                      ]
  2157                    }
  2158                  ]
  2159                }
  2160              ]
  2161            },
  2162            {
  2163              "OperatorType": "Route",
  2164              "Variant": "EqualUnique",
  2165              "Keyspace": {
  2166                "Name": "user",
  2167                "Sharded": true
  2168              },
  2169              "FieldQuery": "select tbl2.id from `user` as tbl2 where 1 != 1",
  2170              "Query": "select tbl2.id from `user` as tbl2 where tbl2.id = :tbl1_id",
  2171              "Table": "`user`",
  2172              "Values": [
  2173                ":tbl1_id"
  2174              ],
  2175              "Vindex": "user_index"
  2176            }
  2177          ]
  2178        }
  2179      },
  2180      "gen4-plan": {
  2181        "QueryType": "SELECT",
  2182        "Original": "select tbl2.id FROM ((select id from user order by id limit 5) union all (select id from user order by id desc limit 5)) as tbl1 INNER JOIN user as tbl2  ON tbl1.id = tbl2.id",
  2183        "Instructions": {
  2184          "OperatorType": "Join",
  2185          "Variant": "Join",
  2186          "JoinColumnIndexes": "R:0",
  2187          "JoinVars": {
  2188            "tbl1_id": 0
  2189          },
  2190          "TableName": "`user`_`user`",
  2191          "Inputs": [
  2192            {
  2193              "OperatorType": "SimpleProjection",
  2194              "Columns": [
  2195                0
  2196              ],
  2197              "Inputs": [
  2198                {
  2199                  "OperatorType": "Concatenate",
  2200                  "Inputs": [
  2201                    {
  2202                      "OperatorType": "Limit",
  2203                      "Count": "INT64(5)",
  2204                      "Inputs": [
  2205                        {
  2206                          "OperatorType": "Route",
  2207                          "Variant": "Scatter",
  2208                          "Keyspace": {
  2209                            "Name": "user",
  2210                            "Sharded": true
  2211                          },
  2212                          "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1",
  2213                          "OrderBy": "(0|1) ASC",
  2214                          "Query": "select id, weight_string(id) from `user` order by id asc limit :__upper_limit",
  2215                          "ResultColumns": 1,
  2216                          "Table": "`user`"
  2217                        }
  2218                      ]
  2219                    },
  2220                    {
  2221                      "OperatorType": "Limit",
  2222                      "Count": "INT64(5)",
  2223                      "Inputs": [
  2224                        {
  2225                          "OperatorType": "Route",
  2226                          "Variant": "Scatter",
  2227                          "Keyspace": {
  2228                            "Name": "user",
  2229                            "Sharded": true
  2230                          },
  2231                          "FieldQuery": "select id, weight_string(id) from `user` where 1 != 1",
  2232                          "OrderBy": "(0|1) DESC",
  2233                          "Query": "select id, weight_string(id) from `user` order by id desc limit :__upper_limit",
  2234                          "ResultColumns": 1,
  2235                          "Table": "`user`"
  2236                        }
  2237                      ]
  2238                    }
  2239                  ]
  2240                }
  2241              ]
  2242            },
  2243            {
  2244              "OperatorType": "Route",
  2245              "Variant": "EqualUnique",
  2246              "Keyspace": {
  2247                "Name": "user",
  2248                "Sharded": true
  2249              },
  2250              "FieldQuery": "select tbl2.id from `user` as tbl2 where 1 != 1",
  2251              "Query": "select tbl2.id from `user` as tbl2 where tbl2.id = :tbl1_id",
  2252              "Table": "`user`",
  2253              "Values": [
  2254                ":tbl1_id"
  2255              ],
  2256              "Vindex": "user_index"
  2257            }
  2258          ]
  2259        },
  2260        "TablesUsed": [
  2261          "user.user"
  2262        ]
  2263      }
  2264    },
  2265    {
  2266      "comment": "ambiguous LIMIT",
  2267      "query": "select id from user limit 1 union all select id from music limit 1",
  2268      "plan": "syntax error at position 34 near 'union'"
  2269    },
  2270    {
  2271      "comment": "ambiguous ORDER BY",
  2272      "query": "select id from user order by id union all select id from music order by id desc",
  2273      "plan": "syntax error at position 38 near 'union'"
  2274    },
  2275    {
  2276      "comment": "different number of columns",
  2277      "query": "select id, 42 from user where id = 1 union all select id from user where id = 5",
  2278      "v3-plan": "The used SELECT statements have a different number of columns (errno 1222) (sqlstate 21000) during query: select id, 42 from `user` where id = 1 union all select id from `user` where id = 5",
  2279      "gen4-plan": "The used SELECT statements have a different number of columns"
  2280    },
  2281    {
  2282      "comment": "union with invalid order by clause with table qualifier",
  2283      "query": "select id from user union select 3 order by user.id",
  2284      "v3-plan": "VT12001: unsupported: ORDER BY on top of UNION",
  2285      "gen4-plan": "Table `user` from one of the SELECTs cannot be used in global ORDER clause"
  2286    },
  2287    {
  2288      "comment": "union with invalid order by clause with table qualifier",
  2289      "query": "select id from user union select 3 order by id",
  2290      "plan": "VT12001: unsupported: ORDER BY on top of UNION"
  2291    },
  2292    {
  2293      "comment": "select 1 from (select id+42 as foo from user union select 1+id as foo from unsharded) as t",
  2294      "query": "select 1 from (select id+42 as foo from user union select 1+id as foo from unsharded) as t",
  2295      "v3-plan": "VT12001: unsupported: expression on results of a cross-shard subquery",
  2296      "gen4-plan": {
  2297        "QueryType": "SELECT",
  2298        "Original": "select 1 from (select id+42 as foo from user union select 1+id as foo from unsharded) as t",
  2299        "Instructions": {
  2300          "OperatorType": "SimpleProjection",
  2301          "Columns": [
  2302            2
  2303          ],
  2304          "Inputs": [
  2305            {
  2306              "OperatorType": "Distinct",
  2307              "Collations": [
  2308                "(0:1)"
  2309              ],
  2310              "Inputs": [
  2311                {
  2312                  "OperatorType": "Concatenate",
  2313                  "Inputs": [
  2314                    {
  2315                      "OperatorType": "Route",
  2316                      "Variant": "Scatter",
  2317                      "Keyspace": {
  2318                        "Name": "user",
  2319                        "Sharded": true
  2320                      },
  2321                      "FieldQuery": "select id + 42 as foo, weight_string(id + 42), 1 from `user` where 1 != 1",
  2322                      "Query": "select distinct id + 42 as foo, weight_string(id + 42), 1 from `user`",
  2323                      "Table": "`user`"
  2324                    },
  2325                    {
  2326                      "OperatorType": "Route",
  2327                      "Variant": "Unsharded",
  2328                      "Keyspace": {
  2329                        "Name": "main",
  2330                        "Sharded": false
  2331                      },
  2332                      "FieldQuery": "select 1 + id as foo, weight_string(1 + id), 1 from unsharded where 1 != 1",
  2333                      "Query": "select distinct 1 + id as foo, weight_string(1 + id), 1 from unsharded",
  2334                      "Table": "unsharded"
  2335                    }
  2336                  ]
  2337                }
  2338              ]
  2339            }
  2340          ]
  2341        },
  2342        "TablesUsed": [
  2343          "main.unsharded",
  2344          "user.user"
  2345        ]
  2346      }
  2347    },
  2348    {
  2349      "comment": "systable union query in derived table with constraint on outside (without star projection)",
  2350      "query": "select * from (select kcu.`COLUMN_NAME` from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'user_extra' union select kcu.`COLUMN_NAME` from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'music') `kcu` where `COLUMN_NAME` = 'primary'",
  2351      "v3-plan": "VT12001: unsupported: filtering on results of cross-shard subquery",
  2352      "gen4-plan": {
  2353        "QueryType": "SELECT",
  2354        "Original": "select * from (select kcu.`COLUMN_NAME` from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'user_extra' union select kcu.`COLUMN_NAME` from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'music') `kcu` where `COLUMN_NAME` = 'primary'",
  2355        "Instructions": {
  2356          "OperatorType": "Route",
  2357          "Variant": "DBA",
  2358          "Keyspace": {
  2359            "Name": "main",
  2360            "Sharded": false
  2361          },
  2362          "FieldQuery": "select kcu.COLUMN_NAME from (select kcu.COLUMN_NAME from information_schema.key_column_usage as kcu where 1 != 1 union select kcu.COLUMN_NAME from information_schema.key_column_usage as kcu where 1 != 1) as kcu where 1 != 1",
  2363          "Query": "select kcu.COLUMN_NAME from (select kcu.COLUMN_NAME from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname and kcu.table_name = :kcu_table_name and kcu.COLUMN_NAME = 'primary' union select kcu.COLUMN_NAME from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname and kcu.table_name = :kcu_table_name1 and kcu.COLUMN_NAME = 'primary') as kcu",
  2364          "SysTableTableName": "[kcu_table_name1:VARCHAR(\"music\"), kcu_table_name:VARCHAR(\"user_extra\")]",
  2365          "SysTableTableSchema": "[VARCHAR(\"user\"), VARCHAR(\"user\")]",
  2366          "Table": "information_schema.key_column_usage"
  2367        }
  2368      }
  2369    },
  2370    {
  2371      "comment": "pushes predicate on both sides of UNION",
  2372      "query": "select * from (select name, id as foo from user union select 'extra', user_id from user_extra) X where X.foo = 3",
  2373      "v3-plan": "VT12001: unsupported: filtering on results of cross-shard subquery",
  2374      "gen4-plan": {
  2375        "QueryType": "SELECT",
  2376        "Original": "select * from (select name, id as foo from user union select 'extra', user_id from user_extra) X where X.foo = 3",
  2377        "Instructions": {
  2378          "OperatorType": "Route",
  2379          "Variant": "EqualUnique",
  2380          "Keyspace": {
  2381            "Name": "user",
  2382            "Sharded": true
  2383          },
  2384          "FieldQuery": "select X.`name`, X.foo from (select `name`, id as foo from `user` where 1 != 1 union select 'extra', user_id from user_extra where 1 != 1) as X where 1 != 1",
  2385          "Query": "select X.`name`, X.foo from (select `name`, id as foo from `user` where id = 3 union select 'extra', user_id from user_extra where user_id = 3) as X",
  2386          "Table": "`user`",
  2387          "Values": [
  2388            "INT64(3)"
  2389          ],
  2390          "Vindex": "user_index"
  2391        },
  2392        "TablesUsed": [
  2393          "user.user",
  2394          "user.user_extra"
  2395        ]
  2396      }
  2397    },
  2398    {
  2399      "comment": "systable union query in derived table with constraint on outside (star projection)",
  2400      "query": "select * from (select * from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'user_extra' union select * from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'music') `kcu` where `constraint_name` = 'primary'",
  2401      "v3-plan": "VT03019: symbol constraint_name not found",
  2402      "gen4-plan": {
  2403        "QueryType": "SELECT",
  2404        "Original": "select * from (select * from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'user_extra' union select * from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'music') `kcu` where `constraint_name` = 'primary'",
  2405        "Instructions": {
  2406          "OperatorType": "Route",
  2407          "Variant": "DBA",
  2408          "Keyspace": {
  2409            "Name": "main",
  2410            "Sharded": false
  2411          },
  2412          "FieldQuery": "select kcu.CONSTRAINT_CATALOG, kcu.CONSTRAINT_SCHEMA, kcu.CONSTRAINT_NAME, kcu.TABLE_CATALOG, kcu.TABLE_SCHEMA, kcu.TABLE_NAME, kcu.COLUMN_NAME, kcu.ORDINAL_POSITION, kcu.POSITION_IN_UNIQUE_CONSTRAINT, kcu.REFERENCED_TABLE_SCHEMA, kcu.REFERENCED_TABLE_NAME, kcu.REFERENCED_COLUMN_NAME from (select kcu.CONSTRAINT_CATALOG, kcu.CONSTRAINT_SCHEMA, kcu.CONSTRAINT_NAME, kcu.TABLE_CATALOG, kcu.TABLE_SCHEMA, kcu.TABLE_NAME, kcu.COLUMN_NAME, kcu.ORDINAL_POSITION, kcu.POSITION_IN_UNIQUE_CONSTRAINT, kcu.REFERENCED_TABLE_SCHEMA, kcu.REFERENCED_TABLE_NAME, kcu.REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where 1 != 1 union select kcu.CONSTRAINT_CATALOG, kcu.CONSTRAINT_SCHEMA, kcu.CONSTRAINT_NAME, kcu.TABLE_CATALOG, kcu.TABLE_SCHEMA, kcu.TABLE_NAME, kcu.COLUMN_NAME, kcu.ORDINAL_POSITION, kcu.POSITION_IN_UNIQUE_CONSTRAINT, kcu.REFERENCED_TABLE_SCHEMA, kcu.REFERENCED_TABLE_NAME, kcu.REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where 1 != 1) as kcu where 1 != 1",
  2413          "Query": "select kcu.CONSTRAINT_CATALOG, kcu.CONSTRAINT_SCHEMA, kcu.CONSTRAINT_NAME, kcu.TABLE_CATALOG, kcu.TABLE_SCHEMA, kcu.TABLE_NAME, kcu.COLUMN_NAME, kcu.ORDINAL_POSITION, kcu.POSITION_IN_UNIQUE_CONSTRAINT, kcu.REFERENCED_TABLE_SCHEMA, kcu.REFERENCED_TABLE_NAME, kcu.REFERENCED_COLUMN_NAME from (select kcu.CONSTRAINT_CATALOG, kcu.CONSTRAINT_SCHEMA, kcu.CONSTRAINT_NAME, kcu.TABLE_CATALOG, kcu.TABLE_SCHEMA, kcu.TABLE_NAME, kcu.COLUMN_NAME, kcu.ORDINAL_POSITION, kcu.POSITION_IN_UNIQUE_CONSTRAINT, kcu.REFERENCED_TABLE_SCHEMA, kcu.REFERENCED_TABLE_NAME, kcu.REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname and kcu.table_name = :kcu_table_name and kcu.CONSTRAINT_NAME = 'primary' union select kcu.CONSTRAINT_CATALOG, kcu.CONSTRAINT_SCHEMA, kcu.CONSTRAINT_NAME, kcu.TABLE_CATALOG, kcu.TABLE_SCHEMA, kcu.TABLE_NAME, kcu.COLUMN_NAME, kcu.ORDINAL_POSITION, kcu.POSITION_IN_UNIQUE_CONSTRAINT, kcu.REFERENCED_TABLE_SCHEMA, kcu.REFERENCED_TABLE_NAME, kcu.REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname and kcu.table_name = :kcu_table_name1 and kcu.CONSTRAINT_NAME = 'primary') as kcu",
  2414          "SysTableTableName": "[kcu_table_name1:VARCHAR(\"music\"), kcu_table_name:VARCHAR(\"user_extra\")]",
  2415          "SysTableTableSchema": "[VARCHAR(\"user\"), VARCHAR(\"user\")]",
  2416          "Table": "information_schema.key_column_usage"
  2417        }
  2418      }
  2419    },
  2420    {
  2421      "comment": "unknown columns are OK as long as the whole query is unsharded",
  2422      "query": "(SELECT * FROM (SELECT * FROM unsharded WHERE branchId = 203622 AND buildNumber <= 113893 AND state = 'FAILED' ORDER BY buildNumber DESC LIMIT 1) AS last_failed) UNION ALL (SELECT * FROM (SELECT * FROM unsharded WHERE branchId = 203622 AND buildNumber <= 113893 AND state = 'SUCCEEDED' ORDER BY buildNumber DESC LIMIT 1) AS last_succeeded) ORDER BY buildNumber DESC LIMIT 1",
  2423      "v3-plan": {
  2424        "QueryType": "SELECT",
  2425        "Original": "(SELECT * FROM (SELECT * FROM unsharded WHERE branchId = 203622 AND buildNumber <= 113893 AND state = 'FAILED' ORDER BY buildNumber DESC LIMIT 1) AS last_failed) UNION ALL (SELECT * FROM (SELECT * FROM unsharded WHERE branchId = 203622 AND buildNumber <= 113893 AND state = 'SUCCEEDED' ORDER BY buildNumber DESC LIMIT 1) AS last_succeeded) ORDER BY buildNumber DESC LIMIT 1",
  2426        "Instructions": {
  2427          "OperatorType": "Route",
  2428          "Variant": "Unsharded",
  2429          "Keyspace": {
  2430            "Name": "main",
  2431            "Sharded": false
  2432          },
  2433          "FieldQuery": "select * from (select * from unsharded where 1 != 1) as last_failed where 1 != 1 union all select * from (select * from unsharded where 1 != 1) as last_succeeded where 1 != 1",
  2434          "Query": "select * from (select * from unsharded where branchId = 203622 and buildNumber <= 113893 and state = 'FAILED' order by buildNumber desc limit 1) as last_failed union all select * from (select * from unsharded where branchId = 203622 and buildNumber <= 113893 and state = 'SUCCEEDED' order by buildNumber desc limit 1) as last_succeeded order by buildNumber desc limit 1",
  2435          "Table": "unsharded"
  2436        }
  2437      },
  2438      "gen4-plan": {
  2439        "QueryType": "SELECT",
  2440        "Original": "(SELECT * FROM (SELECT * FROM unsharded WHERE branchId = 203622 AND buildNumber <= 113893 AND state = 'FAILED' ORDER BY buildNumber DESC LIMIT 1) AS last_failed) UNION ALL (SELECT * FROM (SELECT * FROM unsharded WHERE branchId = 203622 AND buildNumber <= 113893 AND state = 'SUCCEEDED' ORDER BY buildNumber DESC LIMIT 1) AS last_succeeded) ORDER BY buildNumber DESC LIMIT 1",
  2441        "Instructions": {
  2442          "OperatorType": "Route",
  2443          "Variant": "Unsharded",
  2444          "Keyspace": {
  2445            "Name": "main",
  2446            "Sharded": false
  2447          },
  2448          "FieldQuery": "select * from (select * from unsharded where 1 != 1) as last_failed where 1 != 1 union all select * from (select * from unsharded where 1 != 1) as last_succeeded where 1 != 1",
  2449          "Query": "select * from (select * from unsharded where branchId = 203622 and buildNumber <= 113893 and state = 'FAILED' order by buildNumber desc limit 1) as last_failed union all select * from (select * from unsharded where branchId = 203622 and buildNumber <= 113893 and state = 'SUCCEEDED' order by buildNumber desc limit 1) as last_succeeded order by buildNumber desc limit 1",
  2450          "Table": "unsharded"
  2451        },
  2452        "TablesUsed": [
  2453          "main.unsharded"
  2454        ]
  2455      }
  2456    },
  2457    {
  2458      "comment": "union of unsharded route with sharded join with involvement of weight string",
  2459      "query": "select id, foo, bar from unsharded union select user.intcol, user.textcol2, authoritative.col2 from user join authoritative",
  2460      "v3-plan": {
  2461        "QueryType": "SELECT",
  2462        "Original": "select id, foo, bar from unsharded union select user.intcol, user.textcol2, authoritative.col2 from user join authoritative",
  2463        "Instructions": {
  2464          "OperatorType": "Distinct",
  2465          "Inputs": [
  2466            {
  2467              "OperatorType": "Concatenate",
  2468              "Inputs": [
  2469                {
  2470                  "OperatorType": "Route",
  2471                  "Variant": "Unsharded",
  2472                  "Keyspace": {
  2473                    "Name": "main",
  2474                    "Sharded": false
  2475                  },
  2476                  "FieldQuery": "select id, foo, bar from unsharded where 1 != 1",
  2477                  "Query": "select id, foo, bar from unsharded",
  2478                  "Table": "unsharded"
  2479                },
  2480                {
  2481                  "OperatorType": "Join",
  2482                  "Variant": "Join",
  2483                  "JoinColumnIndexes": "L:0,L:1,R:0",
  2484                  "TableName": "`user`_authoritative",
  2485                  "Inputs": [
  2486                    {
  2487                      "OperatorType": "Route",
  2488                      "Variant": "Scatter",
  2489                      "Keyspace": {
  2490                        "Name": "user",
  2491                        "Sharded": true
  2492                      },
  2493                      "FieldQuery": "select `user`.intcol, `user`.textcol2 from `user` where 1 != 1",
  2494                      "Query": "select `user`.intcol, `user`.textcol2 from `user`",
  2495                      "Table": "`user`"
  2496                    },
  2497                    {
  2498                      "OperatorType": "Route",
  2499                      "Variant": "Scatter",
  2500                      "Keyspace": {
  2501                        "Name": "user",
  2502                        "Sharded": true
  2503                      },
  2504                      "FieldQuery": "select authoritative.col2 from authoritative where 1 != 1",
  2505                      "Query": "select authoritative.col2 from authoritative",
  2506                      "Table": "authoritative"
  2507                    }
  2508                  ]
  2509                }
  2510              ]
  2511            }
  2512          ]
  2513        }
  2514      },
  2515      "gen4-plan": {
  2516        "QueryType": "SELECT",
  2517        "Original": "select id, foo, bar from unsharded union select user.intcol, user.textcol2, authoritative.col2 from user join authoritative",
  2518        "Instructions": {
  2519          "OperatorType": "Distinct",
  2520          "Collations": [
  2521            "(0:3)",
  2522            "(1:4)",
  2523            "(2:5)"
  2524          ],
  2525          "ResultColumns": 3,
  2526          "Inputs": [
  2527            {
  2528              "OperatorType": "Concatenate",
  2529              "Inputs": [
  2530                {
  2531                  "OperatorType": "Route",
  2532                  "Variant": "Unsharded",
  2533                  "Keyspace": {
  2534                    "Name": "main",
  2535                    "Sharded": false
  2536                  },
  2537                  "FieldQuery": "select id, foo, bar, weight_string(id), weight_string(foo), weight_string(bar) from unsharded where 1 != 1",
  2538                  "Query": "select distinct id, foo, bar, weight_string(id), weight_string(foo), weight_string(bar) from unsharded",
  2539                  "Table": "unsharded"
  2540                },
  2541                {
  2542                  "OperatorType": "Join",
  2543                  "Variant": "Join",
  2544                  "JoinColumnIndexes": "L:0,L:1,R:0,L:2,L:3,R:1",
  2545                  "TableName": "`user`_authoritative",
  2546                  "Inputs": [
  2547                    {
  2548                      "OperatorType": "Route",
  2549                      "Variant": "Scatter",
  2550                      "Keyspace": {
  2551                        "Name": "user",
  2552                        "Sharded": true
  2553                      },
  2554                      "FieldQuery": "select `user`.intcol, `user`.textcol2, weight_string(`user`.intcol), weight_string(`user`.textcol2) from `user` where 1 != 1",
  2555                      "Query": "select `user`.intcol, `user`.textcol2, weight_string(`user`.intcol), weight_string(`user`.textcol2) from `user`",
  2556                      "Table": "`user`"
  2557                    },
  2558                    {
  2559                      "OperatorType": "Route",
  2560                      "Variant": "Scatter",
  2561                      "Keyspace": {
  2562                        "Name": "user",
  2563                        "Sharded": true
  2564                      },
  2565                      "FieldQuery": "select authoritative.col2, weight_string(authoritative.col2) from authoritative where 1 != 1",
  2566                      "Query": "select authoritative.col2, weight_string(authoritative.col2) from authoritative",
  2567                      "Table": "authoritative"
  2568                    }
  2569                  ]
  2570                }
  2571              ]
  2572            }
  2573          ]
  2574        },
  2575        "TablesUsed": [
  2576          "main.unsharded",
  2577          "user.authoritative",
  2578          "user.user"
  2579        ]
  2580      }
  2581    }
  2582  ]