v23-0005-Remove-all-references-between-RestrictInfo-and-i.patch

application/octet-stream

Filename: v23-0005-Remove-all-references-between-RestrictInfo-and-i.patch
Type: application/octet-stream
Part: 5
Message: Re: [PoC] Reducing planning time when tables have many partitions

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v23-0005
Subject: Remove all references between RestrictInfo and its relating RangeTblEntry
File+
src/backend/optimizer/plan/analyzejoins.c 32 2
From 0c61c44e693e12ca918bdd24ab266423b0758395 Mon Sep 17 00:00:00 2001
From: Yuya Watari <watari.yuya@gmail.com>
Date: Thu, 11 Jan 2024 16:18:36 +0900
Subject: [PATCH v23 5/6] Remove all references between RestrictInfo and its
 relating RangeTblEntry

This commit adds code to adjust eclass_derive_indexes and
eclass_source_indexes during self-join elimination.

Note that this commit fails some regression tests. The failures will be
fixed in the next commit. See its commit message for more details.
---
 src/backend/optimizer/plan/analyzejoins.c | 34 +++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/src/backend/optimizer/plan/analyzejoins.c b/src/backend/optimizer/plan/analyzejoins.c
index 49f3c17057..4081827e3a 100644
--- a/src/backend/optimizer/plan/analyzejoins.c
+++ b/src/backend/optimizer/plan/analyzejoins.c
@@ -1639,9 +1639,25 @@ update_eclasses(PlannerInfo *root, EquivalenceClass *ec, int from, int to)
 	i = -1;
 	while ((i = bms_next_member(ec->ec_derive_indexes, i)) >= 0)
 	{
+		RestrictInfo *rinfo = list_nth_node(RestrictInfo, root->eq_derives, i);
+
+		/*
+		 * Remove all references between this RestrictInfo and its relating
+		 * RangeTblEntry.
+		 */
+		j = -1;
+		while ((j = bms_next_member(rinfo->clause_relids, j)) >= 0)
+		{
+			RangeTblEntry *rte = root->simple_rte_array[j];
+
+			Assert(bms_is_member(i, rte->eclass_derive_indexes));
+			rte->eclass_derive_indexes =
+				bms_del_member(rte->eclass_derive_indexes, i);
+		}
+
 		/*
 		 * Can't delete the element because we would need to rebuild all
-		 * the eq_derives indexes. But set a nuke to detect potential problems.
+		 * the eq_derives indexes. But set a null to detect potential problems.
 		 */
 		list_nth_cell(root->eq_derives, i)->ptr_value = NULL;
 	}
@@ -1685,9 +1701,23 @@ update_eclasses(PlannerInfo *root, EquivalenceClass *ec, int from, int to)
 
 		if (is_redundant)
 		{
+			/*
+			 * Remove all references between this RestrictInfo and its relating
+			 * RangeTblEntry.
+			 */
+			j = -1;
+			while ((j = bms_next_member(rinfo->clause_relids, j)) >= 0)
+			{
+				RangeTblEntry *rte = root->simple_rte_array[j];
+
+				Assert(bms_is_member(i, rte->eclass_source_indexes));
+				rte->eclass_source_indexes =
+					bms_del_member(rte->eclass_source_indexes, i);
+			}
+
 			/*
 			 * Can't delete the element because we would need to rebuild all
-			 * the eq_sources indexes. But set a nuke to detect potential problems.
+			 * the eq_sources indexes. But set a null to detect potential problems.
 			 */
 			list_nth_cell(root->eq_sources, i)->ptr_value = NULL;
 		}
-- 
2.42.0.windows.2