PostGIS  2.5.0dev-r@@SVN_REVISION@@
static GBOX * spatial_index_read_extent ( Oid  idx_oid,
int  key_type 
)
static

Definition at line 2472 of file gserialized_estimate.c.

References box2df_copy(), box2df_is_empty(), box2df_merge(), box2df_to_gbox_p(), buffer(), gbox_new(), gidx_copy(), gidx_is_unknown(), gidx_merge(), STATISTIC_SLOT_2D, and STATISTIC_SLOT_ND.

Referenced by _postgis_gserialized_index_extent(), and gserialized_estimated_extent().

2473 {
2474  BOX2DF *bounds_2df = NULL;
2475  GIDX *bounds_gidx = NULL;
2476  GBOX *gbox = NULL;
2477 
2478  if (!idx_oid)
2479  return NULL;
2480 
2481  Relation idx_rel = index_open(idx_oid, AccessExclusiveLock);
2482  Buffer buffer = ReadBuffer(idx_rel, GIST_ROOT_BLKNO);
2483  Page page = (Page) BufferGetPage(buffer);
2484  OffsetNumber offset = FirstOffsetNumber;
2485  unsigned long offset_max = PageGetMaxOffsetNumber(page);
2486  while (offset <= offset_max)
2487  {
2488  ItemId iid = PageGetItemId(page, offset);
2489  if (!iid)
2490  {
2491  ReleaseBuffer(buffer);
2492  index_close(idx_rel, AccessExclusiveLock);
2493  return NULL;
2494  }
2495  IndexTuple ituple = (IndexTuple) PageGetItem(page, iid);
2496  if (!GistTupleIsInvalid(ituple))
2497  {
2498  bool isnull;
2499  Datum idx_attr = index_getattr(ituple, 1, idx_rel->rd_att, &isnull);
2500  if (!isnull)
2501  {
2502  if (key_type == STATISTIC_SLOT_2D)
2503  {
2504  BOX2DF *b = (BOX2DF*)DatumGetPointer(idx_attr);
2505  if (bounds_2df)
2506  box2df_merge(bounds_2df, b);
2507  else
2508  bounds_2df = box2df_copy(b);
2509  }
2510  else
2511  {
2512  GIDX *b = (GIDX*)DatumGetPointer(idx_attr);
2513  if (bounds_gidx)
2514  gidx_merge(&bounds_gidx, b);
2515  else
2516  bounds_gidx = gidx_copy(b);
2517  }
2518  }
2519  }
2520  offset++;
2521  }
2522 
2523  ReleaseBuffer(buffer);
2524  index_close(idx_rel, AccessExclusiveLock);
2525 
2526  if (key_type == STATISTIC_SLOT_2D && bounds_2df)
2527  {
2528  if (box2df_is_empty(bounds_2df))
2529  return NULL;
2530  gbox = gbox_new(0);
2531  box2df_to_gbox_p(bounds_2df, gbox);
2532  }
2533  else if (key_type == STATISTIC_SLOT_ND && bounds_gidx)
2534  {
2535  if (gidx_is_unknown(bounds_gidx))
2536  return NULL;
2537  gbox = gbox_new(0);
2538  gbox_from_gidx(bounds_gidx, gbox, 0);
2539  }
2540  else
2541  return NULL;
2542 
2543  return gbox;
2544 }
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
Definition: g_box.c:43
int box2df_to_gbox_p(BOX2DF *a, GBOX *box)
void gidx_merge(GIDX **b_union, GIDX *b_new)
#define STATISTIC_SLOT_2D
BOX2DF * box2df_copy(BOX2DF *b)
Datum buffer(PG_FUNCTION_ARGS)
bool gidx_is_unknown(const GIDX *a)
#define STATISTIC_SLOT_ND
GIDX * gidx_copy(GIDX *b)
void box2df_merge(BOX2DF *b_union, BOX2DF *b_new)
bool box2df_is_empty(const BOX2DF *a)

Here is the call graph for this function:

Here is the caller graph for this function: