PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ spatial_index_read_extent()

static GBOX * spatial_index_read_extent ( Oid  idx_oid,
int  key_type 
)
static

Definition at line 2476 of file gserialized_estimate.c.

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

Referenced by _postgis_gserialized_index_extent(), and gserialized_estimated_extent().

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