PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ spatial_index_read_extent()

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

Definition at line 2490 of file gserialized_estimate.c.

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