Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1ca0874

Browse files
committed
Ooops, I was a little too enthusiastic about suppressing default
index opclasses; they might be default for some other datatype, in which case we mustn't suppress 'em.
1 parent 3f8a50c commit 1ca0874

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/backend/utils/adt/ruleutils.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* back to source text
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.83 2001/10/01 20:15:26 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.84 2001/10/04 22:00:10 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -136,7 +136,7 @@ static void get_sublink_expr(Node *node, deparse_context *context);
136136
static void get_from_clause(Query *query, deparse_context *context);
137137
static void get_from_clause_item(Node *jtnode, Query *query,
138138
deparse_context *context);
139-
static void get_opclass_name(Oid opclass, bool only_nondefault,
139+
static void get_opclass_name(Oid opclass, Oid actual_datatype,
140140
StringInfo buf);
141141
static bool tleIsArrayAssign(TargetEntry *tle);
142142
static char *quote_identifier(char *ident);
@@ -408,7 +408,9 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
408408
sep = "";
409409
for (keyno = 0; keyno < INDEX_MAX_KEYS; keyno++)
410410
{
411-
if (idxrec->indkey[keyno] == InvalidAttrNumber)
411+
AttrNumber attnum = idxrec->indkey[keyno];
412+
413+
if (attnum == InvalidAttrNumber)
412414
break;
413415

414416
appendStringInfo(&keybuf, sep);
@@ -419,13 +421,15 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
419421
*/
420422
appendStringInfo(&keybuf, "%s",
421423
quote_identifier(get_relid_attribute_name(idxrec->indrelid,
422-
idxrec->indkey[keyno])));
424+
attnum)));
423425

424426
/*
425427
* If not a functional index, add the operator class name
426428
*/
427429
if (idxrec->indproc == InvalidOid)
428-
get_opclass_name(idxrec->indclass[keyno], true, &keybuf);
430+
get_opclass_name(idxrec->indclass[keyno],
431+
get_atttype(idxrec->indrelid, attnum),
432+
&keybuf);
429433
}
430434

431435
if (idxrec->indproc != InvalidOid)
@@ -446,7 +450,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
446450
appendStringInfo(&buf, "%s(%s)",
447451
quote_identifier(NameStr(procStruct->proname)),
448452
keybuf.data);
449-
get_opclass_name(idxrec->indclass[0], true, &buf);
453+
get_opclass_name(idxrec->indclass[0], procStruct->prorettype, &buf);
450454

451455
ReleaseSysCache(proctup);
452456
}
@@ -2504,12 +2508,14 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
25042508
* get_opclass_name - fetch name of an index operator class
25052509
*
25062510
* The opclass name is appended (after a space) to buf.
2507-
* If "only_nondefault" is true, the opclass name is appended only if
2508-
* it isn't the default for its datatype.
2511+
*
2512+
* Output is suppressed if the opclass is the default for the given
2513+
* actual_datatype. (If you don't want this behavior, just pass
2514+
* InvalidOid for actual_datatype.)
25092515
* ----------
25102516
*/
25112517
static void
2512-
get_opclass_name(Oid opclass, bool only_nondefault,
2518+
get_opclass_name(Oid opclass, Oid actual_datatype,
25132519
StringInfo buf)
25142520
{
25152521
HeapTuple ht_opc;
@@ -2521,7 +2527,7 @@ get_opclass_name(Oid opclass, bool only_nondefault,
25212527
if (!HeapTupleIsValid(ht_opc))
25222528
elog(ERROR, "cache lookup failed for opclass %u", opclass);
25232529
opcrec = (Form_pg_opclass) GETSTRUCT(ht_opc);
2524-
if (!only_nondefault || !opcrec->opcdefault)
2530+
if (actual_datatype != opcrec->opcintype || !opcrec->opcdefault)
25252531
appendStringInfo(buf, " %s",
25262532
quote_identifier(NameStr(opcrec->opcname)));
25272533
ReleaseSysCache(ht_opc);

0 commit comments

Comments
 (0)