Again, thanks a lot for the feedback.

On 2020-12-02 12:03 p.m., Fabien COELHO wrote:

Hello David,

Some feedback about v4.

It looks that the option is *silently* ignored when creating a partitionned table, which currently results in an error, and not passed to partitions, which would accept them. This is pretty weird.
The input check is added with an error message when both partitions and table access method are used.

Hmmm. If you take the resetting the default, I do not think that you should have to test anything? AFAICT the access method is valid on partitions, although not on the partitioned table declaration. So I'd say that you could remove the check.
Yes, it makes sense to remove the *blocking* check, and actually the table access method interface does work with partitioned table. I tested this/v5 by duplicating the heap access method with a different name. For this reason, I removed the condition check as well when applying the table access method.

They should also trigger failures, eg "--table-access-method=no-such-table-am", to be added to the @errors list.
No sure how to address this properly, since the table access method potentially can be *any* name.

I think it is pretty unlikely that someone would chose the name "no-such-table-am" when developing a new storage engine for Postgres inside Postgres, so that it would make this internal test fail.

There are numerous such names used in tests, eg "no-such-database", "no-such-command".

So I'd suggest to add such a test to check for the expected failure.
The test case "no-such-table-am" has been added to the errors list, and the regression test is ok.

I do not understand why you duplicated all possible option entry.

Test with just table access method looks redundant if the feature is make to work orthonogonally to partitions, which should be the case.
Only one positive test case added using *heap* as the table access method to verify the initialization.

Yep, only "heap" if currently available for tables.

Thanks,
--
David

Software Engineer
Highgo Software Inc. (Canada)
www.highgo.ca
From 1d6f434d56c36f95da82d1bae4f99bb917351c08 Mon Sep 17 00:00:00 2001
From: David Zhang <david.zh...@highgo.ca>
Date: Mon, 7 Dec 2020 13:42:00 -0800
Subject: [PATCH] add table access method as an option to pgbench

---
 doc/src/sgml/ref/pgbench.sgml                | 10 ++++++++
 src/bin/pgbench/pgbench.c                    | 25 +++++++++++++++++++-
 src/bin/pgbench/t/001_pgbench_with_server.pl | 22 +++++++++++++++++
 3 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml
index 7180fedd65..992fbbdb4b 100644
--- a/doc/src/sgml/ref/pgbench.sgml
+++ b/doc/src/sgml/ref/pgbench.sgml
@@ -359,6 +359,16 @@ pgbench <optional> <replaceable>options</replaceable> 
</optional> <replaceable>d
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      
<term><option>--table-access-method=<replaceable>TABLEAM</replaceable></option></term>
+      <listitem>
+       <para>
+        Create tables using the specified table access method, rather than the 
default.
+        tablespace.
+       </para>
+      </listitem>
+     </varlistentry>
+     
      <varlistentry>
       
<term><option>--tablespace=<replaceable>tablespace</replaceable></option></term>
       <listitem>
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 3057665bbe..eb91df6d6b 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -184,10 +184,11 @@ double            throttle_delay = 0;
 int64          latency_limit = 0;
 
 /*
- * tablespace selection
+ * tablespace and table access method selection
  */
 char      *tablespace = NULL;
 char      *index_tablespace = NULL;
+char      *table_access_method = NULL;
 
 /*
  * Number of "pgbench_accounts" partitions.  0 is the default and means no
@@ -641,6 +642,9 @@ usage(void)
                   "  --partition-method=(range|hash)\n"
                   "                           partition pgbench_accounts with 
this method (default: range)\n"
                   "  --partitions=NUM         partition pgbench_accounts into 
NUM parts (default: 0)\n"
+                  "  --table-access-method=TABLEAM\n"
+                  "                           create tables with using 
specified table access method,\n"
+                  "                           rather than the default.\n"
                   "  --tablespace=TABLESPACE  create tables in the specified 
tablespace\n"
                   "  --unlogged-tables        create tables as unlogged 
tables\n"
                   "\nOptions to select what to run:\n"
@@ -3747,6 +3751,20 @@ initCreateTables(PGconn *con)
 
        fprintf(stderr, "creating tables...\n");
 
+       if (table_access_method != NULL)
+       {
+               char       *escaped_table_access_method;
+
+               initPQExpBuffer(&query);
+               escaped_table_access_method = PQescapeIdentifier(con,
+                               table_access_method, 
strlen(table_access_method));
+               appendPQExpBuffer(&query, "set default_table_access_method to 
%s;\n",
+                               escaped_table_access_method);
+               PQfreemem(escaped_table_access_method);
+               executeStatement(con, query.data);
+               termPQExpBuffer(&query);
+       }
+
        initPQExpBuffer(&query);
 
        for (i = 0; i < lengthof(DDLs); i++)
@@ -5419,6 +5437,7 @@ main(int argc, char **argv)
                {"show-script", required_argument, NULL, 10},
                {"partitions", required_argument, NULL, 11},
                {"partition-method", required_argument, NULL, 12},
+               {"table-access-method", required_argument, NULL, 13},
                {NULL, 0, NULL, 0}
        };
 
@@ -5792,6 +5811,10 @@ main(int argc, char **argv)
                                        exit(1);
                                }
                                break;
+                       case 13:                        /* table access method*/
+                               initialization_option_set = true;
+                               table_access_method = pg_strdup(optarg);
+                               break;
                        default:
                                fprintf(stderr, _("Try \"%s --help\" for more 
information.\n"), progname);
                                exit(1);
diff --git a/src/bin/pgbench/t/001_pgbench_with_server.pl 
b/src/bin/pgbench/t/001_pgbench_with_server.pl
index 61b671d54f..077e862530 100644
--- a/src/bin/pgbench/t/001_pgbench_with_server.pl
+++ b/src/bin/pgbench/t/001_pgbench_with_server.pl
@@ -100,6 +100,16 @@ pgbench(
        [qr{Perhaps you need to do initialization}],
        'run without init');
 
+pgbench(
+        '-i --table-access-method=no-such-table-am',
+        1,
+        [qr{^$}],
+        [
+                qr{invalid value for parameter "default_table_access_method"},
+                qr{DETAIL:  Table access method "no-such-table-am" does not 
exist}
+        ],
+        'no such table access method');
+
 # Initialize pgbench tables scale 1
 pgbench(
        '-i', 0,
@@ -146,6 +156,18 @@ pgbench(
        ],
        'pgbench --init-steps');
 
+# Test interaction of --table-access-method
+pgbench(
+       '--initialize --table-access-method=heap',
+       0,
+       [qr{^$}],
+       [
+               qr{dropping old tables},
+               qr{creating tables},
+               qr{done in \d+\.\d\d s }
+       ],
+       'pgbench --table-access-method');
+
 # Run all builtin scripts, for a few transactions each
 pgbench(
        '--transactions=5 -Dfoo=bla --client=2 --protocol=simple --builtin=t'
-- 
2.17.1

Reply via email to