Skip to content

Commit a4402ec

Browse files
committed
Fixes a bug in 'create index'
Submitted by: Dan McGuirk <mcguirk@indirect.com>
1 parent d6fa4d9 commit a4402ec

File tree

7 files changed

+106
-59
lines changed

7 files changed

+106
-59
lines changed

src/backend/catalog/pg_amop.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_amop.h,v 1.2 1996/07/20 08:19:11 scrappy Exp $
10+
* $Id: pg_amop.h,v 1.3 1996/08/15 07:42:06 scrappy Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -219,11 +219,11 @@ DATA(insert OID = 0 ( 403 408 462 5 btreesel btreenpage ));
219219
* nbtree name_ops
220220
*/
221221

222-
DATA(insert OID = 0 ( 403 409 660 1 btreesel btreenpage ));
223-
DATA(insert OID = 0 ( 403 409 661 2 btreesel btreenpage ));
224-
DATA(insert OID = 0 ( 403 409 93 3 btreesel btreenpage ));
225-
DATA(insert OID = 0 ( 403 409 663 4 btreesel btreenpage ));
226-
DATA(insert OID = 0 ( 403 409 662 5 btreesel btreenpage ));
222+
DATA(insert OID = 0 ( 403 1181 660 1 btreesel btreenpage ));
223+
DATA(insert OID = 0 ( 403 1181 661 2 btreesel btreenpage ));
224+
DATA(insert OID = 0 ( 403 1181 93 3 btreesel btreenpage ));
225+
DATA(insert OID = 0 ( 403 1181 663 4 btreesel btreenpage ));
226+
DATA(insert OID = 0 ( 403 1181 662 5 btreesel btreenpage ));
227227

228228
/*
229229
* nbtree char16_ops
@@ -453,11 +453,11 @@ DATA(insert OID = 0 ( 404 430 647 5 btreesel btreenpage ));
453453
* nobtree name_ops
454454
*/
455455

456-
DATA(insert OID = 0 ( 404 409 660 1 btreesel btreenpage ));
457-
DATA(insert OID = 0 ( 404 409 661 2 btreesel btreenpage ));
458-
DATA(insert OID = 0 ( 404 409 93 3 btreesel btreenpage ));
459-
DATA(insert OID = 0 ( 404 409 663 4 btreesel btreenpage ));
460-
DATA(insert OID = 0 ( 404 409 662 5 btreesel btreenpage ));
456+
DATA(insert OID = 0 ( 404 1181 660 1 btreesel btreenpage ));
457+
DATA(insert OID = 0 ( 404 1181 661 2 btreesel btreenpage ));
458+
DATA(insert OID = 0 ( 404 1181 93 3 btreesel btreenpage ));
459+
DATA(insert OID = 0 ( 404 1181 663 4 btreesel btreenpage ));
460+
DATA(insert OID = 0 ( 404 1181 662 5 btreesel btreenpage ));
461461

462462
/*
463463
* nobtree text_ops
@@ -526,7 +526,7 @@ DATA(insert OID = 0 ( 405 430 99 1 hashsel hashnpage ));
526526
/*
527527
* hash table name_ops
528528
*/
529-
DATA(insert OID = 0 ( 405 409 93 1 hashsel hashnpage ));
529+
DATA(insert OID = 0 ( 405 1181 93 1 hashsel hashnpage ));
530530
/*
531531
* hash table text_ops
532532
*/

src/backend/catalog/pg_amproc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $Id: pg_amproc.h,v 1.2 1996/07/20 08:19:13 scrappy Exp $
12+
* $Id: pg_amproc.h,v 1.3 1996/08/15 07:42:07 scrappy Exp $
1313
*
1414
* NOTES
1515
* the genbki.sh script reads this file and generates .bki
@@ -82,7 +82,7 @@ DATA(insert OID = 0 (403 429 358 1));
8282
DATA(insert OID = 0 (403 406 689 1));
8383
DATA(insert OID = 0 (403 407 690 1));
8484
DATA(insert OID = 0 (403 408 691 1));
85-
DATA(insert OID = 0 (403 409 359 1));
85+
DATA(insert OID = 0 (403 1181 359 1));
8686
DATA(insert OID = 0 (403 430 374 1));
8787
DATA(insert OID = 0 (403 431 360 1));
8888
DATA(insert OID = 0 (403 432 357 1));
@@ -108,7 +108,7 @@ DATA(insert OID = 0 (404 429 358 1));
108108
DATA(insert OID = 0 (404 406 689 1));
109109
DATA(insert OID = 0 (404 407 690 1));
110110
DATA(insert OID = 0 (404 408 691 1));
111-
DATA(insert OID = 0 (404 409 359 1));
111+
DATA(insert OID = 0 (404 1181 359 1));
112112
DATA(insert OID = 0 (404 430 374 1));
113113
DATA(insert OID = 0 (404 431 360 1));
114114
DATA(insert OID = 0 (404 432 357 1));
@@ -125,7 +125,7 @@ DATA(insert OID = 0 (405 429 454 1));
125125
DATA(insert OID = 0 (405 406 692 1));
126126
DATA(insert OID = 0 (405 407 693 1));
127127
DATA(insert OID = 0 (405 408 694 1));
128-
DATA(insert OID = 0 (405 409 455 1));
128+
DATA(insert OID = 0 (405 1181 455 1));
129129
DATA(insert OID = 0 (405 430 499 1));
130130
DATA(insert OID = 0 (405 431 456 1));
131131
DATA(insert OID = 0 (405 1076 1080 1));

src/backend/catalog/pg_opclass.h

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_opclass.h,v 1.1.1.1 1996/07/09 06:21:17 scrappy Exp $
10+
* $Id: pg_opclass.h,v 1.2 1996/08/15 07:42:09 scrappy Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -34,6 +34,7 @@
3434

3535
CATALOG(pg_opclass) {
3636
NameData opcname;
37+
Oid opcdeftype;
3738
} FormData_pg_opclass;
3839

3940
/* ----------------
@@ -47,39 +48,46 @@ typedef FormData_pg_opclass *Form_pg_opclass;
4748
* compiler constants for pg_opclass
4849
* ----------------
4950
*/
50-
#define Natts_pg_opclass 1
51+
#define Natts_pg_opclass 2
5152
#define Anum_pg_opclass_opcname 1
53+
#define Anum_pg_opclass_opcdeftype 2
5254

5355
/* ----------------
5456
* initial contents of pg_opclass
5557
* ----------------
5658
*/
5759

58-
DATA(insert OID = 406 ( char2_ops ));
59-
DATA(insert OID = 407 ( char4_ops ));
60-
DATA(insert OID = 408 ( char8_ops ));
61-
DATA(insert OID = 409 ( name_ops ));
62-
DATA(insert OID = 421 ( int2_ops ));
63-
DATA(insert OID = 422 ( box_ops ));
64-
DATA(insert OID = 423 ( float8_ops ));
65-
DATA(insert OID = 424 ( int24_ops ));
66-
DATA(insert OID = 425 ( int42_ops ));
67-
DATA(insert OID = 426 ( int4_ops ));
60+
/*
61+
* putting _null_'s in the (fixed-length) type field is bad
62+
* (see the README in this directory), so just put zeros
63+
* in, which are invalid OID's anyway. --djm
64+
*/
65+
DATA(insert OID = 406 ( char2_ops 409 ));
66+
DATA(insert OID = 407 ( char4_ops 410 ));
67+
DATA(insert OID = 408 ( char8_ops 411 ));
68+
/* OID 409 is already used in table pg_type--this one should be unused */
69+
DATA(insert OID = 1181 ( name_ops 19 ));
70+
DATA(insert OID = 421 ( int2_ops 21 ));
71+
DATA(insert OID = 422 ( box_ops 603 ));
72+
DATA(insert OID = 423 ( float8_ops 701 ));
73+
DATA(insert OID = 424 ( int24_ops 0 ));
74+
DATA(insert OID = 425 ( int42_ops 0 ));
75+
DATA(insert OID = 426 ( int4_ops 23 ));
6876
#define INT4_OPS_OID 426
69-
DATA(insert OID = 427 ( oid_ops ));
70-
DATA(insert OID = 428 ( float4_ops ));
71-
DATA(insert OID = 429 ( char_ops ));
72-
DATA(insert OID = 430 ( char16_ops ));
73-
DATA(insert OID = 431 ( text_ops ));
74-
DATA(insert OID = 432 ( abstime_ops ));
75-
DATA(insert OID = 433 ( bigbox_ops));
76-
DATA(insert OID = 434 ( poly_ops));
77-
DATA(insert OID = 435 ( oidint4_ops));
78-
DATA(insert OID = 436 ( oidname_ops));
79-
DATA(insert OID = 437 ( oidint2_ops));
80-
DATA(insert OID = 1076 ( bpchar_ops));
81-
DATA(insert OID = 1077 ( varchar_ops));
82-
DATA(insert OID = 1114 ( date_ops));
83-
DATA(insert OID = 1115 ( time_ops));
77+
DATA(insert OID = 427 ( oid_ops 26 ));
78+
DATA(insert OID = 428 ( float4_ops 700 ));
79+
DATA(insert OID = 429 ( char_ops 18 ));
80+
DATA(insert OID = 430 ( char16_ops 20 ));
81+
DATA(insert OID = 431 ( text_ops 25 ));
82+
DATA(insert OID = 432 ( abstime_ops 702 ));
83+
DATA(insert OID = 433 ( bigbox_ops 0 ));
84+
DATA(insert OID = 434 ( poly_ops 604 ));
85+
DATA(insert OID = 435 ( oidint4_ops 910 ));
86+
DATA(insert OID = 436 ( oidname_ops 911 ));
87+
DATA(insert OID = 437 ( oidint2_ops 810 ));
88+
DATA(insert OID = 1076 ( bpchar_ops 1042 ));
89+
DATA(insert OID = 1077 ( varchar_ops 1043 ));
90+
DATA(insert OID = 1114 ( date_ops 1082 ));
91+
DATA(insert OID = 1115 ( time_ops 1083 ));
8492

8593
#endif /* PG_OPCLASS_H */

src/backend/commands/defind.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/defind.c,v 1.1.1.1 1996/07/09 06:21:20 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/defind.c,v 1.2 1996/08/15 07:42:19 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -23,6 +23,7 @@
2323
#include "catalog/index.h"
2424
#include "catalog/pg_index.h"
2525
#include "catalog/pg_proc.h"
26+
#include "catalog/pg_opclass.h"
2627
#include "nodes/pg_list.h"
2728
#include "nodes/plannodes.h"
2829
#include "nodes/primnodes.h"
@@ -51,6 +52,7 @@ static void FuncIndexArgs(IndexElem *funcIndex, AttrNumber *attNumP,
5152
Oid *argTypes, Oid *opOidP, Oid relId);
5253
static void NormIndexAttrs(List *attList, AttrNumber *attNumP,
5354
Oid *opOidP, Oid relId);
55+
static char *GetDefaultOpClass(Oid atttypid);
5456

5557
/*
5658
* DefineIndex --
@@ -439,14 +441,10 @@ NormIndexAttrs(List *attList, /* list of IndexElem's */
439441

440442
for (rest=attList; rest != NIL; rest = lnext(rest)) {
441443
IndexElem *attribute;
444+
AttributeTupleForm attform;
442445

443446
attribute = lfirst(rest);
444447

445-
if (attribute->class == NULL) {
446-
elog(WARN,
447-
"DefineIndex: default index class unsupported");
448-
}
449-
450448
if (attribute->name == NULL)
451449
elog(WARN, "missing attribute for define index");
452450

@@ -459,7 +457,19 @@ NormIndexAttrs(List *attList, /* list of IndexElem's */
459457
"DefineIndex: attribute \"%s\" not found",
460458
attribute->name);
461459
}
462-
*attNumP++ = ((AttributeTupleForm)GETSTRUCT(tuple))->attnum;
460+
461+
attform = (AttributeTupleForm)GETSTRUCT(tuple);
462+
*attNumP++ = attform->attnum;
463+
464+
if (attribute->class == NULL) {
465+
/* no operator class specified, so find the default */
466+
attribute->class = GetDefaultOpClass(attform->atttypid);
467+
if(attribute->class == NULL) {
468+
elog(WARN,
469+
"Can't find a default operator class for type %d.",
470+
attform->atttypid);
471+
}
472+
}
463473

464474
tuple = SearchSysCacheTuple(CLANAME,
465475
PointerGetDatum(attribute->class),
@@ -473,6 +483,21 @@ NormIndexAttrs(List *attList, /* list of IndexElem's */
473483
}
474484
}
475485

486+
static char *
487+
GetDefaultOpClass(Oid atttypid)
488+
{
489+
HeapTuple tuple;
490+
491+
tuple = SearchSysCacheTuple(CLADEFTYPE,
492+
ObjectIdGetDatum(atttypid),
493+
0, 0, 0);
494+
if(!HeapTupleIsValid(tuple)) {
495+
return 0;
496+
}
497+
498+
return nameout(&(((Form_pg_opclass)GETSTRUCT(tuple))->opcname));
499+
}
500+
476501
/*
477502
* RemoveIndex --
478503
* Deletes an index.

src/backend/parser/gram.y

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.6 1996/08/13 01:29:33 scrappy Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.7 1996/08/15 07:42:29 scrappy Exp $
1414
*
1515
* HISTORY
1616
* AUTHOR DATE MAJOR EVENT
@@ -109,8 +109,8 @@ static Node *makeA_Expr(int op, char *opname, Node *lexpr, Node *rexpr);
109109
ExplainStmt
110110

111111
%type <str> relation_name, copy_file_name, copy_delimiter, def_name,
112-
database_name, access_method, attr_name, class, index_name,
113-
var_name, name, file_name, recipe_name
112+
database_name, access_method_clause, access_method, attr_name,
113+
class, index_name, var_name, name, file_name, recipe_name
114114

115115
%type <str> opt_id, opt_portal_name,
116116
before_clause, after_clause, all_Op, MathOp, opt_name, opt_unique
@@ -653,21 +653,25 @@ opt_portal_name: IN name { $$ = $2;}
653653
*****************************************************************************/
654654

655655
IndexStmt: CREATE INDEX index_name ON relation_name
656-
USING access_method '(' index_params ')'
656+
access_method_clause '(' index_params ')'
657657
{
658658
/* should check that access_method is valid,
659659
etc ... but doesn't */
660660
IndexStmt *n = makeNode(IndexStmt);
661661
n->idxname = $3;
662662
n->relname = $5;
663-
n->accessMethod = $7;
664-
n->indexParams = $9;
663+
n->accessMethod = $6;
664+
n->indexParams = $8;
665665
n->withClause = NIL;
666666
n->whereClause = NULL;
667667
$$ = (Node *)n;
668668
}
669669
;
670670

671+
access_method_clause: USING access_method { $$ = $2; }
672+
| /* empty -- 'btree' is default access method */
673+
{ $$ = "btree"; }
674+
671675
/*****************************************************************************
672676
*
673677
* QUERY:

src/backend/utils/cache/syscache.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.1.1.1 1996/07/09 06:22:07 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.2 1996/08/15 07:42:52 scrappy Exp $
1111
*
1212
* NOTES
1313
* These routines allow the parser/planner/executor to perform
@@ -304,7 +304,16 @@ static struct cachedesc cacheinfo[] = {
304304
0 },
305305
offsetof(FormData_pg_proc, prosrc),
306306
ProcedureSrcIndex,
307-
(ScanFunc) ProcedureSrcIndexScan }
307+
(ScanFunc) ProcedureSrcIndexScan },
308+
{ OperatorClassRelationName, /* CLADEFTYPE */
309+
1,
310+
{ Anum_pg_opclass_opcdeftype,
311+
0,
312+
0,
313+
0 },
314+
sizeof(FormData_pg_opclass),
315+
NULL,
316+
(ScanFunc) NULL }
308317
};
309318

310319
static struct catcache *SysCache[lengthof(cacheinfo)];

src/backend/utils/syscache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: syscache.h,v 1.1.1.1 1996/07/09 06:22:02 scrappy Exp $
9+
* $Id: syscache.h,v 1.2 1996/08/15 07:42:45 scrappy Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -58,6 +58,7 @@
5858
#define GROSYSID 24
5959
#define REWRITENAME 25
6060
#define PROSRC 26
61+
#define CLADEFTYPE 27
6162

6263
/* ----------------
6364
* struct cachedesc: information needed for a call to InitSysCache()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy