Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unique secondary index #322

Closed
robertpang opened this issue Jun 7, 2018 · 6 comments
Closed

Support unique secondary index #322

robertpang opened this issue Jun 7, 2018 · 6 comments
Assignees
Labels
kind/enhancement This is an enhancement of an existing feature

Comments

@robertpang
Copy link
Contributor

robertpang commented Jun 7, 2018

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;
@robertpang robertpang added the kind/enhancement This is an enhancement of an existing feature label Jun 7, 2018
@robertpang robertpang self-assigned this Jun 7, 2018
@rohitjoshi
Copy link

rohitjoshi commented Jun 13, 2018

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

}

@kmuthukk
Copy link
Collaborator

kmuthukk commented Jun 13, 2018

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

@rohitjoshi
Copy link

rohitjoshi commented Jun 13, 2018

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

yugabyte-ci pushed a commit that referenced this issue Jun 15, 2018
Summary:
This revision implements unique secondary index with conditional DML support.

In addition, this revision changes the status row returned when a conditional DML fails due to failed conditions. Apart from the existing values of the non-key columns that are read to check the conditions, the row now includes the primary key of the row being modified (or just the hash key if the DML modifies only the hash key or the static columns). For example:

```
cqlsh:k> create table t (k int primary key, c int);
cqlsh:k> insert into t (k, c) values (1, 2);
cqlsh:k> select * from t;

 k | c
---+---
 1 | 2

cqlsh:k> insert into t (k, c) values (1, 2) if not exists or c <> 2;

 [applied] | k | c
-----------+---+---
     False | 1 | 2
```

Test Plan: TestIndex.testUniqueIndex

Reviewers: kannan, mihnea

Reviewed By: mihnea

Subscribers: kannan, bogdan, yql, bharat

Differential Revision: https://phabricator.dev.yugabyte.com/D4958
@robertpang
Copy link
Contributor Author

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

@rohitjoshi
Copy link

👍 looking forward to try this out.

@kmuthukk
Copy link
Collaborator

kmuthukk commented Jun 15, 2018

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

yugabyte-ci pushed a commit that referenced this issue Jun 15, 2018
Summary: This revision fixes the YCQL proxy to abort the transaction if a conditional DML fails to apply due to unsatisfied condition.

Test Plan: TestIndex.testConditionalDML

Reviewers: mihnea

Reviewed By: mihnea

Subscribers: yql

Differential Revision: https://phabricator.dev.yugabyte.com/D4978
yugabyte-ci pushed a commit that referenced this issue Jun 18, 2018
… violation

Summary: Always raise unique constraint error for when inserting duplicate value in a unique secondary index even when executing via an IF NOT EXISTS conditional DML statement.

Test Plan: TestIndex.testConditionalDML

Reviewers: mihnea

Reviewed By: mihnea

Subscribers: kannan, yql

Differential Revision: https://phabricator.dev.yugabyte.com/D4982
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement This is an enhancement of an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants