Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 95D221337B8C for ; Sat, 16 Oct 2010 00:47:01 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 97910-04 for ; Sat, 16 Oct 2010 03:46:54 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from nm4-vm0.bullet.mail.sp2.yahoo.com (nm4-vm0.bullet.mail.sp2.yahoo.com [98.139.91.190]) by mail.postgresql.org (Postfix) with SMTP id 7615F1337B6F for ; Sat, 16 Oct 2010 00:46:53 -0300 (ADT) Received: from [98.139.91.69] by nm4.bullet.mail.sp2.yahoo.com with NNFMP; 16 Oct 2010 03:46:51 -0000 Received: from [98.139.91.33] by tm9.bullet.mail.sp2.yahoo.com with NNFMP; 16 Oct 2010 03:46:51 -0000 Received: from [127.0.0.1] by omp1033.mail.sp2.yahoo.com with NNFMP; 16 Oct 2010 03:46:50 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 803092.1242.bm@omp1033.mail.sp2.yahoo.com Received: (qmail 28460 invoked by uid 60001); 16 Oct 2010 03:46:50 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1287200810; bh=y5GG0d6WNvrNb13TPDccrozhQ2/15VeyN9V92515jyg=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type; b=LPi6kT3zy20CTl3NjOoKI78gJDd2BpjRQriZyhWC/4cJ95mRZZV6x7qF/LyGYYYkoElUmIjt3MNd4QaBOp1dg8VatbHyJ5n7OhxBqlVcNCLNDOrm/2B/KFux5P477WbQFOgLlk0GHmvwIinrepXV2OrU8qtvjZEQ/NaVdb5qtik= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type; b=IaNfn8on4SukpvE3AFErIIYiC8gFaGz2VKFSKoJ4iZzvzkTkjvzgT1qyywq74A+AdcnSRp9l9HNIWKmQ//S2dO8vn6YdaGXTVwVdPMiyjc0Qne1jciFDmTCitUPr/7njjTTeBrn/bQNB0cvKAvTUdYAxf40c8ikiXUyG2UbZFEU=; Message-ID: <321028.24609.qm@web111312.mail.gq1.yahoo.com> X-YMail-OSG: K3ydBR0VM1mK03QVlvmNsG9ujI2WH6wHMYJx7mOt4IPaPrJ IRzGlLzf9BzVGR8C4JwfNfWf4JuZVNl3W52YkVcuX4qZf..yvbP4FGvR32cc bHMQRtxhhy7rAwxCqCVIFYECT0hgtNDx9Ikleoz_aZE3Sn_2m5mCRDxq1tl8 YvN0hHGi4Rg68KuSjUJqalg5a.07mPWVtZFi1w.iR9fIJF9Gnaxan4GXvEZA 0dAOGJYPmA73ZbDHaFnjQGefoCiGrvqZmn7YIalK2GCuaeoiBsm9lhomae.F nJTS8x2qCfTz2vo9KJIE7.Z6di3xzW1e.j2PqqD64pXeFK1gXDDmhvzU1ygT qizx9ZwuEmezxLzqXu_csgnjWGtBHXSd3 Received: from [24.34.116.83] by web111312.mail.gq1.yahoo.com via HTTP; Fri, 15 Oct 2010 20:46:49 PDT X-Mailer: YahooMailClassic/11.4.9 YahooMailWebService/0.8.106.282862 Date: Fri, 15 Oct 2010 20:46:49 -0700 (PDT) From: Andy Subject: Re: UUID performance as primary key To: Navkirat Singh , Craig Ringer Cc: pgsql-performance@postgresql.org In-Reply-To: <4CB91515.6020201@postnewspapers.com.au> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-709223036-1287200809=:24609" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.909 tagged_above=-10 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201010/271 X-Sequence-Number: 40689 --0-709223036-1287200809=:24609 Content-Type: text/plain; charset=us-ascii Wouldn't UUID PK cause a significant drop in insert performance because every insert is now out of order, which leads to a constant re-arranging of the B+ tree? The amount of random IO's that's going to generate would just kill the performance. --- On Fri, 10/15/10, Craig Ringer wrote: From: Craig Ringer Subject: Re: [PERFORM] UUID performance as primary key To: "Navkirat Singh" Cc: pgsql-performance@postgresql.org Date: Friday, October 15, 2010, 10:59 PM On 16/10/2010 9:58 AM, Navkirat Singh wrote: > Hi Guys, > > I am interested in finding out the pros/cons of using UUID as a primary key field. My requirement states that UUID would be perfect in my case as I will be having many small databases which will link up to a global database using the UUID. Hence, the need for a unique key across all databases. It would be extremely helpful if someone could help me figure this out, as it is critical for my project. Pro: No need for (serverid,serverseq) pair primary keys or hacks with modulus based key generation. Doesn't set any pre-determined limit on how many servers/databases may be in a cluster. Con: Slower than modulo key generation approach, uses more storage. Foreign key relationships may be slower too. Overall, UUIDs seem to be a favoured approach. The other way people seem to do this is by assigning a unique instance id to each server/database out of a maximum "n" instances decided at setup time. Every key generation sequence increments by "n" whenever it generates a key, with an offset of the server/database id. That way, if n=100, server 1 will generate primary keys 001, 101, 201, 301, ..., server 2 will generate primary keys 002, 102, 202, 302, ... and so on. That works great until you need more than 100 instances, at which point you're really, REALLY boned. In really busy systems it also limits the total amount of primary key space - but with BIGINT primary keys, that's unlikely to be something you need to worry about. The composite primary key (serverid,sequenceid) approach avoids the need for a pre-defined maximum number of servers, but can be slow to index and can require more storage, especially because of tuple headers. I have no firsthand experience with any of these approaches so I can't offer you a considered opinion. I know that the MS-SQL crowd at least strongly prefer UUIDs, but they have very strong in-database UUID support. MySQL folks seem to mostly favour the modulo primary key generation approach. I don't see much discussion of the issue here - I get the impression Pg doesn't see heavy use in sharded environments. -- Craig Ringer Tech-related writing at http://soapyfrogs.blogspot.com/ -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance --0-709223036-1287200809=:24609 Content-Type: text/html; charset=us-ascii
Wouldn't UUID PK cause a significant drop in insert performance because every insert is now out of order, which leads to a constant re-arranging of the B+ tree? The amount of random IO's that's going to generate would just kill the performance.

--- On Fri, 10/15/10, Craig Ringer <craig@postnewspapers.com.au> wrote:

From: Craig Ringer <craig@postnewspapers.com.au>
Subject: Re: [PERFORM] UUID performance as primary key
To: "Navkirat Singh" <navkirats@gmail.com>
Cc: pgsql-performance@postgresql.org
Date: Friday, October 15, 2010, 10:59 PM

On 16/10/2010 9:58 AM, Navkirat Singh wrote:
> Hi Guys,
>
> I am interested in finding out the pros/cons of using UUID as a primary key field. My requirement states that UUID would be perfect in my case as I will be having many small databases which will link up to a global database using the UUID. Hence, the need for a unique key across all databases. It would be extremely helpful if someone could help me figure this out, as it is critical for my project.

Pro: No need for (serverid,serverseq) pair primary keys or hacks with modulus based key generation. Doesn't set any pre-determined limit on how many servers/databases may be in a cluster.

Con: Slower than modulo key generation approach, uses more storage. Foreign key relationships may be slower too.

Overall, UUIDs seem to be a favoured approach. The other way people seem to do this is by assigning a unique instance id to each server/database out of a maximum "n" instances decided at setup time. Every key generation sequence increments by "n" whenever it generates a key, with an offset of the server/database id. That way, if n=100, server 1 will generate primary keys 001, 101, 201, 301, ..., server 2 will generate primary keys 002, 102, 202, 302, ... and so on.

That works great until you need more than 100 instances, at which point you're really, REALLY boned. In really busy systems it also limits the total amount of primary key space - but with BIGINT primary keys, that's unlikely to be something you need to worry about.

The composite primary key (serverid,sequenceid) approach avoids the need for a pre-defined maximum number of servers, but can be slow to index and can require more storage, especially because of tuple headers.

I have no firsthand experience with any of these approaches so I can't offer you a considered opinion. I know that the MS-SQL crowd at least strongly prefer UUIDs, but they have very strong in-database UUID support. MySQL folks seem to mostly favour the modulo primary key generation approach. I don't see much discussion of the issue here - I get the impression Pg doesn't see heavy use in sharded environments.

-- Craig Ringer

Tech-related writing at http://soapyfrogs.blogspot.com/

-- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

--0-709223036-1287200809=:24609--