Commit 87545f54 authored by Teodor Sigaev's avatar Teodor Sigaev

Use traversalValue in SP-GiST range opclass.

Author: Alexander Lebedev
parent ccd6eb49
...@@ -310,14 +310,12 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS) ...@@ -310,14 +310,12 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
spgInnerConsistentOut *out = (spgInnerConsistentOut *) PG_GETARG_POINTER(1); spgInnerConsistentOut *out = (spgInnerConsistentOut *) PG_GETARG_POINTER(1);
int which; int which;
int i; int i;
MemoryContext oldCtx;
/* /*
* For adjacent search we need also previous centroid (if any) to improve * For adjacent search we need also previous centroid (if any) to improve
* the precision of the consistent check. In this case needPrevious flag * the precision of the consistent check. In this case needPrevious flag
* is set and centroid is passed into reconstructedValues. This is not the * is set and centroid is passed into traversalValue.
* intended purpose of reconstructedValues (because we already have the
* full value available at the leaf), but it's a convenient place to store
* state while traversing the tree.
*/ */
bool needPrevious = false; bool needPrevious = false;
...@@ -565,9 +563,9 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS) ...@@ -565,9 +563,9 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
* for lower or upper bounds to be adjacent. Deserialize * for lower or upper bounds to be adjacent. Deserialize
* previous centroid range if present for checking this. * previous centroid range if present for checking this.
*/ */
if (in->reconstructedValue != (Datum) 0) if (in->traversalValue != (Datum) 0)
{ {
prevCentroid = DatumGetRangeType(in->reconstructedValue); prevCentroid = DatumGetRangeType(in->traversalValue);
range_deserialize(typcache, prevCentroid, range_deserialize(typcache, prevCentroid,
&prevLower, &prevUpper, &prevEmpty); &prevLower, &prevUpper, &prevEmpty);
} }
...@@ -746,19 +744,37 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS) ...@@ -746,19 +744,37 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
/* We must descend into the quadrant(s) identified by 'which' */ /* We must descend into the quadrant(s) identified by 'which' */
out->nodeNumbers = (int *) palloc(sizeof(int) * in->nNodes); out->nodeNumbers = (int *) palloc(sizeof(int) * in->nNodes);
if (needPrevious) if (needPrevious)
out->reconstructedValues = (Datum *) palloc(sizeof(Datum) * in->nNodes); out->traversalValues = (void **) palloc(sizeof(void *) * in->nNodes);
out->nNodes = 0; out->nNodes = 0;
/*
* Elements of traversalValues should be allocated in
* traversalMemoryContext
*/
oldCtx = MemoryContextSwitchTo(in->traversalMemoryContext);
for (i = 1; i <= in->nNodes; i++) for (i = 1; i <= in->nNodes; i++)
{ {
if (which & (1 << i)) if (which & (1 << i))
{ {
/* Save previous prefix if needed */ /* Save previous prefix if needed */
if (needPrevious) if (needPrevious)
out->reconstructedValues[out->nNodes] = in->prefixDatum; {
out->nodeNumbers[out->nNodes++] = i - 1; Datum previousCentroid;
/* We know, that in->prefixDatum in this place is varlena,
* because it's range
*/
previousCentroid = datumCopy(in->prefixDatum, false, -1);
out->traversalValues[out->nNodes] = (void *)previousCentroid;
}
out->nodeNumbers[out->nNodes] = i - 1;
out->nNodes++;
} }
} }
MemoryContextSwitchTo(oldCtx);
PG_RETURN_VOID(); PG_RETURN_VOID();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment