pgbench: increase the maximum number of variables/arguments
authorAndrew Dunstan <andrew@dunslane.net>
Mon, 11 Mar 2019 15:47:35 +0000 (11:47 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Mon, 11 Mar 2019 17:18:37 +0000 (13:18 -0400)
pgbench's arbitrary limit of 10 arguments for SQL statements or
metacommands is far too low. Increase it to 256.

This results in a very modest increase in memory usage, not enough to
worry about.

The maximum includes the SQL statement or metacommand. This is reflected
in the comments and revised TAP tests.

Simon Riggs and Dagfinn Ilmari MannsÃ¥ker with some light editing by me.
Reviewed by: David Rowley and Fabien Coelho

Discussion: https://postgr.es/m/CANP8+jJiMJOAf-dLoHuR-8GENiK+eHTY=Omw38Qx7j2g0NDTXA@mail.gmail.com

doc/src/sgml/ref/pgbench.sgml
src/bin/pgbench/pgbench.c
src/bin/pgbench/t/001_pgbench_with_server.pl

index 9d185248346edef7bd1dd4f8909763da2e86c576..24833f46bcf56a39b30ff3fe6bf514bb68fd48b9 100644 (file)
@@ -916,6 +916,8 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
    value can be inserted into a SQL command by writing
    <literal>:</literal><replaceable>variablename</replaceable>.  When running more than
    one client session, each session has its own set of variables.
+   <application>pgbench</application> supports up to 255 variable uses in one
+   statement.
   </para>
 
    <table id="pgbench-automatic-variables">
index 5df54a8e57e822a23dc99baa00c58942d227958f..4789ab92eec4bf757958ae6c0d1068bb3bb73683 100644 (file)
@@ -476,7 +476,12 @@ typedef struct
  */
 #define SQL_COMMAND        1
 #define META_COMMAND   2
-#define MAX_ARGS       10
+
+/*
+ * max number of backslash command arguments or SQL variables,
+ * including the command or SQL statement itself
+ */
+#define MAX_ARGS       256
 
 typedef enum MetaCommand
 {
@@ -4124,6 +4129,10 @@ parseQuery(Command *cmd)
            continue;
        }
 
+       /*
+        * cmd->argv[0] is the SQL statement itself, so the max number of
+        * arguments is one less than MAX_ARGS
+        */
        if (cmd->argc >= MAX_ARGS)
        {
            fprintf(stderr, "statement has too many arguments (maximum is %d): %s\n",
@@ -4461,6 +4470,10 @@ process_backslash_command(PsqlScanState sstate, const char *source)
    /* For all other commands, collect remaining words. */
    while (expr_lex_one_word(sstate, &word_buf, &word_offset))
    {
+       /*
+        * my_command->argv[0] is the command itself, so the max number of
+        * arguments is one less than MAX_ARGS
+        */
        if (j >= MAX_ARGS)
            syntax_error(source, lineno, my_command->first_line, my_command->argv[0],
                         "too many arguments", NULL, -1);
index 930ff4ebb9204edb7c66e93162cef7e097b4e7c4..45888dc12e83942b3838b0143528a16936e1fd8e 100644 (file)
@@ -597,11 +597,10 @@ my @errors = (
 }
    ],
    [
-       'sql too many args', 1, [qr{statement has too many arguments.*\b9\b}],
-       q{-- MAX_ARGS=10 for prepared
+       'sql too many args', 1, [qr{statement has too many arguments.*\b255\b}],
+       q{-- MAX_ARGS=256 for prepared
 \set i 0
-SELECT LEAST(:i, :i, :i, :i, :i, :i, :i, :i, :i, :i, :i);
-}
+SELECT LEAST(}.join(', ', (':i') x 256).q{)}
    ],
 
    # SHELL
@@ -619,25 +618,8 @@ SELECT LEAST(:i, :i, :i, :i, :i, :i, :i, :i, :i, :i, :i);
    [ 'shell missing command', 1, [qr{missing command }], q{\shell} ],
    [
        'shell too many args', 1, [qr{too many arguments in command "shell"}],
-       q{-- 257 arguments to \shell
-\shell echo \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F \
- 0 1 2 3 4 5 6 7 8 9 A B C D E F
-}
+       q{-- 256 arguments to \shell
+\shell echo }.join(' ', ('arg') x 255)
    ],
 
    # SET