X-Original-To: pgsql-novice-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 74C253A6511 for ; Sat, 11 Dec 2004 01:09:21 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 53547-09 for ; Sat, 11 Dec 2004 01:08:38 +0000 (GMT) Received: from davinci.ethosmedia.com (server226.ethosmedia.com [209.128.84.226]) by svr1.postgresql.org (Postfix) with ESMTP id A45F13AA0C7 for ; Fri, 10 Dec 2004 23:39:13 +0000 (GMT) Received: from [64.81.245.111] (account josh@agliodbs.com HELO temoku.sf.agliodbs.com) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 6770736; Fri, 10 Dec 2004 15:40:43 -0800 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Matthew Engelbert Subject: Re: Indexing Strategy Date: Fri, 10 Dec 2004 15:42:18 -0800 User-Agent: KMail/1.6.2 Cc: pgsql-novice@postgresql.org References: <20041208192145.95226.qmail@web60308.mail.yahoo.com> In-Reply-To: <20041208192145.95226.qmail@web60308.mail.yahoo.com> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200412101542.18353.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.043 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200412/68 X-Sequence-Number: 11645 Matthew, > I'm having trouble correctly indexing a large table. The table will be > receiving about 30 million rows/day, and has the following definition: > > CREATE TABLE quote ( > symbol varchar (5), > price numeric (7,4), > time timestamp > ); > > I need to configure the indices so that I can minimize the time to request > all the records for a particular symbol, for a particular day, ordered by > time. Please post the query you're using. How are you selecting the day? What version of PostgreSQL are you using? > I've tried clustering a single index based on symbol, then time, but this > operation takes much too long. I think this is because this operation > would have O(N^2) complexity(?). Nope, just because it's a very large table and you're probably swapping. Try increasing sort_mem dramatically, like half your RAM. > I think my next best option would be to > cluster on an index based on symbol, then have another index on time. Not that either. You need a multicolumn index. When you answer the above quesitons, I'll explain it. > Does any one know of some resources on the web that discusses indexing > strategies ? Any help would be appreciated? Thanks. Not that covers your question. I'm writing a book which covers this right now, but it won't be published until January 2006. -- --Josh Josh Berkus Aglio Database Solutions San Francisco