summaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_utilcmd.c
diff options
context:
space:
mode:
authorMichael Paquier2012-10-12 03:00:58 +0000
committerMichael Paquier2012-10-12 03:06:35 +0000
commitd165a5c2458e97cbf943135cf1bb534b8f8af807 (patch)
tree7fd679bc1f7e5a822e1e188ee6b92a95a6ada36b /src/backend/parser/parse_utilcmd.c
parentdfb46fa4df777fd4641a1a1e5aefc5dc6cef43c7 (diff)
Refactor and clean-up of relation locator code
Locator is the part in charge of managing, building and referencing distribution information of tables in catalogs by providing sufficient functions that backends can refer to. Some of this code was pretty outdated and a portion of the APIs used were duplicated, making the code more difficult to apprehend. Locator information also included the following information: - OID of relation it refers to - Attribute number of distribution key if distribution is value-based - Column name of distribution key As column name can be retrieved from system cache by using simply OID and attribute number, the column name is removed, simplifying the code by that much. So now all the APIs of locator.c and related only use the attribute number of a relation when referencing the distribution key inside code. This cleanup also tackles some potential bugs related to hash/modulo management that might have appeared if other value-based distribution would have been defined in XC. So code is more extensible now.
Diffstat (limited to 'src/backend/parser/parse_utilcmd.c')
-rw-r--r--src/backend/parser/parse_utilcmd.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 9fd4a09fe4..b8ebf9b52d 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -1891,13 +1891,16 @@ transformFKConstraints(CreateStmtContext *cxt,
* If not yet set, set it to first column in FK constraint
* if it references a partitioned table
*/
- if (IS_PGXC_COORDINATOR && !cxt->fallback_dist_col)
+ if (IS_PGXC_COORDINATOR &&
+ !cxt->fallback_dist_col &&
+ list_length(constraint->pk_attrs) != 0)
{
Oid pk_rel_id = RangeVarGetRelid(constraint->pktable, NoLock, false);
+ AttrNumber attnum = get_attnum(pk_rel_id,
+ strVal(list_nth(constraint->fk_attrs, 0)));
- /* make sure it is a partitioned column */
- if (list_length(constraint->pk_attrs) != 0
- && IsHashColumnForRelId(pk_rel_id, strVal(list_nth(constraint->pk_attrs,0))))
+ /* Make sure key is done on a partitioned column */
+ if (IsDistribColumn(pk_rel_id, attnum))
{
/* take first column */
char *colstr = strdup(strVal(list_nth(constraint->fk_attrs,0)));