diff options
| author | Tom Lane | 2020-12-01 19:02:27 +0000 |
|---|---|---|
| committer | Tom Lane | 2020-12-01 19:02:27 +0000 |
| commit | f7f83a55bf6051818a0e4387d718867ecfa8561b (patch) | |
| tree | 6bd3c317472c0ac4ef499394a16f943ce5fe0e4d /src/test | |
| parent | 677f74e5bb8360122ebf2f473d7169ed65ce4dba (diff) | |
Ensure that expandTableLikeClause() re-examines the same table.
As it stood, expandTableLikeClause() re-did the same relation_openrv
call that transformTableLikeClause() had done. However there are
scenarios where this would not find the same table as expected.
We hold lock on the LIKE source table, so it can't be renamed or
dropped, but another table could appear before it in the search path.
This explains the odd behavior reported in bug #16758 when cloning a
table as a temp table of the same name. This case worked as expected
before commit 502898192 introduced the need to open the source table
twice, so we should fix it.
To make really sure we get the same table, let's re-open it by OID not
name. That requires adding an OID field to struct TableLikeClause,
which is a little nervous-making from an ABI standpoint, but as long
as it's at the end I don't think there's any serious risk.
Per bug #16758 from Marc Boeren. Like the previous patch,
back-patch to all supported branches.
Discussion: https://postgr.es/m/16758-840e84a6cfab276d@postgresql.org
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/create_table_like.out | 21 | ||||
| -rw-r--r-- | src/test/regress/sql/create_table_like.sql | 8 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/test/regress/expected/create_table_like.out b/src/test/regress/expected/create_table_like.out index 01e3a8435da..10d17be23cf 100644 --- a/src/test/regress/expected/create_table_like.out +++ b/src/test/regress/expected/create_table_like.out @@ -455,6 +455,27 @@ Statistics objects: "public"."pg_attrdef_a_b_stat" (ndistinct, dependencies, mcv) ON a, b FROM public.pg_attrdef DROP TABLE public.pg_attrdef; +-- Check that LIKE isn't confused when new table masks the old, either +BEGIN; +CREATE SCHEMA ctl_schema; +SET LOCAL search_path = ctl_schema, public; +CREATE TABLE ctlt1 (LIKE ctlt1 INCLUDING ALL); +\d+ ctlt1 + Table "ctl_schema.ctlt1" + Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+------+-----------+----------+---------+----------+--------------+------------- + a | text | | not null | | main | | A + b | text | | | | extended | | B +Indexes: + "ctlt1_pkey" PRIMARY KEY, btree (a) + "ctlt1_b_idx" btree (b) + "ctlt1_expr_idx" btree ((a || b)) +Check constraints: + "ctlt1_a_check" CHECK (length(a) > 2) +Statistics objects: + "ctl_schema"."ctlt1_a_b_stat" (ndistinct, dependencies, mcv) ON a, b FROM ctlt1 + +ROLLBACK; DROP TABLE ctlt1, ctlt2, ctlt3, ctlt4, ctlt12_storage, ctlt12_comments, ctlt1_inh, ctlt13_inh, ctlt13_like, ctlt_all, ctla, ctlb CASCADE; NOTICE: drop cascades to table inhe -- LIKE must respect NO INHERIT property of constraints diff --git a/src/test/regress/sql/create_table_like.sql b/src/test/regress/sql/create_table_like.sql index 63548b3d11d..06b76f949d6 100644 --- a/src/test/regress/sql/create_table_like.sql +++ b/src/test/regress/sql/create_table_like.sql @@ -173,6 +173,14 @@ CREATE TABLE pg_attrdef (LIKE ctlt1 INCLUDING ALL); \d+ public.pg_attrdef DROP TABLE public.pg_attrdef; +-- Check that LIKE isn't confused when new table masks the old, either +BEGIN; +CREATE SCHEMA ctl_schema; +SET LOCAL search_path = ctl_schema, public; +CREATE TABLE ctlt1 (LIKE ctlt1 INCLUDING ALL); +\d+ ctlt1 +ROLLBACK; + DROP TABLE ctlt1, ctlt2, ctlt3, ctlt4, ctlt12_storage, ctlt12_comments, ctlt1_inh, ctlt13_inh, ctlt13_like, ctlt_all, ctla, ctlb CASCADE; -- LIKE must respect NO INHERIT property of constraints |
