Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ajp04-0005tx-5I for pgsql-performance@arkaria.postgresql.org; Sat, 26 Mar 2016 14:15:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ajp03-0002Ph-NJ for pgsql-performance@arkaria.postgresql.org; Sat, 26 Mar 2016 14:15:35 +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_2) (envelope-from ) id 1ajoyO-0000RA-OY for pgsql-performance@postgresql.org; Sat, 26 Mar 2016 14:13:52 +0000 Received: from mailout01.ims-firmen.de ([213.174.32.96]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1ajoyL-0006uL-2i for pgsql-performance@postgresql.org; Sat, 26 Mar 2016 14:13:52 +0000 Received: from mailin03.ims-firmen.de ([192.168.1.143]) by mailout01.ims-firmen.de with esmtp (envelope-from ) id 1ajoyJ-0004Sm-g9 for pgsql-performance@postgresql.org; Sat, 26 Mar 2016 15:13:47 +0100 Received: from [79.204.179.3] (helo=a-kretschmer.de) by mailin03.ims-firmen.de with esmtpsa (TLSv1:AES256-SHA:256) (envelope-from ) id 1ajoyI-00080n-9T for pgsql-performance@postgresql.org; Sat, 26 Mar 2016 15:13:47 +0100 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1ajoyI-00008a-3v for pgsql-performance@postgresql.org; Sat, 26 Mar 2016 15:13:46 +0100 Date: Sat, 26 Mar 2016 15:13:46 +0100 From: Andreas Kretschmer To: pgsql-performance@postgresql.org Subject: Re: Query not using Index Message-ID: <20160326141346.GA32059@tux> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Wei Shan wrote: > Hi all, > > Please provide some advise on the following query not using the index: > I have 2 questions: > > 1. Why does the optimizer chose not to use the index when it will run faster? because of the estimated costs.: Seq Scan on testdb auditrecor0_  (cost=0.00..18147465.00 Bitmap Heap Scan on testdb auditrecor0_  (cost=2291521.32..19046381.97 The estimated costs for the index-scan are higher. > 2. How do I ensure the optimizer will use the index without setting > enable_seqscan='off' You have a dedicated tablespace for indexes, is this a SSD? You can try to reduce the random_page_cost, from default 4 to maybe 2.(depends on hardware) This would reduce the estimated costs for the Index-scan and prefer the index-scan. Regards, Andreas Kretschmer -- Andreas Kretschmer http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance