PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ gserialized_gist_compress()

Datum gserialized_gist_compress ( PG_FUNCTION_ARGS  )

Definition at line 1024 of file gserialized_gist_nd.c.

References FALSE, gidx_copy(), gidx_set_unknown(), gidx_validate(), gserialized_gist_decompress(), LW_FAILURE, LW_SUCCESS, and PG_FUNCTION_INFO_V1().

Referenced by gserialized_overlaps().

1025 {
1026  GISTENTRY *entry_in = (GISTENTRY*)PG_GETARG_POINTER(0);
1027  GISTENTRY *entry_out = NULL;
1028  char gidxmem[GIDX_MAX_SIZE];
1029  GIDX *bbox_out = (GIDX*)gidxmem;
1030  int result = LW_SUCCESS;
1031  int i;
1032 
1033  POSTGIS_DEBUG(4, "[GIST] 'compress' function called");
1034 
1035  /*
1036  ** Not a leaf key? There's nothing to do.
1037  ** Return the input unchanged.
1038  */
1039  if ( ! entry_in->leafkey )
1040  {
1041  POSTGIS_DEBUG(4, "[GIST] non-leafkey entry, returning input unaltered");
1042  PG_RETURN_POINTER(entry_in);
1043  }
1044 
1045  POSTGIS_DEBUG(4, "[GIST] processing leafkey input");
1046  entry_out = palloc(sizeof(GISTENTRY));
1047 
1048  /*
1049  ** Null key? Make a copy of the input entry and
1050  ** return.
1051  */
1052  if ( DatumGetPointer(entry_in->key) == NULL )
1053  {
1054  POSTGIS_DEBUG(4, "[GIST] leafkey is null");
1055  gistentryinit(*entry_out, (Datum) 0, entry_in->rel,
1056  entry_in->page, entry_in->offset, FALSE);
1057  POSTGIS_DEBUG(4, "[GIST] returning copy of input");
1058  PG_RETURN_POINTER(entry_out);
1059  }
1060 
1061  /* Extract our index key from the GiST entry. */
1062  result = gserialized_datum_get_gidx_p(entry_in->key, bbox_out);
1063 
1064  /* Is the bounding box valid (non-empty, non-infinite) ?
1065  * If not, use the "unknown" GIDX. */
1066  if ( result == LW_FAILURE )
1067  {
1068  POSTGIS_DEBUG(4, "[GIST] empty geometry!");
1069  gidx_set_unknown(bbox_out);
1070  gistentryinit(*entry_out, PointerGetDatum(gidx_copy(bbox_out)),
1071  entry_in->rel, entry_in->page,
1072  entry_in->offset, FALSE);
1073  PG_RETURN_POINTER(entry_out);
1074  }
1075 
1076  POSTGIS_DEBUGF(4, "[GIST] got entry_in->key: %s", gidx_to_string(bbox_out));
1077 
1078  /* Check all the dimensions for finite values.
1079  * If not, use the "unknown" GIDX as a key */
1080  for ( i = 0; i < GIDX_NDIMS(bbox_out); i++ )
1081  {
1082  if ( ! isfinite(GIDX_GET_MAX(bbox_out, i))
1083  || ! isfinite(GIDX_GET_MIN(bbox_out, i)) )
1084  {
1085  gidx_set_unknown(bbox_out);
1086  gistentryinit(*entry_out,
1087  PointerGetDatum(gidx_copy(bbox_out)),
1088  entry_in->rel, entry_in->page,
1089  entry_in->offset, FALSE);
1090  PG_RETURN_POINTER(entry_out);
1091  }
1092  }
1093 
1094  /* Enure bounding box has minimums below maximums. */
1095  gidx_validate(bbox_out);
1096 
1097  /* Prepare GISTENTRY for return. */
1098  gistentryinit(*entry_out, PointerGetDatum(gidx_copy(bbox_out)),
1099  entry_in->rel, entry_in->page, entry_in->offset, FALSE);
1100 
1101  /* Return GISTENTRY. */
1102  POSTGIS_DEBUG(4, "[GIST] 'compress' function complete");
1103  PG_RETURN_POINTER(entry_out);
1104 }
static GIDX * gidx_copy(GIDX *b)
#define LW_SUCCESS
Definition: liblwgeom.h:79
static void gidx_set_unknown(GIDX *a)
#define LW_FAILURE
Definition: liblwgeom.h:78
static void gidx_validate(GIDX *b)
#define FALSE
Definition: dbfopen.c:168
Here is the call graph for this function:
Here is the caller graph for this function: