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
1
tpch
WITH UnpivotedData AS (SELECT ctid AS row_id, l_extendedprice AS estimate_val FROM lineitem UNION ALL SELECT ctid AS row_id, l_discount AS estimate_val FROM lineitem UNION ALL SELECT ctid AS row_id, l_tax AS estimate_val FROM lineitem), AggregatedAverages AS (SELECT row_id, round(avg(estimate_val), 2) AS avg_estimate F...
SELECT t.*, round(avg_calc.avg_val, 2) AS avg_estimate FROM lineitem AS t LEFT JOIN LATERAL (SELECT avg(v.val) AS avg_val FROM (VALUES (t.l_extendedprice), (t.l_discount), (t.l_tax)) AS v(val)) AS avg_calc ON TRUE;
130,791.865
42,217.071
{ "Plan Width": 149, "Actual Rows": 17996609, "Plan Rows": 200, "Actual Startup Time": 25607.736, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 2092718.38, "Actual Total Time": 129459.461, "Startup Cost": 2091908.88, "Plans": [ { "Plan Width": 38, ...
{ "Plan Width": 149, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 119.398, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1957040.32, "Actual Total Time": 41550.132, "Startup Cost": 0.05, "Plans": [ { "Relation Name": "line...
medium
2
tpch
SELECT d.month, d.year, (SELECT COUNT(*) FROM orders t WHERE EXTRACT(MONTH FROM t.o_orderdate) = d.month AND EXTRACT(YEAR FROM t.o_orderdate) = d.year AND t.o_orderstatus = 'F') AS acc_completed, (SELECT COUNT(*) FROM orders t WHERE EXTRACT(MONTH FROM t.o_orderdate) = d.month AND EXTRACT(YEAR FROM t.o_ord...
SELECT EXTRACT(MONTH FROM o.o_orderdate) AS month, EXTRACT(YEAR FROM o.o_orderdate) AS year, COUNT(CASE WHEN o.o_orderstatus = 'F' THEN 1 END) AS acc_completed, COUNT(CASE WHEN o.o_orderstatus = 'O' THEN 1 END) AS acc_start FROM orders o GROUP BY EXTRACT(MONTH FROM o.o_orderdate), EXTRACT(YEAR FROM o.o_or...
364,865.627
7,351.592
{ "Plan Width": 32, "Actual Rows": 80, "Plan Rows": 2406, "Actual Startup Time": 10911.163, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 3241205573.6, "Actual Total Time": 364845.39, "Startup Cost": 635932.55, "Alias": "d", "Plans": [ { "Plan ...
{ "Plan Width": 32, "Actual Rows": 80, "Plan Rows": 2406, "Actual Startup Time": 7332.59, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 785988.89, "Actual Total Time": 7332.614, "Startup Cost": 785940.77, "Plans": [ { "Relatio...
medium
3
tpch
SELECT o.* FROM orders o WHERE o.o_clerk <> ' ' AND EXISTS ( SELECT 1 FROM (VALUES ('F'::char(1)), ('O'::char(1))) AS v(status) WHERE v.status = o.o_orderstatus );
SELECT t1.* FROM orders AS t1 WHERE t1.o_clerk <> ' ' AND t1.o_orderstatus IN ('F','O');
1,776.159
1,047.851
{ "Plan Width": 107, "Actual Rows": 4385171, "Plan Rows": 2998723, "Actual Startup Time": 6.974, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 179691.05, "Actual Total Time": 1604.146, "Startup Cost": 0.05, "Plans": [ { "Relation Name": "orders", ...
{ "Relation Name": "orders", "Plan Width": 107, "Actual Rows": 4385171, "Plan Rows": 4375437, "Actual Startup Time": 3.22, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 145771.68, "Actual Total Time": 875.083, "Startup Cost": 0, "Alias": "t1" }
easy
4
tpch
SELECT l_orderkey, (array_agg(l_quantity ORDER BY l_quantity DESC) FILTER (WHERE l_returnflag = 'R'))[1] AS A, (array_agg(l_quantity ORDER BY l_quantity DESC) FILTER (WHERE l_returnflag = 'A'))[1] AS B, (array_agg(l_quantity ORDER BY l_quantity DESC) FILTER (WHERE l_returnflag = 'N'))[1] AS V FROM lineitem GROUP BY l_o...
WITH cte AS ( SELECT l_returnflag, l_quantity, l_orderkey FROM lineitem ) SELECT l_orderkey, MAX(CASE WHEN l_returnflag = 'R' THEN l_quantity END) AS A, MAX(CASE WHEN l_returnflag = 'A' THEN l_quantity END) AS B, MAX(CASE WHEN l_returnflag = 'N' THEN l_quantity END) AS V FROM cte GROUP BY l_orderkey
19,065.472
9,116.911
{ "Plan Width": 100, "Actual Rows": 4500000, "Plan Rows": 405253, "Actual Startup Time": 122.366, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 1044001.65, "Actual Total Time": 18871.385, "Startup Cost": 0.44, "Plans": [ { "Re...
{ "Plan Width": 100, "Actual Rows": 4500000, "Plan Rows": 405253, "Actual Startup Time": 140.694, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 1040962.25, "Actual Total Time": 8931.265, "Startup Cost": 0.44, "Plans": [ { "Rel...
medium
5
tpch
SELECT TableActual.price AS "Final Pricing" FROM ( SELECT o.o_orderkey AS ordernumber, o.o_custkey AS customerkey, o.o_orderstatus AS orderstatus, ( SELECT COALESCE(ROUND(SUM(l.l_extendedprice * (1 - l.l_discount)),2), 0) FROM ...
SELECT dt.price AS "Final Pricing" FROM ( SELECT o.o_orderkey AS ordernumber, o.o_custkey AS customerkey, o.o_orderstatus AS orderstatus, ( SELECT COALESCE(ROUND(SUM(l.l_extendedprice * (1 - l.l_discount)),2), 0) FROM lineitem l WHERE o.o_order...
28,045.002
19,491.649
{ "Plan Width": 32, "Actual Rows": 4500000, "Plan Rows": 4500380, "Actual Startup Time": 159.539, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 64269307.38, "Actual Total Time": 27750.721, "Startup Cost": 0.43, "Alias": "tableactual", "Plans": [ { ...
{ "Plan Width": 32, "Actual Rows": 4500000, "Plan Rows": 4500380, "Actual Startup Time": 151.099, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 43207528.98, "Actual Total Time": 19205.039, "Startup Cost": 0.43, "Alias": "dt", "Plans": [ { "Plan...
hard
6
tpch
select orders.*, (first_week + floor(extract(epoch from o_orderdate::timestamp - first_week) / (14 * 86400)) * 14 * interval '1 day')::date as biweek from (select orders.*, min(date_trunc('week', o_orderdate)) over () as first_week from orders ) orders;
WITH first_week_val AS ( SELECT min(date_trunc('week', o_orderdate)) as fw FROM orders ), orders_with_biweek AS ( SELECT orders.*, fw.fw as first_week FROM orders CROSS JOIN first_week_val fw ) SELECT orders.*, (first_week + floor(extract(epoch from o_orderdate::timestamp - first_week) / (14 *...
7,133.529
5,153.832
{ "Plan Width": 119, "Actual Rows": 4500000, "Plan Rows": 4499579, "Actual Startup Time": 3421.815, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 359501.69, "Actual Total Time": 6948.276, "Startup Cost": 0, "Alias": "orders", "Plans": [ { "Plan...
{ "Plan Width": 119, "Actual Rows": 4500000, "Plan Rows": 4499579, "Actual Startup Time": 1934.694, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 437779.71, "Actual Total Time": 4971.459, "Startup Cost": 157020.63, "Plans": [ { "Plan Width": 8, ...
hard
7
tpch
SELECT d.year_value AS year, d.month_value AS month, COUNT(DISTINCT o.o_custkey) AS total_customers FROM ( SELECT DISTINCT EXTRACT(YEAR FROM o_orderdate) AS year_value, EXTRACT(MONTH FROM o_orderdate) AS month_value, DATE_TRUNC('month', o_orderdate)::DATE AS month_bucket FROM orders ) AS d JOIN orders...
SELECT EXTRACT(YEAR FROM o.o_orderdate) AS year, EXTRACT(MONTH FROM o.o_orderdate) AS month, COUNT(DISTINCT o.o_custkey) AS total_customers FROM orders AS o JOIN customer AS c ON o.o_custkey = c.c_custkey GROUP BY year, month ORDER BY year ASC, month ASC
12,729.231
6,939.517
{ "Plan Width": 24, "Actual Rows": 80, "Plan Rows": 241, "Actual Startup Time": 11049.74, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 13103454.47, "Actual Total Time": 12664.04, "Startup Cost": 12562056.35, "Plans": [ { "Pla...
{ "Plan Width": 24, "Actual Rows": 80, "Plan Rows": 2406, "Actual Startup Time": 5216.116, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 963064.89, "Actual Total Time": 6889.235, "Startup Cost": 918012.97, "Plans": [ { "Plan W...
easy
8
tpch
SELECT yt.* FROM orders yt JOIN (VALUES (DATE '1995-07-01', DATE '1996-06-30'), (DATE '1998-07-01', DATE '1998-12-31')) AS ranges(start_date, end_date) ON yt.o_orderdate BETWEEN ranges.start_date AND ranges.end_date
SELECT * FROM orders WHERE (o_orderdate >= DATE '1995-07-01' AND o_orderdate <= DATE '1996-06-30') OR (o_orderdate >= DATE '1998-07-01' AND o_orderdate <= DATE '1998-12-31')
2,323.148
652.711
{ "Plan Width": 107, "Actual Rows": 744880, "Plan Rows": 1000084, "Actual Startup Time": 5.287, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 280795.13, "Actual Total Time": 2276.161, "Startup Cost": 0, "Plans": [ { "Relation Name": "orders", ...
{ "Relation Name": "orders", "Plan Width": 107, "Actual Rows": 744880, "Plan Rows": 718201, "Actual Startup Time": 3.77, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 168285.6, "Actual Total Time": 604.229, "Startup Cost": 0, "Alias": "orders" }
medium
9
tpch
WITH grouped_orderkeys AS (SELECT DISTINCT l_orderkey FROM lineitem) SELECT l.l_orderkey, l.l_shipdate FROM lineitem l INNER JOIN orders o ON l.l_orderkey = o.o_orderkey INNER JOIN grouped_orderkeys g ON l.l_orderkey = g.l_orderkey
SELECT l.l_orderkey, l.l_shipdate FROM lineitem l WHERE EXISTS (SELECT 1 FROM orders o WHERE l.l_orderkey = o.o_orderkey)
14,566.972
10,253.646
{ "Plan Width": 8, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 5215.184, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1315276.1, "Actual Total Time": 13919.978, "Startup Cost": 572787.04, "Plans": [ { "Relation Name": "lin...
{ "Plan Width": 8, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 1220.699, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 913457.56, "Actual Total Time": 9600.629, "Startup Cost": 190700.88, "Plans": [ { "Relation Name": "line...
medium
10
tpch
SELECT t.o_orderstatus FROM orders t INNER JOIN (VALUES ('O'), ('F'), ('P')) AS v(val) ON t.o_orderstatus = v.val
SELECT o_orderstatus FROM orders WHERE o_orderstatus = ANY(ARRAY['O', 'F', 'P'])
3,535.676
1,530.834
{ "Plan Width": 2, "Actual Rows": 4500000, "Plan Rows": 67494, "Actual Startup Time": 6.232, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 146446.7, "Actual Total Time": 3332.54, "Startup Cost": 0.08, "Plans": [ { "Relation Name": "orders", "Pl...
{ "Relation Name": "orders", "Plan Width": 2, "Actual Rows": 4500000, "Plan Rows": 67494, "Actual Startup Time": 3.987, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 151396.16, "Actual Total Time": 1348.996, "Startup Cost": 0, "Alias": "orders" }
easy
11
tpch
select distinct l.l_suppkey from lineitem l where l.l_shipdate >= date '1995-01-01' and l.l_shipdate < date '1995-01-02' and not exists (select 1 from lineitem l2 where l2.l_suppkey = l.l_suppkey and l2.l_shipdate >= date '1995-01-01' and l2.l_shipdate < date '1995-01-02' and l2.l_returnflag = 'R');
select l.l_suppkey from lineitem l where l.l_shipdate >= date '1995-01-01' and l.l_shipdate < date '1995-01-02' group by l.l_suppkey having bool_and(l.l_returnflag <> 'R');
4,980.121
2,050.675
{ "Plan Width": 4, "Actual Rows": 3029, "Plan Rows": 6099, "Actual Startup Time": 4958.095, "Node Type": "Unique", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1260220.71, "Actual Total Time": 4960.728, "Startup Cost": 1260158.3, "Plans": [ { "Plan Width": 4, "Actual R...
{ "Plan Width": 4, "Actual Rows": 3029, "Plan Rows": 3050, "Actual Startup Time": 2027.591, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 607884.87, "Actual Total Time": 2030.153, "Startup Cost": 607755.72, "Plans": [ { "Plan ...
medium
12
tpch
WITH cutoff_date AS ( SELECT MIN(o_orderdate) AS min_date FROM orders ) SELECT r.o_orderkey, r.o_custkey, r.o_orderstatus, r.o_totalprice, r.o_orderdate, r.o_orderpriority, r.o_clerk, r.o_shippriority, r.o_comment FROM ( SELECT orders.*, ROW_NUMBER() OVER(ORDER BY...
WITH cutoff_date AS ( SELECT MIN(O_ORDERDATE) AS min_date FROM ORDERS ), latest_rows AS ( SELECT ORDERS.* FROM ORDERS WHERE O_ORDERDATE = (SELECT min_date FROM cutoff_date) ORDER BY O_ORDERDATE DESC, O_ORDERKEY DESC LIMIT 3 ) SELECT latest_rows.* FROM ...
1,834.488
828.508
{ "Plan Width": 107, "Actual Rows": 3, "Plan Rows": 623, "Actual Startup Time": 1811.547, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 269821.63, "Actual Total Time": 1811.551, "Startup Cost": 269820.07, "Plans": [ { "Plan Width": 107, "Actual Rows...
{ "Plan Width": 107, "Actual Rows": 3, "Plan Rows": 3, "Actual Startup Time": 808.51, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 134854.35, "Actual Total Time": 808.513, "Startup Cost": 134854.34, "Plans": [ { "Plan Width": 107, "Actual Rows": 3,...
medium
13
tpch
SELECT l_returnflag, l_linestatus FROM (SELECT l_returnflag, l_linestatus, ROW_NUMBER() OVER (ORDER BY l_orderkey ASC) as rn FROM lineitem) ranked WHERE rn = 1;
SELECT l.l_returnflag, l.l_linestatus FROM lineitem l ORDER BY l.l_orderkey ASC LIMIT 1;
12,780.307
0.082
{ "Plan Width": 4, "Actual Rows": 1, "Plan Rows": 89988, "Actual Startup Time": 102.452, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1216885.5, "Actual Total Time": 12758.87, "Startup Cost": 0.44, "Alias": "ranked", "Plans": [ { "Plan Width":...
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 0.055, "Node Type": "Limit", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 0.48, "Actual Total Time": 0.056, "Startup Cost": 0.44, "Plans": [ { "Relation Name": "lineitem", "Plan Width": 8, ...
easy
14
tpch
SELECT t.l_returnflag, x_agg.c AS "F", y_agg.c AS "O", z_agg.c AS "P" FROM (SELECT DISTINCT l.l_returnflag FROM lineitem l) t LEFT JOIN LATERAL (SELECT COUNT(*) AS c FROM lineitem l2 WHERE l2.l_returnflag = t.l_returnflag AND l2.l_linestatus = 'F') x_agg ON TRUE LEFT JOIN LATERAL (SELECT COUNT(*) AS c FROM lineitem l2 ...
SELECT l.l_returnflag, SUM((l.l_linestatus = 'F')::int) AS "F", SUM((l.l_linestatus = 'O')::int) AS "O", SUM((l.l_linestatus = 'P')::int) AS "P" FROM lineitem l GROUP BY l.l_returnflag
26,161.88
6,592.034
{ "Plan Width": 26, "Actual Rows": 3, "Plan Rows": 3, "Actual Startup Time": 12021.421, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 6073217.54, "Actual Total Time": 26141.033, "Startup Cost": 2399293.14, "Plans": [ { "Plan Width": 18, "Actu...
{ "Plan Width": 26, "Actual Rows": 3, "Plan Rows": 3, "Actual Startup Time": 6571.326, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 967246.71, "Actual Total Time": 6571.329, "Startup Cost": 967246.68, "Plans": [ { "Relation N...
medium
15
tpch
with sub as materialized (select l_extendedprice, l_shipdate from lineitem where l_shipdate <= current_timestamp) select sum(l_extendedprice * least(extract(epoch from (current_timestamp - l_shipdate)) / 60.0, 30) / 30) as t from sub;
select sum(l_extendedprice * least(extract(epoch from (current_timestamp - l_shipdate)) / 60.0, 30.0) / 30.0) as t from lineitem where l_shipdate <= current_timestamp;
17,971.034
11,328.785
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 17878.47, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 1417151.95, "Actual Total Time": 17878.471, "Startup Cost": 1417151.94, "Plans": [ { "Relation ...
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 11309.277, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 1057235.83, "Actual Total Time": 11309.278, "Startup Cost": 1057235.82, "Plans": [ { "Relation...
medium
16
tpch
SELECT li.l_orderkey, v.mindate AS minimum_date FROM lineitem li LEFT JOIN LATERAL ( SELECT MIN(mindate) AS mindate FROM (VALUES (li.l_shipdate), (li.l_commitdate), (li.l_receiptdate)) AS x(mindate) ) v ON true;
SELECT li.l_orderkey, CASE WHEN li.l_shipdate IS NULL AND li.l_commitdate IS NULL THEN li.l_receiptdate WHEN li.l_shipdate IS NULL AND li.l_receiptdate IS NULL THEN li.l_commitdate WHEN li.l_commitdate IS NULL AND li.l_receiptdate IS NULL THEN li.l_shipdate WHEN li.l_shipdate ...
26,725.222
3,620.935
{ "Plan Width": 8, "Actual Rows": 17996609, "Plan Rows": 17997578, "Actual Startup Time": 71.654, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1867171.13, "Actual Total Time": 26069.581, "Startup Cost": 0.05, "Plans": [ { "Relation Name": "lineite...
{ "Relation Name": "lineitem", "Plan Width": 8, "Actual Rows": 17996609, "Plan Rows": 17997578, "Actual Startup Time": 80.827, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 697328.56, "Actual Total Time": 2977.373, "Startup Cost": 0, "Alias": "li" }
medium
17
tpch
WITH numbered_data AS (SELECT o_orderdate, COUNT(o_orderkey) AS new_customers, ROW_NUMBER() OVER (ORDER BY o_orderdate) AS rn FROM orders GROUP BY o_orderdate), window_boundaries AS (SELECT nd_curr.o_orderdate AS current_dt, nd_curr.rn AS current_rn, nd_start.o_orderdate AS start_dt FROM numbered_data nd_curr LEFT JOIN...
WITH windowed_data AS (SELECT o_orderdate, COUNT(o_orderkey) AS new_customers, SUM(COUNT(o_orderkey)) OVER(ORDER BY o_orderdate ROWS BETWEEN 11 PRECEDING AND CURRENT ROW) AS running_cust_count, COUNT(*) OVER(ORDER BY o_orderdate ROWS UNBOUNDED PRECEDING) AS current_row_count FROM orders GROUP BY o_orderdate) SELECT o_o...
4,077.521
1,294.079
{ "Plan Width": 44, "Actual Rows": 2395, "Plan Rows": 236, "Actual Startup Time": 4031.078, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 440645.06, "Actual Total Time": 4031.185, "Startup Cost": 440644.47, "Plans": [ { "Plan Width": 20, "Actual Row...
{ "Plan Width": 36, "Actual Rows": 2395, "Plan Rows": 802, "Actual Startup Time": 1272.111, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 146051.16, "Actual Total Time": 1274.576, "Startup Cost": 145942.89, "Alias": "windowed_data", "Plans": [ { ...
hard
18
tpch
SELECT DISTINCT s_suppkey, TRUE AS has_nike_partner FROM (SELECT s.s_suppkey, s.s_name, COUNT(*) FILTER (WHERE s.s_name = 'Supplier#000000001') OVER (PARTITION BY s.s_suppkey) AS nike_per_supplier, COUNT(*) FILTER (WHERE s.s_name = 'Supplier#000000002') OVER (PARTITION BY s.s_suppkey) AS reebok_per_supplier FROM suppli...
SELECT s.s_suppkey, bool_or(s.s_name = 'Supplier#000000001') AS has_nike_partner FROM supplier s JOIN partsupp ps ON s.s_suppkey = ps.ps_suppkey GROUP BY s.s_suppkey HAVING COUNT(CASE WHEN s.s_name = 'Supplier#000000001' THEN 1 END) > 0 AND COUNT(CASE WHEN s.s_name = 'Supplier#000000002' THEN 1 END) = 0;
1,602.248
833.775
{ "Plan Width": 5, "Actual Rows": 1, "Plan Rows": 4000, "Actual Startup Time": 6.7940000000000005, "Node Type": "Unique", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 166954.39, "Actual Total Time": 1582.958, "Startup Cost": 0.72, "Plans": [ { "Plan Width": 5, "Actual ...
{ "Plan Width": 5, "Actual Rows": 1, "Plan Rows": 50, "Actual Startup Time": 5.482, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 119390.07, "Actual Total Time": 814.062, "Startup Cost": 0.72, "Plans": [ { "Plan Width": 30, ...
easy
19
tpch
SELECT t.* FROM lineitem t JOIN LATERAL ( SELECT count(*) AS cnt, sum(CASE WHEN t2.l_linenumber = 4 THEN 1 ELSE 0 END) AS s FROM lineitem t2 WHERE t2.l_orderkey = t.l_orderkey AND t2.l_partkey = t.l_partkey ) AS grp ON grp.cnt > 1 AND grp.s > 0;
SELECT t.* FROM lineitem AS t INNER JOIN ( SELECT l_orderkey, l_partkey FROM lineitem GROUP BY l_orderkey, l_partkey HAVING count(*) > 1 AND sum(CASE WHEN l_linenumber = 4 THEN 1 ELSE 0 END) > 0 ) AS tt ON tt.l_orderkey = t.l_orderkey AND tt.l_partkey = t.l_partkey;
46,498.001
16,782.248
{ "Plan Width": 117, "Actual Rows": 44, "Plan Rows": 17997578, "Actual Startup Time": 5520.438, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 168974682.86, "Actual Total Time": 46478.481, "Startup Cost": 9.33, "Plans": [ { "Relation Name": "lineite...
{ "Plan Width": 117, "Actual Rows": 44, "Plan Rows": 15, "Actual Startup Time": 2277.36, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 2927640.26, "Actual Total Time": 16762.815, "Startup Cost": 4.67, "Plans": [ { "Plan Width": 8, "Actual Rows...
easy
20
tpch
SELECT tick_lower, tick_upper, ltv_usdc, ltv_eth FROM (SELECT l.l_shipdate AS tick_lower, l.l_commitdate AS tick_upper, l.l_extendedprice AS ltv_usdc, l.l_quantity AS ltv_eth, ROW_NUMBER() OVER () AS rn FROM lineitem l) AS numbered WHERE rn BETWEEN 1 AND (SELECT COUNT(*) FROM lineitem);
SELECT l.l_shipdate AS tick_lower, l.l_commitdate AS tick_upper, l.l_extendedprice AS ltv_usdc, l.l_quantity AS ltv_eth FROM lineitem l;
14,207.421
3,772.424
{ "Plan Width": 21, "Actual Rows": 17996609, "Plan Rows": 89981, "Actual Startup Time": 3695.045, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1399284.09, "Actual Total Time": 13559.215, "Startup Cost": 387046.79, "Alias": "numbered", "Plans": [ { ...
{ "Relation Name": "lineitem", "Plan Width": 21, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 72.684, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 517340.48, "Actual Total Time": 3121.206, "Startup Cost": 0, "Alias": "l" }
medium
21
tpch
WITH ranked_plans AS (SELECT o.o_orderkey AS id, o.o_orderdate AS planeffectivedate, l.l_shipdate AS planeterminationdate, l.l_receiptdate AS enddate, ROW_NUMBER() OVER (PARTITION BY o.o_orderkey ORDER BY o.o_orderdate) AS rn FROM orders o JOIN lineitem l ON o.o_orderkey = l.l_orderkey), joined_plans AS (SELECT r1.id, ...
WITH plan_data AS (SELECT o.o_orderkey AS id, o.o_orderdate AS planeffectivedate, l.l_shipdate AS planeterminationdate, LEAD(o.o_orderdate, 1) OVER (PARTITION BY o.o_orderkey ORDER BY o.o_orderdate) AS next_plan_eff_date, l.l_receiptdate AS enddate FROM orders o JOIN lineitem l ON o.o_orderkey = l.l_orderkey) SELECT id...
61,910.071
31,033.217
{ "Plan Width": 52, "Actual Rows": 17996609, "Plan Rows": 8096623552, "Actual Startup Time": 49136.772, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 213149656.65, "Actual Total Time": 60840.4, "Startup Cost": 10509114.75, "Plans": [ { "Plan Width":...
{ "Plan Width": 52, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 18926.015, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 4368658.12, "Actual Total Time": 30185.854, "Startup Cost": 3738789.44, "Alias": "plan_data", "Plans": [ ...
hard
22
tpch
SELECT d.day, COUNT(DISTINCT t.o_custkey) FROM (SELECT DISTINCT date_trunc('day', o_orderdate) AS day FROM orders) AS d JOIN orders t ON date_trunc('day', t.o_orderdate) = d.day GROUP BY d.day
SELECT date_trunc('day', o_orderdate) AS day, COUNT(DISTINCT o_custkey) FROM orders GROUP BY date_trunc('day', o_orderdate)
8,267.078
4,683.618
{ "Plan Width": 16, "Actual Rows": 2406, "Plan Rows": 2406, "Actual Startup Time": 6873.775, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 978147.9, "Actual Total Time": 8231.854, "Startup Cost": 944376.99, "Plans": [ { "Plan ...
{ "Plan Width": 16, "Actual Rows": 2406, "Plan Rows": 2406, "Actual Startup Time": 3283.975, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 830585.66, "Actual Total Time": 4644.925, "Startup Cost": 796802.73, "Plans": [ { "Plan...
easy
23
tpch
SELECT p.p_name, (SELECT SUM(ps.ps_supplycost) FROM partsupp ps WHERE ps.ps_partkey = p.p_partkey) AS total FROM part p WHERE EXISTS (SELECT 1 FROM partsupp ps2 WHERE ps2.ps_partkey = p.p_partkey);
SELECT p.p_name, n.total FROM (SELECT SUM(ps.ps_supplycost) as total, ps.ps_partkey FROM partsupp ps GROUP BY ps.ps_partkey) n JOIN part p ON p.p_partkey = n.ps_partkey
2,897.451
1,494.049
{ "Plan Width": 65, "Actual Rows": 600000, "Plan Rows": 401125, "Actual Startup Time": 116.258, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 3544575, "Actual Total Time": 2844.028, "Startup Cost": 1.4, "Plans": [ { "Relation Name": "part", "P...
{ "Plan Width": 65, "Actual Rows": 600000, "Plan Rows": 401125, "Actual Startup Time": 5.8469999999999995, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 158278.19, "Actual Total Time": 1450.018, "Startup Cost": 0.85, "Plans": [ { "Plan Width": 36, ...
easy
24
tpch
SELECT * FROM lineitem l WHERE (SELECT COUNT(*) FROM lineitem l2 WHERE l2.l_orderkey = l.l_orderkey AND l2.l_returnflag = 'R') = 0;
WITH r_orders AS (SELECT DISTINCT l_orderkey FROM lineitem WHERE l_returnflag = 'R') SELECT l.* FROM lineitem l LEFT JOIN r_orders ro ON l.l_orderkey = ro.l_orderkey WHERE ro.l_orderkey IS NULL;
189,480.463
34,291.46
{ "Relation Name": "lineitem", "Plan Width": 117, "Actual Rows": 31858169, "Plan Rows": 299959, "Actual Startup Time": 88.978, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 813112310.78, "Actual Total Time": 187709.608, "Startup Cost": 0, "Alias": "l", "Pla...
{ "Plan Width": 117, "Actual Rows": 31858169, "Plan Rows": 1, "Actual Startup Time": 140.188, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 5755112.54, "Actual Total Time": 33048.663, "Startup Cost": 0.88, "Plans": [ { "Relation Name": "lineitem", ...
easy
25
tpch
SELECT * FROM supplier WHERE s_suppkey IN (SELECT l_suppkey FROM lineitem GROUP BY l_suppkey HAVING COUNT(*) = (SELECT MAX(order_count) FROM (SELECT COUNT(*) AS order_count FROM lineitem GROUP BY l_suppkey) AS counts))
SELECT s.* FROM supplier s JOIN (SELECT l_suppkey FROM (SELECT l_suppkey, RANK() OVER (ORDER BY COUNT(*) DESC) as rnk FROM lineitem GROUP BY l_suppkey) ranked WHERE rnk = 1) top_supplier ON s.s_suppkey = top_supplier.l_suppkey;
5,059.529
2,694.391
{ "Plan Width": 144, "Actual Rows": 1, "Plan Rows": 150, "Actual Startup Time": 3861.712, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 866032.76, "Actual Total Time": 5038.443, "Startup Cost": 432713.58, "Plans": [ { "Plan Width": 4, "Actual...
{ "Plan Width": 144, "Actual Rows": 1, "Plan Rows": 150, "Actual Startup Time": 2657.146, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 436376.48, "Actual Total Time": 2674.885, "Startup Cost": 434570.42, "Plans": [ { "Plan Width": 4, "Actual...
medium
26
tpch
SELECT l_returnflag, COUNT(*) AS count FROM lineitem GROUP BY l_returnflag ORDER BY l_returnflag LIMIT (SELECT COUNT(DISTINCT l_returnflag) FROM lineitem);
select l_returnflag, count(*) from lineitem group by l_returnflag
15,320.66
5,128.996
{ "Plan Width": 10, "Actual Rows": 3, "Plan Rows": 1, "Actual Startup Time": 15301.639, "Node Type": "Limit", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1169652.89, "Actual Total Time": 15301.642, "Startup Cost": 1169652.88, "Plans": [ { "Plan Width": 8, "Actual Rows...
{ "Plan Width": 10, "Actual Rows": 3, "Plan Rows": 3, "Actual Startup Time": 5110.161, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 607321.75, "Actual Total Time": 5110.163, "Startup Cost": 607321.72, "Plans": [ { "Relation N...
easy
27
tpch
SELECT v.visitor, c.unique_shops FROM (SELECT DISTINCT l_orderkey AS visitor FROM lineitem) v CROSS JOIN LATERAL (SELECT COUNT(*) AS unique_shops FROM (SELECT 1 FROM lineitem t2 WHERE t2.l_orderkey = v.visitor GROUP BY t2.l_suppkey) s) c ORDER BY c.unique_shops DESC;
SELECT l_orderkey AS visitor, cardinality(array_agg(DISTINCT l_suppkey)) AS unique_shops FROM lineitem GROUP BY l_orderkey ORDER BY unique_shops DESC;
26,547.724
12,270.745
{ "Plan Width": 12, "Actual Rows": 4500000, "Plan Rows": 405253, "Actual Startup Time": 25906.447, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 4668607.31, "Actual Total Time": 26314.993, "Startup Cost": 4667594.17, "Plans": [ { "Plan Width": 12, "...
{ "Plan Width": 8, "Actual Rows": 4500000, "Plan Rows": 405253, "Actual Startup Time": 11665.573, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 862322.13, "Actual Total Time": 12076.974, "Startup Cost": 861309, "Plans": [ { "Plan Width": 8, "Actual ...
medium
28
tpch
SELECT t.id, t.short_title, t.arr[1] AS classictax1, t.arr[2] AS classictax2, t.arr[3] AS classictax3, t.arr[4] AS classictax4 FROM ( SELECT p.p_partkey AS id, p.p_name AS short_title, ARRAY( SELECT ps.ps_supplycost FROM partsupp ps ...
SELECT p.p_partkey AS id, p.p_name AS short_title, MAX(CASE WHEN c.rnk = 1 THEN c.classictax END) AS classictax1, MAX(CASE WHEN c.rnk = 2 THEN c.classictax END) AS classictax2, MAX(CASE WHEN c.rnk = 3 THEN c.classictax END) AS classictax3, MAX(CASE WHEN c.rnk = 4 THEN c.classictax END) AS classi...
12,078.556
3,973.407
{ "Relation Name": "part", "Plan Width": 109, "Actual Rows": 600000, "Plan Rows": 600000, "Actual Startup Time": 130.623, "Node Type": "Index Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 20722196.27, "Actual Total Time": 12022.769, "Startup Cost": 0.42, "Alias": "p", "Plans...
{ "Plan Width": 165, "Actual Rows": 600000, "Plan Rows": 600000, "Actual Startup Time": 1366.583, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 554113.81, "Actual Total Time": 3909.191, "Startup Cost": 412736.27, "Plans": [ { ...
medium
29
tpch
SELECT MIN(l.l_shipdate) AS min_date, MAX(l.l_shipdate) AS max_date FROM customer AS c INNER JOIN orders AS o ON c.c_custkey = o.o_custkey INNER JOIN lineitem AS l ON o.o_orderkey = l.l_orderkey WHERE l.l_quantity IS NOT NULL;
SELECT MIN(l.l_shipdate) AS min_date, MAX(l.l_shipdate) AS max_date FROM lineitem l WHERE l.l_quantity IS NOT NULL AND EXISTS (SELECT 1 FROM orders o JOIN customer c ON o.o_custkey = c.c_custkey WHERE o.o_orderkey = l.l_orderkey);
17,094.238
12,861.882
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 17073.783, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 1218526.49, "Actual Total Time": 17073.788, "Startup Cost": 1218526.48, "Plans": [ { "Plan Wid...
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 12842.788, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 1367852.96, "Actual Total Time": 12842.793, "Startup Cost": 1367852.95, "Plans": [ { "Plan Wid...
easy
30
tpch
SELECT * FROM lineitem WHERE l_comment !~ '^image.*\.jpg$';
SELECT * FROM lineitem WHERE l_comment NOT LIKE 'image%.jpg'
12,728.496
3,605.56
{ "Relation Name": "lineitem", "Plan Width": 117, "Actual Rows": 17996609, "Plan Rows": 17994449, "Actual Startup Time": 80.879, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 562331.1, "Actual Total Time": 12040, "Startup Cost": 0, "Alias": "lineitem" }
{ "Relation Name": "lineitem", "Plan Width": 117, "Actual Rows": 17996609, "Plan Rows": 17994449, "Actual Startup Time": 78.897, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 562331.1, "Actual Total Time": 2962.221, "Startup Cost": 0, "Alias": "lineitem" }
medium
31
tpch
SELECT n.n_name, 'price' category, ROUND(avg(b.price), 1) price FROM nation n LEFT OUTER JOIN (SELECT l.l_extendedprice - 100.00 AS price, c.c_nationkey FROM lineitem l JOIN orders o ON l.l_orderkey = o.o_orderkey JOIN customer c ON o.o_custkey = c.c_custkey WHERE l.l_shipdate BETWEEN '1998-12-01' AND '1998-12-31') b O...
WITH filtered_lineitems AS (SELECT l.l_extendedprice - 100.00 AS price, c.c_nationkey FROM lineitem l JOIN orders o ON l.l_orderkey = o.o_orderkey JOIN customer c ON o.o_custkey = c.c_custkey WHERE l.l_shipdate BETWEEN '1998-12-01' AND '1998-12-31'), join_nation_lineitem AS (SELECT n.n_name, fl.price FROM nation n LEFT...
3,531.099
2,072.004
{ "Plan Width": 90, "Actual Rows": 25, "Plan Rows": 25, "Actual Startup Time": 3512.096, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 652675.13, "Actual Total Time": 3512.14, "Startup Cost": 652621.45, "Plans": [ { "Plan Widt...
{ "Plan Width": 90, "Actual Rows": 25, "Plan Rows": 25, "Actual Startup Time": 2050.875, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 652675.13, "Actual Total Time": 2050.919, "Startup Cost": 652621.45, "Plans": [ { "Plan Wid...
hard
32
tpch
SELECT i.* FROM lineitem i JOIN LATERAL (SELECT 1) l ON true;
select * from lineitem;
4,453.351
3,190.403
{ "Relation Name": "lineitem", "Plan Width": 117, "Actual Rows": 17996609, "Plan Rows": 17997578, "Actual Startup Time": 0.36, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 517352.78, "Actual Total Time": 3803.507, "Startup Cost": 0, "Alias": "i" }
{ "Relation Name": "lineitem", "Plan Width": 117, "Actual Rows": 17996609, "Plan Rows": 17997578, "Actual Startup Time": 0.015, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 517352.78, "Actual Total Time": 2489.967, "Startup Cost": 0, "Alias": "lineitem" }
easy
33
tpch
select * from lineitem where l_suppkey in (select l_suppkey from lineitem group by l_suppkey having count(distinct l_partkey) > 1) and l_partkey = 123;
with member_counts as (select l_suppkey, count(distinct l_partkey) as ext_id_count from lineitem group by l_suppkey) select t.* from lineitem t join member_counts mc on t.l_suppkey = mc.l_suppkey where mc.ext_id_count > 1 and t.l_partkey = 123;
63,256.894
43,293.651
{ "Plan Width": 117, "Actual Rows": 38, "Plan Rows": 10, "Actual Startup Time": 2648.081, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1782127.09, "Actual Total Time": 63237.717, "Startup Cost": 0.88, "Plans": [ { "Relation Name": "lineitem", ...
{ "Plan Width": 117, "Actual Rows": 38, "Plan Rows": 10, "Actual Startup Time": 442.674, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1782127.09, "Actual Total Time": 43274.251, "Startup Cost": 0.88, "Plans": [ { "Relation Name": "lineitem", ...
medium
34
tpch
select m.att as highest_attendance, m.att - (m.att * 0.15) as lowest_attendance, d.month from (select distinct extract(month from o_orderdate) as month from orders) d cross join lateral (select o_totalprice as att from orders o where extract(month from o_orderdate) = d.month order by o_totalprice desc limit 1) m;
select t.max_att as highest_attendance, t.max_att - (t.max_att * 0.15) as lowest_attendance, t.month from (select extract(month from o_orderdate) as month, max(o_totalprice) as max_att from orders group by extract(month from o_orderdate)) t;
10,964.996
1,989.231
{ "Plan Width": 48, "Actual Rows": 12, "Plan Rows": 2406, "Actual Startup Time": 2262.476, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 378219439.68, "Actual Total Time": 10945.667, "Startup Cost": 314153.76, "Plans": [ { "Plan Width": 8, "A...
{ "Plan Width": 72, "Actual Rows": 12, "Plan Rows": 2406, "Actual Startup Time": 1969.628, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 168341.76, "Actual Total Time": 1969.651, "Startup Cost": 168269.58, "Alias": "t", "Plans": [ { "Plan Width...
medium
35
tpch
WITH filter_list AS (SELECT unnest(ARRAY['RAIL','TRUCK','SHIP','AIR','MAIL','FOB','REG AIR','AIR FREIGHT']) AS shipmode) SELECT l.* FROM lineitem l JOIN filter_list f ON l.l_shipmode = f.shipmode
SELECT * FROM lineitem l WHERE l.l_shipmode IN ('RAIL','TRUCK','SHIP','AIR','MAIL','FOB','REG AIR','AIR FREIGHT')
12,472.449
5,084.57
{ "Plan Width": 117, "Actual Rows": 17996609, "Plan Rows": 719850, "Actual Startup Time": 213.588, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 614520.46, "Actual Total Time": 11805.983, "Startup Cost": 0.24, "Plans": [ { "Relation Name": "lineitem"...
{ "Relation Name": "lineitem", "Plan Width": 117, "Actual Rows": 17996609, "Plan Rows": 11879130, "Actual Startup Time": 72.28, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 697302.96, "Actual Total Time": 4428.263, "Startup Cost": 0, "Alias": "l" }
easy
36
tpch
SELECT Result, StartDate, EndDate, Games FROM ( SELECT o_orderstatus AS Result, MIN(o_orderdate) AS StartDate, MAX(o_orderdate) AS EndDate, COUNT(*) AS Games FROM ( SELECT GR.o_orderstatus, GR.o_orderdate, (SELECT COUNT...
WITH FilteredOrders AS ( SELECT o_orderdate, o_orderstatus FROM orders WHERE o_custkey = 4 ), GroupMarkers AS ( SELECT o_orderdate, o_orderstatus, CASE WHEN o_orderstatus <> LAG(o_orderstatus, 1, o_orderstatus) OVER (ORDER BY o_orderdate) THEN 1 ELSE 0 END AS is_n...
3,367.423
0.342
{ "Plan Width": 18, "Actual Rows": 1, "Plan Rows": 9, "Actual Startup Time": 3346.406, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 2668962.92, "Actual Total Time": 3346.408, "Startup Cost": 2668962.9, "Plans": [ { "Plan Width": 18, "Actual Rows": ...
{ "Plan Width": 26, "Actual Rows": 1, "Plan Rows": 9, "Actual Startup Time": 0.18, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 77.92, "Actual Total Time": 0.181, "Startup Cost": 77.9, "Plans": [ { "Plan Width": 26, "Actual Rows": 1, "Plan Ro...
hard
37
tpch
WITH pre_agg AS MATERIALIZED (SELECT p.p_type, l.l_quantity FROM part p JOIN lineitem l ON p.p_partkey = l.l_partkey) SELECT p_type, SUM(l_quantity) FROM pre_agg GROUP BY p_type;
SELECT p.p_type, SUM(l.l_quantity) AS sum FROM part p JOIN lineitem l ON p.p_partkey = l.l_partkey GROUP BY p.p_type;
19,115.519
13,291.28
{ "Plan Width": 100, "Actual Rows": 150, "Plan Rows": 200, "Actual Startup Time": 18968.333, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 1224228.66, "Actual Total Time": 18968.375, "Startup Cost": 1224226.16, "Plans": [ { "P...
{ "Plan Width": 53, "Actual Rows": 150, "Plan Rows": 150, "Actual Startup Time": 13272.417, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 864303.08, "Actual Total Time": 13272.456, "Startup Cost": 864301.2, "Plans": [ { "Plan ...
easy
38
tpch
SELECT DISTINCT l.l_orderkey FROM lineitem l JOIN lineitem l_prelim ON l.l_orderkey = l_prelim.l_orderkey AND l_prelim.l_returnflag = 'R' LEFT JOIN lineitem l_final ON l.l_orderkey = l_final.l_orderkey AND l_final.l_returnflag = 'N' WHERE l_final.l_orderkey IS NULL
SELECT l1.l_orderkey FROM lineitem l1 LEFT JOIN lineitem l2 ON l1.l_orderkey = l2.l_orderkey AND l2.l_returnflag = 'N' WHERE l1.l_returnflag = 'R' AND l2.l_orderkey IS NULL GROUP BY l1.l_orderkey
54,667.467
10,098.373
{ "Plan Width": 4, "Actual Rows": 1850743, "Plan Rows": 1, "Actual Startup Time": 51042.382, "Node Type": "Unique", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1406024.54, "Actual Total Time": 54458.987, "Startup Cost": 1406024.53, "Plans": [ { "Plan Width": 4, "Actua...
{ "Plan Width": 4, "Actual Rows": 1850743, "Plan Rows": 1, "Actual Startup Time": 9156.453, "Node Type": "Group", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1376315.21, "Actual Total Time": 9996.509, "Startup Cost": 1376315.21, "Plans": [ { "Plan Width": 4, "Actual R...
medium
39
tpch
WITH t AS ( SELECT l_shipdate, l_quantity, p_container FROM lineitem JOIN part ON lineitem.l_partkey = part.p_partkey WHERE p_name LIKE 'sienna%' AND l_shipdate >= '1995-02-15' AND l_shipdate <= '1995-03-01' AND l_shipmode = 'SHIP' AND l_linestatus = 'F' ), min_max_...
WITH t AS ( SELECT l_shipdate, l_quantity, p_container FROM lineitem JOIN part ON lineitem.l_partkey = part.p_partkey WHERE p_name LIKE 'sienna%' AND l_shipdate >= '1995-02-15' AND l_shipdate <= '1995-03-01' AND l_shipmode = 'SHIP' AND l_linestatus = 'F' ), base AS ...
8,540.853
1,079.412
{ "Plan Width": 176, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 8516.637, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 621587.53, "Actual Total Time": 8516.645, "Startup Cost": 621587.37, "Plans": [ { "Plan Width": 20, "Actual ...
{ "Plan Width": 176, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 1059.633, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 621580.31, "Actual Total Time": 1059.637, "Startup Cost": 621580.21, "Plans": [ { "Plan Width": 20, "Actual ...
hard
40
tpch
SELECT * FROM lineitem t1 WHERE t1.l_shipdate = (SELECT MAX(t2.l_shipdate) FROM lineitem t2 WHERE t2.l_orderkey = t1.l_orderkey);
SELECT t1.* FROM lineitem t1 INNER JOIN (SELECT l_orderkey, MAX(l_shipdate) AS max_shipdate FROM lineitem GROUP BY l_orderkey) t2 ON t1.l_orderkey = t2.l_orderkey AND t1.l_shipdate = t2.max_shipdate;
207,690.691
44,672.807
{ "Relation Name": "lineitem", "Plan Width": 117, "Actual Rows": 15240492, "Plan Rows": 299959, "Actual Startup Time": 138.849, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 807563077.79, "Actual Total Time": 206809.081, "Startup Cost": 0, "Alias": "t1", "P...
{ "Plan Width": 117, "Actual Rows": 15240492, "Plan Rows": 23911, "Actual Startup Time": 213.899, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 6021732.41, "Actual Total Time": 44050.475, "Startup Cost": 0.88, "Plans": [ { "Plan Width": 8, "Ac...
medium
41
tpch
WITH DATA AS MATERIALIZED ( SELECT o_orderpriority, o_clerk, o_comment FROM orders WHERE o_orderkey > 0 AND o_orderstatus = 'O' AND NOT o_comment = 'string' ) SELECT o_orderpriority, o_clerk, CASE WHEN o_comment IS NULL THEN 'other_string' WHEN o_comment = 'another_value' THEN 's...
SELECT t.o_orderpriority, t.o_clerk, CASE WHEN t.o_comment IS NULL THEN 'other_string' WHEN t.o_comment = 'another_value' THEN 'some_string' ELSE 'default' END FROM orders t WHERE t.o_orderkey > 0 AND t.o_orderstatus = 'O' AND t.o_comment <> 'string'
2,042.329
950.246
{ "Plan Width": 160, "Actual Rows": 2192938, "Plan Rows": 2174646, "Actual Startup Time": 5.909, "Node Type": "CTE Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 205950.17, "Actual Total Time": 1911.892, "Startup Cost": 157020.63, "Alias": "data", "Plans": [ { "Relati...
{ "Relation Name": "orders", "Plan Width": 64, "Actual Rows": 2192938, "Plan Rows": 2174646, "Actual Startup Time": 5.321, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 162457.25, "Actual Total Time": 850.912, "Startup Cost": 0, "Alias": "t" }
medium
42
tpch
WITH t_data AS MATERIALIZED (SELECT * FROM lineitem) SELECT * FROM t_data;
SELECT * FROM lineitem
8,247.222
2,633.83
{ "Plan Width": 370, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 0.195, "Node Type": "CTE Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 877265.44, "Actual Total Time": 7240.791, "Startup Cost": 517340.48, "Alias": "t_data", "Plans": [ { "Re...
{ "Relation Name": "lineitem", "Plan Width": 117, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 0.018000000000000002, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 517340.48, "Actual Total Time": 1986.045, "Startup Cost": 0, "Alias": ...
easy
43
tpch
SELECT * FROM customer ORDER BY (c_mktsegment = 'AUTOMOBILE' OR c_mktsegment = 'BUILDING') DESC, (c_mktsegment = 'FURNITURE') DESC, (c_mktsegment = 'MACHINERY') DESC, (c_mktsegment = 'HOUSEHOLD') DESC;
SELECT * FROM customer ORDER BY (CASE WHEN c_mktsegment = 'AUTOMOBILE' OR c_mktsegment = 'BUILDING' THEN 1 WHEN c_mktsegment = 'FURNITURE' THEN 2 WHEN c_mktsegment = 'MACHINERY' THEN 3 WHEN c_mktsegment = 'HOUSEHOLD' THEN 4 ELSE 5 END);
1,044.716
550.619
{ "Plan Width": 163, "Actual Rows": 450000, "Plan Rows": 450000, "Actual Startup Time": 695.622, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 138083.02, "Actual Total Time": 961.976, "Startup Cost": 136958.02, "Plans": [ { "Relation Name": "customer", ...
{ "Plan Width": 163, "Actual Rows": 450000, "Plan Rows": 450000, "Actual Startup Time": 400.047, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 138083.02, "Actual Total Time": 475.254, "Startup Cost": 136958.02, "Plans": [ { "Relation Name": "customer", ...
easy
44
tpch
SELECT o.array1, o.array2, (SELECT COALESCE(SUM((SELECT count(*) FROM jsonb_array_elements_text(to_jsonb(o.array2)) b(el2) WHERE b.el2 = a.el1)), 0) > 1 FROM jsonb_array_elements_text(to_jsonb(o.array1)) a(el1) ) FROM ( SELECT orders.o_orderkey, array_agg(lineitem.l_partkey) AS array1, ...
SELECT o.array1, o.array2, (SELECT COALESCE(SUM(cardinality(array_positions(o.array2, el1))), 0) > 1 FROM unnest(o.array1) a1(el1) ) FROM ( SELECT orders.o_orderkey, array_agg(lineitem.l_partkey) AS array1, array_agg(lineitem.l_suppkey) AS array2 FROM orders JOIN lineitem O...
56,985.317
25,746.186
{ "Plan Width": 65, "Actual Rows": 4500000, "Plan Rows": 4499579, "Actual Startup Time": 155.414, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 577358593.13, "Actual Total Time": 56660.209, "Startup Cost": 18.98, "Alias": "o", "Plans": [ { "Pla...
{ "Plan Width": 65, "Actual Rows": 4500000, "Plan Rows": 4499579, "Actual Startup Time": 128.444, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 2177409.56, "Actual Total Time": 25543.41, "Startup Cost": 18.98, "Alias": "o", "Plans": [ { "Plan W...
hard
45
tpch
WITH DistinctRawTagStrings AS (SELECT DISTINCT trim(both '[]' from (l_comment)) AS cleaned_tags_string FROM lineitem WHERE l_comment IS NOT NULL AND trim(both '[]' from (l_comment)) != ''), UnnestedDistinctTagValues AS (SELECT cleaned_tags_string, unnest(string_to_array(cleaned_tags_string, ',')) AS tag_value FROM Dist...
SELECT d.*, unnested_tag.tag_value AS tag FROM lineitem d CROSS JOIN LATERAL (SELECT unnest(string_to_array(trim(both '[]' from (d.l_comment)), ',')) AS tag_value) AS unnested_tag;
68,993.316
26,056.143
{ "Plan Width": 149, "Actual Rows": 19719920, "Plan Rows": 17996248, "Actual Startup Time": 38656.155, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 4650576.75, "Actual Total Time": 68096.015, "Startup Cost": 2713272.97, "Plans": [ { "Relation Name":...
{ "Plan Width": 149, "Actual Rows": 19719920, "Plan Rows": 179962480, "Actual Startup Time": 119.487, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 5421318.06, "Actual Total Time": 25322.529, "Startup Cost": 0, "Plans": [ { "Relation Name": "lineit...
hard
46
tpch
WITH grouped_exams AS MATERIALIZED ( SELECT l.l_orderkey, p.p_name, COUNT(*) AS test_count FROM lineitem l JOIN part p ON l.l_partkey = p.p_partkey GROUP BY l.l_orderkey, p.p_name ) SELECT l_orderkey, p_name, test_count FROM grouped_exams ORDER BY l_orderkey, p_name;
SELECT l.l_orderkey, p.p_name, COUNT(*) AS test_count FROM lineitem l JOIN part p ON l.l_partkey = p.p_partkey GROUP BY l.l_orderkey, p.p_name ORDER BY l.l_orderkey, p.p_name;
49,871.157
30,819.739
{ "Plan Width": 140, "Actual Rows": 17996548, "Plan Rows": 17996248, "Actual Startup Time": 44772.07, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 11035782.77, "Actual Total Time": 48667.707, "Startup Cost": 10990792.15, "Plans": [ { "Plan Width": 45, ...
{ "Plan Width": 45, "Actual Rows": 17996548, "Plan Rows": 17996248, "Actual Startup Time": 20208.001, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 4745180.14, "Actual Total Time": 30017.332, "Startup Cost": 4385255.18, "Plans": [ {...
medium
47
tpch
WITH ActiveCounts AS (SELECT o.o_orderdate, SUM(CASE WHEN o.o_orderstatus = 'O' THEN 1 ELSE 0 END) AS active_ids_count FROM orders o GROUP BY o.o_orderdate), ActiveLists AS (SELECT o.o_orderdate, STRING_AGG(CASE WHEN o.o_orderstatus = 'O' THEN o.o_orderkey::TEXT END, ',' ORDER BY o.o_orderkey) AS listagg_active_ids, ST...
SELECT o.o_orderdate AS "Some Date", SUM(CASE WHEN o.o_orderstatus = 'O' THEN 1 ELSE 0 END) AS "active id numbers", STRING_AGG(CASE WHEN o.o_orderstatus = 'O' THEN o.o_orderkey::TEXT END, ',' ORDER BY o.o_orderkey) AS "Listagg List of active id numbers", STRING_AGG(CASE WHEN o.o_orderstatus = 'O' THEN o.o_orderkey::TEX...
5,914.558
4,637.903
{ "Plan Width": 76, "Actual Rows": 2406, "Plan Rows": 28944, "Actual Startup Time": 3583.797, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1044124.08, "Actual Total Time": 5873.682, "Startup Cost": 931547.98, "Plans": [ { "Plan Width": 68, "Ac...
{ "Plan Width": 76, "Actual Rows": 2406, "Plan Rows": 2406, "Actual Startup Time": 2182.823, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 909482.63, "Actual Total Time": 4602.551, "Startup Cost": 774435.14, "Plans": [ { "Plan...
medium
48
tpch
SELECT * FROM lineitem ORDER BY (10 - l_quantity) ASC
SELECT * FROM lineitem ORDER BY l_quantity DESC
52,921.413
27,830.758
{ "Plan Width": 149, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 44738.761, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 6835686.44, "Actual Total Time": 49848.281, "Startup Cost": 6790695.82, "Plans": [ { "Relation Name": "lin...
{ "Plan Width": 117, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 23077.952, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 6052566.82, "Actual Total Time": 26746.366, "Startup Cost": 6007576.2, "Plans": [ { "Relation Name": "line...
medium
49
tpch
SELECT n_name, nation_count AS max_dep FROM (SELECT n.n_name, COUNT(*) AS nation_count FROM customer c JOIN nation n ON c.c_nationkey = n.n_nationkey GROUP BY n.n_name) main WHERE NOT EXISTS (SELECT 1 FROM customer c2 JOIN nation n2 ON c2.c_nationkey = n2.n_nationkey WHERE n2.n_name <> main.n_name GROUP BY n2.n_name HA...
WITH nation_counts AS (SELECT n.n_name, COUNT(*) AS nation_count FROM customer c JOIN nation n ON c.c_nationkey = n.n_nationkey GROUP BY n.n_name), ranked_nations AS (SELECT n_name, nation_count, FIRST_VALUE(nation_count) OVER (ORDER BY nation_count DESC) AS max_count FROM nation_counts) SELECT n_name, nation_count AS ...
5,087.704
199.271
{ "Plan Width": 34, "Actual Rows": 1, "Plan Rows": 12, "Actual Startup Time": 1382.233, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 306515.3, "Actual Total Time": 5067.544, "Startup Cost": 11875.49, "Alias": "main", "Plans": [ { "Plan Width":...
{ "Plan Width": 34, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 199.117, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 11877.32, "Actual Total Time": 199.14, "Startup Cost": 11876.57, "Alias": "ranked_nations", "Plans": [ { "Plan W...
medium
50
tpch
select c.c_custkey, c.c_name from customer c except select c2.c_custkey, c2.c_name from customer c2 join orders o on c2.c_custkey = o.o_custkey
select c.c_custkey, c.c_name from customer c where not exists(select 1 from orders o where o.o_custkey = c.c_custkey)
5,483.612
940.032
{ "Plan Width": 76, "Actual Rows": 150006, "Plan Rows": 450000, "Actual Startup Time": 4373.773, "Node Type": "SetOp", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 1280295.46, "Actual Total Time": 5422.427, "Startup Cost": 1243167.61, "Plans": [ { "Pl...
{ "Plan Width": 23, "Actual Rows": 150006, "Plan Rows": 191471, "Actual Startup Time": 3.658, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 169974, "Actual Total Time": 914.399, "Startup Cost": 0.85, "Plans": [ { "Relation Name": "customer", "...
easy
51
tpch
WITH aggregated_dates AS ( SELECT o.o_custkey, c.c_name, c.c_nationkey, ARRAY_AGG(o.o_orderdate ORDER BY o.o_orderdate) AS date_array FROM orders o JOIN customer c ON o.o_custkey = c.c_custkey GROUP BY o.o_custkey, c.c_name, c.c_nationkey ), expanded_dates AS ( SELECT o_custkey, c_name, c_nationkey, date_value, ordinal...
WITH numbered_data AS ( SELECT o.o_orderkey, o.o_custkey, o.o_orderdate, c.c_name, c.c_nationkey, ROW_NUMBER() OVER (PARTITION BY o.o_custkey, c.c_name, c.c_nationkey ORDER BY o.o_orderdate) as seqnum FROM orders o JOIN customer c on o.o_custkey = c.c_custkey ) SELECT o_custkey, c_name, c_nationkey, MIN(o_orderdate), M...
21,153.584
13,271.84
{ "Plan Width": 43, "Actual Rows": 4470952, "Plan Rows": 4499580, "Actual Startup Time": 257.054, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 5914665.93, "Actual Total Time": 20901.871, "Startup Cost": 35.51, "Plans": [ { "P...
{ "Plan Width": 43, "Actual Rows": 4470952, "Plan Rows": 4499579, "Actual Startup Time": 5924.352, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 1449764.82, "Actual Total Time": 12999.103, "Startup Cost": 909815.39, "Plans": [ { ...
hard
52
tpch
SELECT c.c_name, o.o_totalprice FROM orders o JOIN customer c ON o.o_custkey = c.c_custkey WHERE o.o_orderpriority = '1-URGENT' AND o.o_orderstatus IN ('F', 'P') AND NOT EXISTS ( SELECT 1 FROM orders o2 WHERE o2.o_orderpriority = '1-URGENT' AND o2.o_orderstatus IN ('F', 'P') AND o2.o_totalprice > o....
SELECT c.c_name, o.o_totalprice FROM orders o JOIN customer c ON o.o_custkey = c.c_custkey JOIN ( SELECT MAX(o2.o_totalprice) AS max_price FROM orders o2 WHERE o2.o_orderpriority = '1-URGENT' AND o2.o_orderstatus IN ('F', 'P') ) mx ON o.o_totalprice = mx.max_price WHERE o.o_orderpriority = '1-URGENT' AND o....
4,336.273
1,715.432
{ "Plan Width": 27, "Actual Rows": 1, "Plan Rows": 307223, "Actual Startup Time": 1911.932, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 2677456351.9, "Actual Total Time": 4314.499, "Startup Cost": 0.42, "Plans": [ { "Plan Width": 12, "Actua...
{ "Plan Width": 27, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 1076.962, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 293929.75, "Actual Total Time": 1697.558, "Startup Cost": 146936.24, "Plans": [ { "Plan Width": 12, "Actual R...
medium
53
tpch
SELECT t.l_orderkey, t.l_partkey, t.l_quantity FROM ( SELECT l_orderkey AS l_orderkey, l_partkey AS l_partkey, l_quantity AS l_quantity, ROW_NUMBER() OVER (PARTITION BY l_orderkey ORDER BY l_quantity DESC) AS xcol FROM lineitem ) t WHERE t.xcol = 1
SELECT DISTINCT ON (l_orderkey) l_orderkey, l_partkey, l_quantity FROM lineitem ORDER BY l_orderkey, l_quantity DESC
22,165.26
14,616.33
{ "Plan Width": 13, "Actual Rows": 4500000, "Plan Rows": 89981, "Actual Startup Time": 11389.736, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 3885984.76, "Actual Total Time": 21898.852, "Startup Cost": 3301106.7, "Alias": "t", "Plans": [ { "P...
{ "Plan Width": 13, "Actual Rows": 4500000, "Plan Rows": 388805, "Actual Startup Time": 11317.195, "Node Type": "Unique", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 3391087.94, "Actual Total Time": 14356.632, "Startup Cost": 3301106.7, "Plans": [ { "Plan Width": 13, ...
hard
54
tpch
SELECT sub.l_extendedprice AS original, sub.l_linenumber AS id, sub.l_extendedprice AS revenue, sub.l_discount AS predicted FROM (SELECT l.*, MAX(l_extendedprice) OVER () AS max_original FROM lineitem l) sub WHERE sub.l_extendedprice = sub.max_original;
SELECT l_extendedprice AS original, l_linenumber AS id, l_extendedprice AS revenue, l_discount AS predicted FROM lineitem WHERE l_extendedprice = (SELECT MAX(l_extendedprice) FROM lineitem);
13,306.978
7,389.018
{ "Plan Width": 24, "Actual Rows": 1, "Plan Rows": 89988, "Actual Startup Time": 9381.194, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 967292.23, "Actual Total Time": 13288.574, "Startup Cost": 0, "Alias": "sub", "Plans": [ { "Plan Width": 37...
{ "Relation Name": "lineitem", "Plan Width": 24, "Actual Rows": 1, "Plan Rows": 21, "Actual Startup Time": 4833.192, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1124693.46, "Actual Total Time": 7370.059, "Startup Cost": 562346.73, "Alias": "lineitem", "Pl...
easy
55
tpch
SELECT t.c_custkey, COUNT(*) AS totalsentlast180days FROM ( SELECT c.c_custkey FROM lineitem l INNER JOIN orders o ON l.l_orderkey = o.o_orderkey INNER JOIN customer c ON o.o_custkey = c.c_custkey INNER JOIN nation n ON c.c_nationkey = n.n_nationkey WHERE n.n_...
SELECT c.c_custkey, COUNT(*) AS totalsentlast180days FROM lineitem l JOIN orders o ON l.l_orderkey = o.o_orderkey JOIN customer c ON o.o_custkey = c.c_custkey WHERE l.l_shipdate >= DATE '1998-12-31' - INTERVAL '180 days' AND EXISTS ( SELECT 1 FROM nation n WHERE n.n_nationkey = c.c_nationkey AND n.n...
4,462.74
3,531.885
{ "Plan Width": 12, "Actual Rows": 12593, "Plan Rows": 56318, "Actual Startup Time": 4433.062, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 659671.32, "Actual Total Time": 4443.405, "Startup Cost": 658685.75, "Plans": [ { "Pl...
{ "Plan Width": 12, "Actual Rows": 12593, "Plan Rows": 56318, "Actual Startup Time": 3500.615, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 659671.32, "Actual Total Time": 3511.516, "Startup Cost": 658685.75, "Plans": [ { "Pl...
medium
56
tpch
SELECT array_to_string(REGEXP_MATCHES(REPLACE(p_name, ' ', '.'), '(?:[^.]+\.){3}([^.]+)(?:\.|$)'), '') AS col1 FROM part
SELECT SPLIT_PART(REPLACE(p_name, ' ', '.'), '.', 4) AS col1 FROM part
3,386.518
324.806
{ "Plan Width": 32, "Actual Rows": 600000, "Plan Rows": 600000, "Actual Startup Time": 0.41400000000000003, "Node Type": "Result", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 37789, "Actual Total Time": 3352.031, "Startup Cost": 0, "Plans": [ { "Plan Width": 32, "Actu...
{ "Relation Name": "part", "Plan Width": 32, "Actual Rows": 600000, "Plan Rows": 600000, "Actual Startup Time": 0.044, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 21289, "Actual Total Time": 303.301, "Startup Cost": 0, "Alias": "part" }
easy
57
tpch
select s1.s_suppkey as seller_id from (select distinct * from lineitem) l1 join supplier s1 on l1.l_suppkey = s1.s_suppkey group by s1.s_suppkey having sum(l1.l_extendedprice * (1 - l1.l_discount)) >= all (select sum(l2.l_extendedprice * (1 - l2.l_discount)) from (select distinct * from lineitem) l2 join supplier s2 on...
with x as (select s.s_suppkey as seller_id, sum(l.l_extendedprice * (1 - l.l_discount)) as total from (select distinct * from lineitem) l join supplier s on l.l_suppkey = s.s_suppkey group by s.s_suppkey ) select seller_id from x where total = (select max(total) from x);
408,564.763
211,990.943
{ "Plan Width": 4, "Actual Rows": 1, "Plan Rows": 50000, "Actual Startup Time": 386409.4, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 3116225178.68, "Actual Total Time": 407413.235, "Startup Cost": 47688130.56, "Plans": [ { ...
{ "Plan Width": 4, "Actual Rows": 1, "Plan Rows": 500, "Actual Startup Time": 210877.673, "Node Type": "CTE Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 23714821.25, "Actual Total Time": 210881.159, "Startup Cost": 23712571.25, "Alias": "x", "Plans": [ { "Plan Width...
medium
58
tpch
WITH ranked_values AS (SELECT l_orderkey, l_comment, DENSE_RANK() OVER (PARTITION BY l_orderkey ORDER BY l_comment) as rank_val FROM lineitem), aggregated AS (SELECT l_orderkey, STRING_AGG(l_comment, ',' ORDER BY rank_val) AS output_val FROM ranked_values GROUP BY l_orderkey) SELECT l_orderkey, output_val FROM aggregat...
SELECT l_orderkey, STRING_AGG(l_comment, ',' ORDER BY l_comment) AS output_val FROM lineitem GROUP BY l_orderkey
36,659.743
17,220.624
{ "Plan Width": 36, "Actual Rows": 4500000, "Plan Rows": 388805, "Actual Startup Time": 14960.339, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 4612455.44, "Actual Total Time": 36367.005, "Startup Cost": 3977726.7, "Plans": [ { ...
{ "Plan Width": 36, "Actual Rows": 4500000, "Plan Rows": 388805, "Actual Startup Time": 125.187, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 816774.46, "Actual Total Time": 17024.24, "Startup Cost": 0.44, "Plans": [ { "Relat...
medium
59
tpch
SELECT o_orderkey, o_custkey FROM (SELECT o_orderkey, o_custkey, ROW_NUMBER() OVER () as rn FROM orders) t WHERE rn % 1 = 0;
SELECT o_orderkey, o_custkey FROM orders WHERE true;
2,519.636
675.958
{ "Plan Width": 8, "Actual Rows": 4500000, "Plan Rows": 22502, "Actual Startup Time": 3.7119999999999997, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 247042.25, "Actual Total Time": 2331.716, "Startup Cost": 0, "Alias": "t", "Plans": [ { "Pla...
{ "Relation Name": "orders", "Plan Width": 8, "Actual Rows": 4500000, "Plan Rows": 4500380, "Actual Startup Time": 2.451, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 123281.8, "Actual Total Time": 499.287, "Startup Cost": 0, "Alias": "orders" }
medium
60
tpch
WITH CalculatedStays AS (SELECT c.c_name AS nomehospede, l.l_extendedprice AS somadiarias FROM lineitem l JOIN orders o ON l.l_orderkey = o.o_orderkey JOIN customer c ON o.o_custkey = c.c_custkey), ClassRanges (limite_superior, classe) AS (VALUES (1000, 'E'), (3000, 'D'), (7000, 'C'), (10000, 'B'), (NULL, 'A')) SELECT ...
SELECT c.c_name AS nomehospede, l.l_extendedprice AS somadiarias, CASE WHEN l.l_extendedprice <= 1000 THEN 'E' WHEN l.l_extendedprice <= 3000 THEN 'D' WHEN l.l_extendedprice <= 7000 THEN 'C' WHEN l.l_extendedprice <= 10000 THEN 'B' ELSE 'A' END AS classe FROM lineitem l JOIN orders o ON l.l_orderkey = o.o_orderkey JOIN...
68,289.078
24,575.762
{ "Plan Width": 59, "Actual Rows": 17996609, "Plan Rows": 17997578, "Actual Startup Time": 1509.743, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 3363887.44, "Actual Total Time": 67607.932, "Startup Cost": 220607.63, "Plans": [ { "Plan Width": 27,...
{ "Plan Width": 59, "Actual Rows": 17996609, "Plan Rows": 17997578, "Actual Startup Time": 1821.071, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1384153.86, "Actual Total Time": 23891.439, "Startup Cost": 220607.53, "Plans": [ { "Plan Width": 12, ...
medium
61
tpch
SELECT CASE WHEN EXISTS ( SELECT p_partkey FROM part EXCEPT SELECT ps_partkey FROM partsupp UNION ALL SELECT ps_partkey FROM partsupp EXCEPT SELECT p_partkey FROM part ) THEN 'false' ELSE 'true' END AS result
SELECT CASE WHEN EXISTS ( SELECT 1 FROM part p FULL OUTER JOIN partsupp ps ON p.p_partkey = ps.ps_partkey WHERE p.p_partkey IS NULL OR ps.ps_partkey IS NULL ) THEN 'false' ELSE 'true' END AS result
3,988.229
530.091
{ "Plan Width": 32, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 3950.596, "Node Type": "Result", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1186498.84, "Actual Total Time": 3950.603, "Startup Cost": 1186498.83, "Plans": [ { "Plan Width": 8, "Actual Rows"...
{ "Plan Width": 32, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 530.012, "Node Type": "Result", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 97614.54, "Actual Total Time": 530.012, "Startup Cost": 97614.53, "Plans": [ { "Plan Width": 0, "Actual Rows": 0, ...
medium
62
tpch
SELECT (SELECT count(*) FROM orders) as my_val, (SELECT count(*) FROM orders) / 2 as half, (SELECT count(*) FROM orders) * 2 as doubleit
SELECT count(*) as my_val, count(*) / 2 as half, count(*) * 2 as doubleit FROM orders
2,145.744
718.045
{ "Plan Width": 24, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 2124.865, "Node Type": "Result", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 304203.29, "Actual Total Time": 2124.868, "Startup Cost": 304203.28, "Plans": [ { "Plan Width": 8, "Actual Rows": ...
{ "Plan Width": 24, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 699.256, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 123903, "Actual Total Time": 699.257, "Startup Cost": 123902.98, "Plans": [ { "Relation Name": ...
easy
63
tpch
WITH RECURSIVE ranked_flags AS (SELECT l_returnflag, ROW_NUMBER() OVER (PARTITION BY l_returnflag ORDER BY ctid) AS rn FROM lineitem WHERE l_shipmode = 'REG AIR') SELECT l_returnflag FROM ranked_flags WHERE rn = 1 ORDER BY l_returnflag
SELECT l_returnflag FROM lineitem WHERE l_shipmode = 'REG AIR' GROUP BY GROUPING SETS ((l_returnflag)) ORDER BY l_returnflag
7,372.966
3,144.242
{ "Plan Width": 2, "Actual Rows": 3, "Plan Rows": 12549, "Actual Startup Time": 5785.084, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 979326.8, "Actual Total Time": 7347.038, "Startup Cost": 897755.8, "Alias": "ranked_flags", "Plans": [ { "Pl...
{ "Plan Width": 2, "Actual Rows": 3, "Plan Rows": 3, "Actual Startup Time": 3125.582, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 568605.85, "Actual Total Time": 3125.583, "Startup Cost": 568605.85, "Plans": [ { "Plan Width": 2, "Actual Rows": 3, ...
easy
64
tpch
select category, ratio from (select l_shipmode as category, sum(case when l_returnflag = 'R' then 1 else 0 end) over (partition by l_shipmode)::double precision / count(*) over (partition by l_shipmode)::double precision as ratio, row_number() over (partition by l_shipmode order by l_shipmode) as rn from lineitem) s wh...
select l_shipmode as category, (count(*) filter (where l_returnflag = 'R'))::double precision / count(*)::double precision as ratio from lineitem group by l_shipmode order by l_shipmode;
48,111.352
7,064.33
{ "Plan Width": 19, "Actual Rows": 7, "Plan Rows": 89988, "Actual Startup Time": 16320.232, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 4381185.54, "Actual Total Time": 48030.378, "Startup Cost": 3301330.86, "Alias": "s", "Plans": [ { "Plan W...
{ "Plan Width": 19, "Actual Rows": 7, "Plan Rows": 7, "Actual Startup Time": 7045.011, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 697328.8, "Actual Total Time": 7045.012, "Startup Cost": 697328.78, "Plans": [ { "Plan Width": 19, "Actual Rows": 7,...
easy
65
tpch
select c.c_custkey, c.c_name from customer c join (select c2.c_custkey from customer c2 except select o.o_custkey from orders o) d on c.c_custkey = d.c_custkey;
select c.c_custkey, c.c_name from orders o right join customer c on c.c_custkey = o.o_custkey where o.o_custkey is null;
3,562.425
909.751
{ "Plan Width": 23, "Actual Rows": 150006, "Plan Rows": 450000, "Actual Startup Time": 2563.458, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 920231.87, "Actual Total Time": 3518.504, "Startup Cost": 861786.98, "Plans": [ { "Relation Name": "custom...
{ "Plan Width": 23, "Actual Rows": 150006, "Plan Rows": 198889, "Actual Startup Time": 3.582, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 169955.28, "Actual Total Time": 884.766, "Startup Cost": 6.24, "Plans": [ { "Relation Name": "customer", ...
easy
66
tpch
SELECT id, (SELECT COUNT(*) FROM orders o2 WHERE o2.o_orderkey = t1.id AND o2.o_orderstatus = 'F') AS "Count Enabled", (SELECT COUNT(*) FROM orders o2 WHERE o2.o_orderkey = t1.id AND o2.o_orderstatus = 'O') AS "Count Disabled" FROM (SELECT DISTINCT o_orderkey AS id FROM orders) t1 ORDER BY id;
SELECT o.o_orderkey AS id, COUNT(CASE WHEN o.o_orderstatus = 'F' THEN 1 END) AS "Count Enabled", COUNT(CASE WHEN o.o_orderstatus = 'O' THEN 1 END) AS "Count Disabled" FROM orders o GROUP BY o.o_orderkey ORDER BY o.o_orderkey;
21,679.176
2,628.968
{ "Plan Width": 20, "Actual Rows": 4500000, "Plan Rows": 4500380, "Actual Startup Time": 118.214, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 76364554.28, "Actual Total Time": 21406.948, "Startup Cost": 0.43, "Alias": "t1", "Plans": [ { "Plan...
{ "Plan Width": 20, "Actual Rows": 4500000, "Plan Rows": 4500380, "Actual Startup Time": 5.038, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 296405.68, "Actual Total Time": 2451.109, "Startup Cost": 0.43, "Plans": [ { "Relati...
easy
67
tpch
SELECT DISTINCT l_partkey, l_suppkey FROM ( SELECT l_partkey, l_suppkey, COUNT(l_partkey) OVER (PARTITION BY l_partkey, l_suppkey) AS occurrence_count FROM lineitem ) AS sub WHERE sub.occurrence_count > 1;
SELECT l_partkey, l_suppkey FROM lineitem GROUP BY l_partkey, l_suppkey HAVING COUNT(*) > 1;
12,618.537
4,903.898
{ "Plan Width": 8, "Actual Rows": 2389062, "Plan Rows": 1768417, "Actual Startup Time": 89.66, "Node Type": "Unique", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 961529.34, "Actual Total Time": 12468.886, "Startup Cost": 0.44, "Plans": [ { "Plan Width": 8, "Actual Row...
{ "Plan Width": 8, "Actual Rows": 2389062, "Plan Rows": 599875, "Actual Startup Time": 67.48, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 549115.33, "Actual Total Time": 4801.567, "Startup Cost": 0.44, "Plans": [ { "Relation...
easy
68
tpch
SELECT to_timestamp(sub.avg_s)::date AS avg_date FROM lineitem l CROSS JOIN LATERAL ( WITH secs AS ( SELECT EXTRACT(EPOCH FROM l.l_shipdate) AS s UNION ALL SELECT EXTRACT(EPOCH FROM l.l_commitdate) AS s ) SELECT AVG(s) AS avg_s FROM secs ) AS sub;
SELECT (DATE '1970-01-01' + ((((l.l_shipdate - DATE '1970-01-01') + (l.l_commitdate - DATE '1970-01-01'))::double precision / 2) * INTERVAL '1 day'))::date AS avg_date FROM lineitem l;
31,952.483
6,464.618
{ "Plan Width": 4, "Actual Rows": 17996609, "Plan Rows": 17997578, "Actual Startup Time": 93.504, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1822177.19, "Actual Total Time": 31285.411, "Startup Cost": 0.04, "Plans": [ { "Relation Name": "lineite...
{ "Relation Name": "lineitem", "Plan Width": 4, "Actual Rows": 17996609, "Plan Rows": 17997578, "Actual Startup Time": 94.955, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 877304.34, "Actual Total Time": 5803.093, "Startup Cost": 0, "Alias": "l" }
medium
69
tpch
SELECT o_custkey, COUNT(CASE WHEN o_orderpriority = '1-URGENT' THEN o_orderkey END) FROM orders GROUP BY o_custkey HAVING COUNT(CASE WHEN o_orderpriority = '5-LOW' THEN o_orderkey END) = 0;
SELECT o.o_custkey, COUNT(CASE WHEN o.o_orderpriority = '1-URGENT' THEN o.o_orderkey END) FROM orders o WHERE NOT EXISTS (SELECT 1 FROM orders o2 WHERE o2.o_custkey = o.o_custkey AND o2.o_orderpriority = '5-LOW') GROUP BY o.o_custkey;
12,330.026
3,340.711
{ "Plan Width": 12, "Actual Rows": 22832, "Plan Rows": 1293, "Actual Startup Time": 6.12, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 462747.26, "Actual Total Time": 12309.515, "Startup Cost": 0.43, "Plans": [ { "Relation Na...
{ "Plan Width": 12, "Actual Rows": 22832, "Plan Rows": 1, "Actual Startup Time": 3267.403, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 384809.9, "Actual Total Time": 3320.883, "Startup Cost": 384809.87, "Plans": [ { "Plan Wi...
hard
70
tpch
SELECT a.user_id, a.total_rows AS total, CASE WHEN a.total_rows = b.year_range THEN 'Y' ELSE 'N' END AS sequential FROM ( SELECT c.c_custkey AS user_id, COUNT(*) AS total_rows FROM customer c JOIN orders o ON c.c_custkey = o.o_custkey GROUP BY c.c_custkey ) a JOIN ( SELECT c.c_custkey AS user_id, ...
WITH user_date_stats AS MATERIALIZED ( SELECT c.c_custkey AS user_id, EXTRACT(YEAR FROM MAX(o.o_orderdate)) - EXTRACT(YEAR FROM MIN(o.o_orderdate)) + 1 AS max_minus_min, COUNT(*) AS total_rows FROM customer c JOIN orders o ON c.c_custkey = o.o_custkey GROUP BY c.c_custkey ) SELECT user_id, tot...
15,801.908
4,389.421
{ "Plan Width": 44, "Actual Rows": 299994, "Plan Rows": 1012500000, "Actual Startup Time": 142.774, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 15902297.27, "Actual Total Time": 15764.393, "Startup Cost": 5.36, "Plans": [ { "Plan Width": 12, ...
{ "Plan Width": 44, "Actual Rows": 299994, "Plan Rows": 450000, "Actual Startup Time": 4298.466, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 581623.35, "Actual Total Time": 4332.897, "Startup Cost": 580498.35, "Plans": [ { "Plan Width": 20, "Actua...
hard
71
tpch
select t1.p_partkey as isin, t1.p_retailprice as amounta, t2.ps_supplycost as amountb from part t1 left join lateral (select ps_supplycost from partsupp t2i where t2i.ps_partkey = t1.p_partkey) t2 on true union all select t2.ps_partkey as isin, null::numeric as amounta, t2.ps_supplycost as amountb from partsupp t2 wher...
SELECT COALESCE(t1.p_partkey, t2.ps_partkey) AS isin, t1.p_retailprice AS amounta, t2.ps_supplycost AS amountb FROM (SELECT p_partkey, p_retailprice FROM part) t1 FULL OUTER JOIN (SELECT ps_partkey, ps_supplycost FROM partsupp) t2 ON t1.p_partkey = t2.ps_partkey
2,792.618
1,525.573
{ "Plan Width": 16, "Actual Rows": 2400000, "Plan Rows": 2400217, "Actual Startup Time": 211.822, "Node Type": "Append", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 310270.42, "Actual Total Time": 2689.962, "Startup Cost": 28719, "Plans": [ { "Plan Width": 16, "Actual...
{ "Plan Width": 16, "Actual Rows": 2400000, "Plan Rows": 2400216, "Actual Startup Time": 212.558, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 137717.77, "Actual Total Time": 1417.512, "Startup Cost": 28719, "Plans": [ { "Relation Name": "partsupp",...
medium
72
tpch
SELECT c.c_custkey, c.c_name, n.n_name AS city, c.c_mktsegment AS "industry-type" FROM customer c INNER JOIN orders o ON o.o_custkey = c.c_custkey INNER JOIN nation n ON c.c_nationkey = n.n_nationkey GROUP BY c.c_custkey, c.c_name, n.n_name, c.c_mktsegment HAVING COUNT(c.c_custkey) > 2;
WITH customer_order_counts AS (SELECT o_custkey, COUNT(*) AS order_count FROM orders GROUP BY o_custkey) SELECT c.c_custkey, c.c_name, n.n_name AS city, c.c_mktsegment AS "industry-type" FROM customer c INNER JOIN customer_order_counts coc ON c.c_custkey = coc.o_custkey JOIN nation n ON c.c_nationkey = n.n_nationkey WH...
14,897.398
4,455.283
{ "Plan Width": 60, "Actual Rows": 998658, "Plan Rows": 5000274, "Actual Startup Time": 153.946, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 1845285.13, "Actual Total Time": 14828.346, "Startup Cost": 14.04, "Plans": [ { "Pl...
{ "Plan Width": 60, "Actual Rows": 998658, "Plan Rows": 301658, "Actual Startup Time": 7.842, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 474316.34, "Actual Total Time": 4396.603, "Startup Cost": 2.42, "Plans": [ { "Plan Width": 38, "Actual R...
easy
73
tpch
SELECT * FROM customer c WHERE NOT EXISTS ( SELECT * FROM orders o WHERE o.o_custkey = c.c_custkey )
SELECT c.* FROM customer c LEFT JOIN orders o ON c.c_custkey = o.o_custkey WHERE o.o_custkey IS NULL
2,288.851
927.44
{ "Plan Width": 158, "Actual Rows": 150006, "Plan Rows": 198889, "Actual Startup Time": 27.485, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 169955.28, "Actual Total Time": 2111.383, "Startup Cost": 6.24, "Plans": [ { "Relation Name": "customer", ...
{ "Plan Width": 158, "Actual Rows": 150006, "Plan Rows": 198889, "Actual Startup Time": 4.372, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 169955.28, "Actual Total Time": 901.123, "Startup Cost": 6.24, "Plans": [ { "Relation Name": "customer", ...
medium
74
tpch
SELECT tf.l_orderkey, tf.l_shipdate FROM ( SELECT t0.l_orderkey, t1.l_shipdate, row_number() OVER (PARTITION BY t0.l_orderkey ORDER BY t1.l_shipdate) AS rn FROM lineitem t0 INNER JOIN lineitem t1 ON t1.l_orderkey = t0.l_orderkey ) tf WHERE tf.rn = 1
SELECT t0.l_orderkey, MIN(t1.l_shipdate) AS l_shipdate FROM lineitem t0 INNER JOIN lineitem t1 ON t1.l_orderkey = t0.l_orderkey GROUP BY t0.l_orderkey
109,518.764
31,607.911
{ "Plan Width": 8, "Actual Rows": 4500000, "Plan Rows": 4164876, "Actual Startup Time": 65737.806, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 206863287.36, "Actual Total Time": 109052.427, "Startup Cost": 179791591.74, "Alias": "tf", "Plans": [ { ...
{ "Plan Width": 8, "Actual Rows": 4500000, "Plan Rows": 388805, "Actual Startup Time": 119.275, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 17814868.98, "Actual Total Time": 31412.581, "Startup Cost": 0.88, "Plans": [ { "Pla...
easy
75
tpch
SELECT c.c_custkey, c.c_name, c.c_address FROM customer c INNER JOIN nation n ON c.c_nationkey = n.n_nationkey LEFT JOIN LATERAL (SELECT 1 as has_nation_1 FROM customer c2 INNER JOIN nation n2 ON c2.c_nationkey = n2.n_nationkey WHERE n2.n_nationkey = 1 AND c2.c_phone = c.c_phone LIMIT 1) nation1_check ON true WHERE n.n...
SELECT c.c_custkey, c.c_name, c.c_address FROM customer c INNER JOIN nation n ON c.c_nationkey = n.n_nationkey WHERE n.n_nationkey != 1 AND NOT EXISTS (SELECT 1 FROM customer c2 INNER JOIN nation n2 ON c2.c_nationkey = n2.n_nationkey WHERE n2.n_nationkey = 1 AND c2.c_phone = c.c_phone) LIMIT 100 OFFSET 0;
1,031.192
29.056
{ "Plan Width": 49, "Actual Rows": 100, "Plan Rows": 100, "Actual Startup Time": 180.566, "Node Type": "Limit", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 231373714.88, "Actual Total Time": 1009.233, "Startup Cost": 204.52, "Plans": [ { "Plan Width": 49, "Actual Rows...
{ "Plan Width": 49, "Actual Rows": 100, "Plan Rows": 100, "Actual Startup Time": 28.799, "Node Type": "Limit", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 11949.43, "Actual Total Time": 28.865, "Startup Cost": 11944.14, "Plans": [ { "Plan Width": 49, "Actual Rows": 10...
hard
76
tpch
SELECT t.l_shipmode, b1.cnt AS "<=2days", b2.cnt AS "<=5days", b3.cnt AS "<=7days" FROM (SELECT DISTINCT l.l_shipmode FROM lineitem l) t LEFT JOIN LATERAL (SELECT COUNT(*) AS cnt FROM lineitem a WHERE a.l_shipmode = t.l_shipmode AND a.l_receiptdate - a.l_shipdate <= 2) b1 ON TRUE LEFT JOIN LATERAL (SELECT COUNT(*) AS c...
SELECT l.l_shipmode, SUM(CASE WHEN l.l_receiptdate - l.l_shipdate <= 2 THEN 1 ELSE 0 END) AS "<=2days", SUM(CASE WHEN l.l_receiptdate - l.l_shipdate > 2 AND l.l_receiptdate - l.l_shipdate <= 5 THEN 1 ELSE 0 END) AS "<=5days", SUM(CASE WHEN l.l_receiptdate - l.l_shipdate > 5 AND l.l_receiptdate - l.l_shipdate <= 7 THEN ...
65,933.484
7,082.404
{ "Plan Width": 35, "Actual Rows": 7, "Plan Rows": 7, "Actual Startup Time": 14660.59, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 15536075.13, "Actual Total Time": 65911.817, "Startup Cost": 2701437.28, "Plans": [ { "Plan Width": 27, "Actu...
{ "Plan Width": 35, "Actual Rows": 7, "Plan Rows": 7, "Actual Startup Time": 7062.101, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 1147209.23, "Actual Total Time": 7062.104, "Startup Cost": 1147209.16, "Plans": [ { "Relation...
medium
77
tpch
SELECT l.acc_combined, COUNT(s.l_orderkey) AS count FROM (SELECT DISTINCT l_orderkey FROM lineitem) s, LATERAL (SELECT STRING_AGG(CAST(l2.l_partkey AS TEXT), ';') AS acc_combined FROM lineitem l2 WHERE l2.l_orderkey = s.l_orderkey) l GROUP BY l.acc_combined
WITH first_cte AS (SELECT l.l_orderkey, STRING_AGG(CAST(l.l_partkey AS TEXT), ';') AS acc_combined FROM lineitem l GROUP BY l.l_orderkey) SELECT acc_combined, COUNT(l_orderkey) AS count FROM first_cte GROUP BY acc_combined
22,741.259
11,947.735
{ "Plan Width": 40, "Actual Rows": 4251059, "Plan Rows": 1, "Actual Startup Time": 20210.488, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 4175678.96, "Actual Total Time": 22524.69, "Startup Cost": 4175678.95, "Plans": [ { "P...
{ "Plan Width": 40, "Actual Rows": 4251059, "Plan Rows": 200, "Actual Startup Time": 9376.799, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 912589.77, "Actual Total Time": 11734.024, "Startup Cost": 912587.77, "Plans": [ { "P...
medium
78
tpch
with date_range as (select case when extract(month from date '1995-12-01') = 1 then date_trunc('year', date '1995-12-01' - interval '1 year') else date_trunc('year', date '1995-12-01') end as start_date, date '1995-12-01' as end_date) select t.* from orders t, date_range dr where t.o_orderdate between dr.start_date and...
select * from orders where o_orderdate between date '1995-01-01' and date '1995-12-01'
1,248.847
588.582
{ "Relation Name": "orders", "Plan Width": 107, "Actual Rows": 625828, "Plan Rows": 639227, "Actual Startup Time": 3.2439999999999998, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 168269.58, "Actual Total Time": 1201.701, "Startup Cost": 0, "Alias": "t" }
{ "Relation Name": "orders", "Plan Width": 107, "Actual Rows": 625828, "Plan Rows": 639227, "Actual Startup Time": 3.231, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 145771.68, "Actual Total Time": 543.18, "Startup Cost": 0, "Alias": "orders" }
medium
79
tpch
SELECT o_orderkey FROM (SELECT o_orderkey, ROW_NUMBER() OVER (PARTITION BY o_orderkey ORDER BY o_orderkey) AS rn FROM orders) t WHERE rn = 1;
SELECT o_orderkey FROM orders GROUP BY o_orderkey ORDER BY o_orderkey;
3,186.119
1,063.708
{ "Plan Width": 4, "Actual Rows": 4500000, "Plan Rows": 22498, "Actual Startup Time": 3.83, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 251841.49, "Actual Total Time": 3009.286, "Startup Cost": 0.43, "Alias": "t", "Plans": [ { "Plan Width": 1...
{ "Plan Width": 4, "Actual Rows": 4500000, "Plan Rows": 4499579, "Actual Startup Time": 2.582, "Node Type": "Group", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 128103.06, "Actual Total Time": 889.426, "Startup Cost": 0.43, "Plans": [ { "Relation Name": "orders", "Pla...
easy
80
tpch
select c_custkey from customer where c_nationkey = 2 and c_custkey in (select c_custkey from customer group by c_custkey having count(distinct c_nationkey) = 1);
select c_custkey from (select c_custkey, min(c_nationkey) as min_nation, max(c_nationkey) as max_nation from customer group by c_custkey) sub where min_nation = 2 and max_nation = 2;
2,063.809
765.742
{ "Plan Width": 4, "Actual Rows": 59952, "Plan Rows": 295, "Actual Startup Time": 207.431, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 140430.4, "Actual Total Time": 2039.578, "Startup Cost": 39295.88, "Plans": [ { "Plan Width": 4, "Actual Ro...
{ "Plan Width": 4, "Actual Rows": 59952, "Plan Rows": 37, "Actual Startup Time": 5.247, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 108540.61, "Actual Total Time": 743.914, "Startup Cost": 0.43, "Alias": "sub", "Plans": [ { "Plan Width": 12, ...
medium
81
tpch
WITH filtered_lineitems AS ( SELECT l.l_partkey, l.l_suppkey, l.l_shipdate, l.l_quantity FROM lineitem AS l INNER JOIN orders AS o ON l.l_orderkey = o.o_orderkey WHERE l.l_shipdate > '1995-03-01' ) SELECT ps.ps_suppkey, s.s_nationkey, p.p_n...
SELECT ps.ps_suppkey, s.s_nationkey, p.p_name, TO_CHAR(l.l_shipdate, 'Mon') AS month, AVG(l.l_quantity) FROM lineitem AS l INNER JOIN partsupp AS ps ON l.l_partkey = ps.ps_partkey AND l.l_suppkey = ps.ps_suppkey INNER JOIN supplier AS s ON ps.ps_suppkey = s.s_suppkey INNER JOIN part ...
77,460.694
49,459.944
{ "Plan Width": 105, "Actual Rows": 8292379, "Plan Rows": 1301, "Actual Startup Time": 65418.745, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 1040398.47, "Actual Total Time": 77049.916, "Startup Cost": 1040356.18, "Plans": [ { ...
{ "Plan Width": 105, "Actual Rows": 8292379, "Plan Rows": 9757044, "Actual Startup Time": 20737.375, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 4218279.1, "Actual Total Time": 49062.994, "Startup Cost": 2991433.79, "Plans": [ { ...
hard
82
tpch
SELECT s.s_suppkey, s.s_name, ps.ps_supplycost AS current_status FROM supplier s JOIN LATERAL ( SELECT ps_supplycost FROM partsupp ps WHERE ps.ps_suppkey = s.s_suppkey ORDER BY ps.ps_partkey DESC LIMIT 1 ) ps ON true ORDER BY s.s_suppkey
SELECT s.s_suppkey, s.s_name, ps.ps_supplycost AS current_status FROM supplier s INNER JOIN ( SELECT ps_suppkey, MAX(ps_partkey) AS max_partkey FROM partsupp GROUP BY ps_suppkey ) latest_ps ON s.s_suppkey = latest_ps.ps_suppkey INNER JOIN partsupp ps ON latest_ps.max_partkey = ps.ps_partkey AND latest_ps.ps...
2,696.269
1,570.114
{ "Plan Width": 36, "Actual Rows": 30000, "Plan Rows": 30000, "Actual Startup Time": 88.941, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 9398607.75, "Actual Total Time": 2675.133, "Startup Cost": 313.5, "Plans": [ { "Relation Name": "supplier", ...
{ "Plan Width": 36, "Actual Rows": 30000, "Plan Rows": 6, "Actual Startup Time": 1546.334, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 164479.27, "Actual Total Time": 1547.714, "Startup Cost": 164479.25, "Plans": [ { "Plan Width": 36, "Actual Rows...
easy
83
tpch
SELECT s.o_orderkey AS id, s.o_orderdate::timestamp AS created_at FROM orders s LEFT JOIN LATERAL ( SELECT o_orderdate::timestamp AS ref_ts FROM orders WHERE o_orderkey = 1 LIMIT 1 ) r ON true WHERE s.o_orderdate::timestamp BETWEEN COALESCE(r.ref_ts, TIMESTAMP '1995-01-01') - INTERVAL '2 minutes' ...
SELECT o.o_orderkey AS id, o.o_orderdate::timestamp AS created_at FROM orders o WHERE o.o_orderdate = COALESCE( (SELECT o_orderdate FROM orders WHERE o_orderkey = 1 LIMIT 1), DATE '1995-01-01' );
1,772.556
431.269
{ "Plan Width": 12, "Actual Rows": 1900, "Plan Rows": 499953, "Actual Startup Time": 6.459, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 248270.56, "Actual Total Time": 1752.945, "Startup Cost": 0.43, "Plans": [ { "Relation Name": "orders", ...
{ "Relation Name": "orders", "Plan Width": 12, "Actual Rows": 1900, "Plan Rows": 1870, "Actual Startup Time": 5.188, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 134535.86, "Actual Total Time": 411.571, "Startup Cost": 8.45, "Alias": "o", "Plans": [ { ...
medium
84
tpch
select c.c_custkey as customer_id, c.c_name as customer_name, coalesce(sum(o.o_totalprice), 0) as grand_total from customer c left join orders o on c.c_custkey = o.o_custkey group by c.c_custkey, c.c_name order by grand_total;
SELECT c.c_custkey AS customer_id, c.c_name AS customer_name, COALESCE(a.grand_total, 0) AS grand_total FROM customer c LEFT JOIN ( SELECT o.o_custkey AS customer_id, SUM(o.o_totalprice) AS grand_total FROM orders o GROUP BY o.o_custkey ) a ON c.c_custkey = a.customer_id ORDER BY grand_tota...
19,816.241
12,584.532
{ "Plan Width": 55, "Actual Rows": 450000, "Plan Rows": 450000, "Actual Startup Time": 19428.467, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 569929.16, "Actual Total Time": 19678.188, "Startup Cost": 568804.16, "Plans": [ { "Plan Width": 55, "Act...
{ "Plan Width": 55, "Actual Rows": 450000, "Plan Rows": 450000, "Actual Startup Time": 12298.739, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 516848.31, "Actual Total Time": 12548.496, "Startup Cost": 515723.31, "Plans": [ { "Plan Width": 55, "Act...
medium
85
tpch
SELECT t1.o_orderkey AS casenumber, EXTRACT(MONTH FROM t1.o_orderdate) AS occurrencemonth, (SELECT COUNT(*) FROM orders t2 WHERE t2.o_orderkey = t1.o_orderkey AND EXTRACT(MONTH FROM t2.o_orderdate) <= EXTRACT(MONTH FROM t1.o_orderdate)) AS consecutivemonths FROM orders t1 ORDER BY t1.o_orderkey, EXTRACT(MONTH FROM t1.o...
SELECT o.o_orderkey AS casenumber, EXTRACT(MONTH FROM o.o_orderdate) AS occurrencemonth, COUNT(*) OVER(PARTITION BY o.o_orderkey ORDER BY EXTRACT(MONTH FROM o.o_orderdate)) AS consecutivemonths FROM orders o ORDER BY o.o_orderkey, EXTRACT(MONTH FROM o.o_orderdate);
13,610.792
5,525.236
{ "Plan Width": 20, "Actual Rows": 4500000, "Plan Rows": 4500380, "Actual Startup Time": 108.017, "Node Type": "Incremental Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 38560886.63, "Actual Total Time": 13417.211, "Startup Cost": 8.97, "Plans": [ { "Relation Name": "o...
{ "Plan Width": 20, "Actual Rows": 4500000, "Plan Rows": 4500380, "Actual Startup Time": 2360.525, "Node Type": "WindowAgg", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 909446.54, "Actual Total Time": 5317.679, "Startup Cost": 796937.04, "Plans": [ { "Plan Width": 12, ...
hard
86
tpch
WITH prepared_data AS ( SELECT TO_CHAR(o_orderdate, 'YYYY-MM') AS month_str, CASE WHEN o_orderstatus = 'F' THEN 1.0 ELSE NULL END AS is_ready_value FROM orders ), aggregated_data AS ( SELECT month_str AS month, AVG(is_ready_value) AS average FROM prepared_data GROUP BY month_str ) SELECT mon...
WITH cte AS ( SELECT LPAD(EXTRACT(YEAR FROM o_orderdate)::text, 4, '0') || '-' || LPAD(EXTRACT(MONTH FROM o_orderdate)::text, 2, '0') AS month, AVG(CASE WHEN o_orderstatus = 'F' THEN 1 ELSE NULL END) AS average FROM orders GROUP BY EXTRACT(YEAR FROM o_orderdate), EXTRACT(MONTH FROM o_ord...
3,201.655
2,367.76
{ "Plan Width": 64, "Actual Rows": 80, "Plan Rows": 2406, "Actual Startup Time": 3182.405, "Node Type": "WindowAgg", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 179779.95, "Actual Total Time": 3182.445, "Startup Cost": 179737.84, "Plans": [ { "Plan Width": 64, "Actual...
{ "Plan Width": 64, "Actual Rows": 80, "Plan Rows": 2406, "Actual Startup Time": 2346.563, "Node Type": "WindowAgg", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 213617.01, "Actual Total Time": 2346.607, "Startup Cost": 213574.9, "Plans": [ { "Plan Width": 64, "Actual ...
hard
87
tpch
SELECT * FROM lineitem l WHERE (SELECT COUNT(*) FROM orders o WHERE o.o_orderkey = l.l_orderkey AND o.o_orderstatus <> l.l_returnflag) > 0
SELECT l.* FROM lineitem l JOIN orders o ON l.l_orderkey = o.o_orderkey WHERE l.l_returnflag <> o.o_orderstatus
148,710.154
35,426.412
{ "Relation Name": "lineitem", "Plan Width": 117, "Actual Rows": 59986052, "Plan Rows": 19997236, "Actual Startup Time": 107.578, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 509854226.84, "Actual Total Time": 145348.021, "Startup Cost": 0, "Alias": "l", "...
{ "Plan Width": 117, "Actual Rows": 59986052, "Plan Rows": 59991708, "Actual Startup Time": 161.485, "Node Type": "Merge Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 3994218.45, "Actual Total Time": 33172.019, "Startup Cost": 43.39, "Plans": [ { "Relation Name": "orde...
medium
88
tpch
SELECT * FROM orders WHERE EXISTS (SELECT 1 FROM (VALUES ('1-URGENT'), ('2-HIGH'), ('3-MEDIUM')) AS vals(o_orderpriority) WHERE vals.o_orderpriority = orders.o_orderpriority);
SELECT * FROM orders WHERE o_orderpriority IN ('1-URGENT', '2-HIGH', '3-MEDIUM');
2,767.683
1,321.163
{ "Plan Width": 107, "Actual Rows": 2699161, "Plan Rows": 67494, "Actual Startup Time": 6.84, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 136474.51, "Actual Total Time": 2647.211, "Startup Cost": 0.08, "Plans": [ { "Relation Name": "orders", ...
{ "Relation Name": "orders", "Plan Width": 107, "Actual Rows": 2699161, "Plan Rows": 2712046, "Actual Startup Time": 3.713, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 140147.21, "Actual Total Time": 1196.41, "Startup Cost": 0, "Alias": "orders" }
easy
89
tpch
select count(distinct a.l_partkey) from lineitem a inner join lineitem b on a.l_partkey = b.l_partkey and a.ctid <> b.ctid;
with recursive group_counts as (select l_partkey, count(*) as cnt from lineitem group by l_partkey), filtered_groups as (select l_partkey from group_counts where cnt > 1) select count(*) from filtered_groups;
312,209.057
3,723.919
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 312189.362, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 10344803.27, "Actual Total Time": 312189.389, "Startup Cost": 10344803.26, "Plans": [ { "Plan...
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 3703.455, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 452536.72, "Actual Total Time": 3703.456, "Startup Cost": 452536.71, "Plans": [ { "Plan Width":...
medium
90
tpch
WITH CountryTotalExtendedPrice AS ( SELECT c.c_mktsegment, SUM(l.l_extendedprice) AS sum_extendedprice FROM customer c JOIN orders o ON c.c_custkey = o.o_custkey JOIN lineitem l ON o.o_orderkey = l.l_orderkey GROUP BY c.c_mktsegment ), CountryDistinctCustKeys AS ( SELECT c.c_mktsegme...
SELECT c.c_mktsegment, (SUM(l.l_extendedprice) / 60) AS total_minutes, COUNT(DISTINCT c.c_custkey) AS total_users, (SUM(l.l_extendedprice) / 60 / NULLIF(COUNT(DISTINCT c.c_custkey), 0)) AS minutes_per_user FROM customer c JOIN orders o ON c.c_custkey = o.o_custkey JOIN lineitem l ON o.o_orderkey = l.l_ord...
52,068.511
38,156.673
{ "Plan Width": 83, "Actual Rows": 5, "Plan Rows": 5, "Actual Startup Time": 45364.212, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 5212193, "Actual Total Time": 51955.342, "Startup Cost": 5077220.95, "Plans": [ { "Plan Width": 19, "Actual Ro...
{ "Plan Width": 83, "Actual Rows": 5, "Plan Rows": 5, "Actual Startup Time": 30189.492, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 4380008.89, "Actual Total Time": 38030.299, "Startup Cost": 4110065.04, "Plans": [ { "Plan W...
hard
91
tpch
SELECT t.o_orderkey FROM orders t WHERE EXISTS ( SELECT 1 FROM (VALUES (1, 5), (10, 14), (100, 104)) AS v(low, high) WHERE t.o_orderkey BETWEEN v.low AND v.high );
WITH bounds(low, high) AS ( VALUES (1, 5), (10, 14), (100, 104) ) SELECT t.o_orderkey FROM orders t JOIN bounds b ON t.o_orderkey BETWEEN b.low AND b.high;
2,500.711
0.079
{ "Plan Width": 4, "Actual Rows": 9, "Plan Rows": 499953, "Actual Startup Time": 3.254, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 339958.29, "Actual Total Time": 2481.05, "Startup Cost": 0.43, "Plans": [ { "Relation Name": "orders", "Plan...
{ "Plan Width": 4, "Actual Rows": 9, "Plan Rows": 1499860, "Actual Startup Time": 0.027, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 59109.1, "Actual Total Time": 0.034, "Startup Cost": 0.43, "Plans": [ { "Plan Width": 8, "Actual Rows": 3, ...
easy
92
tpch
SELECT DISTINCT c_custkey FROM customer c1 WHERE ctid = (SELECT MIN(ctid) FROM customer c2 WHERE c2.c_custkey = c1.c_custkey)
SELECT DISTINCT c_custkey FROM customer
1,331.934
123.911
{ "Plan Width": 4, "Actual Rows": 450000, "Plan Rows": 2250, "Actual Startup Time": 101.895, "Node Type": "Unique", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 3827203.05, "Actual Total Time": 1287.627, "Startup Cost": 0.42, "Plans": [ { "Relation Name": "customer", "...
{ "Plan Width": 4, "Actual Rows": 450000, "Plan Rows": 450000, "Actual Startup Time": 0.029, "Node Type": "Unique", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 12819.42, "Actual Total Time": 107.897, "Startup Cost": 0.42, "Plans": [ { "Relation Name": "customer", "Pla...
easy
93
tpch
WITH numbered_rows AS (SELECT l_extendedprice, ROW_NUMBER() OVER (ORDER BY l_extendedprice) AS rn FROM lineitem) SELECT nr1.l_extendedprice - COALESCE(SUM(nr2.l_extendedprice), 0) AS sum_val FROM numbered_rows nr1 LEFT JOIN numbered_rows nr2 ON nr2.rn < nr1.rn WHERE nr1.rn = (SELECT MAX(rn) FROM numbered_rows) GROUP BY...
SELECT l_extendedprice - COALESCE((SELECT SUM(i.l_extendedprice) FROM lineitem i WHERE i.l_extendedprice < o.l_extendedprice), 0) AS sum_val FROM lineitem o ORDER BY l_extendedprice DESC LIMIT 1;
66,913.137
12,592.351
{ "Plan Width": 50, "Actual Rows": 1, "Plan Rows": 200, "Actual Startup Time": 66744.209, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 50207578495.48, "Actual Total Time": 66744.213, "Startup Cost": 50207578492.48, "Plans": [ { ...
{ "Plan Width": 40, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 12573.357, "Node Type": "Limit", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1184649.72, "Actual Total Time": 12573.36, "Startup Cost": 607321.72, "Plans": [ { "Plan Width": 40, "Actual Rows"...
medium
94
tpch
SELECT c.c_name AS name, c.c_custkey AS "id of person", n.n_name AS "location of home" FROM customer c JOIN orders o ON c.c_custkey = o.o_custkey JOIN nation n ON c.c_nationkey = n.n_nationkey GROUP BY c.c_custkey, c.c_name, n.n_name HAVING COUNT(*) = 2;
WITH customer_order_count AS (SELECT o_custkey AS custkey, COUNT(*) AS cnt FROM orders GROUP BY o_custkey HAVING COUNT(*) = 2) SELECT c.c_name AS name, c.c_custkey AS "id of person", n.n_name AS "location of home" FROM customer c JOIN customer_order_count coc ON c.c_custkey = coc.custkey JOIN nation n ON c.c_nationkey ...
13,648.437
3,298.588
{ "Plan Width": 49, "Actual Rows": 1113, "Plan Rows": 75004, "Actual Startup Time": 134.627, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 1775167.49, "Actual Total Time": 13627.715, "Startup Cost": 13.4, "Plans": [ { "Plan Wi...
{ "Plan Width": 49, "Actual Rows": 1113, "Plan Rows": 4525, "Actual Startup Time": 102.707, "Node Type": "Group", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 420689.71, "Actual Total Time": 3279.548, "Startup Cost": 93.79, "Plans": [ { "Plan Width": 49, "Actual Rows":...
easy
95
tpch
WITH RECURSIVE unique_groups AS ( SELECT l_orderkey, l_extendedprice, l_comment, ROW_NUMBER() OVER (ORDER BY l_orderkey, l_extendedprice, l_comment) AS rn FROM lineitem ), duplicate_invs AS ( SELECT g1.l_orderkey FROM unique_groups g1 JOIN unique_groups g2 ON g1.l_orderkey = g2.l_orderkey WHERE g1....
SELECT COUNT(1) FROM ( SELECT l_orderkey FROM ( SELECT l_orderkey, l_extendedprice, l_comment FROM lineitem GROUP BY l_orderkey, l_extendedprice, l_comment ) AS t1 GROUP BY l_orderkey HAVING COUNT(l_orderkey) > 1 ) AS t2
83,608.866
20,678.212
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 82890.895, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 37801350100.45, "Actual Total Time": 82890.899, "Startup Cost": 37801350100.44, "Plans": [ { "...
{ "Plan Width": 8, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 20657.952, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 1964813.29, "Actual Total Time": 20657.954, "Startup Cost": 1964813.28, "Plans": [ { "Plan Wid...
medium
96
tpch
SELECT c.c_custkey, s.s_suppkey, o.o_orderstatus FROM orders o JOIN customer c ON o.o_custkey = c.c_custkey JOIN lineitem l ON o.o_orderkey = l.l_orderkey JOIN supplier s ON l.l_suppkey = s.s_suppkey WHERE ((c.c_custkey::text LIKE '%1' OR c.c_custkey::text LIKE '%3' OR c.c_custkey::text LIKE '%5' OR c.c_custkey::text L...
SELECT c.c_custkey, s.s_suppkey, o.o_orderstatus FROM orders o JOIN customer c ON o.o_custkey = c.c_custkey JOIN lineitem l ON o.o_orderkey = l.l_orderkey JOIN supplier s ON l.l_suppkey = s.s_suppkey WHERE ((RIGHT(c.c_custkey::text, 1) = ANY(ARRAY['1','3','5','7','9']) AND s.s_suppkey IN (1, 5, 19)) OR (POSITION('2' IN...
26,785.585
17,388.895
{ "Plan Width": 10, "Actual Rows": 10125561, "Plan Rows": 17992649, "Actual Startup Time": 1678.031, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1220895.6, "Actual Total Time": 26389.715, "Startup Cost": 221750.26, "Plans": [ { "Plan Width": 10, ...
{ "Plan Width": 10, "Actual Rows": 10125561, "Plan Rows": 1999623, "Actual Startup Time": 1752.007, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 951950.12, "Actual Total Time": 16999.026, "Startup Cost": 227802.03, "Plans": [ { "Plan Width": 10, ...
hard
97
tpch
SELECT totals.TotalPledge, base.o_orderkey, base.s_suppkey, base.o_orderdate, base.r_name, base.n_name FROM (SELECT o.o_orderkey, s.s_suppkey, o.o_orderdate, r.r_name, n.n_name FROM orders o CROSS JOIN supplier s JOIN nation n ON n.n_nationkey = s.s_nationkey JOIN region r ON r.r_regionkey = n.n_regionkey WHERE EXISTS ...
SELECT pledge_sums.TotalPledge, o.o_orderkey, s.s_suppkey, o.o_orderdate, r.r_name, n.n_name FROM (SELECT l.l_orderkey, l.l_suppkey, SUM(l.l_extendedprice) AS TotalPledge FROM lineitem l GROUP BY l.l_orderkey, l.l_suppkey) pledge_sums JOIN orders o ON o.o_orderkey = pledge_sums.l_orderkey JOIN supplier s ON s.s_suppkey...
110,524.824
36,537.216
{ "Plan Width": 96, "Actual Rows": 17995323, "Plan Rows": 405253, "Actual Startup Time": 10905.022, "Node Type": "Nested Loop", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 3640004.7, "Actual Total Time": 109425.805, "Startup Cost": 3179895.89, "Plans": [ { "Plan Width": 60,...
{ "Plan Width": 96, "Actual Rows": 17995323, "Plan Rows": 1799758, "Actual Startup Time": 230.51, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 2219895.86, "Actual Total Time": 35508.035, "Startup Cost": 1347.34, "Plans": [ { "Plan Width": 74, ...
medium
98
tpch
WITH order_aggregates AS ( SELECT o.o_custkey, l.l_suppkey, SUM(o.o_totalprice) AS total FROM orders o JOIN lineitem l ON o.o_orderkey = l.l_orderkey GROUP BY o.o_custkey, l.l_suppkey ) SELECT c.c_name, c.c_address, s.s_name, SUM(oa.total) AS total FROM order_aggregates oa INNER JOIN custo...
SELECT c.c_name, c.c_address, s.s_name, SUM(o.o_totalprice) AS total FROM customer c INNER JOIN orders o ON c.c_custkey = o.o_custkey INNER JOIN lineitem l ON o.o_orderkey = l.l_orderkey INNER JOIN supplier s ON l.l_suppkey = s.s_suppkey GROUP BY c.c_name, c.c_address, s.s_na...
230,563.69
184,021.523
{ "Plan Width": 103, "Actual Rows": 17975262, "Plan Rows": 17996248, "Actual Startup Time": 185480.195, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 9923608.52, "Actual Total Time": 229533.311, "Startup Cost": 9473702.32, "Plans": [ ...
{ "Plan Width": 103, "Actual Rows": 17975262, "Plan Rows": 17996248, "Actual Startup Time": 143987.389, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Sorted", "Total Cost": 6247377.05, "Actual Total Time": 183110.836, "Startup Cost": 5797470.85, "Plans": [ ...
medium
99
tpch
WITH ranked AS (SELECT l_orderkey, l_suppkey, ROW_NUMBER() OVER (PARTITION BY l_orderkey ORDER BY l_suppkey) AS rn, COUNT(*) OVER (PARTITION BY l_orderkey) AS cnt FROM lineitem WHERE l_suppkey = 200 OR l_suppkey <> 200) SELECT l_orderkey FROM ranked WHERE cnt = 1 AND l_suppkey = 200;
SELECT DISTINCT l1.l_orderkey FROM lineitem l1 WHERE l1.l_suppkey = 200 AND NOT EXISTS (SELECT 1 FROM lineitem l2 WHERE l2.l_orderkey = l1.l_orderkey AND l2.l_suppkey <> 200);
40,134.279
33.22
{ "Plan Width": 4, "Actual Rows": 12, "Plan Rows": 3, "Actual Startup Time": 1498.011, "Node Type": "Subquery Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 4506106.41, "Actual Total Time": 40117.138, "Startup Cost": 0.44, "Alias": "ranked", "Plans": [ { "Plan Width":...
{ "Plan Width": 4, "Actual Rows": 12, "Plan Rows": 1, "Actual Startup Time": 33.116, "Node Type": "Unique", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 2714.9, "Actual Total Time": 33.122, "Startup Cost": 2714.9, "Plans": [ { "Plan Width": 4, "Actual Rows": 12, ...
hard
100
tpch
SELECT MAX(o.o_orderkey) FROM orders o WHERE EXISTS (SELECT 1 FROM customer c WHERE c.c_custkey = o.o_custkey)
SELECT MAX(o_orderkey) FROM orders;
2,390.74
0.246
{ "Plan Width": 4, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 2373.199, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 202341.79, "Actual Total Time": 2373.201, "Startup Cost": 202341.78, "Plans": [ { "Plan Width":...
{ "Plan Width": 4, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 0.203, "Node Type": "Result", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 0.47000000000000003, "Actual Total Time": 0.20400000000000001, "Startup Cost": 0.46, "Plans": [ { "Plan Width": 4, "Ac...
easy