Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit87545f5

Browse files
committed
Use traversalValue in SP-GiST range opclass.
Author: Alexander Lebedev
1 parentccd6eb4 commit87545f5

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

‎src/backend/utils/adt/rangetypes_spgist.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,12 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
310310
spgInnerConsistentOut*out= (spgInnerConsistentOut*)PG_GETARG_POINTER(1);
311311
intwhich;
312312
inti;
313+
MemoryContextoldCtx;
313314

314315
/*
315316
* For adjacent search we need also previous centroid (if any) to improve
316317
* the precision of the consistent check. In this case needPrevious flag
317-
* is set and centroid is passed into reconstructedValues. This is not the
318-
* intended purpose of reconstructedValues (because we already have the
319-
* full value available at the leaf), but it's a convenient place to store
320-
* state while traversing the tree.
318+
* is set and centroid is passed into traversalValue.
321319
*/
322320
boolneedPrevious= false;
323321

@@ -565,9 +563,9 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
565563
* for lower or upper bounds to be adjacent. Deserialize
566564
* previous centroid range if present for checking this.
567565
*/
568-
if (in->reconstructedValue!= (Datum)0)
566+
if (in->traversalValue!= (Datum)0)
569567
{
570-
prevCentroid=DatumGetRangeType(in->reconstructedValue);
568+
prevCentroid=DatumGetRangeType(in->traversalValue);
571569
range_deserialize(typcache,prevCentroid,
572570
&prevLower,&prevUpper,&prevEmpty);
573571
}
@@ -746,19 +744,37 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
746744
/* We must descend into the quadrant(s) identified by 'which' */
747745
out->nodeNumbers= (int*)palloc(sizeof(int)*in->nNodes);
748746
if (needPrevious)
749-
out->reconstructedValues= (Datum*)palloc(sizeof(Datum)*in->nNodes);
747+
out->traversalValues= (void**)palloc(sizeof(void*)*in->nNodes);
750748
out->nNodes=0;
749+
750+
/*
751+
* Elements of traversalValues should be allocated in
752+
* traversalMemoryContext
753+
*/
754+
oldCtx=MemoryContextSwitchTo(in->traversalMemoryContext);
755+
751756
for (i=1;i <=in->nNodes;i++)
752757
{
753758
if (which& (1 <<i))
754759
{
755760
/* Save previous prefix if needed */
756761
if (needPrevious)
757-
out->reconstructedValues[out->nNodes]=in->prefixDatum;
758-
out->nodeNumbers[out->nNodes++]=i-1;
762+
{
763+
DatumpreviousCentroid;
764+
765+
/* We know, that in->prefixDatum in this place is varlena,
766+
* because it's range
767+
*/
768+
previousCentroid=datumCopy(in->prefixDatum, false,-1);
769+
out->traversalValues[out->nNodes]= (void*)previousCentroid;
770+
}
771+
out->nodeNumbers[out->nNodes]=i-1;
772+
out->nNodes++;
759773
}
760774
}
761775

776+
MemoryContextSwitchTo(oldCtx);
777+
762778
PG_RETURN_VOID();
763779
}
764780

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp