PostGIS  3.1.6dev-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 2510 of file gserialized_estimate.c.

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