Skip to content

Commit f3b421d

Browse files
committed
Reorder pg_sequence columns to avoid alignment issue
On AIX, doubles are aligned at 4 bytes, but int64 is aligned at 8 bytes. Our code assumes that doubles have alignment that can also be applied to int64, but that fails in this case. One effect is that heap_form_tuple() writes tuples in a different layout than Form_pg_sequence expects. Rather than rewrite the whole alignment code, work around the issue by reordering the columns in pg_sequence so that the first int64 column naturally comes out at an 8-byte boundary.
1 parent ecbdc4c commit f3b421d

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

doc/src/sgml/catalogs.sgml

+7-7
Original file line numberDiff line numberDiff line change
@@ -5627,6 +5627,13 @@
56275627
<entry>The OID of the <structname>pg_class</> entry for this sequence</entry>
56285628
</row>
56295629

5630+
<row>
5631+
<entry><structfield>seqcycle</structfield></entry>
5632+
<entry><type>bool</type></entry>
5633+
<entry></entry>
5634+
<entry>Whether the sequence cycles</entry>
5635+
</row>
5636+
56305637
<row>
56315638
<entry><structfield>seqstart</structfield></entry>
56325639
<entry><type>int8</type></entry>
@@ -5661,13 +5668,6 @@
56615668
<entry></entry>
56625669
<entry>Cache size of the sequence</entry>
56635670
</row>
5664-
5665-
<row>
5666-
<entry><structfield>seqcycle</structfield></entry>
5667-
<entry><type>bool</type></entry>
5668-
<entry></entry>
5669-
<entry>Whether the sequence cycles</entry>
5670-
</row>
56715671
</tbody>
56725672
</tgroup>
56735673
</table>

src/backend/commands/sequence.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
227227
memset(pgs_nulls, 0, sizeof(pgs_nulls));
228228

229229
pgs_values[Anum_pg_sequence_seqrelid - 1] = ObjectIdGetDatum(seqoid);
230+
pgs_values[Anum_pg_sequence_seqcycle - 1] = BoolGetDatum(seqform.seqcycle);
230231
pgs_values[Anum_pg_sequence_seqstart - 1] = Int64GetDatumFast(seqform.seqstart);
231232
pgs_values[Anum_pg_sequence_seqincrement - 1] = Int64GetDatumFast(seqform.seqincrement);
232233
pgs_values[Anum_pg_sequence_seqmax - 1] = Int64GetDatumFast(seqform.seqmax);
233234
pgs_values[Anum_pg_sequence_seqmin - 1] = Int64GetDatumFast(seqform.seqmin);
234235
pgs_values[Anum_pg_sequence_seqcache - 1] = Int64GetDatumFast(seqform.seqcache);
235-
pgs_values[Anum_pg_sequence_seqcycle - 1] = BoolGetDatum(seqform.seqcycle);
236236

237237
tuple = heap_form_tuple(tupDesc, pgs_values, pgs_nulls);
238238
simple_heap_insert(rel, tuple);
@@ -622,11 +622,11 @@ nextval_internal(Oid relid)
622622
if (!HeapTupleIsValid(pgstuple))
623623
elog(ERROR, "cache lookup failed for sequence %u", relid);
624624
pgsform = (Form_pg_sequence) GETSTRUCT(pgstuple);
625+
cycle = pgsform->seqcycle;
625626
incby = pgsform->seqincrement;
626627
maxv = pgsform->seqmax;
627628
minv = pgsform->seqmin;
628629
cache = pgsform->seqcache;
629-
cycle = pgsform->seqcycle;
630630
ReleaseSysCache(pgstuple);
631631

632632
/* lock page' buffer and read tuple */

src/include/catalog/catversion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201612201
56+
#define CATALOG_VERSION_NO 201612202
5757

5858
#endif

src/include/catalog/pg_sequence.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88
CATALOG(pg_sequence,2224) BKI_WITHOUT_OIDS
99
{
1010
Oid seqrelid;
11+
bool seqcycle;
1112
int64 seqstart;
1213
int64 seqincrement;
1314
int64 seqmax;
1415
int64 seqmin;
1516
int64 seqcache;
16-
bool seqcycle;
1717
} FormData_pg_sequence;
1818

1919
typedef FormData_pg_sequence *Form_pg_sequence;
2020

2121
#define Natts_pg_sequence 7
2222
#define Anum_pg_sequence_seqrelid 1
23-
#define Anum_pg_sequence_seqstart 2
24-
#define Anum_pg_sequence_seqincrement 3
25-
#define Anum_pg_sequence_seqmax 4
26-
#define Anum_pg_sequence_seqmin 5
27-
#define Anum_pg_sequence_seqcache 6
28-
#define Anum_pg_sequence_seqcycle 7
23+
#define Anum_pg_sequence_seqcycle 2
24+
#define Anum_pg_sequence_seqstart 3
25+
#define Anum_pg_sequence_seqincrement 4
26+
#define Anum_pg_sequence_seqmax 5
27+
#define Anum_pg_sequence_seqmin 6
28+
#define Anum_pg_sequence_seqcache 7
2929

3030
#endif /* PG_SEQUENCE_H */

0 commit comments

Comments
 (0)