File: tree_variants.result

package info (click to toggle)
tarantool 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 85,364 kB
  • sloc: ansic: 513,760; cpp: 69,489; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,173; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (325 lines) | stat: -rw-r--r-- 8,489 bytes parent folder | download | duplicates (5)
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
env = require('test_run')
---
...
test_run = env.new()
---
...
engine = test_run:get_cfg('engine')
---
...
space = box.schema.space.create('tweedledum', { engine = engine })
---
...
i0 = space:create_index('primary', { type = 'tree', parts = {1, 'unsigned'}, unique = true })
---
...
i1 = space:create_index('i1', { type = 'tree', parts = {2, 'unsigned'}, unique = false })
---
...
i2 = space:create_index('i2', { type = 'tree', parts = {3, 'unsigned'}, unique = false })
---
...
i3 = space:create_index('i3', { type = 'tree', parts = {4, 'string', 5, 'string'}, unique = false })
---
...
i4 = space:create_index('i4', { type = 'tree', parts = {7, 'string', 6, 'string'}, unique = false })
---
...
i5 = space:create_index('i5', { type = 'tree', parts = {9, 'unsigned'}, unique = false })
---
...
i6 = space:create_index('i6', { type = 'tree', parts = {7, 'string', 6, 'string', 4, 'string', 5, 'string', 9, 'unsigned'}, unique = true })
---
...
space:insert{0, 0, 100, 'Joe', 'Sixpack', 'Drinks', 'Amstel', 'bar', 2000}
---
- [0, 0, 100, 'Joe', 'Sixpack', 'Drinks', 'Amstel', 'bar', 2000]
...
space:insert{1, 1, 200, 'Joe', 'Sixpack', 'Drinks', 'Heineken', 'bar', 2001}
---
- [1, 1, 200, 'Joe', 'Sixpack', 'Drinks', 'Heineken', 'bar', 2001]
...
space:insert{2, 2, 200, 'Joe', 'Sixpack', 'Drinks', 'Carlsberg', 'bar', 2002}
---
- [2, 2, 200, 'Joe', 'Sixpack', 'Drinks', 'Carlsberg', 'bar', 2002]
...
space:insert{3, 3, 300, 'Joe', 'Sixpack', 'Drinks', 'Corona Extra', 'bar', 2003}
---
- [3, 3, 300, 'Joe', 'Sixpack', 'Drinks', 'Corona Extra', 'bar', 2003]
...
space:insert{4, 4, 300, 'Joe', 'Sixpack', 'Drinks', 'Stella Artois', 'bar', 2004}
---
- [4, 4, 300, 'Joe', 'Sixpack', 'Drinks', 'Stella Artois', 'bar', 2004]
...
space:insert{5, 5, 300, 'Joe', 'Sixpack', 'Drinks', 'Miller Genuine Draft', 'bar', 2005}
---
- [5, 5, 300, 'Joe', 'Sixpack', 'Drinks', 'Miller Genuine Draft', 'bar', 2005]
...
space:insert{6, 6, 400, 'John', 'Smoker', 'Hits', 'A Pipe', 'foo', 2006}
---
- [6, 6, 400, 'John', 'Smoker', 'Hits', 'A Pipe', 'foo', 2006]
...
space:insert{7, 7, 400, 'John', 'Smoker', 'Hits', 'A Bong', 'foo', 2007}
---
- [7, 7, 400, 'John', 'Smoker', 'Hits', 'A Bong', 'foo', 2007]
...
space:insert{8, 8, 400, 'John', 'Smoker', 'Rolls', 'A Joint', 'foo', 2008}
---
- [8, 8, 400, 'John', 'Smoker', 'Rolls', 'A Joint', 'foo', 2008]
...
space:insert{9, 9, 400, 'John', 'Smoker', 'Rolls', 'A Blunt', 'foo', 2009}
---
- [9, 9, 400, 'John', 'Smoker', 'Rolls', 'A Blunt', 'foo', 2009]
...
-- In non-unique indexes select output order is undefined,
-- so it's better to additionally sort output to receive same order every time.
function sort_cmp(a, b) return a[1] < b[1] and true or false end
---
...
function sort(t) table.sort(t, sort_cmp) return t end
---
...
space.index['primary']:get{1}
---
- [1, 1, 200, 'Joe', 'Sixpack', 'Drinks', 'Heineken', 'bar', 2001]
...
sort(space.index['i1']:select{2})
---
- - [2, 2, 200, 'Joe', 'Sixpack', 'Drinks', 'Carlsberg', 'bar', 2002]
...
sort(space.index[2]:select({300}))
---
- - [3, 3, 300, 'Joe', 'Sixpack', 'Drinks', 'Corona Extra', 'bar', 2003]
  - [4, 4, 300, 'Joe', 'Sixpack', 'Drinks', 'Stella Artois', 'bar', 2004]
  - [5, 5, 300, 'Joe', 'Sixpack', 'Drinks', 'Miller Genuine Draft', 'bar', 2005]
...
#space.index['i3']:select({'Joe', 'Sixpack'})
---
- 6
...
#space.index['i3']:select('John')
---
- 4
...
#space.index['i4']:select('A Pipe')
---
- 1
...
{sort(space.index['i4']:select{'Miller Genuine Draft', 'Drinks'})}
---
- - - [5, 5, 300, 'Joe', 'Sixpack', 'Drinks', 'Miller Genuine Draft', 'bar', 2005]
...
sort(space.index['i5']:select{2007})
---
- - [7, 7, 400, 'John', 'Smoker', 'Hits', 'A Bong', 'foo', 2007]
...
sort(space.index[6]:select{'Miller Genuine Draft', 'Drinks'})
---
- - [5, 5, 300, 'Joe', 'Sixpack', 'Drinks', 'Miller Genuine Draft', 'bar', 2005]
...
tmp = space:delete{6}
---
...
tmp = space:delete{7}
---
...
tmp = space:delete{8}
---
...
tmp = space:delete{9}
---
...
space:insert{6, 6ULL, 400ULL, 'John', 'Smoker', 'Hits', 'A Pipe', 'foo', 2006}
---
- [6, 6, 400, 'John', 'Smoker', 'Hits', 'A Pipe', 'foo', 2006]
...
space:insert{7, 7ULL, 400ULL, 'John', 'Smoker', 'Hits', 'A Bong', 'foo', 2007}
---
- [7, 7, 400, 'John', 'Smoker', 'Hits', 'A Bong', 'foo', 2007]
...
space:insert{8, 8ULL, 400ULL, 'John', 'Smoker', 'Rolls', 'A Joint', 'foo', 2008}
---
- [8, 8, 400, 'John', 'Smoker', 'Rolls', 'A Joint', 'foo', 2008]
...
space:insert{9, 9ULL, 400ULL, 'John', 'Smoker', 'Rolls', 'A Blunt', 'foo', 2009}
---
- [9, 9, 400, 'John', 'Smoker', 'Rolls', 'A Blunt', 'foo', 2009]
...
sort(space.index['i1']:select{6ULL})
---
- - [6, 6, 400, 'John', 'Smoker', 'Hits', 'A Pipe', 'foo', 2006]
...
sort(space.index['i1']:select{6})
---
- - [6, 6, 400, 'John', 'Smoker', 'Hits', 'A Pipe', 'foo', 2006]
...
sort(space.index['i2']:select(400ULL))
---
- - [6, 6, 400, 'John', 'Smoker', 'Hits', 'A Pipe', 'foo', 2006]
  - [7, 7, 400, 'John', 'Smoker', 'Hits', 'A Bong', 'foo', 2007]
  - [8, 8, 400, 'John', 'Smoker', 'Rolls', 'A Joint', 'foo', 2008]
  - [9, 9, 400, 'John', 'Smoker', 'Rolls', 'A Blunt', 'foo', 2009]
...
sort(space.index['i2']:select(400))
---
- - [6, 6, 400, 'John', 'Smoker', 'Hits', 'A Pipe', 'foo', 2006]
  - [7, 7, 400, 'John', 'Smoker', 'Hits', 'A Bong', 'foo', 2007]
  - [8, 8, 400, 'John', 'Smoker', 'Rolls', 'A Joint', 'foo', 2008]
  - [9, 9, 400, 'John', 'Smoker', 'Rolls', 'A Blunt', 'foo', 2009]
...
sort(space:select{})
---
- - [0, 0, 100, 'Joe', 'Sixpack', 'Drinks', 'Amstel', 'bar', 2000]
  - [1, 1, 200, 'Joe', 'Sixpack', 'Drinks', 'Heineken', 'bar', 2001]
  - [2, 2, 200, 'Joe', 'Sixpack', 'Drinks', 'Carlsberg', 'bar', 2002]
  - [3, 3, 300, 'Joe', 'Sixpack', 'Drinks', 'Corona Extra', 'bar', 2003]
  - [4, 4, 300, 'Joe', 'Sixpack', 'Drinks', 'Stella Artois', 'bar', 2004]
  - [5, 5, 300, 'Joe', 'Sixpack', 'Drinks', 'Miller Genuine Draft', 'bar', 2005]
  - [6, 6, 400, 'John', 'Smoker', 'Hits', 'A Pipe', 'foo', 2006]
  - [7, 7, 400, 'John', 'Smoker', 'Hits', 'A Bong', 'foo', 2007]
  - [8, 8, 400, 'John', 'Smoker', 'Rolls', 'A Joint', 'foo', 2008]
  - [9, 9, 400, 'John', 'Smoker', 'Rolls', 'A Blunt', 'foo', 2009]
...
-- Test incorrect keys - supplied key field type does not match index type
-- https://bugs.launchpad.net/tarantool/+bug/1072624
space:insert{'', 1, 2, '', '', '', '', '', 0}
---
- error: 'Tuple field 1 type does not match one required by operation: expected unsigned'
...
space:insert{'xxxxxxxx', 1, 2, '', '', '', '', '', 0}
---
- error: 'Tuple field 1 type does not match one required by operation: expected unsigned'
...
space:insert{1, '', 2, '', '', '', '', '', 0}
---
- error: 'Tuple field 2 type does not match one required by operation: expected unsigned'
...
space:insert{1, 'xxxxxxxxxxx', 2, '', '', '', '', '', 0}
---
- error: 'Tuple field 2 type does not match one required by operation: expected unsigned'
...
space:drop()
---
...
sort = nil
---
...
sort_cmp = nil
---
...
-- test index bsize
space = box.schema.space.create('test', { engine = engine })
---
...
pk = space:create_index('primary', { type = 'tree', parts = {1, 'unsigned'} })
---
...
index2 = space:create_index('secondary', { type = 'tree', parts = {2, 'string', 3, 'scalar'} })
---
...
pk:bsize() == 0
---
- true
...
index2:bsize() == 0
---
- true
...
space:insert({1, 'a', 3})
---
- [1, 'a', 3]
...
pk:bsize() > 0
---
- true
...
index2:bsize() > 0
---
- true
...
space:insert({2, 'b', 4})
---
- [2, 'b', 4]
...
old_pk_size = pk:bsize()
---
...
old_index2_size = index2:bsize()
---
...
space:insert({2, 'b', 4})
---
- error: Duplicate key exists in unique index 'primary' in space 'test'
...
old_pk_size == pk:bsize()
---
- true
...
old_index2_size == index2:bsize()
---
- true
...
tmp = pk:delete({1})
---
...
pk:bsize() > 0
---
- true
...
index2:bsize() > 0
---
- true
...
tmp = index2:delete({'b', 4})
---
...
pk:bsize() > 0
---
- true
...
index2:bsize() > 0
---
- true
...
space:drop()
---
...
--range queries
space = box.schema.space.create('test', { engine = engine })
---
...
pk = space:create_index('primary', { type = 'tree', parts = {1, 'unsigned', 2, 'unsigned'} })
---
...
str = require('string').rep('A', 500)
---
...
c1 = 100 c2 = 10
---
...
for i = 1,c1 do for j=1,c2 do space:insert{j, i, str} end end
---
...
good = true
---
...
for i = 1,c2 do if #space:select{i} ~= c1 then good = false end end
---
...
good --true
---
- true
...
total_count = 0
---
...
for i = 1,c2 do total_count = total_count + #space:select{i} end
---
...
total_count --c1 * c2
---
- 1000
...
space:drop()
---
...