Distinct 优化

    聚合函数 DISTINCT

    1. mysql> desc select count(distinct a) from test.t;
    2. +-------------------------+----------+-----------+---------------+------------------------------------------+
    3. | id | estRows | task | access object | operator info |
    4. +-------------------------+----------+-----------+---------------+------------------------------------------+
    5. | StreamAgg_6 | 1.00 | root | | funcs:count(distinct test.t.a)->Column#4 |
    6. | └─TableFullScan_9 | 10000.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
    7. +-------------------------+----------+-----------+---------------+------------------------------------------+
    8. 3 rows in set (0.01 sec)
    9. mysql> set session tidb_opt_distinct_agg_push_down = 1;
    10. Query OK, 0 rows affected (0.00 sec)
    11. +---------------------------+----------+-----------+---------------+------------------------------------------+
    12. | id | estRows | task | access object | operator info |
    13. +---------------------------+----------+-----------+---------------+------------------------------------------+
    14. | HashAgg_8 | 1.00 | root | | funcs:count(distinct test.t.a)->Column#3 |
    15. | └─TableReader_9 | 1.00 | root | | data:HashAgg_5 |
    16. | └─HashAgg_5 | 1.00 | cop[tikv] | | group by:test.t.a, |
    17. | └─TableFullScan_7 | 10000.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
    18. 4 rows in set (0.00 sec)