Skip to content

Commit 8c95168

Browse files
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
1 parent 7a0574b commit 8c95168

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/backend/utils/adt/datum.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen)
263263
bool
264264
datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
265265
{
266+
Size len1,
267+
len2;
266268
bool result = true;
267269

268270
if (typByVal)
@@ -277,9 +279,6 @@ datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
277279
}
278280
else if (typLen == -1)
279281
{
280-
Size len1,
281-
len2;
282-
283282
len1 = toast_raw_datum_size(value1);
284283
len2 = toast_raw_datum_size(value2);
285284
/* 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)
304303
pfree(arg2val);
305304
}
306305
}
306+
else if (typLen == -2)
307+
{
308+
char *s1,
309+
*s2;
310+
311+
/* Compare cstring datums */
312+
s1 = DatumGetCString(value1);
313+
s2 = DatumGetCString(value2);
314+
len1 = strlen(s1) + 1;
315+
len2 = strlen(s2) + 1;
316+
if (len1 != len2)
317+
return false;
318+
result = (memcmp(s1, s2, len1) == 0);
319+
}
307320
else
308321
elog(ERROR, "unexpected typLen: %d", typLen);
309322

0 commit comments

Comments
 (0)