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

fix: optimisable height functions #268

Merged
merged 2 commits into from
Dec 2, 2020
Merged

fix: optimisable height functions #268

merged 2 commits into from
Dec 2, 2020

Conversation

olizilla
Copy link
Contributor

@olizilla olizilla commented Nov 26, 2020

add attributes to the height functions to allow postgres to optimise them

  • IMMUTABLE - the function cannot modify the database and always returns the same result when given the same argument value
  • RETURNS NULL ON NULL INPUT - the function is not executed when there are null arguments; instead a null result is assumed automatically.
  • PARALLEL SAFE - safe to run in parallel mode without restriction.

with these in place my test query execution time goes down from 3m40s to 12s, which is as fast as the inlined, functionless version.

see: https://www.postgresql.org/docs/12/sql-createfunction.html

License: MIT
Signed-off-by: Oli Evans [email protected]

@olizilla
Copy link
Contributor Author

This change is idempotent and is already applied to the monitoring and analysis dbs

@alanshaw
Copy link
Member

Just, facinating.

IMMUTABLE RETURNS NULL ON NULL INPUT PARALLEL SAFE - I bet that's a sentence you never thought you'd type.

@iand iand force-pushed the olizilla/height-fun-fast branch from 520538c to 4248e0a Compare December 2, 2020 16:32
olizilla and others added 2 commits December 2, 2020 16:46
add attributes to the height functions to allow postgres to optimise them
- IMMUTABLE - the function cannot modify the database and always returns the same result when given the same argument value
- RETURNS NULL ON NULL INPUT - the function is not executed when there are null arguments; instead a null result is assumed automatically.
- PARALLEL SAFE - safe to run in parallel mode without restriction.

with these in place my test query execution time goes down from 3m40s to 12s, which is as fast as the inlined, funtionless version

License: MIT
Signed-off-by: Oli Evans <[email protected]>
@iand iand force-pushed the olizilla/height-fun-fast branch from 4248e0a to 902759d Compare December 2, 2020 16:47
@iand iand merged commit 66cd49d into master Dec 2, 2020
@iand iand deleted the olizilla/height-fun-fast branch December 2, 2020 17:14
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

Successfully merging this pull request may close these issues.

3 participants