Skip to content

2.27.0.0-b494

@fizaaluthra fizaaluthra tagged this 27 Aug 04:15
Summary:
This revision enables the now() function to be pushed down to DocDB by evaluating it once during query execution and replacing it with a constant in the pushdown qualifiers.

Although now() is a stable (not immutable) function, it returns a consistent value throughout the duration of a transaction. Previously, it was evaluated in YSQL as a filter for each row.

To address this:
- Create a new list of functions, `yb_pushdown_funcs_to_constify`, that can be evaluated to a constant at execution time and then pushed down to DocDB. Add `now()` to this list, and have `yb_can_pushdown_func` return true for such functions.
- `YbInstantiatePushdownParams`, `YbExprInstantiateParams` and `yb_expr_instantiate_params_mutator` are renamed to `YbInstantiatePushdownExprs`, `YbExprInstantiateExprs` and `yb_expr_instantiate_exprs_mutator`
- `YbInstantiatePushdownParams` now includes logic to evaluate certain functions that are marked safe for pushdown and are to be replaced with a constant (checked using `yb_can_constify_and_pushdown_func`)

Note: we will still have to do per-row filtering in YSQL when we are evaluating a timestamp column against `now()`. This is because the comparison operators between timestamp and timestamptz (the function timestamp_eq_timestamptz) are stable functions that depend on the local session's timezone setting. These functions perform the comparison by converting the timestamp value to a timestamptz value (based on the session's timezone setting). Moreover, converting timestamptz to timestamp is not semantically equivalent.
Jira: DB-15864

Test Plan: ./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressDml'

Reviewers: amartsinchyk

Reviewed By: amartsinchyk

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D45638
Assets 2
Loading