PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum gserialized_gist_compress ( PG_FUNCTION_ARGS  )

Definition at line 1090 of file gserialized_gist_nd.c.

References gidx_copy(), gidx_set_unknown(), gidx_validate(), LW_FAILURE, and LW_SUCCESS.

1091 {
1092  GISTENTRY *entry_in = (GISTENTRY*)PG_GETARG_POINTER(0);
1093  GISTENTRY *entry_out = NULL;
1094  char gidxmem[GIDX_MAX_SIZE];
1095  GIDX *bbox_out = (GIDX*)gidxmem;
1096  int result = LW_SUCCESS;
1097  uint32_t i;
1098 
1099  POSTGIS_DEBUG(4, "[GIST] 'compress' function called");
1100 
1101  /*
1102  ** Not a leaf key? There's nothing to do.
1103  ** Return the input unchanged.
1104  */
1105  if ( ! entry_in->leafkey )
1106  {
1107  POSTGIS_DEBUG(4, "[GIST] non-leafkey entry, returning input unaltered");
1108  PG_RETURN_POINTER(entry_in);
1109  }
1110 
1111  POSTGIS_DEBUG(4, "[GIST] processing leafkey input");
1112  entry_out = palloc(sizeof(GISTENTRY));
1113 
1114  /*
1115  ** Null key? Make a copy of the input entry and
1116  ** return.
1117  */
1118  if ( DatumGetPointer(entry_in->key) == NULL )
1119  {
1120  POSTGIS_DEBUG(4, "[GIST] leafkey is null");
1121  gistentryinit(*entry_out, (Datum) 0, entry_in->rel,
1122  entry_in->page, entry_in->offset, false);
1123  POSTGIS_DEBUG(4, "[GIST] returning copy of input");
1124  PG_RETURN_POINTER(entry_out);
1125  }
1126 
1127  /* Extract our index key from the GiST entry. */
1128  result = gserialized_datum_get_gidx_p(entry_in->key, bbox_out);
1129 
1130  /* Is the bounding box valid (non-empty, non-infinite) ?
1131  * If not, use the "unknown" GIDX. */
1132  if ( result == LW_FAILURE )
1133  {
1134  POSTGIS_DEBUG(4, "[GIST] empty geometry!");
1135  gidx_set_unknown(bbox_out);
1136  gistentryinit(*entry_out, PointerGetDatum(gidx_copy(bbox_out)),
1137  entry_in->rel, entry_in->page,
1138  entry_in->offset, false);
1139  PG_RETURN_POINTER(entry_out);
1140  }
1141 
1142  POSTGIS_DEBUGF(4, "[GIST] got entry_in->key: %s", gidx_to_string(bbox_out));
1143 
1144  /* Check all the dimensions for finite values.
1145  * If not, use the "unknown" GIDX as a key */
1146  for ( i = 0; i < GIDX_NDIMS(bbox_out); i++ )
1147  {
1148  if ( ! isfinite(GIDX_GET_MAX(bbox_out, i))
1149  || ! isfinite(GIDX_GET_MIN(bbox_out, i)) )
1150  {
1151  gidx_set_unknown(bbox_out);
1152  gistentryinit(*entry_out,
1153  PointerGetDatum(gidx_copy(bbox_out)),
1154  entry_in->rel, entry_in->page,
1155  entry_in->offset, false);
1156  PG_RETURN_POINTER(entry_out);
1157  }
1158  }
1159 
1160  /* Enure bounding box has minimums below maximums. */
1161  gidx_validate(bbox_out);
1162 
1163  /* Prepare GISTENTRY for return. */
1164  gistentryinit(*entry_out, PointerGetDatum(gidx_copy(bbox_out)),
1165  entry_in->rel, entry_in->page, entry_in->offset, false);
1166 
1167  /* Return GISTENTRY. */
1168  POSTGIS_DEBUG(4, "[GIST] 'compress' function complete");
1169  PG_RETURN_POINTER(entry_out);
1170 }
#define LW_SUCCESS
Definition: liblwgeom.h:79
static void gidx_set_unknown(GIDX *a)
#define LW_FAILURE
Definition: liblwgeom.h:78
unsigned int uint32_t
Definition: uthash.h:78
static void gidx_validate(GIDX *b)
GIDX * gidx_copy(GIDX *b)

Here is the call graph for this function: