Thanks a lot for the comments, Fabien.
Some feedback about v3:
In the doc I find TABLEACCESSMETHOD quite hard to read. Use TABLEAM
instead?
Yes, in this case, *TABLEAM* is easy to read, updated.
Also, the next entry uses lowercase (tablespace), why change the style?
The original style is not so consistent, for example, in doc,
--partition-method using *NAME*, but --table-space using *tablespace*;
in help, --partition-method using *(rang|hash)*, but --tablespace using
*TABLESPACE*. To keep it more consistent, I would rather use *TABLEAM*
in both doc and help.
Remove space after comma in help string. I'd use the more readable
TABLEAM in the help string rather than the mouthful.
Yes the *space* is removed after comma.
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.
I'd suggest that the table am option should rather by changing the
default instead, so that it would apply to everything relevant
implicitely when appropriate.
I think this is a better idea, so in v4 patch I change it to something
like "set default_table_access_method to *TABLEAM*" instead of using the
*using* clause.
About tests :
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 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.
By the way, I saw the same style for other variables, such as
escape_tablespace, should this be fixed as well?
Nope, let it be.
--
David
Software Engineer
Highgo Software Inc. (Canada)
www.highgo.ca
From c25b55580b1b3f3faac63b4d72291c80fb2c9c1f Mon Sep 17 00:00:00 2001
From: David Zhang <david.zh...@highgo.ca>
Date: Tue, 1 Dec 2020 20:47:01 -0800
Subject: [PATCH] add table access method as an option to pgbench
---
doc/src/sgml/ref/pgbench.sgml | 10 +++++++
src/bin/pgbench/pgbench.c | 31 +++++++++++++++++++-
src/bin/pgbench/t/001_pgbench_with_server.pl | 12 ++++++++
3 files changed, 52 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..961841b255 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 && partition_method == PART_NONE &&
partitions == 0)
+ {
+ 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);
@@ -5907,6 +5930,12 @@ main(int argc, char **argv)
}
}
+ if (table_access_method != NULL && (partitions > 0 ||
partition_method != PART_NONE))
+ {
+ pg_log_fatal("--table-access-method cannot work with
--partition-method or --partitions");
+ exit(1);
+ }
+
runInitSteps(initialize_steps);
exit(0);
}
diff --git a/src/bin/pgbench/t/001_pgbench_with_server.pl
b/src/bin/pgbench/t/001_pgbench_with_server.pl
index 61b671d54f..c81b1ac17a 100644
--- a/src/bin/pgbench/t/001_pgbench_with_server.pl
+++ b/src/bin/pgbench/t/001_pgbench_with_server.pl
@@ -146,6 +146,18 @@ pgbench(
],
'pgbench --init-steps');
+# Test interaction of --table-access
+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');
+
# Run all builtin scripts, for a few transactions each
pgbench(
'--transactions=5 -Dfoo=bla --client=2 --protocol=simple --builtin=t'
--
2.17.1