Add immutable version of ash_raise_error
function to support extensions like Citus
#620
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We use the Citus extension for sharding our Postgres database, which adds a requirement that any functions used within CASE or COALESCE expressions must be IMMUTABLE. Currently this means that we can't use error expressions at all because
ash_raise_error
is currently marked as STABLE.The current
ash_raise_error
could technically be IMMUTABLE as it meets all of the requirements. However, the postgres planner will constant-fold the function call, making all expressions that use it immediately raise an exception. To prevent this we need to make the function call dependent on the row so it can't be constant-folded.This PR adds a new function,
ash_raise_error_immutable
, that is marked IMMUTABLE and accepts a third argument that is simply ignored. This works together with a change in AshSql that adds a row-dependent argument, preventing the caching.It's opt-in only via an
AshPostgres.Repo
callback, which stores a value in the repo config. AshSql looks for that config value when building the query and decides whether to call the existingash_raise_error
function, or the newash_raise_error_immutable
.Related AshSql PR: ash-project/ash_sql#175
Contributor checklist
Leave anything that you believe does not apply unchecked.