Commit f3b421da authored by Peter Eisentraut's avatar Peter Eisentraut

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.
parent ecbdc4c5
...@@ -5627,6 +5627,13 @@ ...@@ -5627,6 +5627,13 @@
<entry>The OID of the <structname>pg_class</> entry for this sequence</entry> <entry>The OID of the <structname>pg_class</> entry for this sequence</entry>
</row> </row>
<row>
<entry><structfield>seqcycle</structfield></entry>
<entry><type>bool</type></entry>
<entry></entry>
<entry>Whether the sequence cycles</entry>
</row>
<row> <row>
<entry><structfield>seqstart</structfield></entry> <entry><structfield>seqstart</structfield></entry>
<entry><type>int8</type></entry> <entry><type>int8</type></entry>
...@@ -5661,13 +5668,6 @@ ...@@ -5661,13 +5668,6 @@
<entry></entry> <entry></entry>
<entry>Cache size of the sequence</entry> <entry>Cache size of the sequence</entry>
</row> </row>
<row>
<entry><structfield>seqcycle</structfield></entry>
<entry><type>bool</type></entry>
<entry></entry>
<entry>Whether the sequence cycles</entry>
</row>
</tbody> </tbody>
</tgroup> </tgroup>
</table> </table>
......
...@@ -227,12 +227,12 @@ DefineSequence(ParseState *pstate, CreateSeqStmt *seq) ...@@ -227,12 +227,12 @@ DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
memset(pgs_nulls, 0, sizeof(pgs_nulls)); memset(pgs_nulls, 0, sizeof(pgs_nulls));
pgs_values[Anum_pg_sequence_seqrelid - 1] = ObjectIdGetDatum(seqoid); pgs_values[Anum_pg_sequence_seqrelid - 1] = ObjectIdGetDatum(seqoid);
pgs_values[Anum_pg_sequence_seqcycle - 1] = BoolGetDatum(seqform.seqcycle);
pgs_values[Anum_pg_sequence_seqstart - 1] = Int64GetDatumFast(seqform.seqstart); pgs_values[Anum_pg_sequence_seqstart - 1] = Int64GetDatumFast(seqform.seqstart);
pgs_values[Anum_pg_sequence_seqincrement - 1] = Int64GetDatumFast(seqform.seqincrement); pgs_values[Anum_pg_sequence_seqincrement - 1] = Int64GetDatumFast(seqform.seqincrement);
pgs_values[Anum_pg_sequence_seqmax - 1] = Int64GetDatumFast(seqform.seqmax); pgs_values[Anum_pg_sequence_seqmax - 1] = Int64GetDatumFast(seqform.seqmax);
pgs_values[Anum_pg_sequence_seqmin - 1] = Int64GetDatumFast(seqform.seqmin); pgs_values[Anum_pg_sequence_seqmin - 1] = Int64GetDatumFast(seqform.seqmin);
pgs_values[Anum_pg_sequence_seqcache - 1] = Int64GetDatumFast(seqform.seqcache); pgs_values[Anum_pg_sequence_seqcache - 1] = Int64GetDatumFast(seqform.seqcache);
pgs_values[Anum_pg_sequence_seqcycle - 1] = BoolGetDatum(seqform.seqcycle);
tuple = heap_form_tuple(tupDesc, pgs_values, pgs_nulls); tuple = heap_form_tuple(tupDesc, pgs_values, pgs_nulls);
simple_heap_insert(rel, tuple); simple_heap_insert(rel, tuple);
...@@ -622,11 +622,11 @@ nextval_internal(Oid relid) ...@@ -622,11 +622,11 @@ nextval_internal(Oid relid)
if (!HeapTupleIsValid(pgstuple)) if (!HeapTupleIsValid(pgstuple))
elog(ERROR, "cache lookup failed for sequence %u", relid); elog(ERROR, "cache lookup failed for sequence %u", relid);
pgsform = (Form_pg_sequence) GETSTRUCT(pgstuple); pgsform = (Form_pg_sequence) GETSTRUCT(pgstuple);
cycle = pgsform->seqcycle;
incby = pgsform->seqincrement; incby = pgsform->seqincrement;
maxv = pgsform->seqmax; maxv = pgsform->seqmax;
minv = pgsform->seqmin; minv = pgsform->seqmin;
cache = pgsform->seqcache; cache = pgsform->seqcache;
cycle = pgsform->seqcycle;
ReleaseSysCache(pgstuple); ReleaseSysCache(pgstuple);
/* lock page' buffer and read tuple */ /* lock page' buffer and read tuple */
......
...@@ -53,6 +53,6 @@ ...@@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 201612201 #define CATALOG_VERSION_NO 201612202
#endif #endif
...@@ -8,23 +8,23 @@ ...@@ -8,23 +8,23 @@
CATALOG(pg_sequence,2224) BKI_WITHOUT_OIDS CATALOG(pg_sequence,2224) BKI_WITHOUT_OIDS
{ {
Oid seqrelid; Oid seqrelid;
bool seqcycle;
int64 seqstart; int64 seqstart;
int64 seqincrement; int64 seqincrement;
int64 seqmax; int64 seqmax;
int64 seqmin; int64 seqmin;
int64 seqcache; int64 seqcache;
bool seqcycle;
} FormData_pg_sequence; } FormData_pg_sequence;
typedef FormData_pg_sequence *Form_pg_sequence; typedef FormData_pg_sequence *Form_pg_sequence;
#define Natts_pg_sequence 7 #define Natts_pg_sequence 7
#define Anum_pg_sequence_seqrelid 1 #define Anum_pg_sequence_seqrelid 1
#define Anum_pg_sequence_seqstart 2 #define Anum_pg_sequence_seqcycle 2
#define Anum_pg_sequence_seqincrement 3 #define Anum_pg_sequence_seqstart 3
#define Anum_pg_sequence_seqmax 4 #define Anum_pg_sequence_seqincrement 4
#define Anum_pg_sequence_seqmin 5 #define Anum_pg_sequence_seqmax 5
#define Anum_pg_sequence_seqcache 6 #define Anum_pg_sequence_seqmin 6
#define Anum_pg_sequence_seqcycle 7 #define Anum_pg_sequence_seqcache 7
#endif /* PG_SEQUENCE_H */ #endif /* PG_SEQUENCE_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment