OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.2.0

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.2.0
    iconOceanBase Database
    SQL - V 4.2.0
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Overview

    Last Updated:2023-10-31 11:17:12  Updated
    Share
    What is on this page
    Use of hints
    Define a query block in a hint
    Define a global hint

    folded

    Share

    A hint is a comment in an SQL statement that passes instructions to the OceanBase Database optimizer. You can use hints to make the optimizer generate a specified execution plan.

    Generally, a hint is not required because the optimizer selects the best execution plan for a query. In some scenarios, the execution plan generated by the optimizer may not meet user requirements. In this case, you need to add a hint to specify and generate a specific execution plan.

    However, we recommend that you use as few hints as possible. For example, when statistics of related tables are collected and no hint is specified, we recommend that you use the EXPLAIN PLAN statement to evaluate the plan of the optimizer before you consider using a hint. Changing database conditions and enhancing query performance in subsequent versions may result in a significant impact on the performance.

    Use of hints

    A statement can contain only one hint comment, and this comment must follow the SELECT, UPDATE, INSERT, REPLACE, or DELETE keyword.

    The syntax for hints in statement comments is as follows:

    {DELETE|INSERT|SELECT|UPDATE|REPLACE} /*+ hint_text [,hint_text...] */
    

    A hint is a special SQL comment in terms of syntax, except that a plus sign (+) is added to the right of the opening tag of the comment. If the server does not recognize the hint in an SQL statement, the optimizer ignores the specified hint and uses the execution logic generated by the default plan. In addition, a hint only affects the logic of the execution plan generated by the optimizer. The semantics of the SQL statement remains unaffected.

    Take note of the following rules when you specify a hint:

    • OceanBase Database interprets a comment that starts with a plus sign (+) as a hint list. The plus sign must immediately follow the opening tag of the comment, and no space is allowed.

    • A space between the plus sign (+) and the hint text is optional. If a comment contains multiple hints, separate them with at least one space.

    • A hint is ignored when it contains spelling or grammatical errors. However, OceanBase Database will consider using other correctly specified hints in the same comment.

    • Hints not following the DELETE, INSERT, REPLACE, SELECT, or UPDATE keyword are invalid.

    • If hints in a combination conflict with each other, the hints are invalid. However, OceanBase Database will consider using other nonconflicting hints in the same comment.

    Define a query block in a hint

    You can define a query block that the hint applies to by specifying the query block name in the hint.

    You can use this syntax to specify the hint that applies to an embedded view in an external query.

    The syntax for the query block parameter is @queryblock, where queryblock is the identifier of the query block specified in the query. A queryblock identifier can be system-generated or user-specified. When you directly specify the hint to apply in the query block, @queryblock will be ignored.

    • You can use EXPLAIN to generate a system-generated identifier.

    • You can also use QB_NAME to specify the name of the query block.

    Define a global hint

    Many hints apply to a specific table or index. They can also apply globally to tables of a view or to columns in an index. Syntax elements tablespec and indexspec define these global hints.

    The syntax of tablespec is as follows:

    [ view.[,view. ]... ] table_name
    

    You must specify the tables to be accessed exactly as shown in the statement. If the statement uses an alias of a table, also use the alias instead of the table name in the hint. However, even if the schema name is specified in the statement, do not include the schema name in the table name in the hint.

    Notice

    A global hint specified with the tablespec clause does not work for queries that use ANSI joins, because the optimizer generates additional views during parsing. On the contrary, you can use @queryblock to specify the subject query block of the hint.

    The syntax of indexspec is as follows:

    { index
    | ( [ table. ]column_name [ [ table. ]column_name ]...)
    }
    

    In the description of a hint, if tablespec is followed by indexspec, you can, but do not have to, use a comma to separate the table name from the index name. Likewise, you can, but do not have to, use commas to separate multiple indexspec elements.

    Previous topic

    Comments on schema and nonschema objects
    Last

    Next topic

    Hints related to access path
    Next
    What is on this page
    Use of hints
    Define a query block in a hint
    Define a global hint