This is an automated email from the ASF dual-hosted git repository.

reshke pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 1c07547b3f06928717169cb9b8d8b233a9f80669
Author: bhari <[email protected]>
AuthorDate: Fri Sep 8 15:15:08 2023 +0530

    Remove check restricting some array casts by orca (#16379)
    
    Issue:
    Gporca failed to produce plan for casting int[] to text[] in a query like:
    `explain select CAST(int_arr_col as text[]) FROM foo;`
    
    RCA:
    The commit 
https://github.com/greenplum-db/gpdb-postgres-merge/commit/256b11929f349c27b86e754e4664d3a63426a6e4,
    added a condition restricting the plan dxl to be generated,
    if per-elem expr of `ArrayCoerceExpr` is not of type `RelabelType` or 
`FuncExpr`.
    
    Fix:
    This condition is now redundant, since DXL is working well with per-elem 
expr
    of type `CoerceViaIO`. So the condition is now removed.
    
    Note:
    The condition might have been needed because of postgres change added in 
commit 
https://github.com/postgres/postgres/commit/c12d570fa147d0ec273df53de3a2802925d551ba.
    Which was later fixed in 
https://github.com/greenplum-db/gpdb/commit/600c7611512942a65352752e637890c29dcb2a90.
    
    * Added a regression test to verify that plan is being generated by Orca,
    for cast from int[] to text[] which was failing earlier.
---
 .../gpopt/translate/CTranslatorScalarToDXL.cpp        |  8 --------
 src/test/regress/expected/gporca.out                  | 19 +++++++++++++++++++
 src/test/regress/expected/gporca_optimizer.out        | 19 +++++++++++++++++++
 src/test/regress/sql/gporca.sql                       |  9 +++++++++
 4 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/src/backend/gpopt/translate/CTranslatorScalarToDXL.cpp 
b/src/backend/gpopt/translate/CTranslatorScalarToDXL.cpp
index 5a7a7f94e5..0759d103d7 100644
--- a/src/backend/gpopt/translate/CTranslatorScalarToDXL.cpp
+++ b/src/backend/gpopt/translate/CTranslatorScalarToDXL.cpp
@@ -1282,14 +1282,6 @@ CTranslatorScalarToDXL::TranslateArrayCoerceExprToDXL(
        GPOS_ASSERT(nullptr != child_node);
        GPOS_ASSERT(nullptr != elemexpr_node);
 
-       if (!(IsA(array_coerce_expr->elemexpr, FuncExpr) ||
-                 IsA(array_coerce_expr->elemexpr, RelabelType)))
-       {
-               GPOS_RAISE(gpdxl::ExmaDXL, 
gpdxl::ExmiQuery2DXLUnsupportedFeature,
-                                  GPOS_WSZ_LIT("ArrayCoerceExpr with elemexpr 
that is neither "
-                                                               "FuncExpr or 
RelabelType"));
-       }
-
        CDXLNode *dxlnode = GPOS_NEW(m_mp) CDXLNode(
                m_mp, GPOS_NEW(m_mp) CDXLScalarArrayCoerceExpr(
                                  m_mp,
diff --git a/src/test/regress/expected/gporca.out 
b/src/test/regress/expected/gporca.out
index ab827b5ae4..6fe7b29096 100644
--- a/src/test/regress/expected/gporca.out
+++ b/src/test/regress/expected/gporca.out
@@ -14914,3 +14914,22 @@ select check_col_width('select a from 
testPartWidth;','Append','width=5') = 1;
 (1 row)
 
 drop function check_col_width(query text, operator text, width text);
+---------------------------------------------------------------------------------
+-- Test cast from INT[] to TEXT[]
+CREATE TABLE array_coerceviaio(a INT[]) distributed randomly;
+INSERT INTO array_coerceviaio values(ARRAY[1, 2, 3]);
+EXPLAIN SELECT CAST(a AS TEXT[]) FROM array_coerceviaio;
+                                     QUERY PLAN                                
     
+------------------------------------------------------------------------------------
+ Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..1882.00 rows=52800 
width=32)
+   ->  Seq Scan on array_coerceviaio  (cost=0.00..1178.00 rows=17600 width=32)
+ Optimizer: Postgres-based planner
+(3 rows)
+
+SELECT CAST(a AS TEXT[]) FROM array_coerceviaio;
+    a    
+---------
+ {1,2,3}
+(1 row)
+
+---------------------------------------------------------------------------------
diff --git a/src/test/regress/expected/gporca_optimizer.out 
b/src/test/regress/expected/gporca_optimizer.out
index 4d14cbbcde..c7f80012e7 100644
--- a/src/test/regress/expected/gporca_optimizer.out
+++ b/src/test/regress/expected/gporca_optimizer.out
@@ -14999,3 +14999,22 @@ DETAIL:  Falling back to Postgres-based planner 
because GPORCA does not support
 (1 row)
 
 drop function check_col_width(query text, operator text, width text);
+---------------------------------------------------------------------------------
+-- Test cast from INT[] to TEXT[]
+CREATE TABLE array_coerceviaio(a INT[]) distributed randomly;
+INSERT INTO array_coerceviaio values(ARRAY[1, 2, 3]);
+EXPLAIN SELECT CAST(a AS TEXT[]) FROM array_coerceviaio;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..431.00 rows=1 width=8)
+   ->  Seq Scan on array_coerceviaio  (cost=0.00..431.00 rows=1 width=8)
+ Optimizer: GPORCA
+(3 rows)
+
+SELECT CAST(a AS TEXT[]) FROM array_coerceviaio;
+    a    
+---------
+ {1,2,3}
+(1 row)
+
+---------------------------------------------------------------------------------
diff --git a/src/test/regress/sql/gporca.sql b/src/test/regress/sql/gporca.sql
index ff08636b68..a659d5695c 100644
--- a/src/test/regress/sql/gporca.sql
+++ b/src/test/regress/sql/gporca.sql
@@ -3698,6 +3698,15 @@ select check_col_width('select a from 
testPartWidth;','Append','width=5') = 1;
 select check_col_width('select a from testPartWidth;','Append','width=5') = 1;
 drop function check_col_width(query text, operator text, width text);
 
+---------------------------------------------------------------------------------
+-- Test cast from INT[] to TEXT[]
+CREATE TABLE array_coerceviaio(a INT[]) distributed randomly;
+INSERT INTO array_coerceviaio values(ARRAY[1, 2, 3]);
+
+EXPLAIN SELECT CAST(a AS TEXT[]) FROM array_coerceviaio;
+SELECT CAST(a AS TEXT[]) FROM array_coerceviaio;
+---------------------------------------------------------------------------------
+
 -- start_ignore
 DROP SCHEMA orca CASCADE;
 -- end_ignore


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to