-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathrouting_hint.out
230 lines (200 loc) · 4.89 KB
/
routing_hint.out
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
\c spqr-console
SPQR router admin console
Here you can configure your routing rules
------------------------------------------------
You can find documentation here
https://github.com/pg-sharding/spqr/tree/master/docs
CREATE DISTRIBUTION ds1 COLUMN TYPES integer;
add distribution
------------------------
distribution id -> ds1
(1 row)
CREATE KEY RANGE krid1 FROM 1 ROUTE TO sh1 FOR DISTRIBUTION ds1;
add key range
---------------
bound -> 1
(1 row)
CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds1;
add key range
---------------
bound -> 11
(1 row)
ALTER DISTRIBUTION ds1 ATTACH RELATION test DISTRIBUTION KEY id;
attach table
-------------------------
relation name -> test
distribution id -> ds1
(2 rows)
\c regress
CREATE TABLE test(id int, age int);
NOTICE: send query to shard(s) : sh1,sh2,sh3,sh4
-- TODO: specify distribution as well as sharding_key
INSERT INTO test(id, age) VALUES (1210, 16) /*__spqr__sharding_key: 1, __spqr__distribution: ds1 */;
NOTICE: send query to shard(s) : sh1
INSERT INTO test(id, age) VALUES (10, 16) /*__spqr__sharding_key: 30, __spqr__distribution: ds1 */;
NOTICE: send query to shard(s) : sh2
INSERT INTO test(id, age) VALUES (10, 16) /*__spqr__sharding_key: 3000, __spqr__distribution: ds1 */;
NOTICE: send query to shard(s) : sh2
-- test transaction support for route-local variables;
SET __spqr__distribution = 'ds1';
SHOW __spqr__distribution;
ERROR: parameter "__spqr__distribution" isn't user accessible
SET __spqr__sharding_key = 1;
SHOW __spqr__sharding_key;
sharding key
--------------
1
(1 row)
SELECT * FROM test;
NOTICE: send query to shard(s) : sh1
id | age
------+-----
1210 | 16
(1 row)
SET __spqr__sharding_key = 12;
SELECT * FROM test;
NOTICE: send query to shard(s) : sh2
id | age
----+-----
10 | 16
10 | 16
(2 rows)
BEGIN;
SET __spqr__sharding_key = 1;
SELECT * FROM test;
NOTICE: send query to shard(s) : sh1
id | age
------+-----
1210 | 16
(1 row)
ROLLBACK;
-- should return to previous value, so select from second shard
SELECT * FROM test;
NOTICE: send query to shard(s) : sh2
id | age
----+-----
10 | 16
10 | 16
(2 rows)
RESET __spqr__sharding_key;
\c regress
-- cleanup test relation to avoid confusion
TRUNCATE test;
NOTICE: send query to shard(s) : sh1,sh2,sh3,sh4
COPY test (id, age) FROM STDIN;
NOTICE: send query to shard(s) : sh1,sh2,sh3,sh4
-- SELECT here with order to avoid flaps
SELECT * FROM test ORDER BY id /* __spqr__execute_on: sh1 */;
NOTICE: send query to shard(s) : sh1
id | age
----+-----
1 | 1
5 | 5
10 | 10
(3 rows)
SELECT * FROM test ORDER BY id /* __spqr__execute_on: sh2 */;
NOTICE: send query to shard(s) : sh2
id | age
----+-----
15 | 15
20 | 20
25 | 25
(3 rows)
SET __spqr__execute_on TO sh1;
SHOW __spqr__execute_on;
execute on
------------
sh1
(1 row)
SELECT * FROM test ORDER BY id;
NOTICE: send query to shard(s) : sh1
id | age
----+-----
1 | 1
5 | 5
10 | 10
(3 rows)
SET __spqr__execute_on TO sh2;
SHOW __spqr__execute_on;
execute on
------------
sh2
(1 row)
SELECT * FROM test ORDER BY id;
NOTICE: send query to shard(s) : sh2
id | age
----+-----
15 | 15
20 | 20
25 | 25
(3 rows)
SET __spqr__execute_on TO sh1;
-- overrides prev set
SELECT * FROM test ORDER BY id /* __spqr__execute_on: sh2 */;
NOTICE: send query to shard(s) : sh2
id | age
----+-----
15 | 15
20 | 20
25 | 25
(3 rows)
-- After stmt select from sh1, not sh2
SELECT * FROM test ORDER BY id;
NOTICE: send query to shard(s) : sh1
id | age
----+-----
1 | 1
5 | 5
10 | 10
(3 rows)
SHOW __spqr__scatter_query; -- error
ERROR: parameter "__spqr__scatter_query" isn't user accessible
SHOW __spqr__default_route_behaviour;
default route behaviour
-------------------------
(1 row)
RESET __spqr__execute_on;
SHOW __spqr__execute_on;
execute on
------------
(1 row)
SET __spqr__default_route_behaviour to 'BLOCK';
SELECT 1 FROM test WHERE id IN (5, 25) /* __spqr__scatter_query: true, __spqr__default_route_behaviour: allow */;
NOTICE: send query to shard(s) : sh1,sh2,sh3,sh4
?column?
----------
1
1
(2 rows)
SET __spqr__default_route_behaviour to 'ALLOW';
SHOW __spqr__default_route_behaviour;
default route behaviour
-------------------------
ALLOW
(1 row)
SELECT 1 FROM test WHERE id IN (5, 25) /* __spqr__scatter_query: true */;
NOTICE: send query to shard(s) : sh1,sh2,sh3,sh4
?column?
----------
1
1
(2 rows)
-- restart session, reset all params
\c regress
DROP TABLE test;
NOTICE: send query to shard(s) : sh1,sh2,sh3,sh4
\c spqr-console
SPQR router admin console
Here you can configure your routing rules
------------------------------------------------
You can find documentation here
https://github.com/pg-sharding/spqr/tree/master/docs
DROP DISTRIBUTION ALL CASCADE;
drop distribution
------------------------
distribution id -> ds1
(1 row)
DROP KEY RANGE ALL;
drop key range
----------------
(0 rows)