Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GiST test case for #4139 #336

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions postgis/gserialized_gist_nd.c
Expand Up @@ -154,8 +154,7 @@ gidx_set_unknown(GIDX *a)
SET_VARSIZE(a, VARHDRSZ);
}

/* Enlarge b_union to contain b_new. If b_new contains more
dimensions than b_union, expand b_union to contain those dimensions. */
/* Enlarge b_union to contain b_new. */
void
gidx_merge(GIDX **b_union, GIDX *b_new)
{
Expand All @@ -180,15 +179,16 @@ gidx_merge(GIDX **b_union, GIDX *b_new)

POSTGIS_DEBUGF(4, "merging gidx (%s) into gidx (%s)", gidx_to_string(b_new), gidx_to_string(*b_union));

if (dims_new > dims_union)
/* Shrink unshared dimensions */
if (dims_new < dims_union)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this shrinking really necessary now? If b_union has 10 dimensions and b_new 2, I'd expect the merge to have 10, not 2; that is, a merge between 2 boxes should be bigger, never smaller.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think of 3DM box: it has (minx, maxx, miny, maxy, -FLT_MAX, FLT_MAX, minm, maxm ) for padding, it is a 4D gidx.

When this gets into calculations here, it resets whatever was there in Z to -flt_max / flt_max, in gidx_merge logic. That is equivalent of dropping the dimension. Thus, unshared dimensions should be dropped to correctly summarize a group of other mixed-dimensions boxes.

Is there a fault in this logic?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think of 3DM box: it has (minx, maxx, miny, maxy, -FLT_MAX, FLT_MAX, minm, maxm ) for padding, it is a 4D gidx.

That's what I wasn't expecting. I'd expect that a XYM GBOX would result in a 3-dimension gidx, but as you say it's done by adding an infinite dimension instead [1]. Based on the preferences taken ([2]), I'm unsure whether gidx_merge the union should contain that extra dimension or not, but it appears that this was in fact the issue here.

[1]

/* if M is present but Z is not, pad Z and shift M */

[2] https://lists.osgeo.org/pipermail/postgis-devel/2015-February/024759.html

{
POSTGIS_DEBUGF(5, "reallocating b_union from %d dims to %d dims", dims_union, dims_new);
*b_union = (GIDX *)repalloc(*b_union, GIDX_SIZE(dims_new));
SET_VARSIZE(*b_union, VARSIZE(b_new));
dims_union = dims_new;
}

for (i = 0; i < dims_new; i++)
for (i = 0; i < dims_union; i++)
{
/* Adjust minimums */
GIDX_SET_MIN(*b_union, i, Min(GIDX_GET_MIN(*b_union, i), GIDX_GET_MIN(b_new, i)));
Expand All @@ -197,6 +197,7 @@ gidx_merge(GIDX **b_union, GIDX *b_new)
}

POSTGIS_DEBUGF(5, "merge complete (%s)", gidx_to_string(*b_union));
assert(gidx_contains(*b_union, b_new));
return;
}

Expand Down Expand Up @@ -1071,7 +1072,7 @@ gserialized_gist_consistent_leaf(GIDX *key, GIDX *query, StrategyNumber strategy
retval = false;
}

return (retval);
return retval;
}

/*
Expand Down Expand Up @@ -1105,7 +1106,7 @@ gserialized_gist_consistent_internal(GIDX *key, GIDX *query, StrategyNumber stra
retval = false;
}

return (retval);
return retval;
}

/*
Expand Down
5 changes: 2 additions & 3 deletions regress/core/Makefile.in
Expand Up @@ -107,6 +107,7 @@ TESTS = \
quantize_coordinates \
regress \
regress_bdpoly \
regress_gist_index_nd \
regress_index \
regress_index_nulls \
regress_management \
Expand Down Expand Up @@ -189,7 +190,6 @@ TESTS += \
delaunaytriangles



ifeq ($(INTERRUPTTESTS),yes)
# Allow CI servers to configure --with-interrupt-tests
TESTS += \
Expand Down Expand Up @@ -234,8 +234,7 @@ ifeq ($(HAVE_SPGIST),yes)
TESTS += \
regress_spgist_index_2d \
regress_spgist_index_3d \
regress_spgist_index_nd #\
# regress_gist_index_nd
regress_spgist_index_nd
endif

ifeq ($(HAVE_PROTOBUF),yes)
Expand Down
3 changes: 1 addition & 2 deletions regress/core/regress_gist_index_nd.sql
Expand Up @@ -85,5 +85,4 @@ select * from test_gist_idx_nd;

DROP TABLE tbl_geomcollection_nd CASCADE;
DROP TABLE test_gist_idx_nd CASCADE;
DROP FUNCTION qnodes;

DROP FUNCTION qnodes (text);
4 changes: 2 additions & 2 deletions regress/core/regress_gist_index_nd_expected
@@ -1,4 +1,4 @@
&&&|180502|Seq Scan|180502|Index Scan
~~ |35498|Seq Scan|35498|Index Scan
@@ |35498|Seq Scan|35498|Index Scan
~~ |39682|Seq Scan|39682|Index Scan
@@ |39682|Seq Scan|39682|Index Scan
~~=|480|Seq Scan|480|Index Scan