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

Commitccd6eb4

Browse files
committed
Introduce traversalValue for SP-GiST scan
During scan sometimes it would be very helpful to know some information aboutparent node or all ancestor nodes. Right now reconstructedValue could be usedbut it's not a right usage of it (range opclass uses that).traversalValue is arbitrary piece of memory in separate MemoryContext whilereconstructedVale should have the same type as indexed column.Subsequent patches for range opclass and quad4d tree will use it.Author: Alexander Lebedev, Teodor Sigaev
1 parent3063e7a commitccd6eb4

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

‎doc/src/sgml/spgist.sgml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,8 @@ typedef struct spgInnerConsistentIn
542542
int nkeys; /* length of array */
543543

544544
Datum reconstructedValue; /* value reconstructed at parent */
545+
void *traversalValue; /* opclass-specific traverse value */
546+
MemoryContext traversalMemoryContext;
545547
int level; /* current level (counting from zero) */
546548
bool returnData; /* original data must be returned? */
547549

@@ -559,6 +561,8 @@ typedef struct spgInnerConsistentOut
559561
int *nodeNumbers; /* their indexes in the node array */
560562
int *levelAdds; /* increment level by this much for each */
561563
Datum *reconstructedValues; /* associated reconstructed values */
564+
void **traversalValues; /* opclass-specific traverse values */
565+
562566
} spgInnerConsistentOut;
563567
</programlisting>
564568

@@ -593,6 +597,9 @@ typedef struct spgInnerConsistentOut
593597
inner tuple, and
594598
<structfield>nodeLabels</> is an array of their label values, or
595599
NULL if the nodes do not have labels.
600+
<structfield>traversalValue</> is a pointer to data that
601+
<function>inner_consistent</> gets when called on child nodes from an
602+
outer call of <function>inner_consistent</> on parent nodes.
596603
</para>
597604

598605
<para>
@@ -612,6 +619,13 @@ typedef struct spgInnerConsistentOut
612619
responsible for palloc'ing the
613620
<structfield>nodeNumbers</>, <structfield>levelAdds</> and
614621
<structfield>reconstructedValues</> arrays.
622+
Sometimes accumulating some information is needed, while
623+
descending from parent to child node was happened. In this case
624+
<structfield>traversalValues</> array keeps pointers to
625+
specific data you need to accumulate for every child node.
626+
Memory for <structfield>traversalValues</> should be allocated in
627+
the default context, but each element of it should be allocated in
628+
<structfield>traversalMemoryContext</>.
615629
</para>
616630
</listitem>
617631
</varlistentry>
@@ -638,6 +652,7 @@ typedef struct spgLeafConsistentIn
638652
ScanKey scankeys; /* array of operators and comparison values */
639653
int nkeys; /* length of array */
640654

655+
void *traversalValue; /* opclass-specific traverse value */
641656
Datum reconstructedValue; /* value reconstructed at parent */
642657
int level; /* current level (counting from zero) */
643658
bool returnData; /* original data must be returned? */

‎src/backend/access/spgist/spgscan.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef void (*storeRes_func) (SpGistScanOpaque so, ItemPointer heapPtr,
3030
typedefstructScanStackEntry
3131
{
3232
DatumreconstructedValue;/* value reconstructed from parent */
33+
void*traversalValue;/* opclass-specific traverse value */
3334
intlevel;/* level of items on this page */
3435
ItemPointerDataptr;/* block and offset to scan from */
3536
}ScanStackEntry;
@@ -42,6 +43,9 @@ freeScanStackEntry(SpGistScanOpaque so, ScanStackEntry *stackEntry)
4243
if (!so->state.attType.attbyval&&
4344
DatumGetPointer(stackEntry->reconstructedValue)!=NULL)
4445
pfree(DatumGetPointer(stackEntry->reconstructedValue));
46+
if (stackEntry->traversalValue)
47+
pfree(stackEntry->traversalValue);
48+
4549
pfree(stackEntry);
4650
}
4751

@@ -239,6 +243,7 @@ static bool
239243
spgLeafTest(Relationindex,SpGistScanOpaqueso,
240244
SpGistLeafTupleleafTuple,boolisnull,
241245
intlevel,DatumreconstructedValue,
246+
void*traversalValue,
242247
Datum*leafValue,bool*recheck)
243248
{
244249
boolresult;
@@ -265,6 +270,7 @@ spgLeafTest(Relation index, SpGistScanOpaque so,
265270
in.scankeys=so->keyData;
266271
in.nkeys=so->numberOfKeys;
267272
in.reconstructedValue=reconstructedValue;
273+
in.traversalValue=traversalValue;
268274
in.level=level;
269275
in.returnData=so->want_itup;
270276
in.leafDatum=leafDatum;
@@ -365,6 +371,7 @@ spgWalk(Relation index, SpGistScanOpaque so, bool scanWholeIndex,
365371
leafTuple,isnull,
366372
stackEntry->level,
367373
stackEntry->reconstructedValue,
374+
stackEntry->traversalValue,
368375
&leafValue,
369376
&recheck))
370377
{
@@ -411,6 +418,7 @@ spgWalk(Relation index, SpGistScanOpaque so, bool scanWholeIndex,
411418
leafTuple,isnull,
412419
stackEntry->level,
413420
stackEntry->reconstructedValue,
421+
stackEntry->traversalValue,
414422
&leafValue,
415423
&recheck))
416424
{
@@ -456,6 +464,8 @@ spgWalk(Relation index, SpGistScanOpaque so, bool scanWholeIndex,
456464
in.scankeys=so->keyData;
457465
in.nkeys=so->numberOfKeys;
458466
in.reconstructedValue=stackEntry->reconstructedValue;
467+
in.traversalMemoryContext=oldCtx;
468+
in.traversalValue=stackEntry->traversalValue;
459469
in.level=stackEntry->level;
460470
in.returnData=so->want_itup;
461471
in.allTheSame=innerTuple->allTheSame;
@@ -523,6 +533,14 @@ spgWalk(Relation index, SpGistScanOpaque so, bool scanWholeIndex,
523533
else
524534
newEntry->reconstructedValue= (Datum)0;
525535

536+
/*
537+
* Elements of out.traversalValues should be allocated in
538+
* in.traversalMemoryContext, which is actually a long
539+
* lived context of index scan.
540+
*/
541+
newEntry->traversalValue= (out.traversalValues) ?
542+
out.traversalValues[i] :NULL;
543+
526544
so->scanStack=lcons(newEntry,so->scanStack);
527545
}
528546
}

‎src/include/access/spgist.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ typedef struct spgInnerConsistentIn
133133
intnkeys;/* length of array */
134134

135135
DatumreconstructedValue;/* value reconstructed at parent */
136+
void*traversalValue;/* opclass-specific traverse value */
137+
MemoryContexttraversalMemoryContext;
136138
intlevel;/* current level (counting from zero) */
137139
boolreturnData;/* original data must be returned? */
138140

@@ -150,6 +152,7 @@ typedef struct spgInnerConsistentOut
150152
int*nodeNumbers;/* their indexes in the node array */
151153
int*levelAdds;/* increment level by this much for each */
152154
Datum*reconstructedValues;/* associated reconstructed values */
155+
void**traversalValues;/* opclass-specific traverse values */
153156
}spgInnerConsistentOut;
154157

155158
/*
@@ -160,6 +163,7 @@ typedef struct spgLeafConsistentIn
160163
ScanKeyscankeys;/* array of operators and comparison values */
161164
intnkeys;/* length of array */
162165

166+
void*traversalValue;/* opclass-specific traverse value */
163167
DatumreconstructedValue;/* value reconstructed at parent */
164168
intlevel;/* current level (counting from zero) */
165169
boolreturnData;/* original data must be returned? */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp