pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #7786: select from view is computing columns not selected
2+ messages / 2 participants
[nested] [flat]

* BUG #7786: select from view is computing columns not selected
@ 2013-01-04 14:28 doug@oakstreetsoftware.com
  2013-01-04 18:03 ` Re: BUG #7786: select from view is computing columns not selected Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: doug@oakstreetsoftware.com @ 2013-01-04 14:28 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      7786
Logged by:          Douglas Toltzman
Email address:      doug@oakstreetsoftware.com
PostgreSQL version: 9.2.2
Operating system:   Linux CentOS
Description:        

in the interest of simplicity, I've got a view that calls a stored procedure
to compute a value ...

create view testv as select tt.field1, tt.intfield, compute_val(tt.field1)
AS compute1 from tt;

If compute_val() selects sum(intfield) from the testv view, compute_val() is
called again when selecting records from testv (even though compute1 was not
selected), resulting in infinite recursion (stack overflow).

In retrospect, I realize this may have been a bad thing to do, but it worked
in version 8.1.x. I recently upgraded to 9.2.2 and I had to create a 2nd
view that didn't include the computed values, so I could use that view in
the stored procedures.

It seems like a performance problem to compute all columns in a view when
selecting only specific columns. I've already fixed my stack overflow, so
I'll let you decide if this is a bug or a feature.

If you're interested in reproducing this and you don't understand my
description, I'd be happy to provide a test case.



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #7786: select from view is computing columns not selected
  2013-01-04 14:28 BUG #7786: select from view is computing columns not selected doug@oakstreetsoftware.com
@ 2013-01-04 18:03 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2013-01-04 18:03 UTC (permalink / raw)
  To: doug@oakstreetsoftware.com; +Cc: pgsql-bugs

doug@oakstreetsoftware.com writes:
> in the interest of simplicity, I've got a view that calls a stored procedure
> to compute a value ...

> create view testv as select tt.field1, tt.intfield, compute_val(tt.field1)
> AS compute1 from tt;

> If compute_val() selects sum(intfield) from the testv view, compute_val() is
> called again when selecting records from testv (even though compute1 was not
> selected), resulting in infinite recursion (stack overflow).

> In retrospect, I realize this may have been a bad thing to do, but it worked
> in version 8.1.x.

I suspect that your function is declared VOLATILE, possibly by default.
PG versions later than 8.1 refrain from flattening views that contain
volatile functions in their SELECT list, on the grounds that such a
transformation might remove side-effects that the user expects to have
happen, or even cause the side-effects to happen more often than expected.

If you can declare the function STABLE then the view should continue to
work as before.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2013-01-04 18:03 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-01-04 14:28 BUG #7786: select from view is computing columns not selected doug@oakstreetsoftware.com
2013-01-04 18:03 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox