亚欧洲精品在线观看,窝窝影院午夜看片,久久国产成人午夜av影院宅,午夜91,免费国产人成网站,ts在线视频,欧美激情在线一区

Linux認(rèn)證

Linux數(shù)據(jù)庫(kù)MySQL內(nèi)部臨時(shí)表策略

時(shí)間:2024-10-08 08:21:44 Linux認(rèn)證 我要投稿
  • 相關(guān)推薦

Linux數(shù)據(jù)庫(kù)MySQL內(nèi)部臨時(shí)表策略

  MySQL內(nèi)部臨時(shí)表的使用有一定的策略,從源碼中關(guān)于SQL查詢是否需要內(nèi)部臨時(shí)表?梢钥偨Y(jié)如下:

  1、DISTINCT查詢,但是簡(jiǎn)單的DISTINCT查詢,比如對(duì)primary key、unique key等DISTINCT查詢時(shí),查詢優(yōu)化器會(huì)將DISTINCT條件優(yōu)化,去除DISTINCT條件,也不會(huì)創(chuàng)建臨時(shí)表;

  2、不是第一個(gè)表的字段使用ORDER BY 或者GROUP BY;

  3、ORDER BY和GROUP BY使用不同的順序;

  4、用戶需要緩存結(jié)果;

  5、ROLLUP查詢。

  源碼如下所示

  代碼地址:sql_select.cc:854, 函數(shù):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 distincts 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 ));

  內(nèi)部臨時(shí)表使用原則

  但是使用了內(nèi)部臨時(shí)表,那么他是怎么存儲(chǔ)的呢?原則是這樣的:

  1、當(dāng)查詢結(jié)果較小的情況下,使用heap存儲(chǔ)引擎進(jìn)行存儲(chǔ)。也就是說(shuō)在內(nèi)存中存儲(chǔ)查詢結(jié)果。

  2、當(dāng)查詢結(jié)果較大的情況下,使用myisam存儲(chǔ)引擎進(jìn)行存儲(chǔ)。

  3、當(dāng)查詢結(jié)果最初較小,但是不斷增大的情況下,將會(huì)有從heap存儲(chǔ)引擎轉(zhuǎn)化為myisam存儲(chǔ)引擎存儲(chǔ)查詢結(jié)果。

  什么情況算是查詢結(jié)果較小呢?從源碼中if的幾個(gè)參數(shù)可以看出:

  1、有blob字段的情況;

  2、使用唯一限制的情況;

  3、當(dāng)前表定義為大表的情況;

  4、查詢結(jié)果的選項(xiàng)為小結(jié)果集的情況;

  5、查詢結(jié)果的選項(xiàng)為強(qiáng)制使用myisam的情況。

【Linux數(shù)據(jù)庫(kù)MySQL內(nèi)部臨時(shí)表策略】相關(guān)文章:

Linux數(shù)據(jù)庫(kù):關(guān)鍵的MySQL性能優(yōu)化技巧09-08

2016年Linux認(rèn)證基礎(chǔ)知識(shí):mysql數(shù)據(jù)庫(kù)的全量備份10-04

Oracle數(shù)據(jù)庫(kù)臨時(shí)表管理技巧09-15

酒店內(nèi)部營(yíng)銷管理策略07-14

關(guān)于Oracle臨時(shí)表用法06-24

2017年計(jì)算機(jī)二級(jí)mysql數(shù)據(jù)庫(kù)模擬試題09-22

數(shù)據(jù)庫(kù)系統(tǒng)的內(nèi)部結(jié)構(gòu)體系簡(jiǎn)介10-09

企業(yè)內(nèi)部物流管理策略08-05

外部表在Oracle數(shù)據(jù)庫(kù)中使用的限制08-26

PHP常用MySql操作介紹10-09