PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ spatial_index_read_extent()

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

Definition at line 2504 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().

2505 {
2506  BOX2DF *bounds_2df = NULL;
2507  GIDX *bounds_gidx = NULL;
2508  GBOX *gbox = NULL;
2509  Relation idx_rel;
2510  Buffer buffer;
2511  Page page;
2512  OffsetNumber offset;
2513  unsigned long offset_max;
2514 
2515  if (!idx_oid)
2516  return NULL;
2517 
2518  idx_rel = index_open(idx_oid, AccessExclusiveLock);
2519  buffer = ReadBuffer(idx_rel, GIST_ROOT_BLKNO);
2520  page = (Page) BufferGetPage(buffer);
2521  offset = FirstOffsetNumber;
2522  offset_max = PageGetMaxOffsetNumber(page);
2523  while (offset <= offset_max)
2524  {
2525  ItemId iid = PageGetItemId(page, offset);
2526  IndexTuple ituple;
2527  if (!iid)
2528  {
2529  ReleaseBuffer(buffer);
2530  index_close(idx_rel, AccessExclusiveLock);
2531  return NULL;
2532  }
2533  ituple = (IndexTuple) PageGetItem(page, iid);
2534  if (!GistTupleIsInvalid(ituple))
2535  {
2536  bool isnull;
2537  Datum idx_attr = index_getattr(ituple, 1, idx_rel->rd_att, &isnull);
2538  if (!isnull)
2539  {
2540  if (key_type == STATISTIC_SLOT_2D)
2541  {
2542  BOX2DF *b = (BOX2DF*)DatumGetPointer(idx_attr);
2543  if (bounds_2df)
2544  box2df_merge(bounds_2df, b);
2545  else
2546  bounds_2df = box2df_copy(b);
2547  }
2548  else
2549  {
2550  GIDX *b = (GIDX*)DatumGetPointer(idx_attr);
2551  if (bounds_gidx)
2552  gidx_merge(&bounds_gidx, b);
2553  else
2554  bounds_gidx = gidx_copy(b);
2555  }
2556  }
2557  }
2558  offset++;
2559  }
2560 
2561  ReleaseBuffer(buffer);
2562  index_close(idx_rel, AccessExclusiveLock);
2563 
2564  if (key_type == STATISTIC_SLOT_2D && bounds_2df)
2565  {
2566  if (box2df_is_empty(bounds_2df))
2567  return NULL;
2568  gbox = gbox_new(0);
2569  box2df_to_gbox_p(bounds_2df, gbox);
2570  }
2571  else if (key_type == STATISTIC_SLOT_ND && bounds_gidx)
2572  {
2573  if (gidx_is_unknown(bounds_gidx))
2574  return NULL;
2575  gbox = gbox_new(0);
2576  gbox_from_gidx(bounds_gidx, gbox, 0);
2577  }
2578  else
2579  return NULL;
2580 
2581  return gbox;
2582 }
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: