-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path07-demo-shard-rowid-bits-01-show.sql
executable file
·135 lines (128 loc) · 5.6 KB
/
07-demo-shard-rowid-bits-01-show.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* source 07-demo-shard-rowid-bits-01-show.sql */
/* Setup the schema for option SHARD_ROW_ID_BITS */
DROP TABLE IF EXISTS test.shard_rb;
CREATE TABLE test.shard_rb (
id bigint,
name char(255)
) SHARD_ROW_ID_BITS = 4;
/* Populate Seed */
INSERT INTO test.shard_rb (name) VALUES ('A');
INSERT INTO test.shard_rb (name) VALUES ('B');
INSERT INTO test.shard_rb (name) VALUES ('C');
INSERT INTO test.shard_rb (name) VALUES ('D');
INSERT INTO test.shard_rb (name) VALUES ('E');
INSERT INTO test.shard_rb (name) VALUES ('F');
INSERT INTO test.shard_rb (name) VALUES ('G');
INSERT INTO test.shard_rb (name) VALUES ('H');
INSERT INTO test.shard_rb (name) VALUES ('I');
INSERT INTO test.shard_rb (name) VALUES ('J');
INSERT INTO test.shard_rb (name) VALUES ('K');
INSERT INTO test.shard_rb (name) VALUES ('L');
INSERT INTO test.shard_rb (name) VALUES ('M');
INSERT INTO test.shard_rb (name) VALUES ('N');
INSERT INTO test.shard_rb (name) VALUES ('O');
INSERT INTO test.shard_rb (name) VALUES ('P');
INSERT INTO test.shard_rb (name) VALUES ('Q');
INSERT INTO test.shard_rb (name) VALUES ('R');
INSERT INTO test.shard_rb (name) VALUES ('S');
INSERT INTO test.shard_rb (name) VALUES ('T');
INSERT INTO test.shard_rb (name) VALUES ('U');
INSERT INTO test.shard_rb (name) VALUES ('V');
INSERT INTO test.shard_rb (name) VALUES ('W');
INSERT INTO test.shard_rb (name) VALUES ('X');
INSERT INTO test.shard_rb (name) VALUES ('Y');
INSERT INTO test.shard_rb (name) VALUES ('Z');
INSERT INTO test.shard_rb (name) VALUES ('a');
INSERT INTO test.shard_rb (name) VALUES ('b');
INSERT INTO test.shard_rb (name) VALUES ('c');
INSERT INTO test.shard_rb (name) VALUES ('d');
INSERT INTO test.shard_rb (name) VALUES ('e');
INSERT INTO test.shard_rb (name) VALUES ('f');
INSERT INTO test.shard_rb (name) VALUES ('g');
INSERT INTO test.shard_rb (name) VALUES ('h');
INSERT INTO test.shard_rb (name) VALUES ('i');
INSERT INTO test.shard_rb (name) VALUES ('j');
INSERT INTO test.shard_rb (name) VALUES ('k');
INSERT INTO test.shard_rb (name) VALUES ('l');
INSERT INTO test.shard_rb (name) VALUES ('m');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
INSERT INTO test.shard_rb (name) VALUES ('x1');
/* Greetings to CBO */
ANALYZE table test.shard_rb;
select 'test.shard_rb' as Title;
desc test.shard_rb;
select TIDB_ROW_ID_SHARDING_INFO, TIDB_PK_TYPE
from information_schema.tables
where table_schema='test'
and table_name='t9';
/* check value */
SELECT substr(cast(_tidb_rowid as CHAR),1,2) as id_prefix, count(*) as approx_rows_in_shard
FROM test.shard_rb
GROUP BY id_prefix
HAVING approx_rows_in_shard > 1
ORDER BY id_prefix;