Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 42ddad9

Browse files
tglsfdcCommitfest Bot
authored and
Commitfest Bot
committed
Add pg_type.typarray to the typcache's collection of fields.
This was not done in bc8036f which added the typarray column, but I think that was simply an oversight. We generally are willing to cache simple columns of pg_type in the typcache. Add it now to simplify array_sort(). Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/CAEG8a3J41a4dpw_-F94fF-JPRXYxw-GfsgoGotKcjs9LVfEEvw@mail.gmail.com
1 parent a849629 commit 42ddad9

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

src/backend/utils/adt/array_userfuncs.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,8 +1930,7 @@ array_sort_internal(ArrayType *array, bool descending, bool nulls_first,
19301930
cache_info->array_meta.typalign = typentry->typalign;
19311931
cache_info->elem_lt_opr = typentry->lt_opr;
19321932
cache_info->elem_gt_opr = typentry->gt_opr;
1933-
/* For some reason the typcache doesn't track array type */
1934-
cache_info->array_type = InvalidOid;
1933+
cache_info->array_type = typentry->typarray;
19351934
}
19361935

19371936
/* Identify the sort operator to use */
@@ -1944,16 +1943,12 @@ array_sort_internal(ArrayType *array, bool descending, bool nulls_first,
19441943
else
19451944
{
19461945
/* Otherwise we're sorting arrays */
1947-
if (!OidIsValid(cache_info->array_type))
1948-
{
1949-
cache_info->array_type = get_array_type(elmtyp);
1950-
if (!OidIsValid(cache_info->array_type))
1951-
ereport(ERROR,
1952-
(errcode(ERRCODE_UNDEFINED_OBJECT),
1953-
errmsg("could not find array type for data type %s",
1954-
format_type_be(elmtyp))));
1955-
}
19561946
sort_typ = cache_info->array_type;
1947+
if (!OidIsValid(sort_typ))
1948+
ereport(ERROR,
1949+
(errcode(ERRCODE_UNDEFINED_OBJECT),
1950+
errmsg("could not find array type for data type %s",
1951+
format_type_be(elmtyp))));
19571952
/* We know what operators to use for arrays */
19581953
sort_opr = (descending ? ARRAY_GT_OP : ARRAY_LT_OP);
19591954
}

src/backend/utils/cache/typcache.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ lookup_type_cache(Oid type_id, int flags)
499499
typentry->typrelid = typtup->typrelid;
500500
typentry->typsubscript = typtup->typsubscript;
501501
typentry->typelem = typtup->typelem;
502+
typentry->typarray = typtup->typarray;
502503
typentry->typcollation = typtup->typcollation;
503504
typentry->flags |= TCFLAGS_HAVE_PG_TYPE_DATA;
504505

@@ -544,6 +545,7 @@ lookup_type_cache(Oid type_id, int flags)
544545
typentry->typrelid = typtup->typrelid;
545546
typentry->typsubscript = typtup->typsubscript;
546547
typentry->typelem = typtup->typelem;
548+
typentry->typarray = typtup->typarray;
547549
typentry->typcollation = typtup->typcollation;
548550
typentry->flags |= TCFLAGS_HAVE_PG_TYPE_DATA;
549551

src/include/utils/typcache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ typedef struct TypeCacheEntry
4444
Oid typrelid;
4545
Oid typsubscript;
4646
Oid typelem;
47+
Oid typarray;
4748
Oid typcollation;
4849

4950
/*

0 commit comments

Comments
 (0)