Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit61eaefe

Browse files
committed
This patch for Versions 1 and 2 corrects the following bug:
In a catalog class that has a "name" type attribute, UPDATEing of aninstance of that class may destroy all of the attributes of thatinstance that are stored as or after the "name" attribute.This is caused by the alignment value of the "name" type being set to"double" in Class pg_type, but "integer" in Class pg_attribute.Postgres constructs a tuple using double alignment, but interprets itusing integer alignment.The fix is to change the alignment to integer in pg_type.Note that this corrects the problem for new Postgres systems. Existingdatabases already contain the error and it can't easily be repaired becausethis very bug prevents updating the class that contains it.--Bryan Henderson Phone 408-227-6803San Jose, California
1 parent208a30f commit61eaefe

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

‎src/backend/catalog/pg_attribute.h‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_attribute.h,v 1.2 1996/08/21 04:25:47 scrappy Exp $
10+
* $Id: pg_attribute.h,v 1.3 1996/08/24 20:56:13 scrappy Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -44,13 +44,19 @@ CATALOG(pg_attribute) BOOTSTRAP {
4444
Oidattrelid;
4545
NameDataattname;
4646
Oidatttypid;
47+
/* atttypid is the OID of the instance in Catalog Class pg_type that
48+
defines the data type of this attribute (e.g. int4). Information in
49+
that instance is redundant with the attlen, attbyval, and attalign
50+
attributes of this instance, so they had better match or Postgres
51+
will fail.
52+
*/
4753
Oidattdefrel;
4854
int4attnvals;
4955
Oidatttyparg;/* type arg for arrays/spquel/procs */
5056
int2attlen;
51-
/* attlen isthe number ofbytes we use to represent the value
52-
of thisattribute, e.g. 4 for an int4.But for a variable length
53-
attribute, attlen is -1.
57+
/* attlen isa copy ofthe typlen field from pg_type for this
58+
attribute. See atttypid above.See struct TypeTupleFormData for
59+
definition.
5460
*/
5561
int2attnum;
5662
/* attnum is the "attribute number" for the attribute: A
@@ -68,6 +74,10 @@ CATALOG(pg_attribute) BOOTSTRAP {
6874
*/
6975
int2attbound;
7076
boolattbyval;
77+
/* attbyval is a copy of the typbyval field from pg_type for this
78+
attribute. See atttypid above. See struct TypeTupleFormData for
79+
definition.
80+
*/
7181
boolattcanindex;
7282
Oidattproc;/* spquel? */
7383
int4attnelems;
@@ -80,7 +90,11 @@ CATALOG(pg_attribute) BOOTSTRAP {
8090
walking process.
8191
*/
8292
boolattisset;
83-
charattalign;/* alignment (c=char, s=short, i=int, d=double) */
93+
charattalign;
94+
/* attalign is a copy of the typalign field from pg_type for this
95+
attribute. See atttypid above. See struct TypeTupleFormData for
96+
definition.
97+
*/
8498
}FormData_pg_attribute;
8599

86100
/*

‎src/backend/catalog/pg_type.h‎

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_type.h,v 1.3 1996/07/19 05:21:28 scrappy Exp $
10+
* $Id: pg_type.h,v 1.4 1996/08/24 20:56:16 scrappy Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -30,14 +30,34 @@
3030
/* ----------------
3131
*pg_type definition. cpp turns this into
3232
*typedef struct FormData_pg_type
33+
*
34+
* Some of the values in a pg_type instance are copied into
35+
* pg_attribute intances. Some parts of Postgres use the pg_type copy,
36+
* while others use the pg_attribute copy, so they must match.
37+
* See struct FormData_pg_attribute for details.
3338
* ----------------
3439
*/
3540
CATALOG(pg_type)BOOTSTRAP {
3641
NameDatatypname;
3742
Oidtypowner;
3843
int2typlen;
44+
/* typlen is the number of bytes we use to represent a value of
45+
this type, e.g. 4 for an int4. But for a variable length
46+
attribute, typlen is -1.
47+
*/
3948
int2typprtlen;
4049
booltypbyval;
50+
/* typbyval determines whether internal Postgres routines pass a value
51+
of this type by value or by reference. Postgres uses a 4 byte
52+
area for passing class data, so if the value is not 1, 2,
53+
or 4 bytes long, Postgres does not have the option of passing by
54+
value and ignores typbyval.
55+
56+
(I don't understand why this attribute exists. The above description
57+
may be an oversimplification. Also, there appear to be bugs in which
58+
Postgres doesn't ignore typbyval when it should, but I'm
59+
afraid to change them until I see proof of damage. -BRYANH 96.08).
60+
*/
4161
chartyptype;
4262
booltypisdefined;
4363
chartypdelim;
@@ -47,7 +67,23 @@ CATALOG(pg_type) BOOTSTRAP {
4767
regproctypoutput;
4868
regproctypreceive;
4969
regproctypsend;
50-
chartypalign;/* alignment (c=char, s=short, i=int, d=double) */
70+
chartypalign;
71+
/* typalign is the alignment required when storing a value of this
72+
type. It applies to storage on disk as well as most representations
73+
of the value inside Postgres. When multiple values are stored
74+
consecutively, such as in the representation of a complete tuple
75+
on disk, padding is inserted before a datum of this type so that it
76+
begins on the specified boundary. The alignment reference is the
77+
beginning of the first datum in the sequence.
78+
79+
'c' = 1 byte alignment.
80+
's' = 2 byte alignment.
81+
'i' = 4 byte alignment.
82+
'd' = 8 byte alignment.
83+
84+
(This might actually be flexible depending on machine architecture,
85+
but I doubt it - BRYANH 96.08).
86+
*/
5187
texttypdefault;/* VARIABLE LENGTH FIELD */
5288
}TypeTupleFormData;
5389

@@ -87,6 +123,11 @@ typedef TypeTupleFormData*TypeTupleForm;
87123

88124
/* keep the following ordered by OID so that later changes can be made easier*/
89125

126+
/* Make sure the typlen, typbyval, and typalign values here match the initial
127+
values for attlen, attbyval, and attalign in both places in pg_attribute.h
128+
for every instance.
129+
*/
130+
90131
/* OIDS 1 - 99 */
91132
DATA(insertOID=16 (boolPGUID11tbt \05400boolinbooloutboolinbooloutc_null_ ));
92133

@@ -95,7 +136,7 @@ DATA(insert OID = 16 ( bool PGUID 1 1 t b t \054 0 0 boolin boolout
95136
DATA(insertOID=17 (byteaPGUID-1-1fbt \054018byteainbyteaoutbyteainbyteaouti_null_ ));
96137
DATA(insertOID=18 (charPGUID11tbt \05400charincharoutcharincharoutc_null_ ));
97138

98-
DATA(insertOID=19 (namePGUIDNAMEDATALENNAMEDATALENfbt \054018nameinnameoutnameinnameoutd_null_ ));
139+
DATA(insertOID=19 (namePGUIDNAMEDATALENNAMEDATALENfbt \054018nameinnameoutnameinnameouti_null_ ));
99140
DATA(insertOID=20 (char16PGUID1616fbt \054018char16inchar16outchar16inchar16outi_null_ ));
100141
/*DATA(insert OID = 20 ( dt PGUID 4 10 t b t \054 0 0 dtin dtout dtin dtout i _null_ )); */
101142
DATA(insertOID=21 (int2PGUID25tbt \05400int2inint2outint2inint2outs_null_ ));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp