head 1.25; access; symbols release_4_2:1.25 aix_ok:1.24 Version_2_1:1.13 Version_2:1.9 C_Demo_1:1.6; locks; strict; comment @ * @; 1.25 date 94.02.07.11.52.57; author aoki; state Exp; branches; next 1.24; 1.24 date 93.06.15.22.02.46; author aoki; state Exp; branches; next 1.23; 1.23 date 93.05.16.18.44.36; author avi; state Exp; branches; next 1.22; 1.22 date 93.02.17.01.31.31; author olson; state Exp; branches; next 1.21; 1.21 date 92.02.26.22.51.19; author olson; state Exp; branches; next 1.20; 1.20 date 92.02.19.23.09.50; author olson; state Exp; branches; next 1.19; 1.19 date 92.02.12.13.22.54; author olson; state Exp; branches; next 1.18; 1.18 date 91.10.16.23.00.40; author mer; state Exp; branches; next 1.17; 1.17 date 91.10.04.16.06.16; author kemnitz; state Exp; branches; next 1.16; 1.16 date 91.10.04.16.05.23; author kemnitz; state Exp; branches; next 1.15; 1.15 date 91.09.29.00.21.41; author mer; state Exp; branches; next 1.14; 1.14 date 91.09.18.23.35.52; author kemnitz; state Exp; branches; next 1.13; 1.13 date 91.03.03.01.22.03; author mao; state Exp; branches; next 1.12; 1.12 date 90.08.18.00.39.19; author cimarron; state Exp; branches; next 1.11; 1.11 date 90.08.13.20.46.54; author cimarron; state Exp; branches; next 1.10; 1.10 date 90.08.08.08.10.36; author cimarron; state Exp; branches; next 1.9; 1.9 date 90.05.25.09.56.16; author mao; state Version_2; branches; next 1.8; 1.8 date 90.02.12.19.21.50; author mao; state Exp; branches; next 1.7; 1.7 date 89.10.13.17.23.35; author hirohama; state Exp; branches; next 1.6; 1.6 date 89.09.05.16.47.30; author mao; state C_Demo_1; branches; next 1.5; 1.5 date 89.08.29.15.03.46; author hirohama; state Exp; branches; next 1.4; 1.4 date 89.08.22.20.31.57; author hirohama; state Exp; branches; next 1.3; 1.3 date 89.08.09.18.10.08; author cimarron; state Exp; branches; next 1.2; 1.2 date 89.02.02.16.26.24; author dillon; state Stab; branches; next 1.1; 1.1 date 89.01.17.05.52.53; author cimarron; state Exp; branches; next ; desc @@ 1.25 log @SearchSysCacheTuple called with wrong args (not enough, not cast right) @ text @/* * defind.c -- * POSTGRES define, extend and remove index code. */ #include "tmp/postgres.h" RcsId("$Header: /import/faerie/faerie/aoki/postgres/src/backend/commands/RCS/defind.c,v 1.24 1993/06/15 22:02:46 aoki Exp aoki $"); #include "access/attnum.h" #include "access/genam.h" #include "access/heapam.h" #include "access/htup.h" #include "access/funcindex.h" #include "catalog/syscache.h" #include "catalog/pg_index.h" #include "catalog/pg_proc.h" #include "nodes/pg_lisp.h" #include "nodes/plannodes.h" #include "nodes/primnodes.h" #include "nodes/relation.h" #include "utils/log.h" #include "utils/palloc.h" #include "commands/defrem.h" #include "parse.h" #include "parser/parsetree.h" #include "planner/prepqual.h" #include "planner/clause.h" #include "planner/clauses.h" #include "lib/copyfuncs.h" #define IsFuncIndex(ATTR_LIST) (listp(CAAR(ATTR_LIST))) void DefineIndex(heapRelationName, indexRelationName, accessMethodName, attributeList, parameterList, predicate) Name heapRelationName; Name indexRelationName; Name accessMethodName; LispValue attributeList; LispValue parameterList; LispValue predicate; { ObjectId *classObjectId; ObjectId accessMethodId; ObjectId relationId; AttributeNumber numberOfAttributes; AttributeNumber *attributeNumberA; HeapTuple tuple; uint16 parameterCount; Datum *parameterA = NULL; Datum *nextP; FuncIndexInfo fInfo; LispValue cnfPred = LispNil; AssertArg(NameIsValid(heapRelationName)); AssertArg(NameIsValid(indexRelationName)); AssertArg(NameIsValid(accessMethodName)); AssertArg(listp(attributeList)); AssertArg(listp(parameterList)); /* * Handle attributes */ numberOfAttributes = length(attributeList); if (numberOfAttributes <= 0) { elog(WARN, "DefineIndex: must specify at least one attribute"); } /* * compute heap relation id */ tuple = SearchSysCacheTuple(RELNAME, (char *) heapRelationName, (char *) NULL, (char *) NULL, (char *) NULL); if (!HeapTupleIsValid(tuple)) { elog(WARN, "DefineIndex: %s relation not found", &(heapRelationName->data[0])); } relationId = tuple->t_oid; /* * compute access method id */ tuple = SearchSysCacheTuple(AMNAME, (char *) accessMethodName, (char *) NULL, (char *) NULL, (char *) NULL); if (!HeapTupleIsValid(tuple)) { elog(WARN, "DefineIndex: %s access method not found", &(accessMethodName->data[0])); } accessMethodId = tuple->t_oid; /* * Handle parameters */ parameterCount = length(parameterList) / 2; #ifndef PERFECTPARSER AssertArg(length(parameterList) == 2 * parameterCount); #endif if (parameterCount >= 1) { parameterA = LintCast(Datum *, palloc(2 * parameterCount * sizeof *parameterA)); nextP = ¶meterA[0]; while (!lispNullp(parameterList)) { #ifndef PERFECTPARSER AssertArg(lispStringp(CAR(parameterList))); #endif *nextP = (Datum)CString(CAR(parameterList)); parameterList = CDR(parameterList); nextP += 1; } } /* * Convert the partial-index predicate from parsetree form to plan * form, so it can be readily evaluated during index creation. * Note: "predicate" comes in as a list containing (1) the predicate * itself (a where_clause), and (2) a corresponding range table. */ if (predicate != LispNil && CAR(predicate) != LispNil) { cnfPred = cnfify(lispCopy(CAR(predicate)), true); fix_opids(cnfPred); CheckPredicate(cnfPred, CADR(predicate), relationId); } if (IsFuncIndex(attributeList)) { int nargs; nargs = length(CDR(CAAR(attributeList))); if (nargs > INDEX_MAX_KEYS) { elog(WARN, "Too many args to function, limit of %d", INDEX_MAX_KEYS); } FIgetnArgs(&fInfo) = nargs; strncpy(FIgetname(&fInfo), CString(CAAR(CAR(attributeList))), sizeof(NameData)); attributeNumberA = LintCast(AttributeNumber *, palloc(nargs * sizeof attributeNumberA[0])); classObjectId = LintCast(ObjectId *, palloc(sizeof classObjectId[0])); FuncIndexArgs(attributeList, attributeNumberA, &(FIgetArg(&fInfo, 0)), classObjectId, relationId); index_create(heapRelationName, indexRelationName, &fInfo, accessMethodId, numberOfAttributes, attributeNumberA, classObjectId, parameterCount, parameterA, cnfPred); } else { attributeNumberA = LintCast(AttributeNumber *, palloc(numberOfAttributes*sizeof attributeNumberA[0])); classObjectId = LintCast(ObjectId *, palloc(numberOfAttributes * sizeof classObjectId[0])); NormIndexAttrs(attributeList, attributeNumberA, classObjectId, relationId); index_create(heapRelationName, indexRelationName, NULL, accessMethodId, numberOfAttributes, attributeNumberA, classObjectId, parameterCount, parameterA, cnfPred); } } void ExtendIndex(indexRelationName, predicate) Name indexRelationName; LispValue predicate; { ObjectId *classObjectId; ObjectId accessMethodId; ObjectId indexId, relationId; ObjectId indproc; AttributeNumber numberOfAttributes; AttributeNumber *attributeNumberA; HeapTuple tuple; FuncIndexInfo fInfo; FuncIndexInfo *funcInfo = NULL; IndexTupleForm index; LispValue oldPred = LispNil; LispValue cnfPred = LispNil; LispValue predInfo; Relation heapRelation; Relation indexRelation; int i; AssertArg(NameIsValid(indexRelationName)); /* * compute index relation id and access method id */ tuple = SearchSysCacheTuple(RELNAME, (char *) indexRelationName, (char *) NULL, (char *) NULL, (char *) NULL); if (!HeapTupleIsValid(tuple)) { elog(WARN, "ExtendIndex: %s index not found", &(indexRelationName->data[0])); } indexId = tuple->t_oid; accessMethodId = ((Form_pg_relation) GETSTRUCT(tuple))->relam; /* * find pg_index tuple */ tuple = SearchSysCacheTuple(INDEXRELID, (char *) ObjectIdGetDatum(indexId), (char *) NULL, (char *) NULL, (char *) NULL); if (!HeapTupleIsValid(tuple)) { elog(WARN, "ExtendIndex: %s is not an index", &(indexRelationName->data[0])); } /* * Extract info from the pg_index tuple */ index = (IndexTupleForm)GETSTRUCT(tuple); Assert(index->indexrelid == indexId); relationId = index->indrelid; indproc = index->indproc; for (i=0; iindkey[i] == 0) break; numberOfAttributes = i; if (VARSIZE(&index->indpred) != 0) { char *predString; LispValue lispReadString(); predString = fmgr(F_TEXTOUT, &index->indpred); oldPred = lispReadString(predString); pfree(predString); } if (oldPred == LispNil) elog(WARN, "ExtendIndex: %s is not a partial index", &(indexRelationName->data[0])); /* * Convert the extension predicate from parsetree form to plan * form, so it can be readily evaluated during index creation. * Note: "predicate" comes in as a list containing (1) the predicate * itself (a where_clause), and (2) a corresponding range table. */ if (CAR(predicate) != LispNil) { cnfPred = cnfify(lispCopy(CAR(predicate)), true); fix_opids(cnfPred); CheckPredicate(cnfPred, CADR(predicate), relationId); } /* make predInfo list to pass to index_build */ predInfo = lispCons(cnfPred, lispCons(oldPred, LispNil)); attributeNumberA = LintCast(AttributeNumber *, palloc(numberOfAttributes*sizeof attributeNumberA[0])); classObjectId = LintCast(ObjectId *, palloc(numberOfAttributes * sizeof classObjectId[0])); for (i=0; iindkey[i]; classObjectId[i] = index->indclass[i]; } if (indproc != InvalidObjectId) { funcInfo = &fInfo; FIgetnArgs(funcInfo) = numberOfAttributes; tuple = SearchSysCacheTuple(PROOID, (char *) ObjectIdGetDatum(indproc), (char *) NULL, (char *) NULL, (char *) NULL); if (!HeapTupleIsValid(tuple)) elog(WARN, "ExtendIndex: index procedure not found"); strncpy(FIgetname(funcInfo), ((Form_pg_proc) GETSTRUCT(tuple))->proname.data, sizeof(NameData)); FIgetProcOid(funcInfo) = tuple->t_oid; } heapRelation = heap_open(relationId); indexRelation = index_open(indexId); RelationSetLockForWrite(heapRelation); InitIndexStrategy(numberOfAttributes, indexRelation, accessMethodId); index_build(heapRelation, indexRelation, numberOfAttributes, attributeNumberA, 0, NULL, funcInfo, predInfo); } /* * CheckPredicate * Checks that the given list of partial-index predicates refer * (via the given range table) only to the given base relation oid, * and that they're in a form the planner can handle, i.e., * boolean combinations of "ATTR OP CONST" (yes, for now, the ATTR * has to be on the left). */ CheckPredicate(predList, rangeTable, baseRelOid) LispValue predList; LispValue rangeTable; ObjectId baseRelOid; { LispValue item; foreach (item, predList) { CheckPredExpr(CAR(item), rangeTable, baseRelOid); } } CheckPredExpr(predicate, rangeTable, baseRelOid) LispValue predicate; LispValue rangeTable; ObjectId baseRelOid; { LispValue clauses = LispNil, clause; if (fast_is_clause(predicate)) { /* CAR is Oper node */ CheckPredClause(predicate, rangeTable, baseRelOid); return; } else if (fast_or_clause(predicate)) clauses = (LispValue) get_orclauseargs(predicate); else if (fast_and_clause(predicate)) clauses = (LispValue) get_andclauseargs(predicate); else elog(WARN, "Unsupported partial-index predicate expression type"); foreach (clause, clauses) { CheckPredExpr(CAR(clause), rangeTable, baseRelOid); } } CheckPredClause(predicate, rangeTable, baseRelOid) LispValue predicate; LispValue rangeTable; ObjectId baseRelOid; { Var pred_var; Const pred_const; pred_var = (Var)get_leftop(predicate); pred_const = (Const)get_rightop(predicate); if (!IsA(CAR(predicate),Oper) || !IsA(pred_var,Var) || !IsA(pred_const,Const)) { elog(WARN, "Unsupported partial-index predicate clause type"); } if (CInteger(getrelid(get_varno(pred_var), rangeTable)) != baseRelOid) elog(WARN, "Partial-index predicates may refer only to the base relation"); } FuncIndexArgs(attList, attNumP, argTypes, opOidP, relId) LispValue attList; AttributeNumber *attNumP; ObjectId *argTypes; ObjectId *opOidP; ObjectId relId; { LispValue rest; HeapTuple tuple; Attribute att; tuple = SearchSysCacheTuple(CLANAME, (char *) CString(CADR(CAR(attList))), (char *) NULL, (char *) NULL, (char *) NULL); if (!HeapTupleIsValid(tuple)) { elog(WARN, "DefineIndex: %s class not found", CString(CADR(CAR(attList)))); } *opOidP = tuple->t_oid; bzero(argTypes, 8 * sizeof(ObjectId)); /* * process the function arguments */ for (rest=CDR(CAAR(attList)); rest != LispNil; rest = CDR(rest)) { LispValue arg; AssertArg(listp(rest)); arg = CAR(rest); AssertArg(lispStringp(arg)); tuple = SearchSysCacheTuple(ATTNAME, (char *) ObjectIdGetDatum(relId), (char *) CString(arg), (char *) NULL, (char *) NULL); if (!HeapTupleIsValid(tuple)) { elog(WARN, "DefineIndex: attribute \"%s\" not found", CString(arg)); } att = (Attribute)GETSTRUCT(tuple); *attNumP++ = att->attnum; *argTypes++ = att->atttypid; } } NormIndexAttrs(attList, attNumP, opOidP, relId) LispValue attList; AttributeNumber *attNumP; ObjectId *opOidP; ObjectId relId; { LispValue rest; HeapTuple tuple; /* * process attributeList */ for (rest=attList; rest != LispNil; rest = CDR(rest)) { LispValue attribute; AssertArg(listp(rest)); attribute = CAR(rest); AssertArg(listp(attribute)); if (length(attribute) != 2) { if (length(attribute) != 1) { elog(WARN, "DefineIndex: malformed att"); } elog(WARN, "DefineIndex: default index class unsupported"); } if (CADR(attribute) == LispNil || !lispStringp(CADR(attribute))) elog(WARN, "missing opclass for define index"); if (CAR(attribute) == LispNil) elog(WARN, "missing attribute for define index"); tuple = SearchSysCacheTuple(ATTNAME, (char *) ObjectIdGetDatum(relId), (char *) CString(CAR(attribute)), (char *) NULL, (char *) NULL); if (!HeapTupleIsValid(tuple)) { elog(WARN, "DefineIndex: attribute \"%s\" not found", CString(CAR(attribute))); } *attNumP++ = ((Attribute)GETSTRUCT(tuple))->attnum; tuple = SearchSysCacheTuple(CLANAME, (char *) CString(CADR(attribute)), (char *) NULL, (char *) NULL, (char *) NULL); if (!HeapTupleIsValid(tuple)) { elog(WARN, "DefineIndex: %s class not found", CString(CADR(attribute))); } *opOidP++ = tuple->t_oid; } } void RemoveIndex(name) Name name; { ObjectId id; HeapTuple tuple; tuple = SearchSysCacheTuple(RELNAME, (char *) name, (char *) NULL, (char *) NULL, (char *) NULL); if (!HeapTupleIsValid(tuple)) { elog(WARN, "index \"%s\" nonexistant", &(name->data[0])); } if (((RelationTupleForm)GETSTRUCT(tuple))->relkind != 'i') { elog(WARN, "relation \"%s\" is of type \"%c\"", &(name->data[0]), ((RelationTupleForm)GETSTRUCT(tuple))->relkind); } index_destroy(tuple->t_oid); } @ 1.24 log @casting problem (from linux port) @ text @d8 1 a8 1 RcsId("$Header: /home2/aoki/postgres/src/backend/commands/RCS/defind.c,v 1.23 1993/05/16 18:44:36 avi Exp aoki $"); d75 3 a77 1 tuple = SearchSysCacheTuple(RELNAME, heapRelationName); d87 3 a89 1 tuple = SearchSysCacheTuple(AMNAME, accessMethodName); d206 3 a208 1 tuple = SearchSysCacheTuple(RELNAME, indexRelationName); d219 4 a222 1 tuple = SearchSysCacheTuple(INDEXRELID, indexId); d281 4 a284 1 tuple = SearchSysCacheTuple(PROOID, indproc); d382 4 a385 1 tuple = SearchSysCacheTuple(CLANAME, CString(CADR(CAR(attList)))); d407 4 a410 1 tuple = SearchSysCacheTuple(ATTNAME, relId, CString(arg)); d459 4 a462 2 tuple = SearchSysCacheTuple(ATTNAME, relId, CString(CAR(attribute))); d470 4 a473 1 tuple = SearchSysCacheTuple(CLANAME, CString(CADR(attribute))); d490 2 a491 1 tuple = SearchSysCacheTuple(RELNAME, name); @ 1.23 log @FuncIndexArgs now initializes funcInfo with the argument types it needs as it reads the attribute list @ text @d8 1 a8 1 RcsId("$Header: /private/src/postgres/src/backend/commands/RCS/defind.c,v 1.22 1993/02/17 01:31:31 olson Exp avi $"); d276 1 a276 1 ((Form_pg_proc) GETSTRUCT(tuple))->proname, @ 1.22 log @support "extend index" command and index-predicate error checking @ text @d8 1 a8 1 RcsId("$Header: /private/src/postgres/src/backend/commands/RCS/defind.c,v 1.21 1992/02/26 22:51:19 olson Exp olson $"); d130 1 a130 1 d150 2 a151 1 classObjectId, relationId); d359 1 a359 1 FuncIndexArgs(attList, attNumP, opOidP, relId) d362 1 d368 1 d379 1 d400 3 a402 1 *attNumP++ = ((Attribute)GETSTRUCT(tuple))->attnum; @ 1.21 log @disable half-baked partial-index code for the release @ text @d3 1 a3 1 * POSTGRES define and remove index code. d8 1 a8 1 RcsId("$Header: src/commands/RCS/defind.c,v 1.20 92/02/19 23:09:50 olson Exp Locker: olson $"); d17 1 d26 2 d30 1 a71 6 #ifndef PARTIAL_IND if (predicate != LispNil) { elog (WARN, "partial indexes are unsupported in this version"); } #endif d78 1 a78 1 heapRelationName); d88 1 a88 1 accessMethodName); d117 3 a119 1 * form, so it can be readily evaluated during index creation d121 2 a122 2 if (predicate != LispNil) { cnfPred = cnfify(lispCopy(predicate), true); d124 1 d173 185 d464 1 a464 1 elog(WARN, "index \"%s\" nonexistant", name); d468 2 a469 1 elog(WARN, "relation \"%s\" is of type \"%c\"", name, @ 1.20 log @fix up includes for prototypes @ text @d8 1 a8 1 RcsId("$Header: src/commands/RCS/defind.c,v 1.19 92/02/12 13:22:54 olson Exp Locker: olson $"); d68 5 a72 1 @ 1.19 log @support partial index definition @ text @d8 1 a8 1 RcsId("$Header: src/commands/RCS/defind.c,v 1.18 91/10/16 23:00:40 mer Exp Locker: olson $"); d18 3 d27 1 @ 1.18 log @make sure we don't use too many func args in func index spec @ text @d8 1 a8 1 RcsId("$Header: /users/mer/postgres/src/commands/RCS/defind.c,v 1.17 1991/10/04 16:06:16 kemnitz Exp mer $"); d22 2 d29 1 a29 1 attributeList, parameterList) d36 1 d48 1 d109 9 d146 1 a146 1 classObjectId, parameterCount, parameterA); d160 1 a160 1 classObjectId, parameterCount, parameterA); @ 1.17 log @fixed compile warning. @ text @d8 1 a8 1 RcsId("$Header: RCS/defind.c,v 1.16 91/10/04 16:05:23 kemnitz Exp Locker: kemnitz $"); d16 1 d99 1 a99 1 *nextP = (String)CString(CAR(parameterList)); d110 7 @ 1.16 log @fixed argument type mismatch in "parameterA" @ text @d8 1 a8 1 RcsId("$Header: RCS/defind.c,v 1.15 91/09/29 00:21:41 mer Exp Locker: mer $"); d42 1 a42 1 String *nextP; @ 1.15 log @functional indices changes @ text @d8 1 a8 1 RcsId("$Header: /users/mer/postgres/src/commands/RCS/defind.c,v 1.14 1991/09/18 23:35:52 kemnitz Exp mer $"); d41 1 a41 1 String *parameterA; d90 1 a90 1 parameterA = LintCast(String *, @ 1.14 log @catalog support for functional indices. @ text @d8 1 a8 1 RcsId("$Header: RCS/defind.c,v 1.14 91/09/18 23:33:56 kemnitz Exp $"); d14 1 d22 1 a36 1 AttributeNumber attributeNumber; d43 1 a43 1 LispValue rest; a58 2 attributeNumberA = LintCast(AttributeNumber *, palloc(numberOfAttributes * sizeof attributeNumberA[0])); a59 2 classObjectId = LintCast(ObjectId *, palloc(numberOfAttributes * sizeof classObjectId[0])); d81 113 d197 2 a198 3 rest = attributeList; for (attributeNumber = 1; attributeNumber <= numberOfAttributes; attributeNumber += 1) { d202 2 a204 3 rest = CDR(rest); AssertArg(listp(rest)); d212 1 a212 1 "DefineIndex: default index class unsupported"); a214 2 if (CAR(attribute) == LispNil || !lispStringp(CAR(attribute))) elog(WARN, "missing attribute name for define index"); d217 2 d220 1 a220 1 tuple = SearchSysCacheTuple(ATTNAME, relationId, d223 3 a225 2 elog(WARN, "DefineIndex: attribute \"%s\" not found", CString(CAR(attribute))); d227 1 a227 2 attributeNumberA[attributeNumber - 1] = ((Attribute)GETSTRUCT(tuple))->attnum; d230 1 d235 1 a235 23 classObjectId[attributeNumber - 1] = tuple->t_oid; } /* * Handle parameters */ parameterCount = length(parameterList) / 2; #ifndef PERFECTPARSER AssertArg(length(parameterList) == 2 * parameterCount); #endif if (parameterCount >= 1) { parameterA = LintCast(String *, palloc(2 * parameterCount * sizeof *parameterA)); nextP = ¶meterA[0]; while (!lispNullp(parameterList)) { #ifndef PERFECTPARSER AssertArg(lispStringp(CAR(parameterList))); #endif *nextP = (String)CString(CAR(parameterList)); parameterList = CDR(parameterList); nextP += 1; } a236 4 index_create(heapRelationName, indexRelationName, NULL, accessMethodId, numberOfAttributes, attributeNumberA, classObjectId, parameterCount, parameterA); @ 1.13 log @missing param to elog added @ text @d8 1 a8 1 RcsId("$Header: RCS/defind.c,v 1.12 90/08/18 00:39:19 cimarron Exp Locker: mao $"); d151 1 a151 1 RelationNameCreateIndexRelation(heapRelationName, indexRelationName, d174 1 a174 1 DestroyIndexRelationById(tuple->t_oid); @ 1.12 log @eliminated less significant .h files @ text @d8 1 a8 1 RcsId("$Header: RCS/defind.c,v 1.11 90/08/13 20:46:54 cimarron Exp Locker: cimarron $"); d115 2 a116 1 elog(WARN, "DefineIndex: %s attribute not found"); @ 1.11 log @added pathnames to include statements @ text @d8 1 a8 1 RcsId("$Header: RCS/defind.c,v 1.10 90/08/08 08:10:36 cimarron Exp Locker: cimarron $"); a15 1 #include "tmp/name.h" @ 1.10 log @reorganized some header files @ text @d6 1 a6 1 #include "postgres.h" d8 1 a8 1 RcsId("$Header: RCS/defind.c,v 1.9 90/05/25 09:56:16 mao Version_2 Locker: cimarron $"); d10 9 a18 9 #include "attnum.h" #include "genam.h" #include "heapam.h" #include "htup.h" #include "log.h" #include "name.h" #include "pg_lisp.h" #include "palloc.h" #include "syscache.h" d20 1 a20 1 #include "defrem.h" @ 1.9 log @doesn't dump core on some syntax errors anymore @ text @d6 1 a6 1 #include "c.h" d8 1 a8 1 RcsId("$Header: RCS/defind.c,v 1.8 90/02/12 19:21:50 mao Exp Locker: mao $"); a10 1 #include "cat.h" a16 1 #include "oid.h" @ 1.8 log @add missing arg to elog call @ text @d8 1 a8 1 RcsId("$Header: RCS/defind.c,v 1.7 89/10/13 17:23:35 hirohama Exp Locker: mao $"); d97 1 a97 1 #ifndef PERFECTPARSER d101 1 a101 1 #endif d109 6 a114 4 #ifndef PERFECTPARSER AssertArg(lispStringp(CAR(attribute))); AssertArg(lispStringp(CADR(attribute))); #endif @ 1.7 log @RelationNameDestroyIndexRelation -> DestroyIndexRelationById @ text @d8 1 a8 1 RcsId("$Header: RCS/defind.c,v 1.6 89/09/05 16:47:30 mao C_Demo_1 Locker: hirohama $"); d123 2 a124 1 elog(WARN, "DefineIndex: %s class not found"); @ 1.6 log @Working version of C-only demo @ text @d8 1 a8 1 RcsId("$Header: RCS/defind.c,v 1.5 89/08/29 15:03:46 hirohama Exp $"); d11 1 d88 1 a88 1 * process X d159 2 a160 2 /* delete-index(name); */ /* am-destroy(name); */ d162 12 a173 1 RelationNameDestroyIndexRelation(name); @ 1.5 log @end utility now done in utility.c @ text @d8 1 a8 1 RcsId("$Header: RCS/defind.c,v 1.4 89/08/22 20:31:57 hirohama Exp Locker: hirohama $"); @ 1.4 log @DefineIndex now takes "lists" of attributes and parameters instead of arrays now uses catalog cache @ text @d8 1 a8 1 RcsId("$Header: RCS/defind.c,v 1.3 89/08/09 18:10:08 cimarron Exp Locker: hirohama $"); a151 3 #if 0 EndUtility("DEFINE"); #endif a159 1 /* utility-end("REMOVE"); */ @ 1.3 log @"retrieve(x=1)" @ text @d3 1 a3 4 * POSTGRES define index utility code. * * Note: * XXX Generally lacks argument checking.... d8 2 a9 1 #include "anum.h" a10 1 #include "catname.h" d13 1 d16 1 d18 2 a19 5 #include "rel.h" #include "relscan.h" #include "rproc.h" #include "skey.h" #include "trange.h" d21 1 a21 1 #include "defind.h" a22 1 RcsId("$Header: /usr6/postgres/cimarron/postgres3/src/commands/RCS/defind.c,v 1.2 89/02/02 16:26:24 dillon Stab $"); a23 32 /* * AccessMethodNameGetObjectId -- * Returns the object identifier for an access method given its name. * * Note: * Assumes name is valid. * * Aborts if access method does not exist. */ extern ObjectId AccessMethodNameGetObjectId ARGS(( Name accessMethodName; )); /* * OperatorClassNameGetObjectId -- * Returns the object identifier for an operator class given its name. * * Note: * Assumes name is valid. * Assumes relation descriptor is valid. * * Aborts if operator class does not exist. */ extern ObjectId OperatorClassNameGetObjectId ARGS(( Name operatorClassName; Relation operatorClassRelation; )); d26 2 a27 2 numberOfAttributes, attributeNumber, className, parameterCount, parameter) d31 7 d39 2 a40 2 AttributeNumber attributeNumber[]; Name className[]; d42 3 a44 5 Datum parameter[]; { AttributeOffset attributeOffset; ObjectId *classObjectId; Relation relation; d46 5 a50 2 classObjectId = LintCast(ObjectId *, palloc(numberOfAttributes * sizeof classObjectId[0])); d52 6 a57 6 relation = amopenr(OperatorClassRelationName); for (attributeOffset = 0; attributeOffset < numberOfAttributes; attributeOffset += 1) { classObjectId[attributeOffset] = OperatorClassNameGetObjectId(className[attributeOffset], relation); a58 1 amclose(relation); d60 2 a61 5 AMcreati(heapRelationName, indexRelationName, AccessMethodNameGetObjectId(accessMethodName), numberOfAttributes, attributeNumber, classObjectId, parameterCount, parameter); } d63 2 a64 11 static ObjectId AccessMethodNameGetObjectId(accessMethodName) Name accessMethodName; { HeapTuple tuple; Relation relation; HeapScanDesc scan; ObjectId accessMethodObjectId; Buffer buffer; ScanKeyData key[1]; d66 9 a74 1 Assert(NameIsValid(accessMethodName)); d76 4 a79 10 key[0].data[0].flags = 0; key[0].data[0].attributeNumber = AccessMethodNameAttributeNumber; key[0].data[0].procedure = Character16EqualRegProcedure; key[0].data[0].argument.name.value = accessMethodName; relation = amopenr(AccessMethodRelationName); scan = ambeginscan(relation, 0, DefaultTimeRange, 1, &key[0]); tuple = amgetnext(scan, 0, &buffer); d81 1 a81 2 amendscan(scan); elog(WARN, "AccessMethodNameGetObjectId: unknown AM %s", d84 1 a84 1 accessMethodObjectId = tuple->t_oid; d86 6 a91 2 amendscan(scan); amclose(relation); d93 1 a93 2 return (accessMethodObjectId); } d95 24 a118 11 static ObjectId OperatorClassNameGetObjectId(operatorClassName, operatorClassRelation) Name operatorClassName; Relation operatorClassRelation; { HeapTuple tuple; HeapScanDesc scan; ObjectId classObjectId; Buffer buffer; ScanKeyData key[1]; d120 6 a125 2 Assert(NameIsValid(operatorClassName)); Assert(RelationIsValid(operatorClassRelation)); d127 10 a136 4 key[0].data[0].flags = 0; key[0].data[0].attributeNumber = OperatorClassNameAttributeNumber; key[0].data[0].procedure = Character16EqualRegProcedure; key[0].data[0].argument.name.value = operatorClassName; d138 10 a147 2 scan = ambeginscan(operatorClassRelation, 0, DefaultTimeRange, 1, &key[0]); d149 7 a155 1 tuple = amgetnext(scan, 0, &buffer); d157 7 a163 6 if (!HeapTupleIsValid(tuple)) { amendscan(scan); elog(WARN, "OperatorClassNameGetObjectId: unknown class %s", operatorClassName); } classObjectId = tuple->t_oid; d165 1 a165 3 amendscan(scan); return (classObjectId); @ 1.2 log @Txfer from old tree @ text @d27 1 a27 1 RcsId("$Header: defind.c,v 1.2 88/02/11 19:51:08 dillon Locked $"); d103 1 a103 1 HeapScan scan; d140 1 a140 1 HeapScan scan; @ 1.1 log @Initial revision @ text @a0 1 a1 26 * * POSTGRES Data Base Management System * * Copyright (c) 1988 Regents of the University of California * * Permission to use, copy, modify, and distribute this software and its * documentation for educational, research, and non-profit purposes and * without fee is hereby granted, provided that the above copyright * notice appear in all copies and that both that copyright notice and * this permission notice appear in supporting documentation, and that * the name of the University of California not be used in advertising * or publicity pertaining to distribution of the software without * specific, written prior permission. Permission to incorporate this * software into commercial products can be obtained from the Campus * Software Office, 295 Evans Hall, University of California, Berkeley, * Ca., 94720 provided only that the the requestor give the University * of California a free licence to any derived software for educational * and research purposes. The University of California makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * */ /* d27 1 a27 1 RcsId("$Header: defind.c,v 1.1 88/11/11 16:35:30 postgres Exp $"); @