PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ gserialized_gist_penalty()

Datum gserialized_gist_penalty ( PG_FUNCTION_ARGS  )

Definition at line 1175 of file gserialized_gist_nd.c.

1176 {
1177  GISTENTRY *origentry = (GISTENTRY *)PG_GETARG_POINTER(0);
1178  GISTENTRY *newentry = (GISTENTRY *)PG_GETARG_POINTER(1);
1179  float *result = (float *)PG_GETARG_POINTER(2);
1180  GIDX *gbox_index_orig, *gbox_index_new;
1181 
1182  gbox_index_orig = (GIDX *)DatumGetPointer(origentry->key);
1183  gbox_index_new = (GIDX *)DatumGetPointer(newentry->key);
1184 
1185  /* Penalty value of 0 has special code path in Postgres's gistchoose.
1186  * It is used as an early exit condition in subtree loop, allowing faster tree descend.
1187  * For multi-column index, it lets next column break the tie, possibly more confidently.
1188  */
1189  *result = 0.0;
1190 
1191  /* Drop out if we're dealing with null inputs. Shouldn't happen. */
1192  if (gbox_index_orig && gbox_index_new)
1193  {
1194  /* Calculate the size difference of the boxes (volume difference in this case). */
1195  float size_union = gidx_union_volume(gbox_index_orig, gbox_index_new);
1196  float size_orig = gidx_volume(gbox_index_orig);
1197  float volume_extension = size_union - size_orig;
1198 
1199  gbox_index_orig = (GIDX *)PG_DETOAST_DATUM(origentry->key);
1200  gbox_index_new = (GIDX *)PG_DETOAST_DATUM(newentry->key);
1201 
1202  /* REALM 1: Area extension is nonzero, return it */
1203  if (volume_extension > FLT_EPSILON)
1204  *result = pack_float(volume_extension, 1);
1205  else
1206  {
1207  /* REALM 0: Area extension is zero, return nonzero edge extension */
1208  float edge_union = gidx_union_edge(gbox_index_orig, gbox_index_new);
1209  float edge_orig = gidx_edge(gbox_index_orig);
1210  float edge_extension = edge_union - edge_orig;
1211  if (edge_extension > FLT_EPSILON)
1212  *result = pack_float(edge_extension, 0);
1213  }
1214  }
1215  PG_RETURN_POINTER(result);
1216 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
static float gidx_union_volume(GIDX *a, GIDX *b)
static float gidx_union_edge(GIDX *a, GIDX *b)
static float gidx_volume(GIDX *a)
static float gidx_edge(GIDX *a)
static float pack_float(const float value, const uint8_t realm)

References gidx_edge(), gidx_union_edge(), gidx_union_volume(), gidx_volume(), pack_float(), and result.

Referenced by gserialized_gist_picksplit_constructsplit().

Here is the call graph for this function:
Here is the caller graph for this function: