6 #include "access/gist.h"
7 #include "access/skey.h"
11 PG_FUNCTION_INFO_V1(ginint4_queryextract
);
12 Datum
ginint4_queryextract(PG_FUNCTION_ARGS
);
15 ginint4_queryextract(PG_FUNCTION_ARGS
)
17 int32
*nentries
= (int32
*) PG_GETARG_POINTER(1);
18 StrategyNumber strategy
= PG_GETARG_UINT16(2);
23 if (strategy
== BooleanSearchStrategy
)
25 QUERYTYPE
*query
= (QUERYTYPE
*) PG_DETOAST_DATUM_COPY(PG_GETARG_POINTER(0));
26 ITEM
*items
= GETQUERY(query
);
30 PG_RETURN_POINTER(NULL
);
32 if (shorterquery(items
, query
->size
) == 0)
33 elog(ERROR
, "Query requires full scan, GIN doesn't support it");
37 query
= (QUERYTYPE
*) PG_DETOAST_DATUM(PG_GETARG_POINTER(0));
38 items
= GETQUERY(query
);
40 res
= (Datum
*) palloc(sizeof(Datum
) * query
->size
);
43 for (i
= 0; i
< query
->size
; i
++)
44 if (items
[i
].type
== VAL
)
46 res
[*nentries
] = Int32GetDatum(items
[i
].val
);
52 ArrayType
*query
= PG_GETARG_ARRAYTYPE_P(0);
57 *nentries
= ARRNELEMS(query
);
60 res
= (Datum
*) palloc(sizeof(Datum
) * (*nentries
));
63 for (i
= 0; i
< *nentries
; i
++)
64 res
[i
] = Int32GetDatum(arr
[i
]);
72 case BooleanSearchStrategy
:
73 case RTOverlapStrategyNumber
:
74 *nentries
= -1; /* nobody can be found */
76 default: /* require fullscan: GIN can't find void
82 PG_RETURN_POINTER(res
);
85 PG_FUNCTION_INFO_V1(ginint4_consistent
);
86 Datum
ginint4_consistent(PG_FUNCTION_ARGS
);
89 ginint4_consistent(PG_FUNCTION_ARGS
)
91 bool *check
= (bool *) PG_GETARG_POINTER(0);
92 StrategyNumber strategy
= PG_GETARG_UINT16(1);
93 bool *recheck
= (bool *) PG_GETARG_POINTER(3);
97 * we need not check array carefully, it's done by previous
98 * ginarrayextract call
103 case RTOverlapStrategyNumber
:
104 /* result is not lossy */
106 /* at least one element in check[] is true, so result = true */
109 case RTContainedByStrategyNumber
:
110 case RTOldContainedByStrategyNumber
:
111 /* we will need recheck */
113 /* at least one element in check[] is true, so result = true */
116 case RTSameStrategyNumber
:
118 ArrayType
*query
= PG_GETARG_ARRAYTYPE_P(2);
120 nentries
= ARRNELEMS(query
);
122 /* we will need recheck */
125 for (i
= 0; i
< nentries
; i
++)
133 case RTContainsStrategyNumber
:
134 case RTOldContainsStrategyNumber
:
136 ArrayType
*query
= PG_GETARG_ARRAYTYPE_P(2);
138 nentries
= ARRNELEMS(query
);
140 /* result is not lossy */
143 for (i
= 0; i
< nentries
; i
++)
151 case BooleanSearchStrategy
:
153 QUERYTYPE
*query
= (QUERYTYPE
*) PG_DETOAST_DATUM(PG_GETARG_POINTER(2));
155 /* result is not lossy */
157 res
= ginconsistent(query
, check
);
161 elog(ERROR
, "ginint4_consistent: unknown strategy number: %d",