PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ spatial_index_read_extent()

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

Definition at line 2500 of file gserialized_estimate.c.

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