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
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
On this page
Help Center/ GaussDB/ Developer Guide(Distributed_3.x)/ SQL Optimization/ Hint-based Tuning/ Hint Specifying the Query Block Where the Hint Is Located

Hint Specifying the Query Block Where the Hint Is Located

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

Function

This function allows users to use @queryblock in hints to implement block-level hint control. Users can specify the query block to which the hint takes effect. For example, you can specify the hint of an inner query block in the outer query block.

Syntax

Add @queryblock at the beginning of the hint parameter. Hint_SEPC is a specific hint.

Hint_SEPC([@queryblock])

Parameter Description

Hint_SEPC is the hint name, and @queryblock can be left empty. If @queryblock is left empty, the hint takes effect in the current query block declared by the hint. If @queryblock is left empty and Hint_SPEC has no parameter, use Hint_SPEC instead of Hint_SPEC(). Parentheses are unnecessary. The following describes how to name a query block and how to make a hint take effect. Some hints do not take effect only at the outermost layer and cannot be specified using @queryblock. For details, see the syntax description of each hint.

  • Query the name of a query block.

    Each query block must have a name, so as to accurately specify a hint. There are two naming methods: user-specified and system-specified.

    • You can use the blockname hint to specify the block to be queried. For details, see Sublink Name Hints.
    • If no alias is specified for a query block, the default block name is automatically generated based on the processing sequence. Generally, the default alias of each query block consists of the first three letters of the query block name, $, and the number of the query block. For example, the alias of the first SELECT query block is sel$1. In pretty mode, you can use the explain method with a specified block name to view the name of the query block where the processing operator of each table is located. In distributed scenarios, only stream plans can be displayed in pretty mode. You can set enable_fast_query_shipping to generate stream plans.
      gaussdb=# set explain_perf_mode = pretty;
      SET
      gaussdb=# set enable_fast_query_shipping = off;
      SET
      gaussdb=# explain (blockname on,costs off) select * from t1, (select c1 from t2 group by c1) sub1 where t1.c1 = sub1.c1;
       id |               operation                | Query Block 
      ----+----------------------------------------+-------------
        1 | ->  Streaming (type: GATHER)           | sel$1
        2 |    ->  Hash Join (3,4)                 | sel$1
        3 |       ->  Seq Scan on t1@"sel$1"       | sel$1
        4 |       ->  Hash                         | 
        5 |          ->  HashAggregate             | sel$2
        6 |             ->  Seq Scan on t2@"sel$2" | sel$2
      (6 rows)

      You can see that Seq Scan of t2 is located in the sel$2 query block.

  • @queryblock specifies the query block.

    For the preceding example, if you want to modify the indexscan mode in t2, run the following command:

    select /*+indexscan(@sel$2 t2) tablescan(t1)*/ * from t1, (select c1 from t2 group by c1) sub1 where t1.c1 = sub1.c1; 

    Both indexscan and tablescan are scan hints. For details about scan hints, see Scan Operation Hints. You can specify the hint of indexscan(@sel$2 t2) in the sel$1 query block to move the hint to the sel$2 query block. The hint takes effect for t2. If the sel$2 query block is promoted sel$1 during subsequent rewriting, the hint is also promoted together to sel$1 and continues to take effect for t2.

    gaussdb=# explain (blockname on,costs off) select /*+indexscan(@sel$2 t2) tablescan(t1)*/ * from t1, (select c1 from t2 group by c1) sub1 where t1.c1 = sub1.c1;
     id |                        operation                        | Query Block 
    ----+---------------------------------------------------------+-------------
      1 | ->  Streaming (type: GATHER)                            | sel$1
      2 |    ->  Hash Join (3,4)                                  | sel$1
      3 |       ->  Seq Scan on t1@"sel$1"                        | sel$1
      4 |       ->  Hash                                          | 
      5 |          ->  HashAggregate                              | sel$2
      6 |             ->  Index Only Scan using it2 on t2@"sel$2" | sel$2
    (6 rows)
CAUTION:

Sometimes, query rewriting in the optimizer phase expands some query blocks. As a result, the plan does not display related query blocks in the explain method. The hint specifies a query block based on the name of the query block before the optimizer phase. If a query block to be queried may be expanded in the planning phase, you can add the no_expand hint (see Hints Specifying Not to Expand Subqueries) to prevent it from being expanded.

  1. The sel$2 query block is a simple query. The optimizer performs query rewriting during subsequent processing, and t1 is promoted to sel$1 for processing. Therefore, the operation in the sel$2 query block is not displayed in the plan.
    gaussdb=# explain (blockname on,costs off) select * from t2, (select c1 from t1 where t1.c3 = 2) sub1 where t2.c1 = sub1.c1;
     id |                  operation                   | Query Block 
    ----+----------------------------------------------+-------------
      1 | ->  Streaming (type: GATHER)                 | sel$1
      2 |    ->  Nested Loop (3,4)                     | sel$1
      3 |       ->  Index Scan using it3 on t1@"sel$2" | sel$1
      4 |       ->  Index Scan using it2 on t2@"sel$1" | sel$1
    (4 rows)
  2. The sel$2 query block is a simple query. During subsequent processing, the optimizer skips query rewriting because of the no_expand hint, and t1 is still processed in the original query block.
    gaussdb=# explain (blockname on,costs off) select * from t2, (select /*+ no_expand*/ c1 from t1 where t1.c3 = 2) sub1 where t2.c1 = sub1.c1;
     id |                  operation                   | Query Block 
    ----+----------------------------------------------+-------------
      1 | ->  Streaming (type: GATHER)                 | sel$1
      2 |    ->  Nested Loop (3,4)                     | sel$1
      3 |       ->  Index Scan using it3 on t1@"sel$2" | sel$2
      4 |       ->  Index Scan using it2 on t2@"sel$1" | sel$1
    (4 rows)
  3. Because t1 is processed in the sel$2 query block after the no_expand hint is added, you can use @sel$2 to specify the query block for the hint.
    explain (blockname on,costs off) select/*+ tablescan(@sel$2 t1)*/ * from t2, (select c1 from t1 where t1.c3 = 2) sub1 where t2.c1 = sub1.c1;
     id |                  operation                   | Query Block 
    ----+----------------------------------------------+-------------
      1 | ->  Streaming (type: GATHER)                 | sel$1
      2 |    ->  Nested Loop (3,4)                     | sel$1
      3 |       ->  Seq Scan on t1@"sel$2"             | sel$1
      4 |       ->  Index Scan using it2 on t2@"sel$1" | sel$1
    (4 rows)
  4. The query block number in the view depends on the sequence of the statement using the view. Therefore, do not use hints to specify query blocks when creating a view. The behavior is uncontrollable.
    gaussdb=# create view v1 as select/*+ no_expand */ c1 from t1 where c1 in (select /*+ no_expand */ c1 from t2 where t2.c3=4 );
    CREATE VIEW
    gaussdb=# explain (blockname on,costs off) select  * from v1;
     id |                operation                | Query Block 
    ----+-----------------------------------------+-------------
      1 | ->  Streaming (type: GATHER)            | sel$1
      2 |    ->  Seq Scan on t1@"sel$2"           | sel$2
      3 |       ->  Materialize  [2, SubPlan 1]   | 
      4 |          ->  Streaming(type: BROADCAST) | 
      5 |             ->  Seq Scan on t2@"sel$3"  | sel$3
    (5 rows)
    
     Predicate Information (identified by plan id) 
    -----------------------------------------------
       2 --Seq Scan on t1@"sel$2"
             Filter: (hashed SubPlan 1)
       5 --Seq Scan on t2@"sel$3"
             Filter: (c3 = 4)
    (4 rows)

    In this case, the statements in v1 belong to sel$2 and sel$3.

  5. Some hints take effect only at the outermost layer and cannot be specified using @queryblock. For details, see the syntax description of each hint.

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