Note
This variable is available starting from V5.0.1.
Description
ob_udf_selectivity specifies the default selectivity of UDF equality predicates.
When the optimizer estimates the cost of queries containing UDF predicates, it uses this variable as the default selectivity of UDF equality predicates (such as udf(col) = 1), which participates in the calculation of predicate reordering. You can adjust this value based on the actual filtering effect of the UDF to influence the optimizer's decision on the execution order of predicates.
Privilege requirements
Query variables
Global level
systenant and all user tenants can execute theSHOW VARIABLESstatement or query theSYS.TENANT_VIRTUAL_GLOBAL_VARIABLEview (Oracle-compatible mode) or theinformation_schema.GLOBAL_VARIABLESview (MySQL-compatible mode) to obtain the value of a global system variable.Session level
systenant and all user tenants can execute theSHOW VARIABLESstatement or query theSYS.TENANT_VIRTUAL_SESSION_VARIABLEview (Oracle-compatible mode) or theinformation_schema.SESSION_VARIABLESview (MySQL-compatible mode) to obtain the value of a session system variable.
Modify variables
Global level
systenant can directly modify the value of a global system variable.MySQL user tenants must have the
SUPERorALTER SYSTEMprivilege to modify the value of a global system variable.Oracle user tenants must have the
ALTER SYSTEMprivilege to modify the value of a global system variable.
Session level
systenant and all user tenants can directly modify the value of a session system variable.
Attributes
Attribute |
Description |
|---|---|
| Type | numeric |
| Default value | 0.005 |
| Value range | [0.0, 1.0] |
| Scope |
|
| Affects plan generation | Yes. This variable has the INFLUENCE_PLAN flag. When the variable value changes, plan eviction is triggered. |
| Modifiable | Yes. You can execute the SET or ALTER SESSION SET statement to modify the value. |
Usage notes
ob_udf_selectivity and ob_udf_cost_factor jointly determine the rank value of UDF predicates in predicate reordering. The optimizer's goal is to place predicates with smaller rank values earlier in the execution order:
- The rank calculation formula is approximately
(selectivity - 1) / cost_factor. ob_udf_selectivityaffects the selectivity term: a smaller value means stronger UDF filtering capability (fewer rows retained), resulting in a smaller rank, and the UDF is more likely to be executed earlier.ob_udf_cost_factoraffects the cost term: a larger value means higher single-row processing cost of the UDF, resulting in a larger rank (closer to 0), and the UDF is more likely to be executed later.
In general, the default values are sufficient. You can adjust this variable when you have a clear expectation of the actual filtering capability of the UDF.
Examples
Set the UDF equality predicate selectivity to 0.999 (session level).
obclient> SET ob_udf_selectivity = 0.999;
Set the UDF equality predicate selectivity to 0.999 (global level).
obclient> SET GLOBAL ob_udf_selectivity = 0.999;
