This topic describes the OPT_PARAM hint of PolarDB for PostgreSQL(Compatible with Oracle).

You can specify the values of specific parameters at the database level, session level, or user level. This method is traditional. When you execute a SQL statement, you cannot control the values of specific parameters for the statement. In this case, you can use the OPT_PARAM hint to specify the values of specific parameters for a SQL statement. Such values are valid only in the SQL statement.

Syntax

SELECT /*+ opt_param("enable_hashjoin" "off"),
opt_param("enable_mergejoin" "off") */ ...;

Parameters

The OPT_PARAM hint allows you to specify the values of the following parameters:
ParameterDescription
enable_hashjoinSpecifies whether to enable the query planner to use hash-join plan types.
enable_mergejoinSpecifies whether to enable the query planner to use merge-join plan types.
enable_nestloopSpecifies whether to enable the query planner to use nested-loop join plans. Nested-loop joins cannot be completely prohibited. However, if you disable this parameter, the planner prioritizes other methods.
enable_bitmapscanSpecifies whether to enable the query planner to use bitmap-scan plan types.
enable_indexonlyscanSpecifies whether to enable the query planner to use index-only-scan plan types.
enable_indexscanSpecifies whether to enable the query planner to use index-scan plan types.
enable_materialSpecifies whether to enable the query planner to use materialization. Materialization cannot be completely prohibited. However, if you disable this parameter, the planner cannot insert materialization nodes.
enable_seqscanSpecifies whether to enable the query planner to use sequential scan plan types. Sequential scans cannot be completely prohibited. However, if you disable this parameter, the planner prioritizes other methods.
enable_sortSpecifies whether to enable the query planner to use explicit sort steps. Explicit sorts cannot be completely prohibited. However, if you disable this parameter, the planner prioritizes other methods.
enable_tidscanSpecifies whether to enable the query planner to use TID scan plan types.
enable_gathermergeSpecifies whether to enable the query planner to use gather-merge plan types.
enable_hashaggSpecifies whether to enable the query planner to use hashed aggregation plan types.
enable_parallel_appendSpecifies whether to enable the query planner to use parallel-aware append plan types.
enable_parallel_hashSpecifies whether to enable the query planner to use hash-join plan types for parallel hashes. If hash-join plans are not enabled, this parameter does not take effect.
enable_partition_pruningSpecifies whether to enable the query planner to eliminate a partitioned table's partitions from query plans. It also controls the query planner's ability to generate query plans which allow the query executor to remove (ignore) partitions during query execution.
enable_partitionwise_aggregateSpecifies whether to enable the query planner to use partitionwise grouping or aggregation, which allows grouping or aggregation on a partitioned tables performed separately for each partition. If the GROUP BY clause does not include the partition keys, only partial aggregation can be performed on a per-partition basis, and finalization must be performed later.
enable_partitionwise_joinSpecifies whether to enable the query planner to use partitionwise join, which allows a join between partitioned tables to be performed by joining the matching partitions. Partitionwise join currently applies only when the join conditions include all the partition keys, which must be of the same data type and have one-to-one matching sets of child partitions.

Example

Do not use the OPT_PARAM hint:
EXPLAIN (COSTS OFF) SELECT * FROM sampletable WHERE x < 423;
Use the OPT_PARAM hint and set the enable_bitmapscan parameter to off to disable the query planner to use bitmap-scan plan types:
EXPLAIN (COSTS OFF) SELECT /*+ opt_param("enable_bitmapscan" "off") */ * FROM sampletable WHERE x < 423;
Use the OPT_PARAM hint and set the enable_mergejoin parameter to off to disable the query planner to use merge-join plan types:
EXPLAIN (COSTS OFF) SELECT /*+ opt_param("enable_mergejoin" "off") */ tt1.*, tt2.* FROM tt1 JOIN tt2 on tt1.joincol = tt2.joincol;
Use the OPT_PARAM hint and set the enable_hashjoin parameter to on to enable the query planner to use hash-join plan types:
EXPLAIN (COSTS OFF) SELECT/*+ opt_param("enable_hashjoin" "on") */ tt1.*, tt2.* FROM tt1 JOIN tt2 on tt1.joincol = tt2.joincol;