Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Zboqx-0003dH-9a for pgsql-sql@arkaria.postgresql.org; Tue, 15 Sep 2015 11:56:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Zboqw-00032b-RP for pgsql-sql@arkaria.postgresql.org; Tue, 15 Sep 2015 11:56:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Zboqw-00032U-Cw for pgsql-sql@postgresql.org; Tue, 15 Sep 2015 11:56:50 +0000 Received: from mbob.nabble.com ([162.253.133.15]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1Zboqr-0000N8-Oo for pgsql-sql@postgresql.org; Tue, 15 Sep 2015 11:56:48 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mbob.nabble.com (Postfix) with ESMTP id 7081F15892D0 for ; Tue, 15 Sep 2015 04:52:03 -0700 (PDT) Date: Tue, 15 Sep 2015 04:56:44 -0700 (MST) From: gmb To: pgsql-sql@postgresql.org Message-ID: <1442318204445-5865953.post@n5.nabble.com> Subject: View not using index MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.3 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org HI I hope somebody can give some guidance. Since our application make extensive use of views, this is becoming a concern for me. Please see below: CREATE TABLE detail ( invno VARCHAR, accno INTEGER, info INTEGER[] ); CREATE OR REPLACE VIEW detailview AS ( SELECT invno , accno , COALESCE( info[1],0 ) info1, COALESCE( info[2],0 ) info2, COALESCE( info[3],0 ) info3, COALESCE( info[4],0 ) info4 FROM detail ); CREATE INDEX detail_ix_info3 ON detail ( ( info[3] ) ) WHERE COALESCE( info[3],0 ) = 1; EXPLAIN SELECT * FROM detail WHERE COALESCE( info[3],0 ) =1; QUERY PLAN ------------------------------------------------------------------------------ Bitmap Heap Scan on detail (cost=4.13..12.59 rows=4 width=68) Recheck Cond: (COALESCE(info[3], 0) = 1) -> Bitmap Index Scan on detail_ix_info3 (cost=0.00..4.13 rows=4 width=0) (3 rows) EXPLAIN SELECT * FROM detailview WHERE COALESCE( info3,0 ) =1; QUERY PLAN -------------------------------------------------------- Seq Scan on detail (cost=0.00..20.38 rows=4 width=68) Filter: (COALESCE(COALESCE(info[3], 0), 0) = 1) (2 rows) This is an oversimplified example; the view in our production env provides for 20 elements in the info array column. My table in productions env contains ~10mil rows. Is there any way in which I can force the view to use the index? Regards -- View this message in context: http://postgresql.nabble.com/View-not-using-index-tp5865953.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql