Return-Path: X-Original-To: apmail-cassandra-user-archive@www.apache.org Delivered-To: apmail-cassandra-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2B146118DB for ; Sun, 11 May 2014 12:54:13 +0000 (UTC) Received: (qmail 227 invoked by uid 500); 10 May 2014 23:19:16 -0000 Delivered-To: apmail-cassandra-user-archive@cassandra.apache.org Received: (qmail 98709 invoked by uid 500); 10 May 2014 23:03:27 -0000 Mailing-List: contact user-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cassandra.apache.org Delivered-To: mailing list user@cassandra.apache.org Received: (qmail 39616 invoked by uid 99); 10 May 2014 22:58:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 10 May 2014 22:58:53 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy includes SPF record at spf.trusted-forwarder.org) Received: from [74.125.82.178] (HELO mail-we0-f178.google.com) (74.125.82.178) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 May 2014 19:32:26 +0000 Received: by mail-we0-f178.google.com with SMTP id u56so1508833wes.9 for ; Wed, 07 May 2014 12:32:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:content-type; bh=szmoqvYabE0/Rtf7B0FolamiskiVfqTSEjb9plhq9Hs=; b=Hq6jOf0mbDx8RTHJpPM+OH0YuSbGxvH0K+MllvXusnozWL8aJBQLhHl9UaomaIdzIY KiTPJQCGqfGf4yO2hpWSN/Q8MD5Pbz+T3isLu+KjpHA9FR4D1yWAnzOWKD6cUAb7NxX0 F5zQ9PwHOY0atMgwxZAQrmXtd6GU7L990ktfmkkhOkyZ+XgJnZfFfEf4zopQRrKdrtwg jbzIvqZjsZFW23ChWGNNN+PIaQaDAPoaXkadAs95u1JGDiv9/H+B+wzp01/k89lmVyce REsyFI0+bnardXEaJF7YZ/+TSvzk0rMHpgr7Bsp8cFuiaW5BlXhaiyzu9mGiptn2H+tc 3KDg== X-Gm-Message-State: ALoCoQnLQV9uD1Hhu1QrOqGeFV28Tv+Kszc4OB9SZtQ8+JT7R+R7EFqrEZHxeE6UaGCmAvh7CpF5 X-Received: by 10.180.101.6 with SMTP id fc6mr9195789wib.59.1399491124388; Wed, 07 May 2014 12:32:04 -0700 (PDT) MIME-Version: 1.0 Sender: niki@photonhost.com Received: by 10.216.31.201 with HTTP; Wed, 7 May 2014 12:31:34 -0700 (PDT) In-Reply-To: References: From: Nikolay Mihaylov Date: Wed, 7 May 2014 22:31:34 +0300 X-Google-Sender-Auth: jeieFwPUX1nKi2an0ol6AbNNKNg Message-ID: Subject: Re: Avoiding email duplicates when registering users To: user@cassandra.apache.org Content-Type: multipart/alternative; boundary=f46d044400e456384a04f8d46b61 X-Virus-Checked: Checked by ClamAV on apache.org --f46d044400e456384a04f8d46b61 Content-Type: text/plain; charset=UTF-8 the real question is - if you want the email to be unique, why use "surrogate" primary key as UUID. I wonder what UUID gives you at all? If you want to have non email primary key, why not use md5(email) ? On Wed, May 7, 2014 at 2:19 AM, Tyler Hobbs wrote: > > On Mon, May 5, 2014 at 10:27 AM, Ignacio Martin wrote: > >> >> When a user registers, the server generates a UUID and performs an INSERT >> ... IF NOT EXISTS into the email_to_UUID table. Immediately after, perform >> a SELECT from the same table and see if the read UUID is the same that the >> one we just generated. If it is, we are allowed to INSERT the data in the >> user table, knowing that no other will be doing it. >> > > INSERT ... IF NOT EXISTS is the correct thing to do here, but you don't > need to SELECT afterwards. If the row does exist, the query results will > show that the insert was not applied and the existing row will be returned. > > > -- > Tyler Hobbs > DataStax > --f46d044400e456384a04f8d46b61 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
the real question is - if you want the email to be unique,= why use "surrogate" primary key as UUID.

I wo= nder what UUID gives you at all?

If you want to ha= ve non email primary key, why not use md5(email) ?




On Wed, May 7, 2014 at 2:19 AM, Tyler Hobbs <tyler= @datastax.com> wrote:
=

On Mon, May 5, 2014 at 10:27= AM, Ignacio Martin <natx.mc@gmail.com> wrote:

When a user registers, t= he server generates a UUID and performs an INSERT ... IF NOT EXISTS into th= e email_to_UUID table. Immediately after, perform a SELECT from the same ta= ble and see if the read UUID is the same that the one we just generated. If= it is, we are allowed to INSERT the data in the user table, knowing that n= o other will be doing it.

INSERT ... IF NOT EXISTS is the cor= rect thing to do here, but you don't need to SELECT afterwards.=C2=A0 I= f the row does exist, the query results will show that the insert was not a= pplied and the existing row will be returned.


--
Tyler Hobbs
DataStax

--f46d044400e456384a04f8d46b61--