Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fGNby-0007fh-SW for pgsql-hackers@arkaria.postgresql.org; Wed, 09 May 2018 11:50:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fGNbv-0007ZW-Bh for pgsql-hackers@arkaria.postgresql.org; Wed, 09 May 2018 11:50:19 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fGNbr-0007ZM-Te for pgsql-hackers@lists.postgresql.org; Wed, 09 May 2018 11:50:18 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fGNbj-0001Eq-Nf for pgsql-hackers@lists.postgresql.org; Wed, 09 May 2018 11:50:14 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id EAEF021C2318 for ; Wed, 9 May 2018 14:50:04 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from ars-thinkpad (nat03-43-2.netorn.net [188.35.130.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id BF80A21C22EA for ; Wed, 9 May 2018 14:50:04 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1525866604; bh=/MeE2Dp5fLMPQzfAj8MqPKtyBPfxUwb1GkOISRXpMnE=; h=From:To:Subject:Date; b=kYaGmr7moc9++Uteblj4tikref8XPrhw+8vNNzPJCq03us+nAN72P9GePlGd0xXxD Uhofnlh69gsysongnyxsYa+5T4+ZzHsxBHz7SXr9SZF4Z9IDIYNKN+kXp2qIgQUuxa iCSbuKUmc4lI1wNKFMdPZzpIuflPRmW3AXnPdes4= User-agent: mu4e 1.1.0; emacs 26.0.50 From: Arseny Sher To: "pgsql-hackers\@lists.postgresql.org" Subject: Indexes on partitioned tables and foreign partitions Date: Wed, 09 May 2018 14:50:04 +0300 Message-ID: <87sh71cakz.fsf@ars-thinkpad> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=dont_create_part_index_on_ftable.patch *** 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); --=-=-= Content-Type: text/plain -- Arseny Sher Postgres Professional: http://www.postgrespro.com The Russian Postgres Company --=-=-=--