-
Notifications
You must be signed in to change notification settings - Fork 0
/
talgebra_queries.sql
620 lines (528 loc) · 26.2 KB
/
talgebra_queries.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
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
/*****************************************************************************
*
* This MobilityDB code is provided under The PostgreSQL License.
* Copyright (c) 2016-2023, Université libre de Bruxelles and MobilityDB
* contributors
*
* MobilityDB includes portions of PostGIS version 3 source code released
* under the GNU General Public License (GPLv2 or later).
* Copyright (c) 2001-2023, PostGIS contributors
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without a written
* agreement is hereby granted, provided that the above copyright notice and
* this paragraph and the following two paragraphs appear in all copies.
*
* IN NO EVENT SHALL UNIVERSITE LIBRE DE BRUXELLES BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
* LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
* EVEN IF UNIVERSITE LIBRE DE BRUXELLES HAS BEEN ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* UNIVERSITE LIBRE DE BRUXELLES SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON
* AN "AS IS" BASIS, AND UNIVERSITE LIBRE DE BRUXELLES HAS NO OBLIGATIONS TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
*****************************************************************************/
/**
* @brief Scripts used to benchmark the temporal algebra queries on alternative
* implementations of a temporal data warehouse using an excerpt of the
* TPC-DS benchmark https://www.tpc.org/tpcds/.
*
* @note According to
* https://stackoverflow.com/questions/37873517/how-we-can-make-statement-timeout-work-inside-a-function
* in PostgreSQL is not possible to set a timeout to stop long-running queries
* and continue executing a function. For this reason, the queries that exceed
* the time out have been commented out in the code below.
*
* Execution at SF10 that motivated to comment out the queries that run more than 5 minutes
*
* @code
* tpcds_sf10=# select talgebra_queries(1);
* INFO: Query: Q1_MobDB, Run: 1, Total Duration: 00:00:00.021344, Seconds: 0.021344, Number of Rows: 1093
* INFO: Query: Q1_TDW, Run: 1, Total Duration: 00:00:00.037376, Seconds: 0.037376, Number of Rows: 1094
* INFO: Query: Q1_SCD, Run: 1, Total Duration: 00:00:00.267792, Seconds: 0.267792, Number of Rows: 1094
* INFO: Query: Q2_MobDB, Run: 1, Total Duration: 00:00:00.259737, Seconds: 0.259737, Number of Rows: 50957
* INFO: Query: Q2_TDW, Run: 1, Total Duration: 00:05:57.801112, Seconds: 357.801112, Number of Rows: 50994
* INFO: Query: Q2_SCD, Run: 1, Total Duration: 00:10:12.473022, Seconds: 612.473022, Number of Rows: 50994
* INFO: Query: Q3_MobDB, Run: 1, Total Duration: 00:00:00.055781, Seconds: 0.055781, Number of Rows: 44
* INFO: Query: Q3_TDW, Run: 1, Total Duration: 00:00:00.053256, Seconds: 0.053256, Number of Rows: 44
* INFO: Query: Q3_SCD, Run: 1, Total Duration: 00:00:00.065464, Seconds: 0.065464, Number of Rows: 44
* INFO: Query: Q4_MobDB, Run: 1, Total Duration: 00:00:00.084666, Seconds: 0.084666, Number of Rows: 3225
* INFO: Query: Q4_TDW, Run: 1, Total Duration: 00:00:00.196392, Seconds: 0.196392, Number of Rows: 3256
* INFO: Query: Q4_SCD, Run: 1, Total Duration: 00:00:00.493055, Seconds: 0.493055, Number of Rows: 3256
* INFO: Query: Q5_MobDB, Run: 1, Total Duration: 00:00:05.967152, Seconds: 5.967152, Number of Rows: 1093
* INFO: Query: Q6_MobDB, Run: 1, Total Duration: 00:00:00.558739, Seconds: 0.558739, Number of Rows: 10
* INFO: Query: Q6_TDW, Run: 1, Total Duration: 00:00:01.340693, Seconds: 1.340693, Number of Rows: 10
* INFO: Execution Start: 2023-12-05 08:59:38.12409+01, Execution End: 2023-12-05 09:15:57.829497+01, Total Duration: 00:16:19.705407
* talgebra_queries
* ------------------
* The End
* (1 row)
* tpcds_sf10=# select count(*) from q6_scd;
* ^CCancel request sent
* ERROR: canceling statement due to user request
* Time: 911757.784 ms (15:11.758)
* @endcode
*/
DROP FUNCTION IF EXISTS get_sf;
CREATE OR REPLACE FUNCTION get_sf()
RETURNS integer AS $$
DECLARE
dbname text;
sf_text text;
BEGIN
SELECT current_database() INTO dbname;
SELECT replace(dbname, 'tpcds_sf', '') INTO sf_text;
RETURN sf_text::integer;
END;
$$ LANGUAGE 'plpgsql';
DROP FUNCTION IF EXISTS talgebra_queries;
CREATE OR REPLACE FUNCTION talgebra_queries(times integer,
newtable boolean DEFAULT true, detailed boolean DEFAULT false)
RETURNS text AS $$
DECLARE
QueryId char(10);
QueryText text;
J json;
InitialTime timestamptz; /* Initial time of the overall execution */
FinalTime timestamptz; /* Final time of the overall execution */
StartTime timestamptz;
PlanningTime float;
ExecutionTime float;
Duration interval;
Seconds float;
NumberRows bigint;
RunId int;
current_sf int;
BEGIN
IF newtable THEN
DROP TABLE IF EXISTS talgebra_queries;
CREATE TABLE talgebra_queries (
QueryId char(10),
RunId int,
StartTime timestamptz,
PlanningTime float,
ExecutionTime float,
Duration interval,
Seconds float,
NumberRows bigint,
J json
);
END IF;
-- Get the current scale factor
SELECT get_sf() INTO current_sf;
SELECT clock_timestamp() INTO InitialTime;
FOR RunId IN 1..times
LOOP
SET log_error_verbosity to terse;
/******************************************************************************
* Query 1: Temporal Selection
* Time when an item is assigned to brand B
*****************************************************************************/
-- Q1_MobDB ------------------------------------------
QueryId = 'Q1_MobDB';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q1_MobDB
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
-- Q1_TDW ------------------------------------------
QueryId = 'Q1_TDW';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q1_TDW
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
-- Q1_SCD ------------------------------------------
QueryId = 'Q1_SCD';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q1_SCD
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
/******************************************************************************
* Query 2: Temporal Projection
* Time when an item is assigned to any brand
*****************************************************************************/
-- Q2_MobDB ------------------------------------------
QueryId = 'Q2_MobDB';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q2_MobDB
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
-- Q2_TDW ------------------------------------------
QueryId = 'Q2_TDW';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q2_TDW
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
-- Q2_SCD ------------------------------------------
/*
* Execute the OLAP version only for SFs < 100 since it takes more than 1h at SF 100
* Query: Q2_SCD, Run: 1, Total Duration: 01:07:34.326571, Seconds: 4054.326571, Number of Rows: 101997
*/
IF current_sf < 100 THEN
QueryId = 'Q2_SCD';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q2_SCD
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
END IF;
/******************************************************************************
* Query 3: Temporal Join
* Time when an item is assigned to brand B and its price is greater that 80
*****************************************************************************/
-- Q3_MobDB ------------------------------------------
QueryId = 'Q3_MobDB';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q3_MobDB
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
-- Q3_TDW ------------------------------------------
QueryId = 'Q3_TDW';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q3_TDW
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
-- Q3_SCD ------------------------------------------
QueryId = 'Q3_SCD';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q3_SCD
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
/******************************************************************************
* Query 4: Temporal Union
* Time when an item is assigned to brand B or its price is greater than 80
*****************************************************************************/
-- Q4_MobDB ------------------------------------------
QueryId = 'Q4_MobDB';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q4_MobDB
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
-- Q4_TDW ------------------------------------------
QueryId = 'Q4_TDW';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q4_TDW
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
-- Q4_SCD ------------------------------------------
QueryId = 'Q4_SCD';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q4_SCD
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
/******************************************************************************
* Query 5: Temporal Difference
* Time when an item is assigned to brand B and its price is not greater than
* 80
*****************************************************************************/
-- Q5_MobDB ------------------------------------------
QueryId = 'Q5_MobDB';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q5_MobDB
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
-- Q5_TDW ------------------------------------------
QueryId = 'Q5_TDW';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q5_TDW
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
-- Q5_SCD ------------------------------------------
QueryId = 'Q5_SCD';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q5_SCD
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
/******************************************************************************
* Query 6: Temporal Aggregation
* Time when a category has assigned to it more than 3 items
*****************************************************************************/
-- Q6_MobDB ------------------------------------------
QueryId = 'Q6_MobDB';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q6_MobDB
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
-- Q6_TDW ------------------------------------------
QueryId = 'Q6_TDW';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q6_TDW
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
-- Q6_SCD ------------------------------------------
/*
* Execute the algebra version only for SFs < 10 since it takes more than 3h at SF 10
* Query: Q6_SCD, Run: 1, Total Duration: 03:30:28.625489, Seconds: 12628.625489, Number of Rows: 10
*/
IF current_sf < 10 THEN
QueryId = 'Q6_SCD';
StartTime := clock_timestamp();
EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM Q6_SCD
INTO J;
PlanningTime := (J->0->>'Planning Time')::float;
ExecutionTime := (J->0->>'Execution Time')::float;
Duration := make_interval(secs := (PlanningTime + ExecutionTime) / 1000);
Seconds := EXTRACT(epoch FROM Duration);
NumberRows := (J->0->'Plan'->>'Actual Rows')::bigint;
IF detailed THEN
RAISE INFO 'Algebra Query: %, Run: %, Start Time: %, Planning Time: % milisecs, Execution Time: % secs, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows;
ELSE
RAISE INFO 'Algebra Query: %, Run: %, Total Duration: %, Seconds: %, Number of Rows: %',
trim(QueryId), RunId, Duration, Seconds, NumberRows;
END IF;
INSERT INTO talgebra_queries VALUES
(trim(QueryId), RunId, StartTime, PlanningTime, ExecutionTime, Duration, Seconds, NumberRows, J);
END IF;
-------------------------------------------------------------------------------
END LOOP;
SELECT clock_timestamp() INTO FinalTime;
RAISE INFO 'Execution Start: %, Execution End: %, Total Duration: %',
InitialTime, FinalTime, FinalTime - InitialTime;
-- Reset the timeout of queries to 0
set statement_timeout=0;
RETURN 'The End';
END;
$$ LANGUAGE 'plpgsql';
/*****************************************************************************/