Oracle 参数 APPROX_FOR_COUNT_DISTINCT 官方解释,作用,如何配置最优化建议
本站中文解释
APPROX_FOR_COUNT_DISTINCT(计数唯一估算值参数)参数用于控制在条件中指定的唯一列的COUNT(DISTINCT)函数的估计行数的精确度。这个设置对于对结果中返回的值有一定的影响,当我们想要快速执行查询时,可以设置这个参数以允许较低精度的COUNT(DISTINCT)的估计值或使用人工的精确的SQL的优化方案,这就是APPROX_FOR_COUNT_DISTINCT参数的作用。
APPROX_FOR_COUNT_DISTINCT可以选择两个参数值:FALSE 和TRUE,默认是FALSE,即不启用估计参数,FALSE时查询只返回精确值;而TRUE时表示使用统计信息进行估计。
正确设置APPROX_FOR_COUNT_DISTINCT的步骤如下:
1、登录数据库实例:
SQL> CONNECT SYS/ as SYSDBA;
2、更改参数:
SQL> ALTER SYSTEM SET APPROX_FOR_COUNT_DISTINCT=TRUE SCOPE=BOTH;
3、确认参数更改:
SQL>show parameter approx;
4、执行影响变更生效:
SQL> ALTER SYSTEM FLUSH SHARED_POOL;
官方英文解释
APPROX_FOR_COUNT_DISTINCT
automatically replaces COUNT (DISTINCT expr)
queries with APPROX_COUNT_DISTINCT
queries.
Property | Description |
---|---|
Parameter type |
Boolean |
Default value |
|
Modifiable |
|
Modifiable in a PDB |
Yes |
Range of values |
|
Basic |
No |
Oracle RAC |
Different instances can use different values. |
Query results for APPROX_COUNT_DISTINCT
queries are returned faster than the equivalent COUNT (DISTINCT expr)
queries. APPROX_COUNT_DISTINCT
queries are useful for situations where a tolerable amount of error is acceptable in order to obtain faster query results than with a COUNT (DISTINCT expr)
query.
See Also:
-
“APPROX_FOR_AGGREGATION”
-
“APPROX_FOR_PERCENTILE”