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

Commitcadfdd1

Browse files
committed
Add new Tuplesortstate.removeabbrev function
This commit is the preparation to move abbreviation logic intoputtuple_common(). The new removeabbrev function turns datum1 representationof SortTuple's from the abbreviated key to the first column value. Therefore,it encapsulates the differential part of abbreviation handling code intuplesort_put*() functions, making these functions similar.Discussion:https://postgr.es/m/CAPpHfdvjix0Ahx-H3Jp1M2R%2B_74P-zKnGGygx4OWr%3DbUQ8BNdw%40mail.gmail.comAuthor: Alexander KorotkovReviewed-by: Pavel Borisov, Maxim Orlov, Matthias van de MeentReviewed-by: Andres Freund, John Naylor
1 parentd47da31 commitcadfdd1

File tree

1 file changed

+89
-48
lines changed

1 file changed

+89
-48
lines changed

‎src/backend/utils/sort/tuplesort.c

Lines changed: 89 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ struct Tuplesortstate
279279
*/
280280
SortTupleComparatorcomparetup;
281281

282+
/*
283+
* Alter datum1 representation in the SortTuple's array back from the
284+
* abbreviated key to the first column value.
285+
*/
286+
void(*removeabbrev) (Tuplesortstate*state,SortTuple*stups,
287+
intcount);
288+
282289
/*
283290
* Function to write a stored tuple onto tape. The representation of the
284291
* tuple on tape need not be the same as it is in memory; requirements on
@@ -540,6 +547,7 @@ struct Sharedsort
540547
pfree(buf); \
541548
} while(0)
542549

550+
#defineREMOVEABBREV(state,stup,count)((*(state)->removeabbrev) (state, stup, count))
543551
#defineCOMPARETUP(state,a,b)((*(state)->comparetup) (a, b, state))
544552
#defineWRITETUP(state,tape,stup)((*(state)->writetup) (state, tape, stup))
545553
#defineREADTUP(state,stup,tape,len) ((*(state)->readtup) (state, stup, tape, len))
@@ -629,6 +637,14 @@ static void reversedirection(Tuplesortstate *state);
629637
staticunsignedintgetlen(LogicalTape*tape,booleofOK);
630638
staticvoidmarkrunend(LogicalTape*tape);
631639
staticvoid*readtup_alloc(Tuplesortstate*state,Sizetuplen);
640+
staticvoidremoveabbrev_heap(Tuplesortstate*state,SortTuple*stups,
641+
intcount);
642+
staticvoidremoveabbrev_cluster(Tuplesortstate*state,SortTuple*stups,
643+
intcount);
644+
staticvoidremoveabbrev_index(Tuplesortstate*state,SortTuple*stups,
645+
intcount);
646+
staticvoidremoveabbrev_datum(Tuplesortstate*state,SortTuple*stups,
647+
intcount);
632648
staticintcomparetup_heap(constSortTuple*a,constSortTuple*b,
633649
Tuplesortstate*state);
634650
staticvoidwritetup_heap(Tuplesortstate*state,LogicalTape*tape,
@@ -1042,6 +1058,7 @@ tuplesort_begin_heap(TupleDesc tupDesc,
10421058
sortopt&TUPLESORT_RANDOMACCESS,
10431059
PARALLEL_SORT(state));
10441060

1061+
state->removeabbrev=removeabbrev_heap;
10451062
state->comparetup=comparetup_heap;
10461063
state->writetup=writetup_heap;
10471064
state->readtup=readtup_heap;
@@ -1117,6 +1134,7 @@ tuplesort_begin_cluster(TupleDesc tupDesc,
11171134
sortopt&TUPLESORT_RANDOMACCESS,
11181135
PARALLEL_SORT(state));
11191136

1137+
state->removeabbrev=removeabbrev_cluster;
11201138
state->comparetup=comparetup_cluster;
11211139
state->writetup=writetup_cluster;
11221140
state->readtup=readtup_cluster;
@@ -1221,6 +1239,7 @@ tuplesort_begin_index_btree(Relation heapRel,
12211239
sortopt&TUPLESORT_RANDOMACCESS,
12221240
PARALLEL_SORT(state));
12231241

1242+
state->removeabbrev=removeabbrev_index;
12241243
state->comparetup=comparetup_index_btree;
12251244
state->writetup=writetup_index;
12261245
state->readtup=readtup_index;
@@ -1297,6 +1316,7 @@ tuplesort_begin_index_hash(Relation heapRel,
12971316

12981317
state->nKeys=1;/* Only one sort column, the hash code */
12991318

1319+
state->removeabbrev=removeabbrev_index;
13001320
state->comparetup=comparetup_index_hash;
13011321
state->writetup=writetup_index;
13021322
state->readtup=readtup_index;
@@ -1337,6 +1357,7 @@ tuplesort_begin_index_gist(Relation heapRel,
13371357

13381358
state->nKeys=IndexRelationGetNumberOfKeyAttributes(indexRel);
13391359

1360+
state->removeabbrev=removeabbrev_index;
13401361
state->comparetup=comparetup_index_btree;
13411362
state->writetup=writetup_index;
13421363
state->readtup=readtup_index;
@@ -1400,6 +1421,7 @@ tuplesort_begin_datum(Oid datumType, Oid sortOperator, Oid sortCollation,
14001421
sortopt&TUPLESORT_RANDOMACCESS,
14011422
PARALLEL_SORT(state));
14021423

1424+
state->removeabbrev=removeabbrev_datum;
14031425
state->comparetup=comparetup_datum;
14041426
state->writetup=writetup_datum;
14051427
state->readtup=readtup_datum;
@@ -1858,8 +1880,6 @@ tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
18581880
else
18591881
{
18601882
/* Abort abbreviation */
1861-
inti;
1862-
18631883
stup.datum1=original;
18641884

18651885
/*
@@ -1871,20 +1891,7 @@ tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
18711891
* sorted on tape, since serialized tuples lack abbreviated keys
18721892
* (TSS_BUILDRUNS state prevents control reaching here in any case).
18731893
*/
1874-
for (i=0;i<state->memtupcount;i++)
1875-
{
1876-
SortTuple*mtup=&state->memtuples[i];
1877-
1878-
htup.t_len= ((MinimalTuple)mtup->tuple)->t_len+
1879-
MINIMAL_TUPLE_OFFSET;
1880-
htup.t_data= (HeapTupleHeader) ((char*)mtup->tuple-
1881-
MINIMAL_TUPLE_OFFSET);
1882-
1883-
mtup->datum1=heap_getattr(&htup,
1884-
state->sortKeys[0].ssup_attno,
1885-
state->tupDesc,
1886-
&mtup->isnull1);
1887-
}
1894+
REMOVEABBREV(state,state->memtuples,state->memtupcount);
18881895
}
18891896

18901897
puttuple_common(state,&stup);
@@ -1943,8 +1950,6 @@ tuplesort_putheaptuple(Tuplesortstate *state, HeapTuple tup)
19431950
else
19441951
{
19451952
/* Abort abbreviation */
1946-
inti;
1947-
19481953
stup.datum1=original;
19491954

19501955
/*
@@ -1957,16 +1962,7 @@ tuplesort_putheaptuple(Tuplesortstate *state, HeapTuple tup)
19571962
* (TSS_BUILDRUNS state prevents control reaching here in any
19581963
* case).
19591964
*/
1960-
for (i=0;i<state->memtupcount;i++)
1961-
{
1962-
SortTuple*mtup=&state->memtuples[i];
1963-
1964-
tup= (HeapTuple)mtup->tuple;
1965-
mtup->datum1=heap_getattr(tup,
1966-
state->indexInfo->ii_IndexAttrNumbers[0],
1967-
state->tupDesc,
1968-
&mtup->isnull1);
1969-
}
1965+
REMOVEABBREV(state,state->memtuples,state->memtupcount);
19701966
}
19711967
}
19721968

@@ -2023,8 +2019,6 @@ tuplesort_putindextuplevalues(Tuplesortstate *state, Relation rel,
20232019
else
20242020
{
20252021
/* Abort abbreviation */
2026-
inti;
2027-
20282022
stup.datum1=original;
20292023

20302024
/*
@@ -2036,16 +2030,7 @@ tuplesort_putindextuplevalues(Tuplesortstate *state, Relation rel,
20362030
* sorted on tape, since serialized tuples lack abbreviated keys
20372031
* (TSS_BUILDRUNS state prevents control reaching here in any case).
20382032
*/
2039-
for (i=0;i<state->memtupcount;i++)
2040-
{
2041-
SortTuple*mtup=&state->memtuples[i];
2042-
2043-
tuple=mtup->tuple;
2044-
mtup->datum1=index_getattr(tuple,
2045-
1,
2046-
RelationGetDescr(state->indexRel),
2047-
&mtup->isnull1);
2048-
}
2033+
REMOVEABBREV(state,state->memtuples,state->memtupcount);
20492034
}
20502035

20512036
puttuple_common(state,&stup);
@@ -2109,8 +2094,6 @@ tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)
21092094
else
21102095
{
21112096
/* Abort abbreviation */
2112-
inti;
2113-
21142097
stup.datum1=original;
21152098

21162099
/*
@@ -2123,12 +2106,7 @@ tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)
21232106
* (TSS_BUILDRUNS state prevents control reaching here in any
21242107
* case).
21252108
*/
2126-
for (i=0;i<state->memtupcount;i++)
2127-
{
2128-
SortTuple*mtup=&state->memtuples[i];
2129-
2130-
mtup->datum1=PointerGetDatum(mtup->tuple);
2131-
}
2109+
REMOVEABBREV(state,state->memtuples,state->memtupcount);
21322110
}
21332111
}
21342112

@@ -3985,6 +3963,26 @@ readtup_alloc(Tuplesortstate *state, Size tuplen)
39853963
* Routines specialized for HeapTuple (actually MinimalTuple) case
39863964
*/
39873965

3966+
staticvoid
3967+
removeabbrev_heap(Tuplesortstate*state,SortTuple*stups,intcount)
3968+
{
3969+
inti;
3970+
3971+
for (i=0;i<count;i++)
3972+
{
3973+
HeapTupleDatahtup;
3974+
3975+
htup.t_len= ((MinimalTuple)stups[i].tuple)->t_len+
3976+
MINIMAL_TUPLE_OFFSET;
3977+
htup.t_data= (HeapTupleHeader) ((char*)stups[i].tuple-
3978+
MINIMAL_TUPLE_OFFSET);
3979+
stups[i].datum1=heap_getattr(&htup,
3980+
state->sortKeys[0].ssup_attno,
3981+
state->tupDesc,
3982+
&stups[i].isnull1);
3983+
}
3984+
}
3985+
39883986
staticint
39893987
comparetup_heap(constSortTuple*a,constSortTuple*b,Tuplesortstate*state)
39903988
{
@@ -4103,6 +4101,23 @@ readtup_heap(Tuplesortstate *state, SortTuple *stup,
41034101
* comparisons per a btree index definition)
41044102
*/
41054103

4104+
staticvoid
4105+
removeabbrev_cluster(Tuplesortstate*state,SortTuple*stups,intcount)
4106+
{
4107+
inti;
4108+
4109+
for (i=0;i<count;i++)
4110+
{
4111+
HeapTupletup;
4112+
4113+
tup= (HeapTuple)stups[i].tuple;
4114+
stups[i].datum1=heap_getattr(tup,
4115+
state->indexInfo->ii_IndexAttrNumbers[0],
4116+
state->tupDesc,
4117+
&stups[i].isnull1);
4118+
}
4119+
}
4120+
41064121
staticint
41074122
comparetup_cluster(constSortTuple*a,constSortTuple*b,
41084123
Tuplesortstate*state)
@@ -4272,6 +4287,23 @@ readtup_cluster(Tuplesortstate *state, SortTuple *stup,
42724287
* functions can be shared.
42734288
*/
42744289

4290+
staticvoid
4291+
removeabbrev_index(Tuplesortstate*state,SortTuple*stups,intcount)
4292+
{
4293+
inti;
4294+
4295+
for (i=0;i<count;i++)
4296+
{
4297+
IndexTupletuple;
4298+
4299+
tuple=stups[i].tuple;
4300+
stups[i].datum1=index_getattr(tuple,
4301+
1,
4302+
RelationGetDescr(state->indexRel),
4303+
&stups[i].isnull1);
4304+
}
4305+
}
4306+
42754307
staticint
42764308
comparetup_index_btree(constSortTuple*a,constSortTuple*b,
42774309
Tuplesortstate*state)
@@ -4504,6 +4536,15 @@ readtup_index(Tuplesortstate *state, SortTuple *stup,
45044536
* Routines specialized for DatumTuple case
45054537
*/
45064538

4539+
staticvoid
4540+
removeabbrev_datum(Tuplesortstate*state,SortTuple*stups,intcount)
4541+
{
4542+
inti;
4543+
4544+
for (i=0;i<count;i++)
4545+
stups[i].datum1=PointerGetDatum(stups[i].tuple);
4546+
}
4547+
45074548
staticint
45084549
comparetup_datum(constSortTuple*a,constSortTuple*b,Tuplesortstate*state)
45094550
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp