Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't push down comparisons to 'now()' #18

Closed
davidcrawford opened this issue Jun 28, 2013 · 2 comments
Closed

Doesn't push down comparisons to 'now()' #18

davidcrawford opened this issue Jun 28, 2013 · 2 comments

Comments

@davidcrawford
Copy link
Contributor

Since the code only pushes down quals that compare to T_Const, T_Param, and T_Var, it doesn't evaluate now() (a T_FuncExpr) and push down as a constant. I don't know enough about PostgreSQL development to know if this would be easy or hard. I'm happy to contribute this feature if you can give me a starting point.

@rdunklau
Copy link
Contributor

This is something I would really like to see happening: not treating the
T_Param specially, and using the whole expression evaluation.

Frankly, the current code to do this is quite ugly and only manages a
subset of the tree.

I'll try to look a bit deeper into it, but I think it would need the
following:

  • The building of the clauses (quals list and params list) is done at plan
    time, and cached for the execution. (via the extract_restrictions
    machinery). This must change, at least for params.
  • At plan time, the restrictions should be scanned again to find every
    T_Var OPERATOR AnyExpr clauses, and evaluate the right hand side (using
    ExecEvalExpr).

I don't really know what amount of work does that entail, but I'm convinced
the resulting code would be cleaner (no more awkward serialization between
plan and execution phase).

If I recall correctly, postgres_fdw does exactly that. You may look at it
for inspiration :)

2013/6/28 David Crawford notifications@github.com

Since the code only pushes down quals that compare to T_Const, T_Param,
and T_Var, it doesn't evaluate now() (a T_FuncExpr) and push down as a
constant. I don't know enough about PostgreSQL development to know if this
would be easy or hard. I'm happy to contribute this feature if you can give
me a starting point.


Reply to this email directly or view it on GitHubhttps://github.com//issues/18
.

@rdunklau
Copy link
Contributor

rdunklau commented Jul 2, 2013

I just pushed this to the master branch:

  • params are no longer treated specially
  • every expression on the right hand side which does not contain any volatile function (such as random) or a reference to the table itself (ie, col1 = some_function(col2)) will be evaluated at execution time.

@rdunklau rdunklau closed this as completed Jul 2, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants