Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TmO9i-0006fu-5A for pgsql-general@arkaria.postgresql.org; Sat, 22 Dec 2012 12:26:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TmO9h-00087Y-2C for pgsql-general@arkaria.postgresql.org; Sat, 22 Dec 2012 12:26:17 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TmO9f-00087M-O0; Sat, 22 Dec 2012 12:26:15 +0000 Received: from moutng.kundenserver.de ([212.227.17.9]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TmO9b-00089z-9a; Sat, 22 Dec 2012 12:26:14 +0000 Received: from anarazel.de (p5DDC4F0A.dip.t-dialin.net [93.220.79.10]) by mrelayeu.kundenserver.de (node=mrbap4) with ESMTP (Nemesis) id 0MIw2b-1ToK641Pdx-002Ut3; Sat, 22 Dec 2012 13:26:09 +0100 Received: by anarazel.de (Postfix, from userid 1000) id 864001C00E6; Sat, 22 Dec 2012 13:26:08 +0100 (CET) Date: Sat, 22 Dec 2012 13:26:08 +0100 From: Andres Freund To: Alban Hertroys Cc: Jose Martinez , pgsql-general@postgresql.org, pgsql-admin@postgresql.org Subject: Re: Simple Query Very Slow Message-ID: <20121222122608.GA15790@awork2.anarazel.de> References: <79F38E90-60F7-45AC-A3A0-E1EAC42515D6@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <79F38E90-60F7-45AC-A3A0-E1EAC42515D6@gmail.com> X-Provags-ID: V02:K0:MT+LCehwUfGrNoDKyN74Oa4vSntvDGLgl53LOEQehhw PDRrdTjGJpU8tHwsMoH0+BRbWAHliCyaqZB7yy5cnjicZYP3ig PvnYAVUhBrPcEJIlrcOvBntBwMn1gOqY5EC7Jz/caoZmErZp9G AjcSR5Pk47ZQcMvhPrQ6Pke7iS2IqjuvUs2V8hRyCZzj4Rmk+i l4xajkftiL/762oxDmNkbFk6YXbMIEoA9kDo/hk8vyeCYsNFqS Df7ihWBUy450ChBkgmjl+rdQwojJJCqsQyhmkZfw/TdFsz7jhp vaAy0rcokueMk25wxdy91/vY5jIKFQIstD1sH2ccjYNpY4esP2 ExCUPm8WEQHktNWpJegqgNJ3k6A9eASsVQFf53XRS X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org On 2012-12-22 13:06:21 +0100, Alban Hertroys wrote: > > and here's my query > > > > select * from ticket > > where created between '2012-12-19 00:00:00' and '2012-12-20 00:00:00' > > > > This was working fine until the number of records started to grow (about 5 million) and now it's taking forever to return. > > > > Explain analyze reveals this: > > > > "Index Scan using ticket_1_idx on ticket (cost=0.00..10202.64 rows=52543 width=1297) (actual time=0.109..125.704 rows=53340 loops=1)" > > " Index Cond: ((created >= '2012-12-19 00:00:00+00'::timestamp with time zone) AND (created <= '2012-12-20 00:00:00+00'::timestamp with time zone))" > > "Total runtime: 175.853 ms" > > > Nothing works. What am I doing wrong? why is it selecting sequential scan? the indexes are supposed to make the query fast. Anything that can be done to optimize it? Whats the time you would need? Beause the above isn't that slow. Perhaps the timing youre seing from your application includes transferring the data over a not too fast link? It would be interesting to see EXPLAIN (ANALYZE, BUFFERS) $query > It is not selecting sequential scan, you're looking at an index scan. That should be pretty fast, and it isn't that slow - that's still sub-second performance (0.176s). > Is that explain from the correct table? According to the results there are but 53 thousand rows in it, not anywhere near 5 million. Well, thats the estimate *after* applying the restriction, so that seems sensible. Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general