hash_mcv_in_logging.patch

text/x-patch

Filename: hash_mcv_in_logging.patch
Type: text/x-patch
Part: 0
Message: Re: Hash-based MCV matching for large IN-lists

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: unified
File+
src/backend/utils/adt/selfuncs.c 9 3
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index f6d99773b70..f4c7fb605ce 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -1966,7 +1966,7 @@ scalararraysel(PlannerInfo *root,
 	TypeCacheEntry *typentry;
 	RegProcedure oprsel;
 	FmgrInfo	oprselproc;
-	Selectivity s1;
+	Selectivity s1, hash_selec = -1.0;
 	Selectivity s1disjoint;
 
 	/* First, deconstruct the expression */
@@ -2106,7 +2106,7 @@ scalararraysel(PlannerInfo *root,
 				ReleaseVariableStats(vardata);
 
 				if (s1 >= 0.0)
-					return s1;
+					hash_selec = s1;
 			}
 		}
 
@@ -2173,6 +2173,9 @@ scalararraysel(PlannerInfo *root,
 		if ((useOr ? isEquality : isInequality) &&
 			s1disjoint >= 0.0 && s1disjoint <= 1.0)
 			s1 = s1disjoint;
+
+		if (hash_selec >= 0 && fabs(s1 - hash_selec) > 0.000000000001)
+			elog(LOG, "nested_loop selectivity = %f, hash_loop selectivity = %f", s1, hash_selec);
 	}
 	else if (rightop && IsA(rightop, ArrayExpr) &&
 			 !((ArrayExpr *) rightop)->multidims)
@@ -2251,7 +2254,7 @@ scalararraysel(PlannerInfo *root,
 				ReleaseVariableStats(vardata);
 
 				if (s1 >= 0.0)
-					return s1;
+					hash_selec = s1;
 			}
 		}
 
@@ -2310,6 +2313,9 @@ scalararraysel(PlannerInfo *root,
 		if ((useOr ? isEquality : isInequality) &&
 			s1disjoint >= 0.0 && s1disjoint <= 1.0)
 			s1 = s1disjoint;
+
+		if (hash_selec >= 0 && fabs(s1 - hash_selec) > 0.000000000001)
+			elog(LOG, "nested_loop selectivity = %f, hash_loop selectivity = %f", s1, hash_selec);
 	}
 	else
 	{