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

Example of non-prefixed local index on a geo distributed table #3575

Closed
robert-s-lee opened this issue Aug 22, 2018 · 2 comments
Closed

Example of non-prefixed local index on a geo distributed table #3575

robert-s-lee opened this issue Aug 22, 2018 · 2 comments
Assignees
Labels
O-sales-eng Internal source: Sales Engineering P-2 Normal priority; secondary task T-missing-info

Comments

@robert-s-lee
Copy link
Contributor

robert-s-lee commented Aug 22, 2018

When a index is partitioned, there is concept of local and global index. Each type can have prefixed and non-prefixed. A secondary index tends to be global non-prefix. Some examples include secondary index for email id, address, phone numbers.

Read performance of global non-prefixed index on a globally distributed CockroachDB is highly dependent on network latency. In order to provide predictable read performance, multiple local non-prefixed index should be created and used. This trade write performance when that field changes against predictable good read performance. A secondary index that is frequently used but seldom changes are a good candidate for this technique.

CREATE TABLE IF NOT EXISTS customers (
  customer_id UUID,
  email string,
  PRIMARY KEY (customer_id),
  index orders_email_america (email),
  index orders_email_europe (email),
  index orders_email_asia (email)
) PARTITION BY RANGE (customer_id) (
    PARTITION americas VALUES FROM (b'\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') to (b'\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
    ,PARTITION europe VALUES FROM (b'\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') to (b'\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
    ,PARTITION asia VALUES FROM (b'\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') to (b'\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
);

ALTER PARTITION americas OF TABLE customers EXPERIMENTAL CONFIGURE ZONE 'constraints: {"+r=americas": 2}';
ALTER PARTITION europe OF TABLE customers EXPERIMENTAL CONFIGURE ZONE 'constraints: {"+r=americas": 2}';
ALTER PARTITION asia OF TABLE customers EXPERIMENTAL CONFIGURE ZONE 'constraints: {"+r=americas": 2}';

ALTER INDEX customers@orders_email_america EXPERIMENTAL CONFIGURE ZONE 'constraints: {"+r=americas": 2}';
ALTER INDEX customers@orders_email_europe EXPERIMENTAL CONFIGURE ZONE 'constraints: {"+r=europe": 2}';
ALTER INDEX customers@orders_email_asia EXPERIMENTAL CONFIGURE ZONE 'constraints: {"+r=asia": 2}';

ALTER INDEX customers@orders_email_america EXPERIMENTAL CONFIGURE ZONE 'experimental_lease_preferences: [[+r=americas]]';
ALTER INDEX customers@orders_email_europe EXPERIMENTAL CONFIGURE ZONE 'experimental_lease_preferences: [[+r=europe]]';
ALTER INDEX customers@orders_email_asia EXPERIMENTAL CONFIGURE ZONE 'experimental_lease_preferences: [[+r=asia]]';


insert into customers (customer_id,email) values (b'\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', '[email protected]');

SELECT * FROM customers@orders_email_america WHERE email = '[email protected]';
SELECT * FROM customers@orders_email_europe WHERE email = '[email protected]';
SELECT * FROM customers@orders_email_asia WHERE email = '[email protected]';
@robert-s-lee robert-s-lee self-assigned this Aug 22, 2018
@robert-s-lee robert-s-lee changed the title Example of non-prefixed local index on a geo graphically distributed table Example of non-prefixed local index on a geo distributed table Aug 23, 2018
@robert-s-lee
Copy link
Contributor Author

@drewdeally

@awoods187
Copy link
Contributor

Closing this since we have duplicate index documented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-sales-eng Internal source: Sales Engineering P-2 Normal priority; secondary task T-missing-info
Projects
None yet
Development

No branches or pull requests

4 participants