[
  {
    "Name": "TestPKIsHandleRangeScan",
    "Cases": [
      {
        "SQL": "select b from t where a > 1",
        "Plan": [
          "Projection_8 3333.33 root  test.t.b",
          "└─TableReader_9 3333.33 root  data:TableRangeScan_10",
          "  └─TableRangeScan_10 3333.33 cop[tikv] table:t range:(1,+inf], keep order:false, stats:pseudo"
        ],
        "Result": [
          "4",
          "6"
        ]
      },
      {
        "SQL": "select b from t where a > 1 and a < 3",
        "Plan": [
          "Projection_8 2.00 root  test.t.b",
          "└─TableReader_9 2.00 root  data:TableRangeScan_10",
          "  └─TableRangeScan_10 2.00 cop[tikv] table:t range:(1,3), keep order:false, stats:pseudo"
        ],
        "Result": null
      },
      {
        "SQL": "select b from t where a > 1 and b < 6",
        "Plan": [
          "Projection_9 2666.67 root  test.t.b",
          "└─TableReader_10 2666.67 root  data:Selection_11",
          "  └─Selection_11 2666.67 cop[tikv]  lt(test.t.b, 6)",
          "    └─TableRangeScan_12 3333.33 cop[tikv] table:t range:(1,+inf], keep order:false, stats:pseudo"
        ],
        "Result": [
          "4"
        ]
      },
      {
        "SQL": "select a from t where a * 3 + 1 > 9 and a < 5",
        "Plan": [
          "TableReader_9 4.00 root  data:Selection_10",
          "└─Selection_10 4.00 cop[tikv]  gt(plus(mul(test.t.a, 3), 1), 9)",
          "  └─TableRangeScan_11 5.00 cop[tikv] table:t range:[-inf,5), keep order:false, stats:pseudo"
        ],
        "Result": [
          "3"
        ]
      },
      {
        "SQL": "select a from t group by a having sum(b) > 4",
        "Plan": [
          "Projection_13 8000.00 root  test.t.a",
          "└─TableReader_14 8000.00 root  data:Selection_15",
          "  └─Selection_15 8000.00 cop[tikv]  gt(cast(test.t.b, decimal(32,0) BINARY), 4)",
          "    └─TableFullScan_16 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "5"
        ]
      }
    ]
  },
  {
    "Name": "TestSort",
    "Cases": [
      {
        "SQL": "select a from t order by a",
        "Plan": [
          "TableReader_7 10000.00 root  data:TableFullScan_8",
          "└─TableFullScan_8 10000.00 cop[tikv] table:t keep order:true, stats:pseudo"
        ],
        "Result": [
          "1",
          "2",
          "3",
          "4"
        ]
      },
      {
        "SQL": "select b from t order by b",
        "Plan": [
          "Sort_11 10000.00 root  test.t.b",
          "└─TableReader_9 10000.00 root  data:TableFullScan_10",
          "  └─TableFullScan_10 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "11",
          "22",
          "33",
          "44"
        ]
      },
      {
        "SQL": "select b from t order by a+b",
        "Plan": [
          "Projection_7 10000.00 root  test.t.b",
          "└─Projection_12 10000.00 root  test.t.b, test.t.a",
          "  └─Sort_8 10000.00 root  Column#4",
          "    └─Projection_13 10000.00 root  test.t.b, test.t.a, plus(test.t.a, test.t.b)->Column#4",
          "      └─Projection_9 10000.00 root  test.t.b, test.t.a",
          "        └─TableReader_10 10000.00 root  data:TableFullScan_11",
          "          └─TableFullScan_11 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "11",
          "22",
          "33",
          "44"
        ]
      },
      {
        "SQL": "select b from t order by b, a+b, a",
        "Plan": [
          "Projection_7 10000.00 root  test.t.b",
          "└─Projection_12 10000.00 root  test.t.b, test.t.a",
          "  └─Sort_8 10000.00 root  test.t.b, Column#4, test.t.a",
          "    └─Projection_13 10000.00 root  test.t.b, test.t.a, plus(test.t.a, test.t.b)->Column#4",
          "      └─Projection_9 10000.00 root  test.t.b, test.t.a",
          "        └─TableReader_10 10000.00 root  data:TableFullScan_11",
          "          └─TableFullScan_11 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "11",
          "22",
          "33",
          "44"
        ]
      }
    ]
  },
  {
    "Name": "TestAggregation",
    "Cases": [
      {
        "SQL": "select sum(a) from t",
        "Plan": [
          "HashAgg_14 1.00 root  funcs:sum(Column#4)->Column#3",
          "└─TableReader_15 1.00 root  data:HashAgg_16",
          "  └─HashAgg_16 1.00 cop[tikv]  funcs:sum(test.t.a)->Column#4",
          "    └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "10"
        ]
      },
      {
        "SQL": "select max(a), min(b) from t",
        "Plan": [
          "HashAgg_11 1.00 root  funcs:max(Column#5)->Column#3, funcs:min(Column#6)->Column#4",
          "└─TableReader_12 1.00 root  data:HashAgg_13",
          "  └─HashAgg_13 1.00 cop[tikv]  funcs:max(test.t.a)->Column#5, funcs:min(test.t.b)->Column#6",
          "    └─TableFullScan_10 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "4 11"
        ]
      },
      {
        "SQL": "select b, avg(a) from t group by b order by b",
        "Plan": [
          "Projection_12 8000.00 root  test.t.b, Column#3",
          "└─Sort_21 8000.00 root  test.t.b",
          "  └─HashAgg_18 8000.00 root  group by:test.t.b, funcs:avg(Column#4, Column#5)->Column#3, funcs:firstrow(test.t.b)->test.t.b",
          "    └─TableReader_19 8000.00 root  data:HashAgg_20",
          "      └─HashAgg_20 8000.00 cop[tikv]  group by:test.t.b, funcs:count(test.t.a)->Column#4, funcs:sum(test.t.a)->Column#5",
          "        └─TableFullScan_17 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "11 1.0000",
          "22 2.0000",
          "33 3.0000",
          "44 4.0000"
        ]
      },
      {
        "SQL": "select b, sum(a) from t group by b order by b",
        "Plan": [
          "Projection_12 8000.00 root  test.t.b, Column#3",
          "└─Sort_21 8000.00 root  test.t.b",
          "  └─HashAgg_18 8000.00 root  group by:test.t.b, funcs:sum(Column#4)->Column#3, funcs:firstrow(test.t.b)->test.t.b",
          "    └─TableReader_19 8000.00 root  data:HashAgg_20",
          "      └─HashAgg_20 8000.00 cop[tikv]  group by:test.t.b, funcs:sum(test.t.a)->Column#4",
          "        └─TableFullScan_17 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "11 1",
          "22 2",
          "33 3",
          "44 4"
        ]
      },
      {
        "SQL": "select b, avg(a) from t group by b having sum(a) > 1 order by b",
        "Plan": [
          "Projection_14 6400.00 root  test.t.b, Column#3",
          "└─Projection_16 6400.00 root  test.t.b, Column#3, Column#4",
          "  └─Sort_29 6400.00 root  test.t.b",
          "    └─Selection_28 6400.00 root  gt(Column#4, 1)",
          "      └─HashAgg_19 8000.00 root  group by:test.t.b, funcs:avg(Column#11)->Column#3, funcs:sum(Column#12)->Column#4, funcs:firstrow(test.t.b)->test.t.b",
          "        └─Projection_20 10000.00 root  cast(test.t.a, decimal(10,0) BINARY)->Column#11, cast(test.t.a, decimal(10,0) BINARY)->Column#12, test.t.b, test.t.b",
          "          └─TableReader_21 10000.00 root  data:TableFullScan_22",
          "            └─TableFullScan_22 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "22 2.0000",
          "33 3.0000",
          "44 4.0000"
        ]
      },
      {
        "SQL": "select max(a+b) from t",
        "Plan": [
          "HashAgg_68 1.00 root  funcs:max(Column#4)->Column#3",
          "└─TableReader_69 1.00 root  data:HashAgg_70",
          "  └─HashAgg_70 1.00 cop[tikv]  funcs:max(plus(test.t.a, test.t.b))->Column#4",
          "    └─TableFullScan_41 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "48"
        ]
      },
      {
        "SQL": "select sum(a) from t group by a, a+b order by a",
        "Plan": [
          "Projection_10 10000.00 root  Column#3",
          "└─Projection_12 10000.00 root  cast(test.t.a, decimal(32,0) BINARY)->Column#3, test.t.a",
          "  └─TableReader_13 10000.00 root  data:TableFullScan_14",
          "    └─TableFullScan_14 10000.00 cop[tikv] table:t keep order:true, stats:pseudo"
        ],
        "Result": [
          "1",
          "2",
          "3",
          "4"
        ]
      },
      {
        "SQL": "select b, sum(a) from t group by b having b > 1 order by b",
        "Plan": [
          "Projection_16 6400.00 root  test.t.b, Column#3",
          "└─Sort_26 6400.00 root  test.t.b",
          "  └─HashAgg_23 6400.00 root  group by:test.t.b, funcs:sum(Column#4)->Column#3, funcs:firstrow(test.t.b)->test.t.b",
          "    └─TableReader_24 6400.00 root  data:HashAgg_25",
          "      └─HashAgg_25 6400.00 cop[tikv]  group by:test.t.b, funcs:sum(test.t.a)->Column#4",
          "        └─Selection_21 8000.00 cop[tikv]  gt(test.t.b, 1)",
          "          └─TableFullScan_22 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "11 1",
          "22 2",
          "33 3",
          "44 4"
        ]
      },
      {
        "SQL": "select c, sum(a) from (select a+b as c, a from t) t1 group by c having c > 1 order by c",
        "Plan": [
          "Projection_23 6400.00 root  Column#3, Column#4",
          "└─Sort_35 6400.00 root  Column#3",
          "  └─HashAgg_32 6400.00 root  group by:Column#7, funcs:sum(Column#8)->Column#4, funcs:firstrow(Column#7)->Column#3",
          "    └─TableReader_33 6400.00 root  data:HashAgg_34",
          "      └─HashAgg_34 6400.00 cop[tikv]  group by:plus(test.t.a, test.t.b), funcs:sum(test.t.a)->Column#8",
          "        └─Selection_28 8000.00 cop[tikv]  gt(plus(test.t.a, test.t.b), 1)",
          "          └─TableFullScan_29 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "12 1",
          "24 2",
          "36 3",
          "48 4"
        ]
      },
      {
        "SQL": "select max(a.a) from t a left join t b on a.a = b.a",
        "Plan": [
          "HashAgg_36 1.00 root  funcs:max(test.t.a)->Column#5",
          "└─Limit_38 1.00 root  offset:0, count:1",
          "  └─TableReader_43 1.00 root  data:Limit_44",
          "    └─Limit_44 1.00 cop[tikv]  offset:0, count:1",
          "      └─TableFullScan_42 1.00 cop[tikv] table:a keep order:true, desc, stats:pseudo"
        ],
        "Result": [
          "4"
        ]
      },
      {
        "SQL": "select avg(a.b) from t a left join t b on a.a = b.a",
        "Plan": [
          "HashAgg_17 1.00 root  funcs:avg(Column#6, Column#7)->Column#5",
          "└─TableReader_18 1.00 root  data:HashAgg_19",
          "  └─HashAgg_19 1.00 cop[tikv]  funcs:count(test.t.b)->Column#6, funcs:sum(test.t.b)->Column#7",
          "    └─TableFullScan_16 10000.00 cop[tikv] table:a keep order:false, stats:pseudo"
        ],
        "Result": [
          "27.5000"
        ]
      },
      {
        "SQL": "select t1.a, max(t1.b) from t as t1 left join (select * from t) as t2 on t1.a = t2.a and t1.b = 3 group by t1.a order by a",
        "Plan": [
          "Projection_15 10000.00 root  test.t.a, test.t.b",
          "└─TableReader_16 10000.00 root  data:TableFullScan_17",
          "  └─TableFullScan_17 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo"
        ],
        "Result": [
          "1 11",
          "2 22",
          "3 33",
          "4 44"
        ]
      },
      {
        "SQL": "select t1.a, sum(distinct t1.b) from t as t1 left join (select * from t) as t2 on t1.b = t2.b group by t1.a order by a",
        "Plan": [
          "Projection_15 10000.00 root  test.t.a, cast(test.t.b, decimal(32,0) BINARY)->Column#5",
          "└─TableReader_16 10000.00 root  data:TableFullScan_17",
          "  └─TableFullScan_17 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo"
        ],
        "Result": [
          "1 11",
          "2 22",
          "3 33",
          "4 44"
        ]
      },
      {
        "SQL": "select t2.a, max(t2.b) from t as t1 right join (select * from t) as t2 on t1.a = t2.a group by t2.a order by a",
        "Plan": [
          "Projection_15 10000.00 root  test.t.a, test.t.b",
          "└─TableReader_16 10000.00 root  data:TableFullScan_17",
          "  └─TableFullScan_17 10000.00 cop[tikv] table:t keep order:true, stats:pseudo"
        ],
        "Result": [
          "1 11",
          "2 22",
          "3 33",
          "4 44"
        ]
      },
      {
        "SQL": "select t3.a, max(t3.b) from (select t1.a, t1.b from t as t1 left join t as t2 on t1.b = t2.b) t3 group by t3.a order by a",
        "Plan": [
          "Projection_18 10000.00 root  test.t.a, test.t.b",
          "└─TableReader_19 10000.00 root  data:TableFullScan_20",
          "  └─TableFullScan_20 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo"
        ],
        "Result": [
          "1 11",
          "2 22",
          "3 33",
          "4 44"
        ]
      },
      {
        "SQL": "select max(a) from t",
        "Plan": [
          "HashAgg_21 1.00 root  funcs:max(test.t.a)->Column#3",
          "└─Limit_23 1.00 root  offset:0, count:1",
          "  └─TableReader_28 1.00 root  data:Limit_29",
          "    └─Limit_29 1.00 cop[tikv]  offset:0, count:1",
          "      └─TableFullScan_27 1.00 cop[tikv] table:t keep order:true, desc, stats:pseudo"
        ],
        "Result": [
          "4"
        ]
      },
      {
        "SQL": "select sum(case when a > 0 and a <= 1000 then b else 0 end) from t",
        "Plan": [
          "HashAgg_18 1.00 root  funcs:sum(Column#4)->Column#3",
          "└─TableReader_19 1.00 root  data:HashAgg_20",
          "  └─HashAgg_20 1.00 cop[tikv]  funcs:sum(test.t.b)->Column#4",
          "    └─TableRangeScan_17 250.00 cop[tikv] table:t range:(0,1000], keep order:false, stats:pseudo"
        ],
        "Result": [
          "110"
        ]
      },
      {
        "SQL": "select sum(case when a > 0 then (case when a <= 1000 then b end) else 0 end) from t",
        "Plan": [
          "HashAgg_21 1.00 root  funcs:sum(Column#4)->Column#3",
          "└─TableReader_22 1.00 root  data:HashAgg_23",
          "  └─HashAgg_23 1.00 cop[tikv]  funcs:sum(test.t.b)->Column#4",
          "    └─TableRangeScan_20 250.00 cop[tikv] table:t range:(0,1000], keep order:false, stats:pseudo"
        ],
        "Result": [
          "110"
        ]
      },
      {
        "SQL": "select sum(case when a <= 0 or a > 1000 then 0.0 else b end) from t",
        "Plan": [
          "HashAgg_18 1.00 root  funcs:sum(Column#4)->Column#3",
          "└─TableReader_19 1.00 root  data:HashAgg_20",
          "  └─HashAgg_20 1.00 cop[tikv]  funcs:sum(cast(test.t.b, decimal(10,0) BINARY))->Column#4",
          "    └─TableRangeScan_17 250.00 cop[tikv] table:t range:(0,1000], keep order:false, stats:pseudo"
        ],
        "Result": [
          "110.0"
        ]
      },
      {
        "SQL": "select count(case when a > 0 and a <= 1000 then b end) from t",
        "Plan": [
          "HashAgg_15 1.00 root  funcs:count(Column#4)->Column#3",
          "└─TableReader_16 1.00 root  data:HashAgg_17",
          "  └─HashAgg_17 1.00 cop[tikv]  funcs:count(test.t.b)->Column#4",
          "    └─TableRangeScan_14 250.00 cop[tikv] table:t range:(0,1000], keep order:false, stats:pseudo"
        ],
        "Result": [
          "4"
        ]
      },
      {
        "SQL": "select count(case when a <= 0 or a > 1000 then null else b end) from t",
        "Plan": [
          "HashAgg_15 1.00 root  funcs:count(Column#4)->Column#3",
          "└─TableReader_16 1.00 root  data:HashAgg_17",
          "  └─HashAgg_17 1.00 cop[tikv]  funcs:count(test.t.b)->Column#4",
          "    └─TableRangeScan_14 250.00 cop[tikv] table:t range:(0,1000], keep order:false, stats:pseudo"
        ],
        "Result": [
          "4"
        ]
      },
      {
        "SQL": "select count(distinct case when a > 0 and a <= 1000 then b end) from t",
        "Plan": [
          "HashAgg_10 1.00 root  funcs:count(distinct test.t.b)->Column#3",
          "└─TableReader_11 250.00 root  data:TableRangeScan_12",
          "  └─TableRangeScan_12 250.00 cop[tikv] table:t range:(0,1000], keep order:false, stats:pseudo"
        ],
        "Result": [
          "4"
        ]
      },
      {
        "SQL": "select approx_count_distinct(case when a > 0 and a <= 1000 then b end) from t",
        "Plan": [
          "HashAgg_10 1.00 root  funcs:approx_count_distinct(test.t.b)->Column#3",
          "└─TableReader_11 250.00 root  data:TableRangeScan_12",
          "  └─TableRangeScan_12 250.00 cop[tikv] table:t range:(0,1000], keep order:false, stats:pseudo"
        ],
        "Result": [
          "4"
        ]
      },
      {
        "SQL": "select count(b), sum(b), avg(b), b, max(b), min(b), bit_and(b), bit_or(b), bit_xor(b) from t group by a having sum(b) >= 0 and count(b) >= 0 order by b",
        "Plan": [
          "Projection_13 8000.00 root  Column#3, Column#4, Column#5, test.t.b, Column#6, Column#7, Column#8, Column#9, Column#10",
          "└─Projection_15 8000.00 root  if(isnull(test.t.b), 0, 1)->Column#3, cast(test.t.b, decimal(32,0) BINARY)->Column#4, cast(test.t.b, decimal(15,4) BINARY)->Column#5, test.t.b, test.t.b, test.t.b, ifnull(cast(test.t.b, bigint(21) UNSIGNED BINARY), 18446744073709551615)->Column#8, ifnull(cast(test.t.b, bigint(21) UNSIGNED BINARY), 0)->Column#9, ifnull(cast(test.t.b, bigint(21) UNSIGNED BINARY), 0)->Column#10, cast(test.t.b, decimal(32,0) BINARY)->Column#4, if(isnull(test.t.b), 0, 1)->Column#3",
          "  └─Sort_22 8000.00 root  test.t.b",
          "    └─TableReader_19 8000.00 root  data:Selection_20",
          "      └─Selection_20 8000.00 cop[tikv]  ge(cast(test.t.b, decimal(32,0) BINARY), 0), ge(if(isnull(test.t.b), 0, 1), 0)",
          "        └─TableFullScan_21 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "1 11 11.0000 11 11 11 11 11 11",
          "1 22 22.0000 22 22 22 22 22 22",
          "1 33 33.0000 33 33 33 33 33 33",
          "1 44 44.0000 44 44 44 44 44 44"
        ]
      },
      {
        "SQL": "select group_concat(a, b), min(b), avg(a / b), a from t group by (a+b), a order by a",
        "Plan": [
          "Sort_15 8000.00 root  test.t.a",
          "└─HashAgg_11 8000.00 root  group by:Column#9, test.t.a, funcs:group_concat(Column#6, Column#7 separator \",\")->Column#3, funcs:min(test.t.b)->Column#4, funcs:avg(Column#8)->Column#5, funcs:firstrow(test.t.a)->test.t.a",
          "  └─Projection_12 10000.00 root  cast(test.t.a, var_string(20))->Column#6, cast(test.t.b, var_string(20))->Column#7, test.t.b, div(cast(test.t.a, decimal(10,0) BINARY), cast(test.t.b, decimal(10,0) BINARY))->Column#8, test.t.a, plus(test.t.a, test.t.b)->Column#9, test.t.a",
          "    └─TableReader_13 10000.00 root  data:TableFullScan_14",
          "      └─TableFullScan_14 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "111 11 0.09090909 1",
          "222 22 0.09090909 2",
          "333 33 0.09090909 3",
          "444 44 0.09090909 4"
        ]
      },
      {
        "SQL": "select approx_percentile(a, 50) from t order by b",
        "Plan": [
          "Projection_8 1.00 root  Column#3",
          "└─Sort_14 1.00 root  test.t.b",
          "  └─HashAgg_11 1.00 root  funcs:approx_percentile(test.t.a, 50)->Column#3, funcs:firstrow(test.t.b)->test.t.b",
          "    └─TableReader_12 10000.00 root  data:TableFullScan_13",
          "      └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "2"
        ]
      }
    ]
  },
  {
    "Name": "TestPushdownDistinctEnable",
    "Cases": [
      {
        "SQL": "select /*+ HASH_AGG() */ avg(distinct a) from t;",
        "Plan": [
          "HashAgg_16 1.00 root  funcs:avg(distinct Column#7)->Column#5",
          "└─Projection_17 8000.00 root  cast(test.t.a, decimal(10,0) BINARY)->Column#7",
          "  └─TableReader_18 8000.00 root  data:HashAgg_19",
          "    └─HashAgg_19 8000.00 cop[tikv]  group by:test.t.a, ",
          "      └─TableFullScan_15 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "1.5000"
        ]
      },
      {
        "SQL": "select /*+ HASH_AGG() */ a, count(distinct a) from t;",
        "Plan": [
          "Projection_8 1.00 root  test.t.a, Column#5",
          "└─HashAgg_12 1.00 root  funcs:count(distinct test.t.a)->Column#5, funcs:firstrow(Column#6)->test.t.a",
          "  └─TableReader_13 8000.00 root  data:HashAgg_14",
          "    └─HashAgg_14 8000.00 cop[tikv]  group by:test.t.a, funcs:firstrow(test.t.a)->Column#6",
          "      └─TableFullScan_11 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "1 2"
        ]
      },
      {
        "SQL": "select /*+ HASH_AGG() */ avg(b), c, avg(b), count(distinct A, B),  count(distinct A), count(distinct c), sum(b) from t group by c;",
        "Plan": [
          "Projection_10 8000.00 root  Column#5, test.t.c, Column#5, Column#6, Column#7, Column#8, Column#9",
          "└─HashAgg_15 8000.00 root  group by:test.t.c, funcs:avg(Column#10, Column#11)->Column#5, funcs:count(distinct test.t.a, test.t.b)->Column#6, funcs:count(distinct test.t.a)->Column#7, funcs:count(distinct test.t.c)->Column#8, funcs:sum(Column#12)->Column#9, funcs:firstrow(test.t.c)->test.t.c",
          "  └─TableReader_16 8000.00 root  data:HashAgg_17",
          "    └─HashAgg_17 8000.00 cop[tikv]  group by:test.t.a, test.t.b, test.t.c, funcs:count(test.t.b)->Column#10, funcs:sum(test.t.b)->Column#11, funcs:sum(test.t.b)->Column#12",
          "      └─TableFullScan_14 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "1.0000 1 1.0000 1 1 1 1",
          "1.3333 3 1.3333 3 2 1 4",
          "2.0000 <nil> 2.0000 1 1 0 2"
        ]
      },
      {
        "SQL": "select /*+ STREAM_AGG() */ count(distinct c) from t group by c;",
        "Plan": [
          "HashAgg_17 8000.00 root  group by:test.t.c, funcs:count(distinct test.t.c)->Column#5",
          "└─IndexReader_18 8000.00 root  index:HashAgg_19",
          "  └─HashAgg_19 8000.00 cop[tikv]  group by:test.t.c, ",
          "    └─IndexFullScan_16 10000.00 cop[tikv] table:t, index:c(c) keep order:false, stats:pseudo"
        ],
        "Result": [
          "0",
          "1",
          "1"
        ]
      },
      {
        "SQL": "select /*+ STREAM_AGG() */ count(distinct c) from t;",
        "Plan": [
          "HashAgg_17 1.00 root  funcs:count(distinct test.t.c)->Column#5",
          "└─IndexReader_18 8000.00 root  index:HashAgg_19",
          "  └─HashAgg_19 8000.00 cop[tikv]  group by:test.t.c, ",
          "    └─IndexFullScan_16 10000.00 cop[tikv] table:t, index:c(c) keep order:false, stats:pseudo"
        ],
        "Result": [
          "2"
        ]
      },
      {
        "SQL": "select /*+ HASH_AGG() */ count(distinct c) from t;",
        "Plan": [
          "HashAgg_17 1.00 root  funcs:count(distinct test.t.c)->Column#5",
          "└─IndexReader_18 8000.00 root  index:HashAgg_19",
          "  └─HashAgg_19 8000.00 cop[tikv]  group by:test.t.c, ",
          "    └─IndexFullScan_16 10000.00 cop[tikv] table:t, index:c(c) keep order:false, stats:pseudo"
        ],
        "Result": [
          "2"
        ]
      },
      {
        "SQL": "select count(distinct c) from t group by c;",
        "Plan": [
          "HashAgg_17 8000.00 root  group by:test.t.c, funcs:count(distinct test.t.c)->Column#5",
          "└─IndexReader_18 8000.00 root  index:HashAgg_19",
          "  └─HashAgg_19 8000.00 cop[tikv]  group by:test.t.c, ",
          "    └─IndexFullScan_16 10000.00 cop[tikv] table:t, index:c(c) keep order:false, stats:pseudo"
        ],
        "Result": [
          "0",
          "1",
          "1"
        ]
      },
      {
        "SQL": "select count(distinct c) from t;",
        "Plan": [
          "HashAgg_17 1.00 root  funcs:count(distinct test.t.c)->Column#5",
          "└─IndexReader_18 8000.00 root  index:HashAgg_19",
          "  └─HashAgg_19 8000.00 cop[tikv]  group by:test.t.c, ",
          "    └─IndexFullScan_16 10000.00 cop[tikv] table:t, index:c(c) keep order:false, stats:pseudo"
        ],
        "Result": [
          "2"
        ]
      }
    ]
  },
  {
    "Name": "TestPushdownDistinctDisable",
    "Cases": [
      {
        "SQL": "select /*+ HASH_AGG(), AGG_TO_COP() */ avg(distinct a) from t;",
        "Plan": [
          "HashAgg_8 1.00 root  funcs:avg(distinct Column#6)->Column#5",
          "└─Projection_9 10000.00 root  cast(test.t.a, decimal(10,0) BINARY)->Column#6",
          "  └─TableReader_10 10000.00 root  data:TableFullScan_11",
          "    └─TableFullScan_11 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "1.5000"
        ]
      },
      {
        "SQL": "select /*+ HASH_AGG(), AGG_TO_COP() */ a, count(distinct a) from t;",
        "Plan": [
          "Projection_6 1.00 root  test.t.a, Column#5",
          "└─HashAgg_7 1.00 root  funcs:count(distinct test.t.a)->Column#5, funcs:firstrow(test.t.a)->test.t.a",
          "  └─TableReader_8 10000.00 root  data:TableFullScan_9",
          "    └─TableFullScan_9 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "1 2"
        ]
      },
      {
        "SQL": "select /*+ HASH_AGG(), AGG_TO_COP() */ avg(b), c, avg(b), count(distinct A, B),  count(distinct A), count(distinct c), sum(b) from t group by c;",
        "Plan": [
          "Projection_8 8000.00 root  Column#5, test.t.c, Column#5, Column#6, Column#7, Column#8, Column#9",
          "└─HashAgg_9 8000.00 root  group by:test.t.c, funcs:avg(Column#10)->Column#5, funcs:count(distinct test.t.a, test.t.b)->Column#6, funcs:count(distinct test.t.a)->Column#7, funcs:count(distinct test.t.c)->Column#8, funcs:sum(Column#11)->Column#9, funcs:firstrow(test.t.c)->test.t.c",
          "  └─Projection_10 10000.00 root  cast(test.t.b, decimal(10,0) BINARY)->Column#10, test.t.a, test.t.b, test.t.a, test.t.c, cast(test.t.b, decimal(10,0) BINARY)->Column#11, test.t.c, test.t.c",
          "    └─TableReader_11 10000.00 root  data:TableFullScan_12",
          "      └─TableFullScan_12 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "1.0000 1 1.0000 1 1 1 1",
          "1.3333 3 1.3333 3 2 1 4",
          "2.0000 <nil> 2.0000 1 1 0 2"
        ]
      },
      {
        "SQL": "select /*+ STREAM_AGG(), AGG_TO_COP() */ count(distinct c) from t group by c;",
        "Plan": [
          "HashAgg_8 8000.00 root  group by:test.t.c, funcs:count(distinct test.t.c)->Column#5",
          "└─IndexReader_11 10000.00 root  index:IndexFullScan_12",
          "  └─IndexFullScan_12 10000.00 cop[tikv] table:t, index:c(c) keep order:false, stats:pseudo"
        ],
        "Result": [
          "0",
          "1",
          "1"
        ]
      },
      {
        "SQL": "select /*+ STREAM_AGG(), AGG_TO_COP() */ count(distinct c) from t;",
        "Plan": [
          "HashAgg_8 1.00 root  funcs:count(distinct test.t.c)->Column#5",
          "└─IndexReader_11 10000.00 root  index:IndexFullScan_12",
          "  └─IndexFullScan_12 10000.00 cop[tikv] table:t, index:c(c) keep order:false, stats:pseudo"
        ],
        "Result": [
          "2"
        ]
      },
      {
        "SQL": "select /*+ HASH_AGG(), AGG_TO_COP() */ count(distinct c) from t;",
        "Plan": [
          "HashAgg_8 1.00 root  funcs:count(distinct test.t.c)->Column#5",
          "└─IndexReader_11 10000.00 root  index:IndexFullScan_12",
          "  └─IndexFullScan_12 10000.00 cop[tikv] table:t, index:c(c) keep order:false, stats:pseudo"
        ],
        "Result": [
          "2"
        ]
      },
      {
        "SQL": "select /*+ AGG_TO_COP() */ count(distinct c) from t group by c;",
        "Plan": [
          "HashAgg_8 8000.00 root  group by:test.t.c, funcs:count(distinct test.t.c)->Column#5",
          "└─IndexReader_11 10000.00 root  index:IndexFullScan_12",
          "  └─IndexFullScan_12 10000.00 cop[tikv] table:t, index:c(c) keep order:false, stats:pseudo"
        ],
        "Result": [
          "0",
          "1",
          "1"
        ]
      }
    ]
  },
  {
    "Name": "TestSimplePlans",
    "Cases": [
      {
        "SQL": "select a from t limit 2",
        "Plan": [
          "Limit_7 2.00 root  offset:0, count:2",
          "└─TableReader_8 2.00 root  data:Limit_9",
          "  └─Limit_9 2.00 cop[tikv]  offset:0, count:2",
          "    └─TableFullScan_10 2.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "1",
          "2"
        ]
      },
      {
        "SQL": "select a from t limit 1 offset 2",
        "Plan": [
          "Limit_7 1.00 root  offset:2, count:1",
          "└─TableReader_8 3.00 root  data:Limit_9",
          "  └─Limit_9 3.00 cop[tikv]  offset:0, count:3",
          "    └─TableFullScan_10 3.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "3"
        ]
      },
      {
        "SQL": "select b from t order by b limit 3",
        "Plan": [
          "TopN_9 3.00 root  test.t.b, offset:0, count:3",
          "└─TableReader_11 3.00 root  data:TopN_12",
          "  └─TopN_12 3.00 cop[tikv]  test.t.b, offset:0, count:3",
          "    └─TableFullScan_14 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "11",
          "22",
          "33"
        ]
      },
      {
        "SQL": "select a from t order by a limit 1 offset 2",
        "Plan": [
          "Limit_10 1.00 root  offset:2, count:1",
          "└─TableReader_16 3.00 root  data:Limit_17",
          "  └─Limit_17 3.00 cop[tikv]  offset:0, count:3",
          "    └─TableFullScan_15 3.00 cop[tikv] table:t keep order:true, stats:pseudo"
        ],
        "Result": [
          "3"
        ]
      },
      {
        "SQL": "select * from ((select a as aa from t t1) union all (select b as aa from t t2)) as t3 order by aa",
        "Plan": [
          "Sort_23 20000.00 root  Column#5",
          "└─Union_16 20000.00 root  ",
          "  ├─Projection_17 10000.00 root  test.t.a",
          "  │ └─TableReader_18 10000.00 root  data:TableFullScan_19",
          "  │   └─TableFullScan_19 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
          "  └─Projection_20 10000.00 root  test.t.b",
          "    └─TableReader_21 10000.00 root  data:TableFullScan_22",
          "      └─TableFullScan_22 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo"
        ],
        "Result": [
          "1",
          "2",
          "3",
          "4",
          "11",
          "22",
          "33",
          "44"
        ]
      },
      {
        "SQL": "select a, b, lag(a,1) over (order by b) from t order by b",
        "Plan": [
          "Window_10 10000.00 root  lag(test.t.a, 1)->Column#4 over(order by test.t.b)",
          "└─Sort_15 10000.00 root  test.t.b",
          "  └─TableReader_13 10000.00 root  data:TableFullScan_14",
          "    └─TableFullScan_14 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "1 11 <nil>",
          "2 22 1",
          "3 33 2",
          "4 44 3"
        ]
      },
      {
        "SQL": "select * from (select a+1 as c, a+b as d from t) as t1 order by c+d limit 10",
        "Plan": [
          "Projection_22 10.00 root  plus(test.t.a, 1)->Column#3, plus(test.t.a, test.t.b)->Column#4",
          "└─TopN_23 10.00 root  Column#5, offset:0, count:10",
          "  └─Projection_25 10.00 root  test.t.a, test.t.b, plus(plus(test.t.a, 1), plus(test.t.a, test.t.b))->Column#5",
          "    └─TableReader_26 10.00 root  data:TopN_27",
          "      └─TopN_27 10.00 cop[tikv]  plus(plus(test.t.a, 1), plus(test.t.a, test.t.b)), offset:0, count:10",
          "        └─TableFullScan_28 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "2 12",
          "3 24",
          "4 36",
          "5 48"
        ]
      },
      {
        "SQL": "select t1.a, t1.b from t as t1 left join t as t2 on t1.a = t2.a and t1.b = 3 order by a",
        "Plan": [
          "TableReader_26 12500.00 root  data:TableFullScan_27",
          "└─TableFullScan_27 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo"
        ],
        "Result": [
          "1 11",
          "2 22",
          "3 33",
          "4 44"
        ]
      }
    ]
  },
  {
    "Name": "TestIndexScan",
    "Cases": [
      {
        "SQL": "select b from t",
        "Plan": [
          "IndexReader_13 10000.00 root  index:IndexFullScan_14",
          "└─IndexFullScan_14 10000.00 cop[tikv] table:t, index:idx_b(b) keep order:false, stats:pseudo"
        ],
        "Result": [
          "2",
          "5",
          "8"
        ]
      },
      {
        "SQL": "select a from t order by b",
        "Plan": [
          "Projection_11 10000.00 root  test.t.a",
          "└─IndexReader_15 10000.00 root  index:IndexFullScan_16",
          "  └─IndexFullScan_16 10000.00 cop[tikv] table:t, index:idx_b(b) keep order:true, stats:pseudo"
        ],
        "Result": [
          "1",
          "4",
          "7"
        ]
      },
      {
        "SQL": "select c from t",
        "Plan": [
          "IndexReader_9 10000.00 root  index:IndexFullScan_10",
          "└─IndexFullScan_10 10000.00 cop[tikv] table:t, index:idx_c_b(c, b) keep order:false, stats:pseudo"
        ],
        "Result": [
          "3",
          "6",
          "9"
        ]
      },
      {
        "SQL": "select a from t order by c",
        "Plan": [
          "Projection_9 10000.00 root  test.t.a",
          "└─IndexReader_12 10000.00 root  index:IndexFullScan_13",
          "  └─IndexFullScan_13 10000.00 cop[tikv] table:t, index:idx_c_b(c, b) keep order:true, stats:pseudo"
        ],
        "Result": [
          "1",
          "4",
          "7"
        ]
      },
      {
        "SQL": "select a, b from t where b > 5 order by b",
        "Plan": [
          "IndexReader_18 8000.00 root  index:IndexRangeScan_19",
          "└─IndexRangeScan_19 3333.33 cop[tikv] table:t, index:idx_b(b) range:(5,+inf], keep order:true, stats:pseudo"
        ],
        "Result": [
          "7 8"
        ]
      },
      {
        "SQL": "select a, b, c from t where c = 3 and b > 1 order by b",
        "Plan": [
          "IndexReader_15 8000.00 root  index:IndexRangeScan_16",
          "└─IndexRangeScan_16 33.33 cop[tikv] table:t, index:idx_c_b(c, b) range:(3 1,3 +inf], keep order:true, stats:pseudo"
        ],
        "Result": [
          "1 2 3"
        ]
      },
      {
        "SQL": "select a, b from t where c > 1 and b > 1 order by c",
        "Plan": [
          "Projection_14 8000.00 root  test.t.a, test.t.b",
          "└─IndexReader_18 8000.00 root  index:Selection_19",
          "  └─Selection_19 2666.67 cop[tikv]  gt(test.t.b, 1)",
          "    └─IndexRangeScan_20 3333.33 cop[tikv] table:t, index:idx_c_b(c, b) range:(1,+inf], keep order:true, stats:pseudo"
        ],
        "Result": [
          "1 2",
          "4 5",
          "7 8"
        ]
      }
    ]
  },
  {
    "Name": "TestJoin",
    "Cases": [
      {
        "SQL": "select t1.a, t1.b from t1, t2 where t1.a = t2.a and t1.a > 2",
        "Plan": [
          "Projection 4166.67 root  test.t1.a, test.t1.b",
          "└─MergeJoin 4166.67 root  inner join, left key:test.t1.a, right key:test.t2.a",
          "  ├─TableReader(Build) 3333.33 root  data:TableRangeScan",
          "  │ └─TableRangeScan 3333.33 cop[tikv] table:t2 range:(2,+inf], keep order:true, stats:pseudo",
          "  └─TableReader(Probe) 3333.33 root  data:TableRangeScan",
          "    └─TableRangeScan 3333.33 cop[tikv] table:t1 range:(2,+inf], keep order:true, stats:pseudo"
        ],
        "Result": [
          "3 33"
        ]
      },
      {
        "SQL": "select t1.a, t1.b from t1, t2 where t1.a > t2.a and t2.b > 200",
        "Plan": [
          "Projection 80000000.00 root  test.t1.a, test.t1.b",
          "└─HashJoin 80000000.00 root  CARTESIAN inner join, other cond:gt(test.t1.a, test.t2.a)",
          "  ├─TableReader(Build) 8000.00 root  data:Selection",
          "  │ └─Selection 8000.00 cop[tikv]  gt(test.t2.b, 200)",
          "  │   └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo",
          "  └─TableReader(Probe) 10000.00 root  data:TableFullScan",
          "    └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo"
        ],
        "Result": [
          "3 33",
          "4 44",
          "4 44"
        ]
      },
      {
        "SQL": "select t1.a, t1.b from t1 left join t2 on t1.a = t2.a where t1.a > 2 and t2.b > 200",
        "Plan": [
          "Projection 3333.33 root  test.t1.a, test.t1.b",
          "└─Selection 3333.33 root  gt(test.t2.b, 200)",
          "  └─MergeJoin 4166.67 root  left outer join, left key:test.t1.a, right key:test.t2.a",
          "    ├─TableReader(Build) 3333.33 root  data:TableRangeScan",
          "    │ └─TableRangeScan 3333.33 cop[tikv] table:t2 range:(2,+inf], keep order:true, stats:pseudo",
          "    └─TableReader(Probe) 3333.33 root  data:TableRangeScan",
          "      └─TableRangeScan 3333.33 cop[tikv] table:t1 range:(2,+inf], keep order:true, stats:pseudo"
        ],
        "Result": [
          "3 33"
        ]
      },
      {
        "SQL": "select t2.a, t2.b from t1 right join t2 on t1.a = t2.a where t1.a > 2 and t2.b > 200",
        "Plan": [
          "Projection 8000.00 root  test.t2.a, test.t2.b",
          "└─Selection 8000.00 root  gt(test.t1.a, 2)",
          "  └─MergeJoin 10000.00 root  right outer join, left key:test.t1.a, right key:test.t2.a",
          "    ├─TableReader(Build) 10000.00 root  data:TableFullScan",
          "    │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo",
          "    └─TableReader(Probe) 8000.00 root  data:Selection",
          "      └─Selection 8000.00 cop[tikv]  gt(test.t2.b, 200)",
          "        └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo"
        ],
        "Result": [
          "3 333"
        ]
      },
      {
        "SQL": "select t1.a, t1.b from t1, t2 where t1.a = t2.a order by t1.a",
        "Plan": [
          "Projection 12500.00 root  test.t1.a, test.t1.b",
          "└─MergeJoin 12500.00 root  inner join, left key:test.t1.a, right key:test.t2.a",
          "  ├─TableReader(Build) 10000.00 root  data:TableFullScan",
          "  │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo",
          "  └─TableReader(Probe) 10000.00 root  data:TableFullScan",
          "    └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo"
        ],
        "Result": [
          "1 11",
          "2 22",
          "3 33"
        ]
      },
      {
        "SQL": "select * from t1 join t2 on t1.a = t2.a",
        "Plan": [
          "MergeJoin 12500.00 root  inner join, left key:test.t1.a, right key:test.t2.a",
          "├─TableReader(Build) 10000.00 root  data:TableFullScan",
          "│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo",
          "└─TableReader(Probe) 10000.00 root  data:TableFullScan",
          "  └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo"
        ],
        "Result": [
          "1 11 1 111",
          "2 22 2 222",
          "3 33 3 333"
        ]
      },
      {
        "SQL": "select * from t1 join t2 on t1.a = t2.a and t1.a > 2",
        "Plan": [
          "MergeJoin 4166.67 root  inner join, left key:test.t1.a, right key:test.t2.a",
          "├─TableReader(Build) 3333.33 root  data:TableRangeScan",
          "│ └─TableRangeScan 3333.33 cop[tikv] table:t2 range:(2,+inf], keep order:true, stats:pseudo",
          "└─TableReader(Probe) 3333.33 root  data:TableRangeScan",
          "  └─TableRangeScan 3333.33 cop[tikv] table:t1 range:(2,+inf], keep order:true, stats:pseudo"
        ],
        "Result": [
          "3 33 3 333"
        ]
      }
    ]
  },
  {
    "Name": "TestApply",
    "Cases": [
      {
        "SQL": "select a = (select a from t2 where t1.b = t2.b order by a limit 1) from t1",
        "Plan": [
          "Projection_19 10000.00 root  eq(test.t1.a, test.t2.a)->Column#7",
          "└─Apply_21 10000.00 root  CARTESIAN left outer join",
          "  ├─TableReader_22(Build) 10000.00 root  data:TableFullScan_23",
          "  │ └─TableFullScan_23 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
          "  └─MaxOneRow_24(Probe) 1.00 root  ",
          "    └─Projection_25 1.00 root  test.t2.a",
          "      └─Limit_27 1.00 root  offset:0, count:1",
          "        └─TableReader_35 1.00 root  data:Limit_36",
          "          └─Limit_36 1.00 cop[tikv]  offset:0, count:1",
          "            └─Selection_33 1.00 cop[tikv]  eq(test.t1.b, test.t2.b)",
          "              └─TableFullScan_34 1.00 cop[tikv] table:t2 keep order:true, stats:pseudo"
        ],
        "Result": [
          "1",
          "1",
          "1",
          "<nil>"
        ]
      },
      {
        "SQL": "select sum(a), (select t1.a from t1 where t1.a = t2.a limit 1), (select t1.b from t1 where t1.b = t2.b limit 1) from t2",
        "Plan": [
          "Projection_32 1.00 root  Column#7, test.t1.a, test.t1.b",
          "└─Apply_34 1.00 root  CARTESIAN left outer join",
          "  ├─Apply_36(Build) 1.00 root  CARTESIAN left outer join",
          "  │ ├─HashAgg_41(Build) 1.00 root  funcs:sum(Column#12)->Column#7, funcs:firstrow(Column#13)->test.t2.a, funcs:firstrow(Column#14)->test.t2.b",
          "  │ │ └─TableReader_42 1.00 root  data:HashAgg_43",
          "  │ │   └─HashAgg_43 1.00 cop[tikv]  funcs:sum(test.t2.a)->Column#12, funcs:firstrow(test.t2.a)->Column#13, funcs:firstrow(test.t2.b)->Column#14",
          "  │ │     └─TableFullScan_40 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo",
          "  │ └─MaxOneRow_44(Probe) 1.00 root  ",
          "  │   └─Limit_45 1.00 root  offset:0, count:1",
          "  │     └─TableReader_46 1.00 root  data:Limit_47",
          "  │       └─Limit_47 1.00 cop[tikv]  offset:0, count:1",
          "  │         └─Selection_48 1.00 cop[tikv]  eq(test.t1.a, test.t2.a)",
          "  │           └─TableFullScan_49 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
          "  └─MaxOneRow_50(Probe) 1.00 root  ",
          "    └─Limit_51 1.00 root  offset:0, count:1",
          "      └─TableReader_52 1.00 root  data:Limit_53",
          "        └─Limit_53 1.00 cop[tikv]  offset:0, count:1",
          "          └─Selection_54 1.00 cop[tikv]  eq(test.t1.b, test.t2.b)",
          "            └─TableFullScan_55 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo"
        ],
        "Result": [
          "6 1 11"
        ]
      },
      {
        "SQL": "select a from t1 where exists(select 1 from t2 where t1.a = t2.a)",
        "Plan": [
          "MergeJoin_30 10000.00 root  semi join, left key:test.t1.a, right key:test.t2.a",
          "├─TableReader_35(Build) 10000.00 root  data:TableFullScan_36",
          "│ └─TableFullScan_36 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo",
          "└─TableReader_32(Probe) 10000.00 root  data:TableFullScan_33",
          "  └─TableFullScan_33 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo"
        ],
        "Result": [
          "1",
          "2",
          "3"
        ]
      }
    ]
  },
  {
    "Name": "TestMemTableScan",
    "Cases": [
      {
        "SQL": "select USER, HOST, DB, COMMAND, TIME, STATE, INFO, `DIGEST` from information_schema.processlist",
        "Plan": [
          "Projection_3 10000.00 root  Column#2, Column#3, Column#4, Column#5, Column#6, Column#7, Column#8, Column#9",
          "└─MemTableScan_4 10000.00 root table:PROCESSLIST "
        ],
        "Result": ["  test Sleep 0 autocommit select USER, HOST, DB, COMMAND, TIME, STATE, INFO, `DIGEST` from information_schema.processlist 7284ef6cf62f14bccb9fa24aff861b419e9cf59b2c098d3069c7c10bc35d0c14"]
      }
    ]
  },
  {
    "Name": "TestTopN",
    "Cases": [
      {
        "SQL": "select a from (select a from t where b > 2 order by a limit 3 offset 1) as t1 order by a limit 2 offset 1",
        "Plan": [
          "Projection_22 2.00 root  test.t.a",
          "└─Limit_24 2.00 root  offset:2, count:2",
          "  └─TableReader_32 4.00 root  data:Limit_33",
          "    └─Limit_33 4.00 cop[tikv]  offset:0, count:4",
          "      └─Selection_30 4.00 cop[tikv]  gt(test.t.b, 2)",
          "        └─TableFullScan_31 4.00 cop[tikv] table:t keep order:true, stats:pseudo"
        ],
        "Result": [
          "3",
          "4"
        ]
      },
      {
        "SQL": "select * from (select * from t order by a limit 3) as t1 order by a limit 5",
        "Plan": [
          "Limit_15 3.00 root  offset:0, count:3",
          "└─TableReader_21 3.00 root  data:Limit_22",
          "  └─Limit_22 3.00 cop[tikv]  offset:0, count:3",
          "    └─TableFullScan_20 3.00 cop[tikv] table:t keep order:true, stats:pseudo"
        ],
        "Result": [
          "1 11",
          "2 22",
          "3 33"
        ]
      },
      {
        "SQL": "select b from (select b from t order by b limit 10 offset 10) as t1 order by b limit 10 offset 5",
        "Plan": [
          "TopN_14 5.00 root  test.t.b, offset:15, count:5",
          "└─TableReader_16 20.00 root  data:TopN_17",
          "  └─TopN_17 20.00 cop[tikv]  test.t.b, offset:0, count:20",
          "    └─TableFullScan_19 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": null
      },
      {
        "SQL": "select b from (select b from t order by b limit 10 offset 2) as t1 order by b limit 3 offset 5",
        "Plan": [
          "TopN_14 3.00 root  test.t.b, offset:7, count:3",
          "└─TableReader_16 10.00 root  data:TopN_17",
          "  └─TopN_17 10.00 cop[tikv]  test.t.b, offset:0, count:10",
          "    └─TableFullScan_19 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": null
      },
      {
        "SQL": "select a from (select a from t order by a limit 3 offset 5) as t1 order by a limit 3 offset 5",
        "Plan": [
          "TableDual_11 0.00 root  rows:0"
        ],
        "Result": null
      },
      {
        "SQL": "select a from (select a from t where b > 2 order by a, b limit 3 offset 1) as t1 order by a limit 2 offset 1",
        "Plan": [
          "Projection_22 2.00 root  test.t.a",
          "└─TopN_23 2.00 root  test.t.a, test.t.b, offset:2, count:2",
          "  └─TableReader_25 4.00 root  data:TopN_26",
          "    └─TopN_26 4.00 cop[tikv]  test.t.a, test.t.b, offset:0, count:4",
          "      └─Selection_28 8000.00 cop[tikv]  gt(test.t.b, 2)",
          "        └─TableFullScan_29 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
        ],
        "Result": [
          "3",
          "4"
        ]
      },
      {
        "SQL": "select * from (select * from t order by a limit 3) as t1 order by a, b limit 5",
        "Plan": [
          "Limit_14 3.00 root  offset:0, count:5",
          "└─Sort_26 3.00 root  test.t.a, test.t.b",
          "  └─Limit_16 3.00 root  offset:0, count:3",
          "    └─TableReader_22 3.00 root  data:Limit_23",
          "      └─Limit_23 3.00 cop[tikv]  offset:0, count:3",
          "        └─TableFullScan_21 3.00 cop[tikv] table:t keep order:true, stats:pseudo"
        ],
        "Result": [
          "1 11",
          "2 22",
          "3 33"
        ]
      }
    ]
  },
  {
    "Name": "TestCascadePlannerHashedPartTable",
    "Cases": [
      {
        "SQL": "select * from pt1 order by a",
        "Plan": [
          "Sort_11 10000.00 root  test.pt1.a",
          "└─TableReader_9 10000.00 root partition:all data:TableFullScan_10",
          "  └─TableFullScan_10 10000.00 cop[tikv] table:pt1 keep order:false, stats:pseudo"
        ],
        "Result": [
          "1 10",
          "2 20",
          "3 30",
          "4 40",
          "5 50"
        ]
      }
    ]
  },
  {
    "Name": "TestInlineProjection",
    "Cases": [
      {
        "SQL": "select /*+ HASH_JOIN(t1) */ t1.b, t2.b from t1, t2 where t1.a = t2.a;",
        "Plan": [
          "Projection 10000.00 root  test.t1.b, test.t2.b",
          "└─HashJoin 10000.00 root  inner join, equal:[eq(test.t1.a, test.t2.a)]",
          "  ├─TableReader(Build) 8000.00 root  data:Selection",
          "  │ └─Selection 8000.00 cop[tikv]  not(isnull(test.t1.a)), not(isnull(test.t1.a))",
          "  │   └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
          "  └─TableReader(Probe) 8000.00 root  data:Selection",
          "    └─Selection 8000.00 cop[tikv]  not(isnull(test.t2.a)), not(isnull(test.t2.a))",
          "      └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo"
        ],
        "Result": [
          "1 1"
        ]
      },
      {
        "SQL": "select /*+ HASH_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;",
        "Plan": [
          "Projection 10000.00 root  test.t1.b, test.t2.b",
          "└─HashJoin 10000.00 root  inner join, equal:[eq(test.t1.a, test.t2.a)]",
          "  ├─TableReader(Build) 8000.00 root  data:Selection",
          "  │ └─Selection 8000.00 cop[tikv]  not(isnull(test.t1.a)), not(isnull(test.t1.a))",
          "  │   └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
          "  └─TableReader(Probe) 8000.00 root  data:Selection",
          "    └─Selection 8000.00 cop[tikv]  not(isnull(test.t2.a)), not(isnull(test.t2.a))",
          "      └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo"
        ],
        "Result": [
          "1 1"
        ]
      },
      {
        "SQL": "select /*+ HASH_JOIN(t1) */ t1.b, t2.b from t1 left outer join t2 on t1.a = t2.a;",
        "Plan": [
          "HashJoin 10000.00 root  left outer join, equal:[eq(test.t1.a, test.t2.a)]",
          "├─TableReader(Build) 8000.00 root  data:Selection",
          "│ └─Selection 8000.00 cop[tikv]  not(isnull(test.t2.a)), not(isnull(test.t2.a))",
          "│   └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo",
          "└─TableReader(Probe) 10000.00 root  data:TableFullScan",
          "  └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo"
        ],
        "Result": [
          "1 1",
          "2 <nil>"
        ]
      },
      {
        "SQL": "select /*+ HASH_JOIN(t1) */ t1.b, t2.b from t1 right outer join t2 on t1.a = t2.a;",
        "Plan": [
          "HashJoin 10000.00 root  right outer join, equal:[eq(test.t1.a, test.t2.a)]",
          "├─TableReader(Build) 8000.00 root  data:Selection",
          "│ └─Selection 8000.00 cop[tikv]  not(isnull(test.t1.a)), not(isnull(test.t1.a))",
          "│   └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
          "└─TableReader(Probe) 10000.00 root  data:TableFullScan",
          "  └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo"
        ],
        "Result": [
          "1 1",
          "<nil> 3"
        ]
      },
      {
        "SQL": "select 1 from (select /*+ HASH_JOIN(t1) */ t1.a in (select t2.a from t2) from t1) x;",
        "Plan": [
          "Projection 10000.00 root  1->Column#11",
          "└─HashJoin 10000.00 root  CARTESIAN left outer semi join, other cond:eq(test.t1.a, test.t2.a)",
          "  ├─IndexReader(Build) 10000.00 root  index:IndexFullScan",
          "  │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:idx_a(a) keep order:false, stats:pseudo",
          "  └─IndexReader(Probe) 10000.00 root  index:IndexFullScan",
          "    └─IndexFullScan 10000.00 cop[tikv] table:t1, index:idx_a(a) keep order:false, stats:pseudo"
        ],
        "Result": [
          "1",
          "1"
        ]
      },
      {
        "SQL": "select 1 from (select /*+ HASH_JOIN(t1) */ t1.a not in (select t2.a from t2) from t1) x;",
        "Plan": [
          "Projection 10000.00 root  1->Column#11",
          "└─HashJoin 10000.00 root  CARTESIAN anti left outer semi join, other cond:eq(test.t1.a, test.t2.a)",
          "  ├─IndexReader(Build) 10000.00 root  index:IndexFullScan",
          "  │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:idx_a(a) keep order:false, stats:pseudo",
          "  └─IndexReader(Probe) 10000.00 root  index:IndexFullScan",
          "    └─IndexFullScan 10000.00 cop[tikv] table:t1, index:idx_a(a) keep order:false, stats:pseudo"
        ],
        "Result": [
          "1",
          "1"
        ]
      },
      {
        "SQL": "select /*+ INL_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;",
        "Plan": [
          "Projection 10000.00 root  test.t1.b, test.t2.b",
          "└─HashJoin 10000.00 root  inner join, equal:[eq(test.t1.a, test.t2.a)]",
          "  ├─TableReader(Build) 8000.00 root  data:Selection",
          "  │ └─Selection 8000.00 cop[tikv]  not(isnull(test.t1.a)), not(isnull(test.t1.a))",
          "  │   └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
          "  └─TableReader(Probe) 8000.00 root  data:Selection",
          "    └─Selection 8000.00 cop[tikv]  not(isnull(test.t2.a)), not(isnull(test.t2.a))",
          "      └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo"
        ],
        "Result": [
          "1 1"
        ]
      },
      {
        "SQL": "select /*+ INL_HASH_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;",
        "Plan": [
          "Projection 10000.00 root  test.t1.b, test.t2.b",
          "└─HashJoin 10000.00 root  inner join, equal:[eq(test.t1.a, test.t2.a)]",
          "  ├─TableReader(Build) 8000.00 root  data:Selection",
          "  │ └─Selection 8000.00 cop[tikv]  not(isnull(test.t1.a)), not(isnull(test.t1.a))",
          "  │   └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
          "  └─TableReader(Probe) 8000.00 root  data:Selection",
          "    └─Selection 8000.00 cop[tikv]  not(isnull(test.t2.a)), not(isnull(test.t2.a))",
          "      └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo"
        ],
        "Result": [
          "1 1"
        ]
      },
      {
        "SQL": "select /*+ INL_MERGE_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;",
        "Plan": [
          "Projection 10000.00 root  test.t1.b, test.t2.b",
          "└─HashJoin 10000.00 root  inner join, equal:[eq(test.t1.a, test.t2.a)]",
          "  ├─TableReader(Build) 8000.00 root  data:Selection",
          "  │ └─Selection 8000.00 cop[tikv]  not(isnull(test.t1.a)), not(isnull(test.t1.a))",
          "  │   └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
          "  └─TableReader(Probe) 8000.00 root  data:Selection",
          "    └─Selection 8000.00 cop[tikv]  not(isnull(test.t2.a)), not(isnull(test.t2.a))",
          "      └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo"
        ],
        "Result": [
          "1 1"
        ]
      },
      {
        "SQL": "select /*+ MERGE_JOIN(t1, t2) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;",
        "Plan": [
          "Projection 10000.00 root  test.t1.b, test.t2.b",
          "└─HashJoin 10000.00 root  inner join, equal:[eq(test.t1.a, test.t2.a)]",
          "  ├─TableReader(Build) 8000.00 root  data:Selection",
          "  │ └─Selection 8000.00 cop[tikv]  not(isnull(test.t1.a)), not(isnull(test.t1.a))",
          "  │   └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
          "  └─TableReader(Probe) 8000.00 root  data:Selection",
          "    └─Selection 8000.00 cop[tikv]  not(isnull(test.t2.a)), not(isnull(test.t2.a))",
          "      └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo"
        ],
        "Result": [
          "1 1"
        ]
      }
    ]
  }
]
