|
From: mason_s <ma...@us...> - 2010-06-01 21:07:02
|
Project "Postgres-XC".
The branch, master has been updated
via ffe244ab59c464283ac1833e13377782bee1c122 (commit)
from 63b0858e76a740e6b0a5e30fa27d7b1d761ac6af (commit)
- Log -----------------------------------------------------------------
commit ffe244ab59c464283ac1833e13377782bee1c122
Author: Mason S <mas...@ma...>
Date: Tue Jun 1 17:05:56 2010 -0400
Support for pg_dump and pg_restore.
The CREATE TABLE command generation now includes distribution information.
Written by Michael Paquier
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index fdb9564..ec86c18 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -3187,6 +3187,10 @@ getTables(int *numTables)
int i_relfrozenxid;
int i_owning_tab;
int i_owning_col;
+#ifdef PGXC
+ int i_pgxclocatortype;
+ int i_pgxcattnum;
+#endif
int i_reltablespace;
int i_reloptions;
int i_toastreloptions;
@@ -3219,6 +3223,8 @@ getTables(int *numTables)
/*
* Left join to pick up dependency info linking sequences to their
* owning column, if any (note this dependency is AUTO as of 8.2)
+ * PGXC is based on PostgreSQL version 8.4, it is not necessary to
+ * to modify the other SQL queries.
*/
appendPQExpBuffer(query,
"SELECT c.tableoid, c.oid, c.relname, "
@@ -3230,7 +3236,11 @@ getTables(int *numTables)
"d.refobjid AS owning_tab, "
"d.refobjsubid AS owning_col, "
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, "
- "array_to_string(c.reloptions, ', ') AS reloptions, "
+#ifdef PGXC
+ "(SELECT pclocatortype from pgxc_class v where v.pcrelid = c.oid) AS pgxclocatortype,"
+ "(SELECT pcattnum from pgxc_class v where v.pcrelid = c.oid) AS pgxcattnum,"
+#endif
+ "array_to_string(c.reloptions, ', ') AS reloptions, "
"array_to_string(array(SELECT 'toast.' || x FROM unnest(tc.reloptions) x), ', ') AS toast_reloptions "
"FROM pg_class c "
"LEFT JOIN pg_depend d ON "
@@ -3448,6 +3458,10 @@ getTables(int *numTables)
i_relfrozenxid = PQfnumber(res, "relfrozenxid");
i_owning_tab = PQfnumber(res, "owning_tab");
i_owning_col = PQfnumber(res, "owning_col");
+#ifdef PGXC
+ i_pgxclocatortype = PQfnumber(res, "pgxclocatortype");
+ i_pgxcattnum = PQfnumber(res, "pgxcattnum");
+#endif
i_reltablespace = PQfnumber(res, "reltablespace");
i_reloptions = PQfnumber(res, "reloptions");
i_toastreloptions = PQfnumber(res, "toast_reloptions");
@@ -3495,6 +3509,19 @@ getTables(int *numTables)
tblinfo[i].owning_tab = atooid(PQgetvalue(res, i, i_owning_tab));
tblinfo[i].owning_col = atoi(PQgetvalue(res, i, i_owning_col));
}
+#ifdef PGXC
+ /* Not all the tables have pgxc locator Data */
+ if (PQgetisnull(res, i, i_pgxclocatortype))
+ {
+ tblinfo[i].pgxclocatortype = 'E';
+ tblinfo[i].pgxcattnum = 0;
+ }
+ else
+ {
+ tblinfo[i].pgxclocatortype = *(PQgetvalue(res, i, i_pgxclocatortype));
+ tblinfo[i].pgxcattnum = atoi(PQgetvalue(res, i, i_pgxcattnum));
+ }
+#endif
tblinfo[i].reltablespace = strdup(PQgetvalue(res, i, i_reltablespace));
tblinfo[i].reloptions = strdup(PQgetvalue(res, i, i_reloptions));
tblinfo[i].toast_reloptions = strdup(PQgetvalue(res, i, i_toastreloptions));
@@ -9939,6 +9966,30 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
appendPQExpBuffer(q, ")");
}
+#ifdef PGXC
+ /* Add the grammar extension linked to PGXC depending on data got from pgxc_class */
+ if (tbinfo->pgxclocatortype != 'E')
+ {
+ /* N: DISTRIBUTE BY ROUND ROBIN */
+ if (tbinfo->pgxclocatortype == 'N')
+ {
+ appendPQExpBuffer(q, "\nDISTRIBUTE BY ROUND ROBIN");
+ }
+ /* R: DISTRIBUTE BY REPLICATED */
+ else if (tbinfo->pgxclocatortype == 'R')
+ {
+ appendPQExpBuffer(q, "\nDISTRIBUTE BY REPLICATION");
+ }
+ /* H: DISTRIBUTE BY HASH */
+ else if (tbinfo->pgxclocatortype == 'H')
+ {
+ int hashkey = tbinfo->pgxcattnum;
+ appendPQExpBuffer(q, "\nDISTRIBUTE BY HASH (%s)",
+ fmtId(tbinfo->attnames[hashkey - 1]));
+ }
+ }
+#endif
+
appendPQExpBuffer(q, ";\n");
/*
diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h
index a9b3dae..276a3d6 100644
--- a/src/bin/pg_dump/pg_dump.h
+++ b/src/bin/pg_dump/pg_dump.h
@@ -16,6 +16,10 @@
#include "postgres_fe.h"
+#ifdef PGXC
+#include "pgxc/pgxc.h"
+#endif
+
/*
* pg_dump uses two different mechanisms for identifying database objects:
*
@@ -234,6 +238,11 @@ typedef struct _tableInfo
bool interesting; /* true if need to collect more data */
+#ifdef PGXC
+ /* PGXC table locator Data */
+ char pgxclocatortype; /* Type of PGXC table locator */
+ int pgxcattnum; /* Number of the attribute the table is partitioned with */
+#endif
/*
* These fields are computed only if we decide the table is interesting
* (it's either a table to dump, or a direct parent of a dumpable table).
-----------------------------------------------------------------------
Summary of changes:
src/bin/pg_dump/pg_dump.c | 53 ++++++++++++++++++++++++++++++++++++++++++++-
src/bin/pg_dump/pg_dump.h | 9 +++++++
2 files changed, 61 insertions(+), 1 deletions(-)
hooks/post-receive
--
Postgres-XC
|