Other hints under the GLOBAL hint allow developers and database administrators to fine-tune the execution of SQL statements. The supported other hints are as follows:
| Hint Name | Description |
|---|---|
APPEND |
Collects statistics while inserting data; enables direct insert mode (DIRECT INSERT) in INSERT INTO SELECT statements. |
CURSOR_SHARING_EXACT |
Controls whether queries are parameterized. |
DIRECT |
Enables direct load mode in LOAD DATA and INSERT statements to improve data import efficiency and performance. |
NO_DIRECT |
Disables direct load mode in LOAD DATA, INSERT INTO SELECT, and CREATE TABLE AS SELECT statements. |
USE_PX |
Executes SQL statements in PX mode, which allows for multi-threaded execution. |
ENABLE_PARALLEL_DML |
Enables parallel DML. |
DISABLE_PARALLEL_DML |
Disables parallel DML. |
ENABLE_PARALLEL_DAS_DML |
Specifies that the current DML statement must force the use of Distributed Data Access Service (DAS) concurrent write optimization. |
DISABLE_PARALLEL_DAS_DML |
Specifies that the current DML statement must disable Distributed Data Access Service (DAS) concurrent write optimization. |
DYNAMIC_SAMPLING |
Enables dynamic sampling. |
LOAD_BATCH_SIZE |
Specifies the batch size for each insert, and is only used in LOAD DATA. |
LOG_LEVEL |
Specifies the log level for the current query during execution. |
MAX_CONCURRENT |
Sets the maximum allowed concurrency for the query. |
MONITOR |
Enables the capture of SQL Plan Monitor records for the query. |
MV_REWRITE |
When used alone, the MV_REWRITE hint skips the rules and cost checks for materialized view query rewriting and directly uses applicable rewriting. |
NO_MV_REWRITE |
Disables materialized view query rewriting, and you can specify a query block. |
OPT_PARAM |
Sets optimizer-related parameters at the query level. |
PARALLEL |
Sets the parallelism level for the query. Its reverse operation is NO_PARALLEL. |
NO_PARALLEL |
Disables query parallelism (i.e., sets the parallelism level to 1). |
QUERY_TIMEOUT |
Sets the query execution timeout. |
READ_CONSISTENCY |
Sets the read consistency level (strong/weak). |
RESOURCE_GROUP |
Forces the resource group used by the statement. |
STAT |
Tracks output statistics for query operators. |
TRANS_PARAM |
Sets transaction-related variables at the query level. |
TRACING |
Tracks output from query execution operators. |
USE_PLAN_CACHE |
Specifies the plan cache (Plan Cache) usage strategy for the current query. |
APPEND Hint
The APPEND hint specifies to enable the direct load feature for INSERT INTO SELECT statements. For more information, see Use the INSERT INTO SELECT statement to perform direct load.
Syntax
/*+ APPEND */
Examples
INSERT /*+ append enable_parallel_dml parallel(16) */ INTO t2
SELECT * FROM t1;
CURSOR_SHARING_EXACT Hint
The CURSOR_SHARING_EXACT hint specifies to disable parameterization at the query level.
OceanBase Database supports replacing literals in SQL statements with bind variables. This feature is controlled by the CURSOR_SHARING variable. When cursor_sharing='exact', parameterization is not required. For more information, see cursor_sharing.
Syntax
/*+ CURSOR_SHARING_EXACT */
Examples
The following example shows how to use the CURSOR_SHARING_EXACT hint to disable parameterization. After executing the query with two sets of parameters four times, two different query plans are generated in the plan cache.
alter system flush plan cache global;
SELECT /*+ CURSOR_SHARING_EXACT */ * FROM t1 WHERE c1=5;
SELECT /*+ CURSOR_SHARING_EXACT */ * FROM t1 WHERE c1=5;
SELECT /*+ CURSOR_SHARING_EXACT */ * FROM t1 WHERE c1=6;
SELECT /*+ CURSOR_SHARING_EXACT */ * FROM t1 WHERE c1=6;
SELECT sql_id, plan_id, statement FROM oceanbase.gv$ob_plan_cache_plan_stat where query_sql like "SELECT /*+ CURSOR_SHARING_EXACT */ * FROM t1 WHERE c1=%";
+----------------------------------+---------+---------------------------------------------------------+
| sql_id | plan_id | statement |
+----------------------------------+---------+---------------------------------------------------------+
| E024EB33213BF501D4CA7ABB81A195B5 | 13249 | SELECT /*+ CURSOR_SHARING_EXACT */ * FROM t1 WHERE c1=5 |
| E024EB33213BF501D4CA7ABB81A195B5 | 13250 | SELECT /*+ CURSOR_SHARING_EXACT */ * FROM t1 WHERE c1=6 |
+----------------------------------+---------+---------------------------------------------------------+
DIRECT Hint
The DIRECT hint enables the direct load feature in LOAD DATA and INSERT statements to improve the efficiency and performance of data import.
Syntax
The syntax of the DIRECT hint is as follows:
/*+ DIRECT (/*+ direct(need_sort, max_errors_allowed, load_mode) */)*/
Parameters
need_sort: specifies whether to sort the imported data. Valid values:trueandfalse.trueindicates that the data needs to be sorted.falseindicates that the data does not need to be sorted.max_errors_allowed: specifies the maximum number of error rows allowed. If the number of error rows exceeds this value, the import process will fail.load_mode: specifies the import mode. Valid values:full: the default value, indicating a full import.inc: indicating an incremental import, which supports theINSERTandIGNOREsemantics.inc_replace: indicating an incremental import that does not check for duplicate primary keys, equivalent to theREPLACEsemantics of incremental import.
Examples
Example in LOAD DATA statement
Enable incremental direct load
LOAD DATA /*+ DIRECT(true, 0, inc) */
INFILE 'datafile.txt'
INTO TABLE mytable
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n';
In this example, DIRECT(true, 0, inc) enables incremental direct load, sorts the data, and allows up to 0 error rows.
Enable full direct load
LOAD DATA
/*+ PARALLEL(4) DIRECT(true, 0, full) */
REMOTE_OSS INFILE 'oss://example.com/datafile.csv'
INTO TABLE my_table
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\n';
In this example, PARALLEL(4) specifies a parallelism of 4, and DIRECT(true, 0, full) enables full direct load, sorts the data, and allows up to 0 error rows.
For more information, see Direct load.
Example in INSERT INTO SELECT statement
In the INSERT INTO SELECT statement, to enable direct load, you must use the enable_parallel_dml hint in the format: /*+ direct(bool, int, load_mode)} enable_parallel_dml PARALLEL(N) */.
Enable incremental direct load
-- Enable incremental direct load and parallel DML to incrementally import data from old_table to new_table
INSERT /*+ direct(true, 0, 'inc') enable_parallel_dml PARALLEL(4) */ INTO new_table (id, name, value)
SELECT id, name, value
FROM old_table;
In this example, direct(true, 0, 'inc') enables incremental direct load, sorts the data, and allows up to 0 error rows; enable_parallel_dml enables parallel DML; and PARALLEL(4) sets the parallelism to 4.
Enable full direct load
-- Enable full direct load and parallel DML to import data from old_table to new_table
INSERT /*+ direct(true, 0, 'full') enable_parallel_dml PARALLEL(4) */ INTO new_table (id, name, value)
SELECT id, name, value
FROM old_table;
In this example, direct(true, 0, 'full') enables full direct load, sorts the data, and allows up to 0 error rows; enable_parallel_dml enables parallel DML; and PARALLEL(4) sets the parallelism to 4.
For more information, see Use the INSERT INTO SELECT statement to perform direct load.
NO_DIRECT Hint
The NO_DIRECT hint disables the direct load feature in LOAD DATA, INSERT INTO SELECT, and CREATE TABLE AS SELECT statements.
Syntax
The syntax of the NO_DIRECT hint is as follows:
/*+ NO_DIRECT */
Parameters
NO_DIRECT: forces a single SQL statement to not use direct load. If an SQL statement contains this hint, it ignores other direct load hints and executes a regular import.
Examples
Use the NO_DIRECT hint in a LOAD DATA statement
LOAD DATA /*+ NO_DIRECT */ [REMOTE_OSS | LOCAL] INFILE 'file_name' INTO TABLE table_name [COMPRESSION]...Use the NO_DIRECT hint in an INSERT INTO SELECT statement
INSERT /*+ NO_DIRECT */ INTO table_name select_sentenceUse the NO_DIRECT hint in a CREATE TABLE AS SELECT statement
CREATE /*+ NO_DIRECT */ TABLE table_name [AS] select_sentence
DYNAMIC_SAMPLING Hint
DYNAMIC_SAMPLING Hint specifies whether to enable dynamic sampling for a query.
Syntax
/*+ DYNAMIC_SAMPLING ( 0 | 1 ) */
Parameters
The parameters of the DYNAMIC_SAMPLING Hint are described as follows:
- When the parameter is 0, dynamic sampling is disabled.
- When the parameter is 1, dynamic sampling is enabled.
Examples
The following example shows how to use the DYNAMIC_SAMPLING Hint to enable dynamic sampling.
SELECT /*+ dynamic_sampling(1) */ *
FROM t1 WHERE c1 LIKE "%abc%" AND c2 LIKE "%abc%";
USE_PX Hint
USE_PX Hint forces the server to execute SQL statements in parallel execution (PX) mode. PX mode allows SQL statements to be executed using multiple threads, thereby improving query performance. Typically, the USE_PX Hint is used together with the PARALLEL Hint to specify the number of threads for parallel execution. By default, the system uses the USE_PX Hint.
Syntax
The syntax of the USE_PX Hint is as follows:
/*+ USE_PX */
Examples
The following example shows how to use the USE_PX Hint:
SELECT /*+ USE_PX PARALLEL(4)*/ e.dept_id, sum(e.salary)
FROM emp e
WHERE e.dept_id = 1001 GROUP BY e.dept_id;
ENABLE_PARALLEL_DML Hint
ENABLE_PARALLEL_DML Hint specifies to enable parallel DML for the current query. Its reverse Hint is DISABLE_PARALLEL_DML, which is used to disable parallel DML.
For more information, see Parallel DML.
Considerations
When using
/*+ENABLE_PARALLEL_DML PARALLEL(n)*/, the system prioritizes distributed parallel DML (PDML). If PDML is not supported in the current environment, the system will fall back to DAS concurrent writes as a performance optimization.If a forced parallelism level is set at the session level, the execution behavior will remain consistent with the above.
Even if the current environment does not support parallel DML (PDML), if the system parameter
_enable_parallel_das_dmlis set totrueusing theALTER SYSTEM SETcommand (its default value isfalse), the system will not enable DAS (Distributed Active Storage) parallel writes even if the Hint/*+ENABLE_PARALLEL_DML PARALLEL(n)*/is used.If
_enable_parallel_das_dmlis set totrueusing theALTER SYSTEM SETcommand (default isfalse), and a forced parallelism level is already set at the session level, using the Hint/*+ENABLE_PARALLEL_DML PARALLEL(n)*/will not enable DAS parallel writes.
Syntax
/*+ ENABLE_PARALLEL_DML */
Examples
insert /*+ enable_parallel_dml parallel(8) */ into t2 select * from t1;
DISABLE_PARALLEL_DML Hint
DISABLE_PARALLEL_DML Hint specifies to disable parallel DML for the current query. Its reverse Hint is ENABLE_PARALLEL_DML, which is used to enable parallel DML.
For more information, see Parallel DML.
Syntax
/*+ DISABLE_PARALLEL_DML */
Examples
insert /*+ disable_parallel_dml parallel(8) */ into t2 select * from t1;
ENABLE_PARALLEL_DAS_DML Hint
ENABLE_PARALLEL_DAS_DML Hint specifies to enable concurrent writes using the Distributed Data Access Service (DAS) for the current DML statement. Its reverse Hint is DISABLE_PARALLEL_DAS_DML.
Considerations
ENABLE_PARALLEL_DAS_DMLmust be used together withENABLE_PARALLEL_DML.When using the Hint
/*+ENABLE_PARALLEL_DAS_DML ENABLE_PARALLEL_DML PARALLEL(n)*/, the system will enforce the use of DAS concurrent writes based on the specified parallelism level inPARALLEL(n).If the system parameter
_enable_parallel_das_dmlis set totrueusing theALTER SYSTEM SETstatement (default isfalse), the Hint/*+ENABLE_PARALLEL_DAS_DML ENABLE_PARALLEL_DML PARALLEL(n)*/will be ineffective. In this case, the system will not perform DAS concurrent writes.
Syntax
/*+ ENABLE_PARALLEL_DAS_DML */
Examples
insert /*+ ENABLE_PARALLEL_DAS_DML ENABLE_PARALLEL_DML PARALLEL(10)*/
into t1 select * from t2;
DISABLE_PARALLEL_DAS_DML Hint
DISABLE_PARALLEL_DAS_DML Hint specifies to disable concurrent writes using the Distributed Data Access Service (DAS) for the current DML statement. Its reverse Hint is ENABLE_PARALLEL_DAS_DML.
Considerations
DISABLE_PARALLEL_DAS_DMLmust be used together withENABLE_PARALLEL_DML.When using the Hint
/*+DISABLE_PARALLEL_DAS_DML ENABLE_PARALLEL_DML PARALLEL(n)*/, the system will disable DAS concurrent writes, even if other concurrent write optimization options like PDML are enabled.
Syntax
/*+ DISABLE_PARALLEL_DAS_DML */
Examples
insert /*+ DISABLE_PARALLEL_DAS_DML ENABLE_PARALLEL_DML PARALLEL(10)*/
into t1 select * from t2;
LOAD_BATCH_SIZE Hint
LOAD_BATCH_SIZE Hint specifies the size of the batch of records inserted each time in LOAD DATA.
In the LOAD_BATCH_SIZE Hint, batch_size specifies the size of the batch of records inserted each time. For more information about LOAD DATA, see LOAD DATA.
Syntax
/*+ LOAD_BATCH_SIZE ( batch_size ) */
Examples
-- Use four parallel processes to import data, append new data to the end of the table, and specify that each batch processes 1,000 records using the `LOAD_BATCH_SIZE` Hint.
LOAD DATA /*+ PARALLEL(4) APPEND LOAD_BATCH_SIZE(1000) */
INFILE '/home/admin/test.csv' INTO TABLE t1;
LOG_LEVEL Hint
LOG_LEVEL Hint specifies the log level for the current query during execution.
In the LOG_LEVEL Hint, log_level specifies the log level. Common log levels include ERROR, WARN, INFO, TRACE, and DEBUG.
For more information about log levels, see Log levels.
Syntax
/*+ LOG_LEVEL ( [']log_level['] ) */
Examples
-- Use the LOG_LEVEL Hint to specify the `TRACE` log level.
SELECT /*+ LOG_LEVEL(TRACE) */ *
FROM employees e
WHERE e.department_id = 1001;
MAX_CONCURRENT Hint
MAX_CONCURRENT Hint specifies the maximum number of concurrent queries allowed for the specified query.
In the MAX_CONCURRENT Hint, intnum specifies the maximum number of concurrent queries allowed for the specified query. If the number of concurrent queries exceeds the maximum allowed, an error is returned when the query is executed. If intnum is specified as 0, an error is always returned when the query is executed.
Note that MAX_CONCURRENT Hint cannot be directly used in a query. Instead, you can create an outline containing only the MAX_CONCURRENT Hint to limit the concurrency of specific SQL statements.
Syntax
/*+ MAX_CONCURRENT ( intnum ) */
Examples
-- This query creates an outline named otl1 associated with the identifier 'EC102CB006383D732BC98797601D9B3B' and specifies that the maximum number of concurrent executions for the corresponding query is 10.
CREATE OUTLINE otl1 ON 'EC102CB006383D732BC98797601D9B3B'
USING HINT /*+ max_concurrent(10) */;
MONITOR Hint
MONITOR Hint enables capturing the execution process of the query in the SQL Plan Monitor. You can use MONITOR Hint to record the execution process of the query in the SQL Plan Monitor.
If parallel execution is not enabled for the query, OceanBase Database does not record the execution process of the query in the SQL Plan Monitor.
For more information about the SQL Plan Monitor, see the Real-time SQL Plan Monitor section in Display real-time execution plans.
Syntax
/*+ MONITOR */
Examples
-- Use the MONITOR Hint to enable SQL Plan Monitor.
SELECT /*+monitor*/ c1, SUM(distinct c2) FROM t1 GROUP BY c1;
Query rewrite hints
Query rewrite control includes MV_REWRITE and NO_MV_REWRITE hints, and these hints have a higher priority than the system variable query_rewrite_enabled.
MV_REWRITE Hint
The syntax of the MV_REWRITE hint is as follows:
/*+ MV_REWRITE (@ queryblock [mv_name_list]) */
mv_name_list:
mv_name [, mv_name ...]
When you use the MV_REWRITE hint alone, the query rewrite rules and cost checks are skipped, and the available rewrite is directly used. If you specify one or more materialized views after the hint, in addition to skipping the rules and cost checks, the query rewrite will only use the specified materialized views to attempt the rewrite, ignoring all unspecified materialized views.
When you use the MV_REWRITE hint to specify materialized views, you cannot force the use of materialized views without the ENABLE QUERY REWRITE clause (which enables automatic rewrite for the current materialized view). Additionally, you cannot force the use of non-real-time materialized views when the system variable query_rewrite_integrity is set to enforced.
NO_MV_REWRITE Hint
The syntax of the NO_MV_REWRITE hint is as follows:
/*+ NO_MV_REWRITE (@ queryblock) */
The NO_MV_REWRITE hint disables query rewrite and allows you to specify a query block.
Examples of query rewrite control hints
Create the base table
tbl2.CREATE TABLE tbl2 (col1 INT, col2 INT);Insert two rows of data into the base table
tbl2.INSERT INTO tbl2 VALUES (1,2),(3,4);The return result is as follows:
Query OK, 2 rows affected Records: 2 Duplicates: 0 Warnings: 0Create the materialized view
mv1_tbl2and enable automatic rewrite for it.CREATE MATERIALIZED VIEW mv1_tbl2 NEVER REFRESH ENABLE QUERY REWRITE AS SELECT * FROM tbl2;Create the materialized view
mv2_tbl2and enable automatic rewrite for it.CREATE MATERIALIZED VIEW mv2_tbl2 NEVER REFRESH ENABLE QUERY REWRITE AS SELECT * FROM tbl2 WHERE tbl2.col1 > 1;Set the system variable
query_rewrite_integritytostale_tolerated.Note
The
MV_REWRITEandNO_MV_REWRITEhints have a higher priority than the system variablequery_rewrite_enabled. Therefore, you do not need to setquery_rewrite_enabled. However, you need to setquery_rewrite_integritytostale_toleratedto use non-real-time materialized views for rewriting.SET query_rewrite_integrity = 'stale_tolerated';Use the
MV_REWRITEhint to attempt a rewrite using a materialized view, skipping the rewrite cost and rule checks. The following two queries will use the materialized viewmv1_tbl2for rewriting./*+mv_rewrite*/will attempt to use a materialized view that meets the rewrite conditions for rewriting. Once a suitable materialized view is found, subsequent materialized views will be ignored, and the rewrite cost and rule checks will be skipped.EXPLAIN SELECT /*+mv_rewrite*/ count(*), col1 FROM tbl2 WHERE tbl2.col1 > 1 GROUP BY col1;The return result is as follows:
+----------------------------------------------------------------------------------------------+ | Query Plan | +----------------------------------------------------------------------------------------------+ | ===================================================== | | |ID|OPERATOR |NAME |EST.ROWS|EST.TIME(us)| | | ----------------------------------------------------- | | |0 |HASH GROUP BY | |1 |3 | | | |1 |└─TABLE FULL SCAN|MV1_TBL2|1 |3 | | | ===================================================== | | Outputs & filters: | | ------------------------------------- | | 0 - output([T_FUN_COUNT(*)], [MV1_TBL2.COL1]), filter(nil), rowset=16 | | group([MV1_TBL2.COL1]), agg_func([T_FUN_COUNT(*)]) | | 1 - output([MV1_TBL2.COL1]), filter([MV1_TBL2.COL1 > cast(1, NUMBER(-1, -85))]), rowset=16 | | access([MV1_TBL2.COL1]), partitions(p0) | | is_index_back=false, is_global_index=false, filter_before_indexback[false], | | range_key([MV1_TBL2.__pk_increment]), range(MIN ; MAX)always true | +----------------------------------------------------------------------------------------------+ 14 rows in set/*+mv_rewrite(mv1_tbl2)*/will attempt to usemv2_tbl2for rewriting, skipping the rewrite cost and rule checks.EXPLAIN SELECT /*+mv_rewrite(mv2_tbl2)*/ count(*), col1 FROM tbl2 WHERE tbl2.col1 > 1 GROUP BY col1;The return result is as follows:
+-------------------------------------------------------------------------+ | Query Plan | +-------------------------------------------------------------------------+ | ===================================================== | | |ID|OPERATOR |NAME |EST.ROWS|EST.TIME(us)| | | ----------------------------------------------------- | | |0 |HASH GROUP BY | |1 |3 | | | |1 |└─TABLE FULL SCAN|MV2_TBL2|1 |3 | | | ===================================================== | | Outputs & filters: | | ------------------------------------- | | 0 - output([T_FUN_COUNT(*)], [MV2_TBL2.COL1]), filter(nil), rowset=16 | | group([MV2_TBL2.COL1]), agg_func([T_FUN_COUNT(*)]) | | 1 - output([MV2_TBL2.COL1]), filter(nil), rowset=16 | | access([MV2_TBL2.COL1]), partitions(p0) | | is_index_back=false, is_global_index=false, | | range_key([MV2_TBL2.__pk_increment]), range(MIN ; MAX)always true | +-------------------------------------------------------------------------+ 14 rows in set
Although the query specifies using
mv2_tbl2for rewriting, theWHEREcondition in the query does not meet the requirements, somv2_tbl2cannot be used for rewriting. Therefore, no materialized view rewriting will be performed.EXPLAIN SELECT /*+mv_rewrite(mv2_tbl2)*/ count(*), col1 FROM tbl2 WHERE tbl2.col1 < 1 GROUP BY col1;The return result is as follows:
+--------------------------------------------------------------------------------------+ | Query Plan | +--------------------------------------------------------------------------------------+ | ================================================= | | |ID|OPERATOR |NAME|EST.ROWS|EST.TIME(us)| | | ------------------------------------------------- | | |0 |HASH GROUP BY | |1 |3 | | | |1 |└─TABLE FULL SCAN|TBL2|1 |3 | | | ================================================= | | Outputs & filters: | | ------------------------------------- | | 0 - output([T_FUN_COUNT(*)], [TBL2.COL1]), filter(nil), rowset=16 | | group([TBL2.COL1]), agg_func([T_FUN_COUNT(*)]) | | 1 - output([TBL2.COL1]), filter([TBL2.COL1 < cast(1, NUMBER(-1, -85))]), rowset=16 | | access([TBL2.COL1]), partitions(p0) | | is_index_back=false, is_global_index=false, filter_before_indexback[false], | | range_key([TBL2.__pk_increment]), range(MIN ; MAX)always true | +--------------------------------------------------------------------------------------+ 14 rows in setUse the
/*+ no_mv_rewrite*/hint to disable materialized view rewriting.EXPLAIN SELECT /*+no_mv_rewrite*/ count(*), col1 FROM tbl2 WHERE tbl2.col1 > 1 GROUP BY col1;The return result is as follows:
+--------------------------------------------------------------------------------------+ | Query Plan | +--------------------------------------------------------------------------------------+ | ================================================= | | |ID|OPERATOR |NAME|EST.ROWS|EST.TIME(us)| | | ------------------------------------------------- | | |0 |HASH GROUP BY | |1 |3 | | | |1 |└─TABLE FULL SCAN|TBL2|1 |3 | | | ================================================= | | Outputs & filters: | | ------------------------------------- | | 0 - output([T_FUN_COUNT(*)], [TBL2.COL1]), filter(nil), rowset=16 | | group([TBL2.COL1]), agg_func([T_FUN_COUNT(*)]) | | 1 - output([TBL2.COL1]), filter([TBL2.COL1 > cast(1, NUMBER(-1, -85))]), rowset=16 | | access([TBL2.COL1]), partitions(p0) | | is_index_back=false, is_global_index=false, filter_before_indexback[false], | | range_key([TBL2.__pk_increment]), range(MIN ; MAX)always true | +--------------------------------------------------------------------------------------+ 14 rows in set
NO_PARALLEL Hint
The NO_PARALLEL hint disables query parallelism (i.e., sets the parallelism to 1). Its opposite hint is the PARALLEL hint.
The NO_PARALLEL hint is equivalent to /*+ parallel(1)*/.
Syntax
/*+ NO_PARALLEL */
Example
The following query example uses the NO_PARALLEL hint to disable query parallelism.
SELECT /*+ no_parallel */ c1, sum(distinct c2) FROM t1 GROUP BY c1;
NO_QUERY_TRANSFORMATION Hint
The NO_QUERY_TRANSFORMATION hint disables any query rewriting for the current query.
It is important to note that unlike the NO_REWRITE hint in the Query Block Hint, using NO_QUERY_TRANSFORMATION prevents the use of Query Block Hints to enable certain rewritings.
For more information about query rewriting, see Overview of query rewriting.
Syntax
/*+ NO_QUERY_TRANSFORMATION */
Example
The following query example uses the NO_QUERY_TRANSFORMATION hint to disable any query rewriting.
SELECT /*+ NO_QUERY_TRANSFORMATION */ *
FROM (SELECT * FROM t1) v WHERE v.c1 = 3;
OPT_PARAM Hint
The OPT_PARAM Hint specifies optimizer-related configuration items or system variables at the query level.
Syntax
/*+ OPT_PARAM ( parameter_name [,] parameter_value ) */
Parameters
parameter_name: the name of the configuration item or system variable.parameter_value: the value of the variable. TheOPT_PARAMHint is valid for the following parameters:rowsets_enabled: specifies whether to enable or disable vectorization. The data type isVARCHAR, and the value can be either'TRUE'or'FALSE'. The value must be enclosed in single quotation marks ('').rowsets_max_rows: specifies the size of the batch size for returning rows. The data type isINT, and the value can be in the range [0, 65535]. The value must not be enclosed in single quotation marks ('').enable_newsort: specifies whether to enable or disable the newsort optimization. The data type isVARCHAR, and the value can be either'TRUE'or'FALSE'. The value must be enclosed in single quotation marks ('').use_part_sort_mgb: specifies whether to enable or disable the part sort merge group by. The data type isVARCHAR, and the value can be either'TRUE'or'FALSE'. The value must be enclosed in single quotation marks ('').enable_in_range_optimization: specifies whether to enable or disable the in optimization. The data type isVARCHAR, and the value can be either'TRUE'or'FALSE'. The value must be enclosed in single quotation marks ('').xsolapi_generate_with_clause: specifies whether to enable or disable the CTE extraction rewrite. The data type isVARCHAR, and the value can be either'TRUE'or'FALSE'. The value must be enclosed in single quotation marks ('').preserve_order_for_pagination: specifies whether to add anorder byclause for pagination queries. The data type isVARCHAR, and the value can be either'TRUE'or'FALSE'. The value must be enclosed in single quotation marks ('').storage_card_estimation: specifies whether to use the storage layer for row estimation. The data type isVARCHAR, and the value can be either'TRUE'or'FALSE'. The value must be enclosed in single quotation marks ('').workarea_size_policy: specifies the strategy for manually or automatically adjusting the SQL workarea size. The data type isVARCHAR, and the value can be either'MANUAL'for manual adjustment or'AUTO'for automatic adjustment. The value must be enclosed in single quotation marks ('').enable_rich_vector_format: specifies whether to enable or disable vectorization 2.0 (session-level parameter). The data type isVARCHAR, and the value can be either'TRUE'or'FALSE'. The value must be enclosed in single quotation marks ('').spill_compression_codec: specifies the compression algorithm for operators that require temporary materialization. The data type isVARCHAR, and the value can beNONE,LZ4,SNAPPY,ZLIB, orZSTD, representing different compression algorithms. The default value isNONE, indicating no compression.inlist_rewrite_threshold: specifies the threshold for triggering the rewrite ofinlistto avalues statement. The data type isINT64, and the value can be in the range [1, 2147483647].
Examples
The following example uses the OPT_PARAM Hint to enable the IN optimization for the current query by specifying the enable_in_range_optimization value.
SELECT /*+ opt_param('enable_in_range_optimization', 'true') */ *
from t1
where c1 in (1,2,3,4,5,...,1000)
and c2 in (1,2,3,4,5,...,1000);
PARALLEL Hint
As a global hint, the PARALLEL Hint specifies the parallelism or parallelism strategy for the current query.
In addition to being a global hint, the PARALLEL Hint can also be used as a query block hint to specify the parallelism at the table level. For more information, see the Parallel hint section in Access Path Hints.
Syntax
/*+ PARALLEL ( AUTO | MANUAL | parallel_degree) */
Parameters
AUTOorMANUAL: whenAUTOorMANUALis used as the parameter in thePARALLELHint, it specifies the parallel execution strategy. For more information, see Parallel Execution Strategies and Priorities.parallel_degree: whenparallel_degreeis used as the parameter in thePARALLELHint, it specifies the parallelism directly.
Examples
The following examples use the PARALLEL Hint to specify a parallelism of DOP = 8 or to enable Auto DOP.
SELECT /*+parallel(8)*/ c1, SUM(distinct c2) FROM t1 GROUP BY c1;
SELECT /*+parallel(auto)*/ c1, SUM(distinct c2) FROM t1 GROUP BY c1;
Note: In some scenarios, parallel execution is not supported, and even if you specify the PARALLEL hint to enable parallel execution, the execution plan may still disable parallel execution.
QUERY_TIMEOUT Hint
The QUERY_TIMEOUT Hint specifies the execution timeout for the current query.
Syntax
/*+ QUERY_TIMEOUT ( time_usec ) */
Parameters
time_usec: the query timeout, in microseconds.
Examples
-- Specifies a query timeout of 1 second. If the query is not completed within the specified timeout, a timeout error is returned.
SELECT /*+ QUERY_TIMEOUT(1000000) */ *
FROM employees e
WHERE e.department_id = 1001;
READ_CONSISTENCY Hint
The READ_CONSISTENCY Hint specifies the read consistency level for the current query.
Syntax
/*+ READ_CONSISTENCY(WEAK[STRONG]) */
Parameters
WEAK: enables weak consistency, i.e., weak reads.STRONG: enables strong consistency, i.e., disables weak reads.
Examples
-- Uses the READ_CONSISTENCY Hint and sets it to WEAK to enable weak reads for the query.
SELECT /*+ READ_CONSISTENCY(WEAK) */ *
FROM employees
WHERE employees.department_id = 1001;
RESOURCE_GROUP Hint
The RESOURCE_GROUP hint specifies the resource group for the current statement.
Syntax
The syntax of the RESOURCE_GROUP hint is as follows:
/*+ RESOURCE_GROUP ('resource_group_name') */
Parameters
resource_group_name: specifies the name of the resource group.
Examples
Here is an example of using the RESOURCE_GROUP hint:
obclient> SELECT /*+ RESOURCE_GROUP('big_group') */ * FROM t1;
If the resource group big_group does not exist, the default resource group is used.
STAT Hint
The STAT hint specifies to trace the output of a specific operator in the query plan.
After you add the STAT hint, the query plan contains a MONITORING DUMP operator. This operator outputs all data of the child operator and prints the operator execution time and the number of output rows in the observer log after the execution.
Syntax
/*+ STAT(TRACING_NUM_LIST) */
Parameters
TRACING_NUM_LIST: specifies the IDs of the operators to trace.
Examples
-- The execution plans before and after adding the `/*+ STAT(0, 2) */` hint.
explain basic
SELECT /*+leading(t1) use_hash(t2)*/ * FROM t1, t2 WHERE t1.c1 = t2.c1;
Query Plan
===========================
|ID|OPERATOR |NAME|
---------------------------
|0 |HASH JOIN | |
|1 |├─TABLE FULL SCAN|T1 |
|2 |└─TABLE FULL SCAN|T2 |
===========================
explain basic
SELECT /*+leading(t1) use_hash(t2) stat(0, 2)*/ *
FROM t1, t2 where t1.c1 = t2.c1;
Query Plan
===============================
|ID|OPERATOR |NAME|
-------------------------------
|0 |MONITORING DUMP | |
|1 |└─HASH JOIN | |
|2 | ├─TABLE FULL SCAN |T1 |
|3 | └─MONITORING DUMP | |
|4 | └─TABLE FULL SCAN|T2 |
===============================
TRANS_PARAM Hint
The TRANS_PARAM hint specifies transaction-related parameters at the query level.
Syntax
/*+ TRANS_PARAM ['FORCE_EARLY_LOCK_FREE' , 'TRUE'] */
Parameters
Currently, only the FORCE_EARLY_LOCK_FREE parameter is supported, which specifies whether to enable early row lock release at the transaction level.
FORCE_EARLY_LOCK_FREE: specifies whether to enable early row lock release at the transaction level. Valid values: TRUE (enabled) and FALSE (disabled).
Notice: The parameter name and value must be enclosed in single quotation marks ( ' '). If the value is a numeric value, you can omit the quotation marks.
Examples
-- Use the `TRANS_PARAM` hint and set the `FORCE_EARLY_LOCK_FREE` parameter to `TRUE` to enable early row lock release at the transaction level.
SELECT /*+ TRANS_PARAM('FORCE_EARLY_LOCK_FREE' 'TRUE') */ *
FROM employees e
WHERE e.department_id = 1001;
TRACING Hint
The TRACING hint specifies to trace the output of a specific operator in the query plan.
The usage of the TRACING hint, the plan after adding the hint, and the usage of the STAT hint are the same.
The difference between the TRACING and STAT hints is that the MONITORING DUMP operator prints all output data in the observer log when the TRACING hint is used.
Syntax
/*+ TRACING(TRACING_NUM_LIST)*/
Parameters
TRACING_NUM_LIST: specifies the IDs of the operators to trace.
Examples
-- Use the `TRACING` hint and set the level to 1 to enable tracing for the current query.
SELECT /*+ TRACING(1) */ *
FROM employees e
WHERE e.department_id = 1001;
USE_PLAN_CACHE Hint
The USE_PLAN_CACHE hint specifies the plan cache (Plan Cache) usage strategy for the current query. For more information about the plan cache, see Execution plan cache.
Syntax
/*+ USE_PLAN_CACHE ( NONE | DEFAULT ) */
Parameters
NONE: specifies that the query does not use the plan cache.DEFAULT: specifies that the current query uses the system variableob_enable_plan_cacheto control the plan cache strategy.
Examples
-- If you specify `NONE`, the query does not use the plan cache. If you specify `DEFAULT`, the current query uses the system variable `ob_enable_plan_cache` to control the plan cache strategy.
SELECT /*+ USE_PLAN_CACHE(NONE) */ *
FROM employees e
WHERE e.department_id = 1001;
SELECT /*+ USE_PLAN_CACHE(DEFAULT) */ *
FROM employees e
WHERE e.department_id = 1001;