head 1.33; access; symbols release_4_2:1.33 aix_ok:1.31 Version_2_1:1.19 Version_2:1.10; locks; strict; comment @ * @; 1.33 date 94.02.07.11.41.06; author aoki; state Exp; branches; next 1.32; 1.32 date 93.11.03.08.24.31; author aoki; state Exp; branches; next 1.31; 1.31 date 92.03.11.02.20.18; author mer; state Exp; branches; next 1.30; 1.30 date 91.12.15.00.18.12; author dpassage; state Exp; branches; next 1.29; 1.29 date 91.12.07.17.18.25; author dpassage; state Exp; branches; next 1.28; 1.28 date 91.12.04.01.58.45; author glass; state Exp; branches; next 1.27; 1.27 date 91.11.18.22.23.29; author mer; state Exp; branches; next 1.26; 1.26 date 91.11.12.23.30.14; author mer; state Exp; branches; next 1.25; 1.25 date 91.11.11.23.06.06; author hong; state Exp; branches; next 1.24; 1.24 date 91.10.01.16.27.36; author glass; state Exp; branches; next 1.23; 1.23 date 91.04.23.14.54.53; author sp; state Exp; branches; next 1.22; 1.22 date 91.04.11.21.29.47; author sp; state Exp; branches; next 1.21; 1.21 date 91.04.10.16.06.37; author sp; state Exp; branches; next 1.20; 1.20 date 91.04.08.18.12.50; author sp; state Exp; branches; next 1.19; 1.19 date 91.02.25.16.52.12; author sp; state Exp; branches; next 1.18; 1.18 date 91.02.24.19.57.10; author sp; state Exp; branches; next 1.17; 1.17 date 91.02.24.12.34.43; author sp; state Exp; branches; next 1.16; 1.16 date 91.02.08.17.37.12; author sp; state Exp; branches; next 1.15; 1.15 date 91.01.09.18.58.47; author sp; state Exp; branches; next 1.14; 1.14 date 90.10.16.17.15.28; author sp; state Exp; branches; next 1.13; 1.13 date 90.08.19.15.29.13; author sp; state Exp; branches; next 1.12; 1.12 date 90.08.18.00.40.35; author cimarron; state Exp; branches; next 1.11; 1.11 date 90.08.17.08.53.01; author cimarron; state Exp; branches; next 1.10; 1.10 date 90.07.18.18.41.04; author sp; state Version_2; branches; next 1.9; 1.9 date 90.07.17.20.33.27; author sp; state Exp; branches; next 1.8; 1.8 date 90.05.21.15.14.40; author sp; state Exp; branches; next 1.7; 1.7 date 90.05.14.20.30.18; author sp; state Exp; branches; next 1.6; 1.6 date 90.05.10.16.20.34; author sp; state Exp; branches; next 1.5; 1.5 date 90.04.19.19.41.26; author sp; state Exp; branches; next 1.4; 1.4 date 90.04.03.17.02.27; author sp; state Exp; branches; next 1.3; 1.3 date 90.03.07.17.14.17; author sp; state Exp; branches; next 1.2; 1.2 date 90.01.30.23.20.24; author sp; state Exp; branches; next 1.1; 1.1 date 90.01.11.14.46.05; author sp; state Exp; branches; next ; desc @All the PRS2 definitions/declarations you need to know about.. @ 1.33 log @what a mess. the prs2 cruft had circular typedefs all over, making the protos a real tangle. finally changed some stuff in nodes.h (changed from typedef to struct) so that the forward references could be made in an ansi c compatible way. spyros was a sick, sick man. @ text @/* ---------------------------------------------------------------- * FILE * prs2.h * * DESCRIPTION * All you need to include if you are a PRS2 person! * * NOTES * This file includes prototypes for all routines defined in * rules/prs2/*.c * * There are numerous circularities in the header files here, * e.g., this header depends on the definition of Prs2Stub and * RelationRuleInfo, the headers for which #include this file. * If you use mkproto to update you will have to convert some * of the structures from Foo to struct FooData *. * * IDENTIFICATION * $Header: /import/faerie/faerie/aoki/postgres/src/backend/rules/RCS/prs2.h,v 1.32 1993/11/03 08:24:31 aoki Exp aoki $ * ---------------------------------------------------------------- */ /* * Include this file only once... */ #ifndef Prs2Included #define Prs2Included #include "tmp/postgres.h" #include "access/heapam.h" #include "access/tupdesc.h" #include "nodes/pg_lisp.h" #include "storage/buf.h" #include "utils/rel.h" #include "rules/params.h" /*------------------------------------------------------------------ * Include PRS2 lock definition * These defs were put in a separate file because they are included * bit "htup.h" and that created a circular dependency... */ #include "rules/prs2locks.h" #ifdef PROTOTYPES /* ANSI C hack for forward declaration in prototypes */ struct _EState; struct RelationRuleInfoData; struct Prs2StubData; struct Prs2OneStubData; #endif /* PROTOTYPES */ /*------------------------------------------------------------------ * Comment out the following line to supress debugging output * #define PRS2_DEBUG 1 */ /*================================================================== * --Prs2RuleData-- * * This is the structure where we keep all the information * needed to define a rule. * * ruleText: * the text of the rule (i.e. a string) * ruleName: * the name of the rule * ruleId: * the oid of the rule. * NOTE: we do NOT know it until we add the rule in the system * catalogs! * isInstead: * is this an "instead" rule ?? * eventType: * the event type that triggers the rule * actionType: * the type of the action that will be executed if the rule istriggered. * eventRelationOid: * eventRelationName: * oid & name of the relation referenced in the "event" clause of the rule. * eventAttributeNumber: * eventAttributeName: * the number & name of the attribute referenced in the "event" clause * of the rule. If no such attribute exists (i.e. "on retrieve to EMP" - * a view rule) then this is an InvalidAttributeNumber & NULL * respectively. * updatedAttributeNumber: * The attribute no of the attribute that is updated from the rule. * For instance "on retrieve ... then do replace CURRENT(attr = ...)" * or "on retrieve to ... then do retrieve (attr = ....)" * parseTree: * the parse tree for the rule definition. * ruleQual: * the qualification of the rule * ruleAction: * a list of all the actions. * paramParseTree: * paramRuleQual: * paramRuleAction: * same as the parseTree, ruleQual & ruleAction but with all the * Var nodes that reference the CURRENT and/or NEW relations changed * into the appropriate Param nodes... * */ typedef struct Prs2RuleDataData { ObjectId ruleId; char *ruleText; Name ruleName; bool isInstead; EventType eventType; ActionType actionType; ObjectId eventRelationOid; Name eventRelationName; AttributeNumber eventAttributeNumber; Name eventAttributeName; AttributeNumber updatedAttributeNumber; List parseTree; List ruleQual; List ruleAction; List paramParseTree; List paramRuleQual; List paramRuleAction; } Prs2RuleDataData; typedef Prs2RuleDataData *Prs2RuleData; /*======================================================================== * EState Rule Info + Rule Stack * * This structure (which is kept inside the executor state node EState) * contains some information used by the rule manager. * * RULE DETECTION MECHANISM: * prs2Stack: A stack where enough information is ketp in order to detect * rule loops. * prs2StackPointer: the next (free) stack entry * prs2MaxStackSize: number of stack entries allocated. If * prs2StackPointer is >= prs2MaxStackSize the stack is full * and we have to reallocate some more memory... * * MISC INFO: * This would normally go down by the prs2stack.c prototypes * but we have some forward references. *======================================================================== */ typedef struct Prs2StackData { ObjectId ruleId; /* OID of the rule */ ObjectId tupleOid; /* the tuple that activated the rule*/ AttributeNumber attrNo; /* the locked attribute */ } Prs2StackData; typedef Prs2StackData *Prs2Stack; typedef struct Prs2EStateInfoData { Prs2Stack prs2Stack; /* the stack used for loop detection */ int prs2StackPointer; /* the next free stack entry */ int prs2MaxStackSize; /* the max number of entries */ } Prs2EStateInfoData; typedef Prs2EStateInfoData *Prs2EStateInfo; /*================================================================== * PRS2 MAIN ROUTINES * * These are almost all the routines a non Prs2 person wants to know * about! *================================================================== */ /*====================== FILE: prs2main.c * prs2Main * The rule manager itself! Normally this should only be called * from within the executor... * prs2MustCallRuleManager * return true if the executor must call the rule manager, or * false if there is no need to do so (no rules defined). */ typedef int Prs2Status; #define PRS2_STATUS_TUPLE_UNCHANGED 1 #define PRS2_STATUS_TUPLE_CHANGED 2 #define PRS2_STATUS_INSTEAD 3 extern Prs2Status prs2Main ARGS((struct _EState *estate, struct RelationRuleInfoData *retrieveRelationRuleInfo, int operation, int userId, Relation relation, HeapTuple oldTuple, Buffer oldBuffer, HeapTuple newTuple, Buffer newBuffer, HeapTuple rawTuple, Buffer rawBuffer, AttributeNumberPtr attributeArray, int numberOfAttributes, HeapTuple *returnedTupleP, Buffer *returnedBufferP)); extern bool prs2MustCallRuleManager ARGS((struct RelationRuleInfoData *relationRuleInfo, HeapTuple oldTuple, Buffer oldBuffer, int operation)); /*================================================================== * PRS2 LOCKS *================================================================== */ /*====================== FILE: prs2locks.c * prs2FreeLocks * free the space occupied by a rule lock * prs2MakeLocks * return a pointer to a 'Prs2LocksData' structure containing * no locks, i.e. numberOfLocks = 0; * prs2AddLock * Add a new lock (filled in with the given data) to a 'prs2Locks' * Note that this frees the space occupied by 'prs2Locks' and reallocates * some other. So this routine should be used with caution! * prs2GetOneLockFromLocks * Given a 'RuleLock' return a pointer to its Nth lock.. * (the first locks is lock number 0). * prs2OneLocksAreTheSame * return true iff the two 'Prs2OneLock' are the same... * prs2OneLockIsMemberOfLocks * return true iff the given `Prs2OneLock' is one of the locks of * `locks' * prs2GetLocksFromTuple * Extract the locks from a tuple. It returns a 'RuleLock', * (NOTE:it will never return NULL! Even if the tuple has no * locks in it, it will return a 'RuleLock' with 'numberOfLocks' * equal to 0. * The returned rule lock is a copy, and must be pfreed to avoid * memory leaks. * prs2PutLocksInTuple * given a tuple, update its rule lock. * NOTE: the old rule lock is pfreed! * prs2PrintLocks * print the prs2 locks in stdout. Used for debugging... * prs2RemoveOneLockInPlace * remove a rule lock in place (i.e. no copies) * prs2RemoveAllLocksOfRuleInPlace * remove all locks of a given rule in place (i.e. no copies) * returns true if the lcoks have changed, false otherwise (i.e. * if no locks for this rule were found). * prs2RemoveAllLocksOfRule * remove all the locks that have a ruleId equal to the given. * the old `RuleLock' is destroyed and should never be * referenced again. * The new lock is returned. * prs2CopyLocks * Make a copy of a prs2 lock.. * prs2LockUnion * Create the union of two RuleLock. * prs2LockDifference * Create the difference of two RuleLock. * prs2FindLocksOfType * return a copy of all the locks of a given type. * prs2RemoveLocksOfTypeInPlace * remove all the lcoks of the given type in place (i.e. No copies) */ extern void prs2FreeLocks ARGS((RuleLock lock)); extern RuleLock prs2MakeLocks ARGS((void)); extern RuleLock prs2AddLock ARGS((RuleLock oldLocks, ObjectId ruleId, Prs2LockType lockType, AttributeNumber attributeNumber, Prs2PlanNumber planNumber, int partialindx, int npartial)); extern Prs2OneLock prs2GetOneLockFromLocks ARGS((RuleLock lock, int n)); extern bool prs2OneLocksAreTheSame ARGS((Prs2OneLock l1, Prs2OneLock l2)); extern bool prs2OneLockIsMemberOfLocks ARGS((Prs2OneLock oneLock, RuleLock locks)); extern RuleLock prs2GetLocksFromTuple ARGS((HeapTuple tuple, Buffer buffer)); extern void prs2PutLocksInTuple ARGS((HeapTuple tuple, Buffer buffer, Relation relation, RuleLock newLocks)); extern void prs2PrintLocks ARGS((RuleLock locks)); extern RuleLock prs2CopyLocks ARGS((RuleLock locks)); extern void prs2RemoveOneLockInPlace ARGS((RuleLock locks, int n)); extern bool prs2RemoveAllLocksOfRuleInPlace ARGS((RuleLock locks, ObjectId ruleId)); extern RuleLock prs2RemoveAllLocksOfRule ARGS((RuleLock oldLocks, ObjectId ruleId)); extern RuleLock prs2LockUnion ARGS((RuleLock lock1, RuleLock lock2)); extern RuleLock prs2LockDifference ARGS((RuleLock lock1, RuleLock lock2)); extern RuleLock prs2FindLocksOfType ARGS((RuleLock locks, Prs2LockType lockType)); extern void prs2RemoveLocksOfTypeInPlace ARGS((RuleLock locks, Prs2LockType lockType)); /*====================== FILE: prs2inout.c * RuleLockToString * greate a string containing a representation of the given * lock, more suitable for the human brain & eyes than a * sequence of bytes. * StringToRuleLock * the opposite of 'RuleLockToString()' */ extern char *RuleLockToString ARGS((RuleLock locks)); extern char *lockout ARGS((RuleLock locks)); extern RuleLock StringToRuleLock ARGS((char *s)); extern RuleLock lockin ARGS((char *s)); /*================================================================== * Routine to extract rule info from the ParseTree *================================================================== */ #define GetRuleHintFromParse(p) (CADR(nth(1,p))) #define GetRuleNameFromParse(p) (nth(2,p)) #define GetRuleEventTypeFromParse(p) (nth(0,nth(3,p))) #define GetRuleEventTargetFromParse(p) (nth(1,nth(3,p))) #define GetRuleQualFromParse(p) (nth(2,nth(3,p))) #define GetRuleInsteadFromParse(p) (nth(3,nth(3,p))) #define GetRuleActionFromParse(p) (nth(4,nth(3,p))) #define GetRuleRangeTableFromParse(p) (nth(4,p)) /*------------------------------------------------------------------ * Various routines... *------------------------------------------------------------------ */ /*====================== FILE: prs2define.c * prs2DefineTupleRule * Define a PRS2 rule (tuple level proccessing) * prs2RemoveTupleRule * Remove a prs2 rule given its name. */ extern void prs2DefineTupleRule ARGS((LispValue parseTree, char *ruleText)); extern Name prs2GetRuleEventRel ARGS((char *rulename)); extern void prs2RemoveTupleRule ARGS((Name ruleName)); extern Prs2RuleData prs2FindRuleData ARGS((List parseTree, char *ruleText)); extern ObjectId prs2InsertRuleInfoInCatalog ARGS((Prs2RuleData r)); extern void prs2DeleteRuleInfoFromCatalog ARGS((ObjectId ruleId)); extern void prs2InsertRulePlanInCatalog ARGS((ObjectId ruleId, Prs2PlanNumber planNumber, List rulePlan)); extern void prs2DeleteRulePlanFromCatalog ARGS((ObjectId ruleId)); extern LispValue prs2GenerateActionPlans ARGS((Prs2RuleData r)); extern EventType prs2FindEventTypeFromParse ARGS((LispValue parseTree)); extern ActionType prs2FindActionTypeFromParse ARGS((LispValue parseTree, AttributeNumber eventTargetAttributeNumber, AttributeNumberPtr updatedAttributeNumberP, EventType eventType)); extern void changeReplaceToRetrieve ARGS((LispValue parseTree)); extern bool prs2AttributeIsOfBasicType ARGS((ObjectId relOid, AttributeNumber attrNo)); extern LispValue prs2ReadRule ARGS((char *fname)); /*====================== FILE: prs2putlocks.c * prs2AddTheNewRule * add a new rule. Decide what kind of lock to use (tuple-level or * relation-level lock). Add locks and/or stubs and the appropriate * system catalog info. * prs2DeleteTheOldRule * delete a rule given its rule oid. Find if it was a tuple-level * lock or a relation-level lock rule and do the right thing * (delete locks/stubs & system catalog info). */ extern void prs2AddTheNewRule ARGS((Prs2RuleData r, List hint)); extern void prs2DeleteTheOldRule ARGS((ObjectId ruleId)); extern void prs2FindLockTypeAndAttrNo ARGS((Prs2RuleData r, Prs2LockType *lockTypeResult, AttributeNumber *attributeNoResult)); extern LispValue prs2FindConstantQual ARGS((LispValue qual, int currentVarno)); extern LispValue prs2FindConstantClause ARGS((LispValue clause, int currentVarno, bool *isConstant)); extern bool prs2IsATupleLevelLockRule ARGS((ObjectId ruleId, ObjectId relationId)); /*====================== FILE: prs2tup.c */ extern bool prs2DefTupleLevelLockRule ARGS((Prs2RuleData r, bool hintFlag)); extern RuleLock prs2FindLocksThatWeMustPut ARGS((struct Prs2StubData *stubs, RuleLock newlock, AttributeNumber attrno)); extern struct Prs2StubData *prs2FindStubsThatDependOnAttribute ARGS((struct Prs2StubData *stubs, AttributeNumber attrno)); extern bool prs2DoesStubDependsOnAttribute ARGS((struct Prs2OneStubData *onestub, AttributeNumber attrno)); extern bool prs2LockWritesAttributes ARGS((RuleLock locks, AttributeNumber *attrList, int attrListSize)); extern void prs2FindAttributesOfQual ARGS((LispValue qual, int varno, AttributeNumber **attrListP, int *attrListSizeP)); extern void prs2UndefTupleLevelLockRule ARGS((ObjectId ruleId, ObjectId relationOid)); extern void prs2RemoveTupleLeveLocksAndStubsOfManyRules ARGS((ObjectId relationOid, ObjectId *ruleIds, int nrules)); /*====================== FILE: prs2rel.c */ extern void prs2DefRelationLevelLockRule ARGS((Prs2RuleData r)); extern void prs2UndefRelationLevelLockRule ARGS((ObjectId ruleId, ObjectId relationId)); extern void prs2RemoveRelationLevelLocksOfRule ARGS((ObjectId ruleId, ObjectId relationId)); extern void prs2SetRelationLevelLocks ARGS((ObjectId relationId, RuleLock newLocks)); extern void prs2AddRelationLevelLock ARGS((ObjectId ruleId, Prs2LockType lockType, ObjectId relationId, AttributeNumber attrNo)); /*=================================================================== * RULE PLANS * * The rule plans are stored in the "pg_prs2plans" relation. * There are different types of plans. * Each "plan" contains appart from one or more parsetrees/plans * some rule information. * The first item of all the plans is a string describing the type of the * plan. This string can be "action" for the ACTION plans, and "export" * for the EXPORT plans. * The second item is the plan information itself, and its format depends * on the type of plan: * * a) ACTION PLANS: * They are a list with at least two items: * * The first item is a list giving some info for the rule. * Currently this can have the following elements: * The first element is an integer, equal to 1 if the rule is an * instead rule, 0 otherwise. * The second is the "event attribute" number, i.e. the attrno * of the attribute specified in the "on to ." * rule clause. * The third is the "updated attribute" number, i.e. the attrno * of the attribute updated by a backward chaining rule. * * The second item is the qualification of the rule. * This should be tested before and only if it succeeds should the * action part of the rule be executed. * This qualifcation can be either "nil" which means that * there is no qualification and the action part of the rule should be * always executed, or a 2 item list, the first item beeing the parse * tree corresponding to the qualification and the second one the plan. * * Finally the (optional) rest items are the actions of the rule. * Each one of them can be either a 2 item list (parse tree + plan) * or the string "abort" which means that the current Xaction should be * aborted. * * b) EXPORT PLANS: * this is the kind of plan to be executed when an export * lock is broken. * The first item of the plan is a list with information * about this export lock. This information consists of the * following items: * 1) a string containing the lock (use `lockin' to recreate * the lock). * Then there is the plan to be run in order to add/delete * rule locks when this export lock is broken. This plan is actually * a two item list conatining the parsetree and the actual plan. * *=================================================================== */ #define Prs2RulePlanType_EXPORT ("export") #define Prs2RulePlanType_ACTION ("action") #define prs2GetTypeOfRulePlan(x) (CAR(x)) #define prs2GetPlanInfoFromRulePlan(x) (CDR(x)) #define prs2GetRuleInfoFromActionPlan(x) (CAR(CDR(x))) #define prs2GetQualFromActionPlan(x) (CADR(CDR(x))) #define prs2GetActionsFromActionPlan(x) (CDR(CDR(CDR(x)))) #define prs2GetLockInfoFromExportPlan(x) (CAR(CDR(x))) #define prs2GetActionPlanFromExportPlan(x) (CADR(CDR(x))) /*====================== FILE: prs2plan.c * prs2GetRulePlanFromCatalog * Given a rule id and a plan number get the appropriate plan * from the system catalogs. At the same time construct a list * with all the Param nodes contained in this plan. */ extern LispValue prs2GetRulePlanFromCatalog ARGS((ObjectId ruleId, Prs2PlanNumber planNumber, ParamListInfo *paramListP)); extern RuleLock prs2GetLocksFromRelation ARGS((Name relationName)); extern RuleLock prs2SLOWGetLocksFromRelation ARGS((Name relationName)); extern int prs2CheckQual ARGS((LispValue planQual, ParamListInfo paramList, Prs2EStateInfo prs2EStateInfo)); extern void prs2RunActionPlans ARGS((LispValue plans, ParamListInfo paramList, Prs2EStateInfo prs2EStateInfo)); extern int prs2RunOnePlanAndGetValue ARGS((LispValue actionPlan, ParamListInfo paramList, Prs2EStateInfo prs2EStateInfo, Datum *valueP, Boolean *isNullP)); extern void prs2RunOnePlan ARGS((LispValue actionPlan, ParamListInfo paramList, Prs2EStateInfo prs2EStateInfo, int operation)); extern Boolean prs2IsRuleInsteadFromRuleInfo ARGS((LispValue ruleInfo)); extern AttributeNumber prs2GetEventAttributeNumberFromRuleInfo ARGS((LispValue ruleInfo)); extern AttributeNumber prs2GetUpdatedAttributeNumberFromRuleInfo ARGS((LispValue ruleInfo)); extern LispValue prs2MakeQueryDescriptorFromPlan ARGS((LispValue actionPlan)); #define prs2GetParseTreeFromOneActionPlan(x) (CAR(x)) #define prs2GetPlanFromOneActionPlan(x) (CADR(x)) /*================================================================== * AttributeValues stuff... *================================================================== * * These definitions & routines make possible to use an array of * attribute values instead of a tuple, thus making easier to change * these values without having to make multiple copies of the tuple. * It also makes easier to keep some extra information about how the value * of attributes were calculated. * * Explanation of the fileds of a 'AttributesValuesData': * For each attribute of the tuple there is a corresponding * 'AttributeValuesData' structure, with the following fields: * value: the value of this attribute. This is initially * initialized to the value stroed in the tuple. * isNull: true if the coresponding attribute in the tuple is * null. * isCalculated: Initially false. It becomes true if we have * checked this attribute for possibly applicable * rules, and we have finally calculated its correct value. * isChanged: If an attribute has been checked for rules (i.e. * has its 'isCalculated' field equal to true), then two * things can happen. Either thre was no applicable rule * found, in which case we have used the value stored * in the tuple and 'isChanged' is equal to false, * or there was a rule that calculated a value for * this attribute, in which case 'isChanged' is true, and * 'value' is this new value. */ typedef struct AttributeValuesData { Datum value; Boolean isNull; Boolean isCalculated; Boolean isChanged; } AttributeValuesData; typedef AttributeValuesData *AttributeValues; #define InvalidAttributeValues ((AttributeValues)NULL) /*====================== FILE: prs2attr.c * * attributeValuesCreate * Given a tuple create the corresponding 'AttributeValues' array. * Note that in the beginning all the 'value' entries are copied * from the tuple and that 'isCalculated' are all false. * attributeValuesFree * Free a previously allocated 'AttributeValues' array. * attributeValuesMakeNewTuple * Given the old tuple and the values that the new tuple should have * create a new tuple. * Returns 1 if a new tuple has been created (stored in *newTupleP) * and 0 if the old tuple is the same as the new tuple, in which * case we can use 'tuple' instead, in order to avoid a redudant * copy operation. * attributeValuesCombineNewAndOldTuple * In the case of a replace command, given the 'raw' tuple, i.e. * the tuple as retrieved by the AM (*not* changed by any backward * chaining rules) and the 'new' tuple (the one with all backward * chaning rules activated + with all user updates) * form the tuple that will finally replace the old one. */ extern AttributeValues attributeValuesCreate ARGS((HeapTuple tuple, Buffer buffer, Relation relation)); extern void attributeValuesFree ARGS((AttributeValues a, Relation relation)); extern int attributeValuesMakeNewTuple ARGS((HeapTuple tuple, Buffer buffer, AttributeValues attrValues, RuleLock locks, Prs2LockType lockType, Relation relation, HeapTuple *newTupleP)); extern HeapTuple attributeValuesCombineNewAndOldTuple ARGS((AttributeValues rawAttrValues, AttributeValues newAttrValues, Relation relation, AttributeNumberPtr attributeArray, AttributeNumber numberOfAttributes)); /*====================== FILE: prs2stack.c * prs2RuleStackPush * Add a new entry to the rule stack. First check if there is enough * stack space. otherwise reallocate some more memory... * prs2RuleStackPop * Discard the top entry of the stack * prs2RuleStackSearch * Search for a stack entry matching the given arguments. * Return true if found, false otherwise... * prs2RuleStackInitialize * Intialize the stack. * prs2RuleStackFree * Free the memory occupied by the stack. */ extern void prs2RuleStackPush ARGS((Prs2EStateInfo p, ObjectId ruleId, ObjectId tupleOid, AttributeNumber attributeNumber)); extern void prs2RuleStackPop ARGS((Prs2EStateInfo p)); extern bool prs2RuleStackSearch ARGS((Prs2EStateInfo p, ObjectId ruleId, ObjectId tupleOid, AttributeNumber attributeNumber)); extern Prs2EStateInfo prs2RuleStackInitialize ARGS((void)); extern void prs2RuleStackFree ARGS((Prs2EStateInfo p)); /*======================================================================== * VARIOUS ROUTINES.... *======================================================================== */ /*====================== FILE: planner/utils/storeplan.c * * PlanToString * StringToPlan * StringToPlanWithParams */ #include "planner/storeplan.h" /*======================================================================== * These routines are some 'internal' routines. *======================================================================== */ /*====================== FILE: prs2retrieve.c */ extern Prs2Status prs2Retrieve ARGS((Prs2EStateInfo prs2EStateInfo, struct RelationRuleInfoData *relationRuleInfo, Relation explainRelation, HeapTuple tuple, Buffer buffer, AttributeNumberPtr attributeArray, int numberOfAttributes, Relation relation, HeapTuple *returnedTupleP, Buffer *returnedBufferP)); /*====================== FILE: prs2append.c */ extern Prs2Status prs2Append ARGS((Prs2EStateInfo prs2EStateInfo, struct RelationRuleInfoData *relationRuleInfo, Relation explainRelation, HeapTuple tuple, Buffer buffer, Relation relation, HeapTuple *returnedTupleP, Buffer *returnedBufferP)); extern RuleLock prs2FindLocksForNewTupleFromStubs ARGS((HeapTuple tuple, Buffer buffer, struct Prs2StubData *stubs, Relation relation)); /*====================== FILE: prs2delete.c */ extern Prs2Status prs2Delete ARGS((Prs2EStateInfo prs2EStateInfo, struct RelationRuleInfoData *relationRuleInfo, Relation explainRelation, HeapTuple tuple, Buffer buffer, HeapTuple rawTuple, Buffer rawBuffer, Relation relation)); /*====================== FILE: prs2replace.c */ extern Prs2Status prs2Replace ARGS((Prs2EStateInfo prs2EStateInfo, struct RelationRuleInfoData *relationRuleInfo, Relation explainRelation, HeapTuple oldTuple, Buffer oldBuffer, HeapTuple newTuple, Buffer newBuffer, HeapTuple rawTuple, Buffer rawBuffer, AttributeNumberPtr attributeArray, int numberOfAttributes, Relation relation, HeapTuple *returnedTupleP, Buffer *returnedBufferP)); /*====================== FILE: prs2plans.c */ extern LispValue prs2GetRulePlanFromCatalog ARGS((ObjectId ruleId, Prs2PlanNumber planNumber, ParamListInfo *paramListP)); extern RuleLock prs2GetLocksFromRelation ARGS((Name relationName)); extern RuleLock prs2SLOWGetLocksFromRelation ARGS((Name relationName)); extern int prs2CheckQual ARGS((LispValue planQual, ParamListInfo paramList, Prs2EStateInfo prs2EStateInfo)); extern void prs2RunActionPlans ARGS((LispValue plans, ParamListInfo paramList, Prs2EStateInfo prs2EStateInfo)); extern int prs2RunOnePlanAndGetValue ARGS((LispValue actionPlan, ParamListInfo paramList, Prs2EStateInfo prs2EStateInfo, Datum *valueP, Boolean *isNullP)); extern void prs2RunOnePlan ARGS((LispValue actionPlan, ParamListInfo paramList, Prs2EStateInfo prs2EStateInfo, int operation)); extern Boolean prs2IsRuleInsteadFromRuleInfo ARGS((LispValue ruleInfo)); extern AttributeNumber prs2GetEventAttributeNumberFromRuleInfo ARGS((LispValue ruleInfo)); extern AttributeNumber prs2GetUpdatedAttributeNumberFromRuleInfo ARGS((LispValue ruleInfo)); extern LispValue prs2MakeQueryDescriptorFromPlan ARGS((LispValue actionPlan)); /*====================== FILE: prs2bkwd.c */ extern void prs2ActivateBackwardChainingRules ARGS((Prs2EStateInfo prs2EStateInfo, Relation explainRelation, Relation relation, AttributeNumber attributeNumber, int oldOrNewTuple, ObjectId oldTupleOid, AttributeValues oldAttributeValues, RuleLock oldTupleLocks, Prs2LockType oldTupleLockType, ObjectId newTupleOid, AttributeValues newAttributeValues, RuleLock newTupleLocks, Prs2LockType newTupleLockType, AttributeNumberPtr attributeArray, AttributeNumber numberOfAttributes)); extern void prs2CalculateAttributesOfParamNodes ARGS((Prs2EStateInfo prs2EStateInfo, Relation explainRelation, Relation relation, ParamListInfo paramList, ObjectId oldTupleOid, AttributeValues oldTupleAttributeValues, RuleLock oldTupleRuleLock, Prs2LockType oldTupleLockType, ObjectId newTupleOid, AttributeValues newTupleAttributeValues, RuleLock newTupleRuleLock, Prs2LockType newTupleLockType, AttributeNumberPtr attributeArray, AttributeNumber numberOfAttributes)); extern void prs2ActivateForwardChainingRules ARGS((Prs2EStateInfo prs2EStateInfo, Relation explainRelation, Relation relation, AttributeNumber attributeNumber, Prs2LockType actionLockType, int oldOrNewTuple, ObjectId oldTupleOid, AttributeValues oldAttributeValues, RuleLock oldTupleLocks, Prs2LockType oldTupleLockType, ObjectId newTupleOid, AttributeValues newAttributeValues, RuleLock newTupleLocks, Prs2LockType newTupleLockType, bool *insteadRuleFoundP, AttributeNumberPtr attributeArray, AttributeNumber numberOfAttributes)); /*====================== FILE: prs2impexp.c */ extern RuleLock prs2FindNewExportLocksFromLocks ARGS((RuleLock locks)); extern RuleLock prs2GetExportLockFromCatalog ARGS((ObjectId ruleId, Prs2PlanNumber planNo)); extern void prs2ActivateExportLockRulePlan ARGS((Prs2OneLock oneLock, Datum value, ObjectId typeid, int operation)); /*============== RULE STATISTICS ============================*/ /* * the following variables/routines are used to print stats about * the tuple level system usage. */ /*====================== FILE: prs2main.c */ extern int Prs2Stats_rulesActivated; extern int Prs2Stats_rulesTested; extern void ResetPrs2Stats ARGS((void)); extern void ShowPrs2Stats ARGS((FILE *statfp)); /*====================== FILE: prs2explain.c */ extern Relation createExplainRelation ARGS((Name relationName)); extern void storeExplainInfo ARGS((Relation explainRelation, ObjectId ruleId, Relation relation, ObjectId tupleOid)); /*====================== FILE: prs2view.c */ extern struct RelationRuleInfoData *prs2MakeRelationRuleInfo ARGS((Relation relation, int operation)); extern HeapTuple prs2GetOneTupleFromViewRules ARGS((struct RelationRuleInfoData *relationRuleInfo, Prs2EStateInfo prs2EStateInfo, Relation relation, Relation explainRel)); #endif Prs2Included @ 1.32 log @fix broken prs2 protos remove rules/rlock.h, access/xcxt.h, access/newam.h (dead headers with residual dependencies) @ text @d19 1 a19 1 * $Header: /faerie/aoki/postgres/src/backend/rules/RCS/prs2.h,v 1.31 1992/03/11 02:20:18 mer Exp aoki $ d46 8 d128 37 a172 1 d188 1 a188 1 extern Prs2Status prs2Main ARGS((EState estate, struct RelationRuleInfoData *retrieveRelationRuleInfo, int operation, int userId, Relation relation, HeapTuple oldTuple, Buffer oldBuffer, HeapTuple newTuple, Buffer newBuffer, int rawTuple, int rawBuffer, AttributeNumberPtr attributeArray, int numberOfAttributes, HeapTuple *returnedTupleP, Buffer *returnedBufferP)); d344 2 a345 2 extern struct Prs2StubData *prs2FindStubsThatDependOnAttribute ARGS((Prs2Stub stubs, AttributeNumber attrno)); extern bool prs2DoesStubDependsOnAttribute ARGS((Prs2OneStub onestub, AttributeNumber attrno)); a519 35 /*======================================================================== * EState Rule Info + Rule Stack * * This structure (which is kept inside the executor state node EState) * contains some information used by the rule manager. * * RULE DETECTION MECHANISM: * prs2Stack: A stack where enough information is ketp in order to detect * rule loops. * prs2StackPointer: the next (free) stack entry * prs2MaxStackSize: number of stack entries allocated. If * prs2StackPointer is >= prs2MaxStackSize the stack is full * and we have to reallocate some more memory... * * MISC INFO: * *======================================================================== */ typedef struct Prs2StackData { ObjectId ruleId; /* OID of the rule */ ObjectId tupleOid; /* the tuple that activated the rule*/ AttributeNumber attrNo; /* the locked attribute */ } Prs2StackData; typedef Prs2StackData *Prs2Stack; typedef struct Prs2EStateInfoData { Prs2Stack prs2Stack; /* the stack used for loop detection */ int prs2StackPointer; /* the next free stack entry */ int prs2MaxStackSize; /* the max number of entries */ } Prs2EStateInfoData; typedef Prs2EStateInfoData *Prs2EStateInfo; d566 1 a566 1 extern RuleLock prs2FindLocksForNewTupleFromStubs ARGS((HeapTuple tuple, Buffer buffer, Prs2Stub stubs, Relation relation)); @ 1.31 log @turn of debug output @ text @d1 20 a20 9 /* * FILE: * prs2.h * * IDENTIFICATION: * $Header: /users/mer/pg/src/lib/H/rules/RCS/prs2.h,v 1.30 1991/12/15 00:18:12 dpassage Exp mer $ * * DESCRIPTION: * All you need to include if you are a PRS2 person! d129 1 a129 15 /*------------------------------------------------------------------ * return true if the executor must call the rule manager, or * false if there is no need to do so (no rules defined). */ extern bool prs2MustCallRuleManager();/* BAD PROTOTYPE DELETED -- glass */ /* ARGS(( RelationInfo relationInfo, HeapTuple oldTuple, Buffer oldBuffer, int operation ));*/ /*------------------------------------------------------------------ d131 5 a135 2 * The rule manager itself! Normally this should only be called * from within the executor... d144 4 a147 21 extern Prs2Status prs2Main(); /* BAD PROTOTYPE DELETED -- glass */ /*ARGS(( EState estate, RelationInfo scanRelInfo, int operation, int userId, Relation relation, HeapTuple oldTuple, Buffer oldBuffer, HeapTuple newTuple, Buffer newBuffer, HeapTuple rawTuple, Buffer rawBuffer, AttributeNumberPtr attributeArray, int numberOfAttributes, HeapTuple *returnedTupleP, Buffer *returnedBufferP )); */ d153 1 a153 1 /*------------------------------------------------------------------ a155 8 */ extern void prs2FreeLocks ARGS(( RuleLock lock )); /*------------------------------------------------------------------ a158 7 */ extern RuleLock prs2MakeLocks ARGS(( )); /*------------------------------------------------------------------ a162 14 */ extern RuleLock prs2AddLock ARGS(( RuleLock oldLocks, ObjectId ruleId, Prs2LockType lockType, AttributeNumber attributeNumber, Prs2PlanNumber planNumber, int partialindx, int npartial )); /*------------------------------------------------------------------ a165 9 */ extern Prs2OneLock prs2GetOneLockFromLocks ARGS(( RuleLock locks, int n )); /*------------------------------------------------------------------ d167 1 a167 10 * return true iff the two 'Prs2OneLock' are the same... */ extern bool prs2OneLocksAreTheSame ARGS(( Prs2OneLock oneLock1, Prs2OneLock oneLock2 )); /*------------------------------------------------------------------ d169 2 a170 11 * return true iff the given `Prs2OneLock' is one of the locks of * `locks' */ extern bool prs2OneLockIsMemberOfLocks ARGS(( Prs2OneLock oneLock, RuleLock locks )); /*------------------------------------------------------------------ d172 6 a177 14 * Extract the locks from a tuple. It returns a 'RuleLock', * (NOTE:it will never return NULL! Even if the tuple has no * locks in it, it will return a 'RuleLock' with 'numberOfLocks' * equal to 0. * The returned rule lock is a copy, and must be pfreed to avoid memory leaks. */ extern RuleLock prs2GetLocksFromTuple ARGS(( HeapTuple tuple, Buffer buffer )); /*------------------------------------------------------------------ a180 11 */ extern void prs2PutLocksInTuple ARGS(( HeapTuple tuple, Buffer buffer, Relation relation, RuleLock newLocks )); /*------------------------------------------------------------------ a182 8 */ extern void prs2PrintLocks ARGS(( RuleLock locks )); /*------------------------------------------------------------------ d184 1 a184 11 * * remove a rule lock in place (i.e. no copies) */ extern void prs2RemoveOneLockInPlace ARGS(( RuleLock locks, int n )); /*------------------------------------------------------------------ d186 3 a188 13 * * remove all locks of a given rule in place (i.e. no copies) * returns true if the lcoks have changed, false otherwise (i.e. * if no locks for this rule were found). */ extern bool prs2RemoveAllLocksOfRuleInPlace ARGS(( RuleLock locks, ObjectId ruleId )); /*------------------------------------------------------------------ a193 9 */ extern RuleLock prs2RemoveAllLocksOfRule ARGS(( RuleLock oldLocks, ObjectId ruleId )); /*------------------------------------------------------------------ a195 18 */ extern RuleLock prs2CopyLocks ARGS(( RuleLock locks )); /*------------------------------------------------------------------ * prs2GetLocksFromRelation * Get locks from the RelationRelation */ extern RuleLock prs2GetLocksFromRelation ARGS(( Name relationName )); /*------------------------------------------------------------------ a197 9 */ extern RuleLock prs2LockUnion ARGS(( RuleLock lock1, RuleLock lock2 )); /*------------------------------------------------------------------ a199 9 */ extern RuleLock prs2LockDifference ARGS(( RuleLock lock1, RuleLock lock2 )); /*------------------------------------------------------------------ d202 2 d205 17 a221 6 extern RuleLock prs2FindLocksOfType ARGS(( RuleLock locks, Prs2LockType locktype )); a222 10 /*------------------------------------------------------------------ * prs2RemoveLocksOfTypeInPlace * remove all the lcoks of the given type in place (i.e. No copies) */ extern void prs2RemoveLocksOfTypeInPlace ARGS(( RuleLock locks, Prs2LockType lockType )); d224 1 a224 1 /*------------------------------------------------------------------ a228 8 */ extern char * RuleLockToString ARGS(( RuleLock lock )); /*------------------------------------------------------------------ d232 4 a235 5 extern RuleLock StringToRuleLock ARGS(( char *string )); d237 1 d256 1 a256 2 /*====================== FILE: prs2define.c ============================*/ /*------------------------------------------------------------------ a258 9 */ extern void prs2DefineTupleRule ARGS(( LispValue parseTree, char *ruleText )); /*------------------------------------------------------------------ d262 14 a275 16 extern void prs2RemoveTupleRule ARGS(( Name ruleName )); extern Prs2RuleData prs2FindRuleData(); extern ObjectId prs2InsertRuleInfoInCatalog(); extern void prs2DeleteRuleInfoFromCatalog(); extern void prs2InsertRulePlanInCatalog(); extern void prs2DeleteRulePlanFromCatalog(); extern LispValue prs2GenerateActionPlans(); extern EventType prs2FindEventTypeFromParse(); extern ActionType prs2FindActionTypeFromParse(); extern void changeReplaceToRetrieve(); extern bool prs2AttributeIsOfBasicType(); a276 1 /*====================== FILE: prs2putlocks.c ============================*/ d278 1 a278 1 /*------------------------ a282 10 *------------------------ */ extern void prs2AddTheNewRule ARGS(( Prs2RuleData r, List hint )); /*------------------------ a286 1 *------------------------ d288 28 a315 26 extern void prs2DeleteTheOldRule ARGS(( ObjectId ruleId )); extern void prs2FindLockTypeAndAttrNo(); extern LispValue prs2FindConstantQual(); extern LispValue prs2FindConstantClause(); extern bool prs2IsATupleLevelLockRule(); /*====================== FILE: prs2tup.c ============================*/ extern bool prs2DefTupleLevelLockRule(); extern RuleLock prs2FindLocksThatWeMustPut(); extern bool prs2DoesStubDependsOnAttribute(); extern bool prs2LockWritesAttributes(); extern void prs2FindAttributesOfQual(); extern void prs2UndefTupleLeveLockRule(); extern void prs2RemoveTupleLeveLocksAndStubsOfManyRules(); /*====================== FILE: prs2rel.c ============================*/ extern void prs2DefRelationLevelLockRule(); extern void prs2UndefRelationLevelLockRule(); extern void prs2RemoveRelationLevelLocksOfRule(); extern void prs2SetRelationLevelLocks(); extern void prs2AddRelationLevelLock(); a383 20 extern Boolean prs2IsRuleInsteadFromRuleInfo ARGS(( LispValue ruleInfo )); extern AttributeNumber prs2GetEventAttributeNumberFromRuleInfo ARGS(( LispValue ruleInfo )); extern AttributeNumber prs2GetUpdatedAttributeNumberFromRuleInfo ARGS(( LispValue ruleInfo )); #define prs2GetParseTreeFromOneActionPlan(x) (CAR(x)) #define prs2GetPlanFromOneActionPlan(x) (CADR(x)) d385 1 a385 1 /* d391 15 a405 7 extern LispValue prs2GetRulePlanFromCatalog ARGS(( ObjectId ruleId, Prs2PlanNumber planNumber, ParamListInfo *paramListP )); d447 3 a449 1 /*--------------------------------------------------------------------- a453 10 */ extern AttributeValues attributeValuesCreate ARGS(( HeapTuple tuple, Buffer buffer, Relation relation )); /*--------------------------------------------------------------------- a455 9 */ extern void attributeValuesFree ARGS(( AttributeValues a, Relation relation )); /*-------------------------------------------------------------------- a462 14 */ extern int attributeValuesMakeNewTuple ARGS(( HeapTuple tuple, Buffer buffer, AttributeValues attrValues, RuleLock locks, Prs2LockType lockType, Relation relation, HeapTuple *newTupleP )); /*-------------------------------------------------------------------- d470 5 a474 9 extern HeapTuple attributeValuesCombineNewAndOldTuple ARGS(( AttributeValues rawAttrValues, AttributeValues newAttrValues, Relation relation, AttributeNumberPtr attributeArray, AttributeNumber numberOfAttributes )); d510 2 a511 1 /* a514 11 */ extern void prs2RuleStackPush ARGS(( Prs2EStateInfo p, ObjectId ruleId, ObjectId tupleOid, AttributeNumber attributeNumber )); /* a516 8 */ extern void prsRuleStackPop ARGS(( Prs2EStateInfo p )); /* a519 11 */ extern bool prs2RuleStackSearch ARGS(( Prs2EStateInfo p, ObjectId ruleId, ObjectId tupleOid, AttributeNumber attributeNumber )); /* a521 7 */ extern Prs2EStateInfo prs2RuleStackInitialize ARGS(( )); /* d525 5 a529 5 extern void prs2RuleStackFree ARGS(( Prs2EStateInfo p )); d535 3 a537 1 /* d539 4 a542 15 * * Given a plan (or an arbritary (?) lisp structure, transform it into a * a strign which has the following two properties * a) it is readable by (some) humans * b) it can be used to recreate the original plan/lisp structure * (see routine "StringToPlan"). * * * XXX Maybe this should be placed in another header file... */ extern char * PlanToString ARGS(( LispValue lispStructure )); d549 19 a567 2 extern LispValue StringToPlan(); extern LispValue StringToPlanWithParams(); a568 9 /* XXX this causes circular dependency! extern EState CreateExecutorState(); */ extern Prs2Status prs2Retrieve(); extern Prs2Status prs2Append(); extern Prs2Status prs2Delete(); extern Prs2Status prs2Replace(); extern RuleLock prs2FindLocksForNewTupleFromStubs(); d570 1 a570 2 /* * These are functions in prs2plans.c d572 12 a583 6 /*extern LispValue prs2GetRulePlanFromCatalog(); -glass */ extern int prs2CheckQual(); extern void prs2RunActionPlans(); extern int prs2RunOnePlanAndGetValue(); extern void prs2RunOnePlan(); extern LispValue prs2MakeQueryDescriptorFromPlan(); d585 1 a585 2 /* * functions in prs2bkwd.c d587 3 a589 3 extern void prs2CalculateAttributesOfParamNodes(); extern void prs2ActivateBackwardChainingRules(); extern void prs2ActivateForwardChainingRules(); d591 2 a592 2 /* * functions in prs2impexp.c d594 3 a596 3 extern RuleLock prs2FindNewExportLocksFromLocks(); extern RuleLock prs2GetExportLockFromCatalog(); extern void prs2ActivateExportLockRulePlan(); d598 1 d603 4 a606 1 * (all this stuff is defined in "rules/prs2/prs2main.c") a609 2 extern void ResetPrs2Stats(); extern void ShowPrs2Stats(); d611 15 a626 1 @ 1.30 log @fixed prototype for attributeFreeValue @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.29 91/12/07 17:18:25 dpassage Exp $ d37 1 a38 1 #define PRS2_DEBUG 1 @ 1.29 log @deleted spurious semicolon in prototype for attributeValuesFree() @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.28 91/12/04 01:58:45 glass Exp Locker: dpassage $ d672 2 a673 1 AttributeValues a @ 1.28 log @unterminated comment @ text @d6 1 a6 1 * $Header: ../src/lib/H/rules/RCS/prs2.h,v 1.27 91/11/18 22:23:29 mer Exp Locker: glass $ d672 1 a672 1 AttributeValues a; @ 1.27 log @prototypes finale @ text @d6 1 a6 1 * $Header: /users/mer/postgres/src/lib/H/rules/RCS/prs2.h,v 1.26 1991/11/12 23:30:14 mer Exp mer $ d668 1 d808 1 a808 1 @ 1.26 log @prototype fix @ text @d6 1 a6 1 * $Header: /users/mer/postgres/src/lib/H/rules/RCS/prs2.h,v 1.25 1991/11/11 23:06:06 hong Exp $ d471 2 a472 1 Prs2RuleData r d690 1 @ 1.25 log @clean up for prototyping @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.24 91/10/01 16:27:36 glass Exp Locker: hong $ d339 1 a339 1 Relation relation @ 1.24 log @initial ansi c compatibility checkin @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.23 91/04/23 14:54:53 sp Exp Locker: sp $ a831 1 extern LispValue MakeQueryDesc(); @ 1.23 log @some declarations for variables/routines used to collect rule usage statistics. @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.22 91/04/11 21:29:47 sp Exp Locker: sp $ d124 2 a125 1 prs2MustCallRuleManager ARGS(( d130 1 a130 1 )); d146 2 a147 1 prs2Main ARGS(( d164 1 a164 1 d203 1 a203 1 Prs2PlanNumber planNumber d228 1 a228 1 Prs2OneLock oneLock2, d240 1 a240 1 RuleLock locks; d255 1 a255 1 Buffer buffer, d329 1 a329 1 RuleLock locks; d350 1 a350 1 RuleLock lock1 d361 1 a361 1 RuleLock lock1 d372 1 a372 1 Prs2LockType locktype; d659 3 a661 3 HeapTuple tuple; Buffer buffer; Relation relation; d685 6 a690 6 HeapTuple tuple; Buffer buffer; AttributeValues attrValues; RuleLock locks; Relation relation; HeapTuple *newTupleP; d766 1 a766 1 Prs2EStateInfo p; d779 1 a779 1 ObjectId tupleOid; d799 1 a799 1 Prs2EStateInfo p; d846 1 a846 1 extern LispValue prs2GetRulePlanFromCatalog(); @ 1.22 log @new function 'prs2MustCallRuleManager' @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.21 91/04/10 16:06:37 sp Exp $ d864 11 @ 1.21 log @the format of the rule plans has slightly changed... @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.20 91/04/08 18:12:50 sp Exp Locker: sp $ d119 13 d146 2 d155 2 @ 1.20 log @misc changes to support locking more than one path in the rule qualification's tree... @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.19 91/02/25 16:52:12 sp Exp Locker: sp $ d226 5 a230 4 * Extract the locks from a tuple. It returns a 'RuleLock', * (NOTE:it will never return NULL! Even if the tuple has no * locks in it, it will return a 'RuleLock' with 'numberOfLocks' * equal to 0. a236 1 TupleDescriptorData tupleDescriptor d547 1 a547 1 #define prs2GetPlanInfoFromRulePlan(x) (CADR(x)) d549 3 a551 3 #define prs2GetRuleInfoFromActionPlan(x) (CAR(CADR(x))) #define prs2GetQualFromActionPlan(x) (CADR(CADR(x))) #define prs2GetActionsFromActionPlan(x) (CDR(CDR(CADR(x)))) d553 2 a554 2 #define prs2GetLockInfoFromExportPlan(x) (CAR(CADR(x))) #define prs2GetActionPlanFromExportPlan(x) (CADR(CADR(x))) @ 1.19 log @'GetRuleHintFromParse' added. @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.18 91/02/24 19:57:10 sp Exp $ d180 7 a186 5 RuleLock oldLocks, ObjectId ruleId, Prs2LockType lockType, AttributeNumber attributeNumber, Prs2PlanNumber planNumber d202 23 d335 11 d493 8 a500 1 * They are a list with at least two items: d502 2 a503 4 * The first item is a list giving some info for the rule. * Currently this can have the following elements: * The first element is an integer, equal to 1 if the rule is an * instead rule, 0 otherwise. d505 9 a513 7 * The second item is the qualification of the rule. * This should be tested before and only if it succeeds should the * action part of the rule be executed. * This qualifcation can be either "nil" which means that * there is no qualifcation and the action part of the rule should be * executed, or a 2 item list, the first item beeing the parse tree * corresponding to the qualifcation and the second one the plan. d515 25 a539 4 * Finally the (optional) rest items are the actions of the rule. * Each one of them can be either a 2 item list (parse tree + plan) * or the string "abort" which means that the current Xaction should be * aborted. d543 2 a544 3 #define prs2GetRuleInfoFromRulePlan(x) (CAR(x)) #define prs2GetQualFromRulePlan(x) (CADR(x)) #define prs2GetActionsFromRulePlan(x) (CDR(CDR(x))) d546 10 d810 1 d812 1 d840 7 @ 1.18 log @2 new routines: prs2RemoveLocksOfTypeInPlace() and prs2FindLocksForNewTupleFromStubs(). @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.17 91/02/24 12:34:43 sp Exp Locker: sp $ d357 1 @ 1.17 log @A lot of changes (tuple-level-locking is here to stay!) @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.16 91/02/08 17:37:12 sp Exp Locker: sp $ d321 11 d746 1 @ 1.16 log @Now 'prs2PutLocks' makes the update in place (i.e. it does NOT create a copy of the tuple). @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.15 91/01/09 18:58:47 sp Exp Locker: sp $ d41 69 a116 10 /*------------------------------------------------------------------ * prs2DefineTupleRule * Define a PRS2 rule (tuple level proccessing) */ extern void prs2DefineTupleRule ARGS(( LispValue parseTree, char *ruleText )); a118 10 * prs2RemoveTupleRule * Remove a prs2 rule given its name. */ extern void prs2RemoveTupleRule ARGS(( Name ruleName )); /*------------------------------------------------------------------ d239 26 d310 11 d359 4 a362 4 /* * prs2InsertRuleInfoInCatalog * add information about the rule to the system catalogs. * returns the OID of the rule. d365 4 a368 3 ObjectId prs2InsertRuleInfoInCatalog ARGS(( Name ruleName d371 3 a373 10 /* * prs2GenerateActionPlans * Generate the plans for the action part of the rule * The input argument is a list with the parsetrees for all * the commands specified in the action part of the rule + the * rule qualification. * The returned value is a list with one item per command. * Each one of them is a list with a (possibly modified) * parse tree and the corresponding plan. a375 12 LispValue prs2GenerateActionPlans ARGS(( int isRuleInstead, LispValue ruleQual, LispValue ruleAction )); /* * prs2InsertRulePlanInCatalog * Insert a rule plan into the appropriate system catalogs. */ extern d377 2 a378 4 prs2InsertRulePlanInCatalog ARGS(( ObjectId ruleId, /* the OID of the rule */ Prs2PlanNumber planNumber, /* the PlanNumber for this plan*/ LispValue rulePlan d381 19 a399 4 /* * prs2PutRelationLevelLocks * Put all the appropriate locks in the RelationRelation * (relation level locking...). d403 2 a404 5 prs2PutRelationLevelLocks ARGS(( ObjectId ruleId, /* the OID of the rule */ Prs2LockType lockType /* the type of lock */ ObjectId eventRelationOid; /* the OID of the locked relation */ AttributeNumber attrNo; /* the attribute to be locked */ d407 6 a412 4 /* * prs2RemoveRelationLevelLocks * Remove the lock put by 'prs2PutRelationLevelLocks' * (relation level locks) d416 2 a417 3 prs2RemoveRelationLevelLocks ARGS(( ObjectId ruleId, /* the OID of the rule */ ObjectId eventRelationOid /* OID of the locked relation */ d420 4 d425 16 a734 2 extern EventType prs2FindEventTypeFromParse(); extern ActionType prs2FindActionTypeFromParse(); @ 1.15 log @Some functions have been renamed... @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.14 90/10/16 17:15:28 sp Exp $ d167 2 a168 2 * given a tuple, create a copy of it and put the given locks in its * t_lock field... d171 1 a171 1 HeapTuple @ 1.14 log @'prs2RunOnePlan' now does not return a value... @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.13 90/08/19 15:29:13 sp Exp Locker: sp $ d316 1 a316 1 * prs2PutLocksInRelation d322 1 a322 1 prs2PutLocksInRelation ARGS(( d330 3 a332 3 * prs2RemoveLocks * Remove the lock put by 'prs2PutLocks' * For the time being only relation level locking is implemented. d336 1 a336 1 prs2RemoveLocks ARGS(( a637 1 extern void Prs2PutLocks(); @ 1.13 log @Some #defines have been moved to prs2locks.h @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.12 90/08/18 00:40:35 cimarron Exp Locker: sp $ d647 1 a647 1 extern LispValue prs2RunOnePlan(); @ 1.12 log @eliminated less significant .h files @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.11 90/08/17 08:53:01 cimarron Exp Locker: cimarron $ d30 1 a30 1 * These defs were put in a separate file becuase they are included a100 31 /*------------------------------------------------------------------ * Routines to access/set Prs2Lock data... * It is highly recommended that these routines are used instead * of directly manipulating the variosu structures invloved.. *------------------------------------------------------------------ */ #define prs2OneLockGetRuleId(l) ((l)->ruleId) #define prs2OneLockGetLockType(l) ((l)->lockType) #define prs2OneLockGetAttributeNumber(l) ((l)->attributeNumber) #define prs2OneLockGetPlanNumber(l) ((l)->planNumber) #define prs2OneLockSetRuleId(l, x) ((l)->ruleId = (x)) #define prs2OneLockSetLockType(l, x) ((l)->lockType = (x)) #define prs2OneLockSetAttributeNumber(l, x) ((l)->attributeNumber = (x)) #define prs2OneLockSetPlanNumber(l, x) ((l)->planNumber = (x)) /*------------------------------------------------------------------ * prs2LockSize * return the size needed for a 'Prs2LocksData' structure big enough * to hold 'n' of 'Prs2OneLockData' structures... */ #define prs2LockSize(n) (sizeof(Prs2LocksData) \ + ((n)-1)*sizeof(Prs2OneLockData)) /*------------------------------------------------------------------ * prs2GetNumberOfLocks * return the number of locks contained in a 'RuleLock' structure. */ #define prs2GetNumberOfLocks(x) ((x)->numberOfLocks) @ 1.11 log @added pathnames to #include statements @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.10 90/07/18 18:41:04 sp Version_2 Locker: cimarron $ d18 1 a18 1 #include "tmp/c.h" a23 1 #include "tmp/datum.h" @ 1.10 log @Yet anothet parsetree change... @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.9 90/07/17 20:33:27 sp Exp $ d18 1 a18 8 #include "c.h" #include "pg_lisp.h" #include "datum.h" #include "heapam.h" #include "rel.h" #include "tupdesc.h" #include "buf.h" #include "params.h" d20 9 d34 1 a34 1 #include "prs2locks.h" @ 1.9 log @changed some macros because of new parsetree format @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.8 90/05/21 15:14:40 sp Exp $ d291 6 a296 5 #define GetRuleEventTypeFromParse(p) (nth(3,p)) #define GetRuleEventTargetFromParse(p) (nth(4,p)) #define GetRuleQualFromParse(p) (nth(5,p)) #define GetRuleInsteadFromParse(p) (nth(6,p)) #define GetRuleActionFromParse(p) (nth(7,p)) @ 1.8 log @RuleLockToString and StringToRuleLock declared here... @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.7 90/05/14 20:30:18 sp Exp $ d295 1 a295 1 #define GetRuleActionFromParse(p) (lispCons(nth(7,p),LispNil)) @ 1.7 log @I changed the "parse tree" #defines so now they agree with what the parser produces... @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.6 90/05/10 16:20:34 sp Exp $ d264 21 @ 1.6 log @definitions for 'Prs2RuleListItem' have been moved to 'rulescan.h' @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.5 90/04/19 19:41:26 sp Exp Locker: sp $ d269 6 a274 6 #define GetRuleNameFromParse(p) (nth(1,p)) #define GetRuleEventTypeFromParse(p) (nth(2,p)) #define GetRuleEventTargetFromParse(p) (nth(3,p)) #define GetRuleQualFromParse(p) (nth(4,p)) #define GetRuleInsteadFromParse(p) (nth(5,p)) #define GetRuleActionFromParse(p) (nthCdr(6,p)) @ 1.5 log @Some new stuff for the rule info stored in the scan state. @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.4 90/04/03 17:02:27 sp Exp $ a605 93 /*======================================================================== * * SCAN STATE RULE INFORMATION * * In every scan node we have to stroe some information about rules. * So, `CommonScanState' (see execnodes.h) contain a field called * 'css_ruleInfo' where all this information is stored. * This information should be correctly initialized at the same time the * rest of `ScanState' is also initialized (this happens when the * executor is called to perform the EXEC_START operation). * * The scan state rule information contains the current fields: * * ruleList: this is a linked list of records containing information * about all the 'view' like rules, i.e. rules of the form * ON retrieve to * DO [ instead ] retrieve ...... * These rules are processed first by the executor (i.e. before we even * call the access methods for the first time) to retrieve (one by one) * all the tuples returned by the action pat of the rule. * Then if none of these 'view' rules was an "instead" rule, we process * the "real" tuples (the ones returned by the access methods). * * Each record in ruleList can be either a ruleId - plan number pair, * or a plan (a LispValue) corresponding to a rule (NOTE: each rule * can have more than one plans!) or a query descriptor - EState * pair (in which case we have started retrieving tuples, one by one). * A NULL ruleList means that there are no (more) rules to be processed. * * insteadRuleFound: True if there was at least one "instead" * rule was encountered, false otherwise. * * relationLock: the (relation level) rule locks for the scanned * relation (found in the Relation relation) * */ #define PRS2_RULELIST_RULEID 1 #define PRS2_RULELIST_PLAN 2 #define PRS2_RULELIST_QUERYDESC 3 #define PRS2_RULELIST_DONE 99 #define PRS2_RULELIST_INVALID 100 typedef struct Prs2RuleListItem { int type; struct Prs2RuleListItem *next; union { struct ruleId { ObjectId ruleId; Prs2PlanNumber planNumber; } ruleId; struct rulePlan { LispValue plan; } rulePlan; struct { LispValue queryDesc; struct EState *estate; /* XXXXX THIS IS A HACK! */ } queryDesc; } data; } Prs2RuleListItem; typedef Prs2RuleListItem *Prs2RuleList; typedef struct ScanStateRuleInfoData { Prs2RuleList ruleList; bool insteadRuleFound; RuleLock relationLocks; } ScanStateRuleInfoData; typedef ScanStateRuleInfoData *ScanStateRuleInfo; /*------------- * Create and initialize a 'ScanStateRuleInfo' */ extern ScanStateRuleInfo prs2MakeScanStateRuleInfo ARGS(( Relation relation )); /*------------- * Activate the "view" rules & return one by one all the appropriate * tuples... */ extern HeapTuple prs2GetOneTupleFromViewRules ARGS(( ScanStateRuleInfo scanStateRuleInfo, Prs2EStateInfo prs2EStateInfo, Relation explainRel )); @ 1.4 log @Some new function declarations... @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.3 90/03/07 17:14:17 sp Exp $ d608 93 d711 1 a711 2 * (see routine "StringToPlan". * NOTE: used to be called "plan_to_string" d749 1 @ 1.3 log @Added a new attribute `prs2QueryDesc' in Prs2EstateInfo @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.2 90/01/30 23:20:24 sp Exp $ d380 5 a384 1 #define prs2IsRuleInsteadFromRuleInfo(x) (!strcmp(CString(CAR(x)),"instead")) d386 12 d498 18 a530 2 * prs2QueryDesc: the query descriptor of a recursive call made by the * rule manager to the executor. a542 1 LispValue prs2QueryDesc; @ 1.2 log @added some more rutine declarations... @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.1 90/01/11 14:46:05 sp Exp $ d136 5 a140 1 #define prs2FreeLocks(x) pfree((x)) d380 1 a380 1 #define prs2IsRuleInsteadFromRuleInfo(x) (CInteger(CAR(x))) d485 2 a486 5 * The following has to do with a rule loop detection mechanism. * The 'Prs2EStateInfo' is a pointer to a structure that contains * all the appropriate info. Note that this is kept inside the * executor state node EState. * Initially this should be NULL. d488 12 d511 2 a514 1 Prs2Stack prs2Stack; /* the stack used for loop detection */ @ 1.1 log @Initial revision @ text @d6 1 a6 1 * $Header: RCS/prs2.h,v 1.6 90/01/11 00:22:27 sp Exp Locker: sp $ d78 1 a78 1 #define PRS2_STATUS_STATUS_INSTEAD 3 d128 1 a128 1 * return the number of locks contained in a 'Prs2Locks' structure. d144 1 a144 1 Prs2Locks d155 1 a155 1 Prs2Locks d157 1 a157 1 Prs2Locks oldLocks, d166 1 a166 1 * Given a 'Prs2Locks' return a pointer to its Nth lock.. d172 1 a172 1 Prs2Locks locks, d178 1 a178 1 * Extract the locks from a tuple. It returns a 'Prs2Locks', d180 1 a180 1 * locks in it, it will return a 'Prs2Locks' with 'numberOfLocks' d184 1 a184 1 Prs2Locks d202 1 a202 1 Prs2Locks newLocks d212 1 a212 1 Prs2Locks locks d218 1 a218 1 * the old `Prs2Locks' is destroyed and should never be d223 1 a223 1 Prs2Locks d225 1 a225 1 Prs2Locks oldLocks, d234 1 a234 1 Prs2Locks d236 1 a236 1 Prs2Locks locks; d244 1 a244 1 Prs2Locks d251 1 a251 1 * Create the union of two Prs2Locks. d254 1 a254 1 Prs2Locks d256 2 a257 2 Prs2Locks lock1, Prs2Locks lock1 d320 3 a322 3 * prs2PutLocks * Put all the appropriate locks. * For the time being only relation level locking is implemented. d326 5 a330 4 prs2PutLocks ARGS(( ObjectId ruleId, /* the OID of the rule */ LispValue eventTargetList,/* the target list specified in the event */ int lockType /* the event that triggers the rule */ d352 4 a355 4 * The first item is a string giving some info for the rule. * Currently this can have the following values: * "instead" the rule has an instead specified in its action part * "not-instead" no instead specified in the action part.. d376 2 d433 1 d473 1 a473 1 Prs2Locks locks; d503 1 a503 1 typedef Prs2EStateInfoData *Prs2EStateInfo; d562 3 d566 19 d586 1 a586 1 * Thse routines are some 'internal' routines. d590 6 a595 2 extern void prs2CalculateOneAttribute(); extern void prs2CalculateAttributesOfParamNodes(); d600 3 d604 8 d613 6 d621 1 @