ORDER BY NULL in MySQL

后端 未结 5 567
独厮守ぢ
独厮守ぢ 2020-12-23 17:09

What is ORDER BY NULL in MySQL?

Does it decrease the query speed?

5条回答
  •  萌比男神i
    2020-12-23 17:26

    I am soory but i can see perfomance :

    mysql> SELECT *,COUNT(status) FROM big_table GROUP BY status;
    +----------------+----------------------------------+--------+---------------+
    | id             | hash                             | status | COUNT(status) |
    +----------------+----------------------------------+--------+---------------+
    | 14149924276950 | 20e2873f1026c867a1044681895130b8 |      0 |        268044 |
    | 14149924273884 | 889dc604799c563783396a3cb2c688a5 |      1 |        277474 |
    |  1414992427397 | 4e1769e2e64e737f37b918b834f8f696 |      2 |        279815 |
    | 14149924277490 | 539b71f083fc95a93d0d4b904a56ebb2 |      3 |        290216 |
    | 14149924274097 | ec694b8fc1786ea4f612dbe55d351715 |      4 |        272748 |
    | 14149924272735 | 64c3d1077c3ed3ee02398896376327aa |      5 |        280785 |
    | 14149924278670 | 05c143790ba4ecf73fc3be78d095c067 |      6 |        295417 |
    | 14149924271189 | 79bcafe38074703a49fb372c95e3676a |      7 |        310937 |
    | 14149924273279 | 29069b0fe511c160e95f98e2e2b770ac |      8 |        279338 |
    | 14149924277367 | 2e72091679aa6e3d64ed3c407ceeb6d4 |      9 |        281226 |
    +----------------+----------------------------------+--------+---------------+
    10 rows in set (44.43 sec)
    
    mysql> SELECT *,COUNT(status) FROM big_table GROUP BY status ORDER BY NULL;
    +----------------+----------------------------------+--------+---------------+
    | id             | hash                             | status | COUNT(status) |
    +----------------+----------------------------------+--------+---------------+
    | 14149924272735 | 64c3d1077c3ed3ee02398896376327aa |      5 |        280785 |
    | 14149924277367 | 2e72091679aa6e3d64ed3c407ceeb6d4 |      9 |        281226 |
    |  1414992427397 | 4e1769e2e64e737f37b918b834f8f696 |      2 |        279815 |
    | 14149924278670 | 05c143790ba4ecf73fc3be78d095c067 |      6 |        295417 |
    | 14149924274097 | ec694b8fc1786ea4f612dbe55d351715 |      4 |        272748 |
    | 14149924271189 | 79bcafe38074703a49fb372c95e3676a |      7 |        310937 |
    | 14149924276950 | 20e2873f1026c867a1044681895130b8 |      0 |        268044 |
    | 14149924273279 | 29069b0fe511c160e95f98e2e2b770ac |      8 |        279338 |
    | 14149924277490 | 539b71f083fc95a93d0d4b904a56ebb2 |      3 |        290216 |
    | 14149924273884 | 889dc604799c563783396a3cb2c688a5 |      1 |        277474 |
    +----------------+----------------------------------+--------+---------------+
    10 rows in set (44.13 sec)
    

提交回复
热议问题