PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ spatial_index_read_extent()

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

Definition at line 2486 of file gserialized_estimate.c.

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

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().

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