pg_dump: minor performance improvements from eliminating sub-SELECTs.

Get rid of the "username_subquery" mechanism in favor of doing
local lookups of role names from role OIDs.  The PG backend isn't
terribly smart about scalar SubLinks in SELECT output lists,
so this offers a small performance improvement, at least in
installations with more than a couple of users.  In any case
the old method didn't make for particularly readable SQL code.

While at it, I removed the various custom warning messages about
failing to find an object's owner, in favor of just fatal'ing
in the local lookup function.  AFAIK there is no reason any
longer to treat that as anything but a catalog-corruption case,
and certainly no reason to make translators deal with a dozen
different messages where one would do.  (If it turns out that
fatal() is indeed a bad idea, we can back off to issuing
pg_log_warning() and returning an empty string, resulting in
the same behavior as before, except more consistent.)

Also drop an entirely unnecessary sub-SELECT to check on the
pg_depend status of a sequence relation: we already have a
LEFT JOIN to fetch the row of interest in the FROM clause.

Discussion: https://postgr.es/m/2460369.1640903318@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2021-12-31 11:39:26 -05:00
parent 93d9734946
commit d5e8930f50
2 changed files with 217 additions and 214 deletions

File diff suppressed because it is too large Load Diff

View File

@ -171,8 +171,8 @@ typedef struct _namespaceInfo
DumpableObject dobj; DumpableObject dobj;
DumpableAcl dacl; DumpableAcl dacl;
bool create; /* CREATE SCHEMA, or just set owner? */ bool create; /* CREATE SCHEMA, or just set owner? */
Oid nspowner; Oid nspowner; /* OID of owner */
char *rolname; /* name of owner, or empty string */ const char *rolname; /* name of owner */
} NamespaceInfo; } NamespaceInfo;
typedef struct _extensionInfo typedef struct _extensionInfo
@ -196,7 +196,7 @@ typedef struct _typeInfo
* schema-qualified too. * schema-qualified too.
*/ */
char *ftypname; char *ftypname;
char *rolname; /* name of owner, or empty string */ const char *rolname;
Oid typelem; Oid typelem;
Oid typrelid; Oid typrelid;
char typrelkind; /* 'r', 'v', 'c', etc */ char typrelkind; /* 'r', 'v', 'c', etc */
@ -222,7 +222,7 @@ typedef struct _funcInfo
{ {
DumpableObject dobj; DumpableObject dobj;
DumpableAcl dacl; DumpableAcl dacl;
char *rolname; /* name of owner, or empty string */ const char *rolname;
Oid lang; Oid lang;
int nargs; int nargs;
Oid *argtypes; Oid *argtypes;
@ -239,7 +239,7 @@ typedef struct _aggInfo
typedef struct _oprInfo typedef struct _oprInfo
{ {
DumpableObject dobj; DumpableObject dobj;
char *rolname; const char *rolname;
char oprkind; char oprkind;
Oid oprcode; Oid oprcode;
} OprInfo; } OprInfo;
@ -254,25 +254,25 @@ typedef struct _accessMethodInfo
typedef struct _opclassInfo typedef struct _opclassInfo
{ {
DumpableObject dobj; DumpableObject dobj;
char *rolname; const char *rolname;
} OpclassInfo; } OpclassInfo;
typedef struct _opfamilyInfo typedef struct _opfamilyInfo
{ {
DumpableObject dobj; DumpableObject dobj;
char *rolname; const char *rolname;
} OpfamilyInfo; } OpfamilyInfo;
typedef struct _collInfo typedef struct _collInfo
{ {
DumpableObject dobj; DumpableObject dobj;
char *rolname; const char *rolname;
} CollInfo; } CollInfo;
typedef struct _convInfo typedef struct _convInfo
{ {
DumpableObject dobj; DumpableObject dobj;
char *rolname; const char *rolname;
} ConvInfo; } ConvInfo;
typedef struct _tableInfo typedef struct _tableInfo
@ -282,7 +282,7 @@ typedef struct _tableInfo
*/ */
DumpableObject dobj; DumpableObject dobj;
DumpableAcl dacl; DumpableAcl dacl;
char *rolname; /* name of owner, or empty string */ const char *rolname;
char relkind; char relkind;
char relpersistence; /* relation persistence */ char relpersistence; /* relation persistence */
bool relispopulated; /* relation is populated */ bool relispopulated; /* relation is populated */
@ -415,7 +415,7 @@ typedef struct _indexAttachInfo
typedef struct _statsExtInfo typedef struct _statsExtInfo
{ {
DumpableObject dobj; DumpableObject dobj;
char *rolname; /* name of owner, or empty string */ const char *rolname;
int stattarget; /* statistics target */ int stattarget; /* statistics target */
} StatsExtInfo; } StatsExtInfo;
@ -454,7 +454,7 @@ typedef struct _evttriggerInfo
DumpableObject dobj; DumpableObject dobj;
char *evtname; char *evtname;
char *evtevent; char *evtevent;
char *evtowner; const char *evtowner;
char *evttags; char *evttags;
char *evtfname; char *evtfname;
char evtenabled; char evtenabled;
@ -491,7 +491,7 @@ typedef struct _procLangInfo
Oid lanplcallfoid; Oid lanplcallfoid;
Oid laninline; Oid laninline;
Oid lanvalidator; Oid lanvalidator;
char *lanowner; /* name of owner, or empty string */ const char *lanowner;
} ProcLangInfo; } ProcLangInfo;
typedef struct _castInfo typedef struct _castInfo
@ -533,7 +533,7 @@ typedef struct _prsInfo
typedef struct _dictInfo typedef struct _dictInfo
{ {
DumpableObject dobj; DumpableObject dobj;
char *rolname; const char *rolname;
Oid dicttemplate; Oid dicttemplate;
char *dictinitoption; char *dictinitoption;
} TSDictInfo; } TSDictInfo;
@ -548,7 +548,7 @@ typedef struct _tmplInfo
typedef struct _cfgInfo typedef struct _cfgInfo
{ {
DumpableObject dobj; DumpableObject dobj;
char *rolname; const char *rolname;
Oid cfgparser; Oid cfgparser;
} TSConfigInfo; } TSConfigInfo;
@ -556,7 +556,7 @@ typedef struct _fdwInfo
{ {
DumpableObject dobj; DumpableObject dobj;
DumpableAcl dacl; DumpableAcl dacl;
char *rolname; const char *rolname;
char *fdwhandler; char *fdwhandler;
char *fdwvalidator; char *fdwvalidator;
char *fdwoptions; char *fdwoptions;
@ -566,7 +566,7 @@ typedef struct _foreignServerInfo
{ {
DumpableObject dobj; DumpableObject dobj;
DumpableAcl dacl; DumpableAcl dacl;
char *rolname; const char *rolname;
Oid srvfdw; Oid srvfdw;
char *srvtype; char *srvtype;
char *srvversion; char *srvversion;
@ -577,7 +577,7 @@ typedef struct _defaultACLInfo
{ {
DumpableObject dobj; DumpableObject dobj;
DumpableAcl dacl; DumpableAcl dacl;
char *defaclrole; const char *defaclrole;
char defaclobjtype; char defaclobjtype;
} DefaultACLInfo; } DefaultACLInfo;
@ -585,7 +585,7 @@ typedef struct _blobInfo
{ {
DumpableObject dobj; DumpableObject dobj;
DumpableAcl dacl; DumpableAcl dacl;
char *rolname; const char *rolname;
} BlobInfo; } BlobInfo;
/* /*
@ -612,7 +612,7 @@ typedef struct _policyInfo
typedef struct _PublicationInfo typedef struct _PublicationInfo
{ {
DumpableObject dobj; DumpableObject dobj;
char *rolname; const char *rolname;
bool puballtables; bool puballtables;
bool pubinsert; bool pubinsert;
bool pubupdate; bool pubupdate;
@ -649,7 +649,7 @@ typedef struct _PublicationSchemaInfo
typedef struct _SubscriptionInfo typedef struct _SubscriptionInfo
{ {
DumpableObject dobj; DumpableObject dobj;
char *rolname; const char *rolname;
char *subconninfo; char *subconninfo;
char *subslotname; char *subslotname;
char *subbinary; char *subbinary;