mirror of
https://github.com/postgres/postgres.git
synced 2025-07-26 01:22:12 +03:00
Be more careful about marking catalog columns NOT NULL by default.
The bug fixed in commit 72eab84a5
would not have occurred if initdb
had a less surprising rule about which columns should be marked
NOT NULL by default. Let's make that rule be strictly that the
column must be fixed-width and its predecessors must be fixed-width
and NOT NULL, removing the hacky and unsafe exceptions for oidvector
and int2vector.
Since we do still want all existing oidvector and int2vector columns
to be marked NOT NULL, we have to put BKI_FORCE_NOT_NULL labels on
them. But making this less magic and more documented seems like a
good idea, even if it's a shade more verbose.
I didn't bump catversion since the initial catalog contents are
not actually changed by this patch. Note however that the
contents of postgres.bki do change, and feeding an old copy of
that to a new backend will produce wrong results.
Discussion: https://postgr.es/m/204760.1595181800@sss.pgh.pa.us
This commit is contained in:
@ -770,25 +770,18 @@ DefineAttr(char *name, char *type, int attnum, int nullness)
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* likewise fixed-width and not-null. This corresponds to case where
|
||||
* column can be accessed directly via C struct declaration.
|
||||
*/
|
||||
#define MARKNOTNULL(att) \
|
||||
((att)->attlen > 0 || \
|
||||
(att)->atttypid == OIDVECTOROID || \
|
||||
(att)->atttypid == INT2VECTOROID)
|
||||
|
||||
if (MARKNOTNULL(attrtypes[attnum]))
|
||||
if (attrtypes[attnum]->attlen > 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* check earlier attributes */
|
||||
for (i = 0; i < attnum; i++)
|
||||
{
|
||||
if (!attrtypes[i]->attnotnull)
|
||||
if (attrtypes[i]->attlen <= 0 ||
|
||||
!attrtypes[i]->attnotnull)
|
||||
break;
|
||||
}
|
||||
if (i == attnum)
|
||||
|
Reference in New Issue
Block a user