|
53 | 53 | #include <sys/select.h>
|
54 | 54 | #endif
|
55 | 55 |
|
| 56 | +#include "catalog/pg_class_d.h" |
56 | 57 | #include "common/int.h"
|
57 | 58 | #include "common/logging.h"
|
58 | 59 | #include "common/pg_prng.h"
|
@@ -848,6 +849,31 @@ static const PsqlScanCallbacks pgbench_callbacks = {
|
848 | 849 | NULL, /* don't need get_variable functionality */
|
849 | 850 | };
|
850 | 851 |
|
| 852 | +static char |
| 853 | +get_table_relkind(PGconn *con, const char *table) |
| 854 | +{ |
| 855 | + PGresult *res; |
| 856 | + char *val; |
| 857 | + char relkind; |
| 858 | + const char *params[1] = {table}; |
| 859 | + const char *sql = |
| 860 | + "SELECT relkind FROM pg_catalog.pg_class WHERE oid=$1::pg_catalog.regclass"; |
| 861 | + |
| 862 | + res = PQexecParams(con, sql, 1, NULL, params, NULL, NULL, 0); |
| 863 | + if (PQresultStatus(res) != PGRES_TUPLES_OK) |
| 864 | + { |
| 865 | + pg_log_error("query failed: %s", PQerrorMessage(con)); |
| 866 | + pg_log_error_detail("Query was: %s", sql); |
| 867 | + exit(1); |
| 868 | + } |
| 869 | + val = PQgetvalue(res, 0, 0); |
| 870 | + Assert(strlen(val) == 1); |
| 871 | + relkind = val[0]; |
| 872 | + PQclear(res); |
| 873 | + |
| 874 | + return relkind; |
| 875 | +} |
| 876 | + |
851 | 877 | static inline pg_time_usec_t
|
852 | 878 | pg_time_now(void)
|
853 | 879 | {
|
@@ -4962,16 +4988,11 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
|
4962 | 4988 |
|
4963 | 4989 | initPQExpBuffer(&sql);
|
4964 | 4990 |
|
4965 |
| - /* |
4966 |
| - * Use COPY with FREEZE on v14 and later for all the tables except |
4967 |
| - * pgbench_accounts when it is partitioned. |
4968 |
| - */ |
4969 |
| - if (PQserverVersion(con) >= 140000) |
4970 |
| - { |
4971 |
| - if (strcmp(table, "pgbench_accounts") != 0 || |
4972 |
| - partitions == 0) |
4973 |
| - copy_statement_fmt = "copy %s from stdin with (freeze on)"; |
4974 |
| - } |
| 4991 | + /* Use COPY with FREEZE on v14 and later for all ordinary tables */ |
| 4992 | + if ((PQserverVersion(con) >= 140000) && |
| 4993 | + get_table_relkind(con, table) == RELKIND_RELATION) |
| 4994 | + copy_statement_fmt = "copy %s from stdin with (freeze on)"; |
| 4995 | + |
4975 | 4996 |
|
4976 | 4997 | n = pg_snprintf(copy_statement, sizeof(copy_statement), copy_statement_fmt, table);
|
4977 | 4998 | if (n >= sizeof(copy_statement))
|
|
0 commit comments