Re: Does it make sense to break a large query into separate functions?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Seref Arikan <serefarikan(at)kurumsalteknoloji(dot)com>, PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Does it make sense to break a large query into separate functions?
Date: 2013-05-08 19:04:43
Message-ID: 11326.1368039883@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Merlin Moncure <mmoncure(at)gmail(dot)com> writes:
> odd that stable function is inlined but immutable isn't!

Well, it knows that the expansion to to_date() would only be stable not
immutable (because to_date depends on some GUC settings), so doing the
expansion could change the behavior, eg by preventing constant-folding.

Although usually wrapping a stable function in an immutable one is a
recipe for disaster, we don't forbid it because there are cases where it
makes sense --- for instance, you might know that the function really is
immutable *in your usage*, and want to use it as an index function or
some such. But the SQL-function wrapper adds a lot of overhead. I
think a plpgsql wrapper would be better here, if you need to cheat about
the mutability.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tyson Maly 2013-05-08 19:14:39 Re: question on most efficient way to increment a column
Previous Message Merlin Moncure 2013-05-08 18:41:12 Re: Does it make sense to break a large query into separate functions?