0001-fix-anycompatiblemultirange.patch

application/octet-stream

Filename: 0001-fix-anycompatiblemultirange.patch
Type: application/octet-stream
Part: 0
Message: Re: BUG #17066: Cache lookup failed when null (unknown) is passed as anycompatiblemultirange

Patch

Format: format-patch
Series: patch 0001
Subject: fix-anycompatiblemultirange
File+
src/backend/parser/parse_coerce.c 18 0
src/test/regress/expected/polymorphism.out 1 1
From 51c2a77edcadfdb9dad9ca30a23c70d4d9d766e0 Mon Sep 17 00:00:00 2001
From: Neil <carpenter.nail.cz@gmail.com>
Date: Tue, 22 Jun 2021 15:45:50 +0800
Subject: [PATCH] fix-anycompatiblemultirange

---
 src/backend/parser/parse_coerce.c          | 18 ++++++++++++++++++
 src/test/regress/expected/polymorphism.out |  2 +-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c
index 7e963b8895..2aa7f616f2 100644
--- a/src/backend/parser/parse_coerce.c
+++ b/src/backend/parser/parse_coerce.c
@@ -2053,6 +2053,7 @@ enforce_generic_type_consistency(const Oid *actual_arg_types,
 	bool		have_anycompatible_nonarray = (rettype == ANYCOMPATIBLENONARRAYOID);
 	bool		have_anycompatible_array = (rettype == ANYCOMPATIBLEARRAYOID);
 	bool		have_anycompatible_range = (rettype == ANYCOMPATIBLERANGEOID);
+	bool		have_anycompatible_multirange = (rettype == ANYCOMPATIBLEMULTIRANGEOID);
 	int			n_poly_args = 0;	/* this counts all family-1 arguments */
 	int			n_anycompatible_args = 0;	/* this counts only non-unknowns */
 	Oid			anycompatible_actual_types[FUNC_MAX_ARGS];
@@ -2223,6 +2224,7 @@ enforce_generic_type_consistency(const Oid *actual_arg_types,
 		else if (decl_type == ANYCOMPATIBLEMULTIRANGEOID)
 		{
 			have_poly_anycompatible = true;
+			have_anycompatible_multirange = true;
 			if (actual_type == UNKNOWNOID)
 				continue;
 			if (allow_poly && decl_type == actual_type)
@@ -2494,6 +2496,16 @@ enforce_generic_type_consistency(const Oid *actual_arg_types,
 									format_type_be(anycompatible_typeid))));
 			}
 
+			if (have_anycompatible_multirange)
+			{
+				/* we can't infer a range type from the others */
+				if (!OidIsValid(anycompatible_multirange_typeid))
+					ereport(ERROR,
+							(errcode(ERRCODE_DATATYPE_MISMATCH),
+							 errmsg("could not determine polymorphic type %s because input has type %s",
+									"anycompatiblemultirange", "unknown")));
+			}
+
 			if (have_anycompatible_nonarray)
 			{
 				/*
@@ -2531,6 +2543,12 @@ enforce_generic_type_consistency(const Oid *actual_arg_types,
 							(errcode(ERRCODE_DATATYPE_MISMATCH),
 							 errmsg("could not determine polymorphic type %s because input has type %s",
 									"anycompatiblerange", "unknown")));
+
+				if (have_anycompatible_multirange)
+					ereport(ERROR,
+							(errcode(ERRCODE_DATATYPE_MISMATCH),
+							 errmsg("could not determine polymorphic type %s because input has type %s",
+									"anycompatiblemultirange", "unknown")));
 			}
 		}
 
diff --git a/src/test/regress/expected/polymorphism.out b/src/test/regress/expected/polymorphism.out
index 772345584f..9f158f7786 100644
--- a/src/test/regress/expected/polymorphism.out
+++ b/src/test/regress/expected/polymorphism.out
@@ -1914,7 +1914,7 @@ LINE 1: select x, pg_typeof(x) from anyctest(11.2, multirange(int4ra...
                                     ^
 HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
 select x, pg_typeof(x) from anyctest(11.2, '{[4,7)}') x;  -- fail
-ERROR:  could not identify anycompatiblemultirange type
+ERROR:  could not determine polymorphic type anycompatiblemultirange because input has type unknown
 drop function anyctest(anycompatible, anycompatiblemultirange);
 create function anyctest(anycompatiblemultirange, anycompatiblemultirange)
 returns anycompatible as $$
-- 
2.30.1 (Apple Git-130)