PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ spatial_index_read_extent()

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

Definition at line 2442 of file gserialized_estimate.c.

2443 {
2444  BOX2DF *bounds_2df = NULL;
2445  GIDX *bounds_gidx = NULL;
2446  GBOX *gbox = NULL;
2447  Relation idx_rel;
2448  Buffer buffer;
2449  Page page;
2450  unsigned long offset;
2451  unsigned long offset_max;
2452 
2453  if (!idx_oid)
2454  return NULL;
2455 
2456  idx_rel = index_open(idx_oid, AccessShareLock);
2457  buffer = ReadBuffer(idx_rel, GIST_ROOT_BLKNO);
2458  page = (Page) BufferGetPage(buffer);
2459  offset = FirstOffsetNumber;
2460  offset_max = PageGetMaxOffsetNumber(page);
2461  while (offset <= offset_max)
2462  {
2463  ItemId iid = PageGetItemId(page, offset);
2464  IndexTuple ituple;
2465  if (!iid)
2466  {
2467  ReleaseBuffer(buffer);
2468  index_close(idx_rel, AccessShareLock);
2469  return NULL;
2470  }
2471  ituple = (IndexTuple) PageGetItem(page, iid);
2472  if (!GistTupleIsInvalid(ituple))
2473  {
2474  bool isnull;
2475  Datum idx_attr = index_getattr(ituple, idx_att_num, idx_rel->rd_att, &isnull);
2476  if (!isnull)
2477  {
2478  if (key_type == STATISTIC_KIND_2D)
2479  {
2480  BOX2DF *b = (BOX2DF*)DatumGetPointer(idx_attr);
2481  if (bounds_2df)
2482  box2df_merge(bounds_2df, b);
2483  else
2484  bounds_2df = box2df_copy(b);
2485  }
2486  else
2487  {
2488  GIDX *b = (GIDX*)DatumGetPointer(idx_attr);
2489  if (bounds_gidx)
2490  gidx_merge(&bounds_gidx, b);
2491  else
2492  bounds_gidx = gidx_copy(b);
2493  }
2494  }
2495  }
2496  offset++;
2497  }
2498 
2499  ReleaseBuffer(buffer);
2500  index_close(idx_rel, AccessShareLock);
2501 
2502  if (key_type == STATISTIC_KIND_2D && bounds_2df)
2503  {
2504  if (box2df_is_empty(bounds_2df))
2505  return NULL;
2506  gbox = gbox_new(0);
2507  box2df_to_gbox_p(bounds_2df, gbox);
2508  }
2509  else if (key_type == STATISTIC_KIND_ND && bounds_gidx)
2510  {
2511  lwflags_t flags = 0;
2512  if (gidx_is_unknown(bounds_gidx))
2513  return NULL;
2514  FLAGS_SET_Z(flags, GIDX_NDIMS(bounds_gidx) > 2);
2515  FLAGS_SET_M(flags, GIDX_NDIMS(bounds_gidx) > 3);
2516  gbox = gbox_new(flags);
2517  gbox_from_gidx(bounds_gidx, gbox, flags);
2518  }
2519  else
2520  return NULL;
2521 
2522  return gbox;
2523 }
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)
uint16_t lwflags_t
Definition: liblwgeom.h:299
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:173
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:172
Datum buffer(PG_FUNCTION_ARGS)

References box2df_copy(), box2df_is_empty(), box2df_merge(), box2df_to_gbox_p(), buffer(), FLAGS_SET_M, FLAGS_SET_Z, 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: