From 16b7db4484b2d6a75beaf62c35d8237127c1dcb0 Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@2ndquadrant.com>
Date: Mon, 17 Jun 2024 14:11:14 +0200
Subject: [PATCH v20240617 03/56] pgindent

---
 src/backend/optimizer/path/clausesel.c        |  26 +-
 src/backend/statistics/extended_stats.c       | 324 +++++++++---------
 src/backend/statistics/mcv.c                  | 319 ++++++++---------
 .../statistics/extended_stats_internal.h      |   2 +-
 src/include/statistics/statistics.h           |   2 +-
 src/tools/pgindent/typedefs.list              |   1 +
 6 files changed, 348 insertions(+), 326 deletions(-)

diff --git a/src/backend/optimizer/path/clausesel.c b/src/backend/optimizer/path/clausesel.c
index 24e3c9729a3..871d73e3b4f 100644
--- a/src/backend/optimizer/path/clausesel.c
+++ b/src/backend/optimizer/path/clausesel.c
@@ -139,8 +139,8 @@ clauselist_selectivity_ext(PlannerInfo *root,
 	 *
 	 * The optimization skips clause_selectivity_ext when estimating a single
 	 * clause, but for join clauses it would mean we can't consider both the
-	 * join clause and the baserel restrictions. So we disable the optimization
-	 * when estimating a join clause.
+	 * join clause and the baserel restrictions. So we disable the
+	 * optimization when estimating a join clause.
 	 *
 	 * XXX Not sure if this is the best way to deal with the optimization. We
 	 * could make it more elaborate in various ways, but increasing the cost
@@ -148,18 +148,18 @@ clauselist_selectivity_ext(PlannerInfo *root,
 	 *
 	 * XXX Alternatively we could make clause_selectivity_ext smarter and
 	 * combine the join clauses and baserel restrictions there. But that seems
-	 * somewhat against the whole point of the optimization (skipping expensive
-	 * stuff) and it'd making other parts more complex.
+	 * somewhat against the whole point of the optimization (skipping
+	 * expensive stuff) and it'd making other parts more complex.
 	 *
-	 * XXX Maybe this should check if there are at least some restrictions
-	 * on some base relations, which seems important. But then again, that
-	 * seems to go against the idea of this check to be cheap. Moreover, it
-	 * won't work for OR clauses, which may have multiple parts but we still
-	 * see them as a single BoolExpr clause (it doesn't work later, though).
+	 * XXX Maybe this should check if there are at least some restrictions on
+	 * some base relations, which seems important. But then again, that seems
+	 * to go against the idea of this check to be cheap. Moreover, it won't
+	 * work for OR clauses, which may have multiple parts but we still see
+	 * them as a single BoolExpr clause (it doesn't work later, though).
 	 */
 	if (list_length(clauses) == 1)
 	{
-		Node *clause = linitial(clauses);
+		Node	   *clause = linitial(clauses);
 		RestrictInfo *rinfo = NULL;
 
 		if (IsA(clause, RestrictInfo))
@@ -205,9 +205,9 @@ clauselist_selectivity_ext(PlannerInfo *root,
 	}
 
 	/*
-	 * Try applying extended statistics to joins. There's not much we can
-	 * do to detect when this makes sense, but we can check that there are
-	 * join clauses, and that at least some of the rels have stats.
+	 * Try applying extended statistics to joins. There's not much we can do
+	 * to detect when this makes sense, but we can check that there are join
+	 * clauses, and that at least some of the rels have stats.
 	 *
 	 * XXX Isn't this mutually exclusive with the preceding block which
 	 * calculates estimates for a single relation?
diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c
index d3e1dde73d1..25b4d486a09 100644
--- a/src/backend/statistics/extended_stats.c
+++ b/src/backend/statistics/extended_stats.c
@@ -2672,13 +2672,13 @@ statext_find_matching_mcv(PlannerInfo *root, RelOptInfo *rel,
 {
 	ListCell   *l;
 	StatisticExtInfo *mcv = NULL;
-	List *stats = rel->statlist;
+	List	   *stats = rel->statlist;
 
 	foreach(l, stats)
 	{
 		StatisticExtInfo *stat = (StatisticExtInfo *) lfirst(l);
-		List *conditions1 = NIL,
-			 *conditions2 = NIL;
+		List	   *conditions1 = NIL,
+				   *conditions2 = NIL;
 
 		/* We only care about MCV statistics here. */
 		if (stat->kind != STATS_EXT_MCV)
@@ -2697,49 +2697,51 @@ statext_find_matching_mcv(PlannerInfo *root, RelOptInfo *rel,
 		}
 
 		/*
-		 * We have two candidate statistics objects and we need to decide which
-		 * one to keep. We'll use two simple heuristics:
+		 * We have two candidate statistics objects and we need to decide
+		 * which one to keep. We'll use two simple heuristics:
 		 *
 		 * (a) We prefer smaller statistics (fewer columns), on the assumption
-		 * that it represents a larger fraction of the data (due to having fewer
-		 * combinations with higher counts).
+		 * that it represents a larger fraction of the data (due to having
+		 * fewer combinations with higher counts).
 		 *
-		 * (b) If the statistics object covers some additional conditions for the rels,
-		 * that may help with considering additional dependencies between the
-		 * tables.
+		 * (b) If the statistics object covers some additional conditions for
+		 * the rels, that may help with considering additional dependencies
+		 * between the tables.
 		 *
-		 * Of course, those two heuristict are somewhat contradictory - smaller
-		 * stats are less likely to cover as many conditions as a larger one. We
-		 * consider the additional conditions first - if someone created such
-		 * statistics, there probably is a dependency worth considering.
+		 * Of course, those two heuristict are somewhat contradictory -
+		 * smaller stats are less likely to cover as many conditions as a
+		 * larger one. We consider the additional conditions first - if
+		 * someone created such statistics, there probably is a dependency
+		 * worth considering.
 		 *
 		 * When inspecting the restrictions, we need to be careful - we don't
-		 * know which of them are compatible with extended stats, so we have to
-		 * run them through statext_is_compatible_clause first and then match
-		 * them to the statistics.
+		 * know which of them are compatible with extended stats, so we have
+		 * to run them through statext_is_compatible_clause first and then
+		 * match them to the statistics.
 		 *
-		 * XXX Maybe we shouldn't pick statistics that covers just a single join
-		 * clause, without any additional conditions. In such case we could just
-		 * as well pick regular statistics for the column/expression, but it's
-		 * not clear if that actually exists (so we might reject the stats here
-		 * and then fail to find something simpler/better).
+		 * XXX Maybe we shouldn't pick statistics that covers just a single
+		 * join clause, without any additional conditions. In such case we
+		 * could just as well pick regular statistics for the
+		 * column/expression, but it's not clear if that actually exists (so
+		 * we might reject the stats here and then fail to find something
+		 * simpler/better).
 		 *
-		 * XXX I'm not sure about the preceding comment. Why would we find a MCV
-		 * list for a single condition here, but not for the single attribute?
-		 * Would the "partial" extended MCV even be useful?
+		 * XXX I'm not sure about the preceding comment. Why would we find a
+		 * MCV list for a single condition here, but not for the single
+		 * attribute? Would the "partial" extended MCV even be useful?
 		 */
 
 		/*
 		 * Match additional baserel conditions for the two statistics.
 		 *
-		 * XXX Shouldn't we keep this too? If there are more than 2 candidates,
-		 * we'll end up recalculating the conditions for the statistics we kept
-		 * from the preceding loop. Perhaps we could/should even pass the
-		 * conditions to the caller?
+		 * XXX Shouldn't we keep this too? If there are more than 2
+		 * candidates, we'll end up recalculating the conditions for the
+		 * statistics we kept from the preceding loop. Perhaps we could/should
+		 * even pass the conditions to the caller?
 		 *
-		 * XXX Or maybe we should simply "count" the restrictions here, instead
-		 * of constructing a list? Probably not a meaningful difference in CPU
-		 * costs or a memory leak.
+		 * XXX Or maybe we should simply "count" the restrictions here,
+		 * instead of constructing a list? Probably not a meaningful
+		 * difference in CPU costs or a memory leak.
 		 */
 		conditions1 = statext_determine_join_restrictions(root, rel, stat);
 		conditions2 = statext_determine_join_restrictions(root, rel, mcv);
@@ -2751,7 +2753,8 @@ statext_find_matching_mcv(PlannerInfo *root, RelOptInfo *rel,
 			continue;
 		}
 
-		/* The statistics seem about equal, so just use the narrower one.
+		/*
+		 * The statistics seem about equal, so just use the narrower one.
 		 *
 		 * XXX Maybe we should have a function/macro to count the keys/exprs?
 		 */
@@ -2788,12 +2791,12 @@ statext_determine_join_restrictions(PlannerInfo *root, RelOptInfo *rel,
 	List	   *conditions = NIL;
 
 	/* extract conditions that may be applied to the MCV list */
-	foreach (lc, rel->baserestrictinfo)
+	foreach(lc, rel->baserestrictinfo)
 	{
 		RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
-		Bitmapset *indexes = NULL;
-		Bitmapset *attnums = NULL;
-		List *exprs = NIL;
+		Bitmapset  *indexes = NULL;
+		Bitmapset  *attnums = NULL;
+		List	   *exprs = NIL;
 
 		/* clause has to be supported by MCV in general */
 		if (!statext_is_compatible_clause(root, (Node *) rinfo, rel->relid,
@@ -2801,8 +2804,8 @@ statext_determine_join_restrictions(PlannerInfo *root, RelOptInfo *rel,
 			continue;
 
 		/*
-		 * clause is compatible in general, but is it actually covered
-		 * by this particular statistics object?
+		 * clause is compatible in general, but is it actually covered by this
+		 * particular statistics object?
 		 */
 		if (!bms_is_subset(attnums, info->keys) ||
 			!stat_covers_expressions(info, exprs, &indexes))
@@ -2829,10 +2832,10 @@ static bool
 statext_is_supported_join_clause(PlannerInfo *root, Node *clause,
 								 int varRelid, SpecialJoinInfo *sjinfo)
 {
-	Oid	oprsel;
-	RestrictInfo   *rinfo;
-	OpExpr		   *opclause;
-	ListCell	   *lc;
+	Oid			oprsel;
+	RestrictInfo *rinfo;
+	OpExpr	   *opclause;
+	ListCell   *lc;
 
 	/*
 	 * evaluation as a restriction clause, either at scan node or forced
@@ -2871,43 +2874,43 @@ statext_is_supported_join_clause(PlannerInfo *root, Node *clause,
 	 * Make sure we're not mixing vars from multiple relations on the same
 	 * side, like
 	 *
-	 *   (t1.a + t2.a) = (t1.b + t2.b)
+	 * (t1.a + t2.a) = (t1.b + t2.b)
 	 *
 	 * which is still technically an opclause, but we can't match it to
 	 * extended statistics in a simple way.
 	 *
 	 * XXX This also means we require rinfo->clause_relids to have 2 rels.
 	 *
-	 * XXX Also check it's not expression on system attributes, which we
-	 * don't allow in extended statistics.
+	 * XXX Also check it's not expression on system attributes, which we don't
+	 * allow in extended statistics.
 	 *
-	 * XXX Although maybe we could allow cases that combine expressions
-	 * from both relations on either side? Like (t1.a + t2.b = t1.c - t2.d)
-	 * or something like that. We could do "cartesian product" of the MCV
-	 * stats and restrict it using this condition.
+	 * XXX Although maybe we could allow cases that combine expressions from
+	 * both relations on either side? Like (t1.a + t2.b = t1.c - t2.d) or
+	 * something like that. We could do "cartesian product" of the MCV stats
+	 * and restrict it using this condition.
 	 */
-	foreach (lc, opclause->args)
+	foreach(lc, opclause->args)
 	{
-		Bitmapset *varnos = NULL;
-		Node *expr = (Node *) lfirst(lc);
+		Bitmapset  *varnos = NULL;
+		Node	   *expr = (Node *) lfirst(lc);
 
 		varnos = pull_varnos(root, expr);
 
 		/*
 		 * No argument should reference more than just one relation.
 		 *
-		 * This effectively means each side references just two relations.
-		 * If there's no relation on one side, it's a Const, and the other
-		 * side has to be either Const or Expr with a single rel. In which
-		 * case it can't be a join clause.
+		 * This effectively means each side references just two relations. If
+		 * there's no relation on one side, it's a Const, and the other side
+		 * has to be either Const or Expr with a single rel. In which case it
+		 * can't be a join clause.
 		 */
 		if (bms_num_members(varnos) > 1)
 			return false;
 
 		/*
-		 * XXX Maybe check that both relations have extended statistics
-		 * (no point in considering the clause as useful without it). But
-		 * we'll do that check later anyway, so keep this cheap.
+		 * XXX Maybe check that both relations have extended statistics (no
+		 * point in considering the clause as useful without it). But we'll do
+		 * that check later anyway, so keep this cheap.
 		 */
 	}
 
@@ -2945,19 +2948,21 @@ statext_try_join_estimates(PlannerInfo *root, List *clauses, int varRelid,
 	 *
 	 * XXX Currently this only allows simple OpExpr equality clauses with each
 	 * argument referring to single relation, AND-ed together. Maybe we could
-	 * relax this in the future, e.g. to allow more complex (deeper) expressions
-	 * and to allow OR-ed join clauses too. And maybe supporting inequalities.
+	 * relax this in the future, e.g. to allow more complex (deeper)
+	 * expressions and to allow OR-ed join clauses too. And maybe supporting
+	 * inequalities.
 	 *
 	 * Handling more complex expressions seems simple - we already do that for
-	 * baserel estimates by building the match bitmap recursively, and we could
-	 * do something similar for combinations of MCV items (a bit like building
-	 * a single bit in the match bitmap). The challenge is what to do about the
-	 * part not represented by MCV, which is now based on ndistinct estimates.
+	 * baserel estimates by building the match bitmap recursively, and we
+	 * could do something similar for combinations of MCV items (a bit like
+	 * building a single bit in the match bitmap). The challenge is what to do
+	 * about the part not represented by MCV, which is now based on ndistinct
+	 * estimates.
 	 */
 	listidx = -1;
-	foreach (lc, clauses)
+	foreach(lc, clauses)
 	{
-		Node *clause = (Node *) lfirst(lc);
+		Node	   *clause = (Node *) lfirst(lc);
 		RestrictInfo *rinfo;
 
 		/* needs to happen before skipping any clauses */
@@ -2968,15 +2973,15 @@ statext_try_join_estimates(PlannerInfo *root, List *clauses, int varRelid,
 			continue;
 
 		/*
-		 * Skip clauses that are not join clauses or that we don't know
-		 * how to handle estimate using extended statistics.
+		 * Skip clauses that are not join clauses or that we don't know how to
+		 * handle estimate using extended statistics.
 		 */
 		if (!statext_is_supported_join_clause(root, clause, varRelid, sjinfo))
 			continue;
 
 		/*
-		 * XXX We're guaranteed to have RestrictInfo thanks to the checks
-		 * in statext_is_supported_join_clause.
+		 * XXX We're guaranteed to have RestrictInfo thanks to the checks in
+		 * statext_is_supported_join_clause.
 		 */
 		rinfo = (RestrictInfo *) clause;
 
@@ -3003,15 +3008,17 @@ statext_try_join_estimates(PlannerInfo *root, List *clauses, int varRelid,
 	 * cross-check the exact joined pairs of rels, but it's supposed to be a
 	 * cheap check, so maybe better leave that for later.
 	 *
-	 * XXX We could also check the number of parameters in each rel to consider
-	 * extended stats. If there's just a single attribute, it's pointless to use
-	 * extended statistics. OTOH we can also consider restriction clauses from
-	 * baserestrictinfo and use them to calculate conditional probabilities.
+	 * XXX We could also check the number of parameters in each rel to
+	 * consider extended stats. If there's just a single attribute, it's
+	 * pointless to use extended statistics. OTOH we can also consider
+	 * restriction clauses from baserestrictinfo and use them to calculate
+	 * conditional probabilities.
 	 */
 	k = -1;
 	while ((k = bms_next_member(relids, k)) >= 0)
 	{
 		RelOptInfo *rel = find_base_rel(root, k);
+
 		if (rel->statlist)
 			return true;
 	}
@@ -3045,10 +3052,10 @@ statext_build_join_pairs(PlannerInfo *root, List *clauses, int varRelid,
 						 JoinType jointype, SpecialJoinInfo *sjinfo,
 						 Bitmapset *estimatedclauses, int *npairs)
 {
-	int				cnt;
-	int				listidx;
-	JoinPairInfo   *info;
-	ListCell	   *lc;
+	int			cnt;
+	int			listidx;
+	JoinPairInfo *info;
+	ListCell   *lc;
 
 	/*
 	 * Assume each clause is for a different pair of relations (some of them
@@ -3061,10 +3068,10 @@ statext_build_join_pairs(PlannerInfo *root, List *clauses, int varRelid,
 	listidx = -1;
 	foreach(lc, clauses)
 	{
-		int				i;
-		bool			found;
-		Node		   *clause = (Node *) lfirst(lc);
-		RestrictInfo   *rinfo;
+		int			i;
+		bool		found;
+		Node	   *clause = (Node *) lfirst(lc);
+		RestrictInfo *rinfo;
 
 		listidx++;
 
@@ -3073,9 +3080,9 @@ statext_build_join_pairs(PlannerInfo *root, List *clauses, int varRelid,
 			continue;
 
 		/*
-		 * Make sure the clause is a join clause of a supported shape (at
-		 * the moment we support just (Expr op Expr) clauses with each
-		 * side referencing just a single relation).
+		 * Make sure the clause is a join clause of a supported shape (at the
+		 * moment we support just (Expr op Expr) clauses with each side
+		 * referencing just a single relation).
 		 */
 		if (!statext_is_supported_join_clause(root, clause, varRelid, sjinfo))
 			continue;
@@ -3153,23 +3160,23 @@ extract_relation_info(PlannerInfo *root, JoinPairInfo *info, int index,
 	rel = find_base_rel(root, relid);
 
 	/*
-	 * Walk the clauses for this join pair, and extract expressions about
-	 * the relation identified by index / relid. For simple Vars we extract
-	 * the attnum. Otherwise we keep the whole expression.
+	 * Walk the clauses for this join pair, and extract expressions about the
+	 * relation identified by index / relid. For simple Vars we extract the
+	 * attnum. Otherwise we keep the whole expression.
 	 */
-	foreach (lc, info->clauses)
+	foreach(lc, info->clauses)
 	{
-		ListCell *lc2;
-		Node *clause = (Node *) lfirst(lc);
-		OpExpr *opclause = (OpExpr *) clause;
+		ListCell   *lc2;
+		Node	   *clause = (Node *) lfirst(lc);
+		OpExpr	   *opclause = (OpExpr *) clause;
 
 		/* only opclauses supported for now */
 		Assert(is_opclause(clause));
 
-		foreach (lc2, opclause->args)
+		foreach(lc2, opclause->args)
 		{
-			Node *arg = (Node *) lfirst(lc2);
-			Bitmapset *varnos = NULL;
+			Node	   *arg = (Node *) lfirst(lc2);
+			Bitmapset  *varnos = NULL;
 
 			/* plain Var references (boolean Vars or recursive checks) */
 			if (IsA(arg, Var))
@@ -3184,7 +3191,10 @@ extract_relation_info(PlannerInfo *root, JoinPairInfo *info, int index,
 				if (var->varlevelsup > 0)
 					continue;
 
-				/* Also skip system attributes (we don't allow stats on those). */
+				/*
+				 * Also skip system attributes (we don't allow stats on
+				 * those).
+				 */
 				if (!AttrNumberIsForUserDefinedAttr(var->varattno))
 					elog(ERROR, "unexpected system attribute");
 
@@ -3195,10 +3205,9 @@ extract_relation_info(PlannerInfo *root, JoinPairInfo *info, int index,
 			}
 
 			/*
-			 * OK, it's a more complex expression, so check if it matches
-			 * the relid and maybe keep it as a whole. It should be
-			 * compatible because we already checked it when building the
-			 * join pairs.
+			 * OK, it's a more complex expression, so check if it matches the
+			 * relid and maybe keep it as a whole. It should be compatible
+			 * because we already checked it when building the join pairs.
 			 */
 			varnos = pull_varnos(root, arg);
 
@@ -3228,15 +3237,15 @@ extract_relation_info(PlannerInfo *root, JoinPairInfo *info, int index,
 static Node *
 get_expression_for_rel(PlannerInfo *root, RelOptInfo *rel, Node *clause)
 {
-	OpExpr *opexpr;
-	Node   *expr;
+	OpExpr	   *opexpr;
+	Node	   *expr;
 
 	/*
 	 * Strip the RestrictInfo node, get the actual clause.
 	 *
-	 * XXX Not sure if we need to care about removing other node types
-	 * too (e.g. RelabelType etc.). statext_is_supported_join_clause
-	 * matches this, but maybe we need to relax it?
+	 * XXX Not sure if we need to care about removing other node types too
+	 * (e.g. RelabelType etc.). statext_is_supported_join_clause matches this,
+	 * but maybe we need to relax it?
 	 */
 	if (IsA(clause, RestrictInfo))
 		clause = (Node *) ((RestrictInfo *) clause)->clause;
@@ -3279,10 +3288,10 @@ statext_clauselist_join_selectivity(PlannerInfo *root, List *clauses, int varRel
 {
 	int			i;
 	int			listidx;
-	Selectivity	s = 1.0;
+	Selectivity s = 1.0;
 
 	JoinPairInfo *info;
-	int				ninfo;
+	int			ninfo;
 
 	if (!clauses)
 		return 1.0;
@@ -3298,27 +3307,27 @@ statext_clauselist_join_selectivity(PlannerInfo *root, List *clauses, int varRel
 	/*
 	 * Process the join pairs, try to find a matching MCV on each side.
 	 *
-	 * XXX The basic principle is quite similar to eqjoinsel_inner, i.e.
-	 * we try to find a MCV on both sides of the join, and use it to get
-	 * a better join estimate. It's a bit more complicated, because there
-	 * might be multiple MCV lists, we also need ndistinct estimate, and
-	 * there may be interesting baserestrictions too.
+	 * XXX The basic principle is quite similar to eqjoinsel_inner, i.e. we
+	 * try to find a MCV on both sides of the join, and use it to get a better
+	 * join estimate. It's a bit more complicated, because there might be
+	 * multiple MCV lists, we also need ndistinct estimate, and there may be
+	 * interesting baserestrictions too.
 	 *
-	 * XXX At the moment we only handle the case with matching MCVs on
-	 * both sides, but it'd be good to also handle case with just ndistinct
+	 * XXX At the moment we only handle the case with matching MCVs on both
+	 * sides, but it'd be good to also handle case with just ndistinct
 	 * statistics improving ndistinct estimates.
 	 *
-	 * XXX We might also handle cases with a regular MCV on one side and
-	 * an extended MCV on the other side.
+	 * XXX We might also handle cases with a regular MCV on one side and an
+	 * extended MCV on the other side.
 	 *
-	 * XXX Perhaps it'd be good to also handle case with one side only
-	 * having "regular" statistics (e.g. MCV), especially in cases with
-	 * no conditions on that side of the join (where we can't use the
-	 * extended MCV to calculate conditional probability).
+	 * XXX Perhaps it'd be good to also handle case with one side only having
+	 * "regular" statistics (e.g. MCV), especially in cases with no conditions
+	 * on that side of the join (where we can't use the extended MCV to
+	 * calculate conditional probability).
 	 */
 	for (i = 0; i < ninfo; i++)
 	{
-		ListCell *lc;
+		ListCell   *lc;
 
 		RelOptInfo *rel1;
 		RelOptInfo *rel2;
@@ -3336,14 +3345,14 @@ statext_clauselist_join_selectivity(PlannerInfo *root, List *clauses, int varRel
 		 * We can handle three basic cases:
 		 *
 		 * a) Extended stats (with MCV) on both sides is an ideal case, and we
-		 * can simply combine the two MCVs, possibly with additional conditions
-		 * from the relations.
+		 * can simply combine the two MCVs, possibly with additional
+		 * conditions from the relations.
 		 *
 		 * b) Extended stats on one side, regular MCV on the other side (this
 		 * means there's just one join clause / expression). It also means the
-		 * extended stats likely covers at least one extra condition, otherwise
-		 * we could just use regular statistics. We can combine the stats just
-		 * similarly to (a).
+		 * extended stats likely covers at least one extra condition,
+		 * otherwise we could just use regular statistics. We can combine the
+		 * stats just similarly to (a).
 		 *
 		 * c) No extended stats with MCV. If there are multiple join clauses,
 		 * we can try using ndistinct coefficients and do what eqjoinsel does.
@@ -3358,14 +3367,14 @@ statext_clauselist_join_selectivity(PlannerInfo *root, List *clauses, int varRel
 		else if (stat1 && (list_length(info[i].clauses) == 1))
 		{
 			/* try finding MCV on the other relation */
-			VariableStatData	vardata;
-			AttStatsSlot		sslot;
-			Form_pg_statistic	stats = NULL;
-			bool				have_mcvs = false;
-			Node			   *clause = linitial(info[i].clauses);
-			Node			   *expr = get_expression_for_rel(root, rel2, clause);
-			double				nd;
-			bool				isdefault;
+			VariableStatData vardata;
+			AttStatsSlot sslot;
+			Form_pg_statistic stats = NULL;
+			bool		have_mcvs = false;
+			Node	   *clause = linitial(info[i].clauses);
+			Node	   *expr = get_expression_for_rel(root, rel2, clause);
+			double		nd;
+			bool		isdefault;
 
 			examine_variable(root, expr, 0, &vardata);
 
@@ -3377,7 +3386,11 @@ statext_clauselist_join_selectivity(PlannerInfo *root, List *clauses, int varRel
 			{
 				/* note we allow use of nullfrac regardless of security check */
 				stats = (Form_pg_statistic) GETSTRUCT(vardata.statsTuple);
-				/* FIXME should this call statistic_proc_security_check like eqjoinsel? */
+
+				/*
+				 * FIXME should this call statistic_proc_security_check like
+				 * eqjoinsel?
+				 */
 				have_mcvs = get_attstatsslot(&sslot, vardata.statsTuple,
 											 STATISTIC_KIND_MCV, InvalidOid,
 											 ATTSTATSSLOT_VALUES | ATTSTATSSLOT_NUMBERS);
@@ -3398,14 +3411,14 @@ statext_clauselist_join_selectivity(PlannerInfo *root, List *clauses, int varRel
 		else if (stat2 && (list_length(info[i].clauses) == 1))
 		{
 			/* try finding MCV on the other relation */
-			VariableStatData	vardata;
-			AttStatsSlot		sslot;
-			Form_pg_statistic	stats = NULL;
-			bool				have_mcvs = false;
-			Node			   *clause = (Node *) linitial(info[i].clauses);
-			Node			   *expr = get_expression_for_rel(root, rel1, clause);
-			double				nd;
-			bool				isdefault;
+			VariableStatData vardata;
+			AttStatsSlot sslot;
+			Form_pg_statistic stats = NULL;
+			bool		have_mcvs = false;
+			Node	   *clause = (Node *) linitial(info[i].clauses);
+			Node	   *expr = get_expression_for_rel(root, rel1, clause);
+			double		nd;
+			bool		isdefault;
 
 			examine_variable(root, expr, 0, &vardata);
 
@@ -3417,7 +3430,11 @@ statext_clauselist_join_selectivity(PlannerInfo *root, List *clauses, int varRel
 			{
 				/* note we allow use of nullfrac regardless of security check */
 				stats = (Form_pg_statistic) GETSTRUCT(vardata.statsTuple);
-				/* FIXME should this call statistic_proc_security_check like eqjoinsel? */
+
+				/*
+				 * FIXME should this call statistic_proc_security_check like
+				 * eqjoinsel?
+				 */
 				have_mcvs = get_attstatsslot(&sslot, vardata.statsTuple,
 											 STATISTIC_KIND_MCV, InvalidOid,
 											 ATTSTATSSLOT_VALUES | ATTSTATSSLOT_NUMBERS);
@@ -3441,18 +3458,19 @@ statext_clauselist_join_selectivity(PlannerInfo *root, List *clauses, int varRel
 		/*
 		 * Now mark all the clauses for this join pair as estimated.
 		 *
-		 * XXX Maybe track the indexes in JoinPairInfo, so that we can
-		 * simply union the two bitmaps, without the extra matching.
+		 * XXX Maybe track the indexes in JoinPairInfo, so that we can simply
+		 * union the two bitmaps, without the extra matching.
 		 */
-		foreach (lc, info->clauses)
+		foreach(lc, info->clauses)
 		{
-			Node *clause = (Node *) lfirst(lc);
-			ListCell *lc2;
+			Node	   *clause = (Node *) lfirst(lc);
+			ListCell   *lc2;
 
 			listidx = -1;
-			foreach (lc2, clauses)
+			foreach(lc2, clauses)
 			{
-				Node *clause2 = (Node *) lfirst(lc2);
+				Node	   *clause2 = (Node *) lfirst(lc2);
+
 				listidx++;
 
 				Assert(IsA(clause2, RestrictInfo));
diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c
index 49299ed9074..3169022cd6d 100644
--- a/src/backend/statistics/mcv.c
+++ b/src/backend/statistics/mcv.c
@@ -2220,33 +2220,33 @@ mcv_combine_extended(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 	Selectivity s = 0;
 
 	/* match bitmaps and selectivity for baserel conditions (if any) */
-	List   *exprs1 = NIL,
-		   *exprs2 = NIL;
-	List   *conditions1 = NIL,
-		   *conditions2 = NIL;
-	bool   *cmatches1 = NULL,
-		   *cmatches2 = NULL;
+	List	   *exprs1 = NIL,
+			   *exprs2 = NIL;
+	List	   *conditions1 = NIL,
+			   *conditions2 = NIL;
+	bool	   *cmatches1 = NULL,
+			   *cmatches2 = NULL;
 
-	double	csel1 = 1.0,
-			csel2 = 1.0;
+	double		csel1 = 1.0,
+				csel2 = 1.0;
 
-	bool   *matches1 = NULL,
-		   *matches2 = NULL;
+	bool	   *matches1 = NULL,
+			   *matches2 = NULL;
 
 	/* estimates for the two relations */
-	double	matchfreq1,
-			unmatchfreq1,
-			otherfreq1,
-			mcvfreq1,
-			nd1,
-			totalsel1;
-
-	double 	matchfreq2,
-			unmatchfreq2,
-			otherfreq2,
-			mcvfreq2,
-			nd2,
-			totalsel2;
+	double		matchfreq1,
+				unmatchfreq1,
+				otherfreq1,
+				mcvfreq1,
+				nd1,
+				totalsel1;
+
+	double		matchfreq2,
+				unmatchfreq2,
+				otherfreq2,
+				mcvfreq2,
+				nd2,
+				totalsel2;
 
 	/* info about clauses and how they match to MCV stats */
 	FmgrInfo   *opprocs;
@@ -2290,16 +2290,16 @@ mcv_combine_extended(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 	}
 
 	/*
-	 * Match bitmaps for matches between MCV elements. By default there
-	 * are no matches, so we set all items to 0.
+	 * Match bitmaps for matches between MCV elements. By default there are no
+	 * matches, so we set all items to 0.
 	 */
 	matches1 = (bool *) palloc0(sizeof(bool) * mcv1->nitems);
 	matches2 = (bool *) palloc0(sizeof(bool) * mcv2->nitems);
 
 	/*
 	 * Initialize information about clauses and how they match to the MCV
-	 * stats we picked. We do this only once before processing the lists,
-	 * so that we don't have to do that for each MCV item or so.
+	 * stats we picked. We do this only once before processing the lists, so
+	 * that we don't have to do that for each MCV item or so.
 	 */
 	opprocs = (FmgrInfo *) palloc(sizeof(FmgrInfo) * list_length(clauses));
 	indexes1 = (int *) palloc(sizeof(int) * list_length(clauses));
@@ -2307,7 +2307,7 @@ mcv_combine_extended(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 	reverse = (bool *) palloc(sizeof(bool) * list_length(clauses));
 
 	idx = 0;
-	foreach (lc, clauses)
+	foreach(lc, clauses)
 	{
 		Node	   *clause = (Node *) lfirst(lc);
 		OpExpr	   *opexpr;
@@ -2319,9 +2319,9 @@ mcv_combine_extended(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 		/*
 		 * Strip the RestrictInfo node, get the actual clause.
 		 *
-		 * XXX Not sure if we need to care about removing other node types
-		 * too (e.g. RelabelType etc.). statext_is_supported_join_clause
-		 * matches this, but maybe we need to relax it?
+		 * XXX Not sure if we need to care about removing other node types too
+		 * (e.g. RelabelType etc.). statext_is_supported_join_clause matches
+		 * this, but maybe we need to relax it?
 		 */
 		if (IsA(clause, RestrictInfo))
 			clause = (Node *) ((RestrictInfo *) clause)->clause;
@@ -2345,7 +2345,7 @@ mcv_combine_extended(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 		if ((bms_singleton_member(relids1) == rel1->relid) &&
 			(bms_singleton_member(relids2) == rel2->relid))
 		{
-			Oid		collid;
+			Oid			collid;
 
 			indexes1[idx] = mcv_match_expression(expr1,
 												 stat1->keys, stat1->exprs,
@@ -2361,7 +2361,7 @@ mcv_combine_extended(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 		else if ((bms_singleton_member(relids2) == rel1->relid) &&
 				 (bms_singleton_member(relids1) == rel2->relid))
 		{
-			Oid		collid;
+			Oid			collid;
 
 			indexes1[idx] = mcv_match_expression(expr2,
 												 stat2->keys, stat2->exprs,
@@ -2390,21 +2390,22 @@ mcv_combine_extended(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 	/*
 	 * Match items between the two MCV lists.
 	 *
-	 * We don't know if the join conditions match all attributes in the MCV, the
-	 * overlap may be just on a subset of attributes, e.g. (a,b,c) vs. (b,c,d).
-	 * So there may be multiple matches on either side. So we can't optimize by
-	 * aborting the inner loop after the first match, etc.
+	 * We don't know if the join conditions match all attributes in the MCV,
+	 * the overlap may be just on a subset of attributes, e.g. (a,b,c) vs.
+	 * (b,c,d). So there may be multiple matches on either side. So we can't
+	 * optimize by aborting the inner loop after the first match, etc.
 	 *
-	 * XXX We can skip the items eliminated by the base restrictions, of course.
+	 * XXX We can skip the items eliminated by the base restrictions, of
+	 * course.
 	 *
 	 * XXX We might optimize this in two ways. We might sort the MCV items on
 	 * both sides using the "join" attributes, and then perform something like
-	 * merge join. Or we might calculate a hash from the join columns, and then
-	 * compare this (to eliminate the most expensive equality functions).
+	 * merge join. Or we might calculate a hash from the join columns, and
+	 * then compare this (to eliminate the most expensive equality functions).
 	 */
 	for (i = 0; i < mcv1->nitems; i++)
 	{
-		bool	has_nulls;
+		bool		has_nulls;
 
 		/* skip items eliminated by restrictions on rel1 */
 		if (cmatches1 && !cmatches1[i])
@@ -2436,26 +2437,27 @@ mcv_combine_extended(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 				continue;
 
 			/*
-			 * XXX We can't skip based on existing matches2 value, because there
-			 * may be duplicates in the first MCV.
+			 * XXX We can't skip based on existing matches2 value, because
+			 * there may be duplicates in the first MCV.
 			 */
 
 			/*
-			 * Evaluate if all the join clauses match between the two MCV items.
+			 * Evaluate if all the join clauses match between the two MCV
+			 * items.
 			 *
-			 * XXX We might optimize the order of evaluation, using the costs of
-			 * operator functions for individual columns. It does depend on the
-			 * number of distinct values, etc.
+			 * XXX We might optimize the order of evaluation, using the costs
+			 * of operator functions for individual columns. It does depend on
+			 * the number of distinct values, etc.
 			 */
 			idx = 0;
-			foreach (lc, clauses)
+			foreach(lc, clauses)
 			{
-				bool	match;
-				int		index1 = indexes1[idx],
-						index2 = indexes2[idx];
-				Datum	value1,
-						value2;
-				bool	reverse_args = reverse[idx];
+				bool		match;
+				int			index1 = indexes1[idx],
+							index2 = indexes2[idx];
+				Datum		value1,
+							value2;
+				bool		reverse_args = reverse[idx];
 
 				/* If either value is null, it's a mismatch */
 				if (mcv2->items[j].isnull[index2])
@@ -2466,8 +2468,8 @@ mcv_combine_extended(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 					value2 = mcv2->items[j].values[index2];
 
 					/*
-					 * Careful about order of parameters. For same-type equality
-					 * that should not matter, but easy enough.
+					 * Careful about order of parameters. For same-type
+					 * equality that should not matter, but easy enough.
 					 *
 					 * FIXME Use appropriate collation.
 					 */
@@ -2537,10 +2539,10 @@ mcv_combine_extended(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 	/*
 	 * Correction for MCV parts eliminated by the conditions.
 	 *
-	 * We need to be careful about cases where conditions eliminated all
-	 * the MCV items. We must not divide by 0.0, because that would either
-	 * produce bogus value or trigger division by zero. Instead we simply
-	 * set the selectivity to 0.0, because there can't be any matches.
+	 * We need to be careful about cases where conditions eliminated all the
+	 * MCV items. We must not divide by 0.0, because that would either produce
+	 * bogus value or trigger division by zero. Instead we simply set the
+	 * selectivity to 0.0, because there can't be any matches.
 	 */
 	if ((matchfreq1 + unmatchfreq1) > 0)
 		s = s * mcvfreq1 / (matchfreq1 + unmatchfreq1);
@@ -2560,23 +2562,23 @@ mcv_combine_extended(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 	 * Consider the part of the data not represented by the MCV lists.
 	 *
 	 * XXX this is a bit bogus, because we don't know what fraction of
-	 * distinct combinations is covered by the MCV list (we're only
-	 * dealing with some of the columns), so we can't use the same
-	 * formular as eqjoinsel_inner exactly. We just use the estimates
-	 * for the whole table - this is likely an overestimate, because
-	 * (a) items may repeat in the MCV list, if it has more columns,
-	 * and (b) some of the combinations may be present in non-MCV data.
+	 * distinct combinations is covered by the MCV list (we're only dealing
+	 * with some of the columns), so we can't use the same formular as
+	 * eqjoinsel_inner exactly. We just use the estimates for the whole table
+	 * - this is likely an overestimate, because (a) items may repeat in the
+	 * MCV list, if it has more columns, and (b) some of the combinations may
+	 * be present in non-MCV data.
 	 *
-	 * Moreover, we need to look at the conditions. For now we simply
-	 * assume the conditions affect the distinct groups, and use that.
+	 * Moreover, we need to look at the conditions. For now we simply assume
+	 * the conditions affect the distinct groups, and use that.
 	 *
-	 * XXX We might calculate the number of distinct groups in the MCV,
-	 * and then use something between (nd1 - distinct(MCV)) and (nd1),
-	 * which are the possible extreme values, assuming the estimates
-	 * are accurate. Maybe mean or geometric mean would work?
+	 * XXX We might calculate the number of distinct groups in the MCV, and
+	 * then use something between (nd1 - distinct(MCV)) and (nd1), which are
+	 * the possible extreme values, assuming the estimates are accurate. Maybe
+	 * mean or geometric mean would work?
 	 *
-	 * XXX Not sure multiplying ndistinct with probabilities is good.
-	 * Maybe we should do something more like estimate_num_groups?
+	 * XXX Not sure multiplying ndistinct with probabilities is good. Maybe we
+	 * should do something more like estimate_num_groups?
 	 */
 	nd1 *= csel1;
 	nd2 *= csel2;
@@ -2585,21 +2587,21 @@ mcv_combine_extended(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 	totalsel1 += unmatchfreq1 * otherfreq2 / nd2;
 	totalsel1 += otherfreq1 * (otherfreq2 + unmatchfreq2) / nd2;
 
-//	if (nd2 > mcvb->nitems)
-//		totalsel1 += unmatchfreq1 * otherfreq2 / (nd2 - mcvb->nitems);
-//	if (nd2 > nmatches)
-//		totalsel1 += otherfreq1 * (otherfreq2 + unmatchfreq2) /
-//			(nd2 - nmatches);
+/* 	if (nd2 > mcvb->nitems) */
+/* 		totalsel1 += unmatchfreq1 * otherfreq2 / (nd2 - mcvb->nitems); */
+/* 	if (nd2 > nmatches) */
+/* 		totalsel1 += otherfreq1 * (otherfreq2 + unmatchfreq2) / */
+/* 			(nd2 - nmatches); */
 
 	totalsel2 = s;
 	totalsel2 += unmatchfreq2 * otherfreq1 / nd1;
 	totalsel2 += otherfreq2 * (otherfreq1 + unmatchfreq1) / nd1;
 
-//	if (nd1 > mcva->nitems)
-//		totalsel2 += unmatchfreq2 * otherfreq1 / (nd1 - mcva->nitems);
-//	if (nd1 > nmatches)
-//		totalsel2 += otherfreq2 * (otherfreq1 + unmatchfreq1) /
-//			(nd1 - nmatches);
+/* 	if (nd1 > mcva->nitems) */
+/* 		totalsel2 += unmatchfreq2 * otherfreq1 / (nd1 - mcva->nitems); */
+/* 	if (nd1 > nmatches) */
+/* 		totalsel2 += otherfreq2 * (otherfreq1 + unmatchfreq1) / */
+/* 			(nd1 - nmatches); */
 
 	s = Min(totalsel1, totalsel2);
 
@@ -2627,31 +2629,31 @@ mcv_combine_simple(PlannerInfo *root, RelOptInfo *rel, StatisticExtInfo *stat,
 	Selectivity s = 0;
 
 	/* match bitmaps and selectivity for baserel conditions (if any) */
-	List   *conditions = NIL;
-	bool   *cmatches = NULL;
+	List	   *conditions = NIL;
+	bool	   *cmatches = NULL;
 
-	double	csel = 1.0;
+	double		csel = 1.0;
 
-	bool   *matches1 = NULL,
-		   *matches2 = NULL;
+	bool	   *matches1 = NULL,
+			   *matches2 = NULL;
 
 	/* estimates for the two sides */
-	double	matchfreq1,
-			unmatchfreq1,
-			otherfreq1,
-			mcvfreq1,
-			nd1,
-			totalsel1;
-
-	double 	matchfreq2,
-			unmatchfreq2,
-			otherfreq2,
-			mcvfreq2,
-			nd2,
-			totalsel2;
-
-	List   *exprs1 = NIL,
-		   *exprs2 = NIL;
+	double		matchfreq1,
+				unmatchfreq1,
+				otherfreq1,
+				mcvfreq1,
+				nd1,
+				totalsel1;
+
+	double		matchfreq2,
+				unmatchfreq2,
+				otherfreq2,
+				mcvfreq2,
+				nd2,
+				totalsel2;
+
+	List	   *exprs1 = NIL,
+			   *exprs2 = NIL;
 
 	/* info about clauses and how they match to MCV stats */
 	FmgrInfo	opproc;
@@ -2677,14 +2679,14 @@ mcv_combine_simple(PlannerInfo *root, RelOptInfo *rel, StatisticExtInfo *stat,
 	if (conditions)
 	{
 		cmatches = mcv_get_match_bitmap(root, conditions,
-										 stat->keys, stat->exprs,
-										 mcv, false);
+										stat->keys, stat->exprs,
+										mcv, false);
 		csel = clauselist_selectivity(root, conditions, rel->relid, 0, NULL);
 	}
 
 	/*
-	 * Match bitmaps for matches between MCV elements. By default there
-	 * are no matches, so we set all items to 0.
+	 * Match bitmaps for matches between MCV elements. By default there are no
+	 * matches, so we set all items to 0.
 	 */
 	matches1 = (bool *) palloc0(sizeof(bool) * mcv->nitems);
 
@@ -2693,8 +2695,8 @@ mcv_combine_simple(PlannerInfo *root, RelOptInfo *rel, StatisticExtInfo *stat,
 
 	/*
 	 * Initialize information about the clause and how it matches to the
-	 * extended stats we picked. We do this only once before processing
-	 * the lists, so that we don't have to do that for each item or so.
+	 * extended stats we picked. We do this only once before processing the
+	 * lists, so that we don't have to do that for each item or so.
 	 */
 	{
 		OpExpr	   *opexpr;
@@ -2706,9 +2708,9 @@ mcv_combine_simple(PlannerInfo *root, RelOptInfo *rel, StatisticExtInfo *stat,
 		/*
 		 * Strip the RestrictInfo node, get the actual clause.
 		 *
-		 * XXX Not sure if we need to care about removing other node types
-		 * too (e.g. RelabelType etc.). statext_is_supported_join_clause
-		 * matches this, but maybe we need to relax it?
+		 * XXX Not sure if we need to care about removing other node types too
+		 * (e.g. RelabelType etc.). statext_is_supported_join_clause matches
+		 * this, but maybe we need to relax it?
 		 */
 		if (IsA(clause, RestrictInfo))
 			clause = (Node *) ((RestrictInfo *) clause)->clause;
@@ -2731,7 +2733,7 @@ mcv_combine_simple(PlannerInfo *root, RelOptInfo *rel, StatisticExtInfo *stat,
 
 		if (bms_singleton_member(relids1) == rel->relid)
 		{
-			Oid		collid;
+			Oid			collid;
 
 			index = mcv_match_expression(expr1, stat->keys, stat->exprs,
 										 &collid);
@@ -2742,7 +2744,7 @@ mcv_combine_simple(PlannerInfo *root, RelOptInfo *rel, StatisticExtInfo *stat,
 		}
 		else if (bms_singleton_member(relids2) == rel->relid)
 		{
-			Oid		collid;
+			Oid			collid;
 
 			index = mcv_match_expression(expr2, stat->keys, stat->exprs,
 										 &collid);
@@ -2762,17 +2764,18 @@ mcv_combine_simple(PlannerInfo *root, RelOptInfo *rel, StatisticExtInfo *stat,
 	/*
 	 * Match items between the two MCV lists.
 	 *
-	 * We don't know if the join conditions match all attributes in the MCV, the
-	 * overlap may be just on a subset of attributes, e.g. (a,b,c) vs. (b,c,d).
-	 * So there may be multiple matches on either side. So we can't optimize by
-	 * aborting the inner loop after the first match, etc.
+	 * We don't know if the join conditions match all attributes in the MCV,
+	 * the overlap may be just on a subset of attributes, e.g. (a,b,c) vs.
+	 * (b,c,d). So there may be multiple matches on either side. So we can't
+	 * optimize by aborting the inner loop after the first match, etc.
 	 *
-	 * XXX We can skip the items eliminated by the base restrictions, of course.
+	 * XXX We can skip the items eliminated by the base restrictions, of
+	 * course.
 	 *
 	 * XXX We might optimize this in two ways. We might sort the MCV items on
 	 * both sides using the "join" attributes, and then perform something like
-	 * merge join. Or we might calculate a hash from the join columns, and then
-	 * compare this (to eliminate the most expensive equality functions).
+	 * merge join. Or we might calculate a hash from the join columns, and
+	 * then compare this (to eliminate the most expensive equality functions).
 	 */
 	for (i = 0; i < mcv->nitems; i++)
 	{
@@ -2790,9 +2793,9 @@ mcv_combine_simple(PlannerInfo *root, RelOptInfo *rel, StatisticExtInfo *stat,
 		/* find matches in the second MCV list */
 		for (j = 0; j < sslot->nvalues; j++)
 		{
-			bool	match;
-			Datum	value1 = mcv->items[i].values[index];
-			Datum	value2 = sslot->values[j];
+			bool		match;
+			Datum		value1 = mcv->items[i].values[index];
+			Datum		value2 = sslot->values[j];
 
 			/*
 			 * Evaluate the join clause between the two MCV lists. We don't
@@ -2800,8 +2803,8 @@ mcv_combine_simple(PlannerInfo *root, RelOptInfo *rel, StatisticExtInfo *stat,
 			 * NULL in the extended statistics earlier, and the simple MCV
 			 * does not contain NULL values.
 			 *
-			 * Careful about order of parameters. For same-type equality
-			 * that should not matter, but easy enough.
+			 * Careful about order of parameters. For same-type equality that
+			 * should not matter, but easy enough.
 			 *
 			 * FIXME Use appropriate collation.
 			 */
@@ -2821,8 +2824,8 @@ mcv_combine_simple(PlannerInfo *root, RelOptInfo *rel, StatisticExtInfo *stat,
 				s += mcv->items[i].frequency * sslot->numbers[j];
 
 				/*
-				 * We know there can be just a single match in the regular
-				 * MCV list, so we can abort the inner loop.
+				 * We know there can be just a single match in the regular MCV
+				 * list, so we can abort the inner loop.
 				 */
 				break;
 			}
@@ -2864,10 +2867,10 @@ mcv_combine_simple(PlannerInfo *root, RelOptInfo *rel, StatisticExtInfo *stat,
 	/*
 	 * Correction for MCV parts eliminated by the conditions.
 	 *
-	 * We need to be careful about cases where conditions eliminated all
-	 * the MCV items. We must not divide by 0.0, because that would either
-	 * produce bogus value or trigger division by zero. Instead we simply
-	 * set the selectivity to 0.0, because there can't be any matches.
+	 * We need to be careful about cases where conditions eliminated all the
+	 * MCV items. We must not divide by 0.0, because that would either produce
+	 * bogus value or trigger division by zero. Instead we simply set the
+	 * selectivity to 0.0, because there can't be any matches.
 	 */
 	if ((matchfreq1 + unmatchfreq1) > 0)
 		s = s * mcvfreq1 / (matchfreq1 + unmatchfreq1);
@@ -2887,23 +2890,23 @@ mcv_combine_simple(PlannerInfo *root, RelOptInfo *rel, StatisticExtInfo *stat,
 	 * Consider the part of the data not represented by the MCV lists.
 	 *
 	 * XXX this is a bit bogus, because we don't know what fraction of
-	 * distinct combinations is covered by the MCV list (we're only
-	 * dealing with some of the columns), so we can't use the same
-	 * formular as eqjoinsel_inner exactly. We just use the estimates
-	 * for the whole table - this is likely an overestimate, because
-	 * (a) items may repeat in the MCV list, if it has more columns,
-	 * and (b) some of the combinations may be present in non-MCV data.
+	 * distinct combinations is covered by the MCV list (we're only dealing
+	 * with some of the columns), so we can't use the same formular as
+	 * eqjoinsel_inner exactly. We just use the estimates for the whole table
+	 * - this is likely an overestimate, because (a) items may repeat in the
+	 * MCV list, if it has more columns, and (b) some of the combinations may
+	 * be present in non-MCV data.
 	 *
-	 * Moreover, we need to look at the conditions. For now we simply
-	 * assume the conditions affect the distinct groups, and use that.
+	 * Moreover, we need to look at the conditions. For now we simply assume
+	 * the conditions affect the distinct groups, and use that.
 	 *
-	 * XXX We might calculate the number of distinct groups in the MCV,
-	 * and then use something between (nd1 - distinct(MCV)) and (nd1),
-	 * which are the possible extreme values, assuming the estimates
-	 * are accurate. Maybe mean or geometric mean would work?
+	 * XXX We might calculate the number of distinct groups in the MCV, and
+	 * then use something between (nd1 - distinct(MCV)) and (nd1), which are
+	 * the possible extreme values, assuming the estimates are accurate. Maybe
+	 * mean or geometric mean would work?
 	 *
-	 * XXX Not sure multiplying ndistinct with probabilities is good.
-	 * Maybe we should do something more like estimate_num_groups?
+	 * XXX Not sure multiplying ndistinct with probabilities is good. Maybe we
+	 * should do something more like estimate_num_groups?
 	 */
 	nd1 *= csel;
 
@@ -2911,21 +2914,21 @@ mcv_combine_simple(PlannerInfo *root, RelOptInfo *rel, StatisticExtInfo *stat,
 	totalsel1 += unmatchfreq1 * otherfreq2 / nd2;
 	totalsel1 += otherfreq1 * (otherfreq2 + unmatchfreq2) / nd2;
 
-//	if (nd2 > mcvb->nitems)
-//		totalsel1 += unmatchfreq1 * otherfreq2 / (nd2 - mcvb->nitems);
-//	if (nd2 > nmatches)
-//		totalsel1 += otherfreq1 * (otherfreq2 + unmatchfreq2) /
-//			(nd2 - nmatches);
+/* 	if (nd2 > mcvb->nitems) */
+/* 		totalsel1 += unmatchfreq1 * otherfreq2 / (nd2 - mcvb->nitems); */
+/* 	if (nd2 > nmatches) */
+/* 		totalsel1 += otherfreq1 * (otherfreq2 + unmatchfreq2) / */
+/* 			(nd2 - nmatches); */
 
 	totalsel2 = s;
 	totalsel2 += unmatchfreq2 * otherfreq1 / nd1;
 	totalsel2 += otherfreq2 * (otherfreq1 + unmatchfreq1) / nd1;
 
-//	if (nd1 > mcva->nitems)
-//		totalsel2 += unmatchfreq2 * otherfreq1 / (nd1 - mcva->nitems);
-//	if (nd1 > nmatches)
-//		totalsel2 += otherfreq2 * (otherfreq1 + unmatchfreq1) /
-//			(nd1 - nmatches);
+/* 	if (nd1 > mcva->nitems) */
+/* 		totalsel2 += unmatchfreq2 * otherfreq1 / (nd1 - mcva->nitems); */
+/* 	if (nd1 > nmatches) */
+/* 		totalsel2 += otherfreq2 * (otherfreq1 + unmatchfreq1) / */
+/* 			(nd1 - nmatches); */
 
 	s = Min(totalsel1, totalsel2);
 
diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h
index f156fda555e..b1f30dfe2ee 100644
--- a/src/include/statistics/extended_stats_internal.h
+++ b/src/include/statistics/extended_stats_internal.h
@@ -15,7 +15,7 @@
 #define EXTENDED_STATS_INTERNAL_H
 
 #include "statistics/statistics.h"
-#include "utils/lsyscache.h"		/* XXX is this needed? */
+#include "utils/lsyscache.h"	/* XXX is this needed? */
 #include "utils/sortsupport.h"
 
 typedef struct
diff --git a/src/include/statistics/statistics.h b/src/include/statistics/statistics.h
index 60b222028d8..48ab718304e 100644
--- a/src/include/statistics/statistics.h
+++ b/src/include/statistics/statistics.h
@@ -128,7 +128,7 @@ extern StatisticExtInfo *choose_best_statistics(List *stats, char requiredkind,
 extern HeapTuple statext_expressions_load(Oid stxoid, bool inh, int idx);
 
 extern StatisticExtInfo *statext_find_matching_mcv(PlannerInfo *root, RelOptInfo *rel,
-										   Bitmapset *attnums, List *exprs);
+												   Bitmapset *attnums, List *exprs);
 
 extern bool statext_try_join_estimates(PlannerInfo *root, List *clauses, int varRelid,
 									   JoinType jointype, SpecialJoinInfo *sjinfo,
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 61ad417cde6..f7ba7901a27 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1289,6 +1289,7 @@ JoinCostWorkspace
 JoinDomain
 JoinExpr
 JoinHashEntry
+JoinPairInfo
 JoinPath
 JoinPathExtraData
 JoinState
-- 
2.45.2

