-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path5.4 Composite Indexes.sql
More file actions
69 lines (28 loc) · 897 Bytes
/
5.4 Composite Indexes.sql
File metadata and controls
69 lines (28 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- Composite Indexes
EXPLAIN SELECT *
FROM bakery.us_household_income
WHERE State_Name = 'Rhode Island'
AND ALand > 500000;
CREATE INDEX idx_state_Aland
ON bakery.us_household_income(State_Name(8),ALand);
EXPLAIN SELECT *
FROM bakery.us_household_income
WHERE State_Name = 'Rhode Island'
AND ALand > 10000000;
-- ORDER OF COLUMNS IN INDEX
SHOW INDEXES IN bakery.us_household_income;
SELECT *
FROM bakery.us_household_income
WHERE State_ab = 'NC'
AND City LIKE 'A%';
SELECT COUNT(DISTINCT State_ab), COUNT(DISTINCT City)
FROM bakery.us_household_income;
CREATE INDEX idx_city_stateab
ON bakery.us_household_income(City(10), State_ab(2));
SHOW INDEXES IN bakery.us_household_income;
EXPLAIN SELECT *
FROM bakery.us_household_income
WHERE State_ab = 'NC'
AND City LIKE 'A%';
CREATE INDEX idx_stateab_city
ON bakery.us_household_income(State_ab(2),City(10));