From 0f57cfeecb2e0032f23c5098e5e80267dd0c3c4b Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@2ndquadrant.com>
Date: Mon, 17 Jun 2024 17:02:32 +0200
Subject: [PATCH v20240617 49/56] review

---
 src/backend/statistics/mcv.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c
index 4eec6592562..2f055fd1085 100644
--- a/src/backend/statistics/mcv.c
+++ b/src/backend/statistics/mcv.c
@@ -2559,7 +2559,15 @@ mcv_combine_extended(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 				s += mcv1->items[i].frequency * mcv2->items[j].frequency;
 				nmatches += 1;
 
+				/*
+				 * XXX Comment should be before the condition, and should
+				 * explain why there could be no more matches.
+				 *
+				 * XXX I'm not sure about this optimization, could there be a
+				 * case with two clauses matching the same MCV dimension?
+				 */
 				if (mcv2->ndimensions == list_length(clauses))
+
 					/*
 					 * no more items in mcv2 could match mcv1[i] in this case,
 					 * so break fast.
-- 
2.45.2

