-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpostgres_benchmarking.sql
166 lines (141 loc) · 5.43 KB
/
postgres_benchmarking.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
CREATE TABLE dataset_small (
ID INT,
Date DATE,
Category VARCHAR(1),
Value FLOAT
);
CREATE TABLE dataset_medium (
ID INT,
Date DATE,
Category VARCHAR(1),
Value FLOAT
);
CREATE TABLE dataset_large (
ID INT,
Date DATE,
Category VARCHAR(1),
Value FLOAT
);
CREATE TABLE join_dataset (
ID INT,
JoinValue FLOAT
);
COPY dataset_small FROM '/Users/michaelrocchio/git/MSDS_460_Group/Group_Assign3/data/dataset_small.csv' DELIMITER ',' CSV HEADER;
COPY dataset_medium FROM '/Users/michaelrocchio/git/MSDS_460_Group/Group_Assign3/data/dataset_medium.csv' DELIMITER ',' CSV HEADER;
COPY dataset_large FROM '/Users/michaelrocchio/git/MSDS_460_Group/Group_Assign3/data/dataset_large.csv' DELIMITER ',' CSV HEADER;
COPY join_dataset FROM '/Users/michaelrocchio/git/MSDS_460_Group/Group_Assign3/data/join_dataset.csv' DELIMITER ',' CSV HEADER;
CREATE TABLE benchmark_results
(
task_name TEXT,
dataset_size TEXT,
execution_time DOUBLE PRECISION,
language TEXT
);
DO $$
DECLARE
start_time TIMESTAMP;
BEGIN
start_time := clock_timestamp();
INSERT INTO benchmark_results (task_name, dataset_size, execution_time, language)
SELECT 'Sort', 'Small', extract(epoch from (SELECT clock_timestamp() - start_time)), 'PostgreSQL'
FROM dataset_small
ORDER BY "value" DESC;
start_time := clock_timestamp();
INSERT INTO benchmark_results (task_name, dataset_size, execution_time, language)
SELECT 'Filter', 'Small', extract(epoch from (SELECT clock_timestamp() - start_time)), 'PostgreSQL'
FROM dataset_small
WHERE "category" IN ('A', 'B');
start_time := clock_timestamp();
INSERT INTO benchmark_results (task_name, dataset_size, execution_time, language)
SELECT 'Aggregate', 'Small', extract(epoch from (SELECT clock_timestamp() - start_time)), 'PostgreSQL'
FROM (
SELECT "category", AVG("value") AS "AverageValue"
FROM dataset_small
GROUP BY "category"
) AS aggregated_small;
start_time := clock_timestamp();
INSERT INTO benchmark_results (task_name, dataset_size, execution_time, language)
SELECT 'Join', 'Small', extract(epoch from (SELECT clock_timestamp() - start_time)), 'PostgreSQL'
FROM (
SELECT * FROM dataset_small s
JOIN join_dataset j ON s."id" = j."id"
) AS joined_small;
END $$;
DO $$
DECLARE
start_time TIMESTAMP;
BEGIN
start_time := clock_timestamp();
INSERT INTO benchmark_results (task_name, dataset_size, execution_time, language)
SELECT 'Sort', 'Medium', extract(epoch from (SELECT clock_timestamp() - start_time)), 'PostgreSQL'
FROM dataset_medium
ORDER BY "value" DESC;
start_time := clock_timestamp();
INSERT INTO benchmark_results (task_name, dataset_size, execution_time, language)
SELECT 'Filter', 'Medium', extract(epoch from (SELECT clock_timestamp() - start_time)), 'PostgreSQL'
FROM dataset_medium
WHERE "category" IN ('A', 'B');
start_time := clock_timestamp();
INSERT INTO benchmark_results (task_name, dataset_size, execution_time, language)
SELECT 'Aggregate', 'Medium', extract(epoch from (SELECT clock_timestamp() - start_time)), 'PostgreSQL'
FROM (
SELECT "category", AVG("value") AS "AverageValue"
FROM dataset_medium
GROUP BY "category"
) AS aggregated_medium;
start_time := clock_timestamp();
INSERT INTO benchmark_results (task_name, dataset_size, execution_time, language)
SELECT 'Join', 'Medium', extract(epoch from (SELECT clock_timestamp() - start_time)), 'PostgreSQL'
FROM (
SELECT * FROM dataset_medium s
JOIN join_dataset j ON s."id" = j."id"
) AS joined_medium;
END $$;
DO $$
DECLARE
start_time TIMESTAMP;
BEGIN
start_time := clock_timestamp();
INSERT INTO benchmark_results (task_name, dataset_size, execution_time, language)
SELECT 'Sort', 'Large', extract(epoch from (SELECT clock_timestamp() - start_time)), 'PostgreSQL'
FROM dataset_large
ORDER BY "value" DESC;
start_time := clock_timestamp();
INSERT INTO benchmark_results (task_name, dataset_size, execution_time, language)
SELECT 'Filter', 'Large', extract(epoch from (SELECT clock_timestamp() - start_time)), 'PostgreSQL'
FROM dataset_large
WHERE "category" IN ('A', 'B');
start_time := clock_timestamp();
INSERT INTO benchmark_results (task_name, dataset_size, execution_time, language)
SELECT 'Aggregate', 'Large', extract(epoch from (SELECT clock_timestamp() - start_time)), 'PostgreSQL'
FROM (
SELECT "category", AVG("value") AS "AverageValue"
FROM dataset_large
GROUP BY "category"
) AS aggregated_large;
start_time := clock_timestamp();
INSERT INTO benchmark_results (task_name, dataset_size, execution_time, language)
SELECT 'Join', 'Large', extract(epoch from (SELECT clock_timestamp() - start_time)), 'PostgreSQL'
FROM (
SELECT * FROM dataset_large s
JOIN join_dataset j ON s."id" = j."id"
) AS joined_large;
END $$;
CREATE TABLE final_benchmark_results AS
Select task_name,
dataset_size,
execution_time,
language
From (
SELECT DISTINCT
task_name,
dataset_size,
execution_time,
language,
CASE dataset_size
WHEN 'Small' THEN 1
WHEN 'Medium' THEN 2
WHEN 'Large' THEN 3
END AS size_order
FROM benchmark_results
ORDER BY size_order) AS ordered_results;