mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
Alter the xxx_pattern_ops opclasses to use the regular equality operator of
the associated datatype as their equality member. This means that these opclasses can now support plain equality comparisons along with LIKE tests, thus avoiding the need for an extra index in some applications. This optimization was not possible when the pattern opclasses were first introduced, because we didn't insist that text equality meant bitwise equality; but we do now, so there is no semantic difference between regular and pattern equality operators. I removed the name_pattern_ops opclass altogether, since it's really useless: name's regular comparisons are just strcmp() and are unlikely to become something different. Instead teach indxpath.c that btree name_ops can be used for LIKE whether or not the locale is C. This might lead to a useful speedup in LIKE queries on the system catalogs in non-C locales. The ~=~ and ~<>~ operators are gone altogether. (It would have been nice to keep them for backward compatibility's sake, but since the pg_amop structure doesn't allow multiple equality operators per opclass, there's no way.) A not-immediately-obvious incompatibility is that the sort order within bpchar_pattern_ops indexes changes --- it had been identical to plain strcmp, but is now trailing-blank-insensitive. This will impact in-place upgrades, if those ever happen. Per discussions a couple months ago.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.166 2008/05/12 00:00:51 alvherre Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.167 2008/05/27 00:13:09 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1309,22 +1309,27 @@ text_smaller(PG_FUNCTION_ARGS)
|
||||
|
||||
/*
|
||||
* The following operators support character-by-character comparison
|
||||
* of text data types, to allow building indexes suitable for LIKE
|
||||
* clauses.
|
||||
* of text datums, to allow building indexes suitable for LIKE clauses.
|
||||
* Note that the regular texteq/textne comparison operators are assumed
|
||||
* to be compatible with these!
|
||||
*/
|
||||
|
||||
static int
|
||||
internal_text_pattern_compare(text *arg1, text *arg2)
|
||||
{
|
||||
int result;
|
||||
int len1,
|
||||
len2;
|
||||
|
||||
result = memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2),
|
||||
Min(VARSIZE_ANY_EXHDR(arg1), VARSIZE_ANY_EXHDR(arg2)));
|
||||
len1 = VARSIZE_ANY_EXHDR(arg1);
|
||||
len2 = VARSIZE_ANY_EXHDR(arg2);
|
||||
|
||||
result = strncmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), Min(len1, len2));
|
||||
if (result != 0)
|
||||
return result;
|
||||
else if (VARSIZE_ANY_EXHDR(arg1) < VARSIZE_ANY_EXHDR(arg2))
|
||||
else if (len1 < len2)
|
||||
return -1;
|
||||
else if (VARSIZE_ANY_EXHDR(arg1) > VARSIZE_ANY_EXHDR(arg2))
|
||||
else if (len1 > len2)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
@ -1363,25 +1368,6 @@ text_pattern_le(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
|
||||
Datum
|
||||
text_pattern_eq(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *arg1 = PG_GETARG_TEXT_PP(0);
|
||||
text *arg2 = PG_GETARG_TEXT_PP(1);
|
||||
int result;
|
||||
|
||||
if (VARSIZE_ANY_EXHDR(arg1) != VARSIZE_ANY_EXHDR(arg2))
|
||||
result = 1;
|
||||
else
|
||||
result = internal_text_pattern_compare(arg1, arg2);
|
||||
|
||||
PG_FREE_IF_COPY(arg1, 0);
|
||||
PG_FREE_IF_COPY(arg2, 1);
|
||||
|
||||
PG_RETURN_BOOL(result == 0);
|
||||
}
|
||||
|
||||
|
||||
Datum
|
||||
text_pattern_ge(PG_FUNCTION_ARGS)
|
||||
{
|
||||
@ -1414,25 +1400,6 @@ text_pattern_gt(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
|
||||
Datum
|
||||
text_pattern_ne(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *arg1 = PG_GETARG_TEXT_PP(0);
|
||||
text *arg2 = PG_GETARG_TEXT_PP(1);
|
||||
int result;
|
||||
|
||||
if (VARSIZE_ANY_EXHDR(arg1) != VARSIZE_ANY_EXHDR(arg2))
|
||||
result = 1;
|
||||
else
|
||||
result = internal_text_pattern_compare(arg1, arg2);
|
||||
|
||||
PG_FREE_IF_COPY(arg1, 0);
|
||||
PG_FREE_IF_COPY(arg2, 1);
|
||||
|
||||
PG_RETURN_BOOL(result != 0);
|
||||
}
|
||||
|
||||
|
||||
Datum
|
||||
bttext_pattern_cmp(PG_FUNCTION_ARGS)
|
||||
{
|
||||
|
Reference in New Issue
Block a user