Skip to content

Latest commit

 

History

History
75 lines (60 loc) · 2.7 KB

File metadata and controls

75 lines (60 loc) · 2.7 KB

postprocess_sql_command

Location

src/bin/pgbench/pgbench.c:5634-5670

Overview

Completes the processing of an SQL command after it has been fully parsed, setting up additional fields in the Command structure for execution.

Definition

static void postprocess_sql_command(Command *my_command)

Detailed Description

This function performs final setup operations on a Command structure after the SQL text has been completely parsed. It handles different query execution modes (simple, prepared, extended) by setting up the appropriate command arguments and names. The function also saves the first line of the SQL command for error reporting purposes.

Parameters / Member Variables

  • my_command: Pointer to the Command structure that needs post-processing. Must be of type SQL_COMMAND.

Dependencies

  • Functions called/Symbols referenced:
  • Called from:
    • main (src/bin/pgbench/pgbench.c:7064)

Notes and Other Information

  • The function asserts that the command type is SQL_COMMAND
  • Uses a static counter (prepnum) to generate unique prepared statement names
  • Truncates the first line at newline/carriage return characters for clean error display
  • Exits the program if parsing fails or an invalid query mode is encountered
  • Part of the pgbench benchmarking tool's SQL command processing pipeline

Simplified Source

static void postprocess_sql_command(Command *my_command)
{
    char buffer[128];
    static int prepnum = 0;

    Assert(my_command->type == SQL_COMMAND);

    // Save first line for error display
    strlcpy(buffer, my_command->lines.data, sizeof(buffer));
    buffer[strcspn(buffer, "\n\r")] = '\0';
    my_command->first_line = pg_strdup(buffer);

    // Handle different query execution modes
    switch (querymode) {
        case QUERY_SIMPLE:
            // Simple mode: use SQL text as-is
            my_command->argv[0] = my_command->lines.data;
            my_command->argc++;
            break;

        case QUERY_PREPARED:
            // Prepared mode: generate unique statement name
            my_command->prepname = psprintf("P_%d", prepnum++);
            /* fall through */

        case QUERY_EXTENDED:
            // Extended/prepared mode: parse parameters
            if (!parseQuery(my_command))
                exit(1);
            break;

        default:
            exit(1);
    }
}