Updated on 2025-05-29 GMT+08:00

Optimizer Cost Constants

This section describes the optimizer cost constants. The cost variables described here are measured on an arbitrary scale. Only their relative values matter, therefore scaling them all up or down by the same factor will result in no change in the optimizer's choices. By default, they use the cost of fetching sequential pages as the basic unit. That is, seq_page_cost is set to 1.0 and the other cost variables are set with reference to the parameter. However, you can use a different scale, such as actual execution time in milliseconds.

seq_page_cost

Parameter description: Specifies the optimizer's estimated cost of a disk page fetch that is part of a series of sequential fetches. This parameter can be set at the PDB level.

Parameter type: floating point

Unit: None

Value range: 0 to DBL_MAX

Default value: 1. In the PDB scenario, if this parameter is not set, the global settings will apply.

Setting method: This is a USERSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: This parameter affects the performance cost evaluation of sequentially fetching disk pages in a query. If this parameter is incorrectly set, the optimizer's selection of the generation plan is affected, and the query performance is affected in some scenarios. Exercise caution when modifying the parameter to avoid risks caused by misoperations.

random_page_cost

Parameter description: Specifies the optimizer's estimated cost of an out-of-sequence disk page fetch. This parameter can be set at the PDB level.

Parameter type: floating point

Unit: None

Value range: 0 to DBL_MAX

Default value: 4. In the PDB scenario, if this parameter is not set, the global settings will apply.

Setting method: This is a USERSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: See the parameter description.

Risks and impacts of improper settings: This parameter affects the performance cost evaluation of randomly fetching disk pages in a query. If this parameter is incorrectly set, the optimizer's selection of the generation plan is affected, and the query performance is affected in some scenarios. Exercise caution when modifying the parameter to avoid risks caused by misoperations.

  • Although the server allows you to set random_page_cost to a value less than that of seq_page_cost, it is not physically sensitive to do so. However, setting them equal makes sense if the database is entirely cached in RAM, because in that case there is no penalty for fetching pages out of sequence. Also, in a heavily-cached database you should lower both values relative to the CPU parameters, since the cost of fetching a page already in RAM is much smaller than it would normally be.
  • For tables and indexes in a specified tablespace, you can set a tablespace parameter with the same name to overwrite the database-level parameter value. That is, the priority of the tablespace-level parameter is higher than that of the database-level parameter.
  • Reducing this value relative to seq_page_cost will cause the system to prefer index scans and raising it will make index scans relatively more expensive. You can increase or decrease both values together to change the disk I/O costs relative to CPU costs.

cpu_tuple_cost

Parameter description: Specifies the optimizer's estimated cost of processing each row during a query. This parameter can be set at the PDB level.

Parameter type: floating point

Unit: None

Value range: 0 to DBL_MAX

Default value: 0.01. In the PDB scenario, if this parameter is not set, the global settings will apply.

Setting method: This is a USERSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: This parameter affects the evaluation of the performance cost for processing a row of data in a query. If this parameter is incorrectly set, the optimizer's selection of the generation plan is affected, and the query performance is affected in some scenarios. Exercise caution when modifying the parameter to avoid risks caused by misoperations.

cpu_index_tuple_cost

Parameter description: Specifies the optimizer's estimated cost of processing each index entry during an index scan. This parameter can be set at the PDB level.

Parameter type: floating point

Unit: None

Value range: 0 to DBL_MAX

Default value: 0.005. In the PDB scenario, if this parameter is not set, the global settings will apply.

Setting method: This is a USERSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: This parameter affects the performance cost evaluation of index scan in a query. If this parameter is incorrectly set, the optimizer's selection of the generation plan is affected, and the query performance is affected in some scenarios. Exercise caution when modifying the parameter to avoid risks caused by misoperations.

cpu_operator_cost

Parameter description: Specifies the optimizer's estimated cost of processing each operator or function executed during a query. This parameter can be set at the PDB level.

Parameter type: floating point

Unit: None

Value range: 0 to DBL_MAX

Default value: 0.0025. In the PDB scenario, if this parameter is not set, the global settings will apply.

Setting method: This is a USERSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: This parameter affects the performance cost evaluation of operators or functions in a query. If this parameter is incorrectly set, the optimizer's selection of the generation plan is affected, and the query performance is affected in some scenarios. Exercise caution when modifying the parameter to avoid risks caused by misoperations.

effective_cache_size

Parameter description: Specifies the optimizer's assumption about the effective size of the disk cache that is available to a single query. This parameter can be set at the PDB level.

Set this parameter based on the following factors: the GaussDB's shared buffer space, the kernel's disk buffer space, and the estimated number of concurrent queries on different tables that share the available space.

This parameter has no effect on the size of shared memory allocated by GaussDB. It is used only for estimation purposes and does not reserve kernel disk cache. The value is in the unit of disk page. Usually the size of each page is 8192 bytes.

Parameter type: Integer

Unit: page (8 KB)

Value range:

Method 1: Set this parameter to an integer without a unit. The integer ranges from 1 to 2147483647. For example, 200 indicates that there are 200 pages, that is, the size of 200 x 8 KB.

Method 2: Set this parameter to a value with a unit. The value ranges from 1 x 8 KB to 2147483647 x 8 KB. For example, the value 200MB indicates 200 MB. The unit can only be KB, MB, or GB.

Default value:

280GB (196-core CPU/1536 GB memory); 180GB (128-core CPU/1024 GB memory, 104-core CPU/1024 GB memory, 96-core CPU/1024 GB memory); 135GB (96-core CPU/768 GB memory); 100GB (80-core CPU/640 GB memory); 90GB (64-core CPU/512 GB memory); 80GB (60-core CPU/480 GB memory); 40GB (32-core CPU/256 GB memory); 18GB (16-core CPU/128 GB memory); 8GB (8-core CPU/64 GB memory); 4GB (4-core CPU/32 GB memory); 2GB (4-core CPU/16 GB memory). In the PDB scenario, if this parameter is not set, the global settings will apply.

Setting method: This is a USERSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: A value greater than the default one may enable index scan, and a value less than the default one may enable sequential scan.

Risks and impacts of improper settings: The optimizer's selection of the generation plan will be affected, and the query performance will be affected in some scenarios. Exercise caution when modifying the parameter to avoid risks caused by misoperations.

allocate_mem_cost

Parameter description: Specifies the query optimizer's estimated cost of creating a hash table for memory space using hash join. This parameter is used for optimization when the hash join estimation is inaccurate. This parameter can be set at the PDB level.

Parameter type: floating point

Unit: None

Value range: 0 to DBL_MAX

Default value: 0. In the PDB scenario, if this parameter is not set, the global settings will apply.

Setting method: This is a USERSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value. Adjust this parameter only when the Hash Join estimation is inaccurate.

Risks and impacts of improper settings: Hash Join estimation may be inaccurate, affecting query performance in some scenarios. Exercise caution when modifying the parameter to avoid risks caused by misoperations.