Skip to content

Commit b526462

Browse files
committed
Avoid assuming that struct varattrib_pointer doesn't get padded by the
compiler --- at least on ARM, it does. I suspect that the varvarlena patch has been creating larger-than-intended toast pointers all along on ARM, but it wasn't exposed until the latest tweak added some Asserts that calculated the expected size in a different way. We could probably have fixed this by adding __attribute__((packed)) as is done for ItemPointerData, but struct varattrib_pointer isn't really all that useful anyway, so it seems cleanest to just get rid of it and have only struct varattrib_1b_e. Per results from buildfarm member quagga.
1 parent b8ce3d3 commit b526462

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/backend/access/heap/tuptoaster.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.76 2007/09/30 19:54:58 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.77 2007/10/01 16:25:56 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -42,6 +42,9 @@
4242

4343
#undef TOAST_DEBUG
4444

45+
/* Size of an EXTERNAL datum that contains a standard TOAST pointer */
46+
#define TOAST_POINTER_SIZE (VARHDRSZ_EXTERNAL + sizeof(struct varatt_external))
47+
4548
/*
4649
* Testing whether an externally-stored value is compressed now requires
4750
* comparing extsize (the actual length of the external data) to rawsize
@@ -597,7 +600,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
597600
toast_values, toast_isnull) > maxDataLen)
598601
{
599602
int biggest_attno = -1;
600-
int32 biggest_size = MAXALIGN(sizeof(varattrib_pointer));
603+
int32 biggest_size = MAXALIGN(TOAST_POINTER_SIZE);
601604
Datum old_value;
602605
Datum new_value;
603606

@@ -660,7 +663,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
660663
rel->rd_rel->reltoastrelid != InvalidOid)
661664
{
662665
int biggest_attno = -1;
663-
int32 biggest_size = MAXALIGN(sizeof(varattrib_pointer));
666+
int32 biggest_size = MAXALIGN(TOAST_POINTER_SIZE);
664667
Datum old_value;
665668

666669
/*------
@@ -710,7 +713,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
710713
toast_values, toast_isnull) > maxDataLen)
711714
{
712715
int biggest_attno = -1;
713-
int32 biggest_size = MAXALIGN(sizeof(varattrib_pointer));
716+
int32 biggest_size = MAXALIGN(TOAST_POINTER_SIZE);
714717
Datum old_value;
715718
Datum new_value;
716719

@@ -772,7 +775,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
772775
rel->rd_rel->reltoastrelid != InvalidOid)
773776
{
774777
int biggest_attno = -1;
775-
int32 biggest_size = MAXALIGN(sizeof(varattrib_pointer));
778+
int32 biggest_size = MAXALIGN(TOAST_POINTER_SIZE);
776779
Datum old_value;
777780

778781
/*--------
@@ -1085,7 +1088,7 @@ toast_save_datum(Relation rel, Datum value,
10851088
Datum t_values[3];
10861089
bool t_isnull[3];
10871090
CommandId mycid = GetCurrentCommandId();
1088-
varattrib_pointer *result;
1091+
struct varlena *result;
10891092
struct varatt_external toast_pointer;
10901093
struct
10911094
{
@@ -1206,8 +1209,8 @@ toast_save_datum(Relation rel, Datum value,
12061209
/*
12071210
* Create the TOAST pointer value that we'll return
12081211
*/
1209-
result = (varattrib_pointer *) palloc(sizeof(varattrib_pointer));
1210-
SET_VARSIZE_EXTERNAL(result, sizeof(varattrib_pointer));
1212+
result = (struct varlena *) palloc(TOAST_POINTER_SIZE);
1213+
SET_VARSIZE_EXTERNAL(result, TOAST_POINTER_SIZE);
12111214
memcpy(VARDATA_EXTERNAL(result), &toast_pointer, sizeof(toast_pointer));
12121215

12131216
return PointerGetDatum(result);

src/include/postgres.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
1111
* Portions Copyright (c) 1995, Regents of the University of California
1212
*
13-
* $PostgreSQL: pgsql/src/include/postgres.h,v 1.84 2007/09/30 19:54:58 tgl Exp $
13+
* $PostgreSQL: pgsql/src/include/postgres.h,v 1.85 2007/10/01 16:25:56 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -110,13 +110,6 @@ typedef struct
110110
char va_data[1]; /* Data (for now always a TOAST pointer) */
111111
} varattrib_1b_e;
112112

113-
typedef struct
114-
{
115-
uint8 va_header; /* Always 0x80 or 0x01 */
116-
uint8 va_len_1be; /* Physical length of datum */
117-
char va_data[sizeof(struct varatt_external)];
118-
} varattrib_pointer;
119-
120113
/*
121114
* Bit layouts for varlena headers on big-endian machines:
122115
*
@@ -225,6 +218,8 @@ typedef struct
225218
#define VARATT_CONVERTED_SHORT_SIZE(PTR) \
226219
(VARSIZE(PTR) - VARHDRSZ + VARHDRSZ_SHORT)
227220

221+
#define VARHDRSZ_EXTERNAL 2
222+
228223
#define VARDATA_4B(PTR) (((varattrib_4b *) (PTR))->va_4byte.va_data)
229224
#define VARDATA_4B_C(PTR) (((varattrib_4b *) (PTR))->va_compressed.va_data)
230225
#define VARDATA_1B(PTR) (((varattrib_1b *) (PTR))->va_data)
@@ -276,9 +271,9 @@ typedef struct
276271
VARSIZE_4B(PTR)))
277272

278273
#define VARSIZE_ANY_EXHDR(PTR) \
279-
(VARATT_IS_1B_E(PTR) ? VARSIZE_1B_E(PTR)-2 : \
280-
(VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR)-1 : \
281-
VARSIZE_4B(PTR)-4))
274+
(VARATT_IS_1B_E(PTR) ? VARSIZE_1B_E(PTR)-VARHDRSZ_EXTERNAL : \
275+
(VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR)-VARHDRSZ_SHORT : \
276+
VARSIZE_4B(PTR)-VARHDRSZ))
282277

283278
/* caution: this will not work on an external or compressed-in-line Datum */
284279
/* caution: this will return a possibly unaligned pointer */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy