diff --git a/jOOQ-examples/Benchmarks/DB2/Benchmarking DB2 (absolute).sql b/jOOQ-examples/Benchmarks/DB2/Benchmarking DB2 (absolute).sql new file mode 100644 index 0000000000..2856b1fc87 --- /dev/null +++ b/jOOQ-examples/Benchmarks/DB2/Benchmarking DB2 (absolute).sql @@ -0,0 +1,68 @@ +-- This version displays actual execution times. +-- Beware that according to DB2 licensing, it is not allowed to publish benchmark results +BEGIN + DECLARE CONTINUE HANDLER FOR SQLSTATE '42710' BEGIN END; + EXECUTE IMMEDIATE 'CREATE TABLE print (text VARCHAR(500))'; +END + +BEGIN + DECLARE v_ts TIMESTAMP; + DECLARE v_repeat INTEGER DEFAULT 100; + DECLARE v_i INTEGER; + DECLARE v_j INTEGER; + + -- Repeat the whole benchmark several times to avoid warmup penalty + SET v_i = 1; + + DELETE FROM print; + + REPEAT + SET v_j = 1; + SET v_ts = CURRENT_TIMESTAMP; + + REPEAT + FOR rec AS cur CURSOR FOR + -- Paste statement 1 here + SELECT 1 AS a FROM sysibm.dual + DO + BEGIN END; + END FOR; + + SET v_j = v_j + 1; + UNTIL v_j = v_repeat + END REPEAT; + + INSERT INTO print VALUES ('Run ' || v_i ||', Statement 1 : ' || (CURRENT_TIMESTAMP - v_ts)); + + SET v_j = 1; + SET v_ts = CURRENT_TIMESTAMP; + + REPEAT + FOR rec AS cur CURSOR FOR + -- Paste statement 2 here + WITH t(a) AS ( + SELECT 1 AS a FROM sysibm.dual + UNION ALL + SELECT a + 1 + FROM t + WHERE a < 100 + ) + SELECT a FROM t + DO + BEGIN END; + END FOR; + + SET v_j = v_j + 1; + UNTIL v_j > v_repeat + END REPEAT; + + INSERT INTO print VALUES ('Run ' || v_i ||', Statement 2 : ' || (CURRENT_TIMESTAMP - v_ts)); + + SET v_i = v_i + 1; + UNTIL v_i > 5 + END REPEAT; +END + +SELECT * FROM print; + +DROP TABLE print; diff --git a/jOOQ-examples/Benchmarks/DB2/Benchmarking DB2 (relative).sql b/jOOQ-examples/Benchmarks/DB2/Benchmarking DB2 (relative).sql new file mode 100644 index 0000000000..4ab70493ce --- /dev/null +++ b/jOOQ-examples/Benchmarks/DB2/Benchmarking DB2 (relative).sql @@ -0,0 +1,73 @@ +-- This version displays actual execution times. +-- According to our understanding of DB2 licensing, such benchmark results may be published +-- as they cannot be compared to other databases and do not provide absolute time values +BEGIN + DECLARE CONTINUE HANDLER FOR SQLSTATE '42710' BEGIN END; + EXECUTE IMMEDIATE 'CREATE TABLE print_relative (run INTEGER, stmt INTEGER, elapsed DECIMAL(20, 4))'; +END + +BEGIN + DECLARE v_ts TIMESTAMP; + DECLARE v_repeat INTEGER DEFAULT 100; + DECLARE v_i INTEGER; + DECLARE v_j INTEGER; + + -- Repeat the whole benchmark several times to avoid warmup penalty + SET v_i = 1; + + DELETE FROM print_relative; + + REPEAT + SET v_j = 1; + SET v_ts = CURRENT_TIMESTAMP; + + REPEAT + FOR rec AS cur CURSOR FOR + -- Paste statement 1 here + SELECT 1 AS a FROM sysibm.dual + DO + BEGIN END; + END FOR; + + SET v_j = v_j + 1; + UNTIL v_j = v_repeat + END REPEAT; + + INSERT INTO print_relative VALUES (v_i, 1, (CURRENT_TIMESTAMP - v_ts)); + + SET v_j = 1; + SET v_ts = CURRENT_TIMESTAMP; + + REPEAT + FOR rec AS cur CURSOR FOR + -- Paste statement 2 here + WITH t(a) AS ( + SELECT 1 AS a FROM sysibm.dual + UNION ALL + SELECT a + 1 + FROM t + WHERE a < 100 + ) + SELECT a FROM t + DO + BEGIN END; + END FOR; + + SET v_j = v_j + 1; + UNTIL v_j > v_repeat + END REPEAT; + + INSERT INTO print_relative VALUES (v_i, 2, (CURRENT_TIMESTAMP - v_ts)); + + SET v_i = v_i + 1; + UNTIL v_i > 5 + END REPEAT; +END + +SELECT + run, + stmt, + CAST(elapsed / MIN(elapsed) OVER() AS DECIMAL(20, 4)) ratio +FROM print_relative; + +DROP TABLE print_relative; diff --git a/jOOQ-examples/Benchmarks/DB2/Benchmarking DB2 Example (number of films per actors starting with A).sql b/jOOQ-examples/Benchmarks/DB2/Benchmarking DB2 Example (number of films per actors starting with A).sql new file mode 100644 index 0000000000..6b5fde51bb --- /dev/null +++ b/jOOQ-examples/Benchmarks/DB2/Benchmarking DB2 Example (number of films per actors starting with A).sql @@ -0,0 +1,136 @@ +-- This version displays actual execution times. +-- According to our understanding of DB2 licensing, such benchmark results may be published +-- as they cannot be compared to other databases and do not provide absolute time values +BEGIN + DECLARE CONTINUE HANDLER FOR SQLSTATE '42710' BEGIN END; + EXECUTE IMMEDIATE 'CREATE TABLE print_relative (run INTEGER, stmt INTEGER, elapsed DECIMAL(20, 4))'; +END + +BEGIN + DECLARE v_ts TIMESTAMP; + DECLARE v_repeat INTEGER DEFAULT 2000; + DECLARE v_i INTEGER; + DECLARE v_j INTEGER; + + -- Repeat the whole benchmark several times to avoid warmup penalty + SET v_i = 1; + + DELETE FROM print_relative; + + REPEAT + SET v_j = 1; + SET v_ts = CURRENT_TIMESTAMP; + + REPEAT + FOR rec AS cur CURSOR FOR + SELECT + first_name, last_name, count(*) c + FROM actor + JOIN film_actor ON actor.actor_id = film_actor.actor_id + WHERE last_name LIKE 'A%' + GROUP BY first_name, last_name + ORDER BY count(*) DESC + DO + BEGIN END; + END FOR; + + SET v_j = v_j + 1; + UNTIL v_j = v_repeat + END REPEAT; + + INSERT INTO print_relative VALUES (v_i, 1, (CURRENT_TIMESTAMP - v_ts)); + + SET v_j = 1; + SET v_ts = CURRENT_TIMESTAMP; + + REPEAT + FOR rec AS cur CURSOR FOR + SELECT + first_name, last_name, + count(*) a + FROM ( + SELECT * + FROM actor + WHERE last_name LIKE 'A%' + ) a + JOIN film_actor + ON a.actor_id = film_actor.actor_id + GROUP BY + first_name, last_name + ORDER BY count(*) DESC + DO + BEGIN END; + END FOR; + + SET v_j = v_j + 1; + UNTIL v_j = v_repeat + END REPEAT; + + INSERT INTO print_relative VALUES (v_i, 2, (CURRENT_TIMESTAMP - v_ts)); + + SET v_j = 1; + SET v_ts = CURRENT_TIMESTAMP; + + REPEAT + FOR rec AS cur CURSOR FOR + SELECT * FROM ( + SELECT + first_name, last_name, ( + SELECT count(*) + FROM film_actor fa + WHERE a.actor_id = + fa.actor_id + ) AS c + FROM actor a + WHERE last_name LIKE 'A%' + ) a + WHERE c > 0 + ORDER BY c DESC + DO + BEGIN END; + END FOR; + + SET v_j = v_j + 1; + UNTIL v_j = v_repeat + END REPEAT; + + INSERT INTO print_relative VALUES (v_i, 3, (CURRENT_TIMESTAMP - v_ts)); + + SET v_j = 1; + SET v_ts = CURRENT_TIMESTAMP; + + REPEAT + FOR rec AS cur CURSOR FOR + SELECT + first_name, last_name, c + FROM actor + JOIN ( + SELECT actor_id,count(*) c + FROM film_actor + GROUP BY actor_id + ) fa + ON actor.actor_id = fa.actor_id + WHERE last_name LIKE 'A%' + ORDER BY c DESC + DO + BEGIN END; + END FOR; + + SET v_j = v_j + 1; + UNTIL v_j = v_repeat + END REPEAT; + + INSERT INTO print_relative VALUES (v_i, 4, (CURRENT_TIMESTAMP - v_ts)); + + SET v_i = v_i + 1; + UNTIL v_i = 5 + END REPEAT; +END + +SELECT + run, + stmt, + CAST(elapsed / MIN(elapsed) OVER() AS DECIMAL(20, 4)) ratio +FROM print_relative; + +DROP TABLE print_relative; diff --git a/jOOQ-examples/Benchmarks/MySQL/Benchmarking MySQL (absolute).sql b/jOOQ-examples/Benchmarks/MySQL/Benchmarking MySQL (absolute).sql new file mode 100644 index 0000000000..d3b15beff1 --- /dev/null +++ b/jOOQ-examples/Benchmarks/MySQL/Benchmarking MySQL (absolute).sql @@ -0,0 +1,72 @@ +CREATE TABLE IF NOT EXISTS print (text VARCHAR(500)); + +delimiter // + +CREATE PROCEDURE benchmark () +BEGIN + DECLARE done INT DEFAULT FALSE; + DECLARE v_ts BIGINT; + DECLARE v_repeat INT DEFAULT 10000; + DECLARE r, c INT; + DECLARE a INT; + + DECLARE cur1 CURSOR FOR + SELECT 1 AS a FROM dual; + + DECLARE cur2 CURSOR FOR + SELECT 1 AS a FROM dual UNION SELECT 2 FROM dual UNION SELECT 3 FROM dual; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + SET r = 0; + + REPEAT + SET v_ts = ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000); + SET c = 0; + REPEAT + OPEN cur1; + + read_loop: LOOP + FETCH cur1 INTO a; + IF done THEN + LEAVE read_loop; + END IF; + END LOOP; + + CLOSE cur1; + SET c = c + 1; + UNTIL c >= v_repeat END REPEAT; + + INSERT INTO print VALUES (CONCAT('Run ', r, ', Statement 1 : ', ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000) - v_ts)); + + SET v_ts = ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000); + SET c = 0; + REPEAT + OPEN cur2; + + read_loop: LOOP + FETCH cur2 INTO a; + IF done THEN + LEAVE read_loop; + END IF; + END LOOP; + + CLOSE cur2; + SET c = c + 1; + UNTIL c >= v_repeat END REPEAT; + + INSERT INTO print VALUES (CONCAT('Run ', r, ', Statement 2 : ', ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000) - v_ts)); + + SET r = r + 1; + UNTIL r >= 5 END REPEAT; +END// + +delimiter ; + +CALL benchmark(); + +SELECT * FROM print; + +DROP PROCEDURE benchmark; + +DROP TABLE print; \ No newline at end of file diff --git a/jOOQ-examples/Benchmarks/MySQL/Benchmarking MySQL (relative).sql b/jOOQ-examples/Benchmarks/MySQL/Benchmarking MySQL (relative).sql new file mode 100644 index 0000000000..ae019829be --- /dev/null +++ b/jOOQ-examples/Benchmarks/MySQL/Benchmarking MySQL (relative).sql @@ -0,0 +1,76 @@ +CREATE TABLE IF NOT EXISTS print_relative (run INT, stmt INT, elapsed BIGINT); + +delimiter // + +CREATE PROCEDURE benchmark () +BEGIN + DECLARE done INT DEFAULT FALSE; + DECLARE v_ts BIGINT; + DECLARE v_repeat INT DEFAULT 10000; + DECLARE r, c INT; + DECLARE a INT; + + DECLARE cur1 CURSOR FOR + SELECT 1 AS a FROM dual; + + DECLARE cur2 CURSOR FOR + SELECT 1 AS a FROM dual UNION SELECT 2 FROM dual UNION SELECT 3 FROM dual; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + SET r = 0; + + REPEAT + SET v_ts = ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000); + SET c = 0; + REPEAT + OPEN cur1; + + read_loop: LOOP + FETCH cur1 INTO a; + IF done THEN + LEAVE read_loop; + END IF; + END LOOP; + + CLOSE cur1; + SET c = c + 1; + UNTIL c >= v_repeat END REPEAT; + + INSERT INTO print_relative VALUES (r, 1, ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000) - v_ts); + + SET v_ts = ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000); + SET c = 0; + REPEAT + OPEN cur2; + + read_loop: LOOP + FETCH cur2 INTO a; + IF done THEN + LEAVE read_loop; + END IF; + END LOOP; + + CLOSE cur2; + SET c = c + 1; + UNTIL c >= v_repeat END REPEAT; + + INSERT INTO print_relative VALUES (r, 2, ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000) - v_ts); + + SET r = r + 1; + UNTIL r >= 5 END REPEAT; +END// + +delimiter ; + +CALL benchmark(); + +SELECT + run, + stmt, + CAST(elapsed / MIN(elapsed) OVER() AS DECIMAL(20, 4)) ratio +FROM print_relative; + +DROP PROCEDURE benchmark; + +DROP TABLE print_relative; \ No newline at end of file diff --git a/jOOQ-examples/Benchmarks/Oracle/Benchmarking Oracle (absolute).sql b/jOOQ-examples/Benchmarks/Oracle/Benchmarking Oracle (absolute).sql new file mode 100644 index 0000000000..3c0c833745 --- /dev/null +++ b/jOOQ-examples/Benchmarks/Oracle/Benchmarking Oracle (absolute).sql @@ -0,0 +1,40 @@ +-- This version displays actual execution times. +-- Beware that according to Oracle licensing, it is not allowed to publish benchmark results +SET SERVEROUTPUT ON +DECLARE + v_ts TIMESTAMP WITH TIME ZONE; + v_repeat CONSTANT NUMBER := 10000; +BEGIN + + -- Repeat the whole benchmark several times to avoid warmup penalty + FOR r IN 1..5 LOOP + v_ts := SYSTIMESTAMP; + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + -- Paste statement 1 here + SELECT 1 FROM dual + ) LOOP + NULL; + END LOOP; + END LOOP; + + dbms_output.put_line('Run ' || r ||', Statement 1 : ' || (SYSTIMESTAMP - v_ts)); + v_ts := SYSTIMESTAMP; + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + -- Paste statement 2 here + SELECT 1 + FROM dual + CONNECT BY level < 100 + ) LOOP + NULL; + END LOOP; + END LOOP; + + dbms_output.put_line('Run ' || r ||', Statement 2 : ' || (SYSTIMESTAMP - v_ts)); + dbms_output.put_line(''); + END LOOP; +END; +/ diff --git a/jOOQ-examples/Benchmarks/Oracle/Benchmarking Oracle (relative).sql b/jOOQ-examples/Benchmarks/Oracle/Benchmarking Oracle (relative).sql new file mode 100644 index 0000000000..1318b8745d --- /dev/null +++ b/jOOQ-examples/Benchmarks/Oracle/Benchmarking Oracle (relative).sql @@ -0,0 +1,60 @@ +-- This version displays relative execution times (fastest execution = 1) +-- According to our understanding of Oracle licensing, such benchmark results may be published +-- as they cannot be compared to other databases and do not provide absolute time values +SET SERVEROUTPUT ON +CREATE TABLE results ( + run NUMBER(2), + stmt NUMBER(2), + elapsed NUMBER +); + +DECLARE + v_ts TIMESTAMP WITH TIME ZONE; + v_repeat CONSTANT NUMBER := 2000; +BEGIN + + -- Repeat the whole benchmark several times to avoid warmup penalty + FOR r IN 1..5 LOOP + v_ts := SYSTIMESTAMP; + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + -- Paste statement 1 here + SELECT 1 FROM dual + ) LOOP + NULL; + END LOOP; + END LOOP; + + INSERT INTO results VALUES (r, 1, SYSDATE + ((SYSTIMESTAMP - v_ts) * 86400) - SYSDATE); + v_ts := SYSTIMESTAMP; + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + -- Paste statement 2 here + SELECT 1 + FROM dual + CONNECT BY level < 100 + ) LOOP + NULL; + END LOOP; + END LOOP; + + INSERT INTO results VALUES (r, 2, SYSDATE + ((SYSTIMESTAMP - v_ts) * 86400) - SYSDATE); + END LOOP; + + FOR rec IN ( + SELECT + run, stmt, + CAST(elapsed / MIN(elapsed) OVER() AS NUMBER(10, 5)) ratio + FROM results + ) + LOOP + dbms_output.put_line('Run ' || rec.run || + ', Statement ' || rec.stmt || + ' : ' || rec.ratio); + END LOOP; +END; +/ + +DROP TABLE results; \ No newline at end of file diff --git a/jOOQ-examples/Benchmarks/Oracle/Benchmarking Oracle Example (number of films per actors starting with A).sql b/jOOQ-examples/Benchmarks/Oracle/Benchmarking Oracle Example (number of films per actors starting with A).sql new file mode 100644 index 0000000000..6daa089602 --- /dev/null +++ b/jOOQ-examples/Benchmarks/Oracle/Benchmarking Oracle Example (number of films per actors starting with A).sql @@ -0,0 +1,118 @@ +-- This version displays relative execution times (fastest execution = 1) +-- According to our understanding of Oracle licensing, such benchmark results may be published +-- as they cannot be compared to other databases and do not provide absolute time values +SET SERVEROUTPUT ON +CREATE TABLE results ( + run NUMBER(2), + stmt NUMBER(2), + elapsed NUMBER +); + +DECLARE + v_ts TIMESTAMP WITH TIME ZONE; + v_repeat CONSTANT NUMBER := 2000; +BEGIN + + -- Repeat the whole benchmark several times to avoid warmup penalty + FOR r IN 1..5 LOOP + v_ts := SYSTIMESTAMP; + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + SELECT + first_name, last_name, count(*) c + FROM actor + JOIN film_actor ON actor.actor_id = film_actor.actor_id + WHERE last_name LIKE 'A%' + GROUP BY first_name, last_name + ORDER BY count(*) DESC + ) LOOP + NULL; + END LOOP; + END LOOP; + + INSERT INTO results VALUES (r, 1, SYSDATE + ((SYSTIMESTAMP - v_ts) * 86400) - SYSDATE); + v_ts := SYSTIMESTAMP; + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + SELECT + first_name, last_name, + count(*) a + FROM ( + SELECT * + FROM actor + WHERE last_name LIKE 'A%' + ) a + JOIN film_actor + ON a.actor_id = film_actor.actor_id + GROUP BY + first_name, last_name + ORDER BY count(*) DESC + ) LOOP + NULL; + END LOOP; + END LOOP; + + INSERT INTO results VALUES (r, 2, SYSDATE + ((SYSTIMESTAMP - v_ts) * 86400) - SYSDATE); + v_ts := SYSTIMESTAMP; + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + SELECT * FROM ( + SELECT + first_name, last_name, ( + SELECT count(*) + FROM film_actor fa + WHERE a.actor_id = + fa.actor_id + ) AS c + FROM actor a + WHERE last_name LIKE 'A%' + ) a + WHERE c > 0 + ORDER BY c DESC + ) LOOP + NULL; + END LOOP; + END LOOP; + + INSERT INTO results VALUES (r, 3, SYSDATE + ((SYSTIMESTAMP - v_ts) * 86400) - SYSDATE); + v_ts := SYSTIMESTAMP; + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + SELECT + first_name, last_name, c + FROM actor + JOIN ( + SELECT actor_id,count(*) c + FROM film_actor + GROUP BY actor_id + ) fa + ON actor.actor_id = fa.actor_id + WHERE last_name LIKE 'A%' + ORDER BY c DESC + ) LOOP + NULL; + END LOOP; + END LOOP; + + INSERT INTO results VALUES (r, 4, SYSDATE + ((SYSTIMESTAMP - v_ts) * 86400) - SYSDATE); + END LOOP; + + FOR rec IN ( + SELECT + run, stmt, + CAST(elapsed / MIN(elapsed) OVER() AS NUMBER(10, 5)) ratio + FROM results + ) + LOOP + dbms_output.put_line('Run ' || rec.run || + ', Statement ' || rec.stmt || + ' : ' || rec.ratio); + END LOOP; +END; +/ + +DROP TABLE results; \ No newline at end of file diff --git a/jOOQ-examples/Benchmarks/PostgreSQL/Benchmarking PostgreSQL (absolute).sql b/jOOQ-examples/Benchmarks/PostgreSQL/Benchmarking PostgreSQL (absolute).sql new file mode 100644 index 0000000000..2732eae112 --- /dev/null +++ b/jOOQ-examples/Benchmarks/PostgreSQL/Benchmarking PostgreSQL (absolute).sql @@ -0,0 +1,41 @@ +DO $$ +DECLARE + v_ts TIMESTAMP; + v_repeat CONSTANT INT := 10000; + rec RECORD; +BEGIN + + -- Repeat the whole benchmark several times to avoid warmup penalty + FOR r IN 1..5 LOOP + v_ts := clock_timestamp(); + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + -- Paste statement 1 here + SELECT 1 + ) LOOP + NULL; + END LOOP; + END LOOP; + + RAISE INFO 'Run %, Statement 1: %', r, (clock_timestamp() - v_ts); + v_ts := clock_timestamp(); + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + -- Paste statement 2 here + WITH RECURSIVE t(v) AS ( + SELECT 1 + UNION ALL + SELECT v + 1 FROM t WHERE v < 10 + ) + SELECT * FROM t + ) LOOP + NULL; + END LOOP; + END LOOP; + + RAISE INFO 'Run %, Statement 2: %', r, (clock_timestamp() - v_ts); + RAISE INFO ''; + END LOOP; +END$$; \ No newline at end of file diff --git a/jOOQ-examples/Benchmarks/PostgreSQL/Benchmarking PostgreSQL (relative).sql b/jOOQ-examples/Benchmarks/PostgreSQL/Benchmarking PostgreSQL (relative).sql new file mode 100644 index 0000000000..f8c08f5c92 --- /dev/null +++ b/jOOQ-examples/Benchmarks/PostgreSQL/Benchmarking PostgreSQL (relative).sql @@ -0,0 +1,59 @@ +DO $$ +DECLARE + v_ts TIMESTAMP; + v_repeat CONSTANT INT := 10000; + rec RECORD; + run INT[]; + stmt INT[]; + elapsed DECIMAL[]; + min_elapsed DECIMAL; + i INT := 1; +BEGIN + + -- Repeat the whole benchmark several times to avoid warmup penalty + FOR r IN 1..5 LOOP + v_ts := clock_timestamp(); + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + -- Paste statement 1 here + SELECT 1 + ) LOOP + NULL; + END LOOP; + END LOOP; + + run[i] := r; + stmt[i] := 1; + elapsed[i] := (EXTRACT(EPOCH FROM CAST(clock_timestamp() AS TIMESTAMP)) - EXTRACT(EPOCH FROM v_ts)); + i := i + 1; + v_ts := clock_timestamp(); + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + -- Paste statement 2 here + WITH RECURSIVE t(v) AS ( + SELECT 1 + UNION ALL + SELECT v + 1 FROM t WHERE v < 10 + ) + SELECT * FROM t + ) LOOP + NULL; + END LOOP; + END LOOP; + + run[i] := r; + stmt[i] := 2; + elapsed[i] := (EXTRACT(EPOCH FROM CAST(clock_timestamp() AS TIMESTAMP)) - EXTRACT(EPOCH FROM v_ts)); + i := i + 1; + END LOOP; + + SELECT min(t.elapsed) + INTO min_elapsed + FROM unnest(elapsed) AS t(elapsed); + + FOR i IN 1..array_length(run, 1) LOOP + RAISE INFO 'RUN %, Statement %: %', run[i], stmt[i], CAST(elapsed[i] / min_elapsed AS DECIMAL(10, 5)); + END LOOP; +END$$; \ No newline at end of file diff --git a/jOOQ-examples/Benchmarks/PostgreSQL/Benchmarking PostgreSQL Example (number of films per actors starting with A).sql b/jOOQ-examples/Benchmarks/PostgreSQL/Benchmarking PostgreSQL Example (number of films per actors starting with A).sql new file mode 100644 index 0000000000..d56d66dbca --- /dev/null +++ b/jOOQ-examples/Benchmarks/PostgreSQL/Benchmarking PostgreSQL Example (number of films per actors starting with A).sql @@ -0,0 +1,120 @@ +DO $$ +DECLARE + v_ts TIMESTAMP; + v_repeat CONSTANT INT := 2000; + rec RECORD; + run INT[]; + stmt INT[]; + elapsed DECIMAL[]; + min_elapsed DECIMAL; + i INT := 1; +BEGIN + + -- Repeat the whole benchmark several times to avoid warmup penalty + FOR r IN 1..5 LOOP + v_ts := clock_timestamp(); + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + SELECT + first_name, last_name, count(*) c + FROM actor + JOIN film_actor ON actor.actor_id = film_actor.actor_id + WHERE last_name LIKE 'A%' + GROUP BY first_name, last_name + ORDER BY count(*) DESC + ) LOOP + NULL; + END LOOP; + END LOOP; + + run[i] := r; + stmt[i] := 1; + elapsed[i] := (EXTRACT(EPOCH FROM CAST(clock_timestamp() AS TIMESTAMP)) - EXTRACT(EPOCH FROM v_ts)); + i := i + 1; + v_ts := clock_timestamp(); + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + SELECT + first_name, last_name, + count(*) a + FROM ( + SELECT * + FROM actor + WHERE last_name LIKE 'A%' + ) a + JOIN film_actor + ON a.actor_id = film_actor.actor_id + GROUP BY + first_name, last_name + ORDER BY count(*) DESC + ) LOOP + NULL; + END LOOP; + END LOOP; + + run[i] := r; + stmt[i] := 2; + elapsed[i] := (EXTRACT(EPOCH FROM CAST(clock_timestamp() AS TIMESTAMP)) - EXTRACT(EPOCH FROM v_ts)); + i := i + 1; + v_ts := clock_timestamp(); + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + SELECT * FROM ( + SELECT + first_name, last_name, ( + SELECT count(*) + FROM film_actor fa + WHERE a.actor_id = + fa.actor_id + ) AS c + FROM actor a + WHERE last_name LIKE 'A%' + ) a + WHERE c > 0 + ORDER BY c DESC + ) LOOP + NULL; + END LOOP; + END LOOP; + + run[i] := r; + stmt[i] := 3; + elapsed[i] := (EXTRACT(EPOCH FROM CAST(clock_timestamp() AS TIMESTAMP)) - EXTRACT(EPOCH FROM v_ts)); + i := i + 1; + v_ts := clock_timestamp(); + + FOR i IN 1..v_repeat LOOP + FOR rec IN ( + SELECT + first_name, last_name, c + FROM actor + JOIN ( + SELECT actor_id,count(*) c + FROM film_actor + GROUP BY actor_id + ) fa + ON actor.actor_id = fa.actor_id + WHERE last_name LIKE 'A%' + ORDER BY c DESC + ) LOOP + NULL; + END LOOP; + END LOOP; + + run[i] := r; + stmt[i] := 4; + elapsed[i] := (EXTRACT(EPOCH FROM CAST(clock_timestamp() AS TIMESTAMP)) - EXTRACT(EPOCH FROM v_ts)); + i := i + 1; + END LOOP; + + SELECT min(t.elapsed) + INTO min_elapsed + FROM unnest(elapsed) AS t(elapsed); + + FOR i IN 1..array_length(run, 1) LOOP + RAISE INFO 'RUN %, Statement %: %', run[i], stmt[i], CAST(elapsed[i] / min_elapsed AS DECIMAL(10, 5)); + END LOOP; +END$$; \ No newline at end of file diff --git a/jOOQ-examples/Benchmarks/SQLServer/Benchmarking SQL Server (absolute).sql b/jOOQ-examples/Benchmarks/SQLServer/Benchmarking SQL Server (absolute).sql new file mode 100644 index 0000000000..f4476acabd --- /dev/null +++ b/jOOQ-examples/Benchmarks/SQLServer/Benchmarking SQL Server (absolute).sql @@ -0,0 +1,70 @@ +-- This version displays actual execution times. +-- Beware that according to SQL Server licensing, it is not allowed to publish benchmark results +DECLARE @ts DATETIME; +DECLARE @repeat INT = 10000; +DECLARE @r INT; +DECLARE @i INT; +DECLARE @dummy VARCHAR; + +DECLARE @s1 CURSOR; +DECLARE @s2 CURSOR; + +SET @r = 0; +WHILE @r < 5 +BEGIN + SET @r = @r + 1 + + SET @s1 = CURSOR FOR + -- Paste statement 1 here + SELECT 1 x; + + SET @s2 = CURSOR FOR + -- Paste statement 2 here + WITH t(v) AS ( + SELECT 1 + UNION ALL + SELECT v + 1 FROM t WHERE v < 10 + ) + SELECT * FROM t + + SET @ts = current_timestamp; + SET @i = 0; + WHILE @i < @repeat + BEGIN + SET @i = @i + 1 + + OPEN @s1; + FETCH NEXT FROM @s1 INTO @dummy; + WHILE @@FETCH_STATUS = 0 + BEGIN + FETCH NEXT FROM @s1 INTO @dummy; + END; + + CLOSE @s1; + END; + + DEALLOCATE @s1; + PRINT 'Run ' + @r + ', Statement 1: ' + CAST(DATEDIFF(ms, @ts, current_timestamp) AS VARCHAR) + 'ms'; + + SET @ts = current_timestamp; + SET @i = 0; + WHILE @i < @repeat + BEGIN + SET @i = @i + 1 + + OPEN @s2; + FETCH NEXT FROM @s2 INTO @dummy; + WHILE @@FETCH_STATUS = 0 + BEGIN + FETCH NEXT FROM @s2 INTO @dummy; + END; + + CLOSE @s2; + END; + + DEALLOCATE @s2; + PRINT 'Run ' + @r + ', Statement 2: ' + CAST(DATEDIFF(ms, @ts, current_timestamp) AS VARCHAR) + 'ms'; + PRINT ''; +END; + + diff --git a/jOOQ-examples/Benchmarks/SQLServer/Benchmarking SQL Server (relative).sql b/jOOQ-examples/Benchmarks/SQLServer/Benchmarking SQL Server (relative).sql new file mode 100644 index 0000000000..54c41e11ff --- /dev/null +++ b/jOOQ-examples/Benchmarks/SQLServer/Benchmarking SQL Server (relative).sql @@ -0,0 +1,77 @@ +-- This version displays relative execution times (fastest execution = 1) +-- According to our understanding of SQL Server licensing, such benchmark results may be published +-- as they cannot be compared to other databases and do not provide absolute time values +DECLARE @ts DATETIME; +DECLARE @repeat INT = 2000; +DECLARE @r INT; +DECLARE @i INT; +DECLARE @dummy VARCHAR; + +DECLARE @s1 CURSOR; +DECLARE @s2 CURSOR; + +DECLARE @results TABLE ( + run INT, + stmt INT, + elapsed DECIMAL +); + +SET @r = 0; +WHILE @r < 5 +BEGIN + SET @r = @r + 1 + + SET @s1 = CURSOR FOR + -- Paste statement 1 here + SELECT 1 x; + + SET @s2 = CURSOR FOR + -- Paste statement 2 here + WITH t(v) AS ( + SELECT 1 + UNION ALL + SELECT v + 1 FROM t WHERE v < 10 + ) + SELECT * FROM t + + SET @ts = current_timestamp; + SET @i = 0; + WHILE @i < @repeat + BEGIN + SET @i = @i + 1 + + OPEN @s1; + FETCH NEXT FROM @s1 INTO @dummy; + WHILE @@FETCH_STATUS = 0 + BEGIN + FETCH NEXT FROM @s1 INTO @dummy; + END; + + CLOSE @s1; + END; + + DEALLOCATE @s1; + INSERT INTO @results VALUES (@r, 1, DATEDIFF(ms, @ts, current_timestamp)); + + SET @ts = current_timestamp; + SET @i = 0; + WHILE @i < @repeat + BEGIN + SET @i = @i + 1 + + OPEN @s2; + FETCH NEXT FROM @s2 INTO @dummy; + WHILE @@FETCH_STATUS = 0 + BEGIN + FETCH NEXT FROM @s2 INTO @dummy; + END; + + CLOSE @s2; + END; + + DEALLOCATE @s2; + INSERT INTO @results VALUES (@r, 2, DATEDIFF(ms, @ts, current_timestamp)); +END; + +SELECT 'Run ' + CAST(run AS VARCHAR) + ', Statement ' + CAST(stmt AS VARCHAR) + ': ' + CAST(CAST(elapsed / MIN(elapsed) OVER() AS DECIMAL(10, 5)) AS VARCHAR) +FROM @results; diff --git a/jOOQ-examples/Benchmarks/SQLServer/Benchmarking SQL Server Example (number of films per actors starting with A).sql b/jOOQ-examples/Benchmarks/SQLServer/Benchmarking SQL Server Example (number of films per actors starting with A).sql new file mode 100644 index 0000000000..a715276859 --- /dev/null +++ b/jOOQ-examples/Benchmarks/SQLServer/Benchmarking SQL Server Example (number of films per actors starting with A).sql @@ -0,0 +1,158 @@ +-- This version displays relative execution times (fastest execution = 1) +-- According to our understanding of SQL Server licensing, such benchmark results may be published +-- as they cannot be compared to other databases and do not provide absolute time values +DECLARE @ts DATETIME; +DECLARE @repeat INT = 2000; +DECLARE @r INT; +DECLARE @i INT; +DECLARE @dummy1 VARCHAR; +DECLARE @dummy2 VARCHAR; +DECLARE @dummy3 INT; + +DECLARE @s1 CURSOR; +DECLARE @s2 CURSOR; +DECLARE @s3 CURSOR; +DECLARE @s4 CURSOR; + +DECLARE @results TABLE ( + run INT, + stmt INT, + elapsed DECIMAL +); + +SET @r = 0; +WHILE @r < 5 +BEGIN + SET @r = @r + 1 + + SET @s1 = CURSOR FOR + SELECT + first_name, last_name, count(*) c + FROM actor + JOIN film_actor ON actor.actor_id = film_actor.actor_id + WHERE last_name LIKE 'A%' + GROUP BY first_name, last_name + ORDER BY count(*) DESC + + SET @s2 = CURSOR FOR + SELECT + first_name, last_name, + count(*) a + FROM ( + SELECT * + FROM actor + WHERE last_name LIKE 'A%' + ) a + JOIN film_actor + ON a.actor_id = film_actor.actor_id + GROUP BY + first_name, last_name + ORDER BY count(*) DESC + + SET @s3 = CURSOR FOR + SELECT * FROM ( + SELECT + first_name, last_name, ( + SELECT count(*) + FROM film_actor fa + WHERE a.actor_id = + fa.actor_id + ) AS c + FROM actor a + WHERE last_name LIKE 'A%' + ) a + WHERE c > 0 + ORDER BY c DESC + + SET @s4 = CURSOR FOR + SELECT + first_name, last_name, c + FROM actor + JOIN ( + SELECT actor_id,count(*) c + FROM film_actor + GROUP BY actor_id + ) fa + ON actor.actor_id = fa.actor_id + WHERE last_name LIKE 'A%' + ORDER BY c DESC + + SET @ts = current_timestamp; + SET @i = 0; + WHILE @i < @repeat + BEGIN + SET @i = @i + 1 + + OPEN @s1; + FETCH NEXT FROM @s1 INTO @dummy1, @dummy2, @dummy3; + WHILE @@FETCH_STATUS = 0 + BEGIN + FETCH NEXT FROM @s1 INTO @dummy1, @dummy2, @dummy3; + END; + + CLOSE @s1; + END; + + DEALLOCATE @s1; + INSERT INTO @results VALUES (@r, 1, DATEDIFF(ms, @ts, current_timestamp)); + + SET @ts = current_timestamp; + SET @i = 0; + WHILE @i < @repeat + BEGIN + SET @i = @i + 1 + + OPEN @s2; + FETCH NEXT FROM @s2 INTO @dummy1, @dummy2, @dummy3; + WHILE @@FETCH_STATUS = 0 + BEGIN + FETCH NEXT FROM @s2 INTO @dummy1, @dummy2, @dummy3; + END; + + CLOSE @s2; + END; + + DEALLOCATE @s2; + INSERT INTO @results VALUES (@r, 2, DATEDIFF(ms, @ts, current_timestamp)); + + SET @ts = current_timestamp; + SET @i = 0; + WHILE @i < @repeat + BEGIN + SET @i = @i + 1 + + OPEN @s3; + FETCH NEXT FROM @s3 INTO @dummy1, @dummy2, @dummy3; + WHILE @@FETCH_STATUS = 0 + BEGIN + FETCH NEXT FROM @s3 INTO @dummy1, @dummy2, @dummy3; + END; + + CLOSE @s3; + END; + + DEALLOCATE @s3; + INSERT INTO @results VALUES (@r, 3, DATEDIFF(ms, @ts, current_timestamp)); + + SET @ts = current_timestamp; + SET @i = 0; + WHILE @i < @repeat + BEGIN + SET @i = @i + 1 + + OPEN @s4; + FETCH NEXT FROM @s4 INTO @dummy1, @dummy2, @dummy3; + WHILE @@FETCH_STATUS = 0 + BEGIN + FETCH NEXT FROM @s4 INTO @dummy1, @dummy2, @dummy3; + END; + + CLOSE @s4; + END; + + DEALLOCATE @s4; + INSERT INTO @results VALUES (@r, 4, DATEDIFF(ms, @ts, current_timestamp)); +END; + +SELECT 'Run ' + CAST(run AS VARCHAR) + ', Statement ' + CAST(stmt AS VARCHAR) + ': ' + CAST(CAST(elapsed / MIN(elapsed) OVER() AS DECIMAL(10, 5)) AS VARCHAR) +FROM @results;