From f6ed5c958906017b6ac6715243647de0b6d31550 Mon Sep 17 00:00:00 2001 From: yanz Date: Sat, 18 Jan 2025 01:21:39 +0800 Subject: [PATCH] update test cases --- test/sql/test_iceberg/R/test_pkfk_property | 79 ++++++++++++++++++++-- test/sql/test_iceberg/T/test_pkfk_property | 46 ++++++++++--- 2 files changed, 113 insertions(+), 12 deletions(-) diff --git a/test/sql/test_iceberg/R/test_pkfk_property b/test/sql/test_iceberg/R/test_pkfk_property index 198eba234c39e..43f11a7beaf84 100644 --- a/test/sql/test_iceberg/R/test_pkfk_property +++ b/test/sql/test_iceberg/R/test_pkfk_property @@ -31,6 +31,15 @@ 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 @@ -38,14 +47,76 @@ 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 \ No newline at end of file diff --git a/test/sql/test_iceberg/T/test_pkfk_property b/test/sql/test_iceberg/T/test_pkfk_property index 0d3ad3fef889f..05b91b66b4a61 100644 --- a/test/sql/test_iceberg/T/test_pkfk_property +++ b/test/sql/test_iceberg/T/test_pkfk_property @@ -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;