We have a customer who has created a view in Oracle that performs badly and looking at the SQL for the view reveals that they're using a function call in the WHERE clause of the view definition. This function is fairly intensive and includes DELETEs and INSERTs.
My gut feeling is that this isn't a good idea but I'm not sure how to express exactly why...?
Will the function get executed every time someone queries the view?
Would a materialised view with a daily refresh (for example) make more sense, so the function was only executed once per day? (I guess that would depend on whether the data needed to be bang up to date all the time...?)
Thanks
whereclause it's probably being called multiple times by every query against the view by every user. Even if the view is only queried once a day by a single user it's still... unusual... at best and probably still called multiple times. A separate process, maybe called via a job, makes much more sense. Or possibly a procedure that checks if the heavy work has been done for that day, does it if not, and returns the same data as a the view via an OUT sys-refcursor, say, Really depends.