X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9888332A0F7 for ; Wed, 20 Oct 2004 20:38:20 +0100 (BST) 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 07383-02 for ; Wed, 20 Oct 2004 19:38:15 +0000 (GMT) Received: from smtp100.rog.mail.re2.yahoo.com (smtp100.rog.mail.re2.yahoo.com [206.190.36.78]) by svr1.postgresql.org (Postfix) with SMTP id 96E98329F30 for ; Wed, 20 Oct 2004 20:38:12 +0100 (BST) Received: from unknown (HELO phlogiston.dydns.org) (a.sullivan@rogers.com@65.49.125.184 with login) by smtp100.rog.mail.re2.yahoo.com with SMTP; 20 Oct 2004 19:38:10 -0000 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 2C5434058; Wed, 20 Oct 2004 15:38:09 -0400 (EDT) Date: Wed, 20 Oct 2004 15:38:09 -0400 From: Andrew Sullivan To: pgsql-general@postgresql.org Subject: Re: Sequence question Message-ID: <20041020193809.GF8721@phlogiston.dyndns.org> Mail-Followup-To: pgsql-general@postgresql.org References: <41753069.3000406@bonbon.net> <20041020155742.GB8721@phlogiston.dyndns.org> <4176B58F.6020204@bonbon.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4176B58F.6020204@bonbon.net> User-Agent: Mutt/1.5.6+20040722i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/935 X-Sequence-Number: 67458 On Wed, Oct 20, 2004 at 02:59:27PM -0400, Eric E wrote: > - have the sequence preallocation table hold only numbers with status > being available or pending, i.e., delete numbers once they have been > allocated. This leaves on two possible statuses: available and pending. I would argue that you're best to record everything. That is, your proposal moves from a table which covers all the possible states -- granted, pending, and available -- to a table which entails ambiguous answers to some questions. Since you're not going to preallocate every logically possible id, then if an id isn't in the table, you can't tell if it simply has never been allocated, or if it has already been used. If you have that stored elsewhere, though, you can get it from a join, so perhaps there's no need for this. (I note that a real normalisation freak, like the one I occasionally play on TV, would require you to use a REFERENCES constraint on the status value, and use the referenced table as a control for what status values you can use. This has the not inconsiderable benefit that if you have a new status -- say, "storage burned down" or "impounded by SCO for copyright violation" or something else -- you have a completely trivial way to add it. It's certainly the way I'd actually do this.) > I also liked your point about the atomicity of : > get number, change status to pending, commit The real problem with it is that you do have the possibility of orphaned pending actions. > My thought was that the you could set the status ussing sessionID. That > way a server-side job could look for expired sessions and remark those > numbers available. That's something like what I'd do, yes. It mostly depends on what's available to your application. I tend to be very belt-and-suspenders about this sort of thing. Probably I'd put a wall-clock timestamp on the field, too, to give me clues about when things might be going wrong, &c. > > find a better way to solve the "other serious problems" you have > > rather than banging on sequences to get them to fit your intended > > use. > > I just haven't really seen anyway around the need to use all of our > storage rows that doens't involve a complicated mapping to boxes. I was more concerned that you were trying to do this for invoice numbers, another place where people often require serial numbers. In that case, I usually think they're wrong, because I can think of plenty of better ways to solve that one (unless it's a legal requirement, which is sometimes is). But mapping data points to places in space is one of those cases where you probably _do_ need this sort of preallocation mechanism. It's what hotels do, after all. A -- Andrew Sullivan | ajs@crankycanuck.ca The fact that technology doesn't work is no bar to success in the marketplace. --Philip Greenspun