提交 01a6414b 编写于 作者: D Daniel Gustafsson

Fix catalog cleanup on DROP EXTERNAL TABLE

When dropping an external table, the pg_exttable catalog entry must
be removed as well to avoid dangling entries building up. Reverse
the logic in deleting the catalog entry to make sure we delete it
before scanning for a potential next one. Also fix up the tests for
this as they were testing the removal of the pg_class catalog entry
rather than the pg_exttable entry.

Reported by Ashwin Agrawal in Github issue #1498
上级 13f177b6
...@@ -474,8 +474,11 @@ RemoveExtTableEntry(Oid relid) ...@@ -474,8 +474,11 @@ RemoveExtTableEntry(Oid relid)
/* /*
* Delete the external table entry from the catalog (pg_exttable). * Delete the external table entry from the catalog (pg_exttable).
*/ */
while (HeapTupleIsValid(tuple = systable_getnext(scan))) do
{
simple_heap_delete(pg_exttable_rel, &tuple->t_self); simple_heap_delete(pg_exttable_rel, &tuple->t_self);
}
while (HeapTupleIsValid(tuple = systable_getnext(scan)));
/* Finish up scan and close exttable catalog. */ /* Finish up scan and close exttable catalog. */
systable_endscan(scan); systable_endscan(scan);
......
...@@ -232,22 +232,22 @@ drop external table check_ps; ...@@ -232,22 +232,22 @@ drop external table check_ps;
drop external table check_env; drop external table check_env;
drop external table wet_pos4; drop external table wet_pos4;
-- Tests for MPP-2513: dropping an external table must result in the deletion -- Dropping an external table, both via DROP EXTERNAL TABLE and as a result
-- of the relation pg_exttable row. This was done when using drop external -- from a cascading deletion must result in the deletion of the relation
-- table but not drop schema cascade; -- pg_exttable row.
create schema exttabletest; CREATE EXTERNAL WEB TABLE cascadetest (x text) EXECUTE 'echo "cascadetest";' FORMAT 'text';
CREATE EXTERNAL TABLE exttabletest.EXT_NATION ( N_NATIONKEY INTEGER , SELECT count(*) FROM pg_exttable WHERE command = 'echo "cascadetest";';
N_NAME CHAR(25) , DROP EXTERNAL TABLE cascadetest;
N_REGIONKEY INTEGER , SELECT count(*) FROM pg_exttable WHERE command = 'echo "cascadetest";';
N_COMMENT VARCHAR(152))
location ('file://@hostname@@abs_srcdir@/data/nation.tbl' ) CREATE SCHEMA exttabletest;
FORMAT 'text' (delimiter '|'); CREATE
-- Don't just return the row, as we'll get skew from OID differences between EXTERNAL TABLE exttabletest.ext_nation (n_nationkey integer, n_name char(25), n_regionkey integer, n_comment varchar(152))
-- runs. LOCATION ('file://@hostname@@abs_srcdir@/data/nation.tbl') FORMAT 'text' (delimiter '|');
select count(*) from pg_catalog.pg_exttable where reloid in (select r.oid from pg_class r where r.relname in ('ext_nation', 'ext_whois', 'exttab1_gpfdist_status')); SELECT count(*) FROM pg_exttable WHERE location @> '{file://@hostname@@abs_srcdir@/data/nation.tbl}';
drop schema exttabletest cascade; DROP SCHEMA exttabletest CASCADE;
select count(*) from pg_catalog.pg_exttable where reloid in (select r.oid from pg_class r where r.relname in ('ext_nation', 'ext_whois', 'exttab1_gpfdist_status')); SELECT count(*) FROM pg_exttable WHERE location @> '{file://@hostname@@abs_srcdir@/data/nation.tbl}';
-- Tests for MPP17980: generating artificial CTIDs for external table scans -- Tests for MPP17980: generating artificial CTIDs for external table scans
-- This is necessary because the planner currently generates plans that include -- This is necessary because the planner currently generates plans that include
......
...@@ -366,27 +366,36 @@ DROP ROLE exttab1_u6; ...@@ -366,27 +366,36 @@ DROP ROLE exttab1_u6;
drop external table check_ps; drop external table check_ps;
drop external table check_env; drop external table check_env;
drop external table wet_pos4; drop external table wet_pos4;
-- Tests for MPP-2513: dropping an external table must result in the deletion -- Dropping an external table, both via DROP EXTERNAL TABLE and as a result
-- of the relation pg_exttable row. This was done when using drop external -- from a cascading deletion must result in the deletion of the relation
-- table but not drop schema cascade; -- pg_exttable row.
create schema exttabletest; CREATE EXTERNAL WEB TABLE cascadetest (x text) EXECUTE 'echo "cascadetest";' FORMAT 'text';
CREATE EXTERNAL TABLE exttabletest.EXT_NATION ( N_NATIONKEY INTEGER , SELECT count(*) FROM pg_exttable WHERE command = 'echo "cascadetest";';
N_NAME CHAR(25) , count
N_REGIONKEY INTEGER , -------
N_COMMENT VARCHAR(152)) 1
location ('file://@hostname@@abs_srcdir@/data/nation.tbl' ) (1 row)
FORMAT 'text' (delimiter '|');
-- Don't just return the row, as we'll get skew from OID differences between DROP EXTERNAL TABLE cascadetest;
-- runs. SELECT count(*) FROM pg_exttable WHERE command = 'echo "cascadetest";';
select count(*) from pg_catalog.pg_exttable where reloid in (select r.oid from pg_class r where r.relname in ('ext_nation', 'ext_whois', 'exttab1_gpfdist_status')); count
-------
0
(1 row)
CREATE SCHEMA exttabletest;
CREATE
EXTERNAL TABLE exttabletest.ext_nation (n_nationkey integer, n_name char(25), n_regionkey integer, n_comment varchar(152))
LOCATION ('file://@hostname@@abs_srcdir@/data/nation.tbl') FORMAT 'text' (delimiter '|');
SELECT count(*) FROM pg_exttable WHERE location @> '{file://@hostname@@abs_srcdir@/data/nation.tbl}';
count count
------- -------
1 1
(1 row) (1 row)
drop schema exttabletest cascade; DROP SCHEMA exttabletest CASCADE;
NOTICE: drop cascades to external table exttabletest.ext_nation NOTICE: drop cascades to external table exttabletest.ext_nation
select count(*) from pg_catalog.pg_exttable where reloid in (select r.oid from pg_class r where r.relname in ('ext_nation', 'ext_whois', 'exttab1_gpfdist_status')); SELECT count(*) FROM pg_exttable WHERE location @> '{file://@hostname@@abs_srcdir@/data/nation.tbl}';
count count
------- -------
0 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册