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
Situation Awareness
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

Enabling Parallel Query

Updated on 2025-01-24 GMT+08:00

System Parameters and Status Variables

  • Table 1 lists the supported system parameters.
    Table 1 System parameters

    Parameter

    Level

    Description

    force_parallel_execute

    Global, Session

    Controls whether to enable parallel query. If this parameter is set to ON, query SQL statements are executed in parallel as much as possible. If this parameter is set to OFF, parallel query tuning is disabled. If this parameter is set to AUTO (supported in kernel 2.0.60.241200 or later), parallel query tuning is only used in specific scenarios, which are controlled by the options in pq_support_features_switch.

    • Value range: ON, OFF, and AUTO
    • Default value: OFF

    pq_master_enable

    Global

    Controls whether to enable parallel query on the primary node. This parameter must be used together with force_parallel_execute. If this parameter is set to ON and force_parallel_execute is set to ON or AUTO, parallel query is applied on the primary node. If this parameter is set to OFF, parallel query is not applied on the primary node. Read replicas are not affected by this parameter.

    • Value range: ON and OFF
    • Default value: ON

    parallel_max_threads

    Global

    Specifies the maximum number of active threads allowed for parallel execution. If the number of active threads in the current system exceeds the value of this parameter, parallel execution cannot be enabled for new queries.

    • Value range: 0 to 4294967295
    • Default value: 64

    parallel_default_dop

    Global, Session

    Specifies the default parallelism degree for parallel execution. If the parallelism degree is not specified in query statements, this parameter value is used.

    • Value range: 0 to 1024
    • Default value: 4

    parallel_cost_threshold

    Global, Session

    Specifies the cost threshold for enabling parallel execution. If the parallel execution cost of query statements exceeds the value of this parameter, parallel execution is enabled.

    • Value range: 0 to 4294967295
    • Default value: 1000

    parallel_queue_timeout

    Global, Session

    Specifies the waiting time of the parallel execution. If the waiting time exceeds the value of this parameter, new queries will be executed in single-thread mode.

    • Value range: 0 to 4294967295
    • Default value: 0

    parallel_memory_limit

    Global

    Specifies the maximum available memory for parallel execution. If the amount of memory used for parallel execution exceeds the value of this parameter, new queries will not be executed in parallel mode.

    • Value range: 0 to 4294967295
    • Default value: 104857600

    parallel_setup_cost

    Global, Session

    Specifies the cost of launching parallel worker processes. It is used to estimate the total cost of parallel execution.

    • Value range: 0 to 1000000000
    • Default value: 1000

    parallel_tuple_cost

    Global, Session

    Specifies the cost of transferring one tuple from a parallel worker process to another process. It is used to estimate the total cost of parallel execution.

    • Value range: 0 to 1000000
    • Default value: 1.5
  • Table 2 lists the supported status variables.
    Table 2 Status variables

    Variable

    Level

    Description

    PQ_threads_running

    Global

    Specifies the total number of concurrent threads that are running.

    PQ_memory_used

    Global

    Specifies the total memory used for parallel execution.

    PQ_threads_refused

    Global

    Specifies the total number of queries that fail to be executed in parallel due to the limit on the total number of threads.

    PQ_memory_refused

    Global

    Specifies the total number of queries that fail to be executed in parallel due to the limit on the total memory.

Enabling Parallel Query

You can enable or disable parallel query by configuring system parameters on the console or using hints in SQL statements.

  • Method 1: Configuring system parameters on the console

    You can enable or disable parallel query and adjust the parallelism degree by configuring the following system parameters on the Parameters page of the console:

    force_parallel_execute: controls whether to forcibly enable parallel execution.

    pq_master_enable: controls whether to enable parallel query on the primary node.

    parallel_default_dop: controls the number of concurrent threads.

    parallel_cost_threshold: controls the cost threshold for enabling parallel query. The default value is 1000. You are advised not to set this parameter to a small value because parallel query is not suitable for simple queries.

    These parameters can be dynamically modified without the need to reboot the instance.

    You can also adjust the parallelism degree and modify the cost threshold for enabling parallel query in a session. For example, you can set the parallelism degree to 8 and the cost threshold for enabling parallel query to 100 as follows:

    SET parallel_default_dop=8;
    SET parallel_cost_threshold=100;
  • Method 2: Using hints in SQL statements

    Hints can be used to control whether a single statement is executed in parallel. If parallel execution is disabled by default, uses hints to enable parallel execution for specific SQL statements. You can also use hints to disable parallel execution for specified SQL statements.

    Enabling parallel execution:

    Enabling parallel execution: SELECT /*+ PQ() */... FROM...

    Enabling parallel execution and setting the parallelism degree to 8: SELECT /*+ PQ(8) */... FROM...

    Enabling parallel execution and set the parallel-executed table to t1: SELECT /*+ PQ(t1) */... FROM...

    Enabling parallel execution, set the parallel-executed table to t1, and set the parallelism degree to 8: SELECT /*+ PQ(t1 8) */... FROM...

    NOTE:

    SELECT is followed by PQ (Hints). Otherwise, the hints do not take effect. dop indicates the parallelism degree of a parallel query and its value ranges from 1 to min(parallel_max_threads, 1024).

    When the dop value exceeds the normal range, parallel query does not take effect.

    Disabling parallel execution: When parallel query is enabled, use the NO_PQ to disable parallel execution of a single SQL statement.

    SELECT /*+ NO_PQ */ … FROM …

    NOTE:

    NO_PQ (Hints) takes precedence over PQ (Hints). If an SQL statement contains NO_PQ (Hints), the SQL statement will not be executed concurrently even if PQ (Hints) is configured.

Checking the Statuses of Query Statements Executed in Parallel

Run the following SQL statement to display the statuses of query statements executed in parallel, as shown in Figure 1.

show status like "%PQ%"

Figure 1 Status

Use EXPLAIN to display the parallel execution plans of the query statements, as shown in Figure 2.

Figure 2 Parallel execution plan
NOTE:

Compared with a traditional execution plan, a parallel execution plan has one more row of records. In the first row of the query result, the parallel-executed tables and parallelism degree are displayed.

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