Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8sJr-0000UE-FE for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Mar 2019 20:05:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h8sJo-0007D2-Vo for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Mar 2019 20:05:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8sJo-00077Z-CQ for pgsql-hackers@lists.postgresql.org; Tue, 26 Mar 2019 20:05:08 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8sJg-0002DV-0g for pgsql-hackers@postgresql.org; Tue, 26 Mar 2019 20:05:06 +0000 Received: by mail-wm1-x342.google.com with SMTP id z24so11103110wmi.5 for ; Tue, 26 Mar 2019 13:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=KmHioDNm30peoUp9ZVyh4zl9eWidxUVBSh2HEqx69Bo=; b=aIFW193aoU8aTlv2jAx3OFEPupk/u7tF5hwS8/zq1ZrMr3wyvkVDVzask/mlLH2l8c fnVJDVSv7B4jL2uNwksou7AIX/mVeZ9H1KWrER/Q7ojxwKfQYofmQkPmQ/A3bnpvXXXT lhTGqXZnQ58K93TL93H/yDn6TDQUJ2+HDqsibWYhVKUaHxgfnjgLCziUVJDmibcSM1Lh L1u1NT+T4s/hR2J33TuYLyTTLgHfkFyh/3JDms8lPb/QTOoF+lTLUqBY+O/+WuYw0ICo Njua/N41k+HOK9UbR7P4s6iywf76QUZVPLkeKP4KOBAm/9WnC3c1WtQFZtK5Q1JQtadN oEOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=KmHioDNm30peoUp9ZVyh4zl9eWidxUVBSh2HEqx69Bo=; b=krhOOwur25C+8/6r76oYYfp7Y4aFLCsVZHCjRyVwo0oD8VaOdVYlD2lqRNLN+IGLo5 hP0SnRGRnQVfifbYsRiRDKlhqaD7NPseWtEGQmy7mJEIIom6wfti6IO3Pedmk7OScgQo RDZn3LvF+gVoMVYzJMsnwr9Lmba3t6X+ecsJvoHVwgPkITtIsveBd0Mk4PCQS4wPXHav Oca+bI6K2qrzq7gF58g9hNFTSMr/6o+KhFfvGvCrcMH1mjVaLtlhPbRrJWYRZ8EDQsR7 5K7nK2TqbIt4f9nrO3h/lQAh80A9mvvihNuETto3zZ1HDXBzaU2KQzBAMGSwZ8ZiZsyU g3Bg== X-Gm-Message-State: APjAAAUv2hK7JuIXHnkYXUX3BeeMT7AeVzPIDRj1LHf2Ss0/TA018ZC3 s3J8OlsEAbldyFueC614HWetHA== X-Google-Smtp-Source: APXvYqwfHgix2kH6gL5f1OhbdiGNtOWyM3s/W+grh7PzTFQDB5MGfJHeWFkViOnorAGO3KLAQ3Eh0A== X-Received: by 2002:a1c:4105:: with SMTP id o5mr16970041wma.35.1553630698403; Tue, 26 Mar 2019 13:04:58 -0700 (PDT) Received: from localhost (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id x11sm17478406wmh.2.2019.03.26.13.04.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Mar 2019 13:04:57 -0700 (PDT) Date: Tue, 26 Mar 2019 21:04:53 +0100 From: Tomas Vondra To: Rafia Sabih Cc: Michael Paquier , John Naylor , Sergei Agalakov , PostgreSQL-development Subject: Re: explain plans with information about (modified) gucs Message-ID: <20190326200453.GA16551@development> References: <23164510-3f59-3289-3b32-9c8643711a6c@gmail.com> <5396e093-ed6b-5962-2ed5-337a0425160b@2ndquadrant.com> <603089e0-3387-30f1-3cbc-25dd7797e17a@2ndquadrant.com> <20190204022209.GY1881@paquier.xyz> <905460bc-db16-112f-1e2c-8dd48667f000@2ndquadrant.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="AqsLC8rIMeq19msA" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --AqsLC8rIMeq19msA Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On Mon, Mar 18, 2019 at 11:31:48AM +0100, Rafia Sabih wrote: >On Sun, 24 Feb 2019 at 00:06, Tomas Vondra wrote: >> >> Hi, >> >> attached is an updated patch, fixing and slightly tweaking the docs. >> >> >> Barring objections, I'll get this committed later next week. >> >I was having a look at this patch, and this kept me wondering, > >+static void >+ExplainShowSettings(ExplainState *es) >+{ >Is there some reason for not providing any explanation above this >function just like the rest of the functions in this file? > >Similarly, for > >struct config_generic ** >get_explain_guc_options(int *num) >{ > >/* also bail out of there are no options */ >+ if (!num) >+ return; >I think you meant 'if' instead if 'of' here. Thanks for the review - attached is a patch adding the missing comments, and doing two additional minor improvements: 1) Renaming ExplainShowSettings to ExplainPrintSettings, to make it more consistent with naming of the other functions in explain.c. 2) Actually counting GUC_EXPLAIN options, and only allocating space for those in get_explain_guc_options, instead of using num_guc_variables. The diffrence is quite significant (~50 vs. ~300), and considering each entry is 8B it makes a difference because such large chunks tend to have higher palloc overhed (due to ALLOCSET_SEPARATE_THRESHOLD). regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --AqsLC8rIMeq19msA Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="explain-with-settings-20190326.patch" diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index 8e48b94d4a..2a289b8b94 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -599,8 +599,12 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es, ExplainCloseGroup("Query", NULL, true, es); } +/* + * ExplainPrintSettings - + * Print summary of modified settings affecting query planning. + */ static void -ExplainShowSettings(ExplainState *es) +ExplainPrintSettings(ExplainState *es) { int num; struct config_generic **gucs; @@ -700,10 +704,10 @@ ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc) ExplainNode(ps, NIL, NULL, NULL, es); /* - * If requested, include information about GUC parameters that don't - * match the built-in defaults. + * If requested, include information about GUC parameters with values + * that don't match the built-in defaults. */ - ExplainShowSettings(es); + ExplainPrintSettings(es); } /* diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 7306d7c232..39f844ebc5 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -4532,6 +4532,7 @@ static struct config_generic **guc_variables; /* Current number of variables contained in the vector */ static int num_guc_variables; +static int num_guc_explain_variables; /* Vector capacity */ static int size_guc_variables; @@ -4796,6 +4797,7 @@ build_guc_variables(void) { int size_vars; int num_vars = 0; + int num_explain_vars = 0; struct config_generic **guc_vars; int i; @@ -4806,6 +4808,9 @@ build_guc_variables(void) /* Rather than requiring vartype to be filled in by hand, do this: */ conf->gen.vartype = PGC_BOOL; num_vars++; + + if (conf->gen.flags & GUC_EXPLAIN) + num_explain_vars++; } for (i = 0; ConfigureNamesInt[i].gen.name; i++) @@ -4814,6 +4819,9 @@ build_guc_variables(void) conf->gen.vartype = PGC_INT; num_vars++; + + if (conf->gen.flags & GUC_EXPLAIN) + num_explain_vars++; } for (i = 0; ConfigureNamesReal[i].gen.name; i++) @@ -4822,6 +4830,9 @@ build_guc_variables(void) conf->gen.vartype = PGC_REAL; num_vars++; + + if (conf->gen.flags & GUC_EXPLAIN) + num_explain_vars++; } for (i = 0; ConfigureNamesString[i].gen.name; i++) @@ -4830,6 +4841,9 @@ build_guc_variables(void) conf->gen.vartype = PGC_STRING; num_vars++; + + if (conf->gen.flags & GUC_EXPLAIN) + num_explain_vars++; } for (i = 0; ConfigureNamesEnum[i].gen.name; i++) @@ -4838,6 +4852,9 @@ build_guc_variables(void) conf->gen.vartype = PGC_ENUM; num_vars++; + + if (conf->gen.flags & GUC_EXPLAIN) + num_explain_vars++; } /* @@ -4869,6 +4886,7 @@ build_guc_variables(void) free(guc_variables); guc_variables = guc_vars; num_guc_variables = num_vars; + num_guc_explain_variables = num_explain_vars; size_guc_variables = size_vars; qsort((void *) guc_variables, num_guc_variables, sizeof(struct config_generic *), guc_var_compare); @@ -8819,6 +8837,11 @@ ShowAllGUCConfig(DestReceiver *dest) end_tup_output(tstate); } +/* + * Returns an array of modified GUC options to show in EXPLAIN. Only options + * related to query planning (marked with GUC_EXPLAIN), with values different + * from built-in defaults. + */ struct config_generic ** get_explain_guc_options(int *num) { @@ -8826,7 +8849,13 @@ get_explain_guc_options(int *num) struct config_generic **result; *num = 0; - result = palloc(sizeof(struct config_generic *) * num_guc_variables); + + /* + * Allocate enough space to fit all GUC_EXPLAIN options. We may not + * need all the space, but there are fairly few such options so we + * don't waste a lot of memory. + */ + result = palloc(sizeof(struct config_generic *) * num_guc_explain_variables); for (i = 0; i < num_guc_variables; i++) { @@ -8894,6 +8923,8 @@ get_explain_guc_options(int *num) /* assign to the values array */ result[*num] = conf; *num = *num + 1; + + Assert(*num <= num_guc_explain_variables); } return result; --AqsLC8rIMeq19msA--