Indexes on partitioned tables and foreign partitions - Mailing list pgsql-hackers

From Arseny Sher
Subject Indexes on partitioned tables and foreign partitions
Date
Msg-id 87sh71cakz.fsf@ars-thinkpad
Whole thread Raw
Responses Re: Indexes on partitioned tables and foreign partitions  (Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>)
Re: Indexes on partitioned tables and foreign partitions  (Simon Riggs <simon@2ndquadrant.com>)
List pgsql-hackers
Hi,

8b08f7d4 added propagation of indexes on partitioned tables to
partitions, which is very cool. However, index creation also recurses
down to foreign tables. I doubt this is intentional, as such indexes are
forbidden as not making much sense; attempt to create index on
partitioned table with foreign partition leads to an error
now. Attached lines fix this.
*** a/src/backend/commands/indexcmds.c
--- b/src/backend/commands/indexcmds.c
*************** DefineIndex(Oid relationId,
*** 915,920 ****
--- 915,926 ----
                  int            maplen;
  
                  childrel = heap_open(childRelid, lockmode);
+                 /* Foreign table doesn't need indexes */
+                 if (childrel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
+                 {
+                     heap_close(childrel, NoLock);
+                     continue;
+                 }
                  childidxs = RelationGetIndexList(childrel);
                  attmap =
                      convert_tuples_by_name_map(RelationGetDescr(childrel),
*** a/src/backend/commands/tablecmds.c
--- b/src/backend/commands/tablecmds.c
*************** AttachPartitionEnsureIndexes(Relation re
*** 14352,14357 ****
--- 14352,14361 ----
      MemoryContext cxt;
      MemoryContext oldcxt;
  
+     /* Foreign table doesn't need indexes */
+     if (attachrel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
+         return;
+ 
      cxt = AllocSetContextCreate(CurrentMemoryContext,
                                  "AttachPartitionEnsureIndexes",
                                  ALLOCSET_DEFAULT_SIZES);

--
Arseny Sher
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

pgsql-hackers by date:

Previous
From: Oleksandr Shulgin
Date:
Subject: Re: Setting libpq TCP keepalive parameters from environment
Next
From: Etsuro Fujita
Date:
Subject: Re: Expression errors with "FOR UPDATE" and postgres_fdw with partitionwise join enabled.