Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…al_tranactions into inc_txns
  • Loading branch information
Tiemo Bang committed Jul 11, 2024
2 parents dd21cd3 + cdef88b commit 2cb8cb0
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 306 deletions.
Binary file modified incremental_transactions/tpcc/graphs/byname_max_sql.rs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified incremental_transactions/tpcc/graphs/byname_sql.rs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified incremental_transactions/tpcc/graphs/byname_sql_incremental.rs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(in_warehouse_static, in_warehouse, in_district_static, in_district_next_id, in_district_ytd, in_customer, in_transaction_parameters, out_ncustomers, out_cust_enum, out_cust_agg, out_cust_med, out_cust_med, out_cust_max, out_median_pos)
(in_warehouse_static, in_warehouse, in_district_static, in_district_next_id, in_district_ytd, in_customer, in_transaction_parameters, out_cust_agg, out_cust_byname)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(in_warehouse_static, in_warehouse, in_district_static, in_district_next_id, in_district_ytd, in_customer, in_transaction_parameters, out_ncustomers, out_cust_enum, out_cust_agg, out_cust_med, out_cust_med, out_cust_max, out_median_pos)
(in_warehouse_static, in_warehouse, in_district_static, in_district_next_id, in_district_ytd, in_customer, in_transaction_parameters, out_cust_agg, out_cust_byname)
116 changes: 4 additions & 112 deletions incremental_transactions/tpcc/sql/byname.sql
Original file line number Diff line number Diff line change
@@ -1,127 +1,19 @@
-- Ignoring byname for now
-- if (byname)
-- {


-- CREATE VIEW ncustomers AS -- SELECT count(c_id) INTO :namecnt
-- SELECT count(c_id) AS name_cnt -- FROM customer
-- FROM customer AS c, -- WHERE c_last=:c_last AND c_d_id=:c_d_id AND c_w_id=:c_w_id;
-- transaction_parameters as t
-- WHERE c.c_last = t.c_last
-- AND c.c_d_id = t.c_d_id
-- AND c.c_w_id = t.c_w_id;

-- CREATE VIEW cust_enum AS
-- SELECT c.c_first, c.c_middle, c.c_id,
-- c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip,
-- c.c_phone, c.c_credit, c.c_credit_lim,
-- c.c_discount, c.c_balance, c.c_since
-- FROM customer AS c,
-- transaction_parameters AS t
-- WHERE c.c_last = t.c_last
-- AND c.c_d_id = t.c_d_id
-- AND c.c_w_id = t.c_w_id
-- ORDER BY c_first;

CREATE VIEW cust_agg AS
SELECT ARRAY_AGG(c_id ORDER BY c_first) AS cust_array
FROM (SELECT c.c_id, c.c_first
SELECT ARRAY_AGG((c_id + c_w_id + c_d_id) ORDER BY c_first) AS cust_array
FROM (SELECT c.c_id, c.c_w_id, c.c_d_id, c.c_first
FROM customer AS c,
transaction_parameters AS t
WHERE c.c_last = t.c_last
AND c.c_d_id = t.c_d_id
AND c.c_w_id = t.c_w_id
ORDER BY c_first);

CREATE VIEW cust_med AS
CREATE VIEW cust_byname AS
SELECT c.c_first, c.c_middle, c.c_id,
c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip,
c.c_phone, c.c_credit, c.c_credit_lim,
c.c_discount, c.c_balance, c.c_since
FROM customer as c,
cust_agg as a,
transaction_parameters as t
WHERE c.c_id = a.cust_array[(ARRAY_LENGTH(a.cust_array) / 2) + 1];

-- CREATE VIEW cust_med AS
-- SELECT c.c_first, c.c_middle, c.c_id,
-- c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip,
-- c.c_phone, c.c_credit, c.c_credit_lim,
-- c.c_discount, c.c_balance, c.c_since
-- FROM cust_agg AS a,
-- cust_enum AS c,
-- transaction_parameters AS t
-- WHERE c.c_id = a.cust_array[FLOOR(ARRAY_LENGTH(a.cust_array) / 2) + 1];
--
-- create view cust_max as
-- SELECT c.c_first, c.c_middle, c.c_id,
-- c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip,
-- c.c_phone, c.c_credit, c.c_credit_lim,
-- c.c_discount, c.c_balance, c.c_since
-- FROM customer AS c,
-- transaction_parameters AS t
-- WHERE c.c_last = t.c_last
-- AND c.c_d_id = t.c_d_id
-- AND c.c_w_id = t.c_w_id
-- AND c_first = (select max(c_first) from customer LIMIT 1)
-- LIMIT 1;

-- CREATE VIEW cust_max AS
-- SELECT c_first, c_last
-- FROM customer
-- ORDER BY c_first
-- LIMIT 1;

-- SELECT c_first, c_middle, c_id,
-- c_street_1, c_street_2, c_city, c_state, c_zip,
-- c_phone, c_credit, c_credit_lim,
-- c_discount, c_balance, c_since


-- DECLARE c_byname CURSOR FOR
-- SELECT c_first, c_middle, c_id,
-- c_street_1, c_street_2, c_city, c_state, c_zip,
-- c_phone, c_credit, c_credit_lim,
-- c_discount, c_balance, c_since
-- FROM customer
-- WHERE c_w_id=:c_w_id AND c_d_id=:c_d_id AND c_last=:c_last
-- ORDER BY c_first;

-- CREATE VIEW median_pos AS
-- SELECT c_first, c_middle, c_id,
-- c_street_1, c_street_2, c_city, c_state, c_zip,
-- c_phone, c_credit, c_credit_lim,
-- c_discount, c_balance, c_since
-- FROM cust_last
-- ORDER BY c_first
-- LIMIT 1 OFFSET (
-- SELECT FLOOR((COUNT(*) - 1) / 2)
-- FROM cust_last
-- );

-- OPEN c_byname;
--
-- if (namecnt%2) namecnt++; --Locate midpoint customer;
-- for (n=0; n<namecnt/2; n++)
-- {
-- EXEC SQL FETCH c_byname
-- INTO :c_first, :c_middle, :c_id,
-- :c_street_1, :c_street_2, :c_city, :c_state, :c_zip,
-- :c_phone, :c_credit, :c_credit_lim,
-- :c_discount, :c_balance, :c_since;
-- }
-- EXEC SQL CLOSE c_byname;
--}
/*
else
{
EXEC SQL SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip,
c_phone, c_credit, c_credit_lim,
c_discount, c_balance, c_since
INTO :c_first, :c_middle, :c_last,
:c_street_1, :c_street_2, :c_city, :c_state, :c_zip,
:c_phone, :c_credit, :c_credit_lim,
:c_discount, :c_balance, :c_since
FROM customer
WHERE c_w_id=:c_w_id AND c_d_id=:c_d_id AND c_id=:c_id;
} */
WHERE (c.c_id + c.c_w_id + c.c_d_id) = a.cust_array[(ARRAY_LENGTH(a.cust_array) / 2) + 1];
120 changes: 71 additions & 49 deletions incremental_transactions/tpcc/sql/payment.sql
Original file line number Diff line number Diff line change
@@ -1,68 +1,86 @@
-- gettimestamp(datetime);
-- Make transaction parameters a table to join against
CREATE TABLE transaction_parameters (
txn_id INT PRIMARY KEY,
w_id INT,
d_id INT,
c_id INT,
c_w_id INT,
c_d_id INT,
h_amount DECIMAL(5,2),
h_date TIMESTAMP,
datetime_ TIMESTAMP
);

/* UPDATE warehouse SET w_ytd = w_ytd + :h_amount
WHERE w_id=:w_id; */
CREATE VIEW warehouse_updates AS SELECT t.txn_id, w.w_id, (w.w_ytd + t.h_amount) AS w_ytd FROM warehouse AS w, transaction_parameters AS t WHERE w.w_id=t.w_id;
CREATE VIEW warehouse_updates AS SELECT t.txn_id, w.w_id, (w.w_ytd + t.h_amount) AS w_ytd
FROM warehouse AS w, transaction_parameters AS t
WHERE w.w_id=t.w_id;

/* SELECT w_street_1, w_street_2, w_city, w_state, w_zip, w_name
INTO :w_street_1, :w_street_2, :w_city, :w_state, :w_zip, :w_name
FROM warehouse
WHERE w_id=:w_id; */
CREATE VIEW warehouse_select AS SELECT w.w_street_1, w.w_street_2, w.w_city, w.w_state, w.w_zip, w.w_name, t.txn_id FROM warehouse_static AS w, transaction_parameters AS t WHERE w.w_id=t.w_id;
CREATE VIEW warehouse_select AS SELECT w.w_street_1, w.w_street_2, w.w_city, w.w_state, w.w_zip, w.w_name, t.txn_id
FROM warehouse_static AS w, transaction_parameters AS t
WHERE w.w_id=t.w_id;

/* UPDATE district SET d_ytd = d_ytd + :h_amount
WHERE d_w_id=:w_id AND d_id=:d_id; */
CREATE VIEW district_updates AS SELECT d.d_w_id, d.d_id, (d.d_ytd + t.h_amount) AS d_ytd FROM district_ytd AS d, transaction_parameters AS t WHERE d.d_w_id=t.w_id AND d.d_id=t.d_id;
CREATE VIEW district_updates AS SELECT d.d_w_id, d.d_id, (d.d_ytd + t.h_amount) AS d_ytd
FROM district_ytd AS d, transaction_parameters AS t
WHERE d.d_w_id=t.w_id AND d.d_id=t.d_id;

/* SELECT d_street_1, d_street_2, d_city, d_state, d_zip, d_name
INTO :d_street_1, :d_street_2, :d_city, :d_state, :d_zip, :d_name
FROM district
WHERE d_w_id=:w_id AND d_id=:d_id; */
CREATE VIEW district_select AS SELECT d.d_street_1, d.d_street_2, d.d_city, d.d_state, d.d_zip, d.d_name, t.txn_id FROM district_static AS d, transaction_parameters AS t WHERE d.d_w_id=t.w_id AND d.d_id=t.d_id;
CREATE VIEW district_select AS SELECT d.d_street_1, d.d_street_2, d.d_city, d.d_state, d.d_zip, d.d_name, t.txn_id
FROM district_static AS d, transaction_parameters AS t
WHERE d.d_w_id=t.w_id AND d.d_id=t.d_id;

-- Ignoring byname for now
/* if (byname)
{
SELECT count(c_id) INTO :namecnt
FROM customer
WHERE c_last=:c_last AND c_d_id=:c_d_id AND c_w_id=:c_w_id;
DECLARE c_byname CURSOR FOR
SELECT c_first, c_middle, c_id,
c_street_1, c_street_2, c_city, c_state, c_zip,
c_phone, c_credit, c_credit_lim,
c_discount, c_balance, c_since
FROM customer
WHERE c_w_id=:c_w_id AND c_d_id=:c_d_id AND c_last=:c_last
ORDER BY c_first;
OPEN c_byname;
if (namecnt%2) namecnt++; --Locate midpoint customer;
for (n=0; n<namecnt/2; n++)
{
EXEC SQL FETCH c_byname
INTO :c_first, :c_middle, :c_id,
:c_street_1, :c_street_2, :c_city, :c_state, :c_zip,
:c_phone, :c_credit, :c_credit_lim,
:c_discount, :c_balance, :c_since;
}
EXEC SQL CLOSE c_byname;
}
else
{
EXEC SQL SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip,
c_phone, c_credit, c_credit_lim,
c_discount, c_balance, c_since
INTO :c_first, :c_middle, :c_last,
:c_street_1, :c_street_2, :c_city, :c_state, :c_zip,
:c_phone, :c_credit, :c_credit_lim,
:c_discount, :c_balance, :c_since
FROM customer
WHERE c_w_id=:c_w_id AND c_d_id=:c_d_id AND c_id=:c_id;
} */
-- Using the simpler by-id else branch for now
CREATE VIEW customer_select AS SELECT c.c_first, c.c_middle, c.c_last, c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip, c.c_phone, c.c_credit, c.c_credit_lim, c.c_discount, c.c_balance, c.c_since, t.txn_id FROM customer AS c, transaction_parameters AS t WHERE c.c_w_id=t.c_w_id AND c.c_d_id=t.c_d_id AND c.c_id=t.c_id;
CREATE VIEW cust_agg AS -- if (byname)
SELECT ARRAY_AGG(c_id ORDER BY c_first) AS cust_array -- {
FROM (SELECT c.c_id, c.c_first -- SELECT count(c_id) INTO :namecnt
FROM customer AS c, -- FROM customer
transaction_parameters AS t -- WHERE c_last=:c_last AND c_d_id=:c_d_id AND c_w_id=:c_w_id;
WHERE c.c_last = t.c_last --
AND c.c_d_id = t.c_d_id -- DECLARE c_byname CURSOR FOR
AND c.c_w_id = t.c_w_id -- SELECT c_first, c_middle, c_id,
ORDER BY c_first); -- c_street_1, c_street_2, c_city, c_state, c_zip,
-- c_phone, c_credit, c_credit_lim,
CREATE VIEW cust_byname AS -- c_discount, c_balance, c_since
SELECT c.c_first, c.c_middle, c.c_id, -- FROM customer
c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip, -- WHERE c_w_id=:c_w_id AND c_d_id=:c_d_id AND c_last=:c_last
c.c_phone, c.c_credit, c.c_credit_lim, -- ORDER BY c_first;
c.c_discount, c.c_balance, c.c_since, t.txn_id --
FROM customer as c, -- OPEN c_byname;
cust_agg as a, --
transaction_parameters as t -- if (namecnt%2) namecnt++; --Locate midpoint customer;
WHERE c.c_id = a.cust_array[(ARRAY_LENGTH(a.cust_array) / 2) + 1]; -- for (n=0; n<namecnt/2; n++)
-- {
-- EXEC SQL FETCH c_byname
-- INTO :c_first, :c_middle, :c_id,
-- :c_street_1, :c_street_2, :c_city, :c_state, :c_zip,
-- :c_phone, :c_credit, :c_credit_lim,
-- :c_discount, :c_balance, :c_since;
-- }
-- EXEC SQL CLOSE c_byname;
-- }
CREATE VIEW customer_select AS -- else
SELECT c.c_first, c.c_middle, c.c_id, -- {
c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip, -- EXEC SQL SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip,
c.c_phone, c.c_credit, c.c_credit_lim, -- c_phone, c_credit, c_credit_lim,
c.c_discount, c.c_balance, c.c_since, t.txn_id -- c_discount, c_balance, c_since
FROM customer AS c, -- INTO :c_first, :c_middle, :c_last,
transaction_parameters AS t -- :c_street_1, :c_street_2, :c_city, :c_state, :c_zip,
WHERE c.c_w_id=t.c_w_id AND c.c_d_id=t.c_d_id AND c.c_id=t.c_id; -- :c_phone, :c_credit, :c_credit_lim,
-- :c_discount, :c_balance, :c_since
-- FROM customer
-- WHERE c_w_id=:c_w_id AND c_d_id=:c_d_id AND c_id=:c_id;
-- }
-- Using the simpler by-id else branch for now

-- Ignoring the BC credit branch for now, using the simpler else branch
/* c_balance += h_amount;
Expand All @@ -88,7 +106,9 @@ else
c_id = :c_id;
} */
-- TODO: Create a new customer record with the updated balance
CREATE VIEW customer_update AS SELECT c.c_first, c.c_middle, c.c_last, c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip, c.c_phone, c.c_credit, c.c_credit_lim, c.c_discount, (c.c_balance + t.h_amount) as c_balance, c.c_since FROM customer_select AS c, transaction_parameters as t WHERE c.txn_id=t.txn_id;
CREATE VIEW customer_update AS SELECT c.c_first, c.c_middle, c.c_last, c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip, c.c_phone, c.c_credit, c.c_credit_lim, c.c_discount, (c.c_balance + t.h_amount) as c_balance, c.c_since
FROM customer_select AS c, transaction_parameters as t
WHERE c.txn_id=t.txn_id;

/* strncpy(h_data,w_name,10);
h_data[10]='\0';
Expand All @@ -101,4 +121,6 @@ EXEC SQL INSERT INTO history (h_c_d_id, h_c_w_id, h_c_id, h_d_id,
h_w_id, h_date, h_amount, h_data)
VALUES (:c_d_id, :c_w_id, :c_id, :d_id,
:w_id, :datetime, :h_amount, :h_data); */
CREATE VIEW history_insert AS SELECT t.c_d_id AS h_c_d_id, t.c_w_id AS h_c_w_id, t.c_id AS h_c_id, t.d_id AS h_d_id, t.w_id AS h_w_id, t.datetime_ AS h_date, t.h_amount AS h_amount, CONCAT(w.w_name, d.d_name) AS h_data FROM transaction_parameters AS t, warehouse_select AS w, district_select AS d WHERE t.txn_id=w.txn_id AND t.txn_id=d.txn_id;
CREATE VIEW history_insert AS SELECT t.c_d_id AS h_c_d_id, t.c_w_id AS h_c_w_id, t.c_id AS h_c_id, t.d_id AS h_d_id, t.w_id AS h_w_id, t.datetime_ AS h_date, t.h_amount AS h_amount, CONCAT(w.w_name, d.d_name) AS h_data
FROM transaction_parameters AS t, warehouse_select AS w, district_select AS d
WHERE t.txn_id=w.txn_id AND t.txn_id=d.txn_id;
Loading

0 comments on commit 2cb8cb0

Please sign in to comment.