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