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

Commitb47b4db

Browse files
committed
Extend sortsupport for text to more opclasses.
Have varlena.c expose an interface that allows the char(n), bytea, andbpchar types to piggyback on a now-generalized SortSupport for text.This pushes a little more knowledge of the bpchar/char(n) type intovarlena.c than might be preferred, but that seems like the approachthat creates least friction. Also speed things up for index buildsthat use text_pattern_ops or varchar_pattern_ops.This patch does quite a bit of renaming, but it seems likely to beworth it, so as to avoid future confusion about the fact that this codeis now more generally used than the old names might have suggested.Peter Geoghegan, reviewed by Álvaro Herrera and Andreas Karlsson,with small tweaks by me.
1 parent24a26c9 commitb47b4db

File tree

8 files changed

+335
-135
lines changed

8 files changed

+335
-135
lines changed

‎doc/src/sgml/datatype.sgml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,8 +1140,7 @@ SELECT '52093.89'::money::numeric::float8;
11401140
advantages in some other database systems, there is no such advantage in
11411141
<productname>PostgreSQL</productname>; in fact
11421142
<type>character(<replaceable>n</>)</type> is usually the slowest of
1143-
the three because of its additional storage costs and slower
1144-
sorting. In most situations
1143+
the three because of its additional storage costs. In most situations
11451144
<type>text</type> or <type>character varying</type> should be used
11461145
instead.
11471146
</para>

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

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include"access/hash.h"
1919
#include"access/tuptoaster.h"
20+
#include"catalog/pg_collation.h"
2021
#include"libpq/pqformat.h"
2122
#include"nodes/nodeFuncs.h"
2223
#include"utils/array.h"
@@ -649,14 +650,21 @@ varchartypmodout(PG_FUNCTION_ARGS)
649650
*****************************************************************************/
650651

651652
/* "True" length (not counting trailing blanks) of a BpChar */
652-
staticint
653+
staticinlineint
653654
bcTruelen(BpChar*arg)
654655
{
655-
char*s=VARDATA_ANY(arg);
656+
returnbpchartruelen(VARDATA_ANY(arg),VARSIZE_ANY_EXHDR(arg));
657+
}
658+
659+
int
660+
bpchartruelen(char*s,intlen)
661+
{
656662
inti;
657-
intlen;
658663

659-
len=VARSIZE_ANY_EXHDR(arg);
664+
/*
665+
* Note that we rely on the assumption that ' ' is a singleton unit on
666+
* every supported multibyte server encoding.
667+
*/
660668
for (i=len-1;i >=0;i--)
661669
{
662670
if (s[i]!=' ')
@@ -858,6 +866,23 @@ bpcharcmp(PG_FUNCTION_ARGS)
858866
PG_RETURN_INT32(cmp);
859867
}
860868

869+
Datum
870+
bpchar_sortsupport(PG_FUNCTION_ARGS)
871+
{
872+
SortSupportssup= (SortSupport)PG_GETARG_POINTER(0);
873+
Oidcollid=ssup->ssup_collation;
874+
MemoryContextoldcontext;
875+
876+
oldcontext=MemoryContextSwitchTo(ssup->ssup_cxt);
877+
878+
/* Use generic string SortSupport */
879+
varstr_sortsupport(ssup,collid, true);
880+
881+
MemoryContextSwitchTo(oldcontext);
882+
883+
PG_RETURN_VOID();
884+
}
885+
861886
Datum
862887
bpchar_larger(PG_FUNCTION_ARGS)
863888
{
@@ -926,8 +951,9 @@ hashbpchar(PG_FUNCTION_ARGS)
926951
/*
927952
* The following operators support character-by-character comparison
928953
* of bpchar datums, to allow building indexes suitable for LIKE clauses.
929-
* Note that the regular bpchareq/bpcharne comparison operators are assumed
930-
* to be compatible with these!
954+
* Note that the regular bpchareq/bpcharne comparison operators, and
955+
* regular support functions 1 and 2 with "C" collation are assumed to be
956+
* compatible with these!
931957
*/
932958

933959
staticint
@@ -1030,3 +1056,20 @@ btbpchar_pattern_cmp(PG_FUNCTION_ARGS)
10301056

10311057
PG_RETURN_INT32(result);
10321058
}
1059+
1060+
1061+
Datum
1062+
btbpchar_pattern_sortsupport(PG_FUNCTION_ARGS)
1063+
{
1064+
SortSupportssup= (SortSupport)PG_GETARG_POINTER(0);
1065+
MemoryContextoldcontext;
1066+
1067+
oldcontext=MemoryContextSwitchTo(ssup->ssup_cxt);
1068+
1069+
/* Use generic string SortSupport, forcing "C" collation */
1070+
varstr_sortsupport(ssup,C_COLLATION_OID, true);
1071+
1072+
MemoryContextSwitchTo(oldcontext);
1073+
1074+
PG_RETURN_VOID();
1075+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp