ANALYZE collects statistics about table contents in databases, and stores the results in the PG_STATISTIC system catalog. The execution plan generator uses these statistics to generate a most effective execution plan.
If no parameters are specified, ANALYZE analyzes each table and partitioned table in the database. You can also specify table_name, column, and partition_name to limit the analysis to a specified table, column, or partitioned table.
Users who can execute ANALYZE on a specific table include the owner of the table, owner of the database where the table is, users with the ANALYZE permission on the table, users who are granted the gs_role_analyze_any role, and users with the SYSADMIN attribute.
To collect statistics using percentage sampling, you must have the ANALYZE and SELECT permissions.
ANALYZE and ANALYSE VERIFY are used to check whether data files of common tables (row-store and column-store tables) in a database are damaged. Currently, this function does not support HDFS tables.
1 2 | { ANALYZE | ANALYSE } [ VERBOSE ] [ table_name [ ( column_name [, ...] ) ] ]; |
1 2 3 | { ANALYZE | ANALYSE } [ VERBOSE ] [ table_name [ ( column_name [, ...] ) ] ] PARTITION ( patrition_name ) ; |
An ordinary partitioned table supports the syntax but not the function of collecting statistics about specified partitions. Run the ANALYZE command on a specified partition. A warning message is displayed.
1 2 | { ANALYZE | ANALYSE } [ VERBOSE ] { foreign_table_name | FOREIGN TABLES }; |
1 2 | {ANALYZE | ANALYSE} [ VERBOSE ] table_name (( column_1_name, column_2_name [, ...] )); |
1 | {ANALYZE | ANALYSE} VERIFY {FAST|COMPLETE}; |
1 | {ANALYZE | ANALYSE} VERIFY {FAST|COMPLETE} table_name|index_name [CASCADE]; |
1 | {ANALYZE | ANALYSE} VERIFY {FAST|COMPLETE} table_name PARTITION {(partition_name)}[CASCADE]; |
Enables the display of progress messages.
If this parameter is specified, progress information is displayed by ANALYZE to indicate the table that is being processed, and statistics about the table are printed.
Specifies the name (possibly schema-qualified) of a specific table to analyze. If omitted, all regular tables (but not foreign tables) in the current database are analyzed.
Currently, you can use ANALYZE to collect statistics about row-store tables, column-store tables, HDFS tables, ORC- or CARBONDATA-formatted OBS foreign tables, and foreign tables for collaborative analysis.
Value range: an existing table name
Specifies the name of a specific column to analyze. All columns are analyzed by default.
Value range: an existing column name
Assumes the table is a partitioned table. You can specify partition_name following the keyword PARTITION to analyze the statistics of this table. Currently the partitioned table supports the syntax of analyzing a partitioned table, but does not execute this syntax.
Value range: a partition name in a table
Specifies the name (possibly schema-qualified) of a specific table to analyze. The data of the table is stored in HDFS.
Value range: an existing table name
Analyzes HDFS foreign tables stored in HDFS and accessible to the current user.
Name of the index table to be analyzed. The name may contain the schema name.
Value range: an existing table name
For row-store tables, the CRC and page header of row-store tables are verified in FAST mode. If the verification fails, an alarm is reported. In COMPLETE mode, parse and verify the pointers and tuples of row-store tables. For column-store tables, the CRC and magic of column-store tables are verified in FAST mode. If the verification fails, an alarm is reported. In COMPLETE mode, parse and verify CU of column-store tables.
In CASCADE mode, all indexes of the current table are checked.
1 2 3 4 5 6 7 8 9 10 11 | DROP TABLE IF EXISTS CUSTOMER; CREATE TABLE CUSTOMER ( C_CUSTKEY BIGINT NOT NULL CONSTRAINT C_CUSTKEY_pk PRIMARY KEY , C_NAME VARCHAR(25) , C_ADDRESS VARCHAR(40) , C_NATIONKEY INT , C_PHONE CHAR(15) , C_ACCTBAL DECIMAL(15,2) ) DISTRIBUTE BY HASH(C_CUSTKEY); |
1 | ANALYZE CUSTOMER; |
1 | ANALYZE VERBOSE CUSTOMER; |