aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_utilcmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/parser/parse_utilcmd.c')
-rw-r--r--src/backend/parser/parse_utilcmd.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 75c8d863dcd..f09e78dd8e3 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -19,7 +19,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.34 2009/12/22 23:54:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.35 2009/12/23 02:35:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -48,6 +48,7 @@
#include "parser/parse_clause.h"
#include "parser/parse_expr.h"
#include "parser/parse_relation.h"
+#include "parser/parse_target.h"
#include "parser/parse_type.h"
#include "parser/parse_utilcmd.h"
#include "parser/parser.h"
@@ -789,34 +790,24 @@ transformInhRelation(ParseState *pstate, CreateStmtContext *cxt,
/*
* chooseIndexName
*
- * Set name for unnamed index. See also the same logic in DefineIndex.
+ * Compute name for an index. This must match code in indexcmds.c.
+ *
+ * XXX this is inherently broken because the indexes aren't created
+ * immediately, so we fail to resolve conflicts when the same name is
+ * derived for multiple indexes. However, that's a reasonably uncommon
+ * situation, so we'll live with it for now.
*/
static char *
chooseIndexName(const RangeVar *relation, IndexStmt *index_stmt)
{
- Oid namespaceId;
+ Oid namespaceId;
+ List *colnames;
namespaceId = RangeVarGetCreationNamespace(relation);
- if (index_stmt->primary)
- {
- /* no need for column list with pkey */
- return ChooseRelationName(relation->relname, NULL,
- "pkey", namespaceId);
- }
- else if (index_stmt->excludeOpNames != NIL)
- {
- IndexElem *iparam = (IndexElem *) linitial(index_stmt->indexParams);
-
- return ChooseRelationName(relation->relname, iparam->name,
- "exclusion", namespaceId);
- }
- else
- {
- IndexElem *iparam = (IndexElem *) linitial(index_stmt->indexParams);
-
- return ChooseRelationName(relation->relname, iparam->name,
- "key", namespaceId);
- }
+ colnames = ChooseIndexColumnNames(index_stmt->indexParams);
+ return ChooseIndexName(relation->relname, namespaceId,
+ colnames, index_stmt->excludeOpNames,
+ index_stmt->primary, index_stmt->isconstraint);
}
/*
@@ -828,6 +819,7 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
AttrNumber *attmap)
{
Oid source_relid = RelationGetRelid(source_idx);
+ Form_pg_attribute *attrs = RelationGetDescr(source_idx)->attrs;
HeapTuple ht_idxrel;
HeapTuple ht_idx;
Form_pg_class idxrelrec;
@@ -1023,6 +1015,9 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
keycoltype = exprType(indexkey);
}
+ /* Copy the original index column name */
+ iparam->indexcolname = pstrdup(NameStr(attrs[keyno]->attname));
+
/* Add the operator class name, if non-default */
iparam->opclass = get_opclass(indclass->values[keyno], keycoltype);
@@ -1416,6 +1411,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
iparam = makeNode(IndexElem);
iparam->name = pstrdup(key);
iparam->expr = NULL;
+ iparam->indexcolname = NULL;
iparam->opclass = NIL;
iparam->ordering = SORTBY_DEFAULT;
iparam->nulls_ordering = SORTBY_NULLS_DEFAULT;
@@ -1544,6 +1540,11 @@ transformIndexStmt(IndexStmt *stmt, const char *queryString)
if (ielem->expr)
{
+ /* Extract preliminary index col name before transforming expr */
+ if (ielem->indexcolname == NULL)
+ ielem->indexcolname = FigureIndexColname(ielem->expr);
+
+ /* Now do parse transformation of the expression */
ielem->expr = transformExpr(pstate, ielem->expr);
/*