提交 013a6e9d 编写于 作者: B Bhuvnesh Chaudhary 提交者: Bhuvnesh

ORCA should not fallback for external tables

The commit a3f7f4d7 introduced a fall back if the query contained ONLY
in the FROM clause for relations. However, it should exclude external
tables. For external tables RangeTblEntry::inh is set to false always,
so the commit causes ORCA to fall back for all external table queries.

This commit fixes the issue by excluding external tables from the check
of ONLY clause in CTranslatorQueryToDXL::PdxlnFromRelation(), and adds
relevant test cases.
上级 9f8a38b4
......@@ -3024,19 +3024,21 @@ CTranslatorQueryToDXL::PdxlnFromRelation
ULONG //ulCurrQueryLevel
)
{
if (false == prte->inh)
{
GPOS_ASSERT(RTE_RELATION == prte->rtekind);
// RangeTblEntry::inh is set to false iff there is ONLY in the FROM
// clause. c.f. transformTableEntry, called from transformFromClauseItem
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature, GPOS_WSZ_LIT("ONLY in the FROM clause"));
}
// construct table descriptor for the scan node from the range table entry
CDXLTableDescr *pdxltabdesc = CTranslatorUtils::Pdxltabdesc(m_pmp, m_pmda, m_pidgtorCol, prte, &m_fHasDistributedTables);
CDXLLogicalGet *pdxlop = NULL;
const IMDRelation *pmdrel = m_pmda->Pmdrel(pdxltabdesc->Pmdid());
if (false == prte->inh && IMDRelation::ErelstorageExternal != pmdrel->Erelstorage())
{
GPOS_ASSERT(RTE_RELATION == prte->rtekind);
// RangeTblEntry::inh is set to false if there is ONLY in the FROM clause.
// c.f. transformTableEntry, called from transformFromClauseItem. Ignore
// external tables, however, since inh is always false for external tables.
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature, GPOS_WSZ_LIT("ONLY in the FROM clause"));
}
if (IMDRelation::ErelstorageExternal == pmdrel->Erelstorage())
{
pdxlop = GPOS_NEW(m_pmp) CDXLLogicalExternalGet(m_pmp, pdxltabdesc);
......
......@@ -141,3 +141,38 @@ SELECT * FROM homer;
4 | 3 | 44
(4 rows)
-- ORCA should not fallback when ONLY clause is used on external tables
-- 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
EXPLAIN SELECT * FROM ext_table_no_fallback;
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 SELECT * FROM ONLY ext_table_no_fallback;
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 on heap_t1 (cost=0.00..11000.00 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)
......@@ -170,3 +170,39 @@ SELECT * FROM homer;
4 | 3 | 44
(4 rows)
-- ORCA should not fallback when ONLY clause is used on external tables
-- 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
EXPLAIN SELECT * FROM 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
(3 rows)
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
(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)
......@@ -74,3 +74,14 @@ 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
-- 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;
EXPLAIN SELECT * FROM ONLY ext_table_no_fallback;
EXPLAIN INSERT INTO heap_t1 SELECT * FROM ONLY ext_table_no_fallback;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册