Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WTCUR-0003uS-JG for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Mar 2014 15:45:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WTCUQ-0002Zy-D0 for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Mar 2014 15:45:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WTAFy-0005cX-P9 for pgsql-bugs@postgresql.org; Thu, 27 Mar 2014 13:22:06 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WTAFv-0006GB-3Z for pgsql-bugs@postgresql.org; Thu, 27 Mar 2014 13:22:05 +0000 MIME-Version: 1.0 Subject: BUG #9743: subquery on view is not pulling up. To: pgsql-bugs@postgresql.org From: kwalbrecht@cghtech.com Date: Thu, 27 Mar 2014 13:21:34 +0000 Message-ID: <20140327132134.17069.55219@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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