Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 46E0963290A for ; Fri, 31 Jul 2009 12:50:17 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 51841-01 for ; Fri, 31 Jul 2009 15:50:05 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from out01.mta.xmission.com (out01.mta.xmission.com [166.70.13.231]) by mail.postgresql.org (Postfix) with ESMTP id 358C6632179 for ; Fri, 31 Jul 2009 12:50:06 -0300 (ADT) Received: from in02.mta.xmission.com ([166.70.13.52]) by out01.mta.xmission.com with esmtp (Exim 4.62) (envelope-from ) id 1MWuNB-00027v-79; Fri, 31 Jul 2009 09:50:21 -0600 Received: from rsargent.dsl.xmission.com ([199.104.125.126] helo=[192.168.0.6]) by in02.mta.xmission.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1MWuMt-0005Ly-HO; Fri, 31 Jul 2009 09:50:04 -0600 Message-ID: <4A7312AA.4080608@gmail.com> Date: Fri, 31 Jul 2009 09:50:02 -0600 From: Rob Sargent User-Agent: Thunderbird 2.0.0.22 (X11/20090608) MIME-Version: 1.0 To: wkipjohn@gmail.com CC: pgsql-sql@postgresql.org References: <0016364c637589ebcb046ff865c1@google.com> In-Reply-To: <0016364c637589ebcb046ff865c1@google.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-XM-SPF: eid=; ; ; mid=; ; ; hst=in02.mta.xmission.com; ; ; ip=199.104.125.126; ; ; frm=robjsargent@gmail.com; ; ; spf=neutral X-XM-DomainKey: sender_domain=gmail.com; ; ; sender=robjsargent@gmail.com; ; ; status=no signature X-SA-Exim-Connect-IP: 199.104.125.126 X-SA-Exim-Rcpt-To: wkipjohn@gmail.com, pgsql-sql@postgresql.org, robjsargent@gmail.com X-SA-Exim-Mail-From: robjsargent@gmail.com X-Spam-DCC: XMission; sa03 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;wkipjohn@gmail.com X-Spam-Relay-Country: Subject: Re: SQL report X-SA-Exim-Version: 4.2.1 (built Thu, 25 Oct 2007 00:26:12 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=-10 required=5 tests=none X-Spam-Level: X-Archive-Number: 200907/164 X-Sequence-Number: 32905 Did you look at the query plans for the various record counts? That might show which index is missing or misinformed :). I wonder if clustering the status table on objectid would help? This does then require maintenance so you might only load it at 75%. wkipjohn@gmail.com wrote: > Hi Rob, > > I have default B-Tree indexes created for each of the indexed columes > and primary key columes. (No multiple columes indexe or NULL FIRST or > DESC/ASC). I am using PostgreSQL 8.3 with the auto vacuum daemon on. I > assume analyse will be automatically run to collect statistics for use > by the planner and there is no maintainance for B-tree indexes once it > is created. (Please point me out if I am wrong about this) > > I will probably try to partition the status table to group more recent > status records together to minimize the dataset I am querying. > > Thx > John > > > On Jul 31, 2009 1:16am, Rob Sargent wrote: > > I would be curious to know the performance curve for let's say 20K, > 40K , 60K, 80K, 100K records. And what sort of indexing you have, > whether or not it's clustered, re-built and so on. > > > > > > > > One could envision partitioning the status table such that recent > records were grouped together (on the assumption that they will be > most frequently "reported"). > > > > > > > > wkipjohn@gmail.com wrote: > > > > > > I have the following senario. > > > > > > > > I have a tracking system. The system will record the status of an > object regularly, all the status records are stored in one table. And > it will keep a history of maximum 1000 status record for each object > it tracks. The maximum objects the system will track is 100,000. Which > means I will potentially have a table size of 100 million records. > > > > > > > > I have to generate a report on the latest status of all objects > being tracked at a particular point in time, and also I have to allow > user to sort and filter on different columes in the status record > displayed in the report. > > > > > > > > The following is a brief description in the status record (they are > not actual code) > > > > > > > > ObjectRecord( > > > > objectId bigint PrimaryKey > > > > desc varchar > > > > ) > > > > > > > > StatusRecord ( > > > > id bigint PrimaryKey > > > > objectId bigint indexed > > > > datetime bigint indexed > > > > capacity double > > > > reliability double > > > > efficiency double > > > > ) > > > > > > > > I have tried to do the following, it works very well with around > 20,000 objects. (The query return in less than 10s) But when I have > 100,000 objects it becomes very very slow. (I don't even have patience > to wait for it to return.... I kill it after 30 mins) > > > > > > > > select * from statusrecord s1 INNER JOIN ( SELECT objectId , > MAX(datetime) AS msdt FROM statusrecord WHERE startDatetime > > > > > > I did try to write a store procedure like below, for 100,000 objects > and 1000 status records / object, it returns in around 30 mins. > > > > > > > > CREATE OR REPLACE FUNCTION getStatus(pitvalue BIGINT) RETURNS SETOF > statusrecord AS $BODY$ > > > > DECLARE > > > > id VARCHAR; > > > > status statusrecord%ROWTYPE; > > > > BEGIN > > > > FOR object IN SELECT * FROM objectRecord > > > > LOOP > > > > EXECUTE 'SELECT * FROM statusrecord WHERE objectId = ' || > quote_literal(object.objectId) || > > > > ' AND datetime > > INTO status; > > > > IF FOUND THEN > > > > RETURN NEXT status; > > > > END IF; > > > > END LOOP; > > > > RETURN; > > > > END > > > > $BODY$ LANGUAGE plpgsql; > > > > > > > > Just wanna to know if anyone have a different approach to my > senario. Thanks alot. > > > > > > > > John > > > >