4 #include "access/genam.h"
5 #include "access/heapam.h"
6 #include "access/htup_details.h"
7 #include "access/nbtree.h"
8 #include "catalog/indexing.h"
9 #include "catalog/pg_am.h"
10 #include "catalog/pg_amproc.h"
11 #include "catalog/pg_cast.h"
12 #include "catalog/pg_opclass.h"
13 #include "catalog/pg_type.h"
14 #include "executor/spi.h"
15 #include "utils/catcache.h"
16 #include "utils/fmgroids.h"
17 #include "utils/lsyscache.h"
18 #include "utils/memutils.h"
19 #include "utils/tqual.h"
20 #include "utils/syscache.h"
21 #include "utils/typcache.h"
25 #if (PG_VERSION_NUM >= 90400)
28 #define SNAPSHOT SnapshotNow
32 getDefaultOpclass(Oid amoid, Oid typid)
38 Oid opclassOid = InvalidOid;
40 heapRel = heap_open(OperatorClassRelationId, AccessShareLock);
43 Anum_pg_opclass_opcmethod,
44 BTEqualStrategyNumber, F_OIDEQ,
45 ObjectIdGetDatum(amoid));
47 scan = systable_beginscan(heapRel,
48 OpclassAmNameNspIndexId, true,
51 while (HeapTupleIsValid((tuple = systable_getnext(scan))))
53 Form_pg_opclass opclass = (Form_pg_opclass)GETSTRUCT(tuple);
55 if ( opclass->opcintype == typid && opclass->opcdefault )
57 if ( OidIsValid(opclassOid) )
58 elog(ERROR, "Ambiguous opclass for type %u (access method %u)", typid, amoid);
59 opclassOid = HeapTupleGetOid(tuple);
63 systable_endscan(scan);
64 heap_close(heapRel, AccessShareLock);
70 getAMProc(Oid amoid, Oid typid)
72 Oid opclassOid = getDefaultOpclass(amoid, typid);
73 Oid procOid = InvalidOid;
80 if ( !OidIsValid(opclassOid) )
82 typid = getBaseType(typid);
83 opclassOid = getDefaultOpclass(amoid, typid);
86 if ( !OidIsValid(opclassOid) )
92 * Search binary-coercible type
94 catlist = SearchSysCacheList(CASTSOURCETARGET, 1,
95 ObjectIdGetDatum(typid),
98 for (i = 0; i < catlist->n_members; i++)
100 HeapTuple tuple = &catlist->members[i]->tuple;
101 Form_pg_cast castForm = (Form_pg_cast)GETSTRUCT(tuple);
103 if ( castForm->castfunc == InvalidOid && castForm->castcontext == COERCION_CODE_IMPLICIT )
105 typid = castForm->casttarget;
106 opclassOid = getDefaultOpclass(amoid, typid);
107 if( OidIsValid(opclassOid) )
112 ReleaseSysCacheList(catlist);
115 if ( !OidIsValid(opclassOid) )
118 opfamilyOid = get_opclass_family(opclassOid);
120 heapRel = heap_open(AccessMethodProcedureRelationId, AccessShareLock);
121 ScanKeyInit(&skey[0],
122 Anum_pg_amproc_amprocfamily,
123 BTEqualStrategyNumber, F_OIDEQ,
124 ObjectIdGetDatum(opfamilyOid));
125 ScanKeyInit(&skey[1],
126 Anum_pg_amproc_amproclefttype,
127 BTEqualStrategyNumber, F_OIDEQ,
128 ObjectIdGetDatum(typid));
129 ScanKeyInit(&skey[2],
130 Anum_pg_amproc_amprocrighttype,
131 BTEqualStrategyNumber, F_OIDEQ,
132 ObjectIdGetDatum(typid));
133 #if PG_VERSION_NUM >= 90200
134 ScanKeyInit(&skey[3],
135 Anum_pg_amproc_amprocnum,
136 BTEqualStrategyNumber, F_OIDEQ,
137 Int32GetDatum(BTORDER_PROC));
140 scan = systable_beginscan(heapRel, AccessMethodProcedureIndexId, true,
142 #if PG_VERSION_NUM >= 90200
148 while (HeapTupleIsValid(tuple = systable_getnext(scan)))
150 Form_pg_amproc amprocform = (Form_pg_amproc) GETSTRUCT(tuple);
156 if ( OidIsValid(procOid) )
157 elog(ERROR,"Ambiguous support function for type %u (opclass %u)", typid, opfamilyOid);
158 procOid = amprocform->amproc;
161 elog(ERROR,"Unsupported access method");
165 systable_endscan(scan);
166 heap_close(heapRel, AccessShareLock);
171 static ProcTypeInfo *cacheProcs = NULL;
172 static int nCacheProcs = 0;
177 ProcTypeInfo info = malloc(sizeof(ProcTypeInfoData));
180 elog(ERROR, "Can't allocate %u memory", (uint32)sizeof(ProcTypeInfoData));
183 info->typtype = get_typtype(typid);
185 if (info->typtype == 'c')
189 MemoryContext oldcontext;
191 tupdesc = lookup_rowtype_tupdesc(typid, -1);
193 if (tupdesc->natts != 2)
194 elog(ERROR,"Composite type has wrong number of fields");
195 if (tupdesc->attrs[1]->atttypid != FLOAT4OID)
196 elog(ERROR,"Second field of composite type is not float4");
198 oldcontext = MemoryContextSwitchTo(TopMemoryContext);
199 info->tupDesc = CreateTupleDescCopyConstr(tupdesc);
200 MemoryContextSwitchTo(oldcontext);
202 ReleaseTupleDesc(tupdesc);
204 info->cmpFuncOid = getAMProc(BTREE_AM_OID, info->tupDesc->attrs[0]->atttypid);
205 info->hashFuncOid = getAMProc(HASH_AM_OID, info->tupDesc->attrs[0]->atttypid);
209 info->tupDesc = NULL;
212 info->cmpFuncOid = getAMProc(BTREE_AM_OID, typid);
213 info->hashFuncOid = getAMProc(HASH_AM_OID, typid);
216 get_typlenbyvalalign(typid, &info->typlen, &info->typbyval, &info->typalign);
217 info->hashFuncInited = info->cmpFuncInited = false;
224 getFmgrInfoCmp(ProcTypeInfo info)
226 if ( info->cmpFuncInited == false )
228 if ( !OidIsValid(info->cmpFuncOid) )
229 elog(ERROR, "Could not find cmp function for type %u", info->typid);
231 fmgr_info_cxt( info->cmpFuncOid, &info->cmpFunc, TopMemoryContext );
232 info->cmpFuncInited = true;
237 getFmgrInfoHash(ProcTypeInfo info)
239 if ( info->hashFuncInited == false )
241 if ( !OidIsValid(info->hashFuncOid) )
242 elog(ERROR, "Could not find hash function for type %u", info->typid);
244 fmgr_info_cxt( info->hashFuncOid, &info->hashFunc, TopMemoryContext );
245 info->hashFuncInited = true;
250 cmpProcTypeInfo(const void *a, const void *b)
252 ProcTypeInfo av = *(ProcTypeInfo*)a;
253 ProcTypeInfo bv = *(ProcTypeInfo*)b;
255 Assert( av->typid != bv->typid );
257 return ( av->typid > bv->typid ) ? 1 : -1;
263 ProcTypeInfo info = NULL;
265 if ( nCacheProcs == 1 )
267 if ( cacheProcs[0]->typid == typid )
269 /*cacheProcs[0]->hashFuncInited = cacheProcs[0]->cmpFuncInited = false;*/
270 return cacheProcs[0];
273 else if ( nCacheProcs > 1 )
275 ProcTypeInfo *StopMiddle;
276 ProcTypeInfo *StopLow = cacheProcs,
277 *StopHigh = cacheProcs + nCacheProcs;
279 while (StopLow < StopHigh) {
280 StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
283 if ( info->typid == typid )
285 /* info->hashFuncInited = info->cmpFuncInited = false; */
288 else if ( info->typid < typid )
289 StopLow = StopMiddle + 1;
291 StopHigh = StopMiddle;
297 info = fillProcs(typid);
298 if ( nCacheProcs == 0 )
300 cacheProcs = malloc(sizeof(ProcTypeInfo));
303 elog(ERROR, "Can't allocate %u memory", (uint32)sizeof(ProcTypeInfo));
307 cacheProcs[0] = info;
312 ProcTypeInfo *cacheProcsTmp = realloc(cacheProcs, (nCacheProcs+1) * sizeof(ProcTypeInfo));
315 elog(ERROR, "Can't allocate %u memory", (uint32)sizeof(ProcTypeInfo) * (nCacheProcs+1));
318 cacheProcs = cacheProcsTmp;
319 cacheProcs[ nCacheProcs ] = info;
321 qsort(cacheProcs, nCacheProcs, sizeof(ProcTypeInfo), cmpProcTypeInfo);
325 /* info->hashFuncInited = info->cmpFuncInited = false; */
331 * WARNING. Array2SimpleArray* doesn't copy Datum!
334 Array2SimpleArray(ProcTypeInfo info, ArrayType *a)
336 SimpleArray *s = palloc(sizeof(SimpleArray));
341 info = findProcs(ARR_ELEMTYPE(a));
347 deconstruct_array(a, info->typid,
348 info->typlen, info->typbyval, info->typalign,
349 &s->elems, NULL, &s->nelems);
355 deconstructCompositeType(ProcTypeInfo info, Datum in, double *weight)
357 HeapTupleHeader rec = DatumGetHeapTupleHeader(in);
362 /* Build a temporary HeapTuple control structure */
363 tuple.t_len = HeapTupleHeaderGetDatumLength(rec);
364 ItemPointerSetInvalid(&(tuple.t_self));
365 tuple.t_tableOid = InvalidOid;
368 heap_deform_tuple(&tuple, info->tupDesc, values, nulls);
369 if (nulls[0] || nulls[1])
370 elog(ERROR, "Both fields in composite type could not be NULL");
373 *weight = DatumGetFloat4(values[1]);
378 cmpArrayElem(const void *a, const void *b, void *arg)
380 ProcTypeInfo info = (ProcTypeInfo)arg;
384 return DatumGetInt32( FCall2( &info->cmpFunc,
385 deconstructCompositeType(info, *(Datum*)a, NULL),
386 deconstructCompositeType(info, *(Datum*)b, NULL) ) );
388 return DatumGetInt32( FCall2( &info->cmpFunc,
389 *(Datum*)a, *(Datum*)b ) );
393 Array2SimpleArrayS(ProcTypeInfo info, ArrayType *a)
395 SimpleArray *s = Array2SimpleArray(info, a);
399 getFmgrInfoCmp(s->info);
401 qsort_arg(s->elems, s->nelems, sizeof(Datum), cmpArrayElem, s->info);
407 typedef struct cmpArrayElemData {
414 cmpArrayElemArg(const void *a, const void *b, void *arg)
416 cmpArrayElemData *data = (cmpArrayElemData*)arg;
419 if (data->info->tupDesc)
420 res = DatumGetInt32( FCall2( &data->info->cmpFunc,
421 deconstructCompositeType(data->info, *(Datum*)a, NULL),
422 deconstructCompositeType(data->info, *(Datum*)b, NULL) ) );
424 res = DatumGetInt32( FCall2( &data->info->cmpFunc,
425 *(Datum*)a, *(Datum*)b ) );
428 data->hasDuplicate = true;
434 * Uniquefy array and calculate TF. Although
435 * result doesn't depend on normalization, we
436 * normalize TF by length array to have possiblity
437 * to limit estimation for index support.
439 * Cache signals of needing of TF caclulation
443 Array2SimpleArrayU(ProcTypeInfo info, ArrayType *a, void *cache)
445 SimpleArray *s = Array2SimpleArray(info, a);
446 StatElem *stat = NULL;
448 if ( s->nelems > 0 && cache )
450 s->df = palloc(sizeof(double) * s->nelems);
451 s->df[0] = 1.0; /* init */
456 cmpArrayElemData data;
459 getFmgrInfoCmp(s->info);
461 data.hasDuplicate = false;
463 qsort_arg(s->elems, s->nelems, sizeof(Datum), cmpArrayElemArg, &data);
465 if ( data.hasDuplicate )
473 data = tmp = dr = s->elems;
475 while (tmp - data < num)
477 cmp = (tmp == dr) ? 0 : cmpArrayElem(tmp, dr, s->info);
482 s->df[ dr - data ] = 1.0;
487 s->df[ dr - data ] += 1.0;
492 s->nelems = dr + 1 - s->elems;
496 int tfm = getTFMethod();
498 for(i=0;i<s->nelems;i++)
500 stat = fingArrayStat(cache, s->info->typid, s->elems[i], stat);
506 s->df[i] = (1.0 + log( s->df[i] ));
508 s->df[i] *= stat->idf;
511 s->df[i] = stat->idf;
514 elog(ERROR,"Unknown TF method: %d", tfm);
519 s->df[i] = 0.0; /* unknown word */
526 for(i=0;i<s->nelems;i++)
528 stat = fingArrayStat(cache, s->info->typid, s->elems[i], stat);
530 s->df[i] = stat->idf;
536 else if (s->nelems > 0 && cache)
538 stat = fingArrayStat(cache, s->info->typid, s->elems[0], stat);
540 s->df[0] = stat->idf;
549 numOfIntersect(SimpleArray *a, SimpleArray *b)
553 Datum *aptr = a->elems,
555 ProcTypeInfo info = a->info;
557 Assert( a->info->typid == b->info->typid );
559 getFmgrInfoCmp(info);
561 while( aptr - a->elems < a->nelems && bptr - b->elems < b->nelems )
563 cmp = cmpArrayElem(aptr, bptr, info);
580 TFIDFSml(SimpleArray *a, SimpleArray *b)
583 Datum *aptr = a->elems,
585 ProcTypeInfo info = a->info;
587 double suma = 0.0, sumb = 0.0;
589 Assert( a->info->typid == b->info->typid );
593 getFmgrInfoCmp(info);
595 while( aptr - a->elems < a->nelems && bptr - b->elems < b->nelems )
597 cmp = cmpArrayElem(aptr, bptr, info);
600 suma += a->df[ aptr - a->elems ] * a->df[ aptr - a->elems ];
605 sumb += b->df[ bptr - b->elems ] * b->df[ bptr - b->elems ];
610 res += a->df[ aptr - a->elems ] * b->df[ bptr - b->elems ];
611 suma += a->df[ aptr - a->elems ] * a->df[ aptr - a->elems ];
612 sumb += b->df[ bptr - b->elems ] * b->df[ bptr - b->elems ];
619 * Compute last elements
621 while( aptr - a->elems < a->nelems )
623 suma += a->df[ aptr - a->elems ] * a->df[ aptr - a->elems ];
627 while( bptr - b->elems < b->nelems )
629 sumb += b->df[ bptr - b->elems ] * b->df[ bptr - b->elems ];
633 if ( suma > 0.0 && sumb > 0.0 )
634 res = res / sqrt( suma * sumb );
642 PG_FUNCTION_INFO_V1(arraysml);
643 Datum arraysml(PG_FUNCTION_ARGS);
645 arraysml(PG_FUNCTION_ARGS)
648 SimpleArray *sa, *sb;
650 fcinfo->flinfo->fn_extra = SearchArrayCache(
651 fcinfo->flinfo->fn_extra,
652 fcinfo->flinfo->fn_mcxt,
653 PG_GETARG_DATUM(0), &a, &sa, NULL);
654 fcinfo->flinfo->fn_extra = SearchArrayCache(
655 fcinfo->flinfo->fn_extra,
656 fcinfo->flinfo->fn_mcxt,
657 PG_GETARG_DATUM(1), &b, &sb, NULL);
659 if ( ARR_ELEMTYPE(a) != ARR_ELEMTYPE(b) )
660 elog(ERROR,"Arguments array are not the same type!");
662 if (ARRISVOID(a) || ARRISVOID(b))
663 PG_RETURN_FLOAT4(0.0);
668 PG_RETURN_FLOAT4( TFIDFSml(sa, sb) );
675 power = ((double)(sa->nelems)) * ((double)(sb->nelems));
676 cnt = numOfIntersect(sa, sb);
678 PG_RETURN_FLOAT4( ((double)cnt) / sqrt( power ) );
683 float4 res = (float4)numOfIntersect(sa, sb);
685 PG_RETURN_FLOAT4(res);
689 elog(ERROR,"Unsupported formula type of similarity");
692 PG_RETURN_FLOAT4(0.0); /* keep compiler quiet */
695 PG_FUNCTION_INFO_V1(arraysmlw);
696 Datum arraysmlw(PG_FUNCTION_ARGS);
698 arraysmlw(PG_FUNCTION_ARGS)
701 SimpleArray *sa, *sb;
702 bool useIntersect = PG_GETARG_BOOL(2);
703 double numerator = 0.0;
704 double denominatorA = 0.0,
711 fcinfo->flinfo->fn_extra = SearchArrayCache(
712 fcinfo->flinfo->fn_extra,
713 fcinfo->flinfo->fn_mcxt,
714 PG_GETARG_DATUM(0), &a, &sa, NULL);
715 fcinfo->flinfo->fn_extra = SearchArrayCache(
716 fcinfo->flinfo->fn_extra,
717 fcinfo->flinfo->fn_mcxt,
718 PG_GETARG_DATUM(1), &b, &sb, NULL);
720 if ( ARR_ELEMTYPE(a) != ARR_ELEMTYPE(b) )
721 elog(ERROR,"Arguments array are not the same type!");
723 if (ARRISVOID(a) || ARRISVOID(b))
724 PG_RETURN_FLOAT4(0.0);
727 if (info->tupDesc == NULL)
728 elog(ERROR, "Only weigthed (composite) types should be used");
729 getFmgrInfoCmp(info);
731 while(ai < sa->nelems && bi < sb->nelems)
733 Datum ad = deconstructCompositeType(info, sa->elems[ai], &tmpA),
734 bd = deconstructCompositeType(info, sb->elems[bi], &tmpB);
736 cmp = DatumGetInt32(FCall2(&info->cmpFunc, ad, bd));
739 if (useIntersect == false)
740 denominatorA += tmpA * tmpA;
742 } else if ( cmp > 0 ) {
743 if (useIntersect == false)
744 denominatorB += tmpB * tmpB;
747 denominatorA += tmpA * tmpA;
748 denominatorB += tmpB * tmpB;
749 numerator += tmpA * tmpB;
755 if (useIntersect == false) {
756 while(ai < sa->nelems) {
757 deconstructCompositeType(info, sa->elems[ai], &tmpA);
758 denominatorA += tmpA * tmpA;
762 while(bi < sb->nelems) {
763 deconstructCompositeType(info, sb->elems[bi], &tmpB);
764 denominatorB += tmpB * tmpB;
769 if (numerator != 0.0) {
770 numerator = numerator / sqrt( denominatorA * denominatorB );
773 PG_RETURN_FLOAT4(numerator);
776 PG_FUNCTION_INFO_V1(arraysml_op);
777 Datum arraysml_op(PG_FUNCTION_ARGS);
779 arraysml_op(PG_FUNCTION_ARGS)
782 SimpleArray *sa, *sb;
785 fcinfo->flinfo->fn_extra = SearchArrayCache(
786 fcinfo->flinfo->fn_extra,
787 fcinfo->flinfo->fn_mcxt,
788 PG_GETARG_DATUM(0), &a, &sa, NULL);
789 fcinfo->flinfo->fn_extra = SearchArrayCache(
790 fcinfo->flinfo->fn_extra,
791 fcinfo->flinfo->fn_mcxt,
792 PG_GETARG_DATUM(1), &b, &sb, NULL);
794 if ( ARR_ELEMTYPE(a) != ARR_ELEMTYPE(b) )
795 elog(ERROR,"Arguments array are not the same type!");
797 if (ARRISVOID(a) || ARRISVOID(b))
798 PG_RETURN_BOOL(false);
803 power = TFIDFSml(sa, sb);
809 power = sqrt( ((double)(sa->nelems)) * ((double)(sb->nelems)) );
811 if ( ((double)Min(sa->nelems, sb->nelems)) / power < GetSmlarLimit() )
812 PG_RETURN_BOOL(false);
814 cnt = numOfIntersect(sa, sb);
815 power = ((double)cnt) / power;
819 power = (double)numOfIntersect(sa, sb);
822 elog(ERROR,"Unsupported formula type of similarity");
825 PG_RETURN_BOOL(power >= GetSmlarLimit());
829 static char cachedFormula[QBSIZE];
830 static int cachedLen = 0;
831 static void *cachedPlan = NULL;
833 PG_FUNCTION_INFO_V1(arraysml_func);
834 Datum arraysml_func(PG_FUNCTION_ARGS);
836 arraysml_func(PG_FUNCTION_ARGS)
839 SimpleArray *sa, *sb;
841 float4 result = -1.0;
842 Oid arg[] = {INT4OID, INT4OID, INT4OID};
847 text *formula = PG_GETARG_TEXT_P(2);
849 fcinfo->flinfo->fn_extra = SearchArrayCache(
850 fcinfo->flinfo->fn_extra,
851 fcinfo->flinfo->fn_mcxt,
852 PG_GETARG_DATUM(0), &a, &sa, NULL);
853 fcinfo->flinfo->fn_extra = SearchArrayCache(
854 fcinfo->flinfo->fn_extra,
855 fcinfo->flinfo->fn_mcxt,
856 PG_GETARG_DATUM(1), &b, &sb, NULL);
858 if ( ARR_ELEMTYPE(a) != ARR_ELEMTYPE(b) )
859 elog(ERROR,"Arguments array are not the same type!");
861 if (ARRISVOID(a) || ARRISVOID(b))
862 PG_RETURN_BOOL(false);
864 cnt = numOfIntersect(sa, sb);
866 if ( VARSIZE(formula) - VARHDRSZ > QBSIZE - 1024 )
867 elog(ERROR,"Formula is too long");
871 if ( cachedPlan == NULL || cachedLen != VARSIZE(formula) - VARHDRSZ ||
872 memcmp( cachedFormula, VARDATA(formula), VARSIZE(formula) - VARHDRSZ ) != 0 )
874 char *ptr, buf[QBSIZE];
876 *cachedFormula = '\0';
878 SPI_freeplan(cachedPlan);
882 ptr = stpcpy( buf, "SELECT (" );
883 memcpy( ptr, VARDATA(formula), VARSIZE(formula) - VARHDRSZ );
884 ptr += VARSIZE(formula) - VARHDRSZ;
885 ptr = stpcpy( ptr, ")::float4 FROM");
886 ptr = stpcpy( ptr, " (SELECT $1 ::float8 AS i, $2 ::float8 AS a, $3 ::float8 AS b) AS N;");
889 plan = SPI_prepare(buf, 3, arg);
891 elog(ERROR, "SPI_prepare() failed");
893 cachedPlan = SPI_saveplan(plan);
895 elog(ERROR, "SPI_saveplan() failed");
898 cachedLen = VARSIZE(formula) - VARHDRSZ;
899 memcpy( cachedFormula, VARDATA(formula), VARSIZE(formula) - VARHDRSZ );
905 pars[0] = Int32GetDatum( cnt );
906 pars[1] = Int32GetDatum( sa->nelems );
907 pars[2] = Int32GetDatum( sb->nelems );
909 stat = SPI_execute_plan(plan, pars, NULL, true, 3);
911 elog(ERROR, "SPI_execute_plan() returns %d", stat);
913 if ( SPI_processed > 0)
914 result = DatumGetFloat4(SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull));
918 PG_RETURN_FLOAT4(result);
921 PG_FUNCTION_INFO_V1(array_unique);
922 Datum array_unique(PG_FUNCTION_ARGS);
924 array_unique(PG_FUNCTION_ARGS)
926 ArrayType *a = PG_GETARG_ARRAYTYPE_P(0);
930 sa = Array2SimpleArrayU(NULL, a, NULL);
932 res = construct_array( sa->elems,
941 PG_FREE_IF_COPY(a, 0);
943 PG_RETURN_ARRAYTYPE_P(res);
946 PG_FUNCTION_INFO_V1(inarray);
947 Datum inarray(PG_FUNCTION_ARGS);
949 inarray(PG_FUNCTION_ARGS)
953 Datum query = PG_GETARG_DATUM(1);
960 fcinfo->flinfo->fn_extra = SearchArrayCache(
961 fcinfo->flinfo->fn_extra,
962 fcinfo->flinfo->fn_mcxt,
963 PG_GETARG_DATUM(0), &a, &sa, NULL);
965 queryTypeOid = get_fn_expr_argtype(fcinfo->flinfo, 1);
967 if ( queryTypeOid == InvalidOid )
968 elog(ERROR,"inarray: could not determine actual argument type");
970 if ( queryTypeOid != sa->info->typid )
971 elog(ERROR,"inarray: Type of array's element and type of argument are not the same");
973 getFmgrInfoCmp(sa->info);
975 StopHigh = sa->elems + sa->nelems;
977 while (StopLow < StopHigh)
979 StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
980 cmp = cmpArrayElem(StopMiddle, &query, sa->info);
985 if ( PG_NARGS() >= 3 )
986 PG_RETURN_DATUM(PG_GETARG_DATUM(2));
987 PG_RETURN_FLOAT4(1.0);
990 StopLow = StopMiddle + 1;
992 StopHigh = StopMiddle;
995 if ( PG_NARGS() >= 4 )
996 PG_RETURN_DATUM(PG_GETARG_DATUM(3));
997 PG_RETURN_FLOAT4(0.0);