Documentation Home
MySQL 5.6 リファレンスマニュアル
Download this Manual
EPUB - 7.5Mb
HTML Download (TGZ) - 7.2Mb
HTML Download (Zip) - 7.2Mb


8.4.2.4 PROCEDURE ANALYSE の使用

ANALYSE([max_elements[,max_memory]])

ANALYSE() はクエリーからの結果を調査し、テーブルサイズの削減に役立つ可能性がある各カラムの最適なデータ型を提案する結果の分析を返します。この分析を取得するには、SELECT ステートメントの末尾に PROCEDURE ANALYSE を追加します。

SELECT ... FROM ... WHERE ... PROCEDURE ANALYSE([max_elements,[max_memory]])

例:

SELECT col1, col2 FROM table1 PROCEDURE ANALYSE(10, 2000);

結果には、クエリーによって返された値のいくつかの統計が表示され、カラムの最適なデータ型が提案されます。これは、既存のテーブルのチェックや新しいデータのインポート後に役立つことがあります。ENUM データ型が適切でない場合に、PROCEDURE ANALYSE() がそれを提案しないように、引数の異なる設定を試してみる必要がある場合があります。

引数はオプションで次のように使用します。

  • max_elements (デフォルト 256) は、ANALYSE() がカラムあたりに認識する個々の値の最大数です。これは、ANALYSE() によって、最適なデータ型が型 ENUM であるかどうかをチェックするために使用されます。max_elements 個を超える個別の値がある場合、ENUM は提案される型ではありません。

  • max_memory (デフォルト 8192) は ANALYSE() がすべての個別の値を見つけようとする間に、カラムごとに割り当てるべき最大メモリー量です。


User Comments
  Posted by Wagner Bianchi on November 11, 2009
I did some tests using a table with 1000000 rows and this function PROCEDURE ANALYSE() returned all values in ENUM data type.

mysql> SELECT id, ativada, cumprida FROM t1 PROCEDURE ANALYSE(1000000,256)\G
  Posted by Gary Smith on November 13, 2009
I think you may be misunderstanding the syntax here. Let's say we've got a table called charac which has five characters in it:

mysql> select * from charac;
+--------+
| charac |
+--------+
| A |
| B |
| C |
| D |
| E |
+--------+
5 rows in set (0.00 sec)

If we select * from charac show procedure(), we're passing the default values, so we'll get everything back as enum:

mysql> select * from charac procedure analyse()\G
*************************** 1. row ***************************
Field_name: world.charac.charac
Min_value: A
Max_value: E
Min_length: 1
Max_length: 1
Empties_or_zeros: 0
Nulls: 0
Avg_value_or_avg_length: 1.0000
Std: NULL
Optimal_fieldtype: ENUM('A','B','C','D','E') NOT NULL
1 row in set (0.00 sec)

The first argument refers to the number of elements, and the next argument refers to the total memory assigned. So, if we do this:

mysql> select * from charac procedure analyse(5,24)\G
*************************** 1. row ***************************
Field_name: world.charac.charac
Min_value: A
Max_value: E
Min_length: 1
Max_length: 1
Empties_or_zeros: 0
Nulls: 0
Avg_value_or_avg_length: 1.0000
Std: NULL
Optimal_fieldtype: CHAR(1) NOT NULL

Then it's suggested CHAR(1) for the field which is perhaps more applicable. Hope this helps.
  Posted by Dimitriy A on March 24, 2010
Bug #44060: First option of PROCEDURE ANALYSE() does not work, second needs some work

[15 Apr 2009 5:13] Roel Van de Paar

< PARTIAL WORKAROUND >

In regards the issue with 'ENUM column recommendation output' for PROCEDURE ANALYSE, you
can still 'parly' use this function based on the second argument only.

For instance, if you would like to have a maximum of 50 characters (excluding 'NOT NULL')
for any ENUM column declaration, use the function as follows:

PROCEDURE ANALYSE(1,50);

The '1' will not do anything (as per the bug), and the '50' will define the maximum
numbers of characters for any ENUM (excluding the text 'NOT NULL', as per the bug).

If you do not want to use any ENUM columns at all (and for instance use a linked lookup
table with IDs instead), you can use:

PROCEDURE ANALYSE(1,1);

Having a linked lookup table, allows you the advantage of being able to add new values to
the lookup table later on, and then start inserting the new IDs into the main table
immediately (i.e. no ALTER of the ENUM column is required).
Sign Up Login You must be logged in to post a comment.