From: Teodor Sigaev Date: Mon, 22 Jul 2019 11:46:03 +0000 (+0300) Subject: ready for v12 X-Git-Url: http://sigaev.ru/git/gitweb.cgi?a=commitdiff_plain;h=d692451b9debfff2d23b86620a5de8d53b7e6903;p=online_analyze.git ready for v12 --- diff --git a/online_analyze.c b/online_analyze.c index 90f261c..58ac74f 100644 --- a/online_analyze.c +++ b/online_analyze.c @@ -77,6 +77,10 @@ static ExecutorEnd_hook_type oldExecutorEndHook = NULL; static ProcessUtility_hook_type oldProcessUtilityHook = NULL; #endif +#if PG_VERSION_NUM >= 120000 +#define VACOPT_NOWAIT VACOPT_SKIP_LOCKED +#endif + typedef enum CmdKind { CK_SELECT = CMD_SELECT, @@ -513,6 +517,7 @@ makeAnalyze(Oid relOid, CmdKind operation, int64 naffected) VacuumParams vacstmt; #endif TimestampTz startStamp, endStamp; + int flags; memset(&startStamp, 0, sizeof(startStamp)); /* keep compiler quiet */ @@ -541,9 +546,16 @@ makeAnalyze(Oid relOid, CmdKind operation, int64 naffected) vacstmt.log_min_duration = -1; #endif + if (online_analyze_verbose) startStamp = GetCurrentTimestamp(); + flags = VACOPT_ANALYZE | VACOPT_NOWAIT | + ((online_analyze_verbose) ? VACOPT_VERBOSE : 0); + +#if PG_VERSION_NUM >= 120000 + vacstmt.options = flags; +#endif analyze_rel(relOid, #if PG_VERSION_NUM < 90500 &vacstmt @@ -556,7 +568,9 @@ makeAnalyze(Oid relOid, CmdKind operation, int64 naffected) #endif #else makeRangeVarFromOid(relOid), - VACOPT_ANALYZE | VACOPT_NOWAIT | ((online_analyze_verbose) ? VACOPT_VERBOSE : 0), +#if PG_VERSION_NUM < 120000 + flags, +#endif &vacstmt, NULL, true, GetAccessStrategy(BAS_VACUUM) #endif ); @@ -786,6 +800,36 @@ removeTable(XactEvent event, void *arg) toremove = NIL; } +#if PG_VERSION_NUM >= 120000 +static int +parse_vacuum_opt(VacuumStmt *vacstmt) +{ + int options = vacstmt->is_vacuumcmd ? VACOPT_VACUUM : VACOPT_ANALYZE; + ListCell *lc; + + foreach(lc, vacstmt->options) + { + DefElem *opt = (DefElem *) lfirst(lc); + + /* Parse common options for VACUUM and ANALYZE */ + if (strcmp(opt->defname, "verbose") == 0) + options |= VACOPT_VERBOSE; + else if (strcmp(opt->defname, "skip_locked") == 0) + options |= VACOPT_SKIP_LOCKED; + else if (strcmp(opt->defname, "analyze") == 0) + options |= VACOPT_ANALYZE; + else if (strcmp(opt->defname, "freeze") == 0) + options |= VACOPT_FREEZE; + else if (strcmp(opt->defname, "full") == 0) + options |= VACOPT_FULL; + else if (strcmp(opt->defname, "disable_page_skipping") == 0) + options |= VACOPT_DISABLE_PAGE_SKIPPING; + } + + return options; +} +#endif + #if PG_VERSION_NUM >= 90200 static void @@ -852,6 +896,14 @@ onlineAnalyzeHookerUtility( else if (IsA(parsetree, VacuumStmt)) { VacuumStmt *vac = (VacuumStmt*)parsetree; + int options = +#if PG_VERSION_NUM >= 120000 + parse_vacuum_opt(vac) +#else + vac->options +#endif + ; + #if PG_VERSION_NUM >= 110000 tblnames = vac->rels; @@ -860,7 +912,7 @@ onlineAnalyzeHookerUtility( tblnames = list_make1(vac->relation); #endif - if (vac->options & (VACOPT_VACUUM | VACOPT_FULL | VACOPT_FREEZE)) + if (options & (VACOPT_VACUUM | VACOPT_FULL | VACOPT_FREEZE)) { /* optionally with analyze */ op = CK_VACUUM; @@ -869,7 +921,7 @@ onlineAnalyzeHookerUtility( if (tblnames == NIL) relstatsInit(); } - else if (vac->options & VACOPT_ANALYZE) + else if (options & VACOPT_ANALYZE) { op = CK_ANALYZE;