PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ gserialized_gist_distance()

Datum gserialized_gist_distance ( PG_FUNCTION_ARGS  )

Definition at line 1418 of file gserialized_gist_nd.c.

References distance(), gidx_distance(), gidx_distance_leaf_centroid(), gidx_distance_node_centroid(), and LW_FAILURE.

Referenced by gserialized_gist_geog_distance().

1419 {
1420  GISTENTRY *entry = (GISTENTRY*) PG_GETARG_POINTER(0);
1421  StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
1422  char query_box_mem[GIDX_MAX_SIZE];
1423  GIDX *query_box = (GIDX*)query_box_mem;
1424  GIDX *entry_box;
1425 #if POSTGIS_PGSQL_VERSION >= 95
1426  bool *recheck = (bool *) PG_GETARG_POINTER(4);
1427 #endif
1428 
1429  double distance;
1430 
1431  POSTGIS_DEBUG(4, "[GIST] 'distance' function called");
1432 
1433  /* Strategy 13 is <<->> */
1434  /* Strategy 20 is |=| */
1435  if ( strategy != 13 && strategy != 20 ) {
1436  elog(ERROR, "unrecognized strategy number: %d", strategy);
1437  PG_RETURN_FLOAT8(FLT_MAX);
1438  }
1439 
1440  /* Null box should never make this far. */
1441  if ( gserialized_datum_get_gidx_p(PG_GETARG_DATUM(1), query_box) == LW_FAILURE )
1442  {
1443  POSTGIS_DEBUG(4, "[GIST] null query_gbox_index!");
1444  PG_RETURN_FLOAT8(FLT_MAX);
1445  }
1446 
1447  /* Get the entry box */
1448  entry_box = (GIDX*)DatumGetPointer(entry->key);
1449 
1450 #if POSTGIS_PGSQL_VERSION >= 95
1451 
1452  /* Strategy 20 is |=| */
1453  distance = gidx_distance(entry_box, query_box, strategy == 20);
1454 
1455  /* Treat leaf node tests different from internal nodes */
1456  if (GIST_LEAF(entry))
1457  *recheck = true;
1458 #else
1459 
1460  if ( strategy == 20 )
1461  {
1462  elog(ERROR, "You need PostgreSQL 9.5.0 or higher in order to use |=| with index");
1463  PG_RETURN_FLOAT8(FLT_MAX);
1464  }
1465 
1466  /* Treat leaf node tests different from internal nodes */
1467  if (GIST_LEAF(entry))
1468  {
1469  /* Calculate distance to leaves */
1470  distance = (double)gidx_distance_leaf_centroid(entry_box, query_box);
1471  }
1472  else
1473  {
1474  /* Calculate distance for internal nodes */
1475  distance = (double)gidx_distance_node_centroid(entry_box, query_box);
1476  }
1477 #endif
1478  PG_RETURN_FLOAT8(distance);
1479 }
static double gidx_distance_node_centroid(const GIDX *node, const GIDX *query)
#define LW_FAILURE
Definition: liblwgeom.h:78
static double gidx_distance(const GIDX *a, const GIDX *b, int m_is_time)
Calculate the box->box distance.
static double gidx_distance_leaf_centroid(const GIDX *a, const GIDX *b)
Calculate the centroid->centroid distance between the boxes.
Datum distance(PG_FUNCTION_ARGS)
Here is the call graph for this function:
Here is the caller graph for this function: