secondary index in cockroachdb

Solutions on MaxInterview for secondary index in cockroachdb by the best coders in the world

showing results for - "secondary index in cockroachdb"
Marley
29 Apr 2016
1#This helps you understand Secondary index concept 
2
3$ cat index_demo.sql
4DROP TABLE IF EXISTS users;
5CREATE TABLE users (id INT PRIMARY KEY,
6                    last_name STRING NOT NULL,
7                    first_name STRING NOT NULL,
8                    country STRING,
9                    city STRING);
10INSERT INTO users (id, last_name, first_name, country, city)
11     VALUES (1, 'Cross', 'William', 'USA', 'Jersey City'),
12            (2, 'Seldess', 'Jesse', 'USA', 'New York'),
13            (3, 'Hirata', 'Lauren', 'USA', 'New York'),
14            (4, 'Cross', 'Zachary', 'USA', 'Seattle'),
15            (5, 'Shakespeare', 'William', 'UK', 'Stratford-upon-Avon');
16$ clear
17$ cockroach sql --insecure < index_demo.sql 
18
19SELECT * FROM users;
20SHOW INDEXES FROM users;
21SELECT * FROM users WHERE id = 1;
22EXPLAIN SELECT * FROM users WHERE id = 1;
23EXPLAIN SELECT * FROM users WHERE last_name = 'Cross' AND first_name = 'William';
24CREATE INDEX my_index ON users (last_name, first_name);
25SHOW INDEXES FROM users;
26EXPLAIN SELECT * FROM users WHERE last_name = 'Cross' AND first_name = 'William';