Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions benchmark/configs/utility/as_tpcds_sf30.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"sf": 30,
"db": "benchmark/results/tpcds_sf30/data.db",
"queries_dir": "benchmark/results/tpcds_sf30/queries",
"out_dir": "benchmark/results/tpcds_sf30",
"schema": "benchmark/tpcds/schema.sql",
"threads": 16,
"memory_limit": "30GB",
"repetitions": 5,
"timeout_seconds": 3600,
"extension_directory": "benchmark/results/tpcds_extensions"
}
8 changes: 4 additions & 4 deletions benchmark/microbench/approx_sum_stability.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ WITH bit_positions AS (SELECT unnest(range(64)) as bit_pos),
FROM accuracy_test, bit_positions GROUP BY dist, bit_pos),
exact_lists AS (SELECT dist, list(exact_sum ORDER BY bit_pos) as exact_counters
FROM exact_sums GROUP BY dist),
approx_sums AS (SELECT dist, as_sum(priv_hash(hash(rowid)), val) as approx_counters
approx_sums AS (SELECT dist, list_transform(as_sum(priv_hash(hash(rowid)), val), lambda x: x / 2.0) as approx_counters
FROM accuracy_test GROUP BY dist),
per_counter_stats AS (
SELECT e.dist, e.exact_counters, a.approx_counters,
[POWER(e.exact_counters[x+1] - a.approx_counters[x+1] / 2, 2) FOR x IN range(64)] as sq_diffs,
[POWER(e.exact_counters[x+1] - a.approx_counters[x+1], 2) FOR x IN range(64)] as sq_diffs,
[CASE WHEN e.exact_counters[x+1] = 0 THEN NULL
ELSE 100.0 * (a.approx_counters[x+1] / 2 - e.exact_counters[x+1]) / e.exact_counters[x+1]
ELSE 100.0 * (a.approx_counters[x+1] - e.exact_counters[x+1]) / e.exact_counters[x+1]
END FOR x IN range(64)] as pct_diffs
FROM exact_lists e JOIN approx_sums a ON e.dist = a.dist)
SELECT
dist, cast(sqrt(list_avg(sq_diffs)) as bigint) as rmse,
ROUND(list_avg(list_transform(pct_diffs, x -> abs(x))), 4) as pct_err,
ROUND(list_avg(list_transform(pct_diffs, lambda x: abs(x))), 4) as pct_err,
ROUND(POWER(rmse, 2) / NULLIF(list_var_samp(approx_counters), 0), 4) as z_squared,
cast(list_var_samp(exact_counters) as float) as var_exact,
cast(list_var_samp(approx_counters) as float) as var_approx,
Expand Down
23 changes: 23 additions & 0 deletions benchmark/tpcds/as_queries/q01.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Handwritten PAC SQL, following the compiled aggregate scopes and scalar output semantics.
-- The CTE exports customer totals unchanged; its correlated AVG is stochastic across customers.
WITH customer_total_return AS (SELECT sr_customer_sk AS ctr_customer_sk,
sr_store_sk AS ctr_store_sk,
sum(sr_return_amt) AS ctr_total_return
FROM store_returns,
date_dim
WHERE sr_returned_date_sk = d_date_sk
AND d_year = 2000
GROUP BY sr_customer_sk,
sr_store_sk)
SELECT c_customer_id
FROM customer_total_return ctr1,
store,
customer
WHERE priv_filter_gt(CAST(CAST(ctr1.ctr_total_return AS DOUBLE) * 0.8333333333333334 AS FLOAT), (SELECT priv_div(as_sum(priv_hash(hash(ctr2.ctr_customer_sk)), ctr_total_return), as_count(priv_hash(hash(ctr2.ctr_customer_sk)), ctr_total_return))
FROM customer_total_return ctr2
WHERE ctr1.ctr_store_sk = ctr2.ctr_store_sk))
AND s_store_sk = ctr1.ctr_store_sk
AND s_state = 'TN'
AND ctr1.ctr_customer_sk = c_customer_sk
ORDER BY c_customer_id
LIMIT 100;
14 changes: 14 additions & 0 deletions benchmark/tpcds/as_queries/q03.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Handwritten PAC SQL, following the compiled aggregate scopes and scalar output semantics.
WITH asa_states AS (SELECT dt.d_year AS d_year, item.i_brand_id AS brand_id, item.i_brand AS brand, as_sum(priv_hash(hash(ss_customer_sk)), CAST(ss_ext_sales_price AS DOUBLE)) AS sum_agg FROM date_dim dt,
store_sales,
item
WHERE dt.d_date_sk = store_sales.ss_sold_date_sk
AND store_sales.ss_item_sk = item.i_item_sk
AND item.i_manufact_id = 128
AND dt.d_moy=11
GROUP BY dt.d_year,
item.i_brand,
item.i_brand_id
),
asa_ranked AS (SELECT * FROM asa_states ORDER BY d_year, priv_mean(sum_agg) DESC, brand_id LIMIT 100)
SELECT d_year, brand_id, brand, CAST(as_noised(sum_agg) AS DECIMAL(38,2)) AS sum_agg FROM asa_ranked ORDER BY d_year, sum_agg DESC, brand_id;
120 changes: 120 additions & 0 deletions benchmark/tpcds/as_queries/q04.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
-- Handwritten PAC SQL, following the compiled aggregate scopes and scalar output semantics.
-- Keep year_total scalar inside its CTE; outer customer/year joins retain ordinary PAC scalar semantics.
WITH year_total AS (SELECT c_customer_id customer_id,
c_first_name customer_first_name,
c_last_name customer_last_name,
c_preferred_cust_flag customer_preferred_cust_flag,
c_birth_country customer_birth_country,
c_login customer_login,
c_email_address customer_email_address,
d_year dyear,
as_noised_sum(priv_hash(hash(c_customer_sk)), ((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total,
's' sale_type
FROM customer,
store_sales,
date_dim
WHERE c_customer_sk = ss_customer_sk
AND ss_sold_date_sk = d_date_sk
GROUP BY c_customer_id,
c_first_name,
c_last_name,
c_preferred_cust_flag,
c_birth_country,
c_login,
c_email_address,
d_year
UNION ALL SELECT c_customer_id customer_id,
c_first_name customer_first_name,
c_last_name customer_last_name,
c_preferred_cust_flag customer_preferred_cust_flag,
c_birth_country customer_birth_country,
c_login customer_login,
c_email_address customer_email_address,
d_year dyear,
as_noised_sum(priv_hash(hash(c_customer_sk)), (((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2)) year_total,
'c' sale_type
FROM customer,
catalog_sales,
date_dim
WHERE c_customer_sk = cs_bill_customer_sk
AND cs_sold_date_sk = d_date_sk
GROUP BY c_customer_id,
c_first_name,
c_last_name,
c_preferred_cust_flag,
c_birth_country,
c_login,
c_email_address,
d_year
UNION ALL SELECT c_customer_id customer_id,
c_first_name customer_first_name,
c_last_name customer_last_name,
c_preferred_cust_flag customer_preferred_cust_flag,
c_birth_country customer_birth_country,
c_login customer_login,
c_email_address customer_email_address,
d_year dyear,
as_noised_sum(priv_hash(hash(c_customer_sk)), (((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2)) year_total,
'w' sale_type
FROM customer,
web_sales,
date_dim
WHERE c_customer_sk = ws_bill_customer_sk
AND ws_sold_date_sk = d_date_sk
GROUP BY c_customer_id,
c_first_name,
c_last_name,
c_preferred_cust_flag,
c_birth_country,
c_login,
c_email_address,
d_year)
SELECT t_s_secyear.customer_id,
t_s_secyear.customer_first_name,
t_s_secyear.customer_last_name,
t_s_secyear.customer_preferred_cust_flag
FROM year_total t_s_firstyear,
year_total t_s_secyear,
year_total t_c_firstyear,
year_total t_c_secyear,
year_total t_w_firstyear,
year_total t_w_secyear
WHERE t_s_secyear.customer_id = t_s_firstyear.customer_id
AND t_s_firstyear.customer_id = t_c_secyear.customer_id
AND t_s_firstyear.customer_id = t_c_firstyear.customer_id
AND t_s_firstyear.customer_id = t_w_firstyear.customer_id
AND t_s_firstyear.customer_id = t_w_secyear.customer_id
AND t_s_firstyear.sale_type = 's'
AND t_c_firstyear.sale_type = 'c'
AND t_w_firstyear.sale_type = 'w'
AND t_s_secyear.sale_type = 's'
AND t_c_secyear.sale_type = 'c'
AND t_w_secyear.sale_type = 'w'
AND t_s_firstyear.dyear = 2001
AND t_s_secyear.dyear = 2001+1
AND t_c_firstyear.dyear = 2001
AND t_c_secyear.dyear = 2001+1
AND t_w_firstyear.dyear = 2001
AND t_w_secyear.dyear = 2001+1
AND t_s_firstyear.year_total > 0
AND t_c_firstyear.year_total > 0
AND t_w_firstyear.year_total > 0
AND CASE
WHEN t_c_firstyear.year_total > 0 THEN t_c_secyear.year_total / t_c_firstyear.year_total
ELSE NULL
END > CASE
WHEN t_s_firstyear.year_total > 0 THEN t_s_secyear.year_total / t_s_firstyear.year_total
ELSE NULL
END
AND CASE
WHEN t_c_firstyear.year_total > 0 THEN t_c_secyear.year_total / t_c_firstyear.year_total
ELSE NULL
END > CASE
WHEN t_w_firstyear.year_total > 0 THEN t_w_secyear.year_total / t_w_firstyear.year_total
ELSE NULL
END
ORDER BY t_s_secyear.customer_id NULLS FIRST,
t_s_secyear.customer_first_name NULLS FIRST,
t_s_secyear.customer_last_name NULLS FIRST,
t_s_secyear.customer_preferred_cust_flag NULLS FIRST
LIMIT 100;
26 changes: 26 additions & 0 deletions benchmark/tpcds/as_queries/q06.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- PAC COUNT with scalar HAVING, as in the compiled plan.
SELECT a.ca_state state,
as_noised_count(priv_hash(hash(c.c_customer_sk)), 1::BIGINT) cnt
FROM customer_address a ,
customer c ,
store_sales s ,
date_dim d ,
item i
WHERE a.ca_address_sk = c.c_current_addr_sk
AND c.c_customer_sk = s.ss_customer_sk
AND s.ss_sold_date_sk = d.d_date_sk
AND s.ss_item_sk = i.i_item_sk
AND d.d_month_seq =
(SELECT DISTINCT (d_month_seq)
FROM date_dim
WHERE d_year = 2001
AND d_moy = 1 )
AND i.i_current_price > 1.2 *
(SELECT avg(j.i_current_price)
FROM item j
WHERE j.i_category = i.i_category)
GROUP BY a.ca_state
HAVING as_noised_count(priv_hash(hash(c.c_customer_sk)), 1::BIGINT) >= 10
ORDER BY cnt NULLS FIRST,
a.ca_state NULLS FIRST
LIMIT 100;
24 changes: 24 additions & 0 deletions benchmark/tpcds/as_queries/q07.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- Handwritten PAC aggregates; automatic query rewriting is disabled by the benchmark.
SELECT i_item_id,
(CAST(as_noised_sum(priv_hash(hash(ss_customer_sk)), ss_quantity) AS DOUBLE) / CAST(as_noised_count(priv_hash(hash(ss_customer_sk)), ss_quantity) AS DOUBLE)) agg1,
(CAST(as_noised_sum(priv_hash(hash(ss_customer_sk)), ss_list_price) AS DOUBLE) / CAST(as_noised_count(priv_hash(hash(ss_customer_sk)), ss_list_price) AS DOUBLE)) agg2,
(CAST(as_noised_sum(priv_hash(hash(ss_customer_sk)), ss_coupon_amt) AS DOUBLE) / CAST(as_noised_count(priv_hash(hash(ss_customer_sk)), ss_coupon_amt) AS DOUBLE)) agg3,
(CAST(as_noised_sum(priv_hash(hash(ss_customer_sk)), ss_sales_price) AS DOUBLE) / CAST(as_noised_count(priv_hash(hash(ss_customer_sk)), ss_sales_price) AS DOUBLE)) agg4
FROM store_sales,
customer_demographics,
date_dim,
item,
promotion
WHERE ss_sold_date_sk = d_date_sk
AND ss_item_sk = i_item_sk
AND ss_cdemo_sk = cd_demo_sk
AND ss_promo_sk = p_promo_sk
AND cd_gender = 'M'
AND cd_marital_status = 'S'
AND cd_education_status = 'College'
AND (p_channel_email = 'N'
OR p_channel_event = 'N')
AND d_year = 2000
GROUP BY i_item_id
ORDER BY i_item_id
LIMIT 100;
8 changes: 8 additions & 0 deletions benchmark/tpcds/as_queries/q09.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Handwritten PAC SQL, following the compiled aggregate scopes and scalar output semantics.
-- Evaluate CASE lane-wise over counter lists and finalize once; all fifteen scalar subqueries remain.
SELECT CAST(as_noised(list_transform(list_zip((SELECT as_count(priv_hash(hash(ss_customer_sk)),1::BIGINT) FROM store_sales WHERE ss_quantity BETWEEN 1 AND 20), (SELECT priv_div(as_sum(priv_hash(hash(ss_customer_sk)), CAST(ss_ext_discount_amt AS DOUBLE)),as_count(priv_hash(hash(ss_customer_sk)),ss_ext_discount_amt)) FROM store_sales WHERE ss_quantity BETWEEN 1 AND 20), (SELECT priv_div(as_sum(priv_hash(hash(ss_customer_sk)), CAST(ss_net_paid AS DOUBLE)),as_count(priv_hash(hash(ss_customer_sk)),ss_net_paid)) FROM store_sales WHERE ss_quantity BETWEEN 1 AND 20)), lambda x: CASE WHEN x[1] > 74129 THEN x[2] ELSE x[3] END)) AS DOUBLE) AS bucket1,
CAST(as_noised(list_transform(list_zip((SELECT as_count(priv_hash(hash(ss_customer_sk)),1::BIGINT) FROM store_sales WHERE ss_quantity BETWEEN 21 AND 40), (SELECT priv_div(as_sum(priv_hash(hash(ss_customer_sk)), CAST(ss_ext_discount_amt AS DOUBLE)),as_count(priv_hash(hash(ss_customer_sk)),ss_ext_discount_amt)) FROM store_sales WHERE ss_quantity BETWEEN 21 AND 40), (SELECT priv_div(as_sum(priv_hash(hash(ss_customer_sk)), CAST(ss_net_paid AS DOUBLE)),as_count(priv_hash(hash(ss_customer_sk)),ss_net_paid)) FROM store_sales WHERE ss_quantity BETWEEN 21 AND 40)), lambda x: CASE WHEN x[1] > 122840 THEN x[2] ELSE x[3] END)) AS DOUBLE) AS bucket2,
CAST(as_noised(list_transform(list_zip((SELECT as_count(priv_hash(hash(ss_customer_sk)),1::BIGINT) FROM store_sales WHERE ss_quantity BETWEEN 41 AND 60), (SELECT priv_div(as_sum(priv_hash(hash(ss_customer_sk)), CAST(ss_ext_discount_amt AS DOUBLE)),as_count(priv_hash(hash(ss_customer_sk)),ss_ext_discount_amt)) FROM store_sales WHERE ss_quantity BETWEEN 41 AND 60), (SELECT priv_div(as_sum(priv_hash(hash(ss_customer_sk)), CAST(ss_net_paid AS DOUBLE)),as_count(priv_hash(hash(ss_customer_sk)),ss_net_paid)) FROM store_sales WHERE ss_quantity BETWEEN 41 AND 60)), lambda x: CASE WHEN x[1] > 56580 THEN x[2] ELSE x[3] END)) AS DOUBLE) AS bucket3,
CAST(as_noised(list_transform(list_zip((SELECT as_count(priv_hash(hash(ss_customer_sk)),1::BIGINT) FROM store_sales WHERE ss_quantity BETWEEN 61 AND 80), (SELECT priv_div(as_sum(priv_hash(hash(ss_customer_sk)), CAST(ss_ext_discount_amt AS DOUBLE)),as_count(priv_hash(hash(ss_customer_sk)),ss_ext_discount_amt)) FROM store_sales WHERE ss_quantity BETWEEN 61 AND 80), (SELECT priv_div(as_sum(priv_hash(hash(ss_customer_sk)), CAST(ss_net_paid AS DOUBLE)),as_count(priv_hash(hash(ss_customer_sk)),ss_net_paid)) FROM store_sales WHERE ss_quantity BETWEEN 61 AND 80)), lambda x: CASE WHEN x[1] > 10097 THEN x[2] ELSE x[3] END)) AS DOUBLE) AS bucket4,
CAST(as_noised(list_transform(list_zip((SELECT as_count(priv_hash(hash(ss_customer_sk)),1::BIGINT) FROM store_sales WHERE ss_quantity BETWEEN 81 AND 100), (SELECT priv_div(as_sum(priv_hash(hash(ss_customer_sk)), CAST(ss_ext_discount_amt AS DOUBLE)),as_count(priv_hash(hash(ss_customer_sk)),ss_ext_discount_amt)) FROM store_sales WHERE ss_quantity BETWEEN 81 AND 100), (SELECT priv_div(as_sum(priv_hash(hash(ss_customer_sk)), CAST(ss_net_paid AS DOUBLE)),as_count(priv_hash(hash(ss_customer_sk)),ss_net_paid)) FROM store_sales WHERE ss_quantity BETWEEN 81 AND 100)), lambda x: CASE WHEN x[1] > 165306 THEN x[2] ELSE x[3] END)) AS DOUBLE) AS bucket5
FROM reason WHERE r_reason_sk=1;
66 changes: 66 additions & 0 deletions benchmark/tpcds/as_queries/q10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
-- Handwritten PAC SQL, following the compiled aggregate scopes and scalar output semantics.
SELECT cd_gender,
cd_marital_status,
cd_education_status,
as_noised_count(priv_hash(hash(c.c_customer_sk)), 1::BIGINT) cnt1,
cd_purchase_estimate,
as_noised_count(priv_hash(hash(c.c_customer_sk)), 1::BIGINT) cnt2,
cd_credit_rating,
as_noised_count(priv_hash(hash(c.c_customer_sk)), 1::BIGINT) cnt3,
cd_dep_count,
as_noised_count(priv_hash(hash(c.c_customer_sk)), 1::BIGINT) cnt4,
cd_dep_employed_count,
as_noised_count(priv_hash(hash(c.c_customer_sk)), 1::BIGINT) cnt5,
cd_dep_college_count,
as_noised_count(priv_hash(hash(c.c_customer_sk)), 1::BIGINT) cnt6
FROM customer c,
customer_address ca,
customer_demographics
WHERE c.c_current_addr_sk = ca.ca_address_sk
AND ca_county IN ('Rush County',
'Toole County',
'Jefferson County',
'Dona Ana County',
'La Porte County')
AND cd_demo_sk = c.c_current_cdemo_sk
AND EXISTS
(SELECT *
FROM store_sales,
date_dim
WHERE c.c_customer_sk = ss_customer_sk
AND ss_sold_date_sk = d_date_sk
AND d_year = 2002
AND d_moy BETWEEN 1 AND 1+3)
AND (EXISTS
(SELECT *
FROM web_sales,
date_dim
WHERE c.c_customer_sk = ws_bill_customer_sk
AND ws_sold_date_sk = d_date_sk
AND d_year = 2002
AND d_moy BETWEEN 1 AND 1+3)
OR EXISTS
(SELECT *
FROM catalog_sales,
date_dim
WHERE c.c_customer_sk = cs_ship_customer_sk
AND cs_sold_date_sk = d_date_sk
AND d_year = 2002
AND d_moy BETWEEN 1 AND 1+3))
GROUP BY cd_gender,
cd_marital_status,
cd_education_status,
cd_purchase_estimate,
cd_credit_rating,
cd_dep_count,
cd_dep_employed_count,
cd_dep_college_count
ORDER BY cd_gender,
cd_marital_status,
cd_education_status,
cd_purchase_estimate,
cd_credit_rating,
cd_dep_count,
cd_dep_employed_count,
cd_dep_college_count
LIMIT 100;
Loading
Loading