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

Commitfbac127

Browse files
committed
During btree index build, sort equal-keyed tuples according to their
TID (heap position). This doesn't do anything to the validity of thefinished index, but by pretending to qsort() that there are no reallyequal keys in the sort, we can avoid performance problems with qsortimplementations that have trouble with large numbers of equal keys.Patch from Manfred Koizar.
1 parent55f7c33 commitfbac127

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
* Portions Copyright (c) 1994, Regents of the University of California
7979
*
8080
* IDENTIFICATION
81-
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.41 2004/02/03 17:34:03 tgl Exp $
81+
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.42 2004/03/17 22:24:58 tgl Exp $
8282
*
8383
*-------------------------------------------------------------------------
8484
*/
@@ -2020,7 +2020,8 @@ comparetup_index(Tuplesortstate *state, const void *a, const void *b)
20202020
{
20212021
/*
20222022
* This is almost the same as _bt_tuplecompare(), but we need to keep
2023-
* track of whether any null fields are present.
2023+
* track of whether any null fields are present. Also see the special
2024+
* treatment for equal keys at the end.
20242025
*/
20252026
IndexTupletuple1= (IndexTuple)a;
20262027
IndexTupletuple2= (IndexTuple)b;
@@ -2081,6 +2082,27 @@ comparetup_index(Tuplesortstate *state, const void *a, const void *b)
20812082
errmsg("could not create unique index"),
20822083
errdetail("Table contains duplicated values.")));
20832084

2085+
/*
2086+
* If key values are equal, we sort on ItemPointer. This does not
2087+
* affect validity of the finished index, but it offers cheap insurance
2088+
* against performance problems with bad qsort implementations that have
2089+
* trouble with large numbers of equal keys.
2090+
*/
2091+
{
2092+
BlockNumberblk1=ItemPointerGetBlockNumber(&tuple1->t_tid);
2093+
BlockNumberblk2=ItemPointerGetBlockNumber(&tuple2->t_tid);
2094+
2095+
if (blk1!=blk2)
2096+
return (blk1<blk2) ?-1 :1;
2097+
}
2098+
{
2099+
OffsetNumberpos1=ItemPointerGetOffsetNumber(&tuple1->t_tid);
2100+
OffsetNumberpos2=ItemPointerGetOffsetNumber(&tuple2->t_tid);
2101+
2102+
if (pos1!=pos2)
2103+
return (pos1<pos2) ?-1 :1;
2104+
}
2105+
20842106
return0;
20852107
}
20862108

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp