mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44:50 +03:00
Teach datum_image_eq() about cstring datums.
Bring datum_image_eq() in line with datumIsEqual() by adding support for comparing cstring datums. An upcoming patch that adds deduplication to the nbtree AM will use datum_image_eq(). datum_image_eq() will need to work with all datatypes that can be used as the storage type of a B-Tree index column, including cstring. (cstring is used as the storage type for columns of type "name" as a space-saving optimization.) Discussion: https://postgr.es/m/CAH2-Wzn3Ee49Gmxb7V1VJ3-AC8fWn-Fr8pfWQebHe8rYRxt5OQ@mail.gmail.com
This commit is contained in:
parent
7a0574b50e
commit
8c951687f5
@ -263,6 +263,8 @@ datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen)
|
|||||||
bool
|
bool
|
||||||
datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
|
datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
|
||||||
{
|
{
|
||||||
|
Size len1,
|
||||||
|
len2;
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
if (typByVal)
|
if (typByVal)
|
||||||
@ -277,9 +279,6 @@ datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
|
|||||||
}
|
}
|
||||||
else if (typLen == -1)
|
else if (typLen == -1)
|
||||||
{
|
{
|
||||||
Size len1,
|
|
||||||
len2;
|
|
||||||
|
|
||||||
len1 = toast_raw_datum_size(value1);
|
len1 = toast_raw_datum_size(value1);
|
||||||
len2 = toast_raw_datum_size(value2);
|
len2 = toast_raw_datum_size(value2);
|
||||||
/* No need to de-toast if lengths don't match. */
|
/* No need to de-toast if lengths don't match. */
|
||||||
@ -304,6 +303,20 @@ datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
|
|||||||
pfree(arg2val);
|
pfree(arg2val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (typLen == -2)
|
||||||
|
{
|
||||||
|
char *s1,
|
||||||
|
*s2;
|
||||||
|
|
||||||
|
/* Compare cstring datums */
|
||||||
|
s1 = DatumGetCString(value1);
|
||||||
|
s2 = DatumGetCString(value2);
|
||||||
|
len1 = strlen(s1) + 1;
|
||||||
|
len2 = strlen(s2) + 1;
|
||||||
|
if (len1 != len2)
|
||||||
|
return false;
|
||||||
|
result = (memcmp(s1, s2, len1) == 0);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
elog(ERROR, "unexpected typLen: %d", typLen);
|
elog(ERROR, "unexpected typLen: %d", typLen);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user