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

More details for the immutable functions error message #64

Open
YAmikep opened this issue Aug 3, 2023 · 7 comments
Open

More details for the immutable functions error message #64

YAmikep opened this issue Aug 3, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@YAmikep
Copy link

YAmikep commented Aug 3, 2023

Hi

This project looks promising, I wanted to try it but I got the following error.

ERROR:  mutable function is not supported on incrementally maintainable materialized view
HINT:  functions must be marked IMMUTABLE 

SQL state: 0A000

I then marked ALL of my functions as IMMUTABLE but the error is still happening.

It would be helpful to have the name of the function that is causing the problem in the error message.

Thank you

@yugo-n yugo-n self-assigned this Aug 4, 2023
@yugo-n yugo-n added the enhancement New feature or request label Aug 4, 2023
@yugo-n
Copy link
Collaborator

yugo-n commented Aug 4, 2023

Thank you for your suggestion!
I'll fix it so that the message include the name of the causing function.

@yugo-n
Copy link
Collaborator

yugo-n commented Aug 4, 2023

After some investigation, I found this is not easer than I though initially...
We use a public function provied in PostgreSQL core code for this check, but this just returns whether given expression contains IMMUTABLE function or not, but does not return the function name. Actually, PostgreSQL doesn't report the function name in similar error messages; for example, ERROR: functions in index predicate must be marked IMMUTABLE

Therefore, we need make a special function for pg_ivm to meet your request. That is possible, but seems a bit redundant. I'll try to find a better way, but it may take a time.

@YAmikep
Copy link
Author

YAmikep commented Aug 4, 2023

@yugo-n Thanks for looking into this.

What PostgreSQL function do you use to check this?

I found the following

select proname, pronamespace::regnamespace, provolatile
from pg_proc

where proname is the function name and provolatile will equal i for immutable.

@yugo-n
Copy link
Collaborator

yugo-n commented Aug 5, 2023

What PostgreSQL function do you use to check this?

We use contain_mutable_functions that recursively searches for mutable functions within a clause and returns true if any mutable function (or operator implemented by a mutable function) is found.

@YAmikep
Copy link
Author

YAmikep commented Aug 5, 2023

We use contain_mutable_functions that recursively searches for mutable functions within a clause and returns true if any mutable function (or operator implemented by a mutable function) is found.

I see. Interesting. Thanks for the insights.

Any chance you know of a workaround to identify the part in my view that is the problem? I made the couple functions I wrote immutable so now I really don't know what it could be. 🤔

@yugo-n
Copy link
Collaborator

yugo-n commented Aug 5, 2023

I wonder you can try to make an IMMV using a query that contains only part of the your original view definition and check which part is problematic.

@illes
Copy link

illes commented Mar 3, 2024

@YAmikep the usual suspects would be current date/time functions (CURRENT_TIMESTAMP, NOW(), ...) and RAND()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants