Skip to content

Commit

Permalink
update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dirtysalt committed Jan 17, 2025
1 parent 440298d commit f6ed5c9
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 12 deletions.
79 changes: 75 additions & 4 deletions test/sql/test_iceberg/R/test_pkfk_property
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,92 @@ INSERT INTO txn (id, created_at, payment_id) VALUES
(106, '2025-01-06', 1);
-- result:
-- !result
alter table payment set ("unique_constraints" = "id");
-- result:
-- !result
ALTER TABLE txn SET ("foreign_key_constraints" = "(payment_id) REFERENCES payment(id)");
-- result:
-- !result
set enable_ukfk_opt = false;
-- result:
-- !result
SET enable_rbo_table_prune=true;
-- result:
-- !result
SET enable_cbo_table_prune=true;
SET enable_table_prune_on_update = true;
-- result:
-- !result
explain logical select txn.id, txn.created_at, txn.payment_id from txn left join payment on payment.id = txn.payment_id;
alter table payment set ("unique_constraints" = "id");
function: assert_explain_not_contains("select txn.id, txn.created_at, txn.payment_id from txn left join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.payment")
-- result:
None
-- !result
ALTER TABLE txn SET ("foreign_key_constraints" = "(payment_id) REFERENCES payment(id)");
function: assert_explain_contains("select txn.id, txn.created_at, txn.payment_id from txn left join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.txn")
-- result:
None
-- !result
function: assert_explain_contains("select txn.id, txn.created_at, txn.payment_id from txn inner join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.payment")
-- result:
None
-- !result
function: assert_explain_contains("select txn.id, txn.created_at, txn.payment_id from txn inner join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.txn")
-- result:
None
-- !result
set enable_ukfk_opt = true;
-- result:
-- !result
SET enable_rbo_table_prune=false;
-- result:
-- !result
SET enable_cbo_table_prune=false;
SET enable_table_prune_on_update = false;
-- result:
-- !result
function: assert_explain_not_contains("select txn.id, txn.created_at, txn.payment_id from txn left join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.payment")
-- result:
None
-- !result
function: assert_explain_contains("select txn.id, txn.created_at, txn.payment_id from txn left join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.txn")
-- result:
None
-- !result
function: assert_explain_not_contains("select txn.id, txn.created_at, txn.payment_id from txn inner join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.payment")
-- result:
None
-- !result
function: assert_explain_contains("select txn.id, txn.created_at, txn.payment_id from txn inner join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.txn", "payment_id IS NOT NULL")
-- result:
None
-- !result
set enable_eliminate_agg = false;
-- result:
-- !result
function: assert_explain_contains("select count(1) as cnt, payment.id from payment group by payment.id;", "AGGREGATE")
-- result:
None
-- !result
set enable_eliminate_agg = true;
-- result:
-- !result
function: assert_explain_not_contains("select count(1) as cnt, payment.id from payment group by payment.id;", "AGGREGATE")
-- result:
None
-- !result
drop table payment force;
-- result:
-- !result
drop table txn force;
-- result:
E: (5502, "Getting analyzing error. Detail message: Unknown table 'txn'.")
-- !result
drop database iceberg_sql_test_${uuid0}.iceberg_db_${uuid0};
-- result:
E: (1064, 'Database iceberg_db_ad6df88aa3e146628e93381f4a4a9c04 not empty')
-- !result
drop catalog iceberg_sql_test_${uuid0};
-- result:
-- !result
explain logical select txn.id, txn.created_at, txn.payment_id from txn left join payment on payment.id = txn.payment_id;
set catalog default_catalog;
-- result:
-- !result
46 changes: 38 additions & 8 deletions test/sql/test_iceberg/T/test_pkfk_property
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,52 @@ INSERT INTO txn (id, created_at, payment_id) VALUES
(105, '2025-01-05', 5),
(106, '2025-01-06', 1);

-- add table properties
alter table payment set ("unique_constraints" = "id");
ALTER TABLE txn SET ("foreign_key_constraints" = "(payment_id) REFERENCES payment(id)");

-- because two groups of session variables can both work. here we can test one group of session variables.
set enable_ukfk_opt = false;
SET enable_rbo_table_prune=true;
SET enable_cbo_table_prune=true;
SET enable_table_prune_on_update = true;

explain logical select txn.id, txn.created_at, txn.payment_id from txn left join payment on payment.id = txn.payment_id;
-- payment can be elimiated
function: assert_explain_not_contains("select txn.id, txn.created_at, txn.payment_id from txn left join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.payment")
function: assert_explain_contains("select txn.id, txn.created_at, txn.payment_id from txn left join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.txn")

alter table payment set ("unique_constraints" = "id");
ALTER TABLE txn SET ("foreign_key_constraints" = "(payment_id) REFERENCES iceberg_sql_test_0b0212d10fe1436d8e346ee4e16c9877.iceberg_db_0b0212d10fe1436d8e346ee4e16c9877.payment(id)");
-- payment can not be elimiated because txn.id is nullable.
function: assert_explain_contains("select txn.id, txn.created_at, txn.payment_id from txn inner join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.payment")
function: assert_explain_contains("select txn.id, txn.created_at, txn.payment_id from txn inner join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.txn")


-- switch to another group of session variables
set enable_ukfk_opt = true;
SET enable_rbo_table_prune=false;
SET enable_cbo_table_prune=false;
SET enable_table_prune_on_update = false;

-- payment can be elimiated
function: assert_explain_not_contains("select txn.id, txn.created_at, txn.payment_id from txn left join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.payment")
function: assert_explain_contains("select txn.id, txn.created_at, txn.payment_id from txn left join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.txn")

-- payment can be elimiated with a extra predicate: payment_id is not null.
function: assert_explain_not_contains("select txn.id, txn.created_at, txn.payment_id from txn inner join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.payment")
function: assert_explain_contains("select txn.id, txn.created_at, txn.payment_id from txn inner join payment on payment.id = txn.payment_id", "TABLE: iceberg_db_${uuid0}.txn", "payment_id IS NOT NULL")


-- test elimiate agg on primary key
set enable_eliminate_agg = false;
function: assert_explain_contains("select count(1) as cnt, payment.id from payment group by payment.id;", "AGGREGATE")

explain logical select txn.id, txn.created_at, txn.payment_id from txn left join payment on payment.id = txn.payment_id;
set enable_eliminate_agg = true;
function: assert_explain_not_contains("select count(1) as cnt, payment.id from payment group by payment.id;", "AGGREGATE")


-- drop table payment force;
-- drop table txn force;
drop table payment force;
drop table txn force;

-- drop database iceberg_sql_test_${uuid0}.iceberg_db_${uuid0};
-- drop catalog iceberg_sql_test_${uuid0};
drop database iceberg_sql_test_${uuid0}.iceberg_db_${uuid0};
drop catalog iceberg_sql_test_${uuid0};

set catalog default_catalog;

0 comments on commit f6ed5c9

Please sign in to comment.