-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
CREATE TABLE customer ( | ||
c_id INT, | ||
c_d_id INT, | ||
c_w_id INT, | ||
c_first VARCHAR(16), | ||
c_middle CHAR(2), | ||
c_last VARCHAR(16), | ||
c_street_1 VARCHAR(20), | ||
c_street_2 VARCHAR(20), | ||
c_city VARCHAR(20), | ||
c_state CHAR(2), | ||
c_zip CHAR(9), | ||
c_phone CHAR(16), | ||
c_since TIMESTAMP, | ||
c_credit CHAR(2), | ||
c_credit_lim DECIMAL(12,2), | ||
c_discount DECIMAL(4,4), | ||
c_balance DECIMAL(12,2), | ||
c_ytd_payment DECIMAL(12,2), | ||
c_payment_cnt INT, | ||
c_delivery_cnt INT, | ||
c_data VARCHAR(500), | ||
PRIMARY KEY (c_w_id, c_d_id, c_id), | ||
FOREIGN KEY (c_w_id, c_d_id) REFERENCES district(d_w_id, d_id) | ||
); | ||
|
||
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, | ||
c_last VARCHAR(20), -- TODO check | ||
h_amount DECIMAL(5,2), | ||
h_date TIMESTAMP, | ||
datetime_ TIMESTAMP | ||
); | ||
|
||
-- incremental fails with this query present | ||
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 | ||
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 | ||
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
CREATE TABLE customer ( | ||
c_id INT, | ||
c_d_id INT, | ||
c_w_id INT, | ||
c_first VARCHAR(16), | ||
c_middle CHAR(2), | ||
c_last VARCHAR(16), | ||
c_street_1 VARCHAR(20), | ||
c_street_2 VARCHAR(20), | ||
c_city VARCHAR(20), | ||
c_state CHAR(2), | ||
c_zip CHAR(9), | ||
c_phone CHAR(16), | ||
c_since TIMESTAMP, | ||
c_credit CHAR(2), | ||
c_credit_lim DECIMAL(12,2), | ||
c_discount DECIMAL(4,4), | ||
c_balance DECIMAL(12,2), | ||
c_ytd_payment DECIMAL(12,2), | ||
c_payment_cnt INT, | ||
c_delivery_cnt INT, | ||
c_data VARCHAR(500), | ||
PRIMARY KEY (c_w_id, c_d_id, c_id), | ||
FOREIGN KEY (c_w_id, c_d_id) REFERENCES district(d_w_id, d_id) | ||
); | ||
|
||
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, | ||
c_last VARCHAR(20), -- TODO check | ||
h_amount DECIMAL(5,2), | ||
h_date TIMESTAMP, | ||
datetime_ TIMESTAMP | ||
); | ||
|
||
-- incremental fails with this query present | ||
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 | ||
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 | ||
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
CREATE TABLE customer ( | ||
c_id INT, | ||
c_d_id INT, | ||
c_w_id INT, | ||
c_first VARCHAR(16), | ||
c_middle CHAR(2), | ||
c_last VARCHAR(16), | ||
c_street_1 VARCHAR(20), | ||
c_street_2 VARCHAR(20), | ||
c_city VARCHAR(20), | ||
c_state CHAR(2), | ||
c_zip CHAR(9), | ||
c_phone CHAR(16), | ||
c_since TIMESTAMP, | ||
c_credit CHAR(2), | ||
c_credit_lim DECIMAL(12,2), | ||
c_discount DECIMAL(4,4), | ||
c_balance DECIMAL(12,2), | ||
c_ytd_payment DECIMAL(12,2), | ||
c_payment_cnt INT, | ||
c_delivery_cnt INT, | ||
c_data VARCHAR(500), | ||
PRIMARY KEY (c_w_id, c_d_id, c_id), | ||
FOREIGN KEY (c_w_id, c_d_id) REFERENCES district(d_w_id, d_id) | ||
); | ||
|
||
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, | ||
c_last VARCHAR(20), -- TODO check | ||
h_amount DECIMAL(5,2), | ||
h_date TIMESTAMP, | ||
datetime_ TIMESTAMP | ||
); | ||
|
||
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; |