0001-Replace-run-time-error-check-with-assertion.patch

text/plain

Filename: 0001-Replace-run-time-error-check-with-assertion.patch
Type: text/plain
Part: 0
Message: Replace run-time error check with assertion

Patch

Format: format-patch
Series: patch 0001
Subject: Replace run-time error check with assertion
File+
src/backend/commands/statscmds.c 5 16
From a30697758c475db2f4333cedbe6aad1e1acd0ee8 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Tue, 25 May 2021 11:27:04 +0200
Subject: [PATCH] Replace run-time error check with assertion

The error message was checking that the structures returned from the
parser matched expectations.  That's something we usually use
assertions for, not a full user-facing error message.
---
 src/backend/commands/statscmds.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/src/backend/commands/statscmds.c b/src/backend/commands/statscmds.c
index acae19176c..b244a0fbd7 100644
--- a/src/backend/commands/statscmds.c
+++ b/src/backend/commands/statscmds.c
@@ -220,26 +220,14 @@ CreateStatistics(CreateStatsStmt *stmt)
 	 */
 	foreach(cell, stmt->exprs)
 	{
-		Node	   *expr = (Node *) lfirst(cell);
-		StatsElem  *selem;
-		HeapTuple	atttuple;
-		Form_pg_attribute attForm;
-		TypeCacheEntry *type;
-
-		/*
-		 * We should not get anything else than StatsElem, given the grammar.
-		 * But let's keep it as a safety.
-		 */
-		if (!IsA(expr, StatsElem))
-			ereport(ERROR,
-					(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-					 errmsg("only simple column references and expressions are allowed in CREATE STATISTICS")));
-
-		selem = (StatsElem *) expr;
+		StatsElem  *selem = lfirst_node(StatsElem, cell);
 
 		if (selem->name)		/* column reference */
 		{
 			char	   *attname;
+			HeapTuple	atttuple;
+			Form_pg_attribute attForm;
+			TypeCacheEntry *type;
 
 			attname = selem->name;
 
@@ -273,6 +261,7 @@ CreateStatistics(CreateStatsStmt *stmt)
 		{
 			Node	   *expr = selem->expr;
 			Oid			atttype;
+			TypeCacheEntry *type;
 
 			Assert(expr != NULL);
 
-- 
2.31.1