Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.

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

Dynamic PBE Pruning

Updated on 2024-05-20 GMT+08:00
Dynamic PBE pruning is supported in the following scenarios:
  1. Supported partitioning levels: level-1 partition and level-2 partition
  2. Supported partitioning types: range partitioning, interval partitioning, hash partitioning, and list partitioning.
  3. Supported expression types: comparison expression (<, <=, =, >=, >), logical expression, and array expression.
  4. Supported conversions and functions: some implicit type conversions and the IMMUTABLE function.
CAUTION:
  • Dynamic PBE pruning supports expressions, implicit conversions, the IMMUTABLE function, and the STABLE function, but does not support subquery expressions or VOLATILE function. For the STABLE function, type conversion functions such as to_timestamp may be affected by GUC parameters and lead to different pruning results. To ensure performance optimization, you can analyze table to regenerate a Gplan.
  • Dynamic PBE pruning is based on the generic plan. Therefore, when determining whether a statement can be dynamically pruned, you need to set plan_cache_mode to 'force_generic_plan' to eliminate the interference of the custom plan.
  • Query statements that specify level-1 partitions in level-2 partitioned tables cannot prune the filter conditions of the level-2 partition keys.
  • Typical scenarios where dynamic PBE pruning is supported are as follows:
    1. Comparison expressions
      -- Create a partitioned table.
      gaussdb=# CREATE TABLE t1 (c1 int, c2 int)
      PARTITION BY RANGE (c1)
      (
          PARTITION p1 VALUES LESS THAN(10),
          PARTITION p2 VALUES LESS THAN(20),
          PARTITION p3 VALUES LESS THAN(MAXVALUE)
      );
      -- Set parameters.
      gaussdb=# set plan_cache_mode = 'force_generic_plan';
      
      gaussdb=# PREPARE p1(int) AS SELECT * FROM t1 WHERE c1 = $1;
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p1(1);
                     QUERY PLAN                
      -----------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: PART
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: (t1.c1 = $1)
               Selected Partitions:  1 (pbe-pruning)
      (7 rows)
      
      gaussdb=# PREPARE p2(int) AS SELECT * FROM t1 WHERE c1 < $1;
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p2(1);
                     QUERY PLAN                
      -----------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: PART
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: (t1.c1 < $1)
               Selected Partitions:  1 (pbe-pruning)
      (7 rows)
      
      gaussdb=# PREPARE p3(int) AS SELECT * FROM t1 WHERE c1 > $1;
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p3(1);
                     QUERY PLAN                
      -----------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: PART
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: (t1.c1 > $1)
               Selected Partitions:  1..3 (pbe-pruning)
      (7 rows)
    2. Logical expressions
      gaussdb=# PREPARE p5(INT, INT) AS SELECT * FROM t1 WHERE c1 = $1 AND c2 = $2;
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p5(1, 2);
                         QUERY PLAN                    
      -------------------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: PART
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: ((t1.c1 = $1) AND (t1.c2 = $2))
               Selected Partitions:  1 (pbe-pruning)
      (7 rows)
      
      gaussdb=# PREPARE p6(INT, INT) AS SELECT * FROM t1 WHERE c1 = $1 OR c2 = $2;
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p6(1, 2);
                         QUERY PLAN                   
      ------------------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: PART
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: ((t1.c1 = $1) OR (t1.c2 = $2))
               Selected Partitions:  1..3 (pbe-pruning)
      (7 rows)
      gaussdb=# PREPARE p7(INT) AS SELECT * FROM t1 WHERE NOT c1 = $1;
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) execute p7(1);
                     QUERY PLAN                
      -----------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: PART
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: (t1.c1 <> $1)
               Selected Partitions:  1..3 (pbe-pruning)
      (7 rows)
    3. Array expressions
      gaussdb=# PREPARE p8(INT, INT, INT) AS SELECT * FROM t1 WHERE c1 IN ($1, $2, $3);
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p8(1, 2, 3);
                          QUERY PLAN                     
      ---------------------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: PART
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: (t1.c1 = ANY (ARRAY[$1, $2, $3]))
               Selected Partitions:  1 (pbe-pruning)
      (7 rows)
      gaussdb=# PREPARE p9(INT, INT, INT) AS SELECT * FROM t1 WHERE c1 NOT IN ($1, $2, $3);
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p9(1, 2, 3);
                           QUERY PLAN                     
      ----------------------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: PART
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: (t1.c1 <> ALL (ARRAY[$1, $2, $3]))
               Selected Partitions:  1..3 (pbe-pruning)
      (7 rows)
      gaussdb=# PREPARE p10(INT, INT, INT) AS SELECT * FROM t1 WHERE c1 = ALL(ARRAY[$1, $2, $3]);
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p10(1, 2, 3);
                          QUERY PLAN                     
      ---------------------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: PART
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: (t1.c1 = ALL (ARRAY[$1, $2, $3]))
               Selected Partitions:  NONE (pbe-pruning)
      (7 rows)
      gaussdb=# PREPARE p11(INT, INT, INT) AS SELECT * FROM t1 WHERE c1 = ANY(ARRAY[$1, $2, $3]);
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p11(1, 2, 3);
                          QUERY PLAN                     
      ---------------------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: PART
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: (t1.c1 = ANY (ARRAY[$1, $2, $3]))
               Selected Partitions:  1 (pbe-pruning)
      (7 rows)
      gaussdb=# PREPARE p12(INT, INT, INT) AS SELECT * FROM t1 WHERE c1 = SOME(ARRAY[$1, $2, $3]);
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p12(1, 2, 3);
                          QUERY PLAN                     
      ---------------------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: PART
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: (t1.c1 = ANY (ARRAY[$1, $2, $3]))
               Selected Partitions:  1 (pbe-pruning)
      (7 rows)
    4. Implicit type conversion
      gaussdb=# set plan_cache_mode = 'force_generic_plan';
      gaussdb=# PREPARE p13(TEXT) AS SELECT * FROM t1 WHERE c1 = $1;
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p13('12');
                          QUERY PLAN
      --------------------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: PART
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: (t1.c1 = ($1)::bigint)
               Selected Partitions:  2 (pbe-pruning)
      (7 rows)
    5. IMMUTABLE function
      gaussdb=# PREPARE p14(TEXT) AS SELECT * FROM t1 WHERE c1 = LENGTHB($1);
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p14('hello');
                          QUERY PLAN
      --------------------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: PART
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: (t1.c1 = lengthb($1))
               Selected Partitions:  1 (pbe-pruning)
      (7 rows)
  • Typical scenarios where dynamic PBE pruning is not supported are as follows:
    1. Subquery expressions
      gaussdb=# PREPARE p15(INT) AS SELECT * FROM t1 WHERE c1 = ALL(SELECT c2 FROM t1 WHERE c1 > $1);
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p15(1);
                               QUERY PLAN                          
      -------------------------------------------------------------
       Partition Iterator
         Output: public.t1.c1, public.t1.c2
         Iterations: 3
         ->  Partitioned Seq Scan on public.t1
               Output: public.t1.c1, public.t1.c2
               Filter: (SubPlan 1)
               Selected Partitions:  1..3
      (7 rows)
    2. Implicit type conversion failure
      gaussdb=# PREPARE p16(name) AS SELECT * FROM t1 WHERE c1 = $1;
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p16('12');
                        QUERY PLAN
      ----------------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: 3
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: ((t1.c1)::text = ($1)::text)
               Selected Partitions:  1..3
      (7 rows)
    3. STABLE and VOLATILE functions
      gaussdb=# create sequence seq;
      gaussdb=# PREPARE p17(TEXT) AS SELECT * FROM t1 WHERE c1 = currval($1);-- The VOLATILE function does not support pruning.
      PREPARE
      gaussdb=# EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE p17('seq');
                                QUERY PLAN
      --------------------------------------------------------------
       Partition Iterator
         Output: c1, c2
         Iterations: 3
         ->  Partitioned Seq Scan on public.t1
               Output: c1, c2
               Filter: ((t1.c1)::numeric = currval(($1)::regclass))
               Selected Partitions:  1..3
      (7 rows)
      
      -- Cleanup example
      gaussdb=# DROP TABLE t1;

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback