Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 47BA62E3B58 for ; Wed, 9 Jan 2008 15:09:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 36023-02-4 for ; Wed, 9 Jan 2008 15:09:40 -0400 (AST) Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.239]) by postgresql.org (Postfix) with ESMTP id A4ABA2E3EE5 for ; Wed, 9 Jan 2008 15:09:22 -0400 (AST) Received: by nz-out-0506.google.com with SMTP id l8so170532nzf.28 for ; Wed, 09 Jan 2008 11:09:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=jQ5wQt7KP1kf0+7w9OVINDULz9sOPpEt8WUj2B1djPs=; b=ZLpveyCPuZTE9rGs9rdUj5R4N9yS3ak1tYtuICVmOMvd/J+aWWxUvIvfveQ/H9OUTm71WJQfXusUhrbsDFNWdJka7LSnEcUs1DHYbausXPfn0mHa8KcB7R5w34fHEgajq0llx6cJFygfMAvnAlnN6ybrgmchehpR/f8G1YEea30= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=q2PlFeSMPzn66BZQhhnM3hPHmfiyJ4NHd1zqXUvhr3dld5XL92cGXVkic07FNotbvUZNthnTafmxh5mfYI2k5uYWkvfARXWp/jrRiZrpLAXhcvRmTyYAveLm5IRnF7iVgm61pL0O/J+IiO3JchSQ3qHsgnh06tgj9CDnWPVIwUo= Received: by 10.114.254.1 with SMTP id b1mr1176933wai.140.1199905760833; Wed, 09 Jan 2008 11:09:20 -0800 (PST) Received: by 10.114.131.4 with HTTP; Wed, 9 Jan 2008 11:09:20 -0800 (PST) Message-ID: Date: Wed, 9 Jan 2008 13:09:20 -0600 From: "Scott Marlowe" To: "Steve Midgley" Subject: Re: Re: How to keep at-most N rows per group? periodic DELETEs or constraints or..? Cc: pgsql-sql-owner@postgresql.org, pgsql-sql@postgresql.org In-Reply-To: <20080109182115.6E39C2E3239@postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20080109152431.79AFF2E02F6@postgresql.org> <20080109182115.6E39C2E3239@postgresql.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/57 X-Sequence-Number: 29910 On Jan 9, 2008 12:20 PM, Steve Midgley wrote: > This is kludgy but you would have some kind of random number test at > the start of the trigger - if it evals true once per every ten calls to > the trigger (say), you'd cut your delete statements execs by about 10x > and still periodically truncate every set of user rows fairly often. On > average you'd have ~55 rows per user, never less than 50 and a few > outliers with 60 or 70 rows before they get trimmed back down to 50.. > Seems more reliable than a cron job, and solves your problem of an ever > growing table? You could adjust the random number test easily if you > change your mind of the balance of size of table vs. # of delete > statements down the road. And, if you always through a limit 50 on the end of queries that retrieve data, you could let it grow quite a bit more than 60 or 70... Say 200. Then you could have it so that the random chopper function only gets kicked off every 100th or so time.