From d8f629c51f70f936fead1d7a6d1b6d485e0f8a35 Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Sat, 25 Sep 2021 18:40:23 -0500
Subject: [PATCH v2 12/12] fix ext stats exprs references to indexes

Expressions on statistics were based on expressional indexes, but a few places
were copied and pasted without since being cleaned up.

Since a4d75c86bf15220df22de0a92c819ecef9db3849

Backpatch to v14?
---
 src/backend/commands/tablecmds.c   | 4 ++--
 src/backend/parser/parse_utilcmd.c | 2 +-
 src/backend/utils/adt/selfuncs.c   | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 9d2ab31e7e..99f77c36bf 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -12585,13 +12585,13 @@ RememberStatisticsForRebuilding(Oid stxoid, AlteredTableInfo *tab)
 	/*
 	 * This de-duplication check is critical for two independent reasons: we
 	 * mustn't try to recreate the same statistics object twice, and if the
-	 * statistics depends on more than one column whose type is to be altered,
+	 * statistics object depends on more than one column whose type is to be altered,
 	 * we must capture its definition string before applying any of the type
 	 * changes. ruleutils.c will get confused if we ask again later.
 	 */
 	if (!list_member_oid(tab->changedStatisticsOids, stxoid))
 	{
-		/* OK, capture the index's existing definition string */
+		/* OK, capture the statistic object's existing definition string */
 		char	   *defstring = pg_get_statisticsobjdef_string(stxoid);
 
 		tab->changedStatisticsOids = lappend_oid(tab->changedStatisticsOids,
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 1d3ee53244..49f617d2fd 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -2948,7 +2948,7 @@ transformStatsStmt(Oid relid, CreateStatsStmt *stmt, const char *queryString)
 	if (list_length(pstate->p_rtable) != 1)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
-				 errmsg("statistics expressions can refer only to the table being indexed")));
+				 errmsg("statistics expressions can refer only to the table being referenced")));
 
 	free_parsestate(pstate);
 
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 65ab651eb5..abcb628a39 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -5252,7 +5252,7 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
 				{
 					HeapTuple	t = statext_expressions_load(info->statOid, pos);
 
-					/* Get index's table for permission check */
+					/* Get statistic object's table for permission check */
 					RangeTblEntry *rte;
 					Oid			userid;
 
-- 
2.17.0

