diff options
author | Michael Paquier <michael@paquier.xyz> | 2018-10-02 08:53:38 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2018-10-02 08:53:38 +0900 |
commit | e3a25ab9ea56ac540dc683cdf6f6a4b923bd22be (patch) | |
tree | 6874587914dfa46e9a4911302fe05dd52a99939b /src/backend/commands/analyze.c | |
parent | cf3dfea45b13662b3c23d7c481a9f77d67e77c45 (diff) | |
download | postgresql-e3a25ab9ea56ac540dc683cdf6f6a4b923bd22be.tar.gz postgresql-e3a25ab9ea56ac540dc683cdf6f6a4b923bd22be.zip |
Refactor relation opening for VACUUM and ANALYZE
VACUUM and ANALYZE share similar logic when it comes to opening a
relation to work on in terms of how the relation is opened, in which
order locks are tried and how logs should be generated when something
does not work as expected.
This commit refactors things so as both use the same code path to handle
the way a relation is opened, so as the integration of new options
becomes easier.
Author: Michael Paquier
Reviewed-by: Nathan Bossart
Discussion: https://postgr.es/m/20180927075152.GT1659@paquier.xyz
Diffstat (limited to 'src/backend/commands/analyze.c')
-rw-r--r-- | src/backend/commands/analyze.c | 55 |
1 files changed, 6 insertions, 49 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index d11b559b20a..da757f09747 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -120,7 +120,6 @@ analyze_rel(Oid relid, RangeVar *relation, int options, int elevel; AcquireSampleRowsFunc acquirefunc = NULL; BlockNumber relpages = 0; - bool rel_lock = true; /* Select logging level */ if (options & VACOPT_VERBOSE) @@ -142,58 +141,16 @@ analyze_rel(Oid relid, RangeVar *relation, int options, * concurrent VACUUM, which doesn't matter much at the moment but might * matter if we ever try to accumulate stats on dead tuples.) If the rel * has been dropped since we last saw it, we don't need to process it. + * + * Make sure to generate only logs for ANALYZE in this case. */ - if (!(options & VACOPT_SKIP_LOCKED)) - onerel = try_relation_open(relid, ShareUpdateExclusiveLock); - else if (ConditionalLockRelationOid(relid, ShareUpdateExclusiveLock)) - onerel = try_relation_open(relid, NoLock); - else - { - onerel = NULL; - rel_lock = false; - } + onerel = vacuum_open_relation(relid, relation, params, + options & ~(VACOPT_VACUUM), + ShareUpdateExclusiveLock); - /* - * If we failed to open or lock the relation, emit a log message before - * exiting. - */ + /* leave if relation could not be opened or locked */ if (!onerel) - { - /* - * If the RangeVar is not defined, we do not have enough information - * to provide a meaningful log statement. Chances are that - * analyze_rel's caller has intentionally not provided this - * information so that this logging is skipped, anyway. - */ - if (relation == NULL) - return; - - /* - * Determine the log level. For autovacuum logs, we emit a LOG if - * log_autovacuum_min_duration is not disabled. For manual ANALYZE, - * we emit a WARNING to match the log statements in the permissions - * checks. - */ - if (!IsAutoVacuumWorkerProcess()) - elevel = WARNING; - else if (params->log_min_duration >= 0) - elevel = LOG; - else - return; - - if (!rel_lock) - ereport(elevel, - (errcode(ERRCODE_LOCK_NOT_AVAILABLE), - errmsg("skipping analyze of \"%s\" --- lock not available", - relation->relname))); - else - ereport(elevel, - (errcode(ERRCODE_UNDEFINED_TABLE), - errmsg("skipping analyze of \"%s\" --- relation no longer exists", - relation->relname))); - return; - } /* * Check if relation needs to be skipped based on ownership. This check |