Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XgfAD-0001z5-Rf for pgsql-performance@arkaria.postgresql.org; Tue, 21 Oct 2014 19:32:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XgfAD-0002kp-5e for pgsql-performance@arkaria.postgresql.org; Tue, 21 Oct 2014 19:32:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XgfAB-0002iP-AS for pgsql-performance@postgresql.org; Tue, 21 Oct 2014 19:32:11 +0000 Received: from mout.gmx.net ([212.227.15.15]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XgfA7-0006W7-8X for pgsql-performance@postgresql.org; Tue, 21 Oct 2014 19:32:09 +0000 Received: from [192.168.1.27] ([84.58.60.26]) by mail.gmx.com (mrgmx001) with ESMTPSA (Nemesis) id 0M3RVA-1XyC0r1I6C-00qxCA for ; Tue, 21 Oct 2014 21:32:05 +0200 Message-ID: <5446B4B3.4030802@gmx.de> Date: Tue, 21 Oct 2014 21:32:03 +0200 From: =?ISO-8859-15?Q?Bj=F6rn_Wittich?= User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: extremly bad select performance on huge table References: <5446972B.9040409@gmx.de> <9706.1413918462@sss.pgh.pa.us> In-Reply-To: <9706.1413918462@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:4J3sxFjtf1PeKrZ0lQdExb3QMxBGt2426wO7YNvESnFVIgl3nHG jFvAXSwWaVUgwNY9tvC6qGpnnsO54swvVfXxm4510dGrtR/jnIlMqM2gJdypPD+043EFlp/ PwaKKVvIh1u7Niai81bSlrYSWinztt1TE7TtU+qgo/kDCcV3XWwjUGycQs/kPwz7j7B0KkG OP1ThGRBEIjCsOQapwxuA== X-UI-Out-Filterresults: notjunk:1; X-Pg-Spam-Score: -2.5 (--) 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 Hi Tom and Igor, thanks for your help. With the reindex the select query running time was reduced from 5200 sec to 130 sec. Impressive! Even a join on this table is now fast. Unfortunately, there is now another problem: The table in my example has 500 columns which I want to retrieve with my join command. Example which is fast "select value from smallertable inner join myhugetable ON smallertable.mycolumn = myhugetable.mycolumn" Example which is slow "select value,c1,c2,c3,...,c10 from smallertable inner join myhugetable ON smallertable.mycolumn = myhugetable.mycolumn" Which is the number of columns to fetch so bad ? Which action is done in the db system when querying this via pgadmin? I think that there is no real retrieval included, why is the number of additional columns so bad for the join performance? > =?ISO-8859-15?Q?Bj=F6rn_Wittich?= writes: >> Here is the explain (analyze,buffers) select mycolumn from myhugetable >> "Index Only Scan using myprimkey on myhugetable (cost=0.00..8224444.82 >> rows=71768080 width=33) (actual time=16.722..2456300.778 rows=71825999 >> loops=1)" >> " Heap Fetches: 356861" >> " Buffers: shared hit=71799472 read=613813" >> "Total runtime: 2503009.611 ms" > So that works out to about 4 msec per page fetched considering only I/O > costs, which is about as good as you're likely to get if the data is > sitting on spinning rust. > > You could potentially make it faster with a VACUUM (to mark all pages > all-visible and eliminate the "heap fetches" costs), or a REINDEX > (so that the index scan becomes more nearly sequential instead of random > access). However, unless the data is nearly static those will just be > temporary fixes: the time will degrade again as you update the table. > >> Note: This select is just for testing. My final statement will be a join >> on this table via the "mycolumn" column. > In that case it's probably a waste of time to worry about the performance > of this query as such. In the first place, a join is not likely to use > the index at all unless it's fetching a relatively small number of rows, > and in the second place it seems unlikely that the join query can use > an IndexOnlyScan on this index --- I imagine that the purpose of the join > will require fetching additional columns. > > regards, tom lane > > -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance