Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4dbcb3f

Browse files
committed
Restructure polymorphic-type resolution in funcapi.c.
resolve_polymorphic_tupdesc() and resolve_polymorphic_argtypes() failed tocover the case of having to resolve anyarray given only an anyrange input.The bug was masked if anyelement was also used (as either input oroutput), which probably helps account for our not having noticed.While looking at this I noticed that resolve_generic_type() would producethe wrong answer if asked to make that same resolution. ISTM thatresolve_generic_type() is confusingly defined and overly complex, sorather than fix it, let's just make funcapi.c do the specific lookupsit requires for itself.With this change, resolve_generic_type() is not used anywhere, so removeit in HEAD. In the back branches, leave it alone (complete with bug)just in case any external code is using it.While we're here, make some other refactoring adjustments in funcapi.cwith an eye to upcoming future expansion of the set of polymorphic types:* Simplify quick-exit tests by adding an overall have_polymorphic_resultflag. This is about a wash now but will be a win when there are moreflags.* Reduce duplication of code between resolve_polymorphic_tupdesc() andresolve_polymorphic_argtypes().* Don't bother to validate correct matching of anynonarray or anyenum;the parser should have done that, and even if it didn't, just doing"return false" here would lead to a very confusing, off-point errormessage. (Really, "return false" in these two functions should onlyoccur if the call_expr isn't supplied or we can't obtain data typeinfo from it.)* For the same reason, throw an elog rather than "return false" ifwe fail to resolve a polymorphic type.The bug's been there since we added anyrange, so back-patch toall supported branches.Discussion:https://postgr.es/m/6093.1584202130@sss.pgh.pa.us
1 parente83daa7 commit4dbcb3f

File tree

5 files changed

+216
-251
lines changed

5 files changed

+216
-251
lines changed

‎src/backend/parser/parse_coerce.c

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
#include"postgres.h"
1616

17-
#include"access/htup_details.h"
1817
#include"catalog/pg_cast.h"
1918
#include"catalog/pg_class.h"
2019
#include"catalog/pg_inherits.h"
@@ -26,7 +25,6 @@
2625
#include"parser/parse_relation.h"
2726
#include"parser/parse_type.h"
2827
#include"utils/builtins.h"
29-
#include"utils/datum.h"
3028
#include"utils/lsyscache.h"
3129
#include"utils/syscache.h"
3230
#include"utils/typcache.h"
@@ -1968,108 +1966,6 @@ enforce_generic_type_consistency(const Oid *actual_arg_types,
19681966
returnrettype;
19691967
}
19701968

1971-
/*
1972-
* resolve_generic_type()
1973-
*Deduce an individual actual datatype on the assumption that
1974-
*the rules for polymorphic types are being followed.
1975-
*
1976-
* declared_type is the declared datatype we want to resolve.
1977-
* context_actual_type is the actual input datatype to some argument
1978-
* that has declared datatype context_declared_type.
1979-
*
1980-
* If declared_type isn't polymorphic, we just return it. Otherwise,
1981-
* context_declared_type must be polymorphic, and we deduce the correct
1982-
* return type based on the relationship of the two polymorphic types.
1983-
*/
1984-
Oid
1985-
resolve_generic_type(Oiddeclared_type,
1986-
Oidcontext_actual_type,
1987-
Oidcontext_declared_type)
1988-
{
1989-
if (declared_type==ANYARRAYOID)
1990-
{
1991-
if (context_declared_type==ANYARRAYOID)
1992-
{
1993-
/*
1994-
* Use actual type, but it must be an array; or if it's a domain
1995-
* over array, use the base array type.
1996-
*/
1997-
Oidcontext_base_type=getBaseType(context_actual_type);
1998-
Oidarray_typelem=get_element_type(context_base_type);
1999-
2000-
if (!OidIsValid(array_typelem))
2001-
ereport(ERROR,
2002-
(errcode(ERRCODE_DATATYPE_MISMATCH),
2003-
errmsg("argument declared %s is not an array but type %s",
2004-
"anyarray",format_type_be(context_base_type))));
2005-
returncontext_base_type;
2006-
}
2007-
elseif (context_declared_type==ANYELEMENTOID||
2008-
context_declared_type==ANYNONARRAYOID||
2009-
context_declared_type==ANYENUMOID||
2010-
context_declared_type==ANYRANGEOID)
2011-
{
2012-
/* Use the array type corresponding to actual type */
2013-
Oidarray_typeid=get_array_type(context_actual_type);
2014-
2015-
if (!OidIsValid(array_typeid))
2016-
ereport(ERROR,
2017-
(errcode(ERRCODE_UNDEFINED_OBJECT),
2018-
errmsg("could not find array type for data type %s",
2019-
format_type_be(context_actual_type))));
2020-
returnarray_typeid;
2021-
}
2022-
}
2023-
elseif (declared_type==ANYELEMENTOID||
2024-
declared_type==ANYNONARRAYOID||
2025-
declared_type==ANYENUMOID||
2026-
declared_type==ANYRANGEOID)
2027-
{
2028-
if (context_declared_type==ANYARRAYOID)
2029-
{
2030-
/* Use the element type corresponding to actual type */
2031-
Oidcontext_base_type=getBaseType(context_actual_type);
2032-
Oidarray_typelem=get_element_type(context_base_type);
2033-
2034-
if (!OidIsValid(array_typelem))
2035-
ereport(ERROR,
2036-
(errcode(ERRCODE_DATATYPE_MISMATCH),
2037-
errmsg("argument declared %s is not an array but type %s",
2038-
"anyarray",format_type_be(context_base_type))));
2039-
returnarray_typelem;
2040-
}
2041-
elseif (context_declared_type==ANYRANGEOID)
2042-
{
2043-
/* Use the element type corresponding to actual type */
2044-
Oidcontext_base_type=getBaseType(context_actual_type);
2045-
Oidrange_typelem=get_range_subtype(context_base_type);
2046-
2047-
if (!OidIsValid(range_typelem))
2048-
ereport(ERROR,
2049-
(errcode(ERRCODE_DATATYPE_MISMATCH),
2050-
errmsg("argument declared %s is not a range type but type %s",
2051-
"anyrange",format_type_be(context_base_type))));
2052-
returnrange_typelem;
2053-
}
2054-
elseif (context_declared_type==ANYELEMENTOID||
2055-
context_declared_type==ANYNONARRAYOID||
2056-
context_declared_type==ANYENUMOID)
2057-
{
2058-
/* Use the actual type; it doesn't matter if array or not */
2059-
returncontext_actual_type;
2060-
}
2061-
}
2062-
else
2063-
{
2064-
/* declared_type isn't polymorphic, so return it as-is */
2065-
returndeclared_type;
2066-
}
2067-
/* If we get here, declared_type is polymorphic and context isn't */
2068-
/* NB: this is a calling-code logic error, not a user error */
2069-
elog(ERROR,"could not determine polymorphic type because context isn't polymorphic");
2070-
returnInvalidOid;/* keep compiler quiet */
2071-
}
2072-
20731969

20741970
/* TypeCategory()
20751971
*Assign a category to the specified type OID.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp