PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ gserialized_gist_compress()

Datum gserialized_gist_compress ( PG_FUNCTION_ARGS  )

Definition at line 1091 of file gserialized_gist_nd.c.

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

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

Here is the call graph for this function: