Yugabyte-db: Support unique secondary index

Created on 7 Jun 2018  路  6Comments  路  Source: yugabyte/yugabyte-db

Currently, YugaByte DB supports non-unique secondary index. In some use cases, the application may require the index to be unique.

For example, consider an employee table which has id as the primary key column, and another email column where the entries need to be unique. This could be achieved as follows:

CREATE TABLE employee(id text PRIMARY KEY, email text, name text);
CREATE UNIQUE INDEX ON employee(email) covering (name);

Insert statements would look as follows:

INSERT INTO employee(id, email, name) VALUES (...) IF NOT EXISTS;
kinenhancement

Most helpful comment

馃憤 looking forward to try this out.

All 6 comments

For redis interface, adding of two key-value pairs atomically would be helpful as well.

e.g.

 EVAL  {
    if SETNX( id, name) == 1 && SETNX(id, email) == 1 then
      return 1
   end

}

hi @rohitjoshi :

Currently, we don't support Lua scripting in our our Redis-compatible offering. For now, for multiple table ACID or multi-key ACID operations spanning shards- we suggest using our Cassandra based interface with the extensions (YCQL). But we can look into adding this type of capability in the Redis interface in the future.

In your specific example, did you mean for both keys to have the same id (where name & email are different fields of a redis hash map) or could they be two different keys that might fall on two different shards (and hence different servers).

regards,
Kannan

@kmuthukk thanks. thanks correcting. I am looking for id => name and name=>email inserted atomically.

Unique secondary index for YCQL has been implemented in commit 3769c97.

馃憤 looking forward to try this out.

Thx @rohitjoshi . We'll get an updated release tar ball with this change out soon.

Was this page helpful?
0 / 5 - 0 ratings