citusdata / pg_shard

ATTENTION: pg_shard is superseded by Citus, its more powerful replacement
https://github.com/citusdata/citus
GNU Lesser General Public License v3.0
1.06k stars 63 forks source link

Bugfix volalite functions#47 #102

Closed onderkalaci closed 9 years ago

onderkalaci commented 9 years ago

This pull request prevents WHERE clause statements to have VOLATILE or MUTABLE functions.

Fixes #47

Review tasks

onderkalaci commented 9 years ago

@jasonmp85 I think we can do a similar change for this line. In other words, instead of checking

!IsA(targetEntry->expr, Const)

We can do something like:

contain_mutable_functions((targetEntry->exp) ||
    contain_volatile_functions((targetEntry->exp))  

But, since the issue only considers QUALs, I didn't want to do that here.

jasonmp85 commented 9 years ago

@onderkalaci this looks good and after the small style changes (and removing the redundant call), it's a :shipit:.

jasonmp85 commented 9 years ago

Accidentally closed, sorry!

jasonmp85 commented 9 years ago

@onderkalaci on the topic of !IsA(targetEntry->expr, Const), we already know any function calls we see in the target list must be mutable. This is because we have already called the standard_planner on the query. That in turn calls eval_const_expressions, which eagerly replaces any immutable functions with their output (this also applies to the quals; for instance, doing an UPDATE … WHERE foo = (1 + 1) becomes UPDATE … WHERE foo = 2).

So for target lists, we only accept constants, but for quals, there might be a column reference (LHS), operator, and value (RHS). In that case, the standard planner may have collapsed the RHS to a constant (if, as above it's something like 1+1), but the operator call is still there. But e.g. = is IMMUTABLE so it needs to make it through.

jasonmp85 commented 9 years ago

So I guess I'm saying the walker is overkill for the target list but is needed for the quals, so what we have here is now complete.

jasonmp85 commented 9 years ago

Added checklist up to. Fix and submit the changes and I'll merge tomorrow if all looks good.

onderkalaci commented 9 years ago

@jasonmp85 all your comments make sense and I applied the changes.

jasonmp85 commented 9 years ago

Looks good. Merging.