diff options
author | Andres Freund <andres@anarazel.de> | 2015-02-21 22:25:49 +0100 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2015-02-21 22:31:54 +0100 |
commit | eb68379c38202180bc8e33fb9987284e314b7fc8 (patch) | |
tree | 0e6dcc59b1fabfe9c63b0d0377607acee7dad025 /src/backend/bootstrap/bootstrap.c | |
parent | 0627eff3602c0ce0e8358d48ddb3ffa73963e4d0 (diff) | |
download | postgresql-eb68379c38202180bc8e33fb9987284e314b7fc8.tar.gz postgresql-eb68379c38202180bc8e33fb9987284e314b7fc8.zip |
Allow forcing nullness of columns during bootstrap.
Bootstrap determines whether a column is null based on simple builtin
rules. Those work surprisingly well, but nonetheless a few existing
columns aren't set correctly. Additionally there is at least one patch
sent to hackers where forcing the nullness of a column would be helpful.
The boostrap format has gained FORCE [NOT] NULL for this, which will be
emitted by genbki.pl when BKI_FORCE_(NOT_)?NULL is specified for a
column in a catalog header.
This patch doesn't change the marking of any existing columns.
Discussion: 20150215170014.GE15326@awork2.anarazel.de
Diffstat (limited to 'src/backend/bootstrap/bootstrap.c')
-rw-r--r-- | src/backend/bootstrap/bootstrap.c | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index bc66eac9848..ad49964732f 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -642,7 +642,7 @@ closerel(char *name) * ---------------- */ void -DefineAttr(char *name, char *type, int attnum) +DefineAttr(char *name, char *type, int attnum, int nullness) { Oid typeoid; @@ -697,30 +697,44 @@ DefineAttr(char *name, char *type, int attnum) attrtypes[attnum]->atttypmod = -1; attrtypes[attnum]->attislocal = true; - /* - * Mark as "not null" if type is fixed-width and prior columns are too. - * This corresponds to case where column can be accessed directly via C - * struct declaration. - * - * oidvector and int2vector are also treated as not-nullable, even though - * they are no longer fixed-width. - */ -#define MARKNOTNULL(att) \ - ((att)->attlen > 0 || \ - (att)->atttypid == OIDVECTOROID || \ - (att)->atttypid == INT2VECTOROID) - - if (MARKNOTNULL(attrtypes[attnum])) + if (nullness == BOOTCOL_NULL_FORCE_NOT_NULL) + { + attrtypes[attnum]->attnotnull = true; + } + else if (nullness == BOOTCOL_NULL_FORCE_NULL) { - int i; + attrtypes[attnum]->attnotnull = false; + } + else + { + Assert(nullness == BOOTCOL_NULL_AUTO); - for (i = 0; i < attnum; i++) + /* + * Mark as "not null" if type is fixed-width and prior columns are + * too. This corresponds to case where column can be accessed + * directly via C struct declaration. + * + * oidvector and int2vector are also treated as not-nullable, even + * though they are no longer fixed-width. + */ +#define MARKNOTNULL(att) \ + ((att)->attlen > 0 || \ + (att)->atttypid == OIDVECTOROID || \ + (att)->atttypid == INT2VECTOROID) + + if (MARKNOTNULL(attrtypes[attnum])) { - if (!MARKNOTNULL(attrtypes[i])) - break; + int i; + + /* check earlier attributes */ + for (i = 0; i < attnum; i++) + { + if (!attrtypes[i]->attnotnull) + break; + } + if (i == attnum) + attrtypes[attnum]->attnotnull = true; } - if (i == attnum) - attrtypes[attnum]->attnotnull = true; } } |