id
int64
1
300
db
stringclasses
4 values
base_sql
stringlengths
53
2.42k
optimized_sql
stringlengths
22
1.11k
base_time
float64
0.07
450k
fast_time
float64
0.03
212k
base_explain_analyze
unknown
optimized_explain_analyze
unknown
difficulty
stringclasses
3 values
101
tpch
WITH ordered_data AS MATERIALIZED (SELECT o.o_orderdate, o.o_totalprice, NULL::varchar AS type FROM orders o) SELECT o_orderdate, o_totalprice, type FROM ordered_data;
SELECT o.o_orderdate, o.o_totalprice, o.type FROM (SELECT o_orderdate, o_totalprice, NULL::varchar AS type FROM orders) AS o;
2,236.715
794.203
{ "Plan Width": 54, "Actual Rows": 4500000, "Plan Rows": 4500380, "Actual Startup Time": 2.9779999999999998, "Node Type": "CTE Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 213289.4, "Actual Total Time": 2044.202, "Startup Cost": 123281.8, "Alias": "ordered_data", "Plans": [ ...
{ "Relation Name": "orders", "Plan Width": 44, "Actual Rows": 4500000, "Plan Rows": 4500380, "Actual Startup Time": 3.01, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 123281.8, "Actual Total Time": 612.704, "Startup Cost": 0, "Alias": "orders" }
easy
102
tpch
SELECT event_key, c1, c2, c3 FROM (SELECT l.l_orderkey AS event_key, l.l_partkey AS c1, l.l_suppkey AS c2, l.l_linenumber AS c3, count(*) AS cnt FROM lineitem l GROUP BY l.l_orderkey, l.l_partkey, l.l_suppkey, l.l_linenumber) AS sub
SELECT l.l_orderkey AS event_key, l.l_partkey AS c1, l.l_suppkey AS c2, l.l_linenumber AS c3 FROM lineitem l GROUP BY l.l_orderkey, l.l_partkey, l.l_suppkey, l.l_linenumber
9,438.366
6,704.125
{ "Plan Width": 16, "Actual Rows": 17996609, "Plan Rows": 1799625, "Actual Startup Time": 79.345, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1373606.21, "Actual Total Time": 8786.468, "Startup Cost": 0.44, "Alias": "sub", "Plans": [ { "Plan ...
{ "Plan Width": 16, "Actual Rows": 17996609, "Plan Rows": 1799625, "Actual Startup Time": 78.772, "Node Type": "Group", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1337613.71, "Actual Total Time": 6037.659, "Startup Cost": 0.44, "Plans": [ { "Relation Name": "lineitem", ...
medium
103
tpch
SELECT l_returnflag, l_shipdate FROM (SELECT l_returnflag, l_shipdate, ROW_NUMBER() OVER (PARTITION BY l_returnflag ORDER BY l_shipdate) AS rn FROM lineitem) t WHERE rn = 1 ORDER BY l_shipdate;
SELECT l_returnflag, MIN(l_shipdate) AS l_shipdate FROM lineitem GROUP BY l_returnflag ORDER BY MIN(l_shipdate);
33,011.062
5,345.479
{ "Plan Width": 6, "Actual Rows": 3, "Plan Rows": 89981, "Actual Startup Time": 32941.088, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 3770588.94, "Actual Total Time": 32941.089, "Startup Cost": 3770363.99, "Plans": [ { "Plan Width": 6, "Actual Ro...
{ "Plan Width": 6, "Actual Rows": 3, "Plan Rows": 3, "Actual Startup Time": 5326.467, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 607321.78, "Actual Total Time": 5326.468, "Startup Cost": 607321.77, "Plans": [ { "Plan Width": 6, "Actual Rows": 3, ...
medium
104
tpch
SELECT d.o_orderdate, COALESCE(a.cnt,0) AS a, COALESCE(b.cnt,0) AS b, COALESCE(c.cnt,0) AS c FROM ( SELECT DISTINCT o_orderdate FROM orders WHERE o_orderdate BETWEEN '1995-01-03'::date AND '1995-01-05'::date ) d LEFT JOIN LATERAL ( SELECT COUNT(*) AS cnt FROM orders t WHERE t.o_orderdat...
SELECT o_orderdate, SUM(CASE WHEN o_orderkey < 100 THEN 1 ELSE 0 END) AS a, SUM(CASE WHEN o_orderkey::text LIKE '22%' THEN 1 ELSE 0 END) AS b, SUM(CASE WHEN o_orderkey::text LIKE '33%' THEN 1 ELSE 0 END) AS c FROM orders WHERE o_orderdate BETWEEN '1995-01-03'::date AND '1995-01-05'::date GROUP BY o...
2,408.355
502.15
{ "Plan Width": 28, "Actual Rows": 3, "Plan Rows": 2141, "Actual Startup Time": 1150.659, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 720695950.92, "Actual Total Time": 2389.669, "Startup Cost": 482647.9, "Plans": [ { "Plan Width": 20, "Act...
{ "Plan Width": 28, "Actual Rows": 3, "Plan Rows": 2141, "Actual Startup Time": 480.823, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 146280.24, "Actual Total Time": 481.945, "Startup Cost": 146099.74, "Plans": [ { "Plan Widt...
hard
105
tpch
SELECT ids.l_orderkey FROM (SELECT DISTINCT l_orderkey FROM lineitem) ids, LATERAL (SELECT COUNT(DISTINCT l_partkey) AS cnt FROM lineitem l2 WHERE l2.l_orderkey = ids.l_orderkey) agg WHERE agg.cnt = 3;
SELECT l.l_orderkey FROM lineitem l GROUP BY l.l_orderkey HAVING COUNT(DISTINCT l.l_partkey) = 3;
19,221.523
8,853.305
{ "Plan Width": 4, "Actual Rows": 642354, "Plan Rows": 388805, "Actual Startup Time": 90.104, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 4084309.78, "Actual Total Time": 19165.841, "Startup Cost": 9.79, "Plans": [ { "Plan Width": 4, "Actua...
{ "Plan Width": 4, "Actual Rows": 642354, "Plan Rows": 1944, "Actual Startup Time": 86.899, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 816774.46, "Actual Total Time": 8804.101, "Startup Cost": 0.44, "Plans": [ { "Relation N...
easy
106
tpch
WITH ranked AS (SELECT l.l_shipdate, l.l_commitdate, FIRST_VALUE(l.ctid) OVER (PARTITION BY l.l_shipdate, l.l_commitdate ORDER BY l.ctid) AS first_ctid, l.ctid FROM orders o JOIN customer c ON o.o_custkey = c.c_custkey JOIN lineitem l ON o.o_orderkey = l.l_orderkey) SELECT COUNT(*) FROM ranked WHERE ctid = first_ctid;
SELECT COUNT(*) FROM (SELECT l.l_shipdate, l.l_commitdate, MIN(l.ctid) AS min_ctid FROM orders o JOIN customer c ON o.o_custkey = c.c_custkey JOIN lineitem l ON o.o_orderkey = l.l_orderkey GROUP BY l.l_shipdate, l.l_commitdate) grouped;
44,585.538
22,305.064
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 44489.96, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 4683001.1, "Actual Total Time": 44489.965, "Startup Cost": 4683001.09, "Plans": [ { "Plan Width...
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 22189.49, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 2392221.45, "Actual Total Time": 22189.495, "Startup Cost": 2392221.44, "Plans": [ { "Plan Widt...
medium
107
tpch
SELECT '<=30' AS buckets FROM lineitem WHERE l_quantity <= 30 GROUP BY buckets UNION ALL SELECT '31-40' AS buckets FROM lineitem WHERE l_quantity > 30 AND l_quantity <= 40 GROUP BY buckets UNION ALL SELECT '41-50' AS buckets FROM lineitem WHERE l_quantity > 40 AND l_quantity <= 50 GROUP BY buckets UNION ALL SELECT '>50...
SELECT DISTINCT CASE WHEN l_quantity <= 30 THEN '<=30' WHEN l_quantity > 30 AND l_quantity <= 40 THEN '31-40' WHEN l_quantity > 40 AND l_quantity <= 50 THEN '41-50' ELSE '>50' END AS buckets FROM lineitem
11,509.436
6,239.799
{ "Plan Width": 32, "Actual Rows": 3, "Plan Rows": 4, "Actual Startup Time": 120.961, "Node Type": "Append", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 2384368.8, "Actual Total Time": 11487.323, "Startup Cost": 0, "Plans": [ { "Plan Width": 32, "Actual Rows": 1, ...
{ "Plan Width": 32, "Actual Rows": 3, "Plan Rows": 50, "Actual Startup Time": 6219.086, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 787317.57, "Actual Total Time": 6219.088, "Startup Cost": 787316.45, "Plans": [ { "Relation ...
medium
108
tpch
SELECT l_comment, (SELECT count(*) FROM unnest(regexp_split_to_array(l_comment, ',')) el WHERE el = '1') as appearances FROM lineitem
select l_comment, ( select count(*) from unnest(string_to_array(l_comment, ',')) el where el = '1' ) as appearances from lineitem
44,043.16
33,788.537
{ "Relation Name": "lineitem", "Plan Width": 35, "Actual Rows": 17996609, "Plan Rows": 17997578, "Actual Startup Time": 126.02, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 3082007.65, "Actual Total Time": 42722.528, "Startup Cost": 0, "Alias": "lineitem", ...
{ "Relation Name": "lineitem", "Plan Width": 35, "Actual Rows": 17996609, "Plan Rows": 17997578, "Actual Startup Time": 128.756, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 3082007.65, "Actual Total Time": 32487.568, "Startup Cost": 0, "Alias": "lineitem", ...
medium
109
tpch
SELECT t.p_type, COALESCE(ns.cnt,0) AS not_submitted, COALESCE(pt.cnt,0) AS partnered, COALESCE(pg.cnt,0) AS pending, COALESCE(su.cnt,0) AS suspended, COALESCE(rj.cnt,0) AS rejected FROM (SELECT DISTINCT p_type FROM part) t LEFT JOIN LATERAL (SELECT COUNT(p_partkey) AS cnt FROM part p WHERE p.p_type = t.p_type AND p.p_...
SELECT p_type, SUM((p_container = 'SM CASE')::int) AS not_submitted, SUM((p_container = 'SM BOX')::int) AS partnered, SUM((p_container = 'MED BOX')::int) AS pending, SUM((p_container = 'LG CASE')::int) AS suspended, SUM((p_container = 'JUMBO PKG')::int) AS rejected FROM part GROUP BY ...
44,626.841
306.057
{ "Plan Width": 61, "Actual Rows": 150, "Plan Rows": 150, "Actual Startup Time": 706.167, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 15986752, "Actual Total Time": 44606.293, "Startup Cost": 126235.25, "Plans": [ { "Plan Width": 53, "Actua...
{ "Plan Width": 61, "Actual Rows": 150, "Plan Rows": 150, "Actual Startup Time": 305.892, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 42290.5, "Actual Total Time": 305.918, "Startup Cost": 42289, "Plans": [ { "Relation Name"...
medium
110
tpch
SELECT * FROM lineitem WHERE l_shipmode LIKE '%RAIL%' OR l_comment ~ 'unusual|express|pending|accounts' ORDER BY l_orderkey, l_shipdate;
SELECT * FROM lineitem WHERE l_shipmode LIKE '%RAIL%' OR l_comment LIKE '%unusual%' OR l_comment LIKE '%express%' OR l_comment LIKE '%pending%' OR l_comment LIKE '%accounts%' ORDER BY l_orderkey, l_shipdate;
50,068.327
13,063.949
{ "Plan Width": 117, "Actual Rows": 5603039, "Plan Rows": 4583411, "Actual Startup Time": 83.199, "Node Type": "Incremental Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1025173.94, "Actual Total Time": 49832.223, "Startup Cost": 2.89, "Plans": [ { "Relation Name": "li...
{ "Plan Width": 117, "Actual Rows": 5603039, "Plan Rows": 4493809, "Actual Startup Time": 86.172, "Node Type": "Incremental Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1155168.89, "Actual Total Time": 12841.83, "Startup Cost": 3.23, "Plans": [ { "Relation Name": "lin...
medium
111
tpch
WITH date_ranges AS ( SELECT l_shipdate, SUM(l_extendedprice) AS daily_total, l_shipdate - INTERVAL '1 day' AS prev_date, l_shipdate + INTERVAL '1 day' AS next_date FROM lineitem GROUP BY l_shipdate ), prev_sales AS ( SELECT dr.l_shipdate, COALESCE(SUM(t.l_extendedprice)...
WITH daily_sales AS ( SELECT l_shipdate, SUM(l_extendedprice) AS daily_total FROM lineitem GROUP BY l_shipdate ) SELECT l_shipdate, daily_total AS CurrentSales, SUM(daily_total) OVER ( ORDER BY l_shipdate RANGE BETWEEN INTERVAL '1 day' PRECEDING AND CURRENT ROW ) AS total_2...
50,606.483
7,336.7
{ "Plan Width": 100, "Actual Rows": 2526, "Plan Rows": 2508, "Actual Startup Time": 50430.568, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 8020614.7, "Actual Total Time": 50433.211, "Startup Cost": 8020556.82, "Plans": [ { "Plan Width": 52, "...
{ "Plan Width": 100, "Actual Rows": 2526, "Plan Rows": 2508, "Actual Startup Time": 7309.075, "Node Type": "WindowAgg", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 607620.22, "Actual Total Time": 7315.429, "Startup Cost": 607538.71, "Plans": [ { "Plan Width": 68, "Act...
hard
112
tpch
SELECT t2.o_custkey, t2.roi FROM ( SELECT o.o_custkey FROM orders o JOIN lineitem l ON o.o_orderkey = l.l_orderkey GROUP BY o.o_custkey ORDER BY COUNT(DISTINCT l.l_partkey) ASC LIMIT 5 ) AS t1 JOIN ( SELECT o.o_custkey, SUM(l.l_extendedprice * (1 - l.l_discount)) / SUM(ps.ps_supplycost)::float AS ...
SELECT sub.o_custkey, sub.roi FROM ( SELECT o.o_custkey FROM orders o JOIN lineitem l ON o.o_orderkey = l.l_orderkey GROUP BY o.o_custkey ORDER BY COUNT(DISTINCT l.l_partkey) ASC LIMIT 5 ) AS top_customers CROSS JOIN LATERAL ( SELECT top_customers.o_custkey, SUM(l.l_extendedprice * (1 - l.l_discou...
64,239.16
22,520.839
{ "Plan Width": 12, "Actual Rows": 5, "Plan Rows": 6463, "Actual Startup Time": 64020.442, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 6802648.85, "Actual Total Time": 64020.453, "Startup Cost": 6802632.69, "Plans": [ { "Plan Width": 12, "Actual R...
{ "Plan Width": 12, "Actual Rows": 5, "Plan Rows": 5, "Actual Startup Time": 22446.473, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 3723816.08, "Actual Total Time": 22446.48, "Startup Cost": 3723816.06, "Plans": [ { "Plan Width": 12, "Actual Rows"...
hard
113
tpch
SELECT SUM(CASE WHEN source = 'lineitem' THEN val ELSE 0 END) AS sum_books_views, SUM(CASE WHEN source = 'partsupp' THEN val ELSE 0 END) AS sum_apps_views, SUM(CASE WHEN source = 'orders' THEN val ELSE 0 END) AS sum_cars_views FROM (SELECT 'lineitem' AS source, l_quantity AS val FROM lineitem UNION ALL SELECT 'partsupp...
WITH aggregated_views AS (SELECT 'lineitem' AS source, SUM(l_quantity) AS total_views FROM lineitem UNION ALL SELECT 'partsupp' AS source, SUM(ps_availqty) AS total_views FROM partsupp UNION ALL SELECT 'orders' AS source, SUM(o_totalprice) AS total_views FROM orders) SELECT MAX(total_views) FILTER (WHERE source = 'line...
9,238.318
5,341.36
{ "Plan Width": 96, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 9221.309, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 1718824.76, "Actual Total Time": 9221.312, "Startup Cost": 1718824.75, "Plans": [ { "Plan Widt...
{ "Plan Width": 96, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 5322.204, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 779192.72, "Actual Total Time": 5322.208, "Startup Cost": 779192.71, "Plans": [ { "Plan Width"...
hard
114
tpch
WITH keys AS (SELECT DISTINCT l_orderkey, l_shipmode FROM lineitem), max_url AS (SELECT l_orderkey, l_shipmode, MAX(l_comment) AS url FROM lineitem GROUP BY l_orderkey, l_shipmode), max_val AS (SELECT l_orderkey, l_shipmode, MAX(l_extendedprice) AS value FROM lineitem GROUP BY l_orderkey, l_shipmode) SELECT k.l_orderke...
SELECT l_orderkey, l_shipmode, MAX(l_comment) AS url, MAX(l_extendedprice) AS value FROM lineitem GROUP BY l_orderkey, l_shipmode ORDER BY l_shipmode;
145,889.937
39,279.478
{ "Plan Width": 79, "Actual Rows": 13676178, "Plan Rows": 3643530027, "Actual Startup Time": 126766.979, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 44348880.38, "Actual Total Time": 145015.74, "Startup Cost": 6658412.24, "Plans": [ { "Plan Width"...
{ "Plan Width": 79, "Actual Rows": 13676178, "Plan Rows": 1799758, "Actual Startup Time": 26389.429, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 4774604.17, "Actual Total Time": 38586.51, "Startup Cost": 4531636.86, "Plans": [ { ...
easy
115
tpch
WITH daily_sales AS ( SELECT o_orderdate, SUM(o_totalprice) AS daily_amount FROM orders GROUP BY o_orderdate ), indexed_daily_sales AS ( SELECT o_orderdate, daily_amount, ROW_NUMBER() OVER (ORDER BY o_orderdate) as row_num FROM daily_sales ), moving_calculat...
WITH daily_sales AS ( SELECT o_orderdate, SUM(o_totalprice) AS daily_amount FROM orders GROUP BY o_orderdate ), moving_avg AS ( SELECT o_orderdate, SUM(daily_amount) OVER (ORDER BY o_orderdate ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS amount, ROUND(AVG(daily_am...
2,463.724
1,690.33
{ "Plan Width": 68, "Actual Rows": 2400, "Plan Rows": 198, "Actual Startup Time": 2443.174, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 200767.08, "Actual Total Time": 2443.29, "Startup Cost": 200766.58, "Plans": [ { "Plan Width": 44, "Actual Rows...
{ "Plan Width": 68, "Actual Rows": 2400, "Plan Rows": 802, "Actual Startup Time": 1664.399, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 146081.25, "Actual Total Time": 1669.626, "Startup Cost": 145960.95, "Alias": "moving_avg", "Plans": [ { "...
hard
116
tpch
select c.c_custkey as id, c.c_name as name, (select n.n_name from nation n where n.n_nationkey = c.c_nationkey) as city, (select r.r_name from region r join nation n2 on r.r_regionkey = n2.n_regionkey where n2.n_nationkey = c.c_nationkey) as state from customer c
select c.c_custkey as id, c.c_name as name, n1.n_name as city, r1.r_name as state from customer c left join lateral (select n.n_name from nation n where n.n_nationkey = c.c_nationkey) n1 on true left join lateral (select r.r_name from region r join nation n2 on r.r_regionkey = n2.n_regionkey where n2.n_nationkey = c.c_...
2,954.431
232.5
{ "Relation Name": "customer", "Plan Width": 231, "Actual Rows": 450000, "Plan Rows": 450000, "Actual Startup Time": 132.016, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1685537.5, "Actual Total Time": 2906.319, "Startup Cost": 0, "Alias": "c", "Plans": [...
{ "Plan Width": 75, "Actual Rows": 450000, "Plan Rows": 450000, "Actual Startup Time": 0.131, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 22823.36, "Actual Total Time": 215.452, "Startup Cost": 4.36, "Plans": [ { "Plan Width": 53, "Actual Row...
medium
117
tpch
WITH exclusions(col2, col3) AS (SELECT 'A' AS col2, 'B' AS col3 UNION ALL SELECT 'B', 'C') SELECT l."l_orderkey", l."l_returnflag", l."l_linestatus" FROM "lineitem" l WHERE NOT EXISTS (SELECT 1 FROM exclusions e WHERE e.col2 = l."l_returnflag" AND e.col3 = l."l_linestatus");
SELECT l.l_orderkey, l.l_returnflag, l.l_linestatus FROM lineitem l WHERE NOT (l.l_returnflag = 'A' AND l.l_linestatus = 'B') AND NOT (l.l_returnflag = 'B' AND l.l_linestatus = 'C');
8,538.283
4,305.405
{ "Plan Width": 8, "Actual Rows": 17996609, "Plan Rows": 17994448, "Actual Startup Time": 224.196, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 796272.48, "Actual Total Time": 7886.194, "Startup Cost": 0.06, "Plans": [ { "Relation Name": "lineitem",...
{ "Relation Name": "lineitem", "Plan Width": 8, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 91.952, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 697302.96, "Actual Total Time": 3635.657, "Startup Cost": 0, "Alias": "l" }
medium
118
tpch
SELECT t1.l_orderkey, t1.l_shipmode, CASE WHEN t1.l_shipdate > (SELECT MIN(t2.l_shipdate) FROM lineitem t2 WHERE t2.l_orderkey = t1.l_orderkey AND t2.l_shipmode = t1.l_shipmode) THEN 1 ELSE 0 END AS travelled FROM lineitem t1;
SELECT t1.l_orderkey, t1.l_shipmode, CASE WHEN EXISTS ( SELECT 1 FROM lineitem t2 WHERE t2.l_orderkey = t1.l_orderkey AND t2.l_shipmode = t1.l_shipmode AND t2.l_shipdate < t1.l_shipdate ) THEN 1 ELSE 0 END travelled FROM lineitem t1;
61,304.845
44,621.001
{ "Relation Name": "lineitem", "Plan Width": 19, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 183.054, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 169457118.58, "Actual Total Time": 60282.3, "Startup Cost": 0, "Alias": "t1", "Pla...
{ "Relation Name": "lineitem", "Plan Width": 19, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 152.14, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 89688749.32, "Actual Total Time": 43600.412, "Startup Cost": 0, "Alias": "t1", "Pla...
easy
119
tpch
select t.*, w.mode from orders t left join lateral ( select shipmode as mode from ( select l.l_shipmode as shipmode, count(*) over (partition by l.l_shipmode) as cnt from lineitem l where l.l_orderkey = t.o_orderkey ) s order by cnt desc, shipmode limit 1 ) w on true;
select t.*, m.mode from orders t left join lateral ( select l.l_shipmode as mode from lineitem l where l.l_orderkey = t.o_orderkey group by l.l_shipmode order by count(*) desc, l.l_shipmode limit 1 ) m on true;
39,999.057
30,080.725
{ "Plan Width": 118, "Actual Rows": 4500000, "Plan Rows": 4499579, "Actual Startup Time": 135.853, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 53493117.58, "Actual Total Time": 39723.464, "Startup Cost": 11.84, "Plans": [ { "Relation Name": "orde...
{ "Plan Width": 118, "Actual Rows": 4500000, "Plan Rows": 4499579, "Actual Startup Time": 163.526, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 43116751.13, "Actual Total Time": 29796.949, "Startup Cost": 9.53, "Plans": [ { "Relation Name": "order...
medium
120
tpch
SELECT (SELECT STRING_AGG(l.l_partkey::text, ',' ORDER BY l.l_partkey) FROM lineitem AS l WHERE l.l_orderkey = o.o_orderkey) AS project_numbers FROM orders AS o;
SELECT aggfin.project_numbers FROM orders AS o LEFT JOIN (SELECT l_orderkey, STRING_AGG(l_partkey::text, ',' ORDER BY l_partkey) AS project_numbers FROM lineitem GROUP BY l_orderkey) AS aggfin ON o.o_orderkey = aggfin.l_orderkey;
23,423.378
16,684.054
{ "Relation Name": "orders", "Plan Width": 32, "Actual Rows": 4500000, "Plan Rows": 4499579, "Actual Startup Time": 95.055, "Node Type": "Index Only Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 43087833.57, "Actual Total Time": 23143.471, "Startup Cost": 0.43, "Alias": "o", ...
{ "Plan Width": 32, "Actual Rows": 4500000, "Plan Rows": 4499579, "Actual Startup Time": 97.791, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1044214.81, "Actual Total Time": 16489.246, "Startup Cost": 0.87, "Plans": [ { "Relation Name": "orders", ...
medium
121
tpch
WITH MaxClientTotal AS (SELECT i.*, MAX(CASE WHEN o_custkey = 3 THEN o_totalprice ELSE NULL END) OVER () as max_client_3_total, COUNT(CASE WHEN o_custkey = 3 THEN 1 END) OVER () as count_client_3 FROM orders i) SELECT o_orderkey, o_custkey, o_orderstatus, o_totalprice, o_orderdate, o_orderpriority, o_clerk, o_shipprior...
SELECT * FROM orders WHERE o_totalprice > (SELECT MAX(o_totalprice) FROM orders WHERE o_custkey = 3) OR NOT EXISTS (SELECT 1 FROM orders WHERE o_custkey = 3)
3,567.658
874.302
{ "Plan Width": 107, "Actual Rows": 4500000, "Plan Rows": 1514858, "Actual Startup Time": 1828.831, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 280759.05, "Actual Total Time": 3376.262, "Startup Cost": 0, "Alias": "maxclienttotal", "Plans": [ { ...
{ "Relation Name": "orders", "Plan Width": 107, "Actual Rows": 4500000, "Plan Rows": 2999719, "Actual Startup Time": 5.804, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 134599.44, "Actual Total Time": 676.344, "Startup Cost": 76.71, "Alias": "orders", "Pla...
medium
122
tpch
SELECT month, COUNT(o_custkey) FILTER (WHERE rn = 1) AS count FROM (SELECT TO_CHAR(o_orderdate, 'YYYY-MM') AS month, o_custkey, ROW_NUMBER() OVER (PARTITION BY TO_CHAR(o_orderdate, 'YYYY-MM'), o_custkey ORDER BY o_orderdate) AS rn FROM orders) ranked GROUP BY month;
SELECT TO_CHAR(o_orderdate, 'YYYY-MM') AS month, COUNT(DISTINCT o_custkey) AS count FROM orders GROUP BY month;
14,572.518
7,808.274
{ "Plan Width": 40, "Actual Rows": 80, "Plan Rows": 200, "Actual Startup Time": 10433.53, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 1091751.14, "Actual Total Time": 14530.194, "Startup Cost": 889232.04, "Plans": [ { "Plan ...
{ "Plan Width": 40, "Actual Rows": 80, "Plan Rows": 2406, "Actual Startup Time": 6016.499, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 923020.98, "Actual Total Time": 7774.054, "Startup Cost": 889232.04, "Plans": [ { "Plan W...
medium
123
tpch
WITH cteSupplier1Points AS ( SELECT ps1.ps_suppkey AS team, CASE WHEN ps1.ps_supplycost < ps2.ps_supplycost THEN 3 WHEN ps1.ps_supplycost = ps2.ps_supplycost THEN 1 ELSE 0 END AS points FROM partsupp ps1 JOIN partsupp ps2 ON ps1.ps_...
-- DDL statements like CREATE INDEX should be run separately. WITH Supplier1Agg AS ( SELECT ps1.ps_suppkey, SUM(CASE WHEN ps1.ps_supplycost < ps2.ps_supplycost THEN 3 WHEN ps1.ps_supplycost = ps2.ps_supplycost THEN 1 ELSE 0 END) AS points FROM partsupp ps1 JOIN partsupp ps2 ON ps1.ps_partkey = ps2.ps_partkey AND...
9,801.844
7,412.845
{ "Plan Width": 38, "Actual Rows": 30000, "Plan Rows": 30000, "Actual Startup Time": 9766.644, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1134829.67, "Actual Total Time": 9768.404, "Startup Cost": 1134754.67, "Plans": [ { "Plan Width": 38, "Actua...
{ "Plan Width": 38, "Actual Rows": 30000, "Plan Rows": 4378728, "Actual Startup Time": 7386.2, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1661193.89, "Actual Total Time": 7387.917, "Startup Cost": 1650247.07, "Plans": [ { "Plan Width": 38, "Actua...
hard
124
tpch
SELECT c.c_name, o.o_orderdate, n.n_name AS orgs_name, p.p_name AS courses_name FROM orders o LEFT JOIN customer c ON o.o_custkey = c.c_custkey LEFT JOIN nation n ON c.c_nationkey = n.n_nationkey LEFT JOIN lineitem l ON o.o_orderkey = l.l_orderkey LEFT JOIN part p ON l.l_partkey = p.p_partkey WHERE c.c_nationkey = 1 AN...
SELECT c.c_name, o.o_orderdate, n.n_name AS orgs_name, p.p_name AS courses_name FROM orders o JOIN customer c ON o.o_custkey = c.c_custkey AND c.c_nationkey = 1 JOIN nation n ON c.c_nationkey = n.n_nationkey JOIN lineitem l ON o.o_orderkey = l.l_orderkey JOIN part p ON l.l_partkey = p.p_partkey WHERE o.o_orderdate BETW...
1,907.281
1,283.003
{ "Plan Width": 82, "Actual Rows": 108513, "Plan Rows": 110736, "Actual Startup Time": 1598.864, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 301476.56, "Actual Total Time": 1884.038, "Startup Cost": 269383.52, "Plans": [ { "Relation Name": "part", ...
{ "Plan Width": 82, "Actual Rows": 108513, "Plan Rows": 110736, "Actual Startup Time": 977.494, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 301372.7, "Actual Total Time": 1259.652, "Startup Cost": 269279.66, "Plans": [ { "Relation Name": "part", ...
medium
125
tpch
WITH ranked_dates AS ( SELECT o.o_orderdate, ROW_NUMBER() OVER (ORDER BY o.o_orderdate DESC) as rn FROM orders o JOIN customer c ON o.o_custkey = c.c_custkey WHERE c.c_mktsegment = 'AUTOMOBILE' ) SELECT o_orderdate FROM ranked_dates WHERE rn = 1
SELECT o.o_orderdate FROM orders o JOIN customer c ON o.o_custkey = c.c_custkey WHERE c.c_mktsegment = 'AUTOMOBILE' ORDER BY o.o_orderdate DESC LIMIT 1
2,400.114
1,890.108
{ "Plan Width": 4, "Actual Rows": 1, "Plan Rows": 4451, "Actual Startup Time": 1983.66, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 315283.17, "Actual Total Time": 2378.454, "Startup Cost": 288577.92, "Alias": "ranked_dates", "Plans": [ { "Pl...
{ "Plan Width": 4, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 1871.879, "Node Type": "Limit", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 192889.91, "Actual Total Time": 1871.882, "Startup Cost": 192889.91, "Plans": [ { "Plan Width": 4, "Actual Rows": 1,...
medium
126
tpch
WITH min_times AS ( SELECT MAX(CASE WHEN o_orderstatus = 'F' THEN min_time END) AS c_min_time, MAX(CASE WHEN o_orderstatus = 'O' THEN min_time END) AS a_min_time FROM ( SELECT MIN(o_orderdate) OVER (PARTITION BY o_orderstatus) AS min_time, o_orderstatus FROM orders ) AS sub_all ) SELECT o.o_orde...
WITH time_diff AS ( SELECT (MIN(o_orderdate) FILTER (WHERE o_orderstatus = 'F') - MIN(o_orderdate) FILTER (WHERE o_orderstatus = 'O')) AS time_taken FROM orders WHERE EXISTS (SELECT 1 FROM orders WHERE o_orderstatus = 'F') AND EXISTS (SELECT 1 FROM orders WHERE o_orderstatus = 'O') ) ...
5,406.366
2,392.327
{ "Plan Width": 8, "Actual Rows": 4500000, "Plan Rows": 4499579, "Actual Startup Time": 4409.287, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1085379.92, "Actual Total Time": 5215.474, "Startup Cost": 912281.48, "Plans": [ { "Plan Width": 8, ...
{ "Plan Width": 8, "Actual Rows": 4500000, "Plan Rows": 4499579, "Actual Startup Time": 1432.902, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 330119.63, "Actual Total Time": 2211.724, "Startup Cost": 168270.14, "Plans": [ { "Plan Width": 4, ...
medium
127
tpch
SELECT id, event, parameter FROM (SELECT l.l_orderkey AS id, l.l_shipmode AS event, l.l_comment AS parameter, row_number() OVER () AS rn FROM lineitem l) t ORDER BY rn;
SELECT sub.id, sub.event, sub.parameter FROM (SELECT l.l_orderkey AS id, l.l_shipmode AS event, l.l_comment AS parameter FROM lineitem l) AS sub;
23,768.745
3,542.955
{ "Plan Width": 50, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 19879.365, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 4981224.4, "Actual Total Time": 22144.374, "Startup Cost": 4936233.78, "Plans": [ { "Plan Width": 50, ...
{ "Relation Name": "lineitem", "Plan Width": 42, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 74.742, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 517340.48, "Actual Total Time": 2902.868, "Startup Cost": 0, "Alias": "l" }
easy
128
tpch
SELECT c.c_name AS lastname, c.c_acctbal AS salary, CASE WHEN EXISTS(SELECT 1 FROM nation n WHERE n.n_nationkey = c.c_nationkey) THEN (SELECT n.n_name FROM nation n WHERE n.n_nationkey = c.c_nationkey) ELSE NULL END AS depname FROM customer c
SELECT c.c_name AS lastname, c.c_acctbal AS salary, n.n_name AS depname FROM customer c LEFT JOIN LATERAL (SELECT n_name FROM nation WHERE n_nationkey = c.c_nationkey) n ON true
1,010.897
161.687
{ "Relation Name": "customer", "Plan Width": 57, "Actual Rows": 450000, "Plan Rows": 450000, "Actual Startup Time": 140.348, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1196500, "Actual Total Time": 965.088, "Startup Cost": 0, "Alias": "c", "Plans": [ ...
{ "Plan Width": 51, "Actual Rows": 450000, "Plan Rows": 450000, "Actual Startup Time": 0.073, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 16633.06, "Actual Total Time": 145.553, "Startup Cost": 1.56, "Plans": [ { "Relation Name": "customer", ...
easy
129
tpch
SELECT l.l_returnflag, COUNT(*) AS "Count" FROM lineitem l, LATERAL (SELECT 1 FROM orders o WHERE o.o_orderkey = l.l_orderkey AND o.o_orderstatus = 'F' LIMIT 1) s GROUP BY l.l_returnflag;
WITH ActiveOrderLineitems AS ( SELECT l.l_returnflag FROM lineitem l INNER JOIN orders o ON l.l_orderkey = o.o_orderkey WHERE o.o_orderstatus = 'F' ) SELECT l_returnflag, COUNT(*) AS "Count" FROM ActiveOrderLineitems GROUP BY l_returnflag;
37,547.828
10,321.771
{ "Plan Width": 10, "Actual Rows": 3, "Plan Rows": 3, "Actual Startup Time": 37526.665, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 153080532.93, "Actual Total Time": 37526.668, "Startup Cost": 153080532.9, "Plans": [ { "Pla...
{ "Plan Width": 10, "Actual Rows": 3, "Plan Rows": 3, "Actual Startup Time": 10300.419, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 928787.09, "Actual Total Time": 10300.424, "Startup Cost": 928787.06, "Plans": [ { "Plan Wid...
medium
130
tpch
SELECT COUNT(*) FROM ( SELECT l.l_shipdate FROM lineitem l WHERE l.l_returnflag IN ('N', 'Y') GROUP BY l.l_shipdate HAVING MIN(l.l_returnflag) <> MAX(l.l_returnflag) ) t;
SELECT COUNT(*) FROM ( SELECT DISTINCT l1.l_shipdate FROM lineitem l1 WHERE l1.l_returnflag = 'N' AND EXISTS ( SELECT 1 FROM lineitem l2 WHERE l2.l_shipdate = l1.l_shipdate AND l2.l_returnflag = 'Y' ) ) t;
7,689.355
2,053.191
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 7669.157, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 630172.19, "Actual Total Time": 7669.159, "Startup Cost": 630172.18, "Plans": [ { "Plan Width":...
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 2033.773, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 1148688.27, "Actual Total Time": 2033.776, "Startup Cost": 1148688.26, "Plans": [ { "Plan Width...
medium
131
tpch
select ids.id, (select max(l_comment) from lineitem where l_orderkey = ids.id and trim(l_shipinstruct) = 'DELIVER IN PERSON') as are_you_male, (select max(l_comment) from lineitem where l_orderkey = ids.id and trim(l_shipinstruct) = 'TAKE BACK RETURN') as hair_color, (select max(l_comment) from lin...
SELECT l_orderkey AS id, MAX(l_comment) FILTER (WHERE TRIM(l_shipinstruct) = 'DELIVER IN PERSON') AS are_you_male, MAX(l_comment) FILTER (WHERE TRIM(l_shipinstruct) = 'TAKE BACK RETURN') AS hair_color, MAX(l_comment) FILTER (WHERE TRIM(l_shipinstruct) = 'NONE') AS eye_color FROM lineitem GROUP BY l...
63,935.014
26,385.54
{ "Plan Width": 100, "Actual Rows": 4500000, "Plan Rows": 405253, "Actual Startup Time": 365.365, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 12044117.03, "Actual Total Time": 63622.974, "Startup Cost": 0.44, "Alias": "ids", "Plans": [ { "Pla...
{ "Plan Width": 100, "Actual Rows": 4500000, "Plan Rows": 405253, "Actual Startup Time": 174.955, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 1310925.92, "Actual Total Time": 26199.277, "Startup Cost": 0.44, "Plans": [ { "Re...
easy
132
tpch
SELECT count(*) FROM (SELECT 1 FROM lineitem n, LATERAL (SELECT SUBSTR(n.l_quantity::text, 1, 1) AS first_char) s WHERE s.first_char BETWEEN '0' AND '9') AS sub;
SELECT count(*) FROM lineitem WHERE l_quantity >= 0
8,382.371
3,863.269
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 8362.874, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 877529.32, "Actual Total Time": 8362.875, "Startup Cost": 877529.31, "Plans": [ { "Relation Nam...
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 3844.851, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 607340.68, "Actual Total Time": 3844.852, "Startup Cost": 607340.67, "Plans": [ { "Relation Nam...
easy
133
tpch
SELECT l.l_shipdate, COUNT(l.l_partkey) FROM lineitem l WHERE l.l_shipdate >= '1995-03-01' AND l.l_shipdate <= (SELECT MAX(l2.l_shipdate) FROM lineitem l2 WHERE l2.l_shipdate >= '1995-03-01' AND l2.l_shipdate <= '1995-03-31') GROUP BY l.l_shipdate ORDER BY l.l_shipdate;
SELECT l.l_shipdate, COUNT(l.l_partkey) FROM lineitem l WHERE l.l_shipdate BETWEEN '1995-03-01' AND '1995-03-31' GROUP BY l.l_shipdate ORDER BY l.l_shipdate;
6,014.29
2,080.073
{ "Plan Width": 12, "Actual Rows": 31, "Plan Rows": 2515, "Actual Startup Time": 5995.94, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1215898.33, "Actual Total Time": 5995.943, "Startup Cost": 1215892.04, "Plans": [ { "Plan Width": 4, "Actual Rows...
{ "Plan Width": 12, "Actual Rows": 31, "Plan Rows": 2515, "Actual Startup Time": 2060.789, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 608758.18, "Actual Total Time": 2060.792, "Startup Cost": 608751.9, "Plans": [ { "Plan Width": 12, "Actual Rows"...
medium
134
tpch
WITH aggregated_orders AS (SELECT o.o_orderkey, SUM(l.l_quantity * l.l_extendedprice * (1 - l.l_discount)) AS total FROM orders AS o JOIN lineitem AS l ON o.o_orderkey = l.l_orderkey GROUP BY o.o_orderkey), ranked_orders AS (SELECT o_orderkey, total, ROW_NUMBER() OVER (ORDER BY total DESC) AS rn FROM aggregated_orders)...
SELECT o.o_orderkey, SUM(l.l_quantity * l.l_extendedprice * (1 - l.l_discount)) AS total FROM lineitem AS l JOIN orders AS o ON l.l_orderkey = o.o_orderkey GROUP BY o.o_orderkey ORDER BY total DESC LIMIT 10
108,401.519
67,581.417
{ "Plan Width": 36, "Actual Rows": 10, "Plan Rows": 5000274, "Actual Startup Time": 91746.216, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 8139289.03, "Actual Total Time": 108317.347, "Startup Cost": 7689264.37, "Alias": "ranked_orders", "Plans": [ ...
{ "Plan Width": 36, "Actual Rows": 10, "Plan Rows": 10, "Actual Startup Time": 67561.982, "Node Type": "Limit", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 4844893.2, "Actual Total Time": 67561.985, "Startup Cost": 4844893.17, "Plans": [ { "Plan Width": 36, "Actual Ro...
medium
135
tpch
select distinct l1.id, l1.cat from (select l_orderkey as id, l_returnflag as cat, count(*) over (partition by l_orderkey) as cnt from lineitem) l1 where cnt = 1 and l1.cat = 'A';
select l.l_orderkey as id, max(l.l_returnflag) as cat from lineitem l group by l.l_orderkey having count(*) = 1 and max(l.l_returnflag) = 'A';
11,816.395
7,077.008
{ "Plan Width": 6, "Actual Rows": 158099, "Plan Rows": 22361, "Actual Startup Time": 99.661, "Node Type": "Unique", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1261877.01, "Actual Total Time": 11789.618, "Startup Cost": 0.44, "Plans": [ { "Plan Width": 6, "Actual Rows...
{ "Plan Width": 36, "Actual Rows": 158099, "Plan Rows": 10, "Actual Startup Time": 128.48, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 907727.71, "Actual Total Time": 7048.106, "Startup Cost": 0.44, "Plans": [ { "Relation Na...
hard
136
tpch
SELECT o_orderkey FROM orders WHERE o_orderdate > '1995-10-01' INTERSECT SELECT l_orderkey FROM lineitem WHERE l_shipdate < '1996-04-26'
WITH begin_orders AS (SELECT o_orderkey FROM orders WHERE o_orderdate > '1995-10-01'), end_shipments AS (SELECT l_orderkey FROM lineitem WHERE l_shipdate < '1996-04-26') SELECT DISTINCT b.o_orderkey FROM begin_orders b JOIN end_shipments e ON b.o_orderkey = e.l_orderkey
11,922.075
6,363.706
{ "Plan Width": 8, "Actual Rows": 329160, "Plan Rows": 405253, "Actual Startup Time": 9509.606, "Node Type": "SetOp", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 2884429.68, "Actual Total Time": 11845.212, "Startup Cost": 2818387.69, "Plans": [ { "Pl...
{ "Plan Width": 4, "Actual Rows": 329160, "Plan Rows": 1920002, "Actual Startup Time": 105.926, "Node Type": "Unique", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1066550.59, "Actual Total Time": 6324.657, "Startup Cost": 19.61, "Plans": [ { "Plan Width": 4, "Actual R...
easy
137
tpch
SELECT l.l_orderkey AS invoice_num, l.l_linenumber AS invoice_suffix, MAX(c.c_name) AS company_name, MAX(o.o_totalprice) AS invoice_amt FROM lineitem l JOIN orders o ON l.l_orderkey = o.o_orderkey JOIN customer c ON o.o_custkey = c.c_custkey WHERE (SELECT COUNT(*) FROM lineitem l2 WHERE l2.l_orderkey = l.l_orderkey AND...
SELECT l.l_orderkey AS invoice_num, l.l_linenumber AS invoice_suffix, MAX(c.c_name) AS company_name, MAX(o.o_totalprice) AS invoice_amt FROM lineitem l JOIN orders o ON l.l_orderkey = o.o_orderkey JOIN customer c ON o.o_custkey = c.c_custkey GROUP BY l.l_orderkey, l.l_linenumber HAVING COUNT(*) = 1 ORDER BY l.l_orderke...
449,996.261
78,091.902
{ "Plan Width": 72, "Actual Rows": 59986052, "Plan Rows": 285243, "Actual Startup Time": 164.794, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 295944128.36, "Actual Total Time": 446314.435, "Startup Cost": 1.43, "Plans": [ { ...
{ "Plan Width": 72, "Actual Rows": 59986052, "Plan Rows": 14109, "Actual Startup Time": 17637.943, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 6620427.87, "Actual Total Time": 75766.774, "Startup Cost": 3189763.87, "Plans": [ { ...
easy
138
tpch
SELECT l.l_orderkey, l.l_partkey, l.l_shipdate FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY l_orderkey ORDER BY l_shipdate DESC) AS rn FROM lineitem) AS l WHERE l.rn = 1 AND l.l_partkey = 1
SELECT l1.l_orderkey, l1.l_partkey, l1.l_shipdate FROM lineitem l1 WHERE l1.l_partkey = 1 AND NOT EXISTS ( SELECT 1 FROM lineitem l2 WHERE l2.l_orderkey = l1.l_orderkey AND l2.l_shipdate > l1.l_shipdate )
20,537.817
6.037
{ "Plan Width": 12, "Actual Rows": 3, "Plan Rows": 1, "Actual Startup Time": 15535.65, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 3930975.38, "Actual Total Time": 20447.36, "Startup Cost": 3301106.7, "Alias": "l", "Plans": [ { "Plan Width": ...
{ "Plan Width": 12, "Actual Rows": 3, "Plan Rows": 20, "Actual Startup Time": 3.415, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 323.32, "Actual Total Time": 5.979, "Startup Cost": 0.88, "Plans": [ { "Relation Name": "lineitem", "Plan Width...
hard
139
tpch
WITH grouped AS (SELECT l_returnflag, MIN(l_linestatus) AS min_val, MAX(l_linestatus) AS max_val FROM lineitem GROUP BY l_returnflag) SELECT l_returnflag FROM grouped WHERE min_val = max_val AND min_val = 'F';
SELECT l_returnflag FROM lineitem GROUP BY l_returnflag HAVING COUNT(CASE WHEN l_linestatus = 'F' THEN 1 END) = COUNT(*) AND COUNT(*) > 0;
7,436.513
5,707.626
{ "Plan Width": 2, "Actual Rows": 2, "Plan Rows": 1, "Actual Startup Time": 7417.352, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 652312.4, "Actual Total Time": 7417.356, "Startup Cost": 652312.34, "Alias": "grouped", "Plans": [ { "Plan Width...
{ "Plan Width": 2, "Actual Rows": 2, "Plan Rows": 1, "Actual Startup Time": 5688.441, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 742293.62, "Actual Total Time": 5688.443, "Startup Cost": 742293.58, "Plans": [ { "Relation Na...
medium
140
tpch
SELECT t1.year, t1.total_medals_number, t2.medals_usa_and_urs, CASE WHEN t2.medals_usa_and_urs = 0 THEN NULL ELSE t1.total_medals_number::DECIMAL / t2.medals_usa_and_urs END AS ratio FROM ( SELECT EXTRACT(YEAR FROM o.o_orderdate) AS year, COUNT(*) AS total_medals_number FROM orders o JOIN customer c ON o.o_custkey = c....
WITH filtered_data AS ( SELECT EXTRACT(YEAR FROM o.o_orderdate) AS year, n.n_name FROM orders o JOIN customer c ON o.o_custkey = c.c_custkey JOIN nation n ON c.c_nationkey = n.n_nationkey WHERE EXTRACT(YEAR FROM o.o_orderdate) BETWEEN 1992 AND 1995 AND o.o_orderstatus <> 'P' ), aggregated AS ( SELECT year, COUNT(*) AS ...
9,565.516
4,734.26
{ "Plan Width": 56, "Actual Rows": 4, "Plan Rows": 2406, "Actual Startup Time": 5133.706, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 464790160.37, "Actual Total Time": 9535.919, "Startup Cost": 421501.98, "Plans": [ { "Plan Width": 16, "Ac...
{ "Plan Width": 56, "Actual Rows": 4, "Plan Rows": 2406, "Actual Startup Time": 4132.111, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 228775.58, "Actual Total Time": 4692.678, "Startup Cost": 228417.43, "Alias": "aggregated", "Plans": [ { "Pl...
hard
141
tpch
SELECT c.c_custkey FROM customer c LEFT JOIN orders o ON c.c_custkey = o.o_custkey AND o.o_orderstatus = 'F' WHERE c.c_mktsegment = 'BUILDING' AND o.o_custkey IS NULL
SELECT c.c_custkey FROM customer c WHERE c.c_mktsegment = 'BUILDING' AND NOT EXISTS (SELECT 1 FROM orders o WHERE o.o_custkey = c.c_custkey AND o.o_orderstatus = 'F')
5,027.239
512.206
{ "Plan Width": 4, "Actual Rows": 30317, "Plan Rows": 39930, "Actual Startup Time": 10.701, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 116531.95, "Actual Total Time": 4927.725, "Startup Cost": 0.43, "Plans": [ { "Relation Name": "customer", ...
{ "Plan Width": 4, "Actual Rows": 30317, "Plan Rows": 39930, "Actual Startup Time": 7.371, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 116531.95, "Actual Total Time": 489.492, "Startup Cost": 0.43, "Plans": [ { "Relation Name": "customer", ...
easy
142
tpch
SELECT p.p_name FROM part p LEFT JOIN lineitem l ON l.l_partkey = p.p_partkey GROUP BY p.p_partkey, p.p_name HAVING COUNT(l.l_orderkey) FILTER (WHERE l.l_suppkey = 1) = 0;
select p.p_name from part p left join lineitem l on l.l_partkey = p.p_partkey and l.l_suppkey = 1 where l.l_orderkey is null;
69,647.834
201.592
{ "Plan Width": 37, "Actual Rows": 599920, "Plan Rows": 3000, "Actual Startup Time": 111.355, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 2098733.14, "Actual Total Time": 69578.137, "Startup Cost": 0.86, "Plans": [ { "Plan W...
{ "Plan Width": 33, "Actual Rows": 599920, "Plan Rows": 1, "Actual Startup Time": 1.222, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 31757.89, "Actual Total Time": 180.544, "Startup Cost": 2364.91, "Plans": [ { "Relation Name": "part", "Plan...
easy
143
tpch
select l_orderkey, l_partkey from lineitem where l_orderkey in (select l_orderkey from lineitem where l_quantity = 3 group by l_orderkey having count(l_partkey) > 1) and l_quantity = 3;
select s.l_orderkey, s.l_partkey from lineitem s join (select l_orderkey from lineitem where l_quantity = 3 group by l_orderkey having count(l_partkey) > 1) g on s.l_orderkey = g.l_orderkey where s.l_quantity = 3;
4,790.233
2,753.674
{ "Plan Width": 8, "Actual Rows": 27869, "Plan Rows": 74745, "Actual Startup Time": 2975.12, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1103989.7, "Actual Total Time": 4765.594, "Startup Cost": 583235.6, "Plans": [ { "Plan Width": 4, "Actu...
{ "Plan Width": 8, "Actual Rows": 27869, "Plan Rows": 74745, "Actual Startup Time": 2451.004, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1103989.7, "Actual Total Time": 2731.19, "Startup Cost": 583235.6, "Plans": [ { "Plan Width": 4, "Actu...
medium
144
tpch
SELECT SUM(o.o_totalprice * (c.c_mktsegment = 'BUILDING')::int) AS Men, SUM(o.o_totalprice * (c.c_mktsegment = 'MACHINERY')::int) AS Women FROM customer c JOIN orders o ON c.c_custkey = o.o_custkey
SELECT SUM(CASE WHEN c.c_mktsegment = 'BUILDING' THEN o.o_totalprice ELSE 0 END) AS Men, SUM(CASE WHEN c.c_mktsegment = 'MACHINERY' THEN o.o_totalprice ELSE 0 END) AS Women FROM customer c JOIN orders o ON c.c_custkey = o.o_custkey
4,773.231
3,513.015
{ "Plan Width": 64, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 4753.885, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 316825.92, "Actual Total Time": 4753.888, "Startup Cost": 316825.91, "Plans": [ { "Plan Width"...
{ "Plan Width": 64, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 3493.399, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 249320.22, "Actual Total Time": 3493.402, "Startup Cost": 249320.21, "Plans": [ { "Plan Width"...
easy
145
tpch
SELECT SUM(CASE WHEN x.cnt = 1 THEN 1 END) AS occurrences_once, SUM(CASE WHEN x.cnt > 1 THEN 1 END) AS occurrences_greater_than_one FROM (SELECT DISTINCT c_custkey AS id FROM customer) ids JOIN LATERAL (SELECT COUNT(*) AS cnt FROM customer c2 WHERE c2.c_custkey = ids.id) x ON TRUE;
SELECT SUM(CASE WHEN cnt = 1 THEN 1 END) AS occurrences_once, SUM(CASE WHEN cnt > 1 THEN 1 END) AS occurrences_greater_than_one FROM (SELECT c_custkey AS id, COUNT(*) AS cnt FROM customer GROUP BY c_custkey) x
1,091.937
196.929
{ "Plan Width": 16, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 1072.348, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 2034444.43, "Actual Total Time": 1072.35, "Startup Cost": 2034444.42, "Plans": [ { "Plan Width...
{ "Plan Width": 16, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 196.853, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 27444.43, "Actual Total Time": 196.854, "Startup Cost": 27444.42, "Plans": [ { "Plan Width": 12...
hard
146
tpch
SELECT l.*, CASE WHEN l.l_quantity >= 0 THEN l.l_orderkey ELSE lateral_subq.minorderkey END AS purchaseordernotofulfil FROM lineitem l LEFT JOIN LATERAL ( SELECT MIN(l2.l_orderkey) AS minorderkey FROM lineitem l2 WHERE l2.l_orderkey > l.l_orderkey AND l2.l_quantity > 0 ) lateral_subq ON l.l_quantity < 0;
SELECT * , CASE WHEN l.l_quantity >= 0 THEN l.l_orderkey ELSE ( SELECT MIN(l2.l_orderkey) FROM lineitem l2 WHERE l2.l_orderkey > l.l_orderkey AND l2.l_quantity > 0 ) END AS purchaseordernotofulfil FROM ...
301,165.871
17,170.167
{ "Plan Width": 121, "Actual Rows": 59986052, "Plan Rows": 59991708, "Actual Startup Time": 151.287, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 33076883.81, "Actual Total Time": 297787.84, "Startup Cost": 0.49, "Plans": [ { "Relation Name": "lin...
{ "Relation Name": "lineitem", "Plan Width": 121, "Actual Rows": 59986052, "Plan Rows": 59991708, "Actual Startup Time": 108.633, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 31727070.38, "Actual Total Time": 15030.707, "Startup Cost": 0, "Alias": "l", "Pl...
medium
147
tpch
SELECT DISTINCT t_outer.l_orderkey FROM lineitem AS t_outer WHERE t_outer.l_returnflag IN ('R', 'A') AND (SELECT count(*) FROM lineitem AS t_inner WHERE t_inner.l_orderkey = t_outer.l_orderkey AND t_inner.l_returnflag IN ('R', 'A')) = 2;
SELECT l_orderkey FROM lineitem WHERE l_returnflag IN ('R', 'A') GROUP BY l_orderkey HAVING count(*) = 2;
33,388.738
5,352.491
{ "Plan Width": 4, "Actual Rows": 340868, "Plan Rows": 41828, "Actual Startup Time": 108.767, "Node Type": "Unique", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 169674325.82, "Actual Total Time": 33348.89, "Startup Cost": 0.44, "Plans": [ { "Relation Name": "lineitem", ...
{ "Plan Width": 4, "Actual Rows": 340868, "Plan Rows": 2026, "Actual Startup Time": 106.75, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 816105.78, "Actual Total Time": 5316.088, "Startup Cost": 0.44, "Plans": [ { "Relation N...
easy
148
tpch
select l.l_returnflag, l.l_comment, l.l_orderkey, l.l_partkey, l.l_quantity, l.l_suppkey, (select s.s_nationkey from supplier s where s.s_suppkey = l.l_suppkey) as master_location from lineitem l where exists ( select 1 from supplier s where s.s_suppkey = l.l_suppkey )
select l.l_returnflag, l.l_comment, l.l_orderkey, l.l_partkey, l.l_quantity, l.l_suppkey, lt.master_location from lineitem l left join ( select s_suppkey, s_nationkey as master_location from supplier ) lt on l.l_suppkey = lt.s_suppkey
35,786.509
6,786.255
{ "Plan Width": 50, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 173.152, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 150024588.22, "Actual Total Time": 34774.169, "Startup Cost": 1161.29, "Plans": [ { "Relation Name": "li...
{ "Plan Width": 50, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 161.368, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 565927.29, "Actual Total Time": 6135.028, "Startup Cost": 1340, "Plans": [ { "Relation Name": "lineitem"...
easy
149
tpch
SELECT GREATEST(L_SHIPDATE, L_COMMITDATE) AS max_date FROM LINEITEM;
SELECT CASE WHEN L_SHIPDATE >= L_COMMITDATE THEN L_SHIPDATE ELSE L_COMMITDATE END AS max_date FROM LINEITEM;
6,384.472
4,873.447
{ "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 562345.15, "Plan Rows": 17997372, "Plan Width": 4, "Relation Name": "lineitem", "Alias": "lineitem" }
{ "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 562345.15, "Plan Rows": 17997372, "Plan Width": 4, "Relation Name": "lineitem", "Alias": "lineitem" }
medium
150
tpch
WITH aggregated AS ( SELECT MAX(L_RECEIPTDATE) AS max_receiptdate, L_ORDERKEY FROM LINEITEM GROUP BY L_ORDERKEY ), ranked AS ( SELECT max_receiptdate, L_ORDERKEY, ROW_NUMBER() OVER (ORDER BY max_receiptdate DESC, L_ORDERKEY) as rnk FROM aggregated ) SELECT max_receiptdate, ...
SELECT MAX(L_RECEIPTDATE) AS max_receiptdate, L_ORDERKEY FROM LINEITEM GROUP BY L_ORDERKEY ORDER BY MAX(L_RECEIPTDATE) DESC, L_ORDERKEY LIMIT 10
12,498.927
7,883.193
{ "Startup Cost": 865852.82, "Parallel Aware": false, "Node Type": "Subquery Scan", "Total Cost": 879634.35, "Plan Rows": 141349, "Plan Width": 8, "Alias": "ranked", "Plans": [ { "Startup Cost": 865852.82, "Parallel Aware": false, "Node Type": "WindowAgg", "Total Cost": 87433...
{ "Startup Cost": 825340.97, "Parallel Aware": false, "Node Type": "Limit", "Total Cost": 825341, "Plan Rows": 10, "Plan Width": 8, "Plans": [ { "Startup Cost": 825340.97, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 826401.09, "Plan Rows": 424047, "P...
medium
151
tpch
SELECT l.l_orderkey as id, c.category_name as category_indicator, l.l_returnflag as category_data FROM lineitem l LEFT JOIN (VALUES ('A', 'First'), ('N', 'Second'), ('R', 'Third')) AS c(flag, category_name) ON l.l_returnflag = c.flag;
SELECT l_orderkey as id, case when l_returnflag = 'A' then 'First' when l_returnflag = 'N' then 'Second' when l_returnflag = 'R' then 'Third' end as category_indicator, l_returnflag as category_data FROM lineitem as t;
9,249.682
4,472.004
{ "Startup Cost": 0.08, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 610038.27, "Plan Rows": 17997372, "Plan Width": 38, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 517351.72, "Plan Rows": 17997372, ...
{ "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 652332.01, "Plan Rows": 17997372, "Plan Width": 38, "Relation Name": "lineitem", "Alias": "t" }
medium
152
tpch
SELECT l.L_ORDERKEY, l.L_SUPPKEY, l.L_EXTENDEDPRICE, s.S_NAME, l.L_RETURNFLAG, c.C_NAME FROM LINEITEM l LEFT JOIN LATERAL (SELECT S_NAME FROM SUPPLIER WHERE S_SUPPKEY = l.L_SUPPKEY) s ON true LEFT JOIN ORDERS o ON l.L_ORDERKEY = o.O_ORDERKEY LEFT JOIN CUSTOMER c ON o.O_CUSTKEY = c.C_CUSTKEY
SELECT l.L_ORDERKEY, l.L_SUPPKEY, l.L_EXTENDEDPRICE, s.S_NAME, l.L_RETURNFLAG, c.C_NAME FROM LINEITEM l LEFT JOIN SUPPLIER s ON l.L_SUPPKEY = s.S_SUPPKEY LEFT JOIN ORDERS o ON l.L_ORDERKEY = o.O_ORDERKEY LEFT JOIN CUSTOMER c ON o.O_CUSTKEY = c.C_CUSTKEY
39,322.336
29,996.486
{ "Startup Cost": 221977.07, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 1323099.24, "Plan Rows": 17997372, "Plan Width": 63, "Plans": [ { "Startup Cost": 220637.07, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 1274509.48, "Plan Ro...
{ "Startup Cost": 221977.07, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 1323099.24, "Plan Rows": 17997372, "Plan Width": 63, "Plans": [ { "Startup Cost": 220637.07, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 1274509.48, "Plan Ro...
medium
153
tpch
SELECT * FROM orders o1 WHERE o_orderstatus = 'F' AND NOT EXISTS (SELECT 1 FROM orders o2 WHERE o2.o_orderstatus = 'F' AND GREATEST(o2.o_orderdate, o2.o_orderdate) > GREATEST(o1.o_orderdate, o1.o_orderdate)) LIMIT 1;
WITH filtered_orders AS (SELECT * FROM orders WHERE o_orderstatus = 'F') SELECT * FROM filtered_orders ORDER BY GREATEST(o_orderdate, o_orderdate) DESC LIMIT 1;
10,194.465
1,527.423
{ "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Limit", "Total Cost": 51879.09, "Plan Rows": 1, "Plan Width": 107, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Nested Loop", "Total Cost": 75054989268.53, "Plan Rows": 1446729, "P...
{ "Startup Cost": 150812.63, "Parallel Aware": false, "Node Type": "Limit", "Total Cost": 150812.63, "Plan Rows": 1, "Plan Width": 111, "Plans": [ { "Startup Cost": 150812.63, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 156237.86, "Plan Rows": 2170094, ...
medium
154
tpch
SELECT l_orderkey, l_discount, l_extendedprice, cum_length FROM ( SELECT l_orderkey, l_discount, l_extendedprice, SUM(l_extendedprice) OVER (ORDER BY l_discount) AS cum_length FROM lineitem ) AS ordered_table WHERE cum_length <= COALESCE(( SELECT MIN(cum_length) FROM ( SELECT l_orderkey, l_discount, l_...
WITH ordered_table AS ( SELECT l_orderkey, l_discount, l_extendedprice, SUM(l_extendedprice) OVER (ORDER BY l_discount) AS cum_length FROM lineitem ) SELECT l_orderkey, l_discount, l_extendedprice, cum_length FROM ordered_table WHERE cum_length <= COALESCE((SELECT MIN(cum_length) FROM ordered_table WHERE cum_le...
86,207.932
61,489.652
{ "Startup Cost": 1057222.15, "Parallel Aware": false, "Node Type": "Subquery Scan", "Total Cost": 3359389.47, "Plan Rows": 5998869, "Plan Width": 48, "Alias": "ordered_table", "Plans": [ { "Startup Cost": 1057221.58, "Strategy": "Plain", "Parallel Aware": false, "Node Type":...
{ "Startup Cost": 2497131.15, "Parallel Aware": false, "Node Type": "CTE Scan", "Total Cost": 2902054.83, "Plan Rows": 5998869, "Plan Width": 72, "Alias": "ordered_table", "Plans": [ { "Startup Cost": 0.56, "Parallel Aware": false, "Node Type": "WindowAgg", "Total Cost": 2077...
medium
155
tpch
SELECT c.C_NAME AS PatientName, MAX(o.O_ORDERDATE) AS NextVisit, MIN(o.O_ORDERDATE) AS LastVisit FROM CUSTOMER c INNER JOIN ORDERS o ON c.C_CUSTKEY = o.O_CUSTKEY GROUP BY c.C_CUSTKEY, c.C_NAME
WITH customer_orders AS (SELECT o.O_CUSTKEY, MAX(o.O_ORDERDATE) AS max_date, MIN(o.O_ORDERDATE) AS min_date FROM ORDERS o GROUP BY o.O_CUSTKEY) SELECT c.C_NAME AS PatientName, co.max_date AS NextVisit, co.min_date AS LastVisit FROM CUSTOMER c INNER JOIN customer_orders co ON c.C_CUSTKEY = co.O_CUSTKEY
16,018.17
3,723.714
{ "Startup Cost": 21.67, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 521346.67, "Plan Rows": 450000, "Plan Width": 31, "Plans": [ { "Startup Cost": 21.67, "Parallel Aware": false, "Node Type": "Merge Join", "Total Cost": 483091.31, ...
{ "Startup Cost": 411214.09, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 457910.82, "Plan Rows": 274647, "Plan Width": 27, "Plans": [ { "Startup Cost": 387702.09, "Parallel Aware": false, "Node Type": "Subquery Scan", "Total Cost": 428356.86, "Plan Ro...
easy
156
tpch
SELECT P.* FROM ORDERS P LEFT JOIN (SELECT L_ORDERKEY, MAX(L_RECEIPTDATE) AS max_receipt FROM LINEITEM GROUP BY L_ORDERKEY) R ON P.O_ORDERKEY = R.L_ORDERKEY WHERE P.O_ORDERPRIORITY = '1-URGENT' ORDER BY R.max_receipt DESC
SELECT P.* FROM ORDERS P WHERE P.O_ORDERPRIORITY = '1-URGENT' ORDER BY (SELECT MAX(R.L_RECEIPTDATE) FROM LINEITEM R WHERE R.L_ORDERKEY = P.O_ORDERKEY) DESC
10,936.602
6,298.576
{ "Startup Cost": 1190455.67, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 1192671.52, "Plan Rows": 886341, "Plan Width": 111, "Plans": [ { "Startup Cost": 160331.62, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 999891.25, "Plan Rows": 8...
{ "Startup Cost": 8557010.71, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 8559226.57, "Plan Rows": 886341, "Plan Width": 111, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 8366446.29, "Plan Rows": 886341, ...
medium
157
tpch
WITH max_shipdate AS (SELECT MAX(l_shipdate) AS max_date FROM lineitem), date_threshold AS (SELECT max_date - INTERVAL '7 days' AS threshold FROM max_shipdate) SELECT l.* FROM lineitem l CROSS JOIN date_threshold WHERE l.l_shipdate >= date_threshold.threshold;
SELECT * FROM lineitem WHERE l_shipdate >= (SELECT MAX(l_shipdate) FROM lineitem) - INTERVAL '7 days';
8,512.476
6,790.206
{ "Startup Cost": 562345.15, "Parallel Aware": false, "Node Type": "Nested Loop", "Total Cost": 1349657.47, "Plan Rows": 5999124, "Plan Width": 117, "Plans": [ { "Startup Cost": 562345.15, "Strategy": "Plain", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost...
{ "Startup Cost": 562345.16, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 1169683.74, "Plan Rows": 5999124, "Plan Width": 117, "Relation Name": "lineitem", "Alias": "lineitem", "Plans": [ { "Startup Cost": 562345.15, "Strategy": "Plain", "Parallel Aware": false...
medium
158
tpch
SELECT AVG(L_EXTENDEDPRICE) FILTER (WHERE L_SHIPDATE BETWEEN (DATE '1998-12-01' - INTERVAL '14 days') AND DATE '1998-12-01') AS average, (DATE '1998-12-01' - INTERVAL '14 days') AS start_date, DATE '1998-12-01' AS end_date FROM LINEITEM
SELECT AVG(L_EXTENDEDPRICE) AS average, (DATE '1998-12-01' - INTERVAL '14 days') AS start_date, DATE '1998-12-01' AS end_date FROM LINEITEM WHERE L_SHIPDATE BETWEEN (DATE '1998-12-01' - INTERVAL '14 days') AND DATE '1998-12-01'
3,802.444
2,278.999
{ "Startup Cost": 652332.01, "Strategy": "Plain", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 652332.02, "Plan Rows": 1, "Plan Width": 44, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 517351.72, "Pl...
{ "Startup Cost": 607407.76, "Strategy": "Plain", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 607407.77, "Plan Rows": 1, "Plan Width": 44, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 607338.58, "Pl...
medium
159
tpch
SELECT p_partkey as obj_key, MAX(p_size) as updated_on, MAX('A'::char(1)) as status, COALESCE(MAX(CASE WHEN dataset = 1 THEN p_size::text END), (SELECT default_value FROM (VALUES (1, '1990-01-01')) AS types(type_key, default_value) WHERE type_key = 1)) as "DOB", COALESCE(MAX(CASE WHEN datase...
SELECT p_partkey as obj_key, MAX(p_size) as updated_on, MAX('A'::char(1)) as status, COALESCE(MAX(CASE WHEN type_key = 1 THEN p_size::text END), (SELECT default_value FROM (VALUES (1, '1990-01-01')) AS types(type_key, default_value) WHERE type_key = 1)) as "DOB", COALESCE(MAX(CASE WHEN type_...
3,183.281
1,584.28
{ "Startup Cost": 175156.04, "Strategy": "Hashed", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 175158.04, "Plan Rows": 200, "Plan Width": 168, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Result", "Total Cost": 0.01, "Plan ...
{ "Startup Cost": 0.46, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 153884.52, "Plan Rows": 600000, "Plan Width": 168, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Result", "Total Cost": 0.01, "Plan Ro...
hard
160
tpch
SELECT L_ORDERKEY as survey_id, MIN(L_QUANTITY) OVER() as sonda, L_SHIPDATE as data_cria, L_RETURNFLAG as answer FROM LINEITEM;
WITH min_quantity AS (SELECT MIN(L_QUANTITY) as min_qty FROM LINEITEM) SELECT L_ORDERKEY as survey_id, (SELECT min_qty FROM min_quantity) as sonda, L_SHIPDATE as data_cria, L_RETURNFLAG as answer FROM LINEITEM;
11,238.658
7,910.397
{ "Startup Cost": 0, "Parallel Aware": false, "Node Type": "WindowAgg", "Total Cost": 742318.87, "Plan Rows": 17997372, "Plan Width": 42, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 517351.72, "Plan Rows": 17997372, ...
{ "Startup Cost": 562345.17, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 1079696.89, "Plan Rows": 17997372, "Plan Width": 42, "Relation Name": "lineitem", "Alias": "lineitem", "Plans": [ { "Startup Cost": 562345.15, "Strategy": "Plain", "Parallel Aware": false...
medium
161
tpch
WITH ranked_partsupp AS (SELECT PS_PARTKEY, PS_SUPPKEY, PS_SUPPLYCOST, (SELECT COUNT(*) FROM partsupp t2 WHERE t2.PS_PARTKEY = t.PS_PARTKEY AND (t2.PS_SUPPLYCOST < t.PS_SUPPLYCOST OR (t2.PS_SUPPLYCOST = t.PS_SUPPLYCOST AND t2.PS_SUPPKEY <= t.PS_SUPPKEY))) AS rownum FROM partsupp t) SELECT t.*, r.rownum FROM partsupp t ...
SELECT t.*, (SELECT COUNT(*) FROM partsupp t2 WHERE t2.PS_PARTKEY = t.PS_PARTKEY AND (t2.PS_SUPPLYCOST < t.PS_SUPPLYCOST OR (t2.PS_SUPPLYCOST = t.PS_SUPPLYCOST AND t2.PS_SUPPKEY <= t.PS_SUPPKEY))) AS rownum FROM partsupp t
22,020.439
8,525.243
{ "Startup Cost": 130034.51, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 335404.94, "Plan Rows": 1, "Plan Width": 152, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 76322.55, "Plan Rows": 2399655, ...
{ "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 20701540.35, "Plan Rows": 2399655, "Plan Width": 152, "Relation Name": "partsupp", "Alias": "t", "Plans": [ { "Startup Cost": 8.59, "Strategy": "Plain", "Parallel Aware": false, "Node Type"...
medium
162
tpch
WITH region_filter AS ( SELECT r_regionkey FROM region WHERE r_name = 'EUROPE' ), nation_filter AS ( SELECT n_nationkey, n_name FROM nation WHERE n_regionkey IN (SELECT r_regionkey FROM region_filter) ), customer_filter AS ( SELECT c_custkey, n_name FROM customer JOIN nation_filter ON c_nationkey = n_nation...
SELECT n.n_name as country, p.p_type as item_cat, COUNT(*) as cat_sales, COUNT(*) OVER () as total_sales, COUNT(*)::decimal / COUNT(*) OVER () as share FROM nation n JOIN customer c ON c.c_nationkey = n.n_nationkey JOIN orders o ON o.o_custkey = c.c_custkey JOIN lineitem l ON l.l_orderkey = o.o_orderk...
36,668.443
27,012.063
{ "Startup Cost": 106190.14, "Parallel Aware": false, "Node Type": "WindowAgg", "Total Cost": 108278.49, "Plan Rows": 25500, "Plan Width": 173, "Plans": [ { "Startup Cost": 106190.14, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 1...
{ "Startup Cost": 106190.02, "Parallel Aware": false, "Node Type": "WindowAgg", "Total Cost": 108278.36, "Plan Rows": 25500, "Plan Width": 173, "Plans": [ { "Startup Cost": 106190.02, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 1...
hard
163
tpch
WITH ranked_orders AS (SELECT o_clerk, o_orderstatus, o_custkey, dense_rank() OVER (PARTITION BY o_clerk, o_orderstatus ORDER BY o_custkey) AS rnk FROM orders) SELECT o_clerk AS campaign_name, MAX(CASE WHEN o_orderstatus = 'F' THEN rnk ELSE 0 END) AS status_F, MAX(CASE WHEN o_orderstatus = 'O' THEN rnk ELSE 0 END) AS s...
SELECT clerk AS campaign_name, MAX(CASE WHEN status = 'F' THEN cust_count ELSE 0 END) AS status_F, MAX(CASE WHEN status = 'O' THEN cust_count ELSE 0 END) AS status_O, MAX(CASE WHEN status = 'P' THEN cust_count ELSE 0 END) AS status_P FROM (SELECT o_clerk AS clerk, o_orderstatus AS status, COUNT(DISTINCT o_custkey) AS c...
28,078.844
19,400.671
{ "Startup Cost": 805256.8, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 1030322.5, "Plan Rows": 3000, "Plan Width": 40, "Plans": [ { "Startup Cost": 805256.8, "Parallel Aware": false, "Node Type": "WindowAgg", "Total Cost": 906522.86...
{ "Startup Cost": 805256.8, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 850603.44, "Plan Rows": 200, "Plan Width": 40, "Plans": [ { "Startup Cost": 805256.8, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggregate", ...
hard
164
tpch
SELECT p.*, COUNT(*) OVER (PARTITION BY p_name) AS name_count FROM part p;
SELECT p.*, c.name_count FROM part p JOIN (SELECT p_name, COUNT(*) AS name_count FROM part GROUP BY p_name) c ON p.p_name = c.p_name;
3,646.58
1,505.373
{ "Startup Cost": 157905.81, "Parallel Aware": false, "Node Type": "WindowAgg", "Total Cost": 168405.81, "Plan Rows": 600000, "Plan Width": 138, "Plans": [ { "Startup Cost": 157905.81, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 159405.81, "Plan Rows": 600...
{ "Startup Cost": 104938, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 153514.01, "Plan Rows": 600000, "Plan Width": 138, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 18289, "Plan Rows": 600000, ...
medium
165
tpch
WITH order_flags AS (SELECT L_ORDERKEY, MAX(CASE WHEN L_SHIPDATE BETWEEN o.O_ORDERDATE AND (o.O_ORDERDATE + INTERVAL '30 days') THEN 1 ELSE 0 END) as has_match FROM LINEITEM l JOIN ORDERS o ON l.L_ORDERKEY = o.O_ORDERKEY WHERE o.O_ORDERDATE BETWEEN '1995-01-01' AND '1995-03-31' GROUP BY L_ORDERKEY) SELECT o.O_ORDERKEY ...
SELECT o.O_ORDERKEY AS ID, o.O_ORDERDATE AS Start, (o.O_ORDERDATE + INTERVAL '30 days') AS End, CASE WHEN EXISTS (SELECT 1 FROM LINEITEM l WHERE l.L_ORDERKEY = o.O_ORDERKEY AND l.L_SHIPDATE BETWEEN o.O_ORDERDATE AND (o.O_ORDERDATE + INTERVAL '30 days')) THEN 1 ELSE 0 END AS FLAG_NEW FROM ORDERS o WHERE o.O_ORDERDATE BE...
9,870.554
1,913.828
{ "Startup Cost": 872834.46, "Parallel Aware": false, "Node Type": "Unique", "Total Cost": 874933.09, "Plan Rows": 167891, "Plan Width": 20, "Plans": [ { "Startup Cost": 872834.46, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 873254.18, "Plan Rows": 167891,...
{ "Startup Cost": 1757092.14, "Parallel Aware": false, "Node Type": "Unique", "Total Cost": 1759190.78, "Plan Rows": 167891, "Plan Width": 20, "Plans": [ { "Startup Cost": 1757092.14, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 1757511.87, "Plan Rows": 167...
medium
166
tpch
SELECT l_orderkey, ARRAY_TO_STRING(agg_comments, ',') AS values_ FROM ( SELECT l_orderkey, ARRAY_AGG(l_comment) AS agg_comments FROM lineitem GROUP BY l_orderkey ) AS pre_agg
WITH filtered_lineitem AS ( SELECT l_orderkey, l_comment FROM lineitem WHERE l_comment IS NOT NULL -- Though null fraction is 0%, optimizer may benefit ) SELECT l_orderkey, STRING_AGG(l_comment, ',') AS values_ FROM filtered_lineitem GROUP BY l_orderkey
12,208.017
8,318.272
{ "Startup Cost": 0.44, "Parallel Aware": false, "Node Type": "Subquery Scan", "Total Cost": 822538.17, "Plan Rows": 424047, "Plan Width": 36, "Alias": "pre_agg", "Plans": [ { "Startup Cost": 0.44, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggregate", ...
{ "Startup Cost": 0.44, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 817237.59, "Plan Rows": 424047, "Plan Width": 36, "Plans": [ { "Startup Cost": 0.44, "Parallel Aware": false, "Node Type": "Index Scan", "Total Cost": 721950.14, ...
medium
167
tpch
SELECT DISTINCT C_CUSTKEY as clientid FROM (SELECT C_CUSTKEY, SUM(CASE WHEN O_ORDERSTATUS IN ('F', 'O') THEN 1 ELSE 2 END) OVER (PARTITION BY C_CUSTKEY) as total_score FROM CUSTOMER JOIN ORDERS ON C_CUSTKEY = O_CUSTKEY) x WHERE total_score = 2;
SELECT C_CUSTKEY as clientid FROM ( SELECT C_CUSTKEY, CASE WHEN O_ORDERSTATUS IN ('F', 'O') THEN 1 ELSE 2 END as score FROM CUSTOMER JOIN ORDERS ON C_CUSTKEY = O_CUSTKEY ) x GROUP BY C_CUSTKEY HAVING SUM(score) = 2;
22,225.368
5,063.663
{ "Startup Cost": 21.67, "Parallel Aware": false, "Node Type": "Unique", "Total Cost": 607416.26, "Plan Rows": 22504, "Plan Width": 4, "Plans": [ { "Startup Cost": 21.67, "Parallel Aware": false, "Node Type": "Subquery Scan", "Total Cost": 607360, "Plan Rows": 22504, ...
{ "Startup Cost": 455514, "Strategy": "Hashed", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 496300.82, "Plan Rows": 2250, "Plan Width": 4, "Plans": [ { "Startup Cost": 19077.42, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 191097.05, ...
hard
168
tpch
SELECT l.* FROM lineitem l CROSS JOIN LATERAL (VALUES (l.l_quantity, -9999, 9999), (l.l_extendedprice, -9999, 9999), (l.l_discount, -9999, 9999), (l.l_tax, -9999, 9999)) AS thresholds(val, min_th, max_th) WHERE val != min_th AND val != max_th GROUP BY l.l_orderkey, l.l_linenumber HAVING COUNT(*) = 4;
SELECT * FROM lineitem WHERE (l_quantity != -9999 AND l_quantity != 9999 AND l_extendedprice != -9999 AND l_extendedprice != 9999 AND l_discount != -9999 AND l_discount != 9999 AND l_tax != -9999 AND l_tax != 9999);
74,882.381
8,824.468
{ "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 697325.44, "Plan Rows": 17997330, "Plan Width": 117, "Relation Name": "lineitem", "Alias": "lineitem" }
{ "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 877299.16, "Plan Rows": 17997330, "Plan Width": 117, "Relation Name": "lineitem", "Alias": "lineitem" }
medium
169
tpch
SELECT l_shipdate, COUNT(CASE WHEN l_returnflag = 'A' THEN 1 END) AS ZAB_HIP FROM lineitem WHERE l_shipdate = '1994-05-16' AND l_linestatus IN ('F', 'O') GROUP BY l_shipdate;
SELECT l_shipdate, SUM(CASE WHEN l_returnflag = 'A' THEN 1 ELSE 0 END) AS ZAB_HIP FROM lineitem WHERE l_shipdate = '1994-05-16' AND (l_linestatus = 'F' OR l_linestatus = 'O') GROUP BY l_shipdate;
2,875.479
2,151.186
{ "Startup Cost": 0, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 652394.07, "Plan Rows": 2207, "Plan Width": 12, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 652332.01, "Plan R...
{ "Startup Cost": 0, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 652394.07, "Plan Rows": 2207, "Plan Width": 12, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 652332.01, "Plan R...
medium
170
tpch
WITH lattu AS ( SELECT CONCAT_WS('_', L_SHIPDATE::text, L_COMMITDATE::text) AS ship_commit FROM LINEITEM GROUP BY CONCAT_WS('_', L_SHIPDATE::text, L_COMMITDATE::text) HAVING COUNT(CONCAT_WS('_', L_SHIPDATE::text, L_COMMITDATE::text)) < 2 ) SELECT ROUND(SUM(L_EXTENDEDPRICE), 2) as tiv_2016 FROM LINEITEM WHERE ...
WITH rare_combinations AS ( SELECT L_SHIPDATE, L_COMMITDATE FROM LINEITEM GROUP BY L_SHIPDATE, L_COMMITDATE HAVING COUNT(*) = 1 ), lineitem_rare AS ( SELECT l.L_EXTENDEDPRICE, l.L_DISCOUNT FROM LINEITEM l JOIN rare_combinations rc ON l.L_SHIPDATE = rc.L_SHIPDATE AND l.L_COMMITDATE = rc.L_COMMITDATE )...
31,252.725
23,660.099
{ "Startup Cost": 408544697.77, "Strategy": "Hashed", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 408544697.95, "Plan Rows": 4, "Plan Width": 36, "Plans": [ { "Startup Cost": 2870859.64, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 366...
{ "Startup Cost": 5381899.88, "Strategy": "Hashed", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 5381900.06, "Plan Rows": 4, "Plan Width": 36, "Plans": [ { "Startup Cost": 4572018.14, "Parallel Aware": false, "Node Type": "Subquery Scan", "Total Cost": 533...
hard
171
tpch
SELECT c.C_CUSTKEY AS PlayerID FROM CUSTOMER c JOIN ORDERS o ON c.C_CUSTKEY = o.O_CUSTKEY GROUP BY c.C_CUSTKEY HAVING COUNT(o.O_ORDERKEY) = ( SELECT MAX(order_count) FROM ( SELECT COUNT(*) as order_count FROM ORDERS GROUP BY O_CUSTKEY ) counts ) LIMIT 1;
SELECT C_CUSTKEY AS PlayerID FROM CUSTOMER c JOIN ORDERS o ON c.C_CUSTKEY = o.O_CUSTKEY GROUP BY C_CUSTKEY ORDER BY COUNT(O_ORDERKEY) DESC LIMIT 1;
15,122.16
4,529.314
{ "Startup Cost": 417791.7, "Parallel Aware": false, "Node Type": "Limit", "Total Cost": 431551.14, "Plan Rows": 1, "Plan Width": 4, "Plans": [ { "Startup Cost": 417791.69, "Strategy": "Plain", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 417791.7, ...
{ "Startup Cost": 486174.04, "Parallel Aware": false, "Node Type": "Limit", "Total Cost": 486174.04, "Plan Rows": 1, "Plan Width": 12, "Plans": [ { "Startup Cost": 486174.04, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 487299.04, "Plan Rows": 450000, ...
medium
172
tpch
WITH ordered_orders AS ( SELECT c.c_name, c.c_mktsegment, o.o_orderkey, ROW_NUMBER() OVER (PARTITION BY c.c_name ORDER BY o.o_orderkey) as rn FROM customer c JOIN orders o ON c.c_custkey = o.o_custkey ), segment_changes AS ( SELECT o1.c_name, CASE WHEN o1.c_mktsegment <> o2.c_mkts...
SELECT c_name, COUNT(changed) + 1 FROM ( SELECT c_name, o_orderkey, c_mktsegment, CASE WHEN c_mktsegment <> LAG(c_mktsegment) OVER (PARTITION BY c_name ORDER BY o_orderkey ASC) THEN 1 END AS changed FROM ( SELECT c_name, c_mktsegment, o_orderkey FROM custo...
56,857.891
34,855.1
{ "Startup Cost": 941670.28, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 1166705.98, "Plan Rows": 4500714, "Plan Width": 27, "Plans": [ { "Startup Cost": 941670.28, "Parallel Aware": false, "Node Type": "WindowAgg", "Total Cost": 104...
{ "Startup Cost": 941670.28, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 1166705.98, "Plan Rows": 4500714, "Plan Width": 27, "Plans": [ { "Startup Cost": 941670.28, "Parallel Aware": false, "Node Type": "WindowAgg", "Total Cost": 104...
hard
173
tpch
WITH min_shipdate AS (SELECT MIN(l_shipdate) AS min_date FROM lineitem) SELECT l.* FROM lineitem l CROSS JOIN min_shipdate WHERE l.l_shipdate = min_shipdate.min_date;
SELECT * FROM lineitem WHERE l_shipdate = (SELECT MIN(l_shipdate) FROM lineitem);
8,068.22
6,115.365
{ "Startup Cost": 1.02, "Parallel Aware": false, "Node Type": "Nested Loop", "Total Cost": 742.6, "Plan Rows": 7184, "Plan Width": 117, "Plans": [ { "Startup Cost": 0.46, "Parallel Aware": false, "Node Type": "Result", "Total Cost": 0.47000000000000003, "Plan Rows": 1, ...
{ "Startup Cost": 1.03, "Parallel Aware": false, "Node Type": "Index Only Scan", "Total Cost": 670.75, "Plan Rows": 7184, "Plan Width": 117, "Relation Name": "lineitem", "Alias": "lineitem", "Plans": [ { "Startup Cost": 0.46, "Parallel Aware": false, "Node Type": "Result", ...
medium
174
tpch
WITH distinct_groups AS ( SELECT DISTINCT l_partkey, l_extendedprice, l_quantity, l_suppkey, l_linestatus FROM lineitem ) SELECT dg.l_partkey AS upc_code, dg.l_extendedprice AS a_price, dg.l_quantity AS a_qty, MAX(l.l_shipdate) AS f_date, dg.l_suppke...
WITH ranked_lineitem AS ( SELECT l_partkey, l_extendedprice, l_quantity, l_suppkey, l_linestatus, MAX(l_shipdate) OVER (PARTITION BY l_partkey, l_extendedprice, l_quantity, l_suppkey, l_linestatus) as max_shipdate FROM lineitem ) SELECT l_partkey AS upc_code...
101,642.613
55,956.834
{ "Startup Cost": 2131491.02, "Strategy": "Hashed", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 2395546.21, "Plan Rows": 1799737, "Plan Width": 27, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 517351.72, ...
{ "Startup Cost": 2131491.02, "Strategy": "Hashed", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 2395546.21, "Plan Rows": 1799737, "Plan Width": 27, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 517351.72, ...
medium
175
tpch
WITH filtered_orders AS ( SELECT L_ORDERKEY FROM LINEITEM GROUP BY L_ORDERKEY HAVING COUNT(DISTINCT L_PARTKEY) > 1 ), c1 AS ( SELECT t1.L_ORDERKEY AS grp, t1.L_PARTKEY AS e1, t2.L_PARTKEY AS e2 FROM LINEITEM t1 JOIN LINEITEM t2 ON t1.L_ORDERKEY = t2.L_ORDERKEY AND t1.L_PARTKEY < t2.L_PARTKEY WHERE t1.L_...
WITH c1 AS ( SELECT t1.L_ORDERKEY AS grp, t1.L_PARTKEY AS e1, t2.L_PARTKEY AS e2 FROM LINEITEM t1 JOIN LINEITEM t2 ON t1.L_ORDERKEY = t2.L_ORDERKEY AND t1.L_PARTKEY < t2.L_PARTKEY ) SELECT e1, e2 FROM c1 GROUP BY e1, e2 ORDER BY COUNT(*) DESC LIMIT 1
70,303.207
54,277.981
{ "Startup Cost": 17795934.59, "Parallel Aware": false, "Node Type": "Limit", "Total Cost": 17795934.6, "Plan Rows": 1, "Plan Width": 16, "Plans": [ { "Startup Cost": 17795934.59, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 18008113.25, "Plan Rows": 848714...
{ "Startup Cost": 47883925.39, "Parallel Aware": false, "Node Type": "Limit", "Total Cost": 47883925.39, "Plan Rows": 1, "Plan Width": 16, "Plans": [ { "Startup Cost": 47883925.39, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 48520461.35, "Plan Rows": 25461...
hard
176
tpch
WITH lineitem_agg AS ( SELECT l_orderkey, SUM(l_quantity) as total_quantity, SUM(l_extendedprice) as total_price FROM lineitem GROUP BY l_orderkey ) SELECT o.o_clerk, o.o_orderpriority, SUM(la.total_quantity), SUM(la.total_price) FROM orders o INNER JOIN lineitem_agg la ON o.o_orderkey = la.l_orderkey GROUP...
WITH order_lineitems AS ( SELECT o.o_clerk, o.o_orderpriority, l.l_quantity, l.l_extendedprice FROM orders o INNER JOIN lineitem l ON o.o_orderkey = l.l_orderkey ) SELECT o_clerk, o_orderpriority, SUM(l_quantity), SUM(l_extendedprice) FROM order_lineitems GROUP BY o_clerk, o_orderpriority;
34,046.892
24,257.595
{ "Startup Cost": 1140613.5, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 1146139.09, "Plan Rows": 15000, "Plan Width": 96, "Plans": [ { "Startup Cost": 1140613.5, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 1141673.62...
{ "Startup Cost": 2830732.31, "Strategy": "Hashed", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 3147317.36, "Plan Rows": 15000, "Plan Width": 96, "Plans": [ { "Startup Cost": 214706.07, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 1025...
medium
177
tpch
SELECT l_shipmode AS Destination, TRIM(TO_CHAR(l_shipdate, 'Day')) AS Day, COUNT(TO_CHAR(l_shipdate, 'Day')) AS Booking FROM lineitem GROUP BY l_shipmode, TRIM(TO_CHAR(l_shipdate, 'Day')) ORDER BY l_shipmode, COUNT(l_shipmode) DESC
SELECT l_shipmode AS Destination, CASE EXTRACT(DOW FROM l_shipdate) WHEN 0 THEN 'Sunday' WHEN 1 THEN 'Monday' WHEN 2 THEN 'Tuesday' WHEN 3 THEN 'Wednesday' WHEN 4 THEN 'Thursday' WHEN 5 THEN 'Friday' WHEN 6 THEN 'Saturday' END AS Day, COUNT(TO_CHAR(l_shipdate, 'Day')) AS Booking FROM lineitem GROUP BY l_shipmode, EXTRA...
19,944.088
14,089.015
{ "Startup Cost": 923835.49, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 923879.33, "Plan Rows": 17535, "Plan Width": 59, "Plans": [ { "Startup Cost": 922292.59, "Strategy": "Hashed", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 922599....
{ "Startup Cost": 879192.76, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 879236.6, "Plan Rows": 17535, "Plan Width": 67, "Plans": [ { "Startup Cost": 877299.16, "Strategy": "Hashed", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 877956.7...
medium
178
tpch
WITH materialized_orders AS MATERIALIZED ( SELECT o_orderkey FROM orders ), materialized_lineitems AS MATERIALIZED ( SELECT l_orderkey, l_partkey, l_quantity FROM lineitem ) SELECT mo.o_orderkey AS order_id, p.p_name AS item_name, ml.l_quantity AS item_weight FROM materialized_orders mo J...
SELECT o.o_orderkey AS order_id, p.p_name AS item_name, l.l_quantity AS item_weight FROM orders o JOIN lineitem l ON o.o_orderkey = l.l_orderkey JOIN part p ON l.l_partkey = p.p_partkey
39,110.695
19,945.156
{ "Startup Cost": 221188.07, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 1206807.37, "Plan Rows": 17997372, "Plan Width": 42, "Plans": [ { "Startup Cost": 190711.07, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 948642.93, "Plan Row...
{ "Startup Cost": 221188.07, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 1206807.37, "Plan Rows": 17997372, "Plan Width": 42, "Plans": [ { "Startup Cost": 190711.07, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 948642.93, "Plan Row...
medium
179
tpch
WITH filtered_orders AS ( SELECT o_orderdate, o_custkey, o_orderkey FROM orders o WHERE EXISTS ( SELECT 1 FROM lineitem l WHERE l.l_orderkey = o.o_orderkey AND EXISTS ( SELECT 1 FROM partsupp ps WHERE ps.ps_partkey = l.l_partkey AND ps.ps_suppkey = l.l_suppkey...
SELECT o.o_orderdate AS time, o.o_custkey AS person, MAX(o.o_orderkey) AS id1, MAX(l.l_partkey) AS id2, MAX(l.l_suppkey) AS id3, MAX(ps.ps_partkey) AS id4 FROM ( SELECT o_orderdate, o_custkey, o_orderkey FROM orders ) o JOIN lineitem l ON o.o_orderkey = l.l_orderkey JOIN partsupp ps ON l.l_partkey = ps.ps_partk...
52,279.115
34,948.548
{ "Startup Cost": 2689517.84, "Strategy": "Hashed", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 2713889.69, "Plan Rows": 450071, "Plan Width": 24, "Plans": [ { "Startup Cost": 1569893.92, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 25...
{ "Startup Cost": 2824840.05, "Strategy": "Hashed", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 3040247.46, "Plan Rows": 450071, "Plan Width": 24, "Plans": [ { "Startup Cost": 309361.14, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 135...
hard
180
tpch
SELECT MAX(CASE WHEN is_max_price THEN L_QUANTITY END), MAX(CASE WHEN is_max_price THEN L_EXTENDEDPRICE END) FROM (SELECT L_QUANTITY, L_EXTENDEDPRICE, L_EXTENDEDPRICE = MAX(L_EXTENDEDPRICE) OVER () AS is_max_price FROM LINEITEM) AS subquery WHERE is_max_price;
WITH temptable (max_extendedprice) AS ( SELECT MAX(L_EXTENDEDPRICE) AS max_extendedprice FROM LINEITEM ) SELECT MAX(L_QUANTITY), MAX(L_EXTENDEDPRICE) FROM LINEITEM, temptable WHERE L_EXTENDEDPRICE = temptable.max_extendedprice;
12,846.454
9,896.127
{ "Startup Cost": 1012279.45, "Strategy": "Plain", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 1012279.46, "Plan Rows": 1, "Plan Width": 64, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Subquery Scan", "Total Cost": 967286.02, ...
{ "Startup Cost": 1126940.34, "Strategy": "Plain", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 1126940.35, "Plan Rows": 1, "Plan Width": 64, "Plans": [ { "Startup Cost": 562345.18, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 1126940.2...
easy
181
tpch
SELECT encode(sha256(CONCAT(l_orderkey::text, l_partkey::text, l_suppkey::text, l_linenumber::text)::bytea), 'hex') as hash, l_orderkey as field1, l_partkey as field2, l_suppkey as field3, l_linenumber as field4, COUNT(*) as count FROM lineitem WHERE l_shipdate BETWEEN '1992-01-02' AND '199...
WITH filtered_counts AS ( SELECT l_orderkey, l_partkey, l_suppkey, l_linenumber, COUNT(*) as count FROM lineitem WHERE l_shipdate BETWEEN '1992-01-02' AND '1998-12-01' AND l_commitdate BETWEEN '1992-01-31' AND '1998-10-31' GROUP BY l_orderkey, l_partkey,...
40,511.77
27,918.797
{ "Startup Cost": 3086661.89, "Strategy": "Hashed", "Parallel Aware": false, "Node Type": "Aggregate", "Total Cost": 3479386.42, "Plan Rows": 1799737, "Plan Width": 56, "Plans": [ { "Startup Cost": 0, "Parallel Aware": false, "Node Type": "Seq Scan", "Total Cost": 1282010.12,...
{ "Startup Cost": 0.44, "Parallel Aware": false, "Node Type": "Subquery Scan", "Total Cost": 1657036.55, "Plan Rows": 1799737, "Plan Width": 56, "Alias": "filtered_counts", "Plans": [ { "Startup Cost": 0.44, "Strategy": "Sorted", "Parallel Aware": false, "Node Type": "Aggrega...
hard
182
tpch
SELECT t1.l_partkey as name, EXTRACT(YEAR FROM t1.l_shipdate) as year_no FROM lineitem t1 INNER JOIN lineitem t2 ON t1.l_partkey = t2.l_partkey AND EXTRACT(YEAR FROM t1.l_shipdate) = EXTRACT(YEAR FROM t2.l_shipdate) INNER JOIN lineitem t3 ON t1.l_partkey = t3.l_partkey AND EXTRACT(YEAR FROM t1.l_shipdate) = EXTRACT(YEA...
SELECT t1.l_partkey as name, t1.year_no FROM (SELECT l_partkey, l_shipdate, EXTRACT(YEAR FROM l_shipdate) as year_no, l_shipdate + INTERVAL '1 week' as next_week, l_shipdate + INTERVAL '2 weeks' as next_2weeks FROM lineitem) t1 INNER JOIN (SELECT l_partkey, l_shipdate, EXTRACT(YEAR FROM l_shipdate) as year_no FROM line...
117,776.868
85,465.56
{ "Startup Cost": 857615.74, "Parallel Aware": false, "Node Type": "Nested Loop", "Total Cost": 5975505.12, "Plan Rows": 1, "Plan Width": 12, "Plans": [ { "Startup Cost": 857615.3, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 5902703.58, "Plan Rows": 1...
{ "Startup Cost": 857615.74, "Parallel Aware": false, "Node Type": "Nested Loop", "Total Cost": 5975505.12, "Plan Rows": 1, "Plan Width": 12, "Plans": [ { "Startup Cost": 857615.3, "Parallel Aware": false, "Node Type": "Hash Join", "Total Cost": 5902703.58, "Plan Rows": 1...
hard
183
tpch
SELECT SUM((l_returnflag = 'R')::integer * (l_linestatus = 'F')::integer * (l_discount > 0)::integer) FROM lineitem;
SELECT SUM(CASE WHEN l_returnflag = 'R' AND l_linestatus = 'F' AND l_discount > 0 THEN 1 ELSE 0 END) FROM lineitem WHERE l_returnflag = 'R' AND l_linestatus = 'F' AND l_discount > 0;
2,613.259
1,976.97
{ "Node Type": "Aggregate", "Total Cost": 483615.72, "Plan Width": 8, "Parallel Aware": false, "Plan Rows": 1, "Strategy": "Plain", "Startup Cost": 483615.71, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 382374.22, "Relation Name": "line...
{ "Node Type": "Aggregate", "Total Cost": 421213.24, "Plan Width": 8, "Parallel Aware": false, "Plan Rows": 1, "Strategy": "Plain", "Startup Cost": 421213.23, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 416121.39, "Relation Name": "line...
medium
184
tpch
SELECT L_COMMENT FROM LINEITEM WHERE L_COMMENT ~ '(?=.*a)(?=.*e)(?=.*i)(?=.*o)(?=.*u)'
SELECT L_COMMENT FROM LINEITEM WHERE LENGTH(L_COMMENT) >= 5 AND POSITION('a' IN L_COMMENT) > 0 AND POSITION('e' IN L_COMMENT) > 0 AND POSITION('i' IN L_COMMENT) > 0 AND POSITION('o' IN L_COMMENT) > 0 AND POSITION('u' IN L_COMMENT) > 0
39,083.644
3,123.281
{ "Node Type": "Seq Scan", "Total Cost": 393623.28, "Relation Name": "lineitem", "Plan Width": 27, "Parallel Aware": false, "Plan Rows": 1816150, "Startup Cost": 0, "Alias": "lineitem" }
{ "Node Type": "Seq Scan", "Total Cost": 517362.88, "Relation Name": "lineitem", "Plan Width": 27, "Parallel Aware": false, "Plan Rows": 6172, "Startup Cost": 0, "Alias": "lineitem" }
medium
185
tpch
WITH max_date AS (SELECT MAX(o_orderdate) as max_dt FROM orders WHERE o_orderdate <= '2021-02-20') SELECT o.* FROM orders o JOIN max_date md ON o.o_orderdate = md.max_dt ORDER BY o.o_orderdate DESC LIMIT 1;
SELECT * FROM orders WHERE o_orderdate <= '2021-02-20' ORDER BY o_orderdate DESC LIMIT 1;
1,943.091
1,148.148
{ "Node Type": "Limit", "Total Cost": 280917.32, "Plan Width": 107, "Parallel Aware": false, "Plan Rows": 1, "Startup Cost": 280917.32, "Plans": [ { "Node Type": "Sort", "Parent Relationship": "Outer", "Total Cost": 280921.99, "Plan Width": 107, "Parallel Aware": false, ...
{ "Node Type": "Limit", "Total Cost": 157038.28, "Plan Width": 107, "Parallel Aware": false, "Plan Rows": 1, "Startup Cost": 157038.27, "Plans": [ { "Node Type": "Sort", "Parent Relationship": "Outer", "Total Cost": 168288.95, "Plan Width": 107, "Parallel Aware": false, ...
easy
186
tpch
SELECT * FROM ORDERS WHERE O_ORDERSTATUS = 'F' UNION ALL SELECT * FROM ORDERS WHERE O_ORDERSTATUS = 'O' UNION ALL SELECT * FROM ORDERS WHERE O_ORDERSTATUS = 'P'
SELECT * FROM ORDERS WHERE O_ORDERSTATUS LIKE ANY(ARRAY['F%', 'O%', 'P%'])
2,199.587
973.974
{ "Node Type": "Append", "Total Cost": 471121.47, "Plan Width": 107, "Parallel Aware": false, "Plan Rows": 4500713, "Startup Cost": 0, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Member", "Total Cost": 134536.92, "Relation Name": "orders", "Plan Width": ...
{ "Node Type": "Seq Scan", "Total Cost": 140162.82, "Relation Name": "orders", "Plan Width": 107, "Parallel Aware": false, "Plan Rows": 3347598, "Startup Cost": 0, "Alias": "orders" }
easy
187
tpch
SELECT DISTINCT O_CLERK AS office, O_ORDERPRIORITY AS business, COUNT(O_COMMENT) OVER (PARTITION BY O_CLERK, O_ORDERPRIORITY) AS total FROM ORDERS
WITH filtered_orders AS (SELECT O_CLERK, O_ORDERPRIORITY, O_COMMENT FROM ORDERS) SELECT O_CLERK AS office, O_ORDERPRIORITY AS business, COUNT(O_COMMENT) AS total FROM filtered_orders GROUP BY O_CLERK, O_ORDERPRIORITY
23,121.77
2,099.222
{ "Node Type": "Aggregate", "Total Cost": 1657719.15, "Plan Width": 40, "Parallel Aware": false, "Plan Rows": 4092616, "Strategy": "Hashed", "Startup Cost": 1546469.34, "Plans": [ { "Node Type": "WindowAgg", "Parent Relationship": "Outer", "Total Cost": 1141405.08, "Plan Widt...
{ "Node Type": "Aggregate", "Total Cost": 157190.49, "Plan Width": 40, "Parallel Aware": false, "Plan Rows": 15000, "Strategy": "Hashed", "Startup Cost": 157040.49, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 123285.14, "Relation Name":...
easy
188
tpch
SELECT o.*, c.* FROM orders o, LATERAL (SELECT * FROM customer WHERE c_custkey = o.o_custkey LIMIT ALL) c
SELECT * FROM ORDERS JOIN CUSTOMER ON ORDERS.O_CUSTKEY = CUSTOMER.C_CUSTKEY
23,973.892
4,528.763
{ "Node Type": "Nested Loop", "Total Cost": 38199325.58, "Plan Width": 266, "Parallel Aware": false, "Plan Rows": 4500714, "Startup Cost": 0.42, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 123285.14, "Relation Name": "orders", "Plan...
{ "Node Type": "Hash Join", "Total Cost": 325628.63, "Plan Width": 266, "Parallel Aware": false, "Plan Rows": 4500714, "Startup Cost": 30983, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 123285.14, "Relation Name": "orders", "Plan Wi...
easy
189
tpch
SELECT O_CLERK AS Division, O_CLERK AS Emp_Id, SUM(CASE WHEN TO_CHAR(O_ORDERDATE, 'YYYYMM') = '202101' THEN L_EXTENDEDPRICE ELSE NULL END) AS "202101", SUM(CASE WHEN TO_CHAR(O_ORDERDATE, 'YYYYMM') = '202102' THEN L_EXTENDEDPRICE ELSE NULL END) AS "202102", SUM(CASE WHEN TO_CHAR(O_ORDERDATE, 'YYYYMM') = '202103' THEN L_...
SELECT O_CLERK AS Division, O_CLERK AS Emp_Id, SUM(CASE WHEN O_ORDERDATE >= '2021-01-01' AND O_ORDERDATE < '2021-02-01' THEN L_EXTENDEDPRICE ELSE NULL END) AS "202101", SUM(CASE WHEN O_ORDERDATE >= '2021-02-01' AND O_ORDERDATE < '2021-03-01' THEN L_EXTENDEDPRICE ELSE NULL END) AS "202102", SUM(CASE WHEN O_ORDERDATE >= ...
10,948.424
6,370.131
{ "Node Type": "Aggregate", "Total Cost": 816706.02, "Plan Width": 128, "Parallel Aware": false, "Plan Rows": 3000, "Strategy": "Hashed", "Startup Cost": 816653.52, "Plans": [ { "Node Type": "Hash Join", "Parent Relationship": "Outer", "Total Cost": 670415.8, "Plan Width": 28...
{ "Node Type": "Aggregate", "Total Cost": 782958.85, "Plan Width": 128, "Parallel Aware": false, "Plan Rows": 3000, "Strategy": "Hashed", "Startup Cost": 782906.35, "Plans": [ { "Node Type": "Hash Join", "Parent Relationship": "Outer", "Total Cost": 670415.8, "Plan Width": 28...
hard
190
tpch
SELECT o.o_orderkey AS num_courrier, o.o_orderdate AS date_recep, o.o_clerk AS expediteur, o.o_comment AS objet, l.l_receiptdate AS date_lect_prefet, l.l_shipinstruct AS instructions, l.l_returnflag AS caractere FROM orders o LEFT JOIN lineitem l ON o.o_orderkey = l.l_orderkey UNION ALL SELECT NULL AS num_courrier, NUL...
SELECT o.o_orderkey AS num_courrier, o.o_orderdate AS date_recep, o.o_clerk AS expediteur, o.o_comment AS objet, l.l_receiptdate AS date_lect_prefet, l.l_shipinstruct AS instructions, l.l_returnflag AS caractere FROM orders o FULL JOIN lineitem l ON o.o_orderkey = l.l_orderkey
11,762.492
6,727.81
{ "Node Type": "Append", "Total Cost": 1529674.05, "Plan Width": 105, "Parallel Aware": false, "Plan Rows": 4500715, "Startup Cost": 236682.07, "Plans": [ { "Node Type": "Hash Join", "Parent Relationship": "Member", "Total Cost": 758313.8, "Plan Width": 105, "Parallel Awa...
{ "Node Type": "Hash Join", "Total Cost": 758313.8, "Plan Width": 105, "Parallel Aware": false, "Plan Rows": 4500714, "Startup Cost": 236682.07, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 382374.22, "Relation Name": "lineitem", "Pl...
medium
191
tpch
SELECT o.l_orderkey as job_id, no_po.max_receipt as no_po_date, po.max_receipt as po_date, CASE WHEN no_po.max_receipt IS NULL AND po.max_receipt IS NOT NULL THEN true WHEN no_po.max_receipt IS NOT NULL AND po.max_receipt IS NULL THEN false WHEN no_po.max_receipt IS NULL...
SELECT l_orderkey as job_id, MAX(CASE WHEN l_comment = 'NO PO' THEN l_receiptdate ELSE NULL END) as no_po_date, MAX(CASE WHEN l_comment = 'PO-025780' THEN l_receiptdate ELSE NULL END) as po_date, CASE WHEN MAX(CASE WHEN l_comment = 'NO PO' THEN l_receiptdate ELSE NULL END) IS NULL ...
22,208.906
3,706.322
{ "Node Type": "Nested Loop", "Total Cost": 76610286.43, "Plan Width": 13, "Parallel Aware": false, "Plan Rows": 4499622, "Startup Cost": 17.34, "Plans": [ { "Node Type": "Nested Loop", "Parent Relationship": "Outer", "Total Cost": 38419744.71, "Plan Width": 8, "Parallel ...
{ "Node Type": "Aggregate", "Total Cost": 811959.31, "Plan Width": 13, "Parallel Aware": false, "Plan Rows": 4499622, "Strategy": "Sorted", "Startup Cost": 0.43, "Plans": [ { "Node Type": "Index Scan", "Parent Relationship": "Outer", "Total Cost": 519483.88, "Relation Name": ...
hard
192
tpch
SELECT t1.* FROM lineitem t1 INNER JOIN (SELECT l_orderkey, l_returnflag FROM lineitem WHERE l_orderkey <> 0 AND l_returnflag IN ('R', 'N') GROUP BY l_orderkey, l_returnflag HAVING COUNT(DISTINCT l_linestatus) > 1) t2 ON t1.l_orderkey = t2.l_orderkey AND t1.l_returnflag = t2.l_returnflag WHERE t1.l_orderkey <> 0 ORDER ...
SELECT * FROM lineitem t1 WHERE l_orderkey <> 0 AND l_returnflag IN ('R', 'N') AND EXISTS (SELECT 1 FROM lineitem t2 WHERE t1.l_orderkey = t2.l_orderkey AND t2.l_orderkey <> 0 AND t2.l_returnflag IN ('R', 'N') AND t1.l_returnflag = t2.l_returnflag AND t1.l_linestatus <> t2.l_linestatus) ORDER BY l_orderkey
6,553.063
4,585.713
{ "Node Type": "Merge Join", "Total Cost": 1332642.02, "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 5652, "Startup Cost": 1.03, "Plans": [ { "Node Type": "Aggregate", "Parent Relationship": "Outer", "Total Cost": 762401.15, "Plan Width": 6, "Parallel Aware": f...
{ "Node Type": "Merge Join", "Total Cost": 1139254.49, "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 2555618, "Startup Cost": 0.86, "Plans": [ { "Node Type": "Index Scan", "Parent Relationship": "Outer", "Total Cost": 541982.45, "Relation Name": "lineitem", "Pl...
hard
193
tpch
SELECT DISTINCT ON (o.o_orderkey) o.o_orderdate AS temporal_start_date, o.o_orderkey AS report_id, o.o_totalprice AS report_info_id, o.o_orderstatus AS status FROM orders o INNER JOIN (SELECT o_orderkey, MAX(o_orderdate) as max_date FROM orders GROUP BY o_orderkey) latest ON o.o_orderkey = latest.o_orderkey AND o.o_ord...
SELECT DISTINCT ON (o_orderkey) o_orderdate AS temporal_start_date, o_orderkey AS report_id, o_totalprice AS report_info_id, o_orderstatus AS status FROM orders ORDER BY o_orderkey, o_orderdate DESC;
6,790.663
3,611.491
{ "Node Type": "Unique", "Total Cost": 581695.67, "Plan Width": 18, "Parallel Aware": false, "Plan Rows": 1871, "Startup Cost": 581686.32, "Plans": [ { "Node Type": "Sort", "Parent Relationship": "Outer", "Total Cost": 581690.99, "Plan Width": 18, "Parallel Aware": false,...
{ "Node Type": "Unique", "Total Cost": 827760.37, "Plan Width": 18, "Parallel Aware": false, "Plan Rows": 4500714, "Startup Cost": 805256.8, "Plans": [ { "Node Type": "Sort", "Parent Relationship": "Outer", "Total Cost": 816508.58, "Plan Width": 18, "Parallel Aware": fals...
easy
194
tpch
SELECT o_orderdate, SUM(CASE WHEN rn = 1 THEN 1 ELSE 0 END) AS quantity FROM (SELECT o_orderdate, row_number() over(PARTITION BY DATE_PART('year', (o_orderdate - INTERVAL '2 month')::date), o_custkey ORDER BY o_orderdate) rn FROM orders) t GROUP BY o_orderdate;
WITH first_orders AS (SELECT DISTINCT ON (DATE_PART('year', (o_orderdate - INTERVAL '2 month')::date), o_custkey) o_orderdate FROM orders ORDER BY DATE_PART('year', (o_orderdate - INTERVAL '2 month')::date), o_custkey, o_orderdate) SELECT o_orderdate, COUNT(*) AS quantity FROM first_orders GROUP BY o_orderdate;
8,303.277
6,509.826
{ "Node Type": "Aggregate", "Total Cost": 1044558.7, "Plan Width": 12, "Parallel Aware": false, "Plan Rows": 2406, "Strategy": "Hashed", "Startup Cost": 1044534.64, "Plans": [ { "Node Type": "WindowAgg", "Parent Relationship": "Outer", "Total Cost": 965772.14, "Plan Width": 2...
{ "Node Type": "Aggregate", "Total Cost": 860007.36, "Plan Width": 12, "Parallel Aware": false, "Plan Rows": 200, "Strategy": "Hashed", "Startup Cost": 860005.36, "Plans": [ { "Node Type": "Unique", "Parent Relationship": "Outer", "Total Cost": 853254.29, "Plan Width": 16, ...
easy
195
tpch
SELECT DISTINCT l_shipmode as name, EXTRACT(MONTH FROM l_shipdate) as month, MAX(l_extendedprice) OVER (PARTITION BY l_shipmode, EXTRACT(MONTH FROM l_shipdate)) as month_max, MIN(l_extendedprice) OVER (PARTITION BY l_shipmode, EXTRACT(MONTH FROM l_shipdate)) as month_min FROM lineitem
WITH ship_modes AS ( SELECT l_shipmode, EXTRACT(MONTH FROM l_shipdate) as ship_month, l_extendedprice FROM lineitem ) SELECT l_shipmode as name, ship_month as month, MAX(l_extendedprice) as month_max, MIN(l_extendedprice) as month_min FROM ship_modes GROUP BY l_shipmode, ship_month
10,882.645
3,812.508
{ "Node Type": "Aggregate", "Total Cost": 2002061.95, "Plan Width": 83, "Parallel Aware": false, "Plan Rows": 714637, "Strategy": "Hashed", "Startup Cost": 1868305.86, "Plans": [ { "Node Type": "WindowAgg", "Parent Relationship": "Outer", "Total Cost": 1241171.04, "Plan Width...
{ "Node Type": "Aggregate", "Total Cost": 450131.78, "Plan Width": 83, "Parallel Aware": false, "Plan Rows": 17549, "Strategy": "Hashed", "Startup Cost": 449868.55, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 404872.33, "Relation Name":...
easy
196
tpch
WITH materialized_orders AS MATERIALIZED ( SELECT O_ORDERKEY, O_ORDERSTATUS FROM ORDERS ) SELECT O_ORDERKEY AS ID, O_ORDERSTATUS || ':' || COUNT(O_ORDERSTATUS) || '; ' FROM materialized_orders GROUP BY O_ORDERSTATUS, O_ORDERKEY;
SELECT O_ORDERKEY AS ID, O_ORDERSTATUS || ':' || COUNT(O_ORDERSTATUS) || '; ' FROM ORDERS GROUP BY O_ORDERSTATUS, O_ORDERKEY;
6,164.544
3,521.418
{ "Node Type": "Aggregate", "Total Cost": 248054.78, "Plan Width": 44, "Parallel Aware": false, "Plan Rows": 40000, "Strategy": "Hashed", "Startup Cost": 247054.78, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "InitPlan", "Total Cost": 123285.14, "Relation Nam...
{ "Node Type": "Aggregate", "Total Cost": 330173.56, "Plan Width": 38, "Parallel Aware": false, "Plan Rows": 4500714, "Strategy": "Sorted", "Startup Cost": 0.43, "Plans": [ { "Node Type": "Index Scan", "Parent Relationship": "Outer", "Total Cost": 195152.14, "Relation Name": ...
medium
197
tpch
SELECT o.O_ORDERKEY AS OrderID, l.L_QUANTITY_SUM AS OrderQuantity, o.O_ORDERDATE AS OrderPlacementDate, l.L_LINENUMBER AS TransactionID FROM ( SELECT * FROM ORDERS UNION SELECT * FROM ORDERS ) o LEFT JOIN LATERAL ( SELECT L_LINENUMBER, SUM(L_QUANTITY) AS L_QUANTITY_SU...
SELECT o.O_ORDERKEY AS OrderID, agg.L_QUANTITY_SUM AS OrderQuantity, o.O_ORDERDATE AS OrderPlacementDate, agg.L_LINENUMBER AS TransactionID FROM ( SELECT * FROM ORDERS UNION SELECT * FROM ORDERS ) o LEFT JOIN ( SELECT L_ORDERKEY, L_LINENUMBER, SUM(L_QUANTITY)...
27,069.986
21,450.531
{ "Node Type": "Nested Loop", "Total Cost": 82474100.29, "Plan Width": 44, "Parallel Aware": false, "Plan Rows": 9001428, "Startup Cost": 5759430.59, "Plans": [ { "Node Type": "Unique", "Parent Relationship": "Outer", "Total Cost": 5984465.86, "Plan Width": 346, "Parallel...
{ "Node Type": "Merge Join", "Total Cost": 3044669444.24, "Plan Width": 44, "Parallel Aware": false, "Plan Rows": 202515117301, "Startup Cost": 5759430.71, "Plans": [ { "Node Type": "Aggregate", "Parent Relationship": "Outer", "Total Cost": 811959.31, "Plan Width": 40, "P...
medium
198
tpch
SELECT c.C_CUSTKEY as customerid, auto.count as source1, building.count as source2, furniture.count as destination1, household.count as destination2 FROM (SELECT DISTINCT C_CUSTKEY FROM CUSTOMER) c LEFT JOIN LATERAL ( SELECT COUNT(DISTINCT C_NAME || C_MKTSEGMENT) as count FROM CUSTOMER WHERE C_CUSTKEY = c.C_CUSTKEY AND...
SELECT C_CUSTKEY as customerid, COUNT(DISTINCT CASE WHEN C_MKTSEGMENT = 'AUTOMOBILE' THEN C_NAME || C_MKTSEGMENT END) as source1, COUNT(DISTINCT CASE WHEN C_MKTSEGMENT = 'BUILDING' THEN C_NAME || C_MKTSEGMENT END) as source2, COUNT(DISTINCT CASE WHEN C_MKTSEGMENT = 'FURNITURE' THEN C_NAME || C_MKTSEGMENT EN...
5,203.531
1,290.419
{ "Node Type": "Nested Loop", "Total Cost": 15281319.42, "Plan Width": 36, "Parallel Aware": false, "Plan Rows": 450000, "Startup Cost": 34.22, "Plans": [ { "Node Type": "Nested Loop", "Parent Relationship": "Outer", "Total Cost": 11465319.42, "Plan Width": 28, "Parallel ...
{ "Node Type": "Aggregate", "Total Cost": 46072.42, "Plan Width": 36, "Parallel Aware": false, "Plan Rows": 450000, "Strategy": "Sorted", "Startup Cost": 0.42, "Plans": [ { "Node Type": "Index Scan", "Parent Relationship": "Outer", "Total Cost": 22447.42, "Relation Name": "cu...
hard
199
tpch
SELECT l_orderkey as docid, 'C:\documents\' || l_orderkey || '_' || l_linenumber::VARCHAR || '.' || l_shipinstruct AS FilePath FROM lineitem WHERE l_shipinstruct = 'DELIVER IN PERSON' UNION ALL SELECT l_orderkey as docid, 'C:\documents\' || l_orderkey || '.' || l_shipinstruct AS FilePath FROM l...
WITH processed_lineitem AS ( SELECT l_orderkey, l_shipinstruct, l_linenumber, CASE WHEN l_shipinstruct = 'DELIVER IN PERSON' THEN '_' || CAST(l_linenumber AS VARCHAR) ELSE '' END AS linenumber_suffix FROM lineitem ) SELECT l_o...
5,589.852
3,647.61
{ "Node Type": "Append", "Total Cost": 933521.76, "Plan Width": 36, "Parallel Aware": false, "Plan Rows": 4499622, "Startup Cost": 0, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Member", "Total Cost": 421839.65, "Relation Name": "lineitem", "Plan Width":...
{ "Node Type": "Seq Scan", "Total Cost": 506113.82, "Relation Name": "lineitem", "Plan Width": 36, "Parallel Aware": false, "Plan Rows": 4499622, "Startup Cost": 0, "Alias": "lineitem" }
medium
200
tpch
SELECT li.* FROM lineitem li INNER JOIN orders o1 ON li.l_orderkey = o1.o_orderkey LEFT JOIN orders o2 ON li.l_orderkey = o2.o_custkey WHERE li.l_shipmode = 'AIR' AND o2.o_orderkey IS NULL
SELECT li.* FROM lineitem li WHERE li.l_shipmode = 'AIR' AND EXISTS (SELECT 1 FROM orders o WHERE o.o_orderkey = li.l_orderkey) AND NOT EXISTS (SELECT 1 FROM orders o WHERE o.o_custkey = li.l_orderkey)
5,716.576
4,327.647
{ "Node Type": "Nested Loop", "Total Cost": 606230.6, "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 1, "Startup Cost": 413072.16, "Plans": [ { "Node Type": "Hash Join", "Parent Relationship": "Outer", "Total Cost": 606230.07, "Plan Width": 117, "Parallel Aware"...
{ "Node Type": "Merge Join", "Total Cost": 776426.7, "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 607129, "Startup Cost": 93.77, "Plans": [ { "Node Type": "Merge Join", "Parent Relationship": "Outer", "Total Cost": 666935.75, "Plan Width": 117, "Parallel Aware...
hard