|
From: Michael P <mic...@us...> - 2010-05-28 00:19:26
|
Project "Postgres-XC".
The branch, master has been created
at 54529d7ad914e2959d7243055bbec08302c7e8dc (commit)
- Log -----------------------------------------------------------------
commit 54529d7ad914e2959d7243055bbec08302c7e8dc
Author: Mason S <mas...@ma...>
Date: Wed May 26 14:08:02 2010 -0400
Minor change that updates COPY so that it knows ahead
of time whether or not it should only execute on the
Coordinator (pg_catalog tables).
Written by Michael Paquier
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 0fd4cb9..d641df8 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -800,6 +800,32 @@ CopyQuoteIdentifier(StringInfo query_buf, char *value)
}
#endif
+#ifdef PGXC
+/*
+ * In case there is no locator info available, copy to/from is launched in portal on coordinator.
+ * This happens for pg_catalog tables (not user defined ones)
+ * such as pg_catalog, pg_attribute, etc.
+ * This part is launched before the portal is activated, so check a first time if there
+ * some locator data for this relid and if no, return and launch the portal.
+ */
+bool
+IsCoordPortalCopy(const CopyStmt *stmt)
+{
+ RelationLocInfo *rel_loc; /* the locator key */
+
+ /* In the case of a COPY SELECT, this is launched on datanodes */
+ if(!stmt->relation)
+ return false;
+
+ rel_loc = GetRelationLocInfo(RangeVarGetRelid(stmt->relation, true));
+
+ if (!rel_loc)
+ return true;
+
+ return false;
+}
+#endif
+
/*
* DoCopy executes the SQL COPY statement
*
@@ -832,7 +858,7 @@ CopyQuoteIdentifier(StringInfo query_buf, char *value)
*/
uint64
#ifdef PGXC
-DoCopy(const CopyStmt *stmt, const char *queryString, bool exec_on_coord_portal, bool *executed)
+DoCopy(const CopyStmt *stmt, const char *queryString, bool exec_on_coord_portal)
#else
DoCopy(const CopyStmt *stmt, const char *queryString)
#endif
@@ -1155,21 +1181,6 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
exec_nodes = (Exec_Nodes *) palloc0(sizeof(Exec_Nodes));
cstate->rel_loc = GetRelationLocInfo(RelationGetRelid(cstate->rel));
- /*
- * In case there is no locator info available, copy to/from is launched in portal on coordinator.
- * This happens for pg_catalog tables (not user defined ones)
- * such as pg_catalog, pg_attribute, etc.
- * This part is launched before the portal is activated, so check a first time if there
- * some locator data for this relid and if no, return and launch the portal.
- */
- if (!cstate->rel_loc && !exec_on_coord_portal)
- {
- /* close lock before leaving */
- if (cstate->rel)
- heap_close(cstate->rel, (is_from ? NoLock : AccessShareLock));
- *executed = false;
- return 0;
- }
if (exec_on_coord_portal)
cstate->on_coord = true;
@@ -1552,9 +1563,6 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
pfree(cstate->raw_buf);
pfree(cstate);
-#ifdef PGXC
- *executed = true;
-#endif
return processed;
}
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index cce476d..a0c0d90 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -992,17 +992,18 @@ exec_simple_query(const char *query_string)
/*
* A check on locator is made in DoCopy to determine if the copy can be launched on
* Datanode or on Coordinator.
- * If a table has no locator data, then done is set to false and copy is launched
+ * If a table has no locator data, then IsCoordPortalCopy returns false and copy is launched
* on Coordinator instead (e.g., using pg_catalog tables).
- * If a table has some locator data (user tables), then copy was launched normally
+ * If a table has some locator data (user tables), then copy is launched normally
* in Datanodes
*/
- DoCopy(copy, query_string, false, &done);
-
- if (!done)
- exec_on_coord = true;
- else
+ if (!IsCoordPortalCopy(copy))
+ {
+ DoCopy(copy, query_string, false);
exec_on_coord = false;
+ }
+ else
+ exec_on_coord = true;
}
else
{
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index b6275d9..6965e2e 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -602,7 +602,7 @@ ProcessUtility(Node *parsetree,
uint64 processed;
#ifdef PGXC
bool done;
- processed = DoCopy((CopyStmt *) parsetree, queryString, true, &done);
+ processed = DoCopy((CopyStmt *) parsetree, queryString, true);
#else
processed = DoCopy((CopyStmt *) parsetree, queryString):
#endif
diff --git a/src/include/commands/copy.h b/src/include/commands/copy.h
index 7c0b4ca..5e7830a 100644
--- a/src/include/commands/copy.h
+++ b/src/include/commands/copy.h
@@ -18,7 +18,8 @@
#include "tcop/dest.h"
#ifdef PGXC
-extern uint64 DoCopy(const CopyStmt *stmt, const char *queryString, bool exec_on_coord_portal, bool *executed);
+extern uint64 DoCopy(const CopyStmt *stmt, const char *queryString, bool exec_on_coord_portal);
+extern bool IsCoordPortalCopy(const CopyStmt *stmt);
#else
extern uint64 DoCopy(const CopyStmt *stmt, const char *queryString);
#endif
commit 45617c6321fa7a95d0b062f0918c9d9935f7fe53
Author: Mason S <mas...@ma...>
Date: Wed May 19 19:06:10 2010 -0400
Fixed a bug when using a table after it had been created in the same
transaction but not committed. The problem was the location info
in relcache was not read in.
I just invalidated the entry immediately after creation to force it to
be created properly.
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index f74c05c..fa6456a 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -547,6 +547,8 @@ DefineRelation(CreateStmt *stmt, char relkind)
{
AddRelationDistribution (relationId, stmt->distributeby, inheritOids, descriptor);
CommandCounterIncrement();
+ /* Make sure locator info gets rebuilt */
+ RelationCacheInvalidateEntry(relationId);
}
#endif
-----------------------------------------------------------------------
hooks/post-receive
--
Postgres-XC
|