14.6.12.3 Estimating ANALYZE TABLE Complexity for

ANALYZE TABLE complexity for InnoDB tables is dependent on:
InnoDB表的ANALYZE TABLE複雜度取決於:

  • The number of pages sampled, as defined by innodb_stats_persistent_sample_pages.
  • 抽樣的頁面數,由innodb_stats_persistent_sample_pages定義。
  • The number of indexed columns in a table
  • 表中索引列的數量
  • The number of partitions. If a table has no partitions, the number of partitions is considered to be 1.
  • 分區的數量。如果一個表沒有分區,那麼分區的數量被認爲是1。

Using these parameters, an approximate formula for estimating ANALYZE TABLE complexity would be:
利用這些參數,估計ANALYZE TABLE複雜度的近似公式爲:
The value of innodb_stats_persistent_sample_pages number of indexed columns in a table the number of partitions
innodb_stats_persistent_sample_pages的值表中索引列的數量分區的數量
Typically, the greater the resulting value, the greater the execution time for ANALYZE TABLE.
通常,結果值越大,ANALYZE TABLE.的執行時間就越長。
Note
innodb_stats_persistent_sample_pages defines the number of pages sampled at a global level. To set the number of pages sampled for an individual table, use the STATS_SAMPLE_PAGES option withCREATE TABLE or ALTER TABLE. For more information, see Section 14.6.12.1, “Configuring Persistent Optimizer Statistics Parameters”.
innodb_stats_persistent_sample_pages定義在全局級別採樣的頁數。要設置單個表的採樣頁數,請在CREATE TABLE或ALTER TABLE中使用STATS_SAMPLE_PAGES選項。更多信息,請看Section 14.6.12.1, “Configuring Persistent Optimizer Statistics Parameters”.
If innodb_stats_persistent=OFF, the number of pages sampled is defined by innodb_stats_transient_sample_pages. See Section 14.6.12.2, “Configuring Non-Persistent Optimizer Statistics Parameters” for additional information.
如果innodb_stats_persistent = OFF,則採樣的頁數由innodb_stats_transient_sample_pages定義。更多信息請看Section 14.6.12.2, “Configuring Non-Persistent Optimizer Statistics Parameters”

For a more in-depth approach to estimating ANALYZE TABLE complexity, consider the following example.
有關估計ANALYZE TABLE複雜性的更深入方法,請考慮以下示例。
In Big O notation, ANALYZE TABLE complexity is described as:
在Big O notation中,ANALYZE TABLE複雜度描述如下:
14.6.12.3 Estimating ANALYZE TABLE Complexity for
where:

  • n_sample is the number of pages sampled (defined by innodb_stats_persistent_sample_pages)
  • n_sample是抽樣的頁面數(由innodb_stats_persistent_sample_pages定義)
  • n_cols_in_uniq_i is total number of all columns in all unique indexes (not counting the primary key columns)
  • n_cols_in_uniq_i是所有唯一索引中的所有列的總數(不包括主鍵列)
  • n_cols_in_non_uniq_i is the total number of all columns in all nonunique indexes
  • n_cols_in_non_uniq_i是所有非唯一索引中的所有列的總數
  • n_cols_in_pk is the number of columns in the primary key (if a primary key is not defined, InnoDB creates a single column primary key internally)
    • n_cols_in_pk是主鍵中的列數(如果沒有定義主鍵,InnoDB在內部創建一個列主鍵)
  • n_non_uniq_i is the number of nonunique indexes in the table
  • n_non_uniq_i是表中非唯一索引的數量
  • n_part is the number of partitions. If no partitions are defined, the table is considered to be a single partition.
  • n_part是分區的數量。如果沒有定義分區,則將該表視爲單個分區

Now, consider the following table (table t), which has a primary key (2 columns), a unique index (2 columns), and two nonunique indexes (two columns each):
現在考慮下表(表t),它有主鍵(2列)、唯一索引(2列)和兩個非唯一索引(各2列):
CREATE TABLE t (
a INT,
b INT,
c INT,
d INT,
e INT,
f INT,
g INT,
h INT,
PRIMARY KEY (a, b),
UNIQUE KEY i1uniq (c, d),
KEY i2nonuniq (e, f),
KEY i3nonuniq (g, h)
);
For the column and index data required by the algorithm described above, query the mysql.innodb_index_stats persistent index statistics table for table t. The n_diff_pfx% statistics show the columns that are counted for each index. For example, columns a and b are counted for the primary key index. For the nonunique indexes, the primary key columns (a,b) are counted in addition to the user defined columns.
對於上述算法所需的列和索引數據,查詢表t的mysql.innodb_index_statspersistent索引統計信息表。n_diff_pfx%的統計數據顯示了爲每個索引計數的列。例如,主鍵索引將計算列a和b。對於非唯一索引,除了用戶定義的列之外,還將計算主鍵列(a、b)。
Note
For additional information about the InnoDB persistent statistics tables, see Section 14.6.12.1, “Configuring Persistent Optimizer Statistics Parameters”
有關InnoDB持久統計表的其他信息,請看Section 14.6.12.1, “Configuring Persistent Optimizer Statistics Parameters”
mysql> SELECT index_name, stat_name, stat_description
FROM mysql.innodb_index_stats WHERE
database_name='test' AND
table_name='t' AND
stat_name like 'n_diff_pfx%';
+------------+--------------+------------------+
| index_name | stat_name | stat_description |
+------------+--------------+------------------+
| PRIMARY | n_diff_pfx01 | a |
| PRIMARY | n_diff_pfx02 | a,b |
| i1uniq | n_diff_pfx01 | c |
| i1uniq | n_diff_pfx02 | c,d |
| i2nonuniq | n_diff_pfx01 | e |
| i2nonuniq | n_diff_pfx02 | e,f |
| i2nonuniq | n_diff_pfx03 | e,f,a |
| i2nonuniq | n_diff_pfx04 | e,f,a,b |
| i3nonuniq | n_diff_pfx01 | g |
| i3nonuniq | n_diff_pfx02 | g,h |
| i3nonuniq | n_diff_pfx03 | g,h,a |
| i3nonuniq | n_diff_pfx04 | g,h,a,b |
+------------+--------------+------------------+
Based on the index statistics data shown above and the table definition, the following values can be determined:
根據上面顯示的索引統計數據和表定義,可以確定以下值:

  • n_cols_in_uniq_i, the total number of all columns in all unique indexes not counting the primary key columns, is 2 (c and d)
    • n_cols_in_uniq_i,所有惟一索引中不包括主鍵列的所有列的總數爲2 (c和d)
  • n_cols_in_non_uniq_i, the total number of all columns in all nonunique indexes, is 4 (e, f, g and h)
  • n_cols_in_non_uniq_i,所有非唯一索引中所有列的總數爲4(e,f,g和h)
  • n_cols_in_pk, the number of columns in the primary key, is 2 (a and b)
  • n_cols_in_pk,主鍵中的列數爲2 (a和b)
  • n_non_uniq_i, the number of nonunique indexes in the table, is 2 (i2nonuniq and i3nonuniq))
  • n_non_uniq_i,表中非唯一索引的數目是2(i2nonuniq和i3nonuniq))
  • n_part, the number of partitions, is 1.
  • 分區數n_part爲1。

You can now calculate innodb_stats_persistent_sample_pages (2 + 4 + 2 (1 + 2)) 1 to determine the number of leaf pages that are scanned. With innodb_stats_persistent_sample_pages set to the default value of 20, and with a default page size of 16 KiB (innodb_page_size=16384), you can then estimate that 20 12 16384 bytes are read for table t, or about 4 MiB.
您現在可以計算innodb_stats_persistent_sample_pages
(2 + 4 + 2 (1 + 2)) 1,以確定要掃描的頁的數量。隨着innodb_stats_persistent_sample_pages設置爲默認值20,並且默認頁面大小爲16 KiB(innodb_page_size = 16384),則可以估計爲表t讀取了20 12 16384個字節,或者大約4 MiB。
Note
All 4 MiB may not be read from disk, as some leaf pages may already be cached in the buffer pool.
4 MiB的所有可能不會從磁盤讀取,因爲某些葉子頁可能已經緩存在緩衝池中。

PREV: 14.6.12.2 Configuring Non-Persistent Optimizer Statistics Parameters https://blog.51cto.com/itzhoujun/2359336
NEXT: 14.6.13 Configuring the Merge Threshold for Index https://blog.51cto.com/itzhoujun/2359339

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章