pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #9743: subquery on view is not pulling up.
2+ messages / 2 participants
[nested] [flat]

* BUG #9743: subquery on view is not pulling up.
@ 2014-03-27 13:21 kwalbrecht@cghtech.com
  2014-03-27 17:22 ` Re: BUG #9743: subquery on view is not pulling up. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: kwalbrecht@cghtech.com @ 2014-03-27 13:21 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      9743
Logged by:          Karl Walbrecht
Email address:      kwalbrecht@cghtech.com
PostgreSQL version: 9.2.1
Operating system:   solaris
Description:        

When I query a view which has calculated values, even if I don't select one
of the calculated values, they are being calculated.  I believe this is
called subquery unnesting in oracle.  In essence since the calculated
portion of the table is not being referenced then the calculation should not
be preformed.  I tried setting the cost of sda.KML_Sector() and
sda.GeoJSON_Sector() to 150000 but it had no effect on the query plan.  I
have tried rewriting the queries but again to no effect.  I have concluded
that this is a performance issue in the query optimization routines.  I
apologize in advance if this is just stupidity on my part.

Thanks

The functions sda.KML_sector(), and sda.GeoJSON_Sector() are written in
pgplsql.

CREATE TABLE sda.sectors_base_table
( 
    sector_id         INTEGER   NOT NULL
  , airspace_id       INTEGER   NOT NULL
  , area_id           INTEGER   NOT NULL
  , sector_num        VARCHAR   NOT NULL
  , sector_name       VARCHAR   NOT NULL
  , color_number      INTEGER   NOT NULL DEFAULT 0  
  , bb_adjacent_array INTEGER[]
  , sector            GEOMETRY  
  
  , CONSTRAINT sectors_sector_pk      PRIMARY KEY(sector_id)
  , CONSTRAINT sectors_geom_ck        CHECK (GeometryType(sector) =
'GEOMETRYCOLLECTION')
  , CONSTRAINT sectors_airspace_fk    FOREIGN KEY (airspace_id) REFERENCES
sda.airspaces_(airspace_id)
  , CONSTRAINT sectors_area_fk        FOREIGN KEY (area_id) REFERENCES
sda.areas_(area_id)
  , CONSTRAINT sector_color_number_ck CHECK(color_number >= 0 and
color_number <= 12) 
);


CREATE OR REPLACE VIEW sda.sectors_view AS
    SELECT  s.* 
          , sda.KML_Sector(s.sector_id, s.airspace_id) as kml_fragment
          , sda.GeoJSON_Sector(s.sector_id, s.airspace_id) as
geojson_fragment
    FROM sda.sectors_base_table as s
;

sdat=> explain analyze verbose select sector_id from sda.sectors_view;
               QUERY PLAN                
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Subquery Scan on sectors  (cost=0.00..271.83 rows=54 width=4) (actual
time=16.602..3186.404 rows=54 loops=1)
   Output: sectors.sector_id
   ->  Seq Scan on sda.sectors_ s  (cost=0.00..271.29 rows=54 width=53976)
(actual time=16.600..3186.360 rows=54 loops=1)
         Output: s.sector_id, s.airspace_id, s.area_id, s.sector_num,
s.sector_name, s.color_number, s.bb_adjacent_array, s.sector,
sda.kml_sector(s.sector_id, s.airspace_id), sda.geojson_sector(s.sector_id,
s.airspace_id)
 Total runtime: 3186.526 ms
(5 rows)


sdat=> explain analyze verbose select sector_id from
sda.sectors_base_table;
                                               QUERY PLAN 
---------------------------------------------------------------------------------------------------------
 Seq Scan on sda.sectors_  (cost=0.00..48.54 rows=54 width=4) (actual
time=0.015..0.070 rows=54 loops=1)
   Output: sector_id
 Total runtime: 0.102 ms
(3 rows)


-- 
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 #9743: subquery on view is not pulling up.
  2014-03-27 13:21 BUG #9743: subquery on view is not pulling up. kwalbrecht@cghtech.com
@ 2014-03-27 17:22 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2014-03-27 17:22 UTC (permalink / raw)
  To: kwalbrecht@cghtech.com; +Cc: pgsql-bugs

kwalbrecht@cghtech.com writes:
> When I query a view which has calculated values, even if I don't select one
> of the calculated values, they are being calculated.

This example looks like the functions in question are marked volatile;
that prevents the view from being flattened, since doing so would
eliminate side-effects the user might be expecting to happen.  Assuming
yours are side-effect-free, mark them stable or immutable as appropriate.

http://www.postgresql.org/docs/9.2/static/xfunc-volatility.html

			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:[~2014-03-27 17:22 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-03-27 13:21 BUG #9743: subquery on view is not pulling up. kwalbrecht@cghtech.com
2014-03-27 17:22 ` 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