1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Fixes a bug in 'create index'

Submitted by: Dan McGuirk <mcguirk@indirect.com>
This commit is contained in:
Marc G. Fournier
1996-08-15 07:42:52 +00:00
parent d6fa4d95cd
commit a4402ecc8c
7 changed files with 106 additions and 59 deletions

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/defind.c,v 1.1.1.1 1996/07/09 06:21:20 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/defind.c,v 1.2 1996/08/15 07:42:19 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -23,6 +23,7 @@
#include "catalog/index.h"
#include "catalog/pg_index.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_opclass.h"
#include "nodes/pg_list.h"
#include "nodes/plannodes.h"
#include "nodes/primnodes.h"
@@ -51,6 +52,7 @@ static void FuncIndexArgs(IndexElem *funcIndex, AttrNumber *attNumP,
Oid *argTypes, Oid *opOidP, Oid relId);
static void NormIndexAttrs(List *attList, AttrNumber *attNumP,
Oid *opOidP, Oid relId);
static char *GetDefaultOpClass(Oid atttypid);
/*
* DefineIndex --
@@ -439,14 +441,10 @@ NormIndexAttrs(List *attList, /* list of IndexElem's */
for (rest=attList; rest != NIL; rest = lnext(rest)) {
IndexElem *attribute;
AttributeTupleForm attform;
attribute = lfirst(rest);
if (attribute->class == NULL) {
elog(WARN,
"DefineIndex: default index class unsupported");
}
if (attribute->name == NULL)
elog(WARN, "missing attribute for define index");
@@ -459,7 +457,19 @@ NormIndexAttrs(List *attList, /* list of IndexElem's */
"DefineIndex: attribute \"%s\" not found",
attribute->name);
}
*attNumP++ = ((AttributeTupleForm)GETSTRUCT(tuple))->attnum;
attform = (AttributeTupleForm)GETSTRUCT(tuple);
*attNumP++ = attform->attnum;
if (attribute->class == NULL) {
/* no operator class specified, so find the default */
attribute->class = GetDefaultOpClass(attform->atttypid);
if(attribute->class == NULL) {
elog(WARN,
"Can't find a default operator class for type %d.",
attform->atttypid);
}
}
tuple = SearchSysCacheTuple(CLANAME,
PointerGetDatum(attribute->class),
@@ -473,6 +483,21 @@ NormIndexAttrs(List *attList, /* list of IndexElem's */
}
}
static char *
GetDefaultOpClass(Oid atttypid)
{
HeapTuple tuple;
tuple = SearchSysCacheTuple(CLADEFTYPE,
ObjectIdGetDatum(atttypid),
0, 0, 0);
if(!HeapTupleIsValid(tuple)) {
return 0;
}
return nameout(&(((Form_pg_opclass)GETSTRUCT(tuple))->opcname));
}
/*
* RemoveIndex --
* Deletes an index.