pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Fix partitioned index creation with foreign partitions
5+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2019-06-27 050098b14e e4f2d4fe92 Fix use-after-free introduced in 55ed3defc966
* pgsql: Fix partitioned index creation with foreign partitions
@ 2019-06-26 22:39 Alvaro Herrera <alvherre@alvh.no-ip.org>
0 siblings, 0 replies; 5+ messages in thread
From: Alvaro Herrera @ 2019-06-26 22:39 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix partitioned index creation with foreign partitions
When a partitioned tables contains foreign tables as partitions, it is
not possible to implement unique or primary key indexes -- but when
regular indexes are created, there is no reason to do anything other
than ignoring such partitions. We were raising errors upon encountering
the foreign partitions, which is unfriendly and doesn't protect against
any actual problems.
Relax this restriction so that index creation is allowed on partitioned
tables containing foreign partitions, becoming a no-op on them. (We may
later want to redefine this so that the FDW is told to create the
indexes on the foreign side.) This applies to CREATE INDEX, as well as
ALTER TABLE / ATTACH PARTITION and CREATE TABLE / PARTITION OF.
Backpatch to 11, where indexes on partitioned tables were introduced.
Discussion: https://postgr.es/m/15724-d5a58fa9472eef4f@postgresql.org
Author: Álvaro Herrera
Reviewed-by: Amit Langote
Branch
------
REL_11_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/9653ca2197e241ebeae127086ce1cc8b201a477e
Modified Files
--------------
doc/src/sgml/ref/alter_table.sgml | 2 +-
doc/src/sgml/ref/create_foreign_table.sgml | 4 +--
src/backend/commands/indexcmds.c | 20 +++++++++++
src/backend/commands/tablecmds.c | 45 ++++++++++++++++++++++++
src/backend/tcop/utility.c | 12 +++++--
src/test/regress/expected/foreign_data.out | 56 ++++++++++++++++++++++++++++--
src/test/regress/sql/foreign_data.sql | 42 +++++++++++++++++++++-
7 files changed, 172 insertions(+), 9 deletions(-)
^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Fix partitioned index creation with foreign partitions
@ 2019-06-26 22:39 Alvaro Herrera <alvherre@alvh.no-ip.org>
0 siblings, 1 reply; 5+ messages in thread
From: Alvaro Herrera @ 2019-06-26 22:39 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix partitioned index creation with foreign partitions
When a partitioned tables contains foreign tables as partitions, it is
not possible to implement unique or primary key indexes -- but when
regular indexes are created, there is no reason to do anything other
than ignoring such partitions. We were raising errors upon encountering
the foreign partitions, which is unfriendly and doesn't protect against
any actual problems.
Relax this restriction so that index creation is allowed on partitioned
tables containing foreign partitions, becoming a no-op on them. (We may
later want to redefine this so that the FDW is told to create the
indexes on the foreign side.) This applies to CREATE INDEX, as well as
ALTER TABLE / ATTACH PARTITION and CREATE TABLE / PARTITION OF.
Backpatch to 11, where indexes on partitioned tables were introduced.
Discussion: https://postgr.es/m/15724-d5a58fa9472eef4f@postgresql.org
Author: Álvaro Herrera
Reviewed-by: Amit Langote
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/55ed3defc966cf718fe1e8c0efe964580bb23351
Modified Files
--------------
doc/src/sgml/ref/alter_table.sgml | 2 +-
doc/src/sgml/ref/create_foreign_table.sgml | 4 +--
src/backend/commands/indexcmds.c | 20 +++++++++++
src/backend/commands/tablecmds.c | 45 ++++++++++++++++++++++++
src/backend/tcop/utility.c | 12 +++++--
src/test/regress/expected/foreign_data.out | 56 ++++++++++++++++++++++++++++--
src/test/regress/sql/foreign_data.sql | 42 +++++++++++++++++++++-
7 files changed, 172 insertions(+), 9 deletions(-)
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: pgsql: Fix partitioned index creation with foreign partitions
@ 2019-06-26 23:04 Alvaro Herrera <alvherre@2ndquadrant.com>
parent: Alvaro Herrera <alvherre@alvh.no-ip.org>
0 siblings, 1 reply; 5+ messages in thread
From: Alvaro Herrera @ 2019-06-26 23:04 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
On 2019-Jun-26, Alvaro Herrera wrote:
> Fix partitioned index creation with foreign partitions
Hmm, so this causes prion to fail, because -DFORCE_RELCACHE_RELEASE: it
reports the immediate parent of the would-be-partition rather than the
topmost ancestor. I'm not sure I understand why, since relcache release
shouldn't affect recursion order (maybe that's another bug). I'll
investigate more tomorrow.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: pgsql: Fix partitioned index creation with foreign partitions
@ 2019-06-27 02:32 Amit Langote <amitlangote09@gmail.com>
parent: Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 5+ messages in thread
From: Amit Langote @ 2019-06-27 02:32 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-committers@lists.postgresql.org
On Thu, Jun 27, 2019 at 8:04 AM Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
>
> On 2019-Jun-26, Alvaro Herrera wrote:
>
> > Fix partitioned index creation with foreign partitions
>
> Hmm, so this causes prion to fail, because -DFORCE_RELCACHE_RELEASE: it
> reports the immediate parent of the would-be-partition rather than the
> topmost ancestor. I'm not sure I understand why, since relcache release
> shouldn't affect recursion order (maybe that's another bug). I'll
> investigate more tomorrow.
I see this diff:
ALTER TABLE lt1 ADD PRIMARY KEY (a);
-ERROR: cannot create unique index on partitioned table "lt1_part1"
-DETAIL: Table "lt1_part1" contains partitions that are foreign tables.
+ERROR: cannot create unique index on partitioned table "ft_part_1_1"
+DETAIL: Table "ft_part_1_1" contains partitions that are foreign tables.
The table name reported here is that of the foreign table leaf
partition, not of the immediate parent. Also, what's expected is not
the topmost ancestor, but the immediate parent, which seems OK,
because that's the best that the code in question can manage.
Anyway, the problem seems to use-after-close of a Relation pointer,
which the attached patch fixes.
Thanks,
Amit
Attachments:
DefineIndex-fix-use-after-relation-close.patch (application/octet-stream, 769B) download
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index cdbb56f1a4..e950e6ce68 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -1064,8 +1064,6 @@ DefineIndex(Oid relationId,
for (i = 0; i < numberOfKeyAttributes; i++)
opfamOids[i] = get_opclass_family(classObjectId[i]);
- table_close(rel, NoLock);
-
/*
* For each partition, scan all existing indexes; if one matches
* our index definition and is not already attached to some other
@@ -1265,8 +1263,8 @@ DefineIndex(Oid relationId,
heap_freetuple(newtup);
}
}
- else
- table_close(rel, NoLock);
+
+ table_close(rel, NoLock);
/*
* Indexes on partitioned tables are not themselves built, so we're
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: pgsql: Fix partitioned index creation with foreign partitions
@ 2019-06-27 15:58 Alvaro Herrera <alvherre@2ndquadrant.com>
parent: Amit Langote <amitlangote09@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: Alvaro Herrera @ 2019-06-27 15:58 UTC (permalink / raw)
To: Amit Langote <amitlangote09@gmail.com>; +Cc: pgsql-committers@lists.postgresql.org
On 2019-Jun-27, Amit Langote wrote:
> Anyway, the problem seems to use-after-close of a Relation pointer,
> which the attached patch fixes.
Indeed, thanks for tracking it down. Pushed. I couldn't resist the
temptation remove a no-longer-necessary tupdesc copy while at it.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2019-06-27 15:58 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-06-26 22:39 pgsql: Fix partitioned index creation with foreign partitions Alvaro Herrera <alvherre@alvh.no-ip.org>
2019-06-26 23:04 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2019-06-27 02:32 ` Amit Langote <amitlangote09@gmail.com>
2019-06-27 15:58 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2019-06-26 22:39 pgsql: Fix partitioned index creation with foreign partitions Alvaro Herrera <alvherre@alvh.no-ip.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox