Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3oSK-0004hd-QO for pgsql-performance@arkaria.postgresql.org; Thu, 27 Apr 2017 18:47:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d3oSK-0007cy-9m for pgsql-performance@arkaria.postgresql.org; Thu, 27 Apr 2017 18:47:56 +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 1d3oSJ-0007cH-Dr for pgsql-performance@postgresql.org; Thu, 27 Apr 2017 18:47:55 +0000 Received: from mail-it0-x22f.google.com ([2607:f8b0:4001:c0b::22f]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1d3oSF-0005bj-5W for pgsql-performance@postgresql.org; Thu, 27 Apr 2017 18:47:54 +0000 Received: by mail-it0-x22f.google.com with SMTP id x188so20308656itb.0 for ; Thu, 27 Apr 2017 11:47:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=xL7aW9CFBRAEuQNESrYCLCS1ONOXcMvaKyPr13xfKUM=; b=JeCQyQNzL2Jk5ptNc4KkxeWXEW17Jxvrou1ljspBRUAz4CpfOb4CbOBgbLSi2XYjrg 1kDkqVM45hZBWu2qe+7C31Q1s6PMpHgdWW3PK0nYelA5kqusnkQIAWt2GmcVjv+cp2Op NR4LUz8NQpy6kcMGGqnxeyp0HhUaozGAq3BT4wOTNGb1M1m2dTroraiwuOuDESqXN41j 1aBgL8ImobrpyoGaZX6TSKi7q2rfPS8mvfq+ud11T5ayr+mLCSBDtMg5AgZTOiziDlg5 Onq5duaX/Y7M06x7adNiGjCf0WWhmU76derRW9xL5T4WSiUaDb254vVoz37oqGHhTbwg IbDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=xL7aW9CFBRAEuQNESrYCLCS1ONOXcMvaKyPr13xfKUM=; b=tBKAQwr4rqsrOwxe5ULdbD7upQww1JbYgmqXg9MYL4+Co/ntWfO7dcDHDu/NlJsBDo bnbYWyzFdzf1acqrGM0brdo51YMUx4zsOaYmGHeO1Uh+FNIbg30WcG8YcSrS1SibVkbq JtsXKWYJtki90+VQCq9RgGFJRhcp1XQBzi1xkO3HGKPHnWwKOoyT/0t4ZmTniPSHOG2z 3PZn5O1IF0BfLF6OYh4av98EgQpNVA0gQTx+SM/l0jxfYBBsgcrNUCetiW2IAhIdcqNg XEyJfnwvoUWcQregLEwHKh1fok6KVChS5SvSxMPLUUBeh2VTTJQlf2EYk9wlql8jomdP x5fA== X-Gm-Message-State: AN3rC/43RD1eaq5sEe+3R/0coeqQAuvbB2YdHLKnyzQfpQW8qZzTFN9w ySPzZEv7+AS8rQ== X-Received: by 10.36.178.10 with SMTP id u10mr40467ite.64.1493318868710; Thu, 27 Apr 2017 11:47:48 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 62sm1384139iou.10.2017.04.27.11.47.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Apr 2017 11:47:48 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 4EAFD80162C; Thu, 27 Apr 2017 13:47:47 -0500 (CDT) Date: Thu, 27 Apr 2017 13:47:47 -0500 From: Justin Pryzby To: Dinesh Chandra 12108 Cc: Nur Agus , Jeff Janes , "pgsql-performance@postgresql.org" Subject: Re: Performance issue in PostgreSQL server... Message-ID: <20170427184747.GR7289@telsasoft.com> References: <0796d1d53d3e4aa692cfdc329f86b399@cyient.com> <20170306052402.GC16088@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) 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 On Mon, Mar 06, 2017 at 12:17:22PM +0000, Dinesh Chandra 12108 wrote: > Below is the output of Query SELECT * FROM pg_stats WHERE tablename='point' AND attname='domain_class_id' ; > > > schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation > > "evidence"|"point"|"domain_class_id"|f|0|8|10|"{7,9,2,11,43,3,1,10,4,17}"|"{0.9322,0.0451333,0.0145,0.00393333,0.00183333,0.00146667,0.0005,0.0003,6.66667e-05,6.66667e-05}"|""|0.889078 On Fri, Mar 03, 2017 at 12:44:07PM +0000, Dinesh Chandra 12108 wrote: > -> Index Scan using point_domain_class_id_index on point p (cost=0.00..1483472.70 rows=1454751 width=16) (actual time=27.265..142101.1 59 rows=1607491 loops=1) On Sun, Mar 05, 2017 at 08:23:08PM -0800, Jeff Janes wrote: > Why wouldn't this be using a bitmap scan rather than a regular index scan? > It seems like it should prefer the bitmap scan, unless the table is well > clustered on domain_class_id. In which case, why isn't it just faster? I missed your response until now, and can't see that anybody else responded, but I suspect the issue is that the *table* is highly correlated WRT this column, but the index may not be, probably due to duplicated index keys. postgres only stores statistics on expression indices, and falls back to correlation of table column of a simple indices. If you're still fighting this, would you send result of: SELECT domain_class_id, count(1) FROM point GROUP BY 1 ORDER BY 2 DESC LIMIT 22; or, SELECT count(1) FROM point GROUP BY domain_class_id ORDER BY 1 DESC LIMIT 22; if there's much repetition in the index keys, then PG's planner thinks an index scan has low random_page_cost, and effective_cache_size has little effect on large tables, and it never uses bitmap scan, which blows up if the index is fragmented and has duplicate keys. The table reads end up costing something like 1454751*random_page_cost nonsequential reads and fseek() calls when it thinks it'll cost only 1454751*16*seq_page_cost. Is the query much faster if you first reindex point_domain_class_id_index ? This has come up before, see: > https://www.postgresql.org/message-id/flat/520D6610.8040907%40emulex.com#520D6610.8040907@emulex.com > https://www.postgresql.org/message-id/flat/20160524173914.GA11880%40telsasoft.com#20160524173914.GA11880@telsasoft.com > https://www.postgresql.org/message-id/flat/n6cmpug13b9rk1srebjvhphg0lm8dou1kn%404ax.com#n6cmpug13b9rk1srebjvhphg0lm8dou1kn@4ax.com Justin -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance