This is an automated email from the ASF dual-hosted git repository. zhangwenchao pushed a commit to branch fix_orca_empty_table in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 35fcdf24056457ce7162a53d1c18293e46d13d17 Author: zhangwenchao <[email protected]> AuthorDate: Tue Oct 28 14:37:24 2025 +0800 Fix orca judgement of whether relation is empty is not accurate. When retrieve RelStats, orca use reltuples is whether -1 to decide relation is empty. However, reltuples 0 also means relation is empty. Authored-by: Zhang Wenchao <[email protected]> --- .../regress/expected/DML_over_joins_optimizer.out | 27 +++++++++++----------- .../gpopt/translate/CTranslatorRelcacheToDXL.cpp | 2 +- .../regress/expected/DML_over_joins_optimizer.out | 27 +++++++++++----------- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/contrib/pax_storage/src/test/regress/expected/DML_over_joins_optimizer.out b/contrib/pax_storage/src/test/regress/expected/DML_over_joins_optimizer.out index aa87cea2a3e..e151580adce 100644 --- a/contrib/pax_storage/src/test/regress/expected/DML_over_joins_optimizer.out +++ b/contrib/pax_storage/src/test/regress/expected/DML_over_joins_optimizer.out @@ -1613,22 +1613,21 @@ HINT: For non-partitioned tables, run analyze <table_name>(<column_list>). For QUERY PLAN ------------------------------------------------------------------------------ Delete on tab1 - -> Result - -> Redistribute Motion 3:3 (slice1; segments: 3) - Hash Key: tab1.b - -> Hash Join - Hash Cond: (tab2.a = tab1.a) - -> Seq Scan on tab2 - -> Hash - -> Redistribute Motion 3:3 (slice2; segments: 3) - Hash Key: tab1.a - -> Hash Join - Hash Cond: (tab3.b = tab1.b) - -> Seq Scan on tab3 - -> Hash + -> Hash Join + Hash Cond: (tab3.b = tab1.b) + -> Seq Scan on tab3 + -> Hash + -> Redistribute Motion 3:3 (slice1; segments: 3) + Hash Key: tab1.b + -> Hash Join + Hash Cond: (tab2.a = tab1.a) + -> Seq Scan on tab2 + -> Hash + -> Redistribute Motion 3:3 (slice2; segments: 3) + Hash Key: tab1.a -> Seq Scan on tab1 Optimizer: GPORCA -(16 rows) +(15 rows) -- ---------------------------------------------------------------------- -- Test: teardown.sql diff --git a/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp b/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp index d8e1da28f0d..6a5d679a11f 100644 --- a/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp +++ b/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp @@ -1836,7 +1836,7 @@ CTranslatorRelcacheToDXL::RetrieveRelStats(CMemoryPool *mp, IMDId *mdid) * count of the partition table is -1. */ BOOL relation_empty = false; - if (num_rows == -1.0) + if (num_rows == -1.0 || num_rows == 0.0) { relation_empty = true; } diff --git a/src/test/regress/expected/DML_over_joins_optimizer.out b/src/test/regress/expected/DML_over_joins_optimizer.out index c0d7286affd..2f10f995cdc 100644 --- a/src/test/regress/expected/DML_over_joins_optimizer.out +++ b/src/test/regress/expected/DML_over_joins_optimizer.out @@ -1774,22 +1774,21 @@ HINT: For non-partitioned tables, run analyze <table_name>(<column_list>). For QUERY PLAN ------------------------------------------------------------------------------ Delete on tab1 - -> Result - -> Redistribute Motion 3:3 (slice1; segments: 3) - Hash Key: tab1.b - -> Hash Join - Hash Cond: (tab2.a = tab1.a) - -> Seq Scan on tab2 - -> Hash - -> Redistribute Motion 3:3 (slice2; segments: 3) - Hash Key: tab1.a - -> Hash Join - Hash Cond: (tab3.b = tab1.b) - -> Seq Scan on tab3 - -> Hash + -> Hash Join + Hash Cond: (tab3.b = tab1.b) + -> Seq Scan on tab3 + -> Hash + -> Redistribute Motion 3:3 (slice1; segments: 3) + Hash Key: tab1.b + -> Hash Join + Hash Cond: (tab2.a = tab1.a) + -> Seq Scan on tab2 + -> Hash + -> Redistribute Motion 3:3 (slice2; segments: 3) + Hash Key: tab1.a -> Seq Scan on tab1 Optimizer: GPORCA -(16 rows) +(15 rows) -- ---------------------------------------------------------------------- -- Test delete on partition table from join on another partition table --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
