PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ spatial_index_read_extent()

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

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

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