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
201
tpch
SELECT * FROM (SELECT * FROM lineitem WHERE l_linenumber = 1 AND l_returnflag = 'A' AND l_shipdate >= '1992-01-02' UNION SELECT * FROM lineitem WHERE l_linenumber = 2 AND l_returnflag = 'A' AND l_shipdate >= '1992-01-03') AS filtered_data;
SELECT * FROM lineitem WHERE l_returnflag = 'A' AND ((l_linenumber = 1 AND l_shipdate >= '1992-01-02') OR (l_linenumber = 2 AND l_shipdate >= '1992-01-03'));
2,932.779
1,455.463
{ "Node Type": "Unique", "Total Cost": 987298.65, "Plan Width": 370, "Parallel Aware": false, "Plan Rows": 316019, "Startup Cost": 973867.84, "Plans": [ { "Node Type": "Sort", "Parent Relationship": "Outer", "Total Cost": 974657.89, "Plan Width": 370, "Parallel Aware": fa...
{ "Node Type": "Seq Scan", "Total Cost": 438619.49, "Relation Name": "lineitem", "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 293497, "Startup Cost": 0, "Alias": "lineitem" }
easy
202
tpch
SELECT l_partkey, l_suppkey, dCount FROM (SELECT l_partkey, l_suppkey, COUNT(l_quantity) as dCount FROM lineitem WHERE l_partkey != 0 GROUP BY l_partkey, l_suppkey) t GROUP BY t.l_partkey, t.l_suppkey, t.dCount HAVING COUNT(t.l_suppkey) > 0;
SELECT l_partkey, l_suppkey, COUNT(l_quantity) as dCount FROM lineitem WHERE l_partkey != 0 GROUP BY l_partkey, l_suppkey HAVING COUNT(l_suppkey) > 0
7,910.18
5,977.44
{ "Node Type": "Aggregate", "Total Cost": 790034.94, "Plan Width": 16, "Parallel Aware": false, "Plan Rows": 17641, "Strategy": "Hashed", "Startup Cost": 784205.11, "Plans": [ { "Node Type": "Aggregate", "Parent Relationship": "Outer", "Total Cost": 742362.63, "Plan Width": 1...
{ "Node Type": "Aggregate", "Total Cost": 754934.74, "Plan Width": 16, "Parallel Aware": false, "Plan Rows": 176411, "Strategy": "Hashed", "Startup Cost": 704377.8, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 393623.28, "Relation Name":...
easy
203
tpch
SELECT DISTINCT o.o_clerk AS gamertag, COUNT(l.l_quantity) AS "Trophies", c.c_name AS person 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 GROUP BY o.o_clerk, c.c_name ORDER BY COUNT(l.l_quantity) DESC;
WITH order_lineitems AS ( SELECT o.o_custkey, o.o_clerk, l.l_quantity FROM orders o INNER JOIN lineitem l ON o.o_orderkey = l.l_orderkey ) SELECT o_clerk AS gamertag, COUNT(l_quantity) AS "Trophies", c.c_name AS person FROM customer c INNER JOIN order_lineitems ol ON c.c_custkey = ol.o_custkey GROUP BY o_cl...
71,543.838
48,295.177
{ "Node Type": "Unique", "Total Cost": 2422277.3, "Plan Width": 43, "Parallel Aware": false, "Plan Rows": 4499622, "Startup Cost": 2377281.08, "Plans": [ { "Node Type": "Sort", "Parent Relationship": "Outer", "Total Cost": 2388530.13, "Plan Width": 43, "Parallel Aware": f...
{ "Node Type": "Sort", "Total Cost": 2388530.13, "Plan Width": 43, "Parallel Aware": false, "Plan Rows": 4499622, "Startup Cost": 2377281.08, "Plans": [ { "Node Type": "Aggregate", "Parent Relationship": "Outer", "Total Cost": 1603205.97, "Plan Width": 43, "Parallel Aware...
hard
204
tpch
SELECT * FROM ORDERS WHERE O_ORDERSTATUS = 'P' UNION ALL SELECT * FROM ORDERS WHERE O_ORDERSTATUS = 'F';
SELECT * FROM ORDERS WHERE O_ORDERSTATUS IN ('P', 'F');
1,347.975
809.971
{ "Node Type": "Append", "Total Cost": 303353.53, "Plan Width": 107, "Parallel Aware": false, "Plan Rows": 2285312, "Startup Cost": 0, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Member", "Total Cost": 134536.92, "Relation Name": "orders", "Plan Width": ...
{ "Node Type": "Seq Scan", "Total Cost": 134536.92, "Relation Name": "orders", "Plan Width": 107, "Parallel Aware": false, "Plan Rows": 2285313, "Startup Cost": 0, "Alias": "orders" }
easy
205
tpch
SELECT l.* FROM lineitem l CROSS JOIN LATERAL ( SELECT ARRAY( SELECT l_receiptdate FROM lineitem ORDER BY l_receiptdate DESC LIMIT 2 ) AS top_dates ) AS d WHERE l.l_receiptdate BETWEEN d.top_dates[2] AND d.top_dates[1] ORDER BY l.l_receiptdate;
WITH top_dates AS ( SELECT l_receiptdate, ROW_NUMBER() OVER (ORDER BY l_receiptdate DESC) as rn FROM lineitem ORDER BY l_receiptdate DESC LIMIT 2 ) SELECT l.* FROM lineitem l WHERE l.l_receiptdate BETWEEN (SELECT l_receiptdate FROM top_dates WHERE rn = 2) AND (SELECT l_receiptdate FROM top_dates WHERE ...
5,756.659
4,320.814
{ "Node Type": "Sort", "Total Cost": 1261295.79, "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 22498, "Startup Cost": 1261239.55, "Plans": [ { "Node Type": "Limit", "Parent Relationship": "InitPlan", "Total Cost": 427370.45, "Plan Width": 4, "Parallel Aware": f...
{ "Node Type": "Sort", "Total Cost": 1409207.35, "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 22498, "Startup Cost": 1409151.11, "Plans": [ { "Node Type": "Limit", "Parent Relationship": "InitPlan", "Total Cost": 1002652.36, "Plan Width": 12, "Parallel Aware":...
hard
206
tpch
SELECT COUNT(DISTINCT l_partkey) FILTER (WHERE l_shipdate BETWEEN '1992-09-01' AND '1992-09-30'), COUNT(DISTINCT l_shipdate) FILTER (WHERE l_shipdate BETWEEN '1992-09-01' AND '1992-09-30'), SUM(l_extendedprice) FILTER (WHERE l_shipdate BETWEEN '1992-09-01' AND '1992-09-30') FROM lineitem
SELECT COUNT(DISTINCT l_partkey), COUNT(DISTINCT l_shipdate), SUM(l_extendedprice) FROM lineitem WHERE l_shipdate BETWEEN '1992-09-01' AND '1992-09-30'
2,074.451
1,646.255
{ "Node Type": "Aggregate", "Total Cost": 483615.73, "Plan Width": 48, "Parallel Aware": false, "Plan Rows": 1, "Strategy": "Plain", "Startup Cost": 483615.72, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 382374.22, "Relation Name": "lin...
{ "Node Type": "Aggregate", "Total Cost": 405331.83, "Plan Width": 48, "Parallel Aware": false, "Plan Rows": 1, "Strategy": "Plain", "Startup Cost": 405331.82, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 404872.33, "Relation Name": "lin...
hard
207
tpch
WITH filtered_lineitems AS ( SELECT l_suppkey, l_shipdate, l_quantity FROM lineitem WHERE EXTRACT(YEAR FROM l_shipdate) >= 1984 AND l_quantity >= 0 ) SELECT s_name AS site_name, EXTRACT(YEAR FROM l_shipdate) AS survey_year, AVG(l_quantity) AS snow_depth FROM supplier JOIN filtered_lineitems ON s_suppkey = l_suppk...
WITH pre_aggregated AS ( SELECT l_suppkey, EXTRACT(YEAR FROM l_shipdate) AS survey_year, AVG(l_quantity) AS avg_quantity, COUNT(*) AS count_items FROM lineitem WHERE EXTRACT(YEAR FROM l_shipdate) >= 1984 AND l_quantity >= 0 GROUP BY l_suppkey, EXTRACT(YEAR FROM l_shipdate) ) SELECT s_name AS si...
32,660.835
5,819.418
{ "Node Type": "Aggregate", "Total Cost": 717280.22, "Plan Width": 66, "Parallel Aware": false, "Plan Rows": 1499874, "Strategy": "Sorted", "Startup Cost": 676033.68, "Plans": [ { "Node Type": "Sort", "Parent Relationship": "Outer", "Total Cost": 679783.37, "Plan Width": 39, ...
{ "Node Type": "Sort", "Total Cost": 639363.9, "Plan Width": 66, "Parallel Aware": false, "Plan Rows": 442159, "Startup Cost": 638258.5, "Plans": [ { "Node Type": "Hash Join", "Parent Relationship": "Outer", "Total Cost": 578659.79, "Plan Width": 66, "Parallel Aware": fal...
medium
208
tpch
SELECT M.Client_ID, M.Client, SUM(COALESCE(C.Time_spent_h, 0)) + SUM(M.Time_spent_h) AS Total_time FROM (SELECT o.O_CUSTKEY AS Client_ID, c.C_NAME AS Client, SUM(o.O_TOTALPRICE) AS Time_spent_h FROM ORDERS o JOIN CUSTOMER c ON o.O_CUSTKEY = c.C_CUSTKEY ...
WITH customer_orders AS (SELECT o.O_CUSTKEY AS Client_ID, c.C_NAME AS Client, SUM(o.O_TOTALPRICE) AS Time_spent_h FROM ORDERS o JOIN CUSTOMER c ON o.O_CUSTKEY = c.C_CUSTKEY GROUP BY o.O_CUSTKEY, c.C_NAME) SELECT Client_ID, Client, SUM(COALESCE(Time_spent_h, 0)) * 2 AS Total_time FROM customer_orders GROUP BY Client_ID,...
27,765.582
19,826.829
{ "Node Type": "Aggregate", "Total Cost": 2533748109.92, "Plan Width": 55, "Parallel Aware": false, "Plan Rows": 40000, "Strategy": "Sorted", "Startup Cost": 47.99, "Plans": [ { "Node Type": "Merge Join", "Parent Relationship": "Outer", "Total Cost": 1520926084.43, "Plan Widt...
{ "Node Type": "Aggregate", "Total Cost": 875777.56, "Plan Width": 55, "Parallel Aware": false, "Plan Rows": 40000, "Strategy": "Sorted", "Startup Cost": 24, "Plans": [ { "Node Type": "Aggregate", "Parent Relationship": "Outer", "Total Cost": 796415.06, "Plan Width": 55, ...
hard
209
tpch
WITH filtered_lineitem AS MATERIALIZED (SELECT * FROM lineitem WHERE l_returnflag = 'R') SELECT l_returnflag as markup_type, ps_comment as supplier_invoice_number, l_orderkey as client_payment_req_id, l_extendedprice as net_amount, l_discount as markup_value, l_quantity as net_qty, l_tax as markup_value, o_custkey as b...
SELECT l_returnflag as markup_type, ps_comment as supplier_invoice_number, l_orderkey as client_payment_req_id, l_extendedprice as net_amount, l_discount as markup_value, l_quantity as net_qty, l_tax as markup_value, o_custkey as buyerClientId, ps_partkey as contract_id FROM (SELECT * FROM lineitem WHERE l_returnflag =...
12,341.79
6,314.222
{ "Node Type": "Nested Loop", "Total Cost": 660809.23, "Plan Width": 218, "Parallel Aware": false, "Plan Rows": 240, "Startup Cost": 552810.08, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "InitPlan", "Total Cost": 393623.28, "Relation Name": "lineitem", "...
{ "Node Type": "Hash Join", "Total Cost": 840923.32, "Plan Width": 161, "Parallel Aware": false, "Plan Rows": 1117256, "Startup Cost": 575504.35, "Plans": [ { "Node Type": "Hash Join", "Parent Relationship": "Outer", "Total Cost": 611544.35, "Plan Width": 39, "Parallel Aw...
easy
210
tpch
SELECT li.* FROM (SELECT p_partkey FROM part WHERE p_partkey IN (1, 2)) p JOIN (SELECT l_partkey, MIN(l_linenumber) as min_linenumber FROM lineitem GROUP BY l_partkey) min_li ON p.p_partkey = min_li.l_partkey JOIN lineitem li ON li.l_partkey = min_li.l_partkey AND li.l_linenumber = min_li.min_linenumber
SELECT li.* FROM lineitem li JOIN part p ON p.p_partkey = li.l_partkey WHERE p.p_partkey IN (1, 2) AND li.l_linenumber = (SELECT MIN(l_linenumber) FROM lineitem WHERE l_partkey = p.p_partkey)
4,681.523
0.411
{ "Node Type": "Nested Loop", "Total Cost": 682620.73, "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 1, "Startup Cost": 635487.3, "Plans": [ { "Node Type": "Hash Join", "Parent Relationship": "Outer", "Total Cost": 682614.07, "Plan Width": 12, "Parallel Aware":...
{ "Node Type": "Nested Loop", "Total Cost": 821.33, "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 1, "Startup Cost": 0.86, "Plans": [ { "Node Type": "Index Only Scan", "Parent Relationship": "Outer", "Total Cost": 8.88, "Relation Name": "part", "Plan Width": 4,...
medium
211
tpch
SELECT rank() over(PARTITION BY CASE WHEN EXTRACT(DOW FROM l_shipdate) = 6 THEN 1 ELSE 0 END) AS "week", EXTRACT(DOW FROM l_shipdate) AS dayy, to_char(l_shipdate, 'TMDay') AS dayname, l_shipdate AS tanggal FROM lineitem WHERE EXTRACT(MONTH FROM l_shipdate) = 4 AND EXTRACT(YEAR FROM l_shipdate) = 1998 GROUP BY dayy, tan...
WITH filtered_lineitem AS ( SELECT l_shipdate FROM lineitem WHERE l_shipdate >= '1998-04-01' AND l_shipdate <= '1998-04-30' ) SELECT rank() over(PARTITION BY CASE WHEN EXTRACT(DOW FROM l_shipdate) = 6 THEN 1 ELSE 0 END) AS "week", EXTRACT(DOW FROM l_shipdate) AS dayy, to_char(l_shipdate, 'TMDay') AS dayname, l_...
1,774.539
1,377.549
{ "Node Type": "Sort", "Total Cost": 449886.72, "Plan Width": 56, "Parallel Aware": false, "Plan Rows": 110, "Startup Cost": 449886.45, "Plans": [ { "Node Type": "WindowAgg", "Parent Relationship": "Outer", "Total Cost": 449882.72, "Plan Width": 56, "Parallel Aware": fals...
{ "Node Type": "Sort", "Total Cost": 405872.71, "Plan Width": 56, "Parallel Aware": false, "Plan Rows": 2507, "Startup Cost": 405866.45, "Plans": [ { "Node Type": "WindowAgg", "Parent Relationship": "Outer", "Total Cost": 405724.9, "Plan Width": 56, "Parallel Aware": fals...
hard
212
tpch
SELECT DISTINCT o_orderpriority, o_clerk FROM ( SELECT o_orderpriority, o_clerk, COUNT(*) OVER (PARTITION BY o_orderpriority, o_clerk) as group_count FROM orders ) sub WHERE group_count > 1;
SELECT DISTINCT o1.o_orderpriority, o1.o_clerk FROM orders o1 WHERE EXISTS ( SELECT 1 FROM orders o2 WHERE o2.o_orderpriority = o1.o_orderpriority AND o2.o_clerk = o1.o_clerk AND o2.o_orderkey <> o1.o_orderkey );
23,225.254
6,543.89
{ "Node Type": "Unique", "Total Cost": 989796.19, "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 15000, "Startup Cost": 836021.8, "Plans": [ { "Node Type": "Subquery Scan", "Parent Relationship": "Outer", "Total Cost": 982295, "Plan Width": 32, "Parallel Aware": ...
{ "Node Type": "Aggregate", "Total Cost": 814936.11, "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 15000, "Strategy": "Hashed", "Startup Cost": 814786.11, "Plans": [ { "Node Type": "Hash Join", "Parent Relationship": "Outer", "Total Cost": 792282.54, "Plan Width": 3...
easy
213
tpch
WITH cte_1 AS ( SELECT o_clerk AS runner_id, (COUNT(o_clerk)) * 100 AS percentages FROM orders WHERE o_orderstatus = 'F' GROUP BY o_clerk ) SELECT cte_1.runner_id, (cte_1.percentages / COUNT(o.o_orderstatus)) AS percentages_successful_deliveries ...
WITH successful_orders AS ( SELECT o_clerk, COUNT(*) * 100 AS percentages FROM orders WHERE o_orderstatus = 'F' GROUP BY o_clerk ), all_orders AS ( SELECT o_clerk, COUNT(o_orderstatus) AS total_count FROM orders GROUP BY o_clerk ) SELECT COALESCE(s.o_clerk, a.o_clerk) AS runner_id, ...
2,558.141
1,486.033
{ "Node Type": "Sort", "Total Cost": 186413.27, "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 300, "Startup Cost": 186412.52, "Plans": [ { "Node Type": "Aggregate", "Parent Relationship": "Outer", "Total Cost": 186400.18, "Plan Width": 32, "Parallel Aware": fals...
{ "Node Type": "Sort", "Total Cost": 168936.25, "Plan Width": 72, "Parallel Aware": false, "Plan Rows": 45000, "Startup Cost": 168823.75, "Plans": [ { "Node Type": "Hash Join", "Parent Relationship": "Outer", "Total Cost": 163497.78, "Plan Width": 72, "Parallel Aware": fa...
hard
214
tpch
SELECT DISTINCT COUNT(o_orderkey) OVER() FROM orders WHERE o_orderpriority = '1-URGENT' LIMIT 1;
SELECT COUNT(o_orderkey) FROM orders WHERE o_orderpriority = '1-URGENT';
1,163.461
808.413
{ "Node Type": "Limit", "Total Cost": 193257.03, "Plan Width": 8, "Parallel Aware": false, "Plan Rows": 1, "Startup Cost": 193257.02, "Plans": [ { "Node Type": "Aggregate", "Parent Relationship": "Outer", "Total Cost": 209044.97, "Plan Width": 8, "Parallel Aware": false, ...
{ "Node Type": "Aggregate", "Total Cost": 136752.79, "Plan Width": 8, "Parallel Aware": false, "Plan Rows": 1, "Strategy": "Plain", "Startup Cost": 136752.78, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 134536.92, "Relation Name": "orde...
easy
215
tpch
SELECT *, MAX(l_shipdate) OVER () AS date_max FROM lineitem
SELECT l.*, (SELECT MAX(l_shipdate) FROM lineitem) AS date_max FROM lineitem l
4,521.054
3,319.301
{ "Node Type": "WindowAgg", "Total Cost": 438619.49, "Plan Width": 121, "Parallel Aware": false, "Plan Rows": 4499622, "Startup Cost": 0, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 382374.22, "Relation Name": "lineitem", "Plan Widt...
{ "Node Type": "Seq Scan", "Total Cost": 775997.5, "Relation Name": "lineitem", "Plan Width": 121, "Parallel Aware": false, "Plan Rows": 4499622, "Startup Cost": 393623.28, "Alias": "l", "Plans": [ { "Node Type": "Aggregate", "Parent Relationship": "InitPlan", "Total Cost": 39362...
easy
216
tpch
SELECT l.* FROM (SELECT DISTINCT l_orderkey FROM lineitem) orders CROSS JOIN LATERAL (SELECT * FROM lineitem li WHERE li.l_orderkey = orders.l_orderkey ORDER BY li.l_shipdate) l ORDER BY l.l_orderkey, l.l_shipdate;
SELECT * FROM lineitem ORDER BY l_orderkey, l_shipdate;
18,746.462
2,813.266
{ "Node Type": "Sort", "Total Cost": 39481897.87, "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 4499622, "Startup Cost": 39470648.82, "Plans": [ { "Node Type": "Nested Loop", "Parent Relationship": "Outer", "Total Cost": 38419744.71, "Plan Width": 117, "Paralle...
{ "Node Type": "Incremental Sort", "Total Cost": 721966.87, "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 4499622, "Startup Cost": 0.56, "Plans": [ { "Node Type": "Index Scan", "Parent Relationship": "Outer", "Total Cost": 519483.88, "Relation Name": "lineitem", ...
medium
217
tpch
WITH customer_order_flags AS (SELECT o_custkey, BOOL_OR(o_orderdate BETWEEN '1997-01-01' AND '1997-01-31') as has_1997_order FROM orders GROUP BY o_custkey HAVING BOOL_OR(o_orderdate BETWEEN '1997-01-01' AND '1997-01-31')) SELECT o.o_orderdate as order_date, o.o_custkey as customer_key FROM orders o INNER JOIN customer...
SELECT o1.o_orderdate as order_date, o1.o_custkey as customer_key FROM orders o1 WHERE o1.o_orderdate BETWEEN '1998-01-01' AND '1998-01-31' AND EXISTS (SELECT 1 FROM orders o2 WHERE o2.o_orderdate BETWEEN '1997-01-01' AND '1997-01-31' AND o2.o_custkey = o1.o_custkey) ORDER BY customer_key
3,869.957
1,148.321
{ "Node Type": "Sort", "Total Cost": 589610.55, "Plan Width": 8, "Parallel Aware": false, "Plan Rows": 28682, "Startup Cost": 589538.85, "Plans": [ { "Node Type": "Hash Join", "Parent Relationship": "Outer", "Total Cost": 587415.25, "Plan Width": 8, "Parallel Aware": fals...
{ "Node Type": "Sort", "Total Cost": 293764.05, "Plan Width": 8, "Parallel Aware": false, "Plan Rows": 12695, "Startup Cost": 293732.32, "Plans": [ { "Node Type": "Hash Join", "Parent Relationship": "Outer", "Total Cost": 292867.03, "Plan Width": 8, "Parallel Aware": fals...
medium
218
tpch
SELECT l_shipdate as date, SUM(l_extendedprice) AS Attempt_amount, success_agg.Success_amount FROM lineitem CROSS JOIN (SELECT SUM(l_extendedprice) AS Success_amount FROM lineitem WHERE l_returnflag = 'R') success_agg GROUP BY l_shipdate, success_agg.Success_amount;
SELECT l_shipdate as date, SUM(l_extendedprice) AS Attempt_amount, (SELECT SUM(l_extendedprice) FROM lineitem WHERE l_returnflag = 'R') AS Success_amount FROM lineitem GROUP BY l_shipdate;
5,505.084
4,193.929
{ "Node Type": "Aggregate", "Total Cost": 857565.38, "Plan Width": 68, "Parallel Aware": false, "Plan Rows": 2507, "Strategy": "Hashed", "Startup Cost": 857534.04, "Plans": [ { "Node Type": "Nested Loop", "Parent Relationship": "Outer", "Total Cost": 823786.88, "Plan Width": ...
{ "Node Type": "Aggregate", "Total Cost": 801320.09, "Plan Width": 68, "Parallel Aware": false, "Plan Rows": 2507, "Strategy": "Hashed", "Startup Cost": 801288.76, "Plans": [ { "Node Type": "Aggregate", "Parent Relationship": "InitPlan", "Total Cost": 396416.43, "Plan Width":...
easy
219
tpch
SELECT s.s_suppkey as warehouse_id, CONCAT(n.n_name, ': ', s.s_name) as warehouse_name, COUNT(o.o_orderkey) as number_of_orders, (SELECT COUNT(*) FROM orders) as total_orders, CASE WHEN COUNT(o.o_orderkey)/(SELECT COUNT(*) FROM orders) <= 0.20 THEN 'fulfilled 0-20% of Orders' WHEN...
WITH total_orders AS ( SELECT COUNT(*) as total_count FROM orders ) SELECT s.s_suppkey as warehouse_id, CONCAT(n.n_name, ': ', s.s_name) as warehouse_name, COUNT(o.o_orderkey) as number_of_orders, t.total_count as total_orders, CASE WHEN COUNT(o.o_orderkey)::decimal / t.total_count <= 0.20 ...
3,073.857
2,363.605
{ "Node Type": "Aggregate", "Total Cost": 489452.18, "Plan Width": 84, "Parallel Aware": false, "Plan Rows": 163873, "Strategy": "Sorted", "Startup Cost": 405630.54, "Plans": [ { "Node Type": "Aggregate", "Parent Relationship": "InitPlan", "Total Cost": 101406.94, "Plan Width...
{ "Node Type": "Aggregate", "Total Cost": 188064.47, "Plan Width": 84, "Parallel Aware": false, "Plan Rows": 163873, "Strategy": "Sorted", "Startup Cost": 101409.73, "Plans": [ { "Node Type": "Incremental Sort", "Parent Relationship": "Outer", "Total Cost": 166761.01, "Plan W...
hard
220
tpch
WITH return_count AS (SELECT COUNT(l_returnflag) AS cnt FROM lineitem WHERE l_returnflag = 'R'), ship_count AS (SELECT COUNT(l_shipdate) AS cnt FROM lineitem WHERE l_shipdate BETWEEN '1992-01-01' AND '1998-12-31') SELECT return_count.cnt * 100 / ship_count.cnt FROM return_count, ship_count;
SELECT (COUNT(l_returnflag) FILTER (WHERE l_returnflag = 'R') * 100) / COUNT(l_shipdate) FILTER (WHERE l_shipdate BETWEEN '1992-01-01' AND '1998-12-31') FROM lineitem;
3,531.413
2,134.269
{ "Node Type": "Nested Loop", "Total Cost": 812535.63, "Plan Width": 8, "Parallel Aware": false, "Plan Rows": 1, "Startup Cost": 812535.58, "Plans": [ { "Node Type": "Aggregate", "Parent Relationship": "Outer", "Total Cost": 396416.43, "Plan Width": 8, "Parallel Aware": f...
{ "Node Type": "Aggregate", "Total Cost": 438619.51, "Plan Width": 8, "Parallel Aware": false, "Plan Rows": 1, "Strategy": "Plain", "Startup Cost": 438619.49, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 382374.22, "Relation Name": "line...
medium
221
tpch
SELECT * FROM lineitem WHERE l_linenumber = 1 UNION ALL SELECT * FROM lineitem WHERE l_linenumber = 2;
SELECT * FROM lineitem WHERE l_linenumber IN (1, 2);
2,311.768
1,306.304
{ "Node Type": "Append", "Total Cost": 806489.18, "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 1282842, "Startup Cost": 0, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Member", "Total Cost": 393623.28, "Relation Name": "lineitem", "Plan Width"...
{ "Node Type": "Seq Scan", "Total Cost": 393623.28, "Relation Name": "lineitem", "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 1282842, "Startup Cost": 0, "Alias": "lineitem" }
easy
222
tpch
SELECT t1.c_custkey as E_ID, t1.c_nationkey as D_ID, t1.c_comment as email, t2.n_nationkey as D_ID2, t2.n_name as D_NAME FROM customer t1 LEFT JOIN LATERAL (SELECT n_nationkey, n_name FROM nation WHERE n_name = t1.c_comment LIMIT 1) t2 ON true
SELECT c.c_custkey as E_ID, c.c_nationkey as D_ID, c.c_comment as email, n.n_nationkey as D_ID2, n.n_name as D_NAME FROM customer c LEFT JOIN (SELECT n_nationkey, n_name, ROW_NUMBER() OVER (PARTITION BY n_name ORDER BY n_nationkey) as rn FROM nation) n ON c.c_comment = n.n_name AND n.rn = 1
1,381.252
182.679
{ "Node Type": "Nested Loop", "Total Cost": 5480500, "Plan Width": 189, "Parallel Aware": false, "Plan Rows": 450000, "Startup Cost": 0, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 15250, "Relation Name": "customer", "Plan Width": 8...
{ "Node Type": "Hash Join", "Total Cost": 16961.05, "Plan Width": 189, "Parallel Aware": false, "Plan Rows": 450000, "Startup Cost": 23.54, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 15250, "Relation Name": "customer", "Plan Width"...
easy
223
tpch
SELECT c_name AS name, string_agg( CASE length(TRIM((regexp_match(lower(c_comment), 'process\s+explanation\s*:\s*(.*?)(\.\s*final activity|$)', 'i'))[1])) WHEN 0 THEN lower(c_comment) ELSE (regexp_match(lower(c_comment), 'process\s+explanation\s*:\s*(.*?)(\.\s*final activity|$)', 'i'))[1] END, '. ' ) AS final_doc FROM ...
SELECT c_name AS name, string_agg( CASE length(TRIM(match_result)) WHEN 0 THEN lower(c_comment) ELSE match_result END, '. ' ) AS final_doc FROM customer LEFT JOIN LATERAL ( SELECT (regexp_match(lower(c_comment), 'process\s+explanation\s*:\s*(.*?)(\.\s*final activity|$)', 'i'))[1] AS match_result ) AS reg...
6,285.329
4,571.027
{ "Node Type": "Aggregate", "Total Cost": 98576.02, "Plan Width": 51, "Parallel Aware": false, "Plan Rows": 450000, "Strategy": "Sorted", "Startup Cost": 80576.02, "Plans": [ { "Node Type": "Sort", "Parent Relationship": "Outer", "Total Cost": 81701.02, "Plan Width": 92, ...
{ "Node Type": "Aggregate", "Total Cost": 129454.02, "Plan Width": 51, "Parallel Aware": false, "Plan Rows": 450000, "Strategy": "Sorted", "Startup Cost": 115954.02, "Plans": [ { "Node Type": "Sort", "Parent Relationship": "Outer", "Total Cost": 117079.02, "Plan Width": 124, ...
hard
224
tpch
SELECT DISTINCT l_shipdate FROM (SELECT l_shipdate, ROW_NUMBER() OVER (PARTITION BY l_shipdate ORDER BY l_shipdate) as rn FROM lineitem) t WHERE rn = 1;
SELECT l_shipdate FROM lineitem GROUP BY l_shipdate;
4,841.748
2,148.042
{ "Node Type": "Unique", "Total Cost": 1148946.29, "Plan Width": 4, "Parallel Aware": false, "Plan Rows": 2507, "Startup Cost": 1002652.33, "Plans": [ { "Node Type": "Subquery Scan", "Parent Relationship": "Outer", "Total Cost": 1148890.04, "Plan Width": 4, "Parallel Awar...
{ "Node Type": "Aggregate", "Total Cost": 393648.34, "Plan Width": 4, "Parallel Aware": false, "Plan Rows": 2507, "Strategy": "Hashed", "Startup Cost": 393623.27, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 382374.22, "Relation Name": "...
easy
225
tpch
SELECT c.C_CUSTKEY AS USERID, COUNT(*) AS COUNT, SUM(CASE WHEN l.L_RETURNFLAG = 'N' THEN l.L_EXTENDEDPRICE ELSE 0 END) AS SUM FROM CUSTOMER c INNER JOIN LINEITEM l ON c.C_CUSTKEY = l.L_SUPPKEY AND l.L_SHIPDATE > DATE '1992-01-01' GROUP BY c.C_CUSTKEY ORDER BY c.C_CUSTKEY;
WITH lineitem_agg AS (SELECT L_SUPPKEY, COUNT(*) AS count, SUM(CASE WHEN L_RETURNFLAG = 'N' THEN L_EXTENDEDPRICE ELSE 0 END) AS sum FROM LINEITEM WHERE L_SHIPDATE > DATE '1992-01-01' GROUP BY L_SUPPKEY) SELECT c.C_CUSTKEY AS USERID, l.count AS COUNT, l.sum AS SUM FROM CUSTOMER c INNER JOIN lineitem_agg l ON l.L_SUPPKEY...
5,717.211
4,305.908
{ "Node Type": "Sort", "Total Cost": 887718.94, "Plan Width": 44, "Parallel Aware": false, "Plan Rows": 450000, "Startup Cost": 886593.94, "Plans": [ { "Node Type": "Aggregate", "Parent Relationship": "Outer", "Total Cost": 830493.92, "Plan Width": 44, "Parallel Aware": f...
{ "Node Type": "Merge Join", "Total Cost": 764409.66, "Plan Width": 44, "Parallel Aware": false, "Plan Rows": 29574, "Startup Cost": 751147.05, "Plans": [ { "Node Type": "Index Only Scan", "Parent Relationship": "Outer", "Total Cost": 11694.42, "Relation Name": "customer", ...
hard
226
tpch
SELECT * FROM lineitem WHERE l_returnflag IN ('A', 'R') AND l_linestatus <> l_returnflag AND l_linestatus NOT IN ('A', 'R') UNION ALL SELECT * FROM lineitem WHERE l_returnflag NOT IN ('A', 'R') AND l_linestatus <> l_returnflag AND l_linestatus IN ('A', 'R')
SELECT * FROM lineitem WHERE (l_returnflag IN ('A', 'R') AND l_linestatus <> l_returnflag AND l_linestatus NOT IN ('A', 'R')) OR (l_returnflag NOT IN ('A', 'R') AND l_linestatus <> l_returnflag AND l_linestatus IN ('A', 'R'))
3,593.579
2,284.765
{ "Node Type": "Append", "Total Cost": 865463.05, "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 2214685, "Startup Cost": 0, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Member", "Total Cost": 416121.39, "Relation Name": "lineitem", "Plan Width"...
{ "Node Type": "Seq Scan", "Total Cost": 438619.49, "Relation Name": "lineitem", "Plan Width": 117, "Parallel Aware": false, "Plan Rows": 2214684, "Startup Cost": 0, "Alias": "lineitem" }
medium
227
tpch
SELECT c_name, first_nationkey AS c_nationkey, first_acctbal AS c_acctbal FROM (SELECT DISTINCT c_name, FIRST_VALUE(c_nationkey) OVER (PARTITION BY c_name ORDER BY c_nationkey, c_acctbal) AS first_nationkey, FIRST_VALUE(c_acctbal) OVER (PARTITION BY c_name ORDER BY c_nationkey, c_acctbal) AS first_acctbal FROM customer...
SELECT c_name, c_nationkey, c_acctbal FROM ( SELECT c_name, c_nationkey, c_acctbal, ROW_NUMBER() OVER (PARTITION BY c_name ORDER BY c_nationkey, c_acctbal) AS rn FROM customer ) AS subquery WHERE rn = 1
3,495.998
2,709.574
{ "Node Type": "Subquery Scan", "Total Cost": 149236.54, "Plan Width": 55, "Parallel Aware": false, "Plan Rows": 450000, "Startup Cost": 140236.54, "Alias": "subq", "Plans": [ { "Node Type": "Unique", "Parent Relationship": "Subquery", "Total Cost": 144736.54, "Plan Width": 6...
{ "Node Type": "Subquery Scan", "Total Cost": 84023.52, "Plan Width": 29, "Parallel Aware": false, "Plan Rows": 2250, "Startup Cost": 68273.52, "Alias": "subquery", "Plans": [ { "Node Type": "WindowAgg", "Parent Relationship": "Subquery", "Total Cost": 78398.52, "Plan Width":...
easy
228
tpch
WITH supply_costs AS (SELECT ps_supplycost FROM partsupp) SELECT ps_supplycost + 10 AS cust_price FROM supply_costs
SELECT ps_supplycost + 10 AS cust_price FROM partsupp LIMIT ALL
1,031.384
719.43
{ "Node Type": "Seq Scan", "Total Cost": 82321.69, "Relation Name": "partsupp", "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 2399655, "Startup Cost": 0, "Alias": "partsupp" }
{ "Node Type": "Seq Scan", "Total Cost": 82321.69, "Relation Name": "partsupp", "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 2399655, "Startup Cost": 0, "Alias": "partsupp" }
medium
229
solar_panel
SELECT COUNT(DISTINCT(snapkey)) FROM plant_record WHERE sitetie IN ('113', '50')
SELECT COUNT(*) FROM plant_record WHERE sitetie IN ('113', '50')
0.221
0.173
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 19.5, "Strategy": "Plain", "Plan Width": 8, "Parallel Aware": false, "Total Cost": 19.51, "Plan Rows": 1, "Plans": [ { "Async Capable": false, "Node Type": "Sort", "Parent Relationship": "Outer", "Startup C...
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 19.48, "Strategy": "Plain", "Plan Width": 8, "Parallel Aware": false, "Total Cost": 19.49, "Plan Rows": 1, "Plans": [ { "Relation Name": "plant_record", "Alias": "plant_record", "Async Capable": false, "Nod...
hard
230
robot_fault_prediction
WITH excluded_ops AS (SELECT operreg FROM operation WHERE apptypeval = 'xxxx') SELECT o1.* FROM operation o1 LEFT JOIN excluded_ops e ON o1.operreg = e.operreg WHERE e.operreg IS NULL
SELECT * FROM operation WHERE operreg NOT IN (SELECT operreg FROM operation WHERE apptypeval = 'xxxx')
0.622
0.365
{ "Async Capable": false, "Node Type": "Hash Join", "Startup Cost": 27.51, "Plan Width": 87, "Parallel Aware": false, "Total Cost": 65.13, "Plan Rows": 999, "Plans": [ { "Relation Name": "operation", "Alias": "o1", "Async Capable": false, "Node Type": "Seq Scan", "Paren...
{ "Relation Name": "operation", "Alias": "operation", "Async Capable": false, "Node Type": "Seq Scan", "Startup Cost": 27.5, "Plan Width": 87, "Parallel Aware": false, "Total Cost": 55, "Plan Rows": 500, "Plans": [ { "Relation Name": "operation", "Alias": "operation_1", "Async ...
medium
231
solar_panel
WITH cte AS MATERIALIZED (SELECT plant_record.snapts AS Age, plants.docstate AS Gender, plants.envtag AS Country FROM plant_record JOIN plants ON plant_record.sitetie = plants.sitekey) SELECT Age, Gender, Country FROM cte GROUP BY Age, Gender, Country
SELECT DISTINCT pr.snapts AS Age, p.docstate AS Gender, p.envtag AS Country FROM plant_record pr JOIN plants p ON pr.sitetie = p.sitekey
1.81
1.386
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 86.18, "Strategy": "Hashed", "Plan Width": 72, "Parallel Aware": false, "Total Cost": 88.18, "Plan Rows": 200, "Plans": [ { "Async Capable": false, "Node Type": "Hash Join", "Parent Relationship": "InitPlan", ...
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 66.22, "Strategy": "Hashed", "Plan Width": 21, "Parallel Aware": false, "Total Cost": 76.2, "Plan Rows": 998, "Plans": [ { "Async Capable": false, "Node Type": "Hash Join", "Parent Relationship": "Outer", "...
easy
232
solar_panel
SELECT * FROM plant_record WHERE snapts::date >= '2000-01-01' AND snapts::date <= '2999-12-12';
SELECT * FROM plant_record WHERE snapts >= '2000-01-01 00:00:00'::timestamp AND snapts < '2999-12-13 00:00:00'::timestamp;
0.292
0.221
{ "Relation Name": "plant_record", "Alias": "plant_record", "Async Capable": false, "Node Type": "Seq Scan", "Startup Cost": 0, "Plan Width": 24, "Parallel Aware": false, "Total Cost": 26.96, "Plan Rows": 5 }
{ "Relation Name": "plant_record", "Alias": "plant_record", "Async Capable": false, "Node Type": "Seq Scan", "Startup Cost": 0, "Plan Width": 24, "Parallel Aware": false, "Total Cost": 21.97, "Plan Rows": 998 }
medium
233
solar_panel
SELECT sitekey AS id, sitelabel AS forename, sitelabel AS surname FROM (SELECT sitekey, sitelabel, COUNT(*) OVER (PARTITION BY sitelabel) as label_count FROM plants) sub WHERE label_count > 1
SELECT y.sitekey AS id, y.sitelabel AS forename, y.sitelabel AS surname FROM plants y INNER JOIN (SELECT sitelabel, COUNT(*) AS CountOf FROM plants GROUP BY sitelabel HAVING COUNT(*) > 1) dt ON y.sitelabel = dt.sitelabel
3.928
1.015
{ "Alias": "sub", "Async Capable": false, "Node Type": "Subquery Scan", "Startup Cost": 73.75, "Plan Width": 57, "Parallel Aware": false, "Total Cost": 99.58, "Plan Rows": 939, "Plans": [ { "Async Capable": false, "Node Type": "WindowAgg", "Parent Relationship": "Subquery", ...
{ "Async Capable": false, "Node Type": "Hash Join", "Startup Cost": 50.49, "Plan Width": 57, "Parallel Aware": false, "Total Cost": 80.36, "Plan Rows": 313, "Plans": [ { "Relation Name": "plants", "Alias": "y", "Async Capable": false, "Node Type": "Seq Scan", "Parent Re...
medium
234
robot_fault_prediction
SELECT slot FROM (SELECT gs.slot FROM generate_series(0, 8) gs(slot) EXCEPT SELECT axiscountval FROM operation) missing ORDER BY slot LIMIT 5;
SELECT gs.slot FROM generate_series(0, 8) gs(slot) WHERE NOT EXISTS ( SELECT 1 FROM operation o WHERE o.axiscountval = gs.slot ) ORDER BY gs.slot LIMIT 5;
0.624
0.411
{ "Async Capable": false, "Node Type": "Limit", "Startup Cost": 42.92, "Plan Width": 8, "Parallel Aware": false, "Total Cost": 42.93, "Plan Rows": 5, "Plans": [ { "Async Capable": false, "Node Type": "Sort", "Parent Relationship": "Outer", "Startup Cost": 42.92, "Plan W...
{ "Async Capable": false, "Node Type": "Limit", "Startup Cost": 37.73, "Plan Width": 4, "Parallel Aware": false, "Total Cost": 37.75, "Plan Rows": 5, "Plans": [ { "Async Capable": false, "Node Type": "Sort", "Parent Relationship": "Outer", "Startup Cost": 37.73, "Plan W...
medium
235
robot_fault_prediction
WITH daily_metrics AS (SELECT DATE(r.rects) as mdate, o.operreg, MAX(o.totopshrval) as max_totopshr FROM operation o JOIN robot_record r ON o.operrecref = r.botcode WHERE o.totopshrval IS NOT NULL GROUP BY DATE(r.rects), o.operreg) SELECT mdate, MAX(CASE WHEN operreg LIKE '%1%' THEN max_totopshr END) as value1, MAX(CAS...
WITH filtered_data AS (SELECT o.operreg, o.totopshrval, r.rects FROM operation o JOIN robot_record r ON o.operrecref = r.botcode WHERE o.totopshrval IS NOT NULL) SELECT DATE(rects) as mdate, MAX(totopshrval) FILTER (WHERE operreg LIKE '%1%') as value1, MAX(totopshrval) FILTER (WHERE operreg LIKE '%2%') as value2 FROM f...
1.015
0.8
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 71.62, "Strategy": "Hashed", "Plan Width": 12, "Parallel Aware": false, "Total Cost": 73.62, "Plan Rows": 200, "Plans": [ { "Async Capable": false, "Node Type": "Aggregate", "Parent Relationship": "Outer", ...
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 61.94, "Strategy": "Hashed", "Plan Width": 12, "Parallel Aware": false, "Total Cost": 61.96, "Plan Rows": 2, "Plans": [ { "Async Capable": false, "Node Type": "Hash Join", "Parent Relationship": "Outer", "S...
medium
236
solar_panel
SELECT DISTINCT inspectmode as Category, FIRST_VALUE(inspectres) OVER (PARTITION BY inspectmode ORDER BY inspectres) as Details FROM inspection;
SELECT inspectmode as Category, (array_agg(inspectres ORDER BY inspectres))[1] as Details FROM inspection GROUP BY inspectmode;
0.184
0.14
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 1.18, "Strategy": "Hashed", "Plan Width": 96, "Parallel Aware": false, "Total Cost": 1.22, "Plan Rows": 4, "Plans": [ { "Async Capable": false, "Node Type": "WindowAgg", "Parent Relationship": "Outer", "Sta...
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 1.08, "Strategy": "Sorted", "Plan Width": 64, "Parallel Aware": false, "Total Cost": 1.16, "Plan Rows": 4, "Plans": [ { "Async Capable": false, "Node Type": "Sort", "Parent Relationship": "Outer", "Startup ...
easy
237
solar_panel
SELECT COUNT(Reg) as Reg FROM ( SELECT COUNT(*) AS Reg FROM ( SELECT pr.sitetie, COUNT(*) OVER (PARTITION BY pr.sitetie) as cnt FROM plant_record pr JOIN plants p ON pr.sitetie = p.sitekey JOIN operational_metrics om ON pr.snapkey = om.snapops JOIN alert a ON pr.snapke...
WITH plant_filter AS ( SELECT sitekey FROM plants WHERE docstate IN ('1','5','7') AND sitekey NOT IN ('7','13') AND goliveon IS NULL ), record_filter AS ( SELECT sitetie, snapkey FROM plant_record WHERE snapts BETWEEN CURRENT_DATE - INTERVAL '21 days' AND CURRENT_DATE - INTERVAL '7 ...
0.345
0.274
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 57.01, "Strategy": "Plain", "Plan Width": 8, "Parallel Aware": false, "Total Cost": 57.02, "Plan Rows": 1, "Plans": [ { "Async Capable": false, "Node Type": "Aggregate", "Parent Relationship": "Outer", "Sta...
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 56.99, "Strategy": "Plain", "Plan Width": 8, "Parallel Aware": false, "Total Cost": 57, "Plan Rows": 1, "Plans": [ { "Async Capable": false, "Node Type": "Aggregate", "Parent Relationship": "Outer", "Startu...
hard
238
solar_panel
WITH daily_data AS (SELECT a.alrtstate, a.alrtcnt, EXTRACT(DOW FROM pr.snapts) AS day_of_week FROM alert a JOIN plant_record pr ON a.snapalrt = pr.snapkey) SELECT alrtstate AS Action, alrtcnt AS Strength, MAX(CASE WHEN day_of_week = 0 THEN 'Y' ELSE 'N' END) AS Sunday, MAX(CASE WHEN day_of_week = 1 THEN 'Y' ELSE 'N' END...
SELECT alrtstate AS Action, alrtcnt AS Strength, COALESCE(MAX('Y') FILTER (WHERE EXTRACT(DOW FROM pr.snapts) = 0), 'N') AS Sunday, COALESCE(MAX('Y') FILTER (WHERE EXTRACT(DOW FROM pr.snapts) = 1), 'N') AS Monday, COALESCE(MAX('Y') FILTER (WHERE EXTRACT(DOW FROM pr.snapts) = 2), 'N') AS Tuesday, COALESCE(MAX('Y') FILTER...
3.234
2.542
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 107.45, "Strategy": "Hashed", "Plan Width": 241, "Parallel Aware": false, "Total Cost": 107.67, "Plan Rows": 22, "Plans": [ { "Async Capable": false, "Node Type": "Hash Join", "Parent Relationship": "Outer", ...
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 107.45, "Strategy": "Hashed", "Plan Width": 241, "Parallel Aware": false, "Total Cost": 107.67, "Plan Rows": 22, "Plans": [ { "Async Capable": false, "Node Type": "Hash Join", "Parent Relationship": "Outer", ...
hard
239
polar_equipment
WITH filtered_maintenance AS ( SELECT "equipRef", BOOL_OR("OP_MAINT_ID" = 1 AND "LAST_maint_date" < CURRENT_DATE - INTERVAL '1 week') as has_recent_maint, BOOL_OR("OP_MAINT_ID" = 2) as has_maint_id_2 FROM "OperationMaintenance" WHERE ("OP_MAINT_ID" = 1 AND "LAST_maint_date" < CURRENT_DATE - ...
WITH maintenance_flags AS ( SELECT "equipRef", MAX(CASE WHEN "OP_MAINT_ID" = 1 AND "LAST_maint_date" < CURRENT_DATE - INTERVAL '1 week' THEN 1 ELSE 0 END) as has_recent_maint, MAX(CASE WHEN "OP_MAINT_ID" = 2 THEN 1 ELSE 0 END) as has_maint_id_2 FROM "OperationMaintenance" WHERE "OP_MAINT_ID"...
0.205
0.151
{ "Async Capable": false, "Node Type": "Nested Loop", "Startup Cost": 14.63, "Plan Width": 61, "Parallel Aware": false, "Total Cost": 22.74, "Plan Rows": 1, "Plans": [ { "Async Capable": false, "Node Type": "Aggregate", "Parent Relationship": "Outer", "Startup Cost": 14.35, ...
{ "Async Capable": false, "Node Type": "Nested Loop", "Startup Cost": 12.87, "Plan Width": 61, "Parallel Aware": false, "Total Cost": 20.99, "Plan Rows": 1, "Plans": [ { "Async Capable": false, "Node Type": "Aggregate", "Parent Relationship": "Outer", "Startup Cost": 12.6, ...
hard
240
solar_panel
WITH max_snapts AS ( SELECT MAX(snapts) AS max_ts FROM plant_record ), recent_period AS ( SELECT pr.snapkey, pr.sitetie, om.maintcost::text FROM plant_record pr JOIN operational_metrics om ON pr.snapkey = om.snapops CROSS JOIN max_snapts ms WHERE pr.snapts >= ms.max_ts - INTERVAL '7 days' ), pre...
SELECT DISTINCT pr.snapkey AS REPORT_ID, pr.sitetie AS USER_ID, om.maintcost::text AS CLIENT_ID FROM plant_record pr JOIN operational_metrics om ON pr.snapkey = om.snapops LEFT JOIN ( SELECT pr_old.snapkey, pr_old.sitetie, om_old.maintcost::text FROM plant_record pr_old JOIN operational_metrics ...
2.356
1.765
{ "Alias": "new_records", "Async Capable": false, "Node Type": "Subquery Scan", "Startup Cost": 55.62, "Plan Width": 96, "Parallel Aware": false, "Total Cost": 164.17, "Plan Rows": 333, "Plans": [ { "Async Capable": false, "Node Type": "Aggregate", "Parent Relationship": "InitPla...
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 151.61, "Strategy": "Hashed", "Plan Width": 48, "Parallel Aware": false, "Total Cost": 156.29, "Plan Rows": 312, "Plans": [ { "Async Capable": false, "Node Type": "Aggregate", "Parent Relationship": "InitPlan", ...
hard
241
robot_fault_prediction
WITH materialized_data AS MATERIALIZED ( SELECT actrecref, payloadwval FROM actuation_data ) SELECT actrecref, sum(payloadwval) FROM materialized_data GROUP BY actrecref HAVING sum(payloadwval) > 10;
WITH all_data AS ( SELECT actrecref, payloadwval FROM actuation_data ) SELECT actrecref, sum(payloadwval) FROM all_data GROUP BY actrecref HAVING sum(payloadwval) > 10;
1.038
0.691
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 53, "Strategy": "Hashed", "Plan Width": 36, "Parallel Aware": false, "Total Cost": 55.5, "Plan Rows": 67, "Plans": [ { "Relation Name": "actuation_data", "Alias": "actuation_data", "Async Capable": false, "...
{ "Async Capable": false, "Node Type": "Aggregate", "Startup Cost": 33, "Strategy": "Hashed", "Plan Width": 11, "Parallel Aware": false, "Total Cost": 44.89, "Plan Rows": 317, "Plans": [ { "Relation Name": "actuation_data", "Alias": "actuation_data", "Async Capable": false, ...
medium
242
solar_panel
SELECT DISTINCT cap_mw AS col_name, COUNT(cap_mw) OVER(PARTITION BY cap_mw) AS count FROM plants WHERE cap_mw IS NOT NULL
WITH filtered_plants AS (SELECT cap_mw FROM plants WHERE cap_mw IS NOT NULL) SELECT cap_mw AS col_name, COUNT(*) AS count FROM filtered_plants GROUP BY cap_mw
1.401
0.7
{ "Startup Cost": 94.88, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 12, "Parallel Aware": false, "Plan Rows": 931, "Total Cost": 104.19, "Plans": [ { "Startup Cost": 73.75, "Async Capable": false, "Node Type": "WindowAgg", "Plan Wi...
{ "Startup Cost": 32.09, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 12, "Parallel Aware": false, "Plan Rows": 931, "Total Cost": 41.4, "Plans": [ { "Relation Name": "plants", "Alias": "plants", "Startup Cost": 0, "Async Capable": f...
easy
243
robot_fault_prediction
SELECT ID, column1, column2 FROM (SELECT recreg AS ID, width_bucket(EXTRACT(EPOCH FROM rects), 0, 1000000000, 10) AS column1, botcode AS column2, ROW_NUMBER() OVER (PARTITION BY recreg, botcode, width_bucket(EXTRACT(EPOCH FROM rects), 0, 1000000000, 10)) AS rn FROM robot_record) sub WHERE rn = 1
SELECT DISTINCT recreg AS ID, computed_bucket AS column1, botcode AS column2 FROM (SELECT recreg, botcode, width_bucket(EXTRACT(EPOCH FROM rects), 0, 1000000000, 10) AS computed_bucket FROM robot_record) AS sub
2.644
1.032
{ "Alias": "sub", "Startup Cost": 68.31, "Async Capable": false, "Node Type": "Subquery Scan", "Plan Width": 20, "Parallel Aware": false, "Plan Rows": 5, "Total Cost": 106.35, "Plans": [ { "Startup Cost": 68.31, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width"...
{ "Startup Cost": 28.4, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 20, "Parallel Aware": false, "Plan Rows": 951, "Total Cost": 42.66, "Plans": [ { "Relation Name": "robot_record", "Alias": "robot_record", "Startup Cost": 0, "Async...
medium
244
solar_panel
SELECT (COUNT(*) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)) as grp, * FROM plant_record
SELECT (row_number() OVER ()) as grp, * FROM plant_record
0.538
0.408
{ "Startup Cost": 0, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 998, "Total Cost": 29.46, "Plans": [ { "Relation Name": "plant_record", "Alias": "plant_record", "Startup Cost": 0, "Async Capable": false, "No...
{ "Startup Cost": 0, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 998, "Total Cost": 29.46, "Plans": [ { "Relation Name": "plant_record", "Alias": "plant_record", "Startup Cost": 0, "Async Capable": false, "No...
hard
245
polar_equipment
WITH maintenance_agg AS ( SELECT "OPER_status", "LAST_maint_date", sum("MAINT_COST_usd") as total_cost FROM "OperationMaintenance" GROUP BY "OPER_status", "LAST_maint_date" ) SELECT "OPER_status" as status, total_cost as sum_amount, "LAST_maint_date" as transaction_date FROM maintenance_agg
SELECT "OPER_status" as status, sum("MAINT_COST_usd") as sum_amount, "LAST_maint_date" as transaction_date FROM "OperationMaintenance" GROUP BY "OPER_status", "LAST_maint_date"
0.853
0.637
{ "Alias": "maintenance_agg", "Startup Cost": 29.03, "Async Capable": false, "Node Type": "Subquery Scan", "Plan Width": 16, "Parallel Aware": false, "Plan Rows": 314, "Total Cost": 35.31, "Plans": [ { "Startup Cost": 29.03, "Async Capable": false, "Node Type": "Aggregate", ...
{ "Startup Cost": 29.03, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 16, "Parallel Aware": false, "Plan Rows": 314, "Total Cost": 32.17, "Plans": [ { "Relation Name": "OperationMaintenance", "Alias": "OperationMaintenance", "Startup Cost"...
easy
246
polar_equipment
SELECT ds_month, unique_stations * 1.0 / total_records as retention_rate FROM ( SELECT DATE_TRUNC('month', "TimeStamp") as ds_month, COUNT(DISTINCT "STATION_name") as unique_stations, COUNT(*) as total_records FROM "Location" GROUP BY DATE_TRUNC('month', "TimeStamp") ) aggr...
SELECT DATE_TRUNC('month', "TimeStamp") as ds_month, CASE WHEN COUNT(*) > 0 THEN COUNT(DISTINCT "STATION_name") * 1.0 / COUNT(*) ELSE 0 END as retention_rate FROM "Location" GROUP BY DATE_TRUNC('month', "TimeStamp")
0.198
0.138
{ "Alias": "aggregated", "Startup Cost": 1.6800000000000002, "Async Capable": false, "Node Type": "Subquery Scan", "Plan Width": 40, "Parallel Aware": false, "Plan Rows": 20, "Total Cost": 2.33, "Plans": [ { "Startup Cost": 1.6800000000000002, "Async Capable": false, "Node Type":...
{ "Startup Cost": 1.6800000000000002, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Sorted", "Plan Width": 40, "Parallel Aware": false, "Plan Rows": 20, "Total Cost": 2.38, "Plans": [ { "Startup Cost": 1.6800000000000002, "Async Capable": false, "Node Type": "Sor...
medium
247
polar_equipment
WITH distinct_equip_types AS ( SELECT DISTINCT "EQUIP_CODE", "EquipType" FROM "Equipment" ) SELECT "EQUIP_CODE" as col1, array_agg("EquipType") as col2, cardinality(array_agg("EquipType")) as count FROM distinct_equip_types GROUP BY "EQUIP_CODE" ORDER BY "EQUIP_CODE"
SELECT "EQUIP_CODE" as col1, array_agg(DISTINCT "EquipType") as col2, cardinality(array_agg(DISTINCT "EquipType")) as count FROM "Equipment" GROUP BY "EQUIP_CODE" ORDER BY "EQUIP_CODE"
3.156
2.294
{ "Startup Cost": 52.64, "Async Capable": false, "Node Type": "Sort", "Plan Width": 45, "Parallel Aware": false, "Plan Rows": 200, "Total Cost": 53.14, "Plans": [ { "Startup Cost": 42, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width":...
{ "Startup Cost": 71.83, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Sorted", "Plan Width": 45, "Parallel Aware": false, "Plan Rows": 1000, "Total Cost": 94.33, "Plans": [ { "Startup Cost": 71.83, "Async Capable": false, "Node Type": "Sort", "Plan Width":...
easy
248
polar_equipment
WITH filtered_equipment AS (SELECT "EQUIP_CODE" FROM "Equipment" e WHERE EXISTS (SELECT 1 FROM "OperationMaintenance" om WHERE om."equipRef" = e."EQUIP_CODE")) SELECT fe."EQUIP_CODE" as id, om."OPER_status" as columnA FROM filtered_equipment fe INNER JOIN "OperationMaintenance" om ON om."equipRef" = fe."EQUIP_CODE";
SELECT e."EQUIP_CODE" as id, om."OPER_status" as columnA FROM "Equipment" e INNER JOIN "OperationMaintenance" om ON om."equipRef" = e."EQUIP_CODE";
1.414
0.803
{ "Startup Cost": 67.83, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 17, "Parallel Aware": false, "Plan Rows": 738, "Total Cost": 103.15, "Plans": [ { "Startup Cost": 34.5, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 26, "Parallel...
{ "Startup Cost": 34.5, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 17, "Parallel Aware": false, "Plan Rows": 859, "Total Cost": 59.36, "Plans": [ { "Relation Name": "OperationMaintenance", "Alias": "om", "Startup Cost": 0, "Async Capable": false, "N...
medium
249
robot_fault_prediction
SELECT DISTINCT botcode, COUNT(botcode) OVER (PARTITION BY botcode) as name_count FROM robot_record;
SELECT botcode, COUNT(botcode) as name_count FROM robot_record WHERE botcode IS NOT NULL GROUP BY botcode HAVING COUNT(botcode) >= 1;
1.417
0.629
{ "Startup Cost": 81.53, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 15, "Parallel Aware": false, "Plan Rows": 951, "Total Cost": 91.04, "Plans": [ { "Startup Cost": 0.28, "Async Capable": false, "Node Type": "WindowAgg", "Plan Widt...
{ "Startup Cost": 21.27, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 15, "Parallel Aware": false, "Plan Rows": 317, "Total Cost": 33.15, "Plans": [ { "Relation Name": "robot_record", "Alias": "robot_record", "Startup Cost": 0, "Asyn...
easy
250
solar_panel
SELECT op.* FROM (SELECT DISTINCT pr.snapkey FROM plant_record pr) AS distinct_ids INNER JOIN operational_metrics op ON distinct_ids.snapkey = op.snapops WHERE op.revloss NOT IN ('DELETE');
SELECT op.* FROM plant_record pr INNER JOIN operational_metrics op ON pr.snapkey = op.snapops WHERE COALESCE(op.revloss, '') NOT IN ('DELETE');
1.419
0.866
{ "Startup Cost": 41.93, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 45, "Parallel Aware": false, "Plan Rows": 997, "Total Cost": 67.03, "Plans": [ { "Relation Name": "operational_metrics", "Alias": "op", "Startup Cost": 0, "Async Capable": false, "N...
{ "Startup Cost": 29.46, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 45, "Parallel Aware": false, "Plan Rows": 993, "Total Cost": 54.55, "Plans": [ { "Relation Name": "operational_metrics", "Alias": "op", "Startup Cost": 0, "Async Capable": false, "N...
easy
251
polar_equipment
WITH maker_util_counts AS (SELECT "MakerName", COUNT(CASE WHEN "utilPercent" > 0 THEN 1 END) OVER (PARTITION BY "MakerName") as util_count FROM "Equipment") SELECT DISTINCT "MakerName" as company FROM maker_util_counts WHERE util_count = 0;
SELECT "MakerName" as company FROM (SELECT "MakerName", COUNT(*) as total_count, COUNT(CASE WHEN "utilPercent" > 0 THEN 1 END) as util_count FROM "Equipment" GROUP BY "MakerName") agg WHERE util_count = 0;
1.895
0.637
{ "Startup Cost": 71.83, "Async Capable": false, "Node Type": "Unique", "Plan Width": 17, "Parallel Aware": false, "Plan Rows": 5, "Total Cost": 104.34, "Plans": [ { "Alias": "maker_util_counts", "Startup Cost": 71.83, "Async Capable": false, "Node Type": "Subquery Scan", ...
{ "Alias": "agg", "Startup Cost": 29.5, "Async Capable": false, "Node Type": "Subquery Scan", "Plan Width": 17, "Parallel Aware": false, "Plan Rows": 4, "Total Cost": 39.98, "Plans": [ { "Startup Cost": 29.5, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Ha...
easy
252
robot_fault_prediction
SELECT jperfid, array_agg(jperfoperref) OVER (PARTITION BY jperfid ORDER BY jperfoperref) FROM joint_performance;
SELECT jperfid, array_agg(jperfoperref ORDER BY jperfoperref) FROM joint_performance GROUP BY jperfid;
1.813
1.413
{ "Startup Cost": 143.83, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width": 50, "Parallel Aware": false, "Plan Rows": 1000, "Total Cost": 163.83, "Plans": [ { "Startup Cost": 143.83, "Async Capable": false, "Node Type": "Sort", "Plan Width": 18, "Parallel ...
{ "Startup Cost": 143.83, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Sorted", "Plan Width": 40, "Parallel Aware": false, "Plan Rows": 1000, "Total Cost": 163.83, "Plans": [ { "Startup Cost": 143.83, "Async Capable": false, "Node Type": "Sort", "Plan Widt...
easy
253
robot_fault_prediction
SELECT operation.operreg, actuation_data.actrecref, operation.operrecref, COUNT(*) FROM operation INNER JOIN actuation_data ON operation.operreg = actuation_data.actoperref AND operation.operrecref = actuation_data.actrecref GROUP BY operation.operreg, actuation_data.actrecref, operation.operrecref;
SELECT o.operreg, a.actrecref, o.operrecref, a.count FROM operation o INNER JOIN (SELECT actoperref, actrecref, COUNT(*) AS count FROM actuation_data GROUP BY actoperref, actrecref) a ON o.operreg = a.actoperref AND o.operrecref = a.actrecref;
2.875
1.573
{ "Startup Cost": 73.26, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Sorted", "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 1, "Total Cost": 73.28, "Plans": [ { "Startup Cost": 73.26, "Async Capable": false, "Node Type": "Sort", "Plan Width": 24...
{ "Startup Cost": 70.5, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 1, "Total Cost": 100.75, "Plans": [ { "Relation Name": "operation", "Alias": "o", "Startup Cost": 0, "Async Capable": false, "Node Type": "S...
hard
254
solar_panel
SELECT case_number, name, date_entered FROM (SELECT snapkey as case_number, sitetie as name, snapts as date_entered, ROW_NUMBER() OVER (ORDER BY snapts) as rn FROM plant_record) sub ORDER BY rn
SELECT snapkey as case_number, sitetie as name, snapts as date_entered FROM plant_record ORDER BY snapts
1.098
0.406
{ "Startup Cost": 133.87, "Async Capable": false, "Node Type": "Sort", "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 998, "Total Cost": 136.37, "Plans": [ { "Startup Cost": 66.69, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width": 32, "Parallel Aw...
{ "Startup Cost": 66.69, "Async Capable": false, "Node Type": "Sort", "Plan Width": 24, "Parallel Aware": false, "Plan Rows": 998, "Total Cost": 69.19, "Plans": [ { "Relation Name": "plant_record", "Alias": "plant_record", "Startup Cost": 0, "Async Capable": false, "Nod...
easy
255
polar_equipment
SELECT project, COUNT(DISTINCT staff) AS num_distinct_staff, SUM(cost) AS total_cost FROM (SELECT "EQUIP_CODE" AS project, "MakerName" AS staff, "SERVICE_YRS" AS cost FROM "Equipment" UNION ALL SELECT "EQUIP_CODE" AS project, model_name AS staff, NULL AS cost FROM "Equipment" UNION ALL SELECT "EQUIP_CODE" AS project, "...
SELECT e."EQUIP_CODE" AS project, COUNT(DISTINCT s.staff) AS num_distinct_staff, SUM(s.cost) AS total_cost FROM "Equipment" e CROSS JOIN LATERAL (VALUES ("MakerName", "SERVICE_YRS"), (model_name, NULL), ("EquipType", NULL)) AS s(staff, cost) GROUP BY e."EQUIP_CODE"
7.769
4.88
{ "Startup Cost": 254.26, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Sorted", "Plan Width": 49, "Parallel Aware": false, "Plan Rows": 200, "Total Cost": 286.76, "Plans": [ { "Startup Cost": 254.26, "Async Capable": false, "Node Type": "Sort", "Plan Width...
{ "Startup Cost": 0.45, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Sorted", "Plan Width": 49, "Parallel Aware": false, "Plan Rows": 1000, "Total Cost": 271.05, "Plans": [ { "Startup Cost": 0.45, "Async Capable": false, "Node Type": "Incremental Sort", "P...
hard
256
solar_panel
SELECT DISTINCT p.sitekey, p.sitelabel, (SELECT DISTINCT COUNT(pr.sitetie) FROM plant_record pr WHERE pr.sitetie IS NOT NULL AND p.docstate = 'Laki') AS jumlah_laki, (SELECT DISTINCT COUNT(pr.sitetie) FROM plant_record pr WHERE pr.sitetie IS NOT NULL AND p.docstate = 'Perempuan') AS jumlah_perempuan FROM plants p JOIN ...
SELECT DISTINCT p.sitekey, p.sitelabel, (SELECT COUNT(pr.sitetie) FROM plant_record pr WHERE pr.sitetie IS NOT NULL AND p.docstate = 'Laki') AS jumlah_laki, (SELECT COUNT(pr.sitetie) FROM plant_record pr WHERE pr.sitetie IS NOT NULL AND p.docstate = 'Perempuan') AS jumlah_perempuan FROM plants p JOIN plant_record pr ON...
7.208
4.571
{ "Startup Cost": 147.56, "Async Capable": false, "Node Type": "Unique", "Plan Width": 48, "Parallel Aware": false, "Plan Rows": 939, "Total Cost": 36795.41, "Plans": [ { "Startup Cost": 147.56, "Async Capable": false, "Node Type": "Incremental Sort", "Plan Width": 48, ...
{ "Startup Cost": 147.53, "Async Capable": false, "Node Type": "Unique", "Plan Width": 48, "Parallel Aware": false, "Plan Rows": 939, "Total Cost": 36762.54, "Plans": [ { "Startup Cost": 147.53, "Async Capable": false, "Node Type": "Incremental Sort", "Plan Width": 48, ...
hard
257
solar_panel
WITH sample_data AS MATERIALIZED ( SELECT id, CASE WHEN id <= 50 THEN 0 ELSE id END AS value FROM generate_series(1, 100) AS id ) SELECT id, value, ntile(50) OVER (ORDER BY value) AS ntile_v1, CASE WHEN value = 0 THEN 0 ELSE ntile(50) OVER (ORDER BY value) END AS ntile_v2 FROM ...
WITH sample_data AS ( SELECT id, CASE WHEN id <= 50 THEN 0 ELSE id END AS value FROM generate_series(1, 100) AS id ) SELECT id, value, ntile(50) OVER (ORDER BY value) AS ntile_v1, CASE WHEN value = 0 THEN 0 ELSE ntile(50) OVER (ORDER BY value) END AS ntile_v2 FROM sample_data O...
0.27
0.196
{ "Startup Cost": 11.9, "Async Capable": false, "Node Type": "Sort", "Plan Width": 16, "Parallel Aware": false, "Plan Rows": 100, "Total Cost": 12.15, "Plans": [ { "Alias": "id", "Startup Cost": 0, "Async Capable": false, "Node Type": "Function Scan", "Plan Width": 8, ...
{ "Startup Cost": 10.4, "Async Capable": false, "Node Type": "Sort", "Plan Width": 16, "Parallel Aware": false, "Plan Rows": 100, "Total Cost": 10.65, "Plans": [ { "Startup Cost": 4.57, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width": 16, "Parallel Aware"...
medium
258
solar_panel
SELECT COALESCE(df.sitetie, df1.sitetie, df2.sitetie, df3.sitetie, df4.sitetie, df5.sitetie, df6.sitetie) AS id, df.monday, df1.tuesday, df2.wednesday, df3.thursday, df4.friday, df5.saturday, df6.sunday FROM ( SELECT pr.sitetie, SUM(om.maintcost) AS monday FROM plant_record pr JOIN ...
WITH daily_costs AS ( SELECT pr.sitetie, EXTRACT(DOW FROM pr.snapts) AS day_of_week, SUM(om.maintcost) AS daily_total FROM plant_record pr JOIN operational_metrics om ON pr.snapkey = om.snapops GROUP BY pr.sitetie, EXTRACT(DOW FROM pr.snapts) ) SELECT COALESCE(sitetie) AS id, ...
6.82
2.741
{ "Startup Cost": 313.66, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 60, "Parallel Aware": false, "Plan Rows": 5, "Total Cost": 313.98, "Plans": [ { "Startup Cost": 268.81, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 66, "Paralle...
{ "Startup Cost": 111.95, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 67, "Parallel Aware": false, "Plan Rows": 200, "Total Cost": 113.95, "Plans": [ { "Startup Cost": 62.05, "Async Capable": false, "Node Type": "Aggregate", "Strate...
hard
259
robot_fault_prediction
WITH numbered_records AS (SELECT recreg, botcode, rects, ROW_NUMBER() OVER (ORDER BY recreg) as rn FROM robot_record) SELECT r1.recreg as id, r1.botcode as driver_id, 'operational' as driver_status, r1.rects as cur_time, r2.rects as next_time, EXTRACT(EPOCH FROM (r2.rects - r1.rects)) / 60 as timespent_in_minutes FROM ...
WITH ordered_records AS (SELECT recreg, botcode, rects FROM robot_record ORDER BY recreg) SELECT recreg as id, botcode as driver_id, 'operational' as driver_status, rects as cur_time, LEAD(rects) OVER (ORDER BY recreg) as next_time, EXTRACT(EPOCH FROM (LEAD(rects) OVER (ORDER BY recreg) - rects)) / 60 as timespent_in_m...
3.564
2.32
{ "Startup Cost": 607.05, "Async Capable": false, "Node Type": "Sort", "Plan Width": 144, "Parallel Aware": false, "Plan Rows": 4522, "Total Cost": 618.36, "Plans": [ { "Startup Cost": 63.55, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width": 32, "Parallel ...
{ "Startup Cost": 63.55, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width": 96, "Parallel Aware": false, "Plan Rows": 951, "Total Cost": 87.33, "Plans": [ { "Startup Cost": 63.55, "Async Capable": false, "Node Type": "Sort", "Plan Width": 24, "Parallel Awar...
medium
260
solar_panel
SELECT COUNT(*) FILTER (WHERE sitetie = 'Bob' AND DATE(snapts) = CURRENT_DATE) AS count_called_bob FROM plant_record
SELECT COUNT(*) count_called_bob FROM plant_record WHERE sitetie = 'Bob' AND DATE(snapts) = CURRENT_DATE
0.245
0.152
{ "Startup Cost": 29.46, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Plain", "Plan Width": 8, "Parallel Aware": false, "Plan Rows": 1, "Total Cost": 29.47, "Plans": [ { "Relation Name": "plant_record", "Alias": "plant_record", "Startup Cost": 0, "Async Ca...
{ "Startup Cost": 26.96, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Plain", "Plan Width": 8, "Parallel Aware": false, "Plan Rows": 1, "Total Cost": 26.97, "Plans": [ { "Relation Name": "plant_record", "Alias": "plant_record", "Startup Cost": 0, "Async Ca...
easy
261
robot_fault_prediction
SELECT customer, product FROM ( SELECT mfgnameval AS customer, modelseriesval AS product, ROW_NUMBER() OVER (ORDER BY mfgnameval, modelseriesval) as rn FROM robot_details ) AS ordered_data ORDER BY rn;
WITH customer_products AS ( SELECT mfgnameval AS customer, modelseriesval AS product FROM robot_details ) SELECT customer, product FROM customer_products ORDER BY customer, product;
2.683
2.122
{ "Startup Cost": 135.62, "Async Capable": false, "Node Type": "Sort", "Plan Width": 27, "Parallel Aware": false, "Plan Rows": 951, "Total Cost": 137.99, "Plans": [ { "Startup Cost": 69.55, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width": 27, "Parallel Aw...
{ "Startup Cost": 69.55, "Async Capable": false, "Node Type": "Sort", "Plan Width": 19, "Parallel Aware": false, "Plan Rows": 951, "Total Cost": 71.93, "Plans": [ { "Relation Name": "robot_details", "Alias": "robot_details", "Startup Cost": 0, "Async Capable": false, "N...
medium
262
polar_equipment
SELECT TO_CHAR("LAST_maint_date", 'HH12:MI AM') AS formatted_time FROM (SELECT "LAST_maint_date", row_number() OVER () as rn FROM "OperationMaintenance" WHERE "LAST_maint_date" IS NOT NULL) sub WHERE rn <= 100;
WITH filtered_maintenance AS (SELECT "LAST_maint_date" FROM "OperationMaintenance" WHERE "LAST_maint_date" IS NOT NULL LIMIT 100) SELECT TO_CHAR("LAST_maint_date", 'HH12:MI AM') AS formatted_time FROM filtered_maintenance;
0.261
0.185
{ "Alias": "sub", "Startup Cost": 0, "Async Capable": false, "Node Type": "Subquery Scan", "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 733, "Total Cost": 42.75, "Plans": [ { "Startup Cost": 0, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width": 12, ...
{ "Alias": "filtered_maintenance", "Startup Cost": 0, "Async Capable": false, "Node Type": "Subquery Scan", "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 100, "Total Cost": 3.58, "Plans": [ { "Startup Cost": 0, "Async Capable": false, "Node Type": "Limit", "Plan W...
medium
263
robot_fault_prediction
SELECT DISTINCT robot_details.modelseriesval as name, SUM(operation.totopshrval) OVER (PARTITION BY robot_details.modelseriesval) as commission FROM operation LEFT JOIN robot_details ON robot_details.botdetreg = operation.operrecref
SELECT robot_details.modelseriesval as name, SUM(operation.totopshrval) as commission FROM operation LEFT JOIN robot_details ON robot_details.botdetreg = operation.operrecref GROUP BY 1
3.518
1.166
{ "Startup Cost": 134.36, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 15, "Parallel Aware": false, "Plan Rows": 1000, "Total Cost": 144.36, "Plans": [ { "Startup Cost": 111.86, "Async Capable": false, "Node Type": "WindowAgg", "Plan...
{ "Startup Cost": 67.03, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 15, "Parallel Aware": false, "Plan Rows": 585, "Total Cost": 72.88, "Plans": [ { "Startup Cost": 34.4, "Async Capable": false, "Node Type": "Hash Join", "Plan Widt...
easy
264
robot_fault_prediction
SELECT COUNT(*) FILTER (WHERE faultpredscore IS NOT NULL) OVER () FROM maintenance_and_fault LIMIT 1
WITH filtered_faults AS (SELECT 1 FROM maintenance_and_fault WHERE faultpredscore IS NOT NULL) SELECT count(*) FROM filtered_faults
0.268
0.185
{ "Startup Cost": 0, "Async Capable": false, "Node Type": "Limit", "Plan Width": 8, "Parallel Aware": false, "Plan Rows": 1, "Total Cost": 0.04, "Plans": [ { "Startup Cost": 0, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width": 8, "Parallel Aware": false, ...
{ "Startup Cost": 12.73, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Plain", "Plan Width": 8, "Parallel Aware": false, "Plan Rows": 1, "Total Cost": 12.74, "Plans": [ { "Relation Name": "maintenance_and_fault", "Alias": "maintenance_and_fault", "Startup Cost": ...
easy
265
robot_fault_prediction
SELECT recreg as entry_id, botcode as entry_name FROM robot_record WHERE recreg NOT IN (SELECT DISTINCT mechactref FROM mechanical_status WHERE mechoperref NOT IN ('OP001', 'OP002', 'OP003'))
SELECT rr.recreg as entry_id, rr.botcode as entry_name FROM robot_record rr LEFT JOIN mechanical_status ms ON rr.recreg = ms.mechactref AND ms.mechoperref NOT IN ('OP001', 'OP002', 'OP003') WHERE ms.mechactref IS NULL
1.053
0.793
{ "Relation Name": "robot_record", "Alias": "robot_record", "Startup Cost": 93.89, "Async Capable": false, "Node Type": "Seq Scan", "Plan Width": 16, "Parallel Aware": false, "Plan Rows": 476, "Total Cost": 112.77, "Plans": [ { "Startup Cost": 84.82, "Async Capable": false, "No...
{ "Startup Cost": 92.07, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 16, "Parallel Aware": false, "Plan Rows": 226, "Total Cost": 114.15, "Plans": [ { "Relation Name": "robot_record", "Alias": "rr", "Startup Cost": 0, "Async Capable": false, "Node Ty...
easy
266
solar_panel
SELECT sitetie, ROUND((max_epoch - min_epoch)/60, 2) as Minutes FROM (SELECT sitetie, DATE_TRUNC('day', snapts) as day, MIN(EXTRACT(EPOCH FROM snapts)) as min_epoch, MAX(EXTRACT(EPOCH FROM snapts)) as max_epoch FROM plant_record GROUP BY sitetie, DATE_TRUNC('day', snapts)) as time_ranges
WITH filtered_records AS (SELECT sitetie, snapts FROM plant_record) SELECT sitetie, ROUND(EXTRACT(EPOCH FROM (MAX(snapts) - MIN(snapts)))/60, 2) as Minutes FROM filtered_records GROUP BY sitetie, DATE_TRUNC('day', snapts)
1.484
1.074
{ "Alias": "time_ranges", "Startup Cost": 34.45, "Async Capable": false, "Node Type": "Subquery Scan", "Plan Width": 39, "Parallel Aware": false, "Plan Rows": 998, "Total Cost": 64.38, "Plans": [ { "Startup Cost": 34.45, "Async Capable": false, "Node Type": "Aggregate", "St...
{ "Startup Cost": 29.46, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 47, "Parallel Aware": false, "Plan Rows": 998, "Total Cost": 51.91, "Plans": [ { "Relation Name": "plant_record", "Alias": "plant_record", "Startup Cost": 0, "Asyn...
easy
267
robot_fault_prediction
SELECT rr.*, ps.conditionindexval FROM robot_record rr JOIN performance_and_safety ps ON rr.botcode = ps.effectivenessrobot WHERE ps.conditionindexval = 10 UNION ALL SELECT rr.*, NULL AS conditionindexval FROM robot_record rr WHERE NOT EXISTS (SELECT 1 FROM performance_and_safety ps WHERE ps.effectivenessrobot = rr.bot...
WITH filtered_ps AS (SELECT effectivenessrobot, conditionindexval FROM performance_and_safety WHERE conditionindexval = 10) SELECT rr.*, COALESCE(fp.conditionindexval, NULL) as conditionindexval FROM robot_record rr LEFT JOIN filtered_ps fp ON rr.botcode = fp.effectivenessrobot ORDER BY rr.botcode
1.816
0.633
{ "Startup Cost": 118.6, "Async Capable": false, "Node Type": "Sort", "Plan Width": 28, "Parallel Aware": false, "Plan Rows": 951, "Total Cost": 120.98, "Plans": [ { "Startup Cost": 0.28, "Async Capable": false, "Node Type": "Append", "Plan Width": 28, "Parallel Aware":...
{ "Startup Cost": 15.27, "Async Capable": false, "Node Type": "Merge Join", "Plan Width": 28, "Parallel Aware": false, "Plan Rows": 951, "Total Cost": 79.91, "Plans": [ { "Relation Name": "robot_record", "Alias": "rr", "Startup Cost": 0.28, "Async Capable": false, "Node...
medium
268
solar_panel
SELECT pr.snapkey as matrix_id, (COALESCE((ep.elec_perf_snapshot->>'value')::real, 0) + COALESCE((ec.env_snapshot->>'value')::real, 0) + COALESCE((mc.mech_health_snapshot->>'value')::real, 0)) as total_sum FROM plant_record pr LEFT JOIN electrical_performance ep ON pr.snapkey = ep.snaplink LEF...
SELECT pr.snapkey as matrix_id, (COALESCE(ep.value, 0) + COALESCE(ec.value, 0) + COALESCE(mc.value, 0)) as total_sum FROM plant_record pr LEFT JOIN LATERAL (SELECT (elec_perf_snapshot->>'value')::real as value FROM electrical_performance WHERE snaplink = pr.snapkey) ep ON true LEFT JOIN LATERAL (SELECT (env_snap...
11.471
5.131
{ "Startup Cost": 446.22, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 2502, "Parallel Aware": false, "Plan Rows": 998, "Total Cost": 483.64, "Plans": [ { "Startup Cost": 251.36, "Async Capable": false, "Node Type": "Hash Join", "Pla...
{ "Startup Cost": 468.67, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 25, "Parallel Aware": false, "Plan Rows": 998, "Total Cost": 528.55, "Plans": [ { "Startup Cost": 251.36, "Async Capable": false, "Node Type": "Hash Join", "Plan ...
medium
269
solar_panel
WITH filtered_plants AS ( SELECT modhook, sitelabel FROM plants ), filtered_models AS ( SELECT modkey, pnlkind FROM panel_models ) SELECT fm.pnlkind, MAX(fp.sitelabel) AS max_site_label FROM filtered_plants fp JOIN filtered_models fm ON fp.modhook = fm.modkey GROUP BY fm.pnlkind;
SELECT pm.pnlkind, MAX(p.sitelabel) AS max_site_label FROM plants p JOIN panel_models pm ON p.modhook = pm.modkey GROUP BY pm.pnlkind;
1.431
1.119
{ "Startup Cost": 53.98, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 39, "Parallel Aware": false, "Plan Rows": 5, "Total Cost": 54.03, "Plans": [ { "Startup Cost": 19.41, "Async Capable": false, "Node Type": "Hash Join", "Plan Width...
{ "Startup Cost": 53.98, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 39, "Parallel Aware": false, "Plan Rows": 5, "Total Cost": 54.03, "Plans": [ { "Startup Cost": 19.41, "Async Capable": false, "Node Type": "Hash Join", "Plan Width...
medium
270
polar_equipment
SELECT e1."EQUIP_CODE" AS ID, e2."EQUIP_CODE" AS UltimateParentID FROM "Equipment" e1 JOIN "Equipment" e2 ON e1."EQUIP_CODE" = e2."EQUIP_CODE" || '_parent' WHERE e1."EQUIP_CODE" IS NOT NULL UNION ALL SELECT e1."EQUIP_CODE" AS ID, NULL AS UltimateParentID FROM "Equipment" e1 WHERE e1."EQUIP_CODE" IS NOT NULL AND NOT EXI...
WITH filtered_parents AS (SELECT "EQUIP_CODE" || '_parent' AS parent_pattern, "EQUIP_CODE" FROM "Equipment" WHERE "EQUIP_CODE" IS NOT NULL) SELECT e1."EQUIP_CODE" AS ID, COALESCE(fp."EQUIP_CODE", NULL) AS UltimateParentID FROM "Equipment" e1 LEFT JOIN filtered_parents fp ON e1."EQUIP_CODE" = fp.parent_pattern WHERE e1....
1.26
0.685
{ "Startup Cost": 34.5, "Async Capable": false, "Node Type": "Limit", "Plan Width": 26, "Parallel Aware": false, "Plan Rows": 100, "Total Cost": 41.01, "Plans": [ { "Startup Cost": 34.5, "Async Capable": false, "Node Type": "Append", "Plan Width": 26, "Parallel Aware": ...
{ "Startup Cost": 34.5, "Async Capable": false, "Node Type": "Limit", "Plan Width": 41, "Parallel Aware": false, "Plan Rows": 100, "Total Cost": 36.98, "Plans": [ { "Startup Cost": 34.5, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 41, "Parallel Aware...
hard
271
solar_panel
SELECT EXTRACT(HOUR FROM pr.snapts) AS hour, ep.elec_perf_snapshot AS tableValue1 FROM plant_record pr JOIN electrical_performance ep ON pr.snapkey = ep.snaplink WHERE DATE(pr.snapts) = '2020-05-29' AND EXTRACT(HOUR FROM pr.snapts) BETWEEN 0 AND 10 UNION ALL SELECT EXTRACT(HOUR FROM pr.snapts) AS hour, ec.env_snapshot ...
WITH filtered_pr AS (SELECT snapkey, snapts FROM plant_record WHERE DATE(snapts) = '2020-05-29') SELECT EXTRACT(HOUR FROM pr.snapts) AS hour, ep.elec_perf_snapshot AS tableValue1 FROM filtered_pr pr JOIN electrical_performance ep ON pr.snapkey = ep.snaplink WHERE EXTRACT(HOUR FROM pr.snapts) BETWEEN 0 AND 10 UNION ALL ...
1.02
0.3
{ "Startup Cost": 0.28, "Async Capable": false, "Node Type": "Append", "Plan Width": 862, "Parallel Aware": false, "Plan Rows": 3, "Total Cost": 120.8, "Plans": [ { "Startup Cost": 0.28, "Async Capable": false, "Node Type": "Nested Loop", "Plan Width": 1208, "Parallel A...
{ "Startup Cost": 22.24, "Async Capable": false, "Node Type": "Append", "Plan Width": 862, "Parallel Aware": false, "Plan Rows": 3, "Total Cost": 47.37, "Plans": [ { "Relation Name": "plant_record", "Alias": "plant_record", "Startup Cost": 0, "Async Capable": false, "No...
medium
272
solar_panel
SELECT snapkey AS ID, snapts AS Timestamp, sitetie AS Value FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY snapts) as rn FROM plant_record) AS ordered ORDER BY rn
SELECT snapkey AS ID, snapts AS Timestamp, sitetie AS Value FROM plant_record ORDER BY snapts
1.24
0.523
{ "Startup Cost": 143.85, "Async Capable": false, "Node Type": "Sort", "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 998, "Total Cost": 146.35, "Plans": [ { "Alias": "ordered", "Startup Cost": 66.69, "Async Capable": false, "Node Type": "Subquery Scan", "Plan ...
{ "Startup Cost": 66.69, "Async Capable": false, "Node Type": "Sort", "Plan Width": 24, "Parallel Aware": false, "Plan Rows": 998, "Total Cost": 69.19, "Plans": [ { "Relation Name": "plant_record", "Alias": "plant_record", "Startup Cost": 0, "Async Capable": false, "Nod...
easy
273
robot_fault_prediction
WITH RECURSIVE location_hierarchy AS ( SELECT r.botcode as id, r.botcode as name, r.botcode as path, 1 as level FROM robot_record r WHERE r.botcode IN (SELECT DISTINCT o.operrecref FROM operation o WHERE o.operrecref IS NOT NULL) UNION ALL SELECT r.botcode as id, r.botcode as n...
WITH RECURSIVE location_hierarchy AS ( SELECT r.botcode as id, r.botcode as name, r.botcode as path, 1 as level FROM robot_record r WHERE EXISTS ( SELECT 1 FROM operation o WHERE o.operrecref = r.botcode AND o.operrecref IS NOT NULL ) UNION ALL SELECT r.botcode...
4.196
3.165
{ "Startup Cost": 19927.62, "Async Capable": false, "Node Type": "Sort", "Plan Width": 100, "Parallel Aware": false, "Plan Rows": 96051, "Total Cost": 20167.74, "Plans": [ { "Startup Cost": 48.9, "Async Capable": false, "Node Type": "Recursive Union", "Plan Width": 50, ...
{ "Startup Cost": 19929.17, "Async Capable": false, "Node Type": "Sort", "Plan Width": 100, "Parallel Aware": false, "Plan Rows": 96051, "Total Cost": 20169.29, "Plans": [ { "Startup Cost": 37.5, "Async Capable": false, "Node Type": "Recursive Union", "Plan Width": 50, ...
hard
274
robot_fault_prediction
WITH filtered_operations AS (SELECT operreg, progcyclecount, operrecref FROM operation), valid_robots AS (SELECT botdetreg, modelseriesval, payloadcapkg, instdateval, reachmmval FROM robot_details WHERE botdetreg IN (SELECT botcode FROM robot_record)) SELECT o.operreg AS CONumber, o.progcyclecount AS LineNumber, r.mode...
SELECT o.operreg AS CONumber, o.progcyclecount AS LineNumber, rd.modelseriesval AS PartNumber, rd.payloadcapkg AS OrderQty, rd.instdateval AS ScheduleDate, rd.reachmmval AS OnHandQty FROM operation o JOIN robot_details rd ON o.operrecref = rd.botdetreg
1.673
0.912
{ "Startup Cost": 62.8, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 45, "Parallel Aware": false, "Plan Rows": 1000, "Total Cost": 93.07, "Plans": [ { "Startup Cost": 34.4, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 59, "Parallel ...
{ "Startup Cost": 34.4, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 45, "Parallel Aware": false, "Plan Rows": 1000, "Total Cost": 62.03, "Plans": [ { "Relation Name": "operation", "Alias": "o", "Startup Cost": 0, "Async Capable": false, "Node Type": ...
medium
275
solar_panel
WITH plant_stats AS ( SELECT sitelabel, modhook, cap_mw, MIN(cap_mw) OVER w AS min_cap, MAX(cap_mw) OVER w AS max_cap, COUNT(*) OVER w AS row_count FROM plants WINDOW w AS (PARTITION BY sitelabel, modhook) ) SELECT sitelabel as campaign, modhook as supplier, cap_mw as plan_quantity...
SELECT sitelabel as campaign, modhook as supplier, cap_mw as plan_quantity, CASE WHEN MIN(cap_mw) OVER(PARTITION BY sitelabel, modhook) = MAX(cap_mw) OVER(PARTITION BY sitelabel, modhook) THEN CASE WHEN COUNT(*) OVER(PARTITION BY sitelabel, modhook) = 1 THEN 'non-releva...
5.778
4.537
{ "Startup Cost": 73.79, "Async Capable": false, "Node Type": "Incremental Sort", "Plan Width": 71, "Parallel Aware": false, "Plan Rows": 939, "Total Cost": 143.51, "Plans": [ { "Alias": "plant_stats", "Startup Cost": 73.75, "Async Capable": false, "Node Type": "Subquery Scan...
{ "Startup Cost": 73.79, "Async Capable": false, "Node Type": "Incremental Sort", "Plan Width": 71, "Parallel Aware": false, "Plan Rows": 939, "Total Cost": 143.51, "Plans": [ { "Startup Cost": 73.75, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width": 71, "...
medium
276
solar_panel
WITH RankedRecords AS ( SELECT sitetie, snapts, ROW_NUMBER() OVER (PARTITION BY sitetie ORDER BY snapts) AS rn FROM plant_record ), ConsecutivePairs AS ( SELECT r1.rn AS from_rank, r2.rn AS to_rank, r2.snapts - r1.snapts AS days_between FROM RankedRecords r1 JOIN RankedRecord...
SELECT from_rank, to_rank, AVG(next_borrowing_date - current_borrowing_date) AS avg_days_between_borrowings FROM ( SELECT name, borrowing_rank AS from_rank, LEAD(borrowing_rank) OVER (PARTITION BY name ORDER BY date_library_book_borrowed) AS to_rank, date_library_book_borrowed AS current_borrowi...
3.467
2.726
{ "Startup Cost": 246.8, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Sorted", "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 25, "Total Cost": 247.42, "Plans": [ { "Startup Cost": 66.69, "Async Capable": false, "Node Type": "WindowAgg", "Plan Wid...
{ "Startup Cost": 146.65, "Async Capable": false, "Node Type": "Sort", "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 200, "Total Cost": 147.15, "Plans": [ { "Startup Cost": 136.5, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Wi...
hard
277
robot_fault_prediction
WITH filtered_data AS (SELECT actrecref, payloadwval FROM actuation_data WHERE payloadwval IS NOT NULL OR payloadwval IS NULL) SELECT actrecref AS item_name, SUM(payloadwval) AS issue_material FROM filtered_data WHERE payloadwval IS NOT NULL GROUP BY actrecref UNION ALL SELECT actrecref AS item_name, SUM(payloadwval) A...
SELECT actrecref AS item_name, SUM(payloadwval) AS issue_material FROM actuation_data WHERE payloadwval IS NOT NULL GROUP BY actrecref UNION ALL SELECT actrecref AS item_name, SUM(payloadwval) AS return_material FROM actuation_data WHERE payloadwval IS NULL GROUP BY actrecref
1.774
1.03
{ "Startup Cost": 46.73, "Async Capable": false, "Node Type": "Append", "Plan Width": 36, "Parallel Aware": false, "Plan Rows": 204, "Total Cost": 64.86, "Plans": [ { "Relation Name": "actuation_data", "Alias": "actuation_data", "Startup Cost": 0, "Async Capable": false, ...
{ "Startup Cost": 30.4, "Async Capable": false, "Node Type": "Append", "Plan Width": 11, "Parallel Aware": false, "Plan Rows": 984, "Total Cost": 75.76, "Plans": [ { "Startup Cost": 30.4, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Widt...
hard
278
robot_fault_prediction
WITH PERIODS AS ( SELECT DATE '2020-01-01' AS PERIOD, 1 AS value UNION ALL SELECT DATE '2020-01-02' AS PERIOD, 2 AS value UNION ALL SELECT DATE '2020-01-03' AS PERIOD, 3 AS value UNION ALL SELECT DATE '2020-01-04' AS PERIOD, 4 AS value UNION ALL SELECT DATE '2020-01-05' AS PERIOD, 5 ...
SELECT period, value FROM (VALUES (DATE '2020-01-01', 1), (DATE '2020-01-02', 2), (DATE '2020-01-03', 3), (DATE '2020-01-04', 4), (DATE '2020-01-05', 5), (DATE '2020-01-06', 0), (DATE '2020-01-07', 6), (DATE '2020-01-08', 7), (DATE '2020-01-09', 8), (DATE '2020-01-10', 9) ) AS P...
0.069
0.031
{ "Startup Cost": 0, "Async Capable": false, "Node Type": "Append", "Plan Width": 8, "Parallel Aware": false, "Plan Rows": 10, "Total Cost": 0.15, "Plans": [ { "Startup Cost": 0, "Async Capable": false, "Node Type": "Result", "Plan Width": 8, "Parallel Aware": false, ...
{ "Alias": "*VALUES*", "Startup Cost": 0, "Async Capable": false, "Node Type": "Values Scan", "Plan Width": 8, "Parallel Aware": false, "Plan Rows": 10, "Total Cost": 0.12 }
hard
279
solar_panel
SELECT * FROM (SELECT sitekey as id, ARRAY_AGG(DISTINCT docstate) AS table1Country FROM plants WHERE docstate IS NOT NULL GROUP BY sitekey) as table1 UNION ALL SELECT * FROM (SELECT sitekey as id, ARRAY_AGG(DISTINCT docstate) AS table2Country FROM plants WHERE docstate IS NOT NULL GROUP BY sitekey) as table2
WITH plant_data AS ( SELECT sitekey, docstate FROM plants WHERE docstate IS NOT NULL ), agg_result AS ( SELECT sitekey as id, ARRAY_AGG(DISTINCT docstate) AS country_array FROM plant_data GROUP BY sitekey ) SELECT id, country_array AS table1Country FROM agg_result UNION ALL SELECT id, country_ar...
4.292
2.752
{ "Startup Cost": 73.75, "Async Capable": false, "Node Type": "Append", "Plan Width": 39, "Parallel Aware": false, "Plan Rows": 1878, "Total Cost": 194.46, "Plans": [ { "Startup Cost": 73.75, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Sorted", "Plan ...
{ "Startup Cost": 92.53, "Async Capable": false, "Node Type": "Append", "Plan Width": 64, "Parallel Aware": false, "Plan Rows": 1878, "Total Cost": 139.48, "Plans": [ { "Startup Cost": 73.75, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Sorted", "Plan ...
medium
280
polar_equipment
SELECT c.* FROM (SELECT e.*, COUNT(*) OVER (PARTITION BY LEFT("EQUIP_CODE", 3)) AS cnt FROM "Equipment" e) c ORDER BY "EQUIP_CODE";
WITH prefix_counts AS (SELECT LEFT("EQUIP_CODE", 3) AS prefix, COUNT(*) AS cnt FROM "Equipment" GROUP BY 1) SELECT e.*, pc.cnt FROM "Equipment" e JOIN prefix_counts pc ON LEFT(e."EQUIP_CODE", 3) = pc.prefix ORDER BY e."EQUIP_CODE"
3.612
2.547
{ "Startup Cost": 154.16, "Async Capable": false, "Node Type": "Sort", "Plan Width": 69, "Parallel Aware": false, "Plan Rows": 1000, "Total Cost": 156.66, "Plans": [ { "Alias": "c", "Startup Cost": 74.33, "Async Capable": false, "Node Type": "Subquery Scan", "Plan Width...
{ "Startup Cost": 396.5, "Async Capable": false, "Node Type": "Sort", "Plan Width": 69, "Parallel Aware": false, "Plan Rows": 5000, "Total Cost": 409, "Plans": [ { "Startup Cost": 64.5, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 69, "Parallel Aware"...
hard
281
robot_fault_prediction
SELECT rd.botdetreg, rd.mfgnameval, rd.modelseriesval, o.operreg, o.operreg FROM (SELECT operreg, operrecref FROM operation WHERE operreg BETWEEN 'OP001' AND 'OP950') o INNER JOIN robot_details rd ON rd.botdetreg = o.operrecref ORDER BY rd.mfgnameval, o.operreg
SELECT rd.botdetreg, rd.mfgnameval, rd.modelseriesval, o.operreg, o.operreg FROM operation o INNER JOIN robot_details rd ON rd.botdetreg = o.operrecref WHERE o.operreg BETWEEN 'OP001' AND 'OP950' ORDER BY rd.mfgnameval, o.operreg
1.425
1.117
{ "Startup Cost": 74.73, "Async Capable": false, "Node Type": "Sort", "Plan Width": 46, "Parallel Aware": false, "Plan Rows": 260, "Total Cost": 75.38, "Plans": [ { "Startup Cost": 33.25, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 46, "Parallel Awar...
{ "Startup Cost": 74.73, "Async Capable": false, "Node Type": "Sort", "Plan Width": 46, "Parallel Aware": false, "Plan Rows": 260, "Total Cost": 75.38, "Plans": [ { "Startup Cost": 33.25, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 46, "Parallel Awar...
medium
282
polar_equipment
SELECT DISTINCT l."STATION_name" FROM "Location" l WHERE EXISTS (SELECT 1 FROM "StationEquipmentType" set WHERE set.station_name = l."STATION_name") AND (SELECT COUNT(*) FROM "StationEquipmentType" set2 WHERE set2.station_name = l."STATION_name") = (SELECT COUNT(*) FROM "EquipmentType");
SELECT l."STATION_name" FROM "Location" l WHERE (SELECT COUNT(*) FROM "StationEquipmentType" set WHERE set.station_name = l."STATION_name") = (SELECT COUNT(*) FROM "EquipmentType");
0.501
0.339
{ "Startup Cost": 55.47, "Async Capable": false, "Node Type": "Unique", "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 1, "Total Cost": 55.48, "Plans": [ { "Startup Cost": 1.07, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Plain", "Plan Width"...
{ "Relation Name": "Location", "Alias": "l", "Startup Cost": 1.08, "Async Capable": false, "Node Type": "Seq Scan", "Plan Width": 32, "Parallel Aware": false, "Plan Rows": 1, "Total Cost": 52.83, "Plans": [ { "Startup Cost": 1.07, "Async Capable": false, "Node Type": "Aggregate...
easy
283
polar_equipment
SELECT j.date, j.product_id, j.qty_in, j.qty_out FROM "OperationMaintenance" om JOIN "Equipment" e ON om."equipRef" = e."EQUIP_CODE" CROSS JOIN LATERAL ( VALUES (om."LAST_maint_date", e."EQUIP_CODE", om."OPER_hours", NULL), (om."LAST_maint_date", e."EQUIP_CODE", NULL, om."MAINT_COST_usd") ...
SELECT om."LAST_maint_date" AS date, e."EQUIP_CODE" AS product_id, om."OPER_hours" AS qty_in, NULL AS qty_out FROM "OperationMaintenance" om JOIN "Equipment" e ON om."equipRef" = e."EQUIP_CODE" UNION ALL SELECT om."LAST_maint_date" AS date, e."EQUIP_CODE" AS product_id, NULL AS qty_in, om."MAINT_COST_usd" AS qty_out FR...
1.859
1.45
{ "Startup Cost": 34.5, "Async Capable": false, "Node Type": "Nested Loop", "Plan Width": 44, "Parallel Aware": false, "Plan Rows": 1718, "Total Cost": 98.01, "Plans": [ { "Startup Cost": 34.5, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 21, "Paralle...
{ "Startup Cost": 34.5, "Async Capable": false, "Node Type": "Append", "Plan Width": 21, "Parallel Aware": false, "Plan Rows": 1718, "Total Cost": 127.3, "Plans": [ { "Startup Cost": 34.5, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 21, "Parallel Awa...
medium
284
robot_fault_prediction
WITH CTE AS ( SELECT TO_CHAR(rects, 'YYYY-MM') AS Year_Month, EXTRACT(YEAR FROM rects) AS Year, EXTRACT(MONTH FROM rects) AS Month, COUNT(DISTINCT botcode) AS Headcount FROM robot_record GROUP BY TO_CHAR(rects, 'YYYY-MM'), EXTRACT(YEAR FROM rects), EXTRACT(MONTH FROM rects) ), YearStartingHeadcoun...
WITH MonthlyHeadcount AS ( SELECT EXTRACT(YEAR FROM rects) AS Year, EXTRACT(MONTH FROM rects) AS Month, COUNT(DISTINCT botcode) AS Headcount FROM robot_record GROUP BY EXTRACT(YEAR FROM rects), EXTRACT(MONTH FROM rects) ) SELECT 0 AS NumVolTerms, Month, Year, Headcount, CASE WHEN Month =...
4.871
3.474
{ "Startup Cost": 82.64, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width": 84, "Parallel Aware": false, "Plan Rows": 2, "Total Cost": 82.69, "Plans": [ { "Startup Cost": 82.64, "Async Capable": false, "Node Type": "Sort", "Plan Width": 72, "Parallel Aware"...
{ "Startup Cost": 68.31, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width": 84, "Parallel Aware": false, "Plan Rows": 2, "Total Cost": 77.91, "Plans": [ { "Alias": "monthlyheadcount", "Startup Cost": 68.31, "Async Capable": false, "Node Type": "Subquery Scan", ...
hard
285
robot_fault_prediction
SELECT rr.botcode AS EmployeeCode, (SELECT rd.payloadcapkg FROM robot_details rd WHERE rd.botdetreg = rr.botcode) AS EstimatedWeight FROM robot_record rr WHERE EXISTS (SELECT 1 FROM robot_details rd WHERE rd.botdetreg = rr.botcode)
WITH filtered_robots AS (SELECT botcode FROM robot_record) SELECT fr.botcode AS EmployeeCode, rd.payloadcapkg AS EstimatedWeight FROM filtered_robots fr JOIN robot_details rd ON fr.botcode = rd.botdetreg
3.379
0.683
{ "Startup Cost": 28.4, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 11, "Parallel Aware": false, "Plan Rows": 951, "Total Cost": 7939.58, "Plans": [ { "Relation Name": "robot_details", "Alias": "rd", "Startup Cost": 0, "Async Capable": false, "Node T...
{ "Startup Cost": 28.4, "Async Capable": false, "Node Type": "Hash Join", "Plan Width": 11, "Parallel Aware": false, "Plan Rows": 951, "Total Cost": 53.41, "Plans": [ { "Relation Name": "robot_details", "Alias": "rd", "Startup Cost": 0, "Async Capable": false, "Node Typ...
easy
286
robot_fault_prediction
SELECT DISTINCT actoperref as agent_from, SUM(payloadwval) OVER (PARTITION BY actoperref) as from_transaccions FROM actuation_data;
SELECT actoperref as agent_from, SUM(payloadwval) as from_transaccions FROM actuation_data GROUP BY actoperref;
2.743
0.797
{ "Startup Cost": 100.33, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 14, "Parallel Aware": false, "Plan Rows": 1000, "Total Cost": 110.33, "Plans": [ { "Startup Cost": 77.83, "Async Capable": false, "Node Type": "WindowAgg", "Plan ...
{ "Startup Cost": 33, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 14, "Parallel Aware": false, "Plan Rows": 1000, "Total Cost": 43, "Plans": [ { "Relation Name": "actuation_data", "Alias": "actuation_data", "Startup Cost": 0, "Async...
easy
287
polar_equipment
WITH AggregatedData AS (SELECT "EQUIP_CODE", MIN(CAST("utilPercent" AS DECIMAL(9,2))) as min_util, SUM(CAST("utilPercent" AS DECIMAL(9,2))) as sum_util FROM "Equipment" GROUP BY "EQUIP_CODE") SELECT "EQUIP_CODE" AS IDNUMBER, CASE WHEN min_util < 0 THEN min_util ELSE CAST(sum_util AS DECIMAL(9,2)) END AS Sum_Result, CAS...
SELECT "EQUIP_CODE" AS IDNUMBER, CASE WHEN MIN(CAST("utilPercent" AS DECIMAL(9,2))) < 0 THEN MIN(CAST("utilPercent" AS DECIMAL(9,2))) ELSE CAST(SUM(CAST("utilPercent" AS DECIMAL(9,2))) AS DECIMAL(9,2)) END AS Sum_Result, CASE WHEN MIN(CAST("utilPercent" AS DECIMAL(9,2))) < 0 THEN 1 ELSE 2 END AS "FLAG_In" FROM "Equipme...
2.666
2.04
{ "Alias": "aggregateddata", "Startup Cost": 39.5, "Async Capable": false, "Node Type": "Subquery Scan", "Plan Width": 45, "Parallel Aware": false, "Plan Rows": 1000, "Total Cost": 59.5, "Plans": [ { "Startup Cost": 39.5, "Async Capable": false, "Node Type": "Aggregate", "S...
{ "Startup Cost": 39.5, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Hashed", "Plan Width": 45, "Parallel Aware": false, "Plan Rows": 1000, "Total Cost": 59.5, "Plans": [ { "Relation Name": "Equipment", "Alias": "Equipment", "Startup Cost": 0, "Async Capab...
hard
288
solar_panel
SELECT snapkey, RowNum FROM (SELECT snapkey, ROW_NUMBER() OVER (ORDER BY snapts) AS RowNum FROM plant_record) sub
SELECT snapkey, ROW_NUMBER() OVER (ORDER BY snapts) AS RowNum FROM plant_record
0.983
0.749
{ "Alias": "sub", "Startup Cost": 66.69, "Async Capable": false, "Node Type": "Subquery Scan", "Plan Width": 17, "Parallel Aware": false, "Plan Rows": 998, "Total Cost": 94.14, "Plans": [ { "Startup Cost": 66.69, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width...
{ "Startup Cost": 66.69, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width": 25, "Parallel Aware": false, "Plan Rows": 998, "Total Cost": 84.16, "Plans": [ { "Startup Cost": 66.69, "Async Capable": false, "Node Type": "Sort", "Plan Width": 17, "Parallel Awar...
medium
289
solar_panel
SELECT TO_CHAR(snapts, 'YYYY-MM') AS month_year, COUNT(DISTINCT sitetie) AS customer_count FROM plant_record WHERE snapts IS NOT NULL GROUP BY TO_CHAR(snapts, 'YYYY-MM') HAVING COUNT(snapkey) > 1
WITH pre_aggregated AS ( SELECT DATE_TRUNC('month', snapts) AS month_start, sitetie, snapkey FROM plant_record WHERE snapts IS NOT NULL ) SELECT TO_CHAR(month_start, 'YYYY-MM') AS month_year, COUNT(DISTINCT sitetie) AS customer_count FROM pre_aggregated...
2.601
1.276
{ "Startup Cost": 69.19, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Sorted", "Plan Width": 40, "Parallel Aware": false, "Plan Rows": 333, "Total Cost": 92.48, "Plans": [ { "Startup Cost": 69.19, "Async Capable": false, "Node Type": "Sort", "Plan Width": ...
{ "Startup Cost": 69.19, "Async Capable": false, "Node Type": "Aggregate", "Strategy": "Sorted", "Plan Width": 48, "Parallel Aware": false, "Plan Rows": 333, "Total Cost": 94.14, "Plans": [ { "Startup Cost": 69.19, "Async Capable": false, "Node Type": "Sort", "Plan Width": ...
medium
290
polar_equipment
SELECT currency, rate FROM ( SELECT "EquipType" as currency, COUNT(*) as rate, RANK() OVER (ORDER BY COUNT(*) DESC) as drnk FROM "Equipment" GROUP BY "EquipType" ) ranked WHERE drnk <= 5 ORDER BY rate DESC
SELECT "EquipType" as currency, COUNT(*) as rate FROM "Equipment" GROUP BY "EquipType" ORDER BY rate DESC LIMIT 5
0.55
0.418
{ "Alias": "ranked", "Startup Cost": 27.14, "Async Capable": false, "Node Type": "Subquery Scan", "Plan Width": 17, "Parallel Aware": false, "Plan Rows": 6, "Total Cost": 27.3, "Plans": [ { "Startup Cost": 27.14, "Async Capable": false, "Node Type": "WindowAgg", "Plan Width...
{ "Startup Cost": 27.14, "Async Capable": false, "Node Type": "Limit", "Plan Width": 17, "Parallel Aware": false, "Plan Rows": 5, "Total Cost": 27.15, "Plans": [ { "Startup Cost": 27.14, "Async Capable": false, "Node Type": "Sort", "Plan Width": 17, "Parallel Aware": fa...
hard
291
tpch
WITH RECURSIVE date_range AS ( SELECT MIN(CAST(o.o_orderdate AS DATE))::DATE AS date FROM orders o UNION ALL SELECT (date + INTERVAL '1 day')::DATE FROM date_range WHERE date < (SELECT MAX(CAST(o.o_orderdate AS DATE)) FROM orders o) ) SELECT dr.date, COALESCE(SUM(o.o_totalprice), 0) AS total...
SELECT CAST(o.o_orderdate AS DATE) AS date, SUM(o.o_totalprice) AS total_transaction_amount FROM orders o GROUP BY CAST(o.o_orderdate AS DATE) ORDER BY CAST(o.o_orderdate AS DATE);
4,045.522
1,708.267
{ "Plan Width": 36, "Actual Rows": 2406, "Plan Rows": 31, "Actual Startup Time": 4028.061, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1620893.62, "Actual Total Time": 4028.176, "Startup Cost": 1620893.54, "Plans": [ { "Plan Width": 4, "Actual Row...
{ "Plan Width": 36, "Actual Rows": 2406, "Plan Rows": 2406, "Actual Startup Time": 1689.865, "Node Type": "Sort", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 145954.92, "Actual Total Time": 1689.972, "Startup Cost": 145948.9, "Plans": [ { "Plan Width": 36, "Actual Row...
hard
292
tpch
SELECT o_orderstatus, SUM(CASE WHEN o_orderdate BETWEEN '1995-05-02' AND '1996-03-01' THEN 1 ELSE 0 END) AS count FROM orders WHERE o_orderstatus IN ('F', 'O', 'P') GROUP BY o_orderstatus;
SELECT o_orderstatus, COUNT(*) FROM orders WHERE o_orderstatus IN ('F', 'O', 'P') AND o_orderdate BETWEEN '1995-05-02' AND '1996-03-01' GROUP BY o_orderstatus;
1,615.766
683.314
{ "Plan Width": 10, "Actual Rows": 3, "Plan Rows": 3, "Actual Startup Time": 1597.177, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 185162.06, "Actual Total Time": 1597.178, "Startup Cost": 185162.03, "Plans": [ { "Relation N...
{ "Plan Width": 10, "Actual Rows": 3, "Plan Rows": 3, "Actual Startup Time": 665.752, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Hashed", "Total Cost": 165415.79, "Actual Total Time": 665.753, "Startup Cost": 165415.76, "Plans": [ { "Relation Nam...
medium
293
tpch
SELECT * FROM lineitem WHERE ctid IN ( SELECT ctid FROM lineitem WHERE l_suppkey <> 25 INTERSECT SELECT ctid FROM lineitem WHERE l_partkey <> 25 INTERSECT SELECT ctid FROM lineitem WHERE l_orderkey <> 25 INTERSECT SELECT ctid FROM lineitem WHERE l_linenumber <> 25 INTERSECT SELECT ctid FROM lineitem W...
SELECT * FROM lineitem WHERE l_suppkey <> 25 AND l_partkey <> 25 AND l_orderkey <> 25 AND l_linenumber <> 25 AND l_quantity <> 25.00 AND l_extendedprice <> 25.00;
173,651.978
5,184.263
{ "Plan Width": 117, "Actual Rows": 17634447, "Plan Rows": 17635723, "Actual Startup Time": 150844.129, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 40405648.46, "Actual Total Time": 172432.903, "Startup Cost": 39104347.82, "Plans": [ { "Relation Na...
{ "Relation Name": "lineitem", "Plan Width": 117, "Actual Rows": 17634447, "Plan Rows": 17635039, "Actual Startup Time": 70.782, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 787284.2, "Actual Total Time": 4497.071, "Startup Cost": 0, "Alias": "lineitem" }
medium
294
tpch
SELECT s.*, (s.s_acctbal + COALESCE(g.sum_signed, 0)) AS score FROM supplier s LEFT JOIN ( SELECT s_suppkey, SUM(score_signed) AS sum_signed FROM ( SELECT l_suppkey AS s_suppkey, l_extendedprice AS score_signed FROM lineitem UNION ALL SELECT l_suppkey AS s_suppkey, -l_extendedprice AS score_signed FROM ...
SELECT s.*, s.s_acctbal AS score FROM supplier s WHERE s.s_nationkey = 1;
23,465.071
5.554
{ "Plan Width": 176, "Actual Rows": 1245, "Plan Rows": 1245, "Actual Startup Time": 23340.732, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1440704.45, "Actual Total Time": 23345.43, "Startup Cost": 1439658.06, "Plans": [ { "Relation Name": "supplie...
{ "Relation Name": "supplier", "Plan Width": 150, "Actual Rows": 1245, "Plan Rows": 1245, "Actual Startup Time": 0.013000000000000001, "Node Type": "Seq Scan", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 1040, "Actual Total Time": 5.436, "Startup Cost": 0, "Alias": "s" }
medium
295
tpch
SELECT l_orderkey FROM ( SELECT l_orderkey, l_partkey FROM lineitem WHERE l_shipdate >= '1995-01-01' GROUP BY l_orderkey, l_partkey ) AS unique_parts GROUP BY l_orderkey HAVING COUNT(l_partkey) > 1
SELECT DISTINCT l_orderkey FROM ( SELECT l_orderkey, COUNT(l_partkey) OVER (PARTITION BY l_orderkey) as distinct_parts FROM lineitem WHERE l_shipdate >= '1995-01-01' ) AS order_parts WHERE distinct_parts > 1
5,235.762
3,838.11
{ "Node Type": "Aggregate", "Total Cost": 621569.93, "Plan Width": 4, "Parallel Aware": false, "Plan Rows": 67, "Strategy": "Hashed", "Startup Cost": 621567.43, "Plans": [ { "Node Type": "Aggregate", "Parent Relationship": "Outer", "Total Cost": 583176.84, "Plan Width": 8, ...
{ "Node Type": "Unique", "Total Cost": 603248.51, "Plan Width": 4, "Parallel Aware": false, "Plan Rows": 853124, "Startup Cost": 0.43, "Plans": [ { "Node Type": "Subquery Scan", "Parent Relationship": "Outer", "Total Cost": 601115.7, "Plan Width": 4, "Parallel Aware": fal...
medium
296
tpch
SELECT p.p_partkey AS "Products__id", p.p_name AS "Products__title", p.p_retailprice AS "Products__price", COUNT(l.l_partkey) AS "count", CASE WHEN ps.ps_suppkey IS NULL THEN FALSE ELSE TRUE END AS "isFavorite" FROM part p LEFT JOIN partsupp ps ON ps.ps_partkey = p.p_partkey JOIN lineitem l ON l.l_partkey = p.p_partkey...
WITH part_lineitem AS (SELECT p_partkey, p_name, p_retailprice, COUNT(l_partkey) as count FROM part JOIN lineitem ON p_partkey = l_partkey GROUP BY p_partkey, p_name, p_retailprice), part_partsupp AS (SELECT ps_partkey, ps_suppkey FROM partsupp GROUP BY ps_partkey, ps_suppkey) SELECT pl.p_partkey AS "Products__id", pl....
14,585.375
4,291.258
{ "Node Type": "Limit", "Total Cost": 2564789.5, "Plan Width": 56, "Parallel Aware": false, "Plan Rows": 100, "Startup Cost": 2564789.25, "Plans": [ { "Node Type": "Sort", "Parent Relationship": "Outer", "Total Cost": 2609779, "Plan Width": 56, "Parallel Aware": false, ...
{ "Node Type": "Limit", "Total Cost": 60017339.7, "Plan Width": 52, "Parallel Aware": false, "Plan Rows": 100, "Startup Cost": 60017339.45, "Plans": [ { "Node Type": "Sort", "Parent Relationship": "Outer", "Total Cost": 62819879.45, "Plan Width": 52, "Parallel Aware": fal...
medium
297
tpch
SELECT l.*, (SELECT o.o_orderdate FROM orders o WHERE (o.o_orderkey, o.o_orderdate) = (l.l_orderkey, l.l_shipdate)) AS starttime, p.p_name AS title FROM lineitem l LEFT JOIN part p ON l.l_partkey = p.p_partkey;
WITH lineitem_orders AS (SELECT l1.*, o1.o_orderdate AS starttime FROM lineitem l1 LEFT JOIN orders o1 ON (l1.l_orderkey, l1.l_shipdate) = (o1.o_orderkey, o1.o_orderdate)) SELECT lo.*, p.p_name AS title FROM lineitem_orders lo LEFT JOIN part p ON lo.l_partkey = p.p_partkey;
56,570.967
32,893.068
{ "Plan Width": 154, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 480.172, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 153345714.18, "Actual Total Time": 55564.764, "Startup Cost": 30477, "Plans": [ { "Relation Name": "lin...
{ "Plan Width": 154, "Actual Rows": 17996609, "Plan Rows": 17996248, "Actual Startup Time": 487.856, "Node Type": "Hash Join", "Actual Loops": 1, "Parallel Aware": false, "Total Cost": 2027240.73, "Actual Total Time": 32191.58, "Startup Cost": 30477.87, "Plans": [ { "Plan Width": 121, ...
medium
298
tpch
SELECT Country, City FROM ( SELECT n.n_name AS Country , n.n_nationkey AS CountryCode , r.r_name AS Region , c.c_name AS City , c.c_acctbal AS CityPopulation , DENSE_RANK() OVER (PARTITION BY n.n_nationkey ORDER BY c.c_acctbal DESC) AS Rnk FROM nation AS n JOIN region AS r ON r.r_r...
SELECT n.n_name AS Country, c.c_name AS City FROM nation n JOIN region r ON r.r_regionkey = n.n_regionkey JOIN customer c ON c.c_nationkey = n.n_nationkey JOIN ( SELECT c_nationkey, MAX(c_acctbal) AS max_bal FROM customer WHERE c_acctbal > 1000 GROUP BY c_nationkey ) max_c ON max_c.c_nationkey = n.n_nat...
1,327.434
322.143
{ "Startup Cost": 137332.54, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 137337.13, "Plan Rows": 1835, "Plan Width": 129, "Plans": [ { "Startup Cost": 121483.07, "Parallel Aware": false, "Node Type": "Subquery Scan", "Total Cost": 137233.07, "Plan Rows": 1...
{ "Startup Cost": 1984308.9, "Parallel Aware": false, "Node Type": "Sort", "Total Cost": 1984309.33, "Plan Rows": 170, "Plan Width": 129, "Plans": [ { "Startup Cost": 11686.02, "Parallel Aware": false, "Node Type": "Nested Loop", "Total Cost": 1984302.61, "Plan Rows": 170...
hard
299
tpch
SELECT ROUND(100.0 * COUNT(DISTINCT CASE WHEN EXISTS (SELECT 1 FROM customer c WHERE c.c_custkey = o.o_custkey) THEN o.o_custkey END) / COUNT(DISTINCT o.o_custkey)) AS browse_to_checkout_percent FROM orders o;
SELECT ROUND(100.0 * COUNT(DISTINCT c.c_custkey) / NULLIF(COUNT(DISTINCT o.o_custkey), 0)) AS browse_to_checkout_percent FROM orders o LEFT JOIN customer c ON o.o_custkey = c.c_custkey;
7,287.687
2,556.797
{ "Plan Width": 32, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 7269.022, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 20094339.26, "Actual Total Time": 7269.024, "Startup Cost": 20094339.23, "Plans": [ { "Relatio...
{ "Plan Width": 32, "Actual Rows": 1, "Plan Rows": 1, "Actual Startup Time": 2540.02, "Node Type": "Aggregate", "Actual Loops": 1, "Parallel Aware": false, "Strategy": "Plain", "Total Cost": 181726.23, "Actual Total Time": 2540.022, "Startup Cost": 181726.2, "Plans": [ { "Plan Width": ...
medium
300
tpch
SELECT DISTINCT ON (p_type, p_name) p_name AS name, p_type AS category, MAX(p_retailprice) OVER (PARTITION BY p_type, p_name) AS max_score FROM part;
SELECT p_name AS name, p_type AS category, MAX(p_retailprice) AS max_score FROM (SELECT p_name, p_type, p_retailprice FROM part WHERE p_retailprice >= 0) AS filtered_parts GROUP BY p_type, p_name;
3,127.27
871.731
{ "Node Type": "Unique", "Total Cost": 113433.81, "Plan Width": 86, "Parallel Aware": false, "Plan Rows": 600000, "Startup Cost": 98433.81, "Plans": [ { "Node Type": "WindowAgg", "Parent Relationship": "Outer", "Total Cost": 110433.81, "Plan Width": 86, "Parallel Aware": ...
{ "Node Type": "Aggregate", "Total Cost": 106733.43, "Plan Width": 86, "Parallel Aware": false, "Plan Rows": 599940, "Strategy": "Hashed", "Startup Cost": 87844.69, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Total Cost": 19789, "Relation Name": "pa...
easy