-
Notifications
You must be signed in to change notification settings - Fork 68
/
queries.out
199 lines (186 loc) · 6.92 KB
/
queries.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
-- ===================================================================
-- test end-to-end query functionality
-- ===================================================================
CREATE TABLE articles (
id bigint NOT NULL,
author_id bigint NOT NULL,
title text NOT NULL,
word_count integer NOT NULL CHECK (word_count > 0)
);
SELECT master_create_distributed_table('articles', 'author_id');
master_create_distributed_table
---------------------------------
(1 row)
-- test when a table is distributed but no shards created yet
SELECT count(*) from articles;
ERROR: could not find any shards for query
DETAIL: No shards exist for distributed table "articles".
HINT: Run master_create_worker_shards to create shards and try again.
\set VERBOSITY terse
SELECT master_create_worker_shards('articles', 2, 1);
WARNING: Connection failed to adeadhost:5432
WARNING: could not create shard on "adeadhost:5432"
master_create_worker_shards
-----------------------------
(1 row)
\set VERBOSITY default
INSERT INTO articles VALUES ( 1, 1, 'arsenous', 9572);
INSERT INTO articles VALUES ( 2, 2, 'abducing', 13642);
INSERT INTO articles VALUES ( 3, 3, 'asternal', 10480);
INSERT INTO articles VALUES ( 4, 4, 'altdorfer', 14551);
INSERT INTO articles VALUES ( 5, 5, 'aruru', 11389);
INSERT INTO articles VALUES ( 6, 6, 'atlases', 15459);
INSERT INTO articles VALUES ( 7, 7, 'aseptic', 12298);
INSERT INTO articles VALUES ( 8, 8, 'agatized', 16368);
INSERT INTO articles VALUES ( 9, 9, 'alligate', 438);
INSERT INTO articles VALUES (10, 10, 'aggrandize', 17277);
INSERT INTO articles VALUES (11, 1, 'alamo', 1347);
INSERT INTO articles VALUES (12, 2, 'archiblast', 18185);
INSERT INTO articles VALUES (13, 3, 'aseyev', 2255);
INSERT INTO articles VALUES (14, 4, 'andesite', 19094);
INSERT INTO articles VALUES (15, 5, 'adversa', 3164);
INSERT INTO articles VALUES (16, 6, 'allonym', 2);
INSERT INTO articles VALUES (17, 7, 'auriga', 4073);
INSERT INTO articles VALUES (18, 8, 'assembly', 911);
INSERT INTO articles VALUES (19, 9, 'aubergiste', 4981);
INSERT INTO articles VALUES (20, 10, 'absentness', 1820);
INSERT INTO articles VALUES (21, 1, 'arcading', 5890);
INSERT INTO articles VALUES (22, 2, 'antipope', 2728);
INSERT INTO articles VALUES (23, 3, 'abhorring', 6799);
INSERT INTO articles VALUES (24, 4, 'audacious', 3637);
INSERT INTO articles VALUES (25, 5, 'antehall', 7707);
INSERT INTO articles VALUES (26, 6, 'abington', 4545);
INSERT INTO articles VALUES (27, 7, 'arsenous', 8616);
INSERT INTO articles VALUES (28, 8, 'aerophyte', 5454);
INSERT INTO articles VALUES (29, 9, 'amateur', 9524);
INSERT INTO articles VALUES (30, 10, 'andelee', 6363);
INSERT INTO articles VALUES (31, 1, 'athwartships', 7271);
INSERT INTO articles VALUES (32, 2, 'amazon', 11342);
INSERT INTO articles VALUES (33, 3, 'autochrome', 8180);
INSERT INTO articles VALUES (34, 4, 'amnestied', 12250);
INSERT INTO articles VALUES (35, 5, 'aminate', 9089);
INSERT INTO articles VALUES (36, 6, 'ablation', 13159);
INSERT INTO articles VALUES (37, 7, 'archduchies', 9997);
INSERT INTO articles VALUES (38, 8, 'anatine', 14067);
INSERT INTO articles VALUES (39, 9, 'anchises', 10906);
INSERT INTO articles VALUES (40, 10, 'attemper', 14976);
INSERT INTO articles VALUES (41, 1, 'aznavour', 11814);
INSERT INTO articles VALUES (42, 2, 'ausable', 15885);
INSERT INTO articles VALUES (43, 3, 'affixal', 12723);
INSERT INTO articles VALUES (44, 4, 'anteport', 16793);
INSERT INTO articles VALUES (45, 5, 'afrasia', 864);
INSERT INTO articles VALUES (46, 6, 'atlanta', 17702);
INSERT INTO articles VALUES (47, 7, 'abeyance', 1772);
INSERT INTO articles VALUES (48, 8, 'alkylic', 18610);
INSERT INTO articles VALUES (49, 9, 'anyone', 2681);
INSERT INTO articles VALUES (50, 10, 'anjanette', 19519);
-- single-shard tests
-- test simple select for a single row
SELECT * FROM articles WHERE author_id = 10 AND id = 50;
id | author_id | title | word_count
----+-----------+-----------+------------
50 | 10 | anjanette | 19519
(1 row)
-- get all titles by a single author
SELECT title FROM articles WHERE author_id = 10;
title
------------
aggrandize
absentness
andelee
attemper
anjanette
(5 rows)
-- try ordering them by word count
SELECT title, word_count FROM articles
WHERE author_id = 10
ORDER BY word_count DESC NULLS LAST;
title | word_count
------------+------------
anjanette | 19519
aggrandize | 17277
attemper | 14976
andelee | 6363
absentness | 1820
(5 rows)
-- look at last two articles by an author
SELECT title, id FROM articles
WHERE author_id = 5
ORDER BY id
LIMIT 2;
title | id
---------+----
aruru | 5
adversa | 15
(2 rows)
-- find all articles by two authors in same shard
SELECT title, author_id FROM articles
WHERE author_id = 7 OR author_id = 8
ORDER BY author_id ASC, id;
title | author_id
-------------+-----------
aseptic | 7
auriga | 7
arsenous | 7
archduchies | 7
abeyance | 7
agatized | 8
assembly | 8
aerophyte | 8
anatine | 8
alkylic | 8
(10 rows)
-- add in some grouping expressions, still on same shard
SELECT author_id, sum(word_count) AS corpus_size FROM articles
WHERE author_id = 1 OR author_id = 7 OR author_id = 8 OR author_id = 10
GROUP BY author_id
HAVING sum(word_count) > 40000
ORDER BY sum(word_count) DESC;
author_id | corpus_size
-----------+-------------
10 | 59955
8 | 55410
(2 rows)
-- UNION/INTERSECT queries are unsupported
SELECT * FROM articles WHERE author_id = 10 UNION
SELECT * FROM articles WHERE author_id = 1;
ERROR: unsupported range table type: 1
-- queries using CTEs are unsupported
CREATE TABLE authors ( name text, id bigint );
WITH long_names AS ( SELECT id FROM authors WHERE char_length(name) > 15 )
SELECT title FROM articles;
ERROR: cannot perform distributed planning on this query
DETAIL: Joins are currently unsupported
-- joins are unsupported
SELECT title, authors.name FROM authors, articles WHERE authors.id = articles.author_id;
ERROR: cannot perform distributed planning on this query
DETAIL: Joins are currently unsupported
-- subqueries are not supported
SELECT * FROM articles WHERE author_id IN (SELECT id FROM authors WHERE name LIKE '%a');
ERROR: unsupported range table type: 1
-- test cross-shard queries
SELECT COUNT(*) FROM articles;
count
-------
50
(1 row)
SELECT author_id, sum(word_count) AS corpus_size FROM articles
GROUP BY author_id
HAVING sum(word_count) > 25000
ORDER BY sum(word_count) DESC
LIMIT 5;
author_id | corpus_size
-----------+-------------
4 | 66325
2 | 61782
10 | 59955
8 | 55410
6 | 50867
(5 rows)
-- verify temp tables used by cross-shard queries do not persist
SELECT COUNT(*) FROM pg_class WHERE relname LIKE 'pg_shard_temp_table%' AND
relkind = 'r';
count
-------
0
(1 row)