?????????MySQL?????????????????????ο?MySQL??????????MySQL??????????ò???????????????????????????

???????????????????

????MySQL?????????????????????????????й???SQL????????????????????????????£?

????1??DISTINCT????????????DISTINCT??????????primary key??unique key??DISTINCT????????????????DISTINCT????????????DISTINCT???????????????????

????2???????????????????ORDER BY ????GROUP BY??

????3??ORDER BY??GROUP BY??ò???????

????4????????????????

????5??ROLLUP?????

??????????????

????????????sql_select.cc:854????????JOIN::optimize()??λ???sql_select.cc:1399


/*
    Check if we need to create a temporary table.
    This has to be done if all tables are not already read (const tables)
    and one of the following conditions holds:
    - We are using DISTINCT (simple distinct's are already optimized away)
    - We are using an ORDER BY or GROUP BY on fields not in the first table
    - We are using different ORDER BY and GROUP BY orders
    - The user wants us to buffer the result.
    When the WITH ROLLUP modifier is present?? we cannot skip temporary table
    creation for the DISTINCT clause just because there are only const tables.
  */
  need_tmp= (( const_tables != tables &&
               (( select_distinct || !simple_order || !simple_group) ||
                ( group_list && order ) ||
                test(select_options & OPTION_BUFFER_RESULT))) ||
             ( rollup.state != ROLLUP:: STATE_NONE && select_distinct ));


??????????????????

?????????????????????????????????洢?????????????????

????1????????????С??????£????heap?洢??????д洢????????????д洢????????

????2??????????????????£????myisam?洢??????д洢??

????3??????????????С??????????????????£??????д?heap?洢????????myisam?洢????洢????????

????????????????????С??????????if??????????????????

????1????blob??ε??????

????2???????????????

????3????????????????????

????4??????????????С????????????

????5????????????????????myisam???????

??????????????

????????????sql_select.cc:10229????????create_tmp_table()??λ???sql_select.cc:10557