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

◆ spatial_index_read_extent()

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

Definition at line 2288 of file gserialized_estimate.c.

2289{
2290 BOX2DF *bounds_2df = NULL;
2291 GIDX *bounds_gidx = NULL;
2292 GBOX *gbox = NULL;
2293 Relation idx_rel;
2294 Buffer buffer;
2295 Page page;
2296 unsigned long offset;
2297 unsigned long offset_max;
2298
2299 if (!idx_oid)
2300 return NULL;
2301
2302 idx_rel = index_open(idx_oid, AccessShareLock);
2303 buffer = ReadBuffer(idx_rel, GIST_ROOT_BLKNO);
2304 page = (Page) BufferGetPage(buffer);
2305 offset = FirstOffsetNumber;
2306 offset_max = PageGetMaxOffsetNumber(page);
2307 while (offset <= offset_max)
2308 {
2309 ItemId iid = PageGetItemId(page, offset);
2310 IndexTuple ituple;
2311 if (!iid)
2312 {
2313 ReleaseBuffer(buffer);
2314 index_close(idx_rel, AccessShareLock);
2315 return NULL;
2316 }
2317 ituple = (IndexTuple) PageGetItem(page, iid);
2318 if (!GistTupleIsInvalid(ituple))
2319 {
2320 bool isnull;
2321 Datum idx_attr = index_getattr(ituple, idx_att_num, idx_rel->rd_att, &isnull);
2322 if (!isnull)
2323 {
2324 if (key_type == STATISTIC_KIND_2D)
2325 {
2326 BOX2DF *b = (BOX2DF*)DatumGetPointer(idx_attr);
2327 if (bounds_2df)
2328 box2df_merge(bounds_2df, b);
2329 else
2330 bounds_2df = box2df_copy(b);
2331 }
2332 else
2333 {
2334 GIDX *b = (GIDX*)DatumGetPointer(idx_attr);
2335 if (bounds_gidx)
2336 gidx_merge(&bounds_gidx, b);
2337 else
2338 bounds_gidx = gidx_copy(b);
2339 }
2340 }
2341 }
2342 offset++;
2343 }
2344
2345 ReleaseBuffer(buffer);
2346 index_close(idx_rel, AccessShareLock);
2347
2348 if (key_type == STATISTIC_KIND_2D && bounds_2df)
2349 {
2350 if (box2df_is_empty(bounds_2df))
2351 return NULL;
2352 gbox = gbox_new(0);
2353 box2df_to_gbox_p(bounds_2df, gbox);
2354 }
2355 else if (key_type == STATISTIC_KIND_ND && bounds_gidx)
2356 {
2357 lwflags_t flags = 0;
2358 if (gidx_is_unknown(bounds_gidx))
2359 return NULL;
2360 FLAGS_SET_Z(flags, GIDX_NDIMS(bounds_gidx) > 2);
2361 FLAGS_SET_M(flags, GIDX_NDIMS(bounds_gidx) > 3);
2362 gbox = gbox_new(flags);
2363 gbox_from_gidx(bounds_gidx, gbox, flags);
2364 }
2365 else
2366 return NULL;
2367
2368 return gbox;
2369}
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: