diff --git a/src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp b/src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp index 93ec2826c9078975ddc1808634f66352295929d6..08947cb39a182ced128c5b7f518e768ce0c970bf 100644 --- a/src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp +++ b/src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp @@ -2995,15 +2995,7 @@ CTranslatorQueryToDXL::TranslateRTEToDXLLogicalGet(const RangeTblEntry *rte, ULONG //current_query_level ) { - CDXLTableDescr *table_descr = CTranslatorUtils::GetTableDescr( - m_mp, m_md_accessor, m_colid_counter, rte, &m_has_distributed_tables); - - CDXLLogicalGet *dxlop = NULL; - const IMDRelation *md_rel = m_md_accessor->RetrieveRel(table_descr->MDId()); - - - if (false == rte->inh && - IMDRelation::ErelstorageExternal != md_rel->RetrieveRelStorageType()) + if (false == rte->inh) { GPOS_ASSERT(RTE_RELATION == rte->rtekind); // RangeTblEntry::inh is set to false iff there is ONLY in the FROM @@ -3013,6 +3005,12 @@ CTranslatorQueryToDXL::TranslateRTEToDXLLogicalGet(const RangeTblEntry *rte, } // construct table descriptor for the scan node from the range table entry + CDXLTableDescr *table_descr = CTranslatorUtils::GetTableDescr( + m_mp, m_md_accessor, m_colid_counter, rte, &m_has_distributed_tables); + + CDXLLogicalGet *dxlop = NULL; + const IMDRelation *md_rel = m_md_accessor->RetrieveRel(table_descr->MDId()); + if (IMDRelation::ErelstorageExternal == md_rel->RetrieveRelStorageType()) { dxlop = GPOS_NEW(m_mp) CDXLLogicalExternalGet(m_mp, table_descr); diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index 2e000ea7da0397212540f13e16bc882439d5cd62..5ebb3092785e12d3b2892c2a36d837a87666e7ac 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -822,9 +822,6 @@ addRangeTableEntry(ParseState *pstate, rte->alias = alias; rte->rtekind = RTE_RELATION; - /* external tables don't allow inheritance */ - if (RelationIsExternal(rel)) - inh = false; /* * Build the list of effective column names using user-supplied aliases diff --git a/src/test/regress/expected/qp_orca_fallback.out b/src/test/regress/expected/qp_orca_fallback.out index 40b08b5c68a37d4e14fde226aca1d7c442c8b07e..9bb20e2c105ab278601a30d36fca99eb55e823d6 100644 --- a/src/test/regress/expected/qp_orca_fallback.out +++ b/src/test/regress/expected/qp_orca_fallback.out @@ -105,12 +105,8 @@ SELECT * FROM homer; 4 | 3 | 44 (4 rows) --- ORCA should not fallback when ONLY clause is used on external tables +-- ORCA should not fallback just because external tables are in FROM clause -- start_ignore -DROP TABLE IF EXISTS t1; -NOTICE: table "t1" does not exist, skipping -DROP TABLE IF EXISTS ext_table_no_fallback; -NOTICE: table "ext_table_no_fallback" does not exist, skipping CREATE TABLE heap_t1 (a int, b int) DISTRIBUTED BY (b); CREATE EXTERNAL TABLE ext_table_no_fallback (a int, b int) LOCATION ('gpfdist://myhost:8080/test.csv') FORMAT 'CSV'; -- end_ignore @@ -122,6 +118,7 @@ EXPLAIN SELECT * FROM ext_table_no_fallback; Optimizer: legacy query optimizer (3 rows) +-- ORCA should fallback due to ONLY keyword EXPLAIN SELECT * FROM ONLY ext_table_no_fallback; QUERY PLAN ----------------------------------------------------------------------------------------- diff --git a/src/test/regress/expected/qp_orca_fallback_optimizer.out b/src/test/regress/expected/qp_orca_fallback_optimizer.out index a7d2380e05afebcba532f3a4c7dfd8d4246369a6..e9822cf99d51e27c532521298ae3e8b65c3e291a 100644 --- a/src/test/regress/expected/qp_orca_fallback_optimizer.out +++ b/src/test/regress/expected/qp_orca_fallback_optimizer.out @@ -144,12 +144,8 @@ SELECT * FROM homer; 4 | 3 | 44 (4 rows) --- ORCA should not fallback when ONLY clause is used on external tables +-- ORCA should not fallback just because external tables are in FROM clause -- start_ignore -DROP TABLE IF EXISTS t1; -NOTICE: table "t1" does not exist, skipping -DROP TABLE IF EXISTS ext_table_no_fallback; -NOTICE: table "ext_table_no_fallback" does not exist, skipping CREATE TABLE heap_t1 (a int, b int) DISTRIBUTED BY (b); CREATE EXTERNAL TABLE ext_table_no_fallback (a int, b int) LOCATION ('gpfdist://myhost:8080/test.csv') FORMAT 'CSV'; -- end_ignore @@ -161,24 +157,26 @@ EXPLAIN SELECT * FROM ext_table_no_fallback; Optimizer: PQO version 2.67.0 (3 rows) +-- ORCA should fallback due to ONLY keyword EXPLAIN SELECT * FROM ONLY ext_table_no_fallback; - QUERY PLAN ---------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..472.74 rows=1000000 width=8) - -> External Scan on ext_table_no_fallback (cost=0.00..437.97 rows=333334 width=8) - Optimizer: PQO version 2.67.0 +INFO: GPORCA failed to produce a plan, falling back to planner + QUERY PLAN +----------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..11000.00 rows=1000000 width=8) + -> External Scan on ext_table_no_fallback (cost=0.00..11000.00 rows=333334 width=8) + Optimizer: legacy query optimizer (3 rows) EXPLAIN INSERT INTO heap_t1 SELECT * FROM ONLY ext_table_no_fallback; - QUERY PLAN ------------------------------------------------------------------------------------------------------ - Insert (cost=0.00..16080.27 rows=333334 width=8) - -> Result (cost=0.00..455.27 rows=333334 width=12) - -> Redistribute Motion 3:3 (slice1; segments: 3) (cost=0.00..451.27 rows=333334 width=8) - Hash Key: ext_table_no_fallback.b - -> External Scan on ext_table_no_fallback (cost=0.00..437.97 rows=333334 width=8) - Optimizer: PQO version 2.67.0 -(6 rows) +INFO: GPORCA failed to produce a plan, falling back to planner + QUERY PLAN +------------------------------------------------------------------------------------------------- + Insert (slice0; segments: 3) (rows=333334 width=8) + -> Redistribute Motion 3:3 (slice1; segments: 3) (cost=0.00..11000.00 rows=333334 width=8) + Hash Key: ext_table_no_fallback.b + -> External Scan on ext_table_no_fallback (cost=0.00..11000.00 rows=333334 width=8) + Optimizer: legacy query optimizer +(5 rows) set optimizer_enable_dml=off; EXPLAIN INSERT INTO homer VALUES (1,0,40),(2,1,43),(3,2,41),(4,3,44); diff --git a/src/test/regress/sql/qp_orca_fallback.sql b/src/test/regress/sql/qp_orca_fallback.sql index 9637f0dc7147abff8a3e5b67c2d2b6ba9b994bba..ad8965f0e08ca545c26d38a654da58770398ab0f 100644 --- a/src/test/regress/sql/qp_orca_fallback.sql +++ b/src/test/regress/sql/qp_orca_fallback.sql @@ -75,14 +75,13 @@ SELECT * FROM homer; DELETE FROM ONLY homer WHERE a = 3; SELECT * FROM homer; --- ORCA should not fallback when ONLY clause is used on external tables +-- ORCA should not fallback just because external tables are in FROM clause -- start_ignore -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS ext_table_no_fallback; CREATE TABLE heap_t1 (a int, b int) DISTRIBUTED BY (b); CREATE EXTERNAL TABLE ext_table_no_fallback (a int, b int) LOCATION ('gpfdist://myhost:8080/test.csv') FORMAT 'CSV'; -- end_ignore EXPLAIN SELECT * FROM ext_table_no_fallback; +-- ORCA should fallback due to ONLY keyword EXPLAIN SELECT * FROM ONLY ext_table_no_fallback; EXPLAIN INSERT INTO heap_t1 SELECT * FROM ONLY ext_table_no_fallback;