Re: [GENERAL] Performance implications of creating many, many sequences

2010-10-24 Thread Craig Ringer
On 10/24/2010 12:42 AM, Michael Gardner wrote: On Oct 22, 2010, at 11:03 PM, Craig Ringer wrote: Instead, maintain a counter, either in the main customer record or in an associated (customer_id, counter) side table if you want to reduce potential lock contention. Write a simple SQL function t

Re: [GENERAL] Performance implications of creating many, many sequences

2010-10-23 Thread Michael Gardner
On Oct 22, 2010, at 11:03 PM, Craig Ringer wrote: > Instead, maintain a counter, either in the main customer record or in an > associated (customer_id, counter) side table if you want to reduce potential > lock contention. Write a simple SQL function that uses an UPDATE ... > RETURNING statemen

Re: [GENERAL] Performance implications of creating many, many sequences

2010-10-22 Thread Craig Ringer
On 23/10/2010 3:18 AM, Michael Gardner wrote: Consider the following table: CREATE TABLE invoice ( account_id integer NOT NULL REFERENCES account, invoice_number integer NOT NULL, UNIQUE (account_id,invoice_number)); I would like to do the equivalent of making invoice_nu

Re: [GENERAL] Performance implications of creating many, many sequences

2010-10-22 Thread Michael Gardner
On Oct 22, 2010, at 2:50 PM, Rob Sargent wrote: > Is this "invoice_number" just an id or what might appear an a bill (in > some pretty form etc)? It will appear on actual invoices, as part of a compound invoice identifier (like ABCD-0042, where ABCD is an identifier for the account in question a

Re: [GENERAL] Performance implications of creating many, many sequences

2010-10-22 Thread Rob Sargent
Is this "invoice_number" just an id or what might appear an a bill (in some pretty form etc)? If the former, just get a unique id over all invoices. At the very least it will save time i) in writing where clauses ii) re-creating the correct id once some one assigns an invoice to the wrong custome

[GENERAL] Performance implications of creating many, many sequences

2010-10-22 Thread Michael Gardner
Consider the following table: CREATE TABLE invoice ( account_id integer NOT NULL REFERENCES account, invoice_number integer NOT NULL, UNIQUE (account_id,invoice_number)); I would like to do the equivalent of making invoice_number a serial type, but on a per-account basis.