PostGIS 3.7.0dev-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 2284 of file gserialized_estimate.c.

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