* array_cmp() * Internal comparison function for arrays. * * Returns -1, 0 or 1 */
| 3873 | * Returns -1, 0 or 1 |
| 3874 | */ |
| 3875 | static int |
| 3876 | array_cmp(FunctionCallInfo fcinfo) |
| 3877 | { |
| 3878 | LOCAL_FCINFO(locfcinfo, 2); |
| 3879 | AnyArrayType *array1 = PG_GETARG_ANY_ARRAY_P(0); |
| 3880 | AnyArrayType *array2 = PG_GETARG_ANY_ARRAY_P(1); |
| 3881 | Oid collation = PG_GET_COLLATION(); |
| 3882 | int ndims1 = AARR_NDIM(array1); |
| 3883 | int ndims2 = AARR_NDIM(array2); |
| 3884 | int *dims1 = AARR_DIMS(array1); |
| 3885 | int *dims2 = AARR_DIMS(array2); |
| 3886 | int nitems1 = ArrayGetNItems(ndims1, dims1); |
| 3887 | int nitems2 = ArrayGetNItems(ndims2, dims2); |
| 3888 | Oid element_type = AARR_ELEMTYPE(array1); |
| 3889 | int result = 0; |
| 3890 | TypeCacheEntry *typentry; |
| 3891 | int typlen; |
| 3892 | bool typbyval; |
| 3893 | char typalign; |
| 3894 | int min_nitems; |
| 3895 | array_iter it1; |
| 3896 | array_iter it2; |
| 3897 | int i; |
| 3898 | |
| 3899 | if (element_type != AARR_ELEMTYPE(array2)) |
| 3900 | ereport(ERROR, |
| 3901 | (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 3902 | errmsg("cannot compare arrays of different element types"))); |
| 3903 | |
| 3904 | /* |
| 3905 | * We arrange to look up the comparison function only once per series of |
| 3906 | * calls, assuming the element type doesn't change underneath us. The |
| 3907 | * typcache is used so that we have no memory leakage when being used as |
| 3908 | * an index support function. |
| 3909 | */ |
| 3910 | typentry = (TypeCacheEntry *) fcinfo->flinfo->fn_extra; |
| 3911 | if (typentry == NULL || |
| 3912 | typentry->type_id != element_type) |
| 3913 | { |
| 3914 | typentry = lookup_type_cache(element_type, |
| 3915 | TYPECACHE_CMP_PROC_FINFO); |
| 3916 | if (!OidIsValid(typentry->cmp_proc_finfo.fn_oid)) |
| 3917 | ereport(ERROR, |
| 3918 | (errcode(ERRCODE_UNDEFINED_FUNCTION), |
| 3919 | errmsg("could not identify a comparison function for type %s", |
| 3920 | format_type_be(element_type)))); |
| 3921 | fcinfo->flinfo->fn_extra = (void *) typentry; |
| 3922 | } |
| 3923 | typlen = typentry->typlen; |
| 3924 | typbyval = typentry->typbyval; |
| 3925 | typalign = typentry->typalign; |
| 3926 | |
| 3927 | /* |
| 3928 | * apply the operator to each pair of array elements. |
| 3929 | */ |
| 3930 | InitFunctionCallInfoData(*locfcinfo, &typentry->cmp_proc_finfo, 2, |
| 3931 | collation, NULL, NULL); |
| 3932 |
no test coverage detected