-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path07-demo-placement-rule-classroom81-region.sql
executable file
·67 lines (67 loc) · 2.56 KB
/
07-demo-placement-rule-classroom81-region.sql
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* source 07-demo-placement-rule-classroom81-region.sql */
/* This script is designed for 201.3 training Exercise 8-2 */
/* Query 1: Show available labels */
SHOW PLACEMENT LABELS;
/* Query 2: Show TiKV stores and their labels */
SELECT store_id,
address,
store_state_name,
label
FROM information_schema.tikv_store_status
WHERE label NOT LIKE '%tiflash%';
/* Create the geo-location placement policy favor for seattle */
DROP PLACEMENT POLICY IF EXISTS seattle;
CREATE PLACEMENT POLICY seattle PRIMARY_REGION = "seattle" REGIONS = "seattle,tokyo" FOLLOWERS = 2;
/* Create the geo-location placement policy favor for tokyo */
DROP PLACEMENT POLICY IF EXISTS tokyo;
CREATE PLACEMENT POLICY tokyo PRIMARY_REGION = "tokyo" REGIONS = "tokyo,seattle" FOLLOWERS = 2;
/* Query 3: Show the definition of created placement policies */
SELECT policy_name,
primary_region,
regions
FROM information_schema.placement_policies
ORDER BY primary_region;
/* Create a table using `seattle` placement policy */
DROP TABLE IF EXISTS test.orders_seattle;
CREATE TABLE test.orders_seattle (
order_id INT PRIMARY KEY AUTO_INCREMENT,
item VARCHAR(50),
order_date DATE
) PLACEMENT POLICY = seattle;
/* Create a table using `tokyo` placement policy */
DROP TABLE IF EXISTS test.orders_tokyo;
CREATE TABLE test.orders_tokyo (
order_id INT PRIMARY KEY AUTO_INCREMENT,
item VARCHAR(50),
order_date DATE
) PLACEMENT POLICY = tokyo;
/* Query 4: Show relevant information about table test.orders_seattle */
SHOW TABLE test.orders_seattle REGIONS \ G
SELECT kvrs.region_id,
kvss.store_id,
kvrp.is_leader,
kvss.label,
kvss.start_ts
FROM information_schema.tikv_region_status kvrs
JOIN information_schema.tikv_region_peers kvrp ON kvrs.region_id = kvrp.region_id
JOIN information_schema.tikv_store_status kvss ON kvrp.store_id = kvss.store_id
JOIN information_schema.tables t ON t.table_name = kvrs.table_name
WHERE t.table_schema = 'test'
AND t.table_name = 'orders_seattle'
AND kvrs.is_index = 0
AND kvrp.is_leader = 1;
/* Query 5: Show relevant information about table test.order2 */
SHOW TABLE test.orders_tokyo REGIONS \ G
SELECT kvrs.region_id,
kvss.store_id,
kvrp.is_leader,
kvss.label,
kvss.start_ts
FROM information_schema.tikv_region_status kvrs
JOIN information_schema.tikv_region_peers kvrp ON kvrs.region_id = kvrp.region_id
JOIN information_schema.tikv_store_status kvss ON kvrp.store_id = kvss.store_id
JOIN information_schema.tables t ON t.table_name = kvrs.table_name
WHERE t.table_schema = 'test'
AND t.table_name = 'orders_tokyo'
AND kvrs.is_index = 0
AND kvrp.is_leader = 1;