Header And Logo

PostgreSQL
| The world's most advanced open source database.

btree_bytea.c

Go to the documentation of this file.
00001 /*
00002  * contrib/btree_gist/btree_bytea.c
00003  */
00004 #include "postgres.h"
00005 
00006 #include "btree_gist.h"
00007 #include "btree_utils_var.h"
00008 #include "utils/bytea.h"
00009 
00010 
00011 /*
00012 ** Bytea ops
00013 */
00014 PG_FUNCTION_INFO_V1(gbt_bytea_compress);
00015 PG_FUNCTION_INFO_V1(gbt_bytea_union);
00016 PG_FUNCTION_INFO_V1(gbt_bytea_picksplit);
00017 PG_FUNCTION_INFO_V1(gbt_bytea_consistent);
00018 PG_FUNCTION_INFO_V1(gbt_bytea_penalty);
00019 PG_FUNCTION_INFO_V1(gbt_bytea_same);
00020 
00021 Datum       gbt_bytea_compress(PG_FUNCTION_ARGS);
00022 Datum       gbt_bytea_union(PG_FUNCTION_ARGS);
00023 Datum       gbt_bytea_picksplit(PG_FUNCTION_ARGS);
00024 Datum       gbt_bytea_consistent(PG_FUNCTION_ARGS);
00025 Datum       gbt_bytea_penalty(PG_FUNCTION_ARGS);
00026 Datum       gbt_bytea_same(PG_FUNCTION_ARGS);
00027 
00028 
00029 /* define for comparison */
00030 
00031 static bool
00032 gbt_byteagt(const void *a, const void *b, Oid collation)
00033 {
00034     return DatumGetBool(DirectFunctionCall2(byteagt,
00035                                             PointerGetDatum(a),
00036                                             PointerGetDatum(b)));
00037 }
00038 
00039 static bool
00040 gbt_byteage(const void *a, const void *b, Oid collation)
00041 {
00042     return DatumGetBool(DirectFunctionCall2(byteage,
00043                                             PointerGetDatum(a),
00044                                             PointerGetDatum(b)));
00045 }
00046 
00047 static bool
00048 gbt_byteaeq(const void *a, const void *b, Oid collation)
00049 {
00050     return DatumGetBool(DirectFunctionCall2(byteaeq,
00051                                             PointerGetDatum(a),
00052                                             PointerGetDatum(b)));
00053 }
00054 
00055 static bool
00056 gbt_byteale(const void *a, const void *b, Oid collation)
00057 {
00058     return DatumGetBool(DirectFunctionCall2(byteale,
00059                                             PointerGetDatum(a),
00060                                             PointerGetDatum(b)));
00061 }
00062 
00063 static bool
00064 gbt_bytealt(const void *a, const void *b, Oid collation)
00065 {
00066     return DatumGetBool(DirectFunctionCall2(bytealt,
00067                                             PointerGetDatum(a),
00068                                             PointerGetDatum(b)));
00069 }
00070 
00071 static int32
00072 gbt_byteacmp(const void *a, const void *b, Oid collation)
00073 {
00074     return DatumGetInt32(DirectFunctionCall2(byteacmp,
00075                                              PointerGetDatum(a),
00076                                              PointerGetDatum(b)));
00077 }
00078 
00079 
00080 static const gbtree_vinfo tinfo =
00081 {
00082     gbt_t_bytea,
00083     0,
00084     TRUE,
00085     gbt_byteagt,
00086     gbt_byteage,
00087     gbt_byteaeq,
00088     gbt_byteale,
00089     gbt_bytealt,
00090     gbt_byteacmp,
00091     NULL
00092 };
00093 
00094 
00095 /**************************************************
00096  * Text ops
00097  **************************************************/
00098 
00099 
00100 Datum
00101 gbt_bytea_compress(PG_FUNCTION_ARGS)
00102 {
00103     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
00104 
00105     PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
00106 }
00107 
00108 
00109 
00110 Datum
00111 gbt_bytea_consistent(PG_FUNCTION_ARGS)
00112 {
00113     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
00114     void       *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
00115     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
00116 
00117     /* Oid      subtype = PG_GETARG_OID(3); */
00118     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
00119     bool        retval;
00120     GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
00121     GBT_VARKEY_R r = gbt_var_key_readable(key);
00122 
00123     /* All cases served by this function are exact */
00124     *recheck = false;
00125 
00126     retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
00127                                 GIST_LEAF(entry), &tinfo);
00128     PG_RETURN_BOOL(retval);
00129 }
00130 
00131 
00132 
00133 Datum
00134 gbt_bytea_union(PG_FUNCTION_ARGS)
00135 {
00136     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
00137     int32      *size = (int *) PG_GETARG_POINTER(1);
00138 
00139     PG_RETURN_POINTER(gbt_var_union(entryvec, size, PG_GET_COLLATION(),
00140                                     &tinfo));
00141 }
00142 
00143 
00144 Datum
00145 gbt_bytea_picksplit(PG_FUNCTION_ARGS)
00146 {
00147     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
00148     GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
00149 
00150     gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
00151                       &tinfo);
00152     PG_RETURN_POINTER(v);
00153 }
00154 
00155 Datum
00156 gbt_bytea_same(PG_FUNCTION_ARGS)
00157 {
00158     Datum       d1 = PG_GETARG_DATUM(0);
00159     Datum       d2 = PG_GETARG_DATUM(1);
00160     bool       *result = (bool *) PG_GETARG_POINTER(2);
00161 
00162     *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo);
00163     PG_RETURN_POINTER(result);
00164 }
00165 
00166 
00167 Datum
00168 gbt_bytea_penalty(PG_FUNCTION_ARGS)
00169 {
00170     GISTENTRY  *o = (GISTENTRY *) PG_GETARG_POINTER(0);
00171     GISTENTRY  *n = (GISTENTRY *) PG_GETARG_POINTER(1);
00172     float      *result = (float *) PG_GETARG_POINTER(2);
00173 
00174     PG_RETURN_POINTER(gbt_var_penalty(result, o, n, PG_GET_COLLATION(),
00175                                       &tinfo));
00176 }