On 21/08/2018 17:38, Peter Eisentraut wrote: > On 20/08/2018 15:14, Tom Lane wrote: >> I agree this is all moot as long as there's no pad bytes. What I'm >> trying to figure out is if we need to put in place some provisions >> to prevent there from being pad bytes at the end of any catalog struct. >> According to what Andres is saying, it seems like we do (at least for >> ones with varlena fields). > > Yes, I think there could be a problem. I took a brief look through the > catalogs, and while there are plenty of catalogs with trailing padding, > finding that in combination with trailing varlena fields that might > legitimately be all null in practice might require a closer look.
Looking into this a bit more, a few catalogs could use some BKI_FORCE_NOT_NULL settings, which then avoids the described situation. See attached patch. That leaves pg_constraint and pg_event_trigger where you can construct legitimate tuples where the fixed portion has trailing padding and the variable fields can all be null. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From db8534ddab46560ea870b3197db22a9b3b2ab551 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <pete...@gmx.net> Date: Fri, 24 Aug 2018 16:33:55 +0200 Subject: [PATCH] Add some not null constraints to catalogs Use BKI_FORCE_NOT_NULL on some catalog field declarations that are never null (according to the source code that accesses them). --- src/include/catalog/pg_attrdef.h | 4 ++-- src/include/catalog/pg_default_acl.h | 2 +- src/include/catalog/pg_policy.h | 2 +- src/include/catalog/pg_rewrite.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/include/catalog/pg_attrdef.h b/src/include/catalog/pg_attrdef.h index 68800ffd8e..e4a37ec326 100644 --- a/src/include/catalog/pg_attrdef.h +++ b/src/include/catalog/pg_attrdef.h @@ -32,8 +32,8 @@ CATALOG(pg_attrdef,2604,AttrDefaultRelationId) int16 adnum; /* attnum of attribute */ #ifdef CATALOG_VARLEN /* variable-length fields start here */ - pg_node_tree adbin; /* nodeToString representation of default */ - text adsrc; /* human-readable representation of default */ + pg_node_tree adbin BKI_FORCE_NOT_NULL; /* nodeToString representation of default */ + text adsrc BKI_FORCE_NOT_NULL; /* human-readable representation of default */ #endif } FormData_pg_attrdef; diff --git a/src/include/catalog/pg_default_acl.h b/src/include/catalog/pg_default_acl.h index d0410f5586..aee49fdb6d 100644 --- a/src/include/catalog/pg_default_acl.h +++ b/src/include/catalog/pg_default_acl.h @@ -34,7 +34,7 @@ CATALOG(pg_default_acl,826,DefaultAclRelationId) char defaclobjtype; /* see DEFACLOBJ_xxx constants below */ #ifdef CATALOG_VARLEN /* variable-length fields start here */ - aclitem defaclacl[1]; /* permissions to add at CREATE time */ + aclitem defaclacl[1] BKI_FORCE_NOT_NULL; /* permissions to add at CREATE time */ #endif } FormData_pg_default_acl; diff --git a/src/include/catalog/pg_policy.h b/src/include/catalog/pg_policy.h index ea3765b1cb..0dd9c50e53 100644 --- a/src/include/catalog/pg_policy.h +++ b/src/include/catalog/pg_policy.h @@ -34,7 +34,7 @@ CATALOG(pg_policy,3256,PolicyRelationId) bool polpermissive; /* restrictive or permissive policy */ #ifdef CATALOG_VARLEN - Oid polroles[1]; /* Roles associated with policy, not-NULL */ + Oid polroles[1] BKI_FORCE_NOT_NULL; /* Roles associated with policy */ pg_node_tree polqual; /* Policy quals. */ pg_node_tree polwithcheck; /* WITH CHECK quals. */ #endif diff --git a/src/include/catalog/pg_rewrite.h b/src/include/catalog/pg_rewrite.h index a385445884..0e50b87926 100644 --- a/src/include/catalog/pg_rewrite.h +++ b/src/include/catalog/pg_rewrite.h @@ -38,8 +38,8 @@ CATALOG(pg_rewrite,2618,RewriteRelationId) bool is_instead; #ifdef CATALOG_VARLEN /* variable-length fields start here */ - pg_node_tree ev_qual; - pg_node_tree ev_action; + pg_node_tree ev_qual BKI_FORCE_NOT_NULL; + pg_node_tree ev_action BKI_FORCE_NOT_NULL; #endif } FormData_pg_rewrite; -- 2.18.0