Add compute_query_id = regress
authorMichael Paquier <[email protected]>
Tue, 22 Feb 2022 01:22:15 +0000 (10:22 +0900)
committerMichael Paquier <[email protected]>
Tue, 22 Feb 2022 01:22:15 +0000 (10:22 +0900)
"regress" is a new mode added to compute_query_id aimed at facilitating
regression testing when a module computing query IDs is loaded into the
backend, like pg_stat_statements.  It works the same way as "auto",
meaning that query IDs are computed if a module enables it, except that
query IDs are hidden in EXPLAIN outputs to ensure regression output
stability.

Like any GUCs of the kind (force_parallel_mode, etc.), this new
configuration can be added to an instance's postgresql.conf, or just
passed down with PGOPTIONS at command level.  compute_query_id uses an
enum for its set of option values, meaning that this addition ensures
ABI compatibility.

Using this new configuration mode allows installcheck-world to pass when
running the tests on an instance with pg_stat_statements enabled,
stabilizing the test output while checking the paths doing query ID
computations.

Reported-by: Anton Melnikov
Reviewed-by: Julien Rouhaud
Discussion: https://postgr.es/m/1634283396.372373993@f75.i.mail.ru
Discussion: https://postgr.es/m/YgHlxgc/[email protected]
Backpatch-through: 14

doc/src/sgml/config.sgml
src/backend/commands/explain.c
src/backend/utils/misc/guc.c
src/include/utils/queryjumble.h

index d99bf38e677926ee64efc9315c7c9f478f3b0cf7..7ed8c82a9dd79f4938be912670470518860a604c 100644 (file)
@@ -7934,9 +7934,12 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
         method is not acceptable.  In this case, in-core computation
         must be always disabled.
         Valid values are <literal>off</literal> (always disabled),
-        <literal>on</literal> (always enabled) and <literal>auto</literal>,
+        <literal>on</literal> (always enabled), <literal>auto</literal>,
         which lets modules such as <xref linkend="pgstatstatements"/>
-        automatically enable it.
+        automatically enable it, and <literal>regress</literal> which
+        has the same effect as <literal>auto</literal>, except that the
+        query identifier is hidden in the <literal>EXPLAIN</literal> output
+        to facilitate automated regression testing.
         The default is <literal>auto</literal>.
        </para>
        <note>
index b970997c34616ac9db6c18b355459ba04079434f..de81379da39ac31e1caa4d973c990dd9d5ba5b8f 100644 (file)
@@ -604,7 +604,13 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
    /* Create textual dump of plan tree */
    ExplainPrintPlan(es, queryDesc);
 
-   if (es->verbose && plannedstmt->queryId != UINT64CONST(0))
+   /*
+    * COMPUTE_QUERY_ID_REGRESS means COMPUTE_QUERY_ID_AUTO, but we don't show
+    * the queryid in any of the EXPLAIN plans to keep stable the results
+    * generated by regression test suites.
+    */
+   if (es->verbose && plannedstmt->queryId != UINT64CONST(0) &&
+       compute_query_id != COMPUTE_QUERY_ID_REGRESS)
    {
        /*
         * Output the queryid as an int64 rather than a uint64 so we match
index eaa4bf2c30405c9bf51e79cee67477198262d885..e4afd07bfe1dad0ddd821d8baa4571ec771bfaf6 100644 (file)
@@ -414,6 +414,7 @@ static const struct config_enum_entry backslash_quote_options[] = {
  */
 static const struct config_enum_entry compute_query_id_options[] = {
    {"auto", COMPUTE_QUERY_ID_AUTO, false},
+   {"regress", COMPUTE_QUERY_ID_REGRESS, false},
    {"on", COMPUTE_QUERY_ID_ON, false},
    {"off", COMPUTE_QUERY_ID_OFF, false},
    {"true", COMPUTE_QUERY_ID_ON, true},
index a4c277269e0374814229819054171e21fc70e214..c670662db2b44416c0bc699230492cb40f618d9e 100644 (file)
@@ -57,7 +57,8 @@ enum ComputeQueryIdType
 {
    COMPUTE_QUERY_ID_OFF,
    COMPUTE_QUERY_ID_ON,
-   COMPUTE_QUERY_ID_AUTO
+   COMPUTE_QUERY_ID_AUTO,
+   COMPUTE_QUERY_ID_REGRESS
 };
 
 /* GUC parameters */