forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistsql_numtables
More file actions
226 lines (187 loc) · 5.17 KB
/
distsql_numtables
File metadata and controls
226 lines (187 loc) · 5.17 KB
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
# LogicTest: 5node-default-configs
# This test occasionally times out due to overload under race.
skip under race
# First, we set up two data tables:
# - NumToSquare maps integers from 1 to 100 to their squares
# - NumToStr maps integers from 1 to 100*100 to strings; this table is
# split and distributed to all nodes.
statement ok
CREATE TABLE NumToSquare (x INT PRIMARY KEY, xsquared INT)
statement ok
INSERT INTO NumToSquare SELECT i, i*i FROM generate_series(1, 100) AS g(i)
statement ok
CREATE TABLE NumToStr (y INT PRIMARY KEY, str STRING)
# Split into five parts.
statement ok
ALTER TABLE NumToStr SPLIT AT SELECT (i * 100 * 100 / 5)::int FROM generate_series(1, 4) AS g(i)
# Relocate the five parts to the five nodes.
retry
statement ok
ALTER TABLE NumToStr EXPERIMENTAL_RELOCATE
SELECT ARRAY[i+1], (i * 100 * 100 / 5)::int FROM generate_series(0, 4) AS g(i)
statement ok
INSERT INTO NumToStr SELECT i, to_english(i) FROM generate_series(1, 100*100) AS g(i)
# Verify data placement.
query TTTI colnames
SELECT start_key, end_key, replicas, lease_holder FROM [SHOW RANGES FROM TABLE NumToSquare WITH DETAILS]
----
start_key end_key replicas lease_holder
<before:/Table/XX> <after:/Table/XX/1/2000> {1} 1
query TTTI colnames,rowsort
SELECT start_key, end_key, replicas, lease_holder FROM [SHOW RANGES FROM TABLE NumToStr WITH DETAILS]
ORDER BY 1
----
start_key end_key replicas lease_holder
<before:/Table/XX> …/1/2000 {1} 1
…/1/2000 …/1/4000 {2} 2
…/1/4000 …/1/6000 {3} 3
…/1/6000 …/1/8000 {4} 4
…/1/8000 <after:/Max> {5} 5
#
# -- Basic tests --
#
# Query with a restricted span.
query IIIT
SELECT 5, 2+y, * FROM NumToStr WHERE y <= 10 ORDER BY str
----
5 10 8 eight
5 7 5 five
5 6 4 four
5 11 9 nine
5 3 1 one
5 12 10 one-zero
5 9 7 seven
5 8 6 six
5 5 3 three
5 4 2 two
# Query which requires a full table scan.
query IIIT
SELECT 5, 2 + y, * FROM NumToStr WHERE y % 1000 = 0 ORDER BY str
----
5 8002 8000 eight-zero-zero-zero
5 5002 5000 five-zero-zero-zero
5 4002 4000 four-zero-zero-zero
5 9002 9000 nine-zero-zero-zero
5 1002 1000 one-zero-zero-zero
5 10002 10000 one-zero-zero-zero-zero
5 7002 7000 seven-zero-zero-zero
5 6002 6000 six-zero-zero-zero
5 3002 3000 three-zero-zero-zero
5 2002 2000 two-zero-zero-zero
# Query with a restricted span + filter.
query T
SELECT str FROM NumToStr WHERE y < 10 AND str LIKE '%e%' ORDER BY y
----
one
three
five
seven
eight
nine
# Query which requires a full table scan.
query T
SELECT str FROM NumToStr WHERE y % 1000 = 0 AND str LIKE '%i%' ORDER BY y
----
five-zero-zero-zero
six-zero-zero-zero
eight-zero-zero-zero
nine-zero-zero-zero
#
# -- Join tests --
#
# Save the result of the following statement to a label.
query IT rowsort label-sq-str
SELECT i, to_english(i*i) FROM generate_series(1, 100) AS g(i)
# Compare the results of this query to the one above.
query IT rowsort label-sq-str
SELECT x, str FROM NumToSquare JOIN NumToStr ON y = xsquared
# Save the result of the following statement to a label.
query IT rowsort label-sq-2-str
SELECT 2*i, to_english(2*i) FROM generate_series(1, 50) AS g(i)
# Compare the results of this query to the one above.
query IT rowsort label-sq-2-str
SELECT x, str FROM NumToSquare JOIN NumToStr ON x = y WHERE x % 2 = 0
#
# -- Aggregation tests --
#
# Sum the numbers in the NumToStr table. The expected result is
# n * n * (n * n + 1) / 2
query R
SELECT sum(y) FROM NumToStr
----
50005000
# Count the rows in the NumToStr table.
query I
SELECT count(*) FROM NumToStr
----
10000
# Count how many numbers contain the digit 5.
# Result calculated here: https://play.golang.org/p/e-YsJRDsXF
query I
SELECT count(*) FROM NumToStr WHERE str LIKE '%five%'
----
3439
#
# -- Limit tests --
#
query I
SELECT y FROM NumToStr ORDER BY y LIMIT 5
----
1
2
3
4
5
query I
SELECT y FROM NumToStr WHERE y < 1000 OR y > 9000 ORDER BY y DESC LIMIT 5
----
10000
9999
9998
9997
9996
query I
SELECT y FROM NumToStr ORDER BY y OFFSET 5 LIMIT 2
----
6 7
query I
SELECT y FROM NumToStr ORDER BY y LIMIT 0
----
query I
SELECT * FROM (SELECT y FROM NumToStr LIMIT 3) AS a ORDER BY y OFFSET 3
----
query I
SELECT y FROM NumToStr ORDER BY str LIMIT 5
----
8
88
888
8888
8885
query I
SELECT y FROM (SELECT y FROM NumToStr ORDER BY y LIMIT 5) AS a WHERE y <> 2
----
1
3
4
5
# Regression test for #20481.
query I
SELECT count(*) FROM (SELECT 1 AS one FROM NumToSquare WHERE x > 10 ORDER BY xsquared LIMIT 10)
----
10
# Regression test for incorrectly propagating "misplanned ranges" metadata when
# only a single TableReader is created in a distributed plan (#101471). The
# query is constructed in such a manner so that the TableReader is placed on
# node 2 and then it needs to perform remote reads since the range with y >=
# 4000 lives on node 3.
statement ok
SET TRACING = ON;
SELECT * FROM NumToStr WHERE y >= 3999 LIMIT 2;
SET TRACING = OFF;
# Ensure that we didn't create the "misplanned ranges" metadata for the range
# with y >= 4000.
query I
SELECT count(*) FROM [SHOW TRACE FOR SESSION] WHERE message LIKE '%misplanned ranges%' AND location LIKE '%readerbase%'
----
0