Description
To safely enable predicate constant folding, as introduced in #3411, we propose adding constraints to extracted literals from the query. These constraints should apply regardless of whether the literals originate directly from the query text or are provided through prepared statement parameters.
These constraints must be consistent with the constant folding rules, which are triggered by:
- Explicit boolean values (
true
,false
). - Explicit null values.
- Whether a literal is not null.
Implementing these constraints is crucial to prevent the use of physical plans generated based on assumptions about literal values that may not hold true during subsequent query executions. This can occur when the actual literal values differ from those initially assumed.
Therefore, the plan generator should analyze the literals and generate necessary constraints about their values according to the above rules to be used in the plan cache key.