提交 e8de956e 编写于 作者: H Heikki Linnakangas

Speed improvements to pg_dump.

* Don't query for external partitions in non-partitioned tables. The
  query for possible external partitions is fairly expensive, and it's
  pointless if the table is not partitioned at all.

* Cache the results of server version checks.

With these improvements, dumping the regression database takes about 25
seconds on my laptop, vs. 70 seconds before.
上级 8a27417d
...@@ -286,27 +286,33 @@ error_unsupported_server_version(void) ...@@ -286,27 +286,33 @@ error_unsupported_server_version(void)
static bool static bool
isGPDB4300OrLater(void) isGPDB4300OrLater(void)
{ {
static int value = -1; /* -1 = not known yet, 0 = no, 1 = yes */
bool retValue = false; bool retValue = false;
if (isGPbackend) /* Query the server on first call, and cache the result */
if (value == -1)
{ {
PQExpBuffer query; if (isGPbackend)
PGresult *res; {
const char *query;
PGresult *res;
query = createPQExpBuffer(); query = "select attnum from pg_catalog.pg_attribute "
appendPQExpBuffer(query, "where attrelid = 'pg_catalog.pg_proc'::regclass and "
"select attnum from pg_catalog.pg_attribute " "attname = 'prodataaccess'";
"where attrelid = 'pg_catalog.pg_proc'::regclass and "
"attname = 'prodataaccess'");
res = PQexec(g_conn, query->data); res = PQexec(g_conn, query);
check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK); check_sql_result(res, g_conn, query, PGRES_TUPLES_OK);
if (PQntuples(res) == 1) if (PQntuples(res) == 1)
retValue = true; value = 1;
else
value = 0;
PQclear(res); PQclear(res);
destroyPQExpBuffer(query); }
else
value = 0;
} }
return retValue; return retValue;
...@@ -318,54 +324,38 @@ isGPDB4300OrLater(void) ...@@ -318,54 +324,38 @@ isGPDB4300OrLater(void)
static bool static bool
isGPDB(void) isGPDB(void)
{ {
PQExpBuffer query; static int value = -1; /* -1 = not known yet, 0 = no, 1 = yes */
PGresult *res;
char *ver;
bool retValue = false;
query = createPQExpBuffer(); /* Query the server on first call, and cache the result */
appendPQExpBuffer(query, "select version()"); if (value == -1)
res = PQexec(g_conn, query->data); {
check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK); const char *query = "select pg_catalog.version()";
PGresult *res;
char *ver;
ver = (PQgetvalue(res, 0, 0)); res = PQexec(g_conn, query);
if (strstr(ver, "Greenplum") != NULL) check_sql_result(res, g_conn, query, PGRES_TUPLES_OK);
retValue = true;
PQclear(res); ver = (PQgetvalue(res, 0, 0));
destroyPQExpBuffer(query); if (strstr(ver, "Greenplum") != NULL)
return retValue; value = 1;
else
value = 0;
PQclear(res);
}
return (value == 1) ? true : false;
} }
/*
* If GPDB version is 5.0, pg_proc has provariadic column.
* When we have version() returns GPDB version instead of "main build dev" or
* something similar, we'll fix this function (MPP-17313)
*/
static bool static bool
isGPDB5000OrLater(void) isGPDB5000OrLater(void)
{ {
bool retValue = false; if (!isGPDB())
return false; /* Not Greenplum at all. */
if (isGPDB() == true)
{
PQExpBuffer query;
PGresult *res;
query = createPQExpBuffer();
appendPQExpBuffer(query,"select attnum from pg_catalog.pg_attribute where attrelid = 1255 and attname = 'provariadic'");
res = PQexec(g_conn, query->data);
check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK);
if (PQntuples(res) == 1)
retValue = true;
PQclear(res);
destroyPQExpBuffer(query);
}
return retValue; /* GPDB 5 is based on PostgreSQL 8.3 */
return g_fout->remoteVersion >= 80400;
} }
...@@ -11024,6 +11014,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -11024,6 +11014,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
char *storage; char *storage;
int j, int j,
k; k;
bool isPartitioned = false;
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(tbinfo->dobj.namespace->dobj.name); selectSourceSchema(tbinfo->dobj.namespace->dobj.name);
...@@ -11289,7 +11280,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -11289,7 +11280,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
tbinfo->dobj.name); tbinfo->dobj.name);
exit_nicely(); exit_nicely();
} }
if (!PQgetisnull(res, 0, 0)) isPartitioned = !PQgetisnull(res, 0, 0);
if (isPartitioned)
appendPQExpBuffer(q, " %s", PQgetvalue(res, 0, 0)); appendPQExpBuffer(q, " %s", PQgetvalue(res, 0, 0));
PQclear(res); PQclear(res);
...@@ -11343,7 +11335,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -11343,7 +11335,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
appendPQExpBuffer(q, ";\n"); appendPQExpBuffer(q, ";\n");
/* Exchange external partition */ /* Exchange external partition */
if (gp_partitioning_available) if (isPartitioned)
{ {
int i = 0; int i = 0;
int ntups = 0; int ntups = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册