2501{
2502 BOX2DF *bounds_2df = NULL;
2503 GIDX *bounds_gidx = NULL;
2505 Relation idx_rel;
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 {
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 {
2537 {
2538 BOX2DF *b = (BOX2DF*)DatumGetPointer(idx_attr);
2539 if (bounds_2df)
2541 else
2543 }
2544 else
2545 {
2546 GIDX *b = (GIDX*)DatumGetPointer(idx_attr);
2547 if (bounds_gidx)
2549 else
2551 }
2552 }
2553 }
2554 offset++;
2555 }
2556
2558 index_close(idx_rel, AccessShareLock);
2559
2561 {
2563 return NULL;
2566 }
2568 {
2570 return NULL;
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.
#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)