@@ -898,8 +898,6 @@ record_cmp(FunctionCallInfo fcinfo)
898
898
{
899
899
TypeCacheEntry * typentry ;
900
900
Oid collation ;
901
- FunctionCallInfoData locfcinfo ;
902
- int32 cmpresult ;
903
901
904
902
/*
905
903
* Skip dropped columns
@@ -959,6 +957,9 @@ record_cmp(FunctionCallInfo fcinfo)
959
957
*/
960
958
if (!nulls1 [i1 ] || !nulls2 [i2 ])
961
959
{
960
+ FunctionCallInfoData locfcinfo ;
961
+ int32 cmpresult ;
962
+
962
963
if (nulls1 [i1 ])
963
964
{
964
965
/* arg1 is greater than arg2 */
@@ -1295,12 +1296,12 @@ btrecordcmp(PG_FUNCTION_ARGS)
1295
1296
* identical. As an example, for the citext type 'A' and 'a' are equal, but
1296
1297
* they are not identical.
1297
1298
*/
1298
- static bool
1299
- record_image_cmp (PG_FUNCTION_ARGS )
1299
+ static int
1300
+ record_image_cmp (FunctionCallInfo fcinfo )
1300
1301
{
1301
1302
HeapTupleHeader record1 = PG_GETARG_HEAPTUPLEHEADER (0 );
1302
1303
HeapTupleHeader record2 = PG_GETARG_HEAPTUPLEHEADER (1 );
1303
- int32 result = 0 ;
1304
+ int result = 0 ;
1304
1305
Oid tupType1 ;
1305
1306
Oid tupType2 ;
1306
1307
int32 tupTypmod1 ;
@@ -1418,6 +1419,12 @@ record_image_cmp(PG_FUNCTION_ARGS)
1418
1419
format_type_be (tupdesc2 -> attrs [i2 ]-> atttypid ),
1419
1420
j + 1 )));
1420
1421
1422
+ /*
1423
+ * The same type should have the same length (or both should be variable).
1424
+ */
1425
+ Assert (tupdesc1 -> attrs [i1 ]-> attlen ==
1426
+ tupdesc2 -> attrs [i2 ]-> attlen );
1427
+
1421
1428
/*
1422
1429
* We consider two NULLs equal; NULL > not-NULL.
1423
1430
*/
@@ -1453,7 +1460,7 @@ record_image_cmp(PG_FUNCTION_ARGS)
1453
1460
1454
1461
cmpresult = memcmp (VARDATA_ANY (arg1val ),
1455
1462
VARDATA_ANY (arg2val ),
1456
- len1 - VARHDRSZ );
1463
+ Min ( len1 , len2 ) - VARHDRSZ );
1457
1464
if ((cmpresult == 0 ) && (len1 != len2 ))
1458
1465
cmpresult = (len1 < len2 ) ? -1 : 1 ;
1459
1466
@@ -1464,8 +1471,45 @@ record_image_cmp(PG_FUNCTION_ARGS)
1464
1471
}
1465
1472
else if (tupdesc1 -> attrs [i1 ]-> attbyval )
1466
1473
{
1467
- if (values1 [i1 ] != values2 [i2 ])
1468
- cmpresult = (values1 [i1 ] < values2 [i2 ]) ? -1 : 1 ;
1474
+ switch (tupdesc1 -> attrs [i1 ]-> attlen )
1475
+ {
1476
+ case 1 :
1477
+ if (GET_1_BYTE (values1 [i1 ]) !=
1478
+ GET_1_BYTE (values2 [i2 ]))
1479
+ {
1480
+ cmpresult = (GET_1_BYTE (values1 [i1 ]) <
1481
+ GET_1_BYTE (values2 [i2 ])) ? -1 : 1 ;
1482
+ }
1483
+ break ;
1484
+ case 2 :
1485
+ if (GET_2_BYTES (values1 [i1 ]) !=
1486
+ GET_2_BYTES (values2 [i2 ]))
1487
+ {
1488
+ cmpresult = (GET_2_BYTES (values1 [i1 ]) <
1489
+ GET_2_BYTES (values2 [i2 ])) ? -1 : 1 ;
1490
+ }
1491
+ break ;
1492
+ case 4 :
1493
+ if (GET_4_BYTES (values1 [i1 ]) !=
1494
+ GET_4_BYTES (values2 [i2 ]))
1495
+ {
1496
+ cmpresult = (GET_4_BYTES (values1 [i1 ]) <
1497
+ GET_4_BYTES (values2 [i2 ])) ? -1 : 1 ;
1498
+ }
1499
+ break ;
1500
+ #if SIZEOF_DATUM == 8
1501
+ case 8 :
1502
+ if (GET_8_BYTES (values1 [i1 ]) !=
1503
+ GET_8_BYTES (values2 [i2 ]))
1504
+ {
1505
+ cmpresult = (GET_8_BYTES (values1 [i1 ]) <
1506
+ GET_8_BYTES (values2 [i2 ])) ? -1 : 1 ;
1507
+ }
1508
+ break ;
1509
+ #endif
1510
+ default :
1511
+ Assert (false); /* cannot happen */
1512
+ }
1469
1513
}
1470
1514
else
1471
1515
{
@@ -1694,7 +1738,29 @@ record_image_eq(PG_FUNCTION_ARGS)
1694
1738
}
1695
1739
else if (tupdesc1 -> attrs [i1 ]-> attbyval )
1696
1740
{
1697
- result = (values1 [i1 ] == values2 [i2 ]);
1741
+ switch (tupdesc1 -> attrs [i1 ]-> attlen )
1742
+ {
1743
+ case 1 :
1744
+ result = (GET_1_BYTE (values1 [i1 ]) ==
1745
+ GET_1_BYTE (values2 [i2 ]));
1746
+ break ;
1747
+ case 2 :
1748
+ result = (GET_2_BYTES (values1 [i1 ]) ==
1749
+ GET_2_BYTES (values2 [i2 ]));
1750
+ break ;
1751
+ case 4 :
1752
+ result = (GET_4_BYTES (values1 [i1 ]) ==
1753
+ GET_4_BYTES (values2 [i2 ]));
1754
+ break ;
1755
+ #if SIZEOF_DATUM == 8
1756
+ case 8 :
1757
+ result = (GET_8_BYTES (values1 [i1 ]) ==
1758
+ GET_8_BYTES (values2 [i2 ]));
1759
+ break ;
1760
+ #endif
1761
+ default :
1762
+ Assert (false); /* cannot happen */
1763
+ }
1698
1764
}
1699
1765
else
1700
1766
{
0 commit comments