このページは、お客様の言語ではご利用いただけません。Huawei Cloudは、より多くの言語バージョンを追加するために懸命に取り組んでいます。ご協力ありがとうございました。

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Show all

Collecting Statistics in Cascading Mode

Updated on 2024-06-07 GMT+08:00

When ANALYZE | ANALYSE is used to analyze a partitioned table, the system automatically collects all partition-level statistics that comply with semantics in the partitioned table based on the specified or default PARTITION_MODE. For details about PARTITION_MODE, see the PARTITION_MODE parameter in "SQL Reference > SQL Syntax > ANALYZE | ANALYSE" in Developer Guide.

CAUTION:
  • When statistics about replication, and hash bucket partitioned tables are collected in cascading mode and PARTITION_MODE is set to ALL, the behavior is converted to the ALL COMPLETE mode.
  • Cascading collection of partition-level statistics does not support the scenario where the value of default_statistics_target is a negative number.

Examples

  • Create a partitioned table and insert data.
    gaussdb=# CREATE TABLE t1_range_int
    (
        c1 INT,
        c2 INT,
        c3 INT,
        c4 INT
    )
    PARTITION BY RANGE(c1)
    (
        PARTITION range_p00 VALUES LESS THAN(10),
        PARTITION range_p01 VALUES LESS THAN(20),
        PARTITION range_p02 VALUES LESS THAN(30),
        PARTITION range_p03 VALUES LESS THAN(40),
        PARTITION range_p04 VALUES LESS THAN(50)
    );
    gaussdb=# INSERT INTO t1_range_int SELECT v,v,v,v FROM generate_series(0, 49) AS v;
  • Collect statistics in cascading mode.
    gaussdb=# ANALYZE t1_range_int WITH ALL;
  • View partition-level statistics.
    gaussdb=# SELECT relname, parttype, relpages, reltuples FROM pg_partition WHERE parentid=(SELECT oid FROM pg_class WHERE relname='t1_range_int') ORDER BY relname;
       relname    | parttype | relpages | reltuples 
    --------------+----------+----------+-----------
     range_p00    | p        |        4 |         9
     range_p01    | p        |        7 |        17
     range_p02    | p        |        6 |        13
     range_p03    | p        |        2 |         5
     range_p04    | p        |        4 |         9
     t1_range_int | r        |        0 |         0
    (6 rows)
    
    gaussdb=# SELECT schemaname,tablename,partitionname,subpartitionname,attname,inherited,null_frac,avg_width,n_distinct,n_dndistinct,most_common_vals,most_common_freqs,histogram_bounds FROM pg_stats WHERE tablename='t1_range_int' ORDER BY tablename, partitionname, attname;
     schemaname |  tablename   | partitionname | subpartitionname | attname | inherited | null_frac | avg_width | n_distinct | n_dndistinct | most_common_vals | most_common_freqs |                                                               histogram_bounds               
                                                     
    ------------+--------------+---------------+------------------+---------+-----------+-----------+-----------+------------+--------------+------------------+-------------------+----------------------------------------------------------------------------------------------
    -------------------------------------------------
     public     | t1_range_int | range_p00     |                  | c1      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {0,1,2,3,4,5,6,7,8,9}
     public     | t1_range_int | range_p00     |                  | c2      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {0,1,2,3,4,5,6,7,8,9}
     public     | t1_range_int | range_p00     |                  | c3      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {0,1,2,3,4,5,6,7,8,9}
     public     | t1_range_int | range_p00     |                  | c4      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {0,1,2,3,4,5,6,7,8,9}
     public     | t1_range_int | range_p01     |                  | c1      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {10,11,12,13,14,15,16,17,18,19}
     public     | t1_range_int | range_p01     |                  | c2      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {10,11,12,13,14,15,16,17,18,19}
     public     | t1_range_int | range_p01     |                  | c3      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {10,11,12,13,14,15,16,17,18,19}
     public     | t1_range_int | range_p01     |                  | c4      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {10,11,12,13,14,15,16,17,18,19}
     public     | t1_range_int | range_p02     |                  | c1      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {20,21,22,23,24,25,26,27,28,29}
     public     | t1_range_int | range_p02     |                  | c2      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {20,21,22,23,24,25,26,27,28,29}
     public     | t1_range_int | range_p02     |                  | c3      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {20,21,22,23,24,25,26,27,28,29}
     public     | t1_range_int | range_p02     |                  | c4      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {20,21,22,23,24,25,26,27,28,29}
     public     | t1_range_int | range_p03     |                  | c1      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {30,31,32,33,34,35,36,37,38,39}
     public     | t1_range_int | range_p03     |                  | c2      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {30,31,32,33,34,35,36,37,38,39}
     public     | t1_range_int | range_p03     |                  | c3      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {30,31,32,33,34,35,36,37,38,39}
     public     | t1_range_int | range_p03     |                  | c4      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {30,31,32,33,34,35,36,37,38,39}
     public     | t1_range_int | range_p04     |                  | c1      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {40,41,42,43,44,45,46,47,48,49}
     public     | t1_range_int | range_p04     |                  | c2      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {40,41,42,43,44,45,46,47,48,49}
     public     | t1_range_int | range_p04     |                  | c3      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {40,41,42,43,44,45,46,47,48,49}
     public     | t1_range_int | range_p04     |                  | c4      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {40,41,42,43,44,45,46,47,48,49}
     public     | t1_range_int |               |                  | c1      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,
    34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49}
     public     | t1_range_int |               |                  | c2      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,
    34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49}
     public     | t1_range_int |               |                  | c3      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,
    34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49}
     public     | t1_range_int |               |                  | c4      | f         |         0 |         4 |         -1 |           -1 |                  |                   | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,
    34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49}
    (24 rows)
  • Generate partition-level statistics of data in multiple columns.
    gaussdb=# ALTER TABLE t1_range_int ADD STATISTICS ((c2, c3));
    gaussdb=# ANALYZE t1_range_int WITH ALL;
  • View partition-level statistics of data in multiple columns.
    gaussdb=# SELECT schemaname,tablename,partitionname,subpartitionname,attname,inherited,null_frac,avg_width,n_distinct,n_dndistinct,most_common_vals,most_common_freqs,histogram_bounds FROM pg_ext_stats WHERE tablename='t1_range_int' ORDER BY tablename,partitionname,attname;
     schemaname |  tablename   | partitionname | subpartitionname | attname | inherited | null_frac | avg_width | n_distinct | n_dndistinct | most_common_vals | most_common_freqs | histogram_bounds 
    ------------+--------------+---------------+------------------+---------+-----------+-----------+-----------+------------+--------------+------------------+-------------------+------------------
     public     | t1_range_int | range_p00     |                  | 2 3     | f         |         0 |         8 |         -1 |           -1 |                  |                   | 
     public     | t1_range_int | range_p01     |                  | 2 3     | f         |         0 |         8 |         -1 |           -1 |                  |                   | 
     public     | t1_range_int | range_p02     |                  | 2 3     | f         |         0 |         8 |         -1 |           -1 |                  |                   | 
     public     | t1_range_int | range_p03     |                  | 2 3     | f         |         0 |         8 |         -1 |           -1 |                  |                   | 
     public     | t1_range_int | range_p04     |                  | 2 3     | f         |         0 |         8 |         -1 |           -1 |                  |                   | 
     public     | t1_range_int |               |                  | 2 3     | f         |         0 |         8 |         -1 |           -1 |                  |                   | 
    (6 rows)
  • Create an expression index and generate partition-level statistics.
    gaussdb=# CREATE INDEX t1_range_int_index ON t1_range_int(text(c1)) LOCAL;
    gaussdb=# ANALYZE t1_range_int WITH ALL;
  • View the partition-level statistics of the expression index.
    gaussdb=# SELECT schemaname,tablename,partitionname,subpartitionname,attname,inherited,null_frac,avg_width,n_distinct,n_dndistinct,most_common_vals,most_common_freqs,histogram_bounds FROM pg_stats WHERE tablename='t1_range_int_index' ORDER BY tablename,partitionname,attname;
     schemaname |     tablename      |   partitionname    | subpartitionname | attname | inherited | null_frac | avg_width | n_distinct | n_dndistinct | most_common_vals | most_common_freqs |                                                               histogram_bounds    
    
    ------------+--------------------+--------------------+------------------+---------+-----------+-----------+-----------+------------+--------------+------------------+-------------------+-----------------------------------------------------------------------------------
    ------------------------------------------------------------
     public     | t1_range_int_index | range_p00_text_idx |                  | text    | f         |         0 |         5 |         -1 |            0 |                  |                   | {0,1,2,3,4,5,6,7,8,9}
     public     | t1_range_int_index | range_p01_text_idx |                  | text    | f         |         0 |         6 |         -1 |            0 |                  |                   | {10,11,12,13,14,15,16,17,18,19}
     public     | t1_range_int_index | range_p02_text_idx |                  | text    | f         |         0 |         6 |         -1 |            0 |                  |                   | {20,21,22,23,24,25,26,27,28,29}
     public     | t1_range_int_index | range_p03_text_idx |                  | text    | f         |         0 |         6 |         -1 |            0 |                  |                   | {30,31,32,33,34,35,36,37,38,39}
     public     | t1_range_int_index | range_p04_text_idx |                  | text    | f         |         0 |         6 |         -1 |            0 |                  |                   | {40,41,42,43,44,45,46,47,48,49}
     public     | t1_range_int_index |                    |                  | text    | f         |         0 |         5 |         -1 |            0 |                  |                   | {0,1,10,11,12,13,14,15,16,17,18,19,2,20,21,22,23,24,25,26,27,28,29,3,30,31,32,33,3
    4,35,36,37,38,39,4,40,41,42,43,44,45,46,47,48,49,5,6,7,8,9}
    (6 rows)
  • Delete the partitioned table.
    gaussdb=# DROP TABLE t1_range_int;

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback