head	1.14;
access;
symbols
	Version_2_1:1.12
	Version_2:1.6;
locks; strict;
comment	@ * @;


1.14
date	92.03.11.02.20.38;	author mer;	state Exp;
branches;
next	1.13;

1.13
date	91.04.08.18.12.45;	author sp;	state Exp;
branches;
next	1.12;

1.12
date	91.02.24.12.35.25;	author sp;	state Exp;
branches;
next	1.11;

1.11
date	91.02.08.13.03.48;	author sp;	state Exp;
branches;
next	1.10;

1.10
date	91.01.17.18.58.50;	author sp;	state Exp;
branches;
next	1.9;

1.9
date	91.01.09.18.59.18;	author sp;	state Exp;
branches;
next	1.8;

1.8
date	90.08.19.15.29.55;	author sp;	state Exp;
branches;
next	1.7;

1.7
date	90.08.17.08.53.03;	author cimarron;	state Exp;
branches;
next	1.6;

1.6
date	90.07.30.16.41.01;	author sp;	state Version_2;
branches;
next	1.5;

1.5
date	90.07.17.21.13.55;	author sp;	state Exp;
branches;
next	1.4;

1.4
date	90.04.19.19.43.05;	author sp;	state Exp;
branches;
next	1.3;

1.3
date	90.02.08.14.47.09;	author hong;	state Exp;
branches;
next	1.2;

1.2
date	90.01.30.23.21.09;	author sp;	state Exp;
branches;
next	1.1;

1.1
date	90.01.11.14.46.34;	author sp;	state Exp;
branches;
next	;


desc
@PRS2 locks are defined here (this is separated from 'prs2.h' in
order to keep it simple so that it can be easily included in
'htup.h' - otherwise there are some circular dependencies...)
@


1.14
log
@turn of debug output
@
text
@/*
 * FILE:
 *   prs2locks.h
 *
 * IDENTIFICATION:
 *   $Header: /users/mer/pg/src/lib/H/rules/RCS/prs2locks.h,v 1.13 1991/04/08 18:12:45 sp Exp mer $
 *
 * DESCRIPTION:
 *   include stuff for PRS2 locks.
 *   This file contain only the definition for the prs2Locks, so that
 *   it can be easily included in "htup.h".
 *   For declarations of routines that manipulate locks, see
 *   "prs2.h"
 */

/*
 * Include this file only once...
 */
#ifndef Prs2LocksIncluded
#define Prs2LocksIncluded
#define PRS2LOCKS_H

#include "tmp/postgres.h"
#include "access/attnum.h"

/* -----------------------------------
 * Comment out the following to suppress debugging output
 *
 * #define PRS2_DEBUG 1
 */

/*==================================================================
 * PRS2 LOCKS
 *==================================================================
 */

/*------------------------------------------------------------------
 * event types: the types of event that can cause rule activations...
 *------------------------------------------------------------------
 */
typedef char EventType;
#define EventTypeRetrieve	'R'
#define EventTypeReplace	'U'
#define EventTypeAppend		'A'
#define EventTypeDelete		'D'
#define EventTypeInvalid	'*'

/*------------------------------------------------------------------
 * Action types. These are the possible actions that can be defined
 * in the 'do' part of a rule.
 * Currently the actiosn suuported are:
 * ActionTypeRetrieveValue: the action part of the rule is a
 *   'retrieve (expression) where ....'. (a 'retrieve  into relation'
 *   query is NOT of this type!
 *   NOTE: under the current implementation, if such an action is
 *   specified in the action part of a rule, no other action can
 *   be specified!
 * ActionTypeReplaceCurrent: the action is a 'replace CURRENT(x=..)'
 *   NOTE: under the current implementation, if such an action is
 *   specified in the action part of a rule, no other action can
 *   be specified!
 * ActionTypeReplaceNew: the action is a 'replace NEW(x=..)'
 *   NOTE: under the current implementation, if such an action is
 *   specified in the action part of a rule, no other action can
 *   be specified!
 * ActionTypeOther: Any other action... (including 'retrieve into...')
 *------------------------------------------------------------------
 */
typedef char ActionType;
#define ActionTypeRetrieveValue		'r'
#define ActionTypeReplaceCurrent	'u'
#define ActionTypeReplaceNew		'U'
#define ActionTypeOther			'o'
#define ActionTypeInvalid		'*'

/*------------------------------------------------------------------
 * Plan numbers for various rule plans (as stored in the system catalogs)
 *------------------------------------------------------------------
 */
typedef uint16 Prs2PlanNumber;

/* #define QualificationPlanNumber		((Prs2PlanNumber)0) */
#define ActionPlanNumber		((Prs2PlanNumber)1)

/*------------------------------------------------------------------
 * Used to distinguish between 'old' and 'new' tuples...
 *------------------------------------------------------------------
 */
#define PRS2_OLD_TUPLE 1
#define PRS2_NEW_TUPLE 2

/*------------------------------------------------------------------
 * Types of locks..
 *
 * We distinguish between two types of rules: the 'backward' & 'forward'
 * chaning rules. The 'backward' chaining rules are the ones that
 * calculate a value for the current tuple, like:
 *    on retrieve to EMP.salary where EMP.name = "mike"
 *    do instead retrieve (salary=1000)
 * or
 *    on append to EMP where EMP.age<25
 *    do replace CURRENT(salary=2000)
 *
 * The forward chaining rules are the ones that do some action but do not
 * update the current tuple, like:
 *    on replace to EMP.salary where EMP.name = "mike"
 *    do replace EMP(salary=NEW.salary) where EMP.name = "john"
 * or
 *    on retrieve to EMP.age where EMP.name = "mike"
 *    do append TEMP(username = user(), age = OLD.age)
 *
 * The first type of rules gets a `LockTypeXXXWrite' lock (where XXX is
 * the event specified in the "on ..." clause and can be one of
 * retrieve, append, delete or replace) and the forward chinign rules
 * get locks of the form `LockTypeXXXAction'
 *
 * There is also the LockTypeRetrieveRelation, put by 'view' rules, 
 * i.e. rules of the form
 *	ON retrieve to relation
 *      DO [ instead ] retrieve .... <some other tuples> ...
 * These rules are used to implement views.
 *
 * NOTE: as we have 2 rule systems (tuple-level & query rewrite)
 * we use different lock types for each one of them.
 * Otherwise it wouldn't be possible to distinguish whether a rule
 * is a tuple-level rule or of query-rewrite flavor.
 *
 *------------------------------------------------------------------
 */
typedef char Prs2LockType;

#define LockTypeInvalid			((Prs2LockType) '*')

#ifdef OBSOLETE
/*--- QUERY REWRITE LOCK TYPES ------------------------------------*/
#define LockTypeTupleRetrieveAction		((Prs2LockType) '1')
#define LockTypeTupleAppendAction		((Prs2LockType) '2')
#define LockTypeTupleDeleteAction		((Prs2LockType) '3')
#define LockTypeTupleReplaceAction		((Prs2LockType) '4')
#define LockTypeTupleRetrieveWrite		((Prs2LockType) '5')
#define LockTypeTupleAppendWrite		((Prs2LockType) '6')
#define LockTypeTupleDeleteWrite		((Prs2LockType) '7')
#define LockTypeTupleReplaceWrite		((Prs2LockType) '8')
#define LockTypeTupleRetrieveRelation		((Prs2LockType) '9')
#endif OBSOLETE

/*--- TUPLE LEVEL LOCK TYPES --------------------------------------*/
#define LockTypeRetrieveAction		((Prs2LockType) 'r')
#define LockTypeAppendAction		((Prs2LockType) 'a')
#define LockTypeDeleteAction		((Prs2LockType) 'd')
#define LockTypeReplaceAction		((Prs2LockType) 'u')
#define LockTypeRetrieveWrite		((Prs2LockType) 'R')
#define LockTypeAppendWrite		((Prs2LockType) 'A')
#define LockTypeDeleteWrite		((Prs2LockType) 'D')
#define LockTypeReplaceWrite		((Prs2LockType) 'U')
#define LockTypeRetrieveRelation	((Prs2LockType) 'V')
#define LockTypeImport			((Prs2LockType) 'I')
#define LockTypeExport			((Prs2LockType) 'E')

/*------------------------------------------------------------------
 * Every single lock (`Prs2OneLock') has the following fields:
 *	ruleId:		OID of the rule
 *	lockType:	the type of locks
 *	attributeNumber:the attribute that is locked. A value
 *			equal to 'InvalidAttributeNumber' means that
 *                      all the attributes of the tuple are locked.
 *	planNumber:	the plan number of the plan (which is stored
 *			in the system catalogs) that must be executed
 *                      if the rule is activated. This is usually
 *                      equal to 'ActionPlanNumber', but we might add
 *                      others as well when we'll implement a 
 *                      more complex locking scheme.
 *	partialindx,
 *	npartial:	This is a field unique to 'import' locks.
 *			A tuple might have many "import" locks,
 *			depending on the rule. Each such import
 *			lock is only a "partial" lock, and in order
 *			for the tuple to be locked, we must have all
 *			its partial locks. `npartial' is the number
 *			of locks this tuple must have to be considered
 *			as locked, and foreach lock `partialindx'
 *			is the "index" of this partial lock
 *			(a number between 0 ... npartial-1).
 *			NOTE: we might have more than one locks with
 *			the same `partialindx'. However they only count
 *			as one.
 *
 * Every tuple can have more than one rule locks, so we need
 * a structure 'Prs2LocksData' to hold them.
 *   	numberOfLocks:	the number of entries in the 'locks' array.
 *	locks[]:	A *VARIABLE LENGTH* array with 0 or more
 *                      entries of type Prs2OneLock.
 *------------------------------------------------------------------
 */
typedef struct Prs2OneLockData {
    ObjectId		ruleId;	
    Prs2LockType	lockType;
    AttributeNumber	attributeNumber;
    Prs2PlanNumber	planNumber;
    int			partialindx;
    int			npartial;
} Prs2OneLockData;

typedef Prs2OneLockData *Prs2OneLock;

typedef struct Prs2LocksData {
    int			numberOfLocks;
    Prs2OneLockData	locks[1];	/* XXX VARIABLE LENGTH DATA */
} Prs2LocksData;

typedef Prs2LocksData	*RuleLock;


/*------------------------------------------------------------------
 * INVALID RULE LOCK:
 *
 * This is an illegal value for a (main memory representation) of a
 * rule lock. You must not confuse it with the "empty" lock, i.e.
 * the lock: "(numOfLocs: 0)"::lock.
 *
 * However note that (as even an empty rule lock is 4 bytes long)
 * in order to save disk space, when we 
 * store an empty lock in the disk, we use an InvalidItemPointer
 *
 * NOTE: `RuleLockIsValid' only applies for the main memory
 * representation of a lock!
 */
#define InvalidRuleLock		((RuleLock) NULL)
#define RuleLockIsValid(x)    PointerIsValid(x)

/*------------------------------------------------------------------
 * #defines to access/set Prs2Lock data...
 * It is highly recommended that these routines are used instead
 * of directly manipulating the various structures invloved..
 *------------------------------------------------------------------
 */

#define prs2OneLockGetRuleId(l)			((l)->ruleId)
#define prs2OneLockGetLockType(l)		((l)->lockType)
#define prs2OneLockGetAttributeNumber(l)	((l)->attributeNumber)
#define prs2OneLockGetPlanNumber(l)		((l)->planNumber)
#define prs2OneLockGetPartialIndx(l)		((l)->partialindx)
#define prs2OneLockGetNPartial(l)		((l)->npartial)

#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))
#define prs2OneLockSetPartialIndx(l, x)		((l)->partialindx = (x))
#define prs2OneLockSetNPartial(l, x)		((l)->npartial = (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)==NULL ? 0 : (x)->numberOfLocks)

/*------------------------------------------------------------------
 * prs2RuleLockIsEmpty
 * 	return true if this is an empty rule lock.
 */
#define prs2RuleLockIsEmpty(l)	(prs2GetNumberOfLocks(l) == 0)

/*=================================================================
 *
 * VARIOUS SYSTEM RELATION CONSTANTS
 *
 *=================================================================
 */

/*----
 * pg_type.oid for the "lock" type
 */
#define PRS2_LOCK_TYPEID	((ObjectId) 31)
#define PRS2_BOOL_TYPEID	((ObjectId) 16)
/*---
 * varnos for the NEW & CURRENT tuple.
 * these are hardwired in the parser code...
 */
#define PRS2_CURRENT_VARNO	1
#define PRS2_NEW_VARNO		2

#endif Prs2LocksIncluded
@


1.13
log
@misc changes to support locking more than one path in the rule
qualification's tree...
@
text
@d6 1
a6 1
 *   $Header: RCS/prs2locks.h,v 1.12 91/02/24 12:35:25 sp Exp Locker: sp $
d26 5
a30 1
#define PRS2_DEBUG 1
@


1.12
log
@The "current" and "new" varnos are hardwired in the code...
@
text
@d6 1
a6 1
 *   $Header: RCS/prs2locks.h,v 1.11 91/02/08 13:03:48 sp Exp $
d130 2
a131 1
/*--- TUPLE LEVEL LOCK TYPES --------------------------------------*/
d141 1
d143 1
a143 1
/*--- QUERY REWRITE LOCK TYPES ------------------------------------*/
d153 2
d169 14
d195 3
a197 1
    Prs2PlanNumber		planNumber;
d238 2
d245 2
@


1.11
log
@the oid of type "bool" is hardwired in the code, i am afraid...
@
text
@d6 1
a6 1
 *   $Header: RCS/prs2locks.h,v 1.10 91/01/17 18:58:50 sp Exp $
d256 6
@


1.10
log
@More comments about InvalidRuleLocks. They are diff from EMPTY locks!
@
text
@d6 1
a6 1
 *   $Header: RCS/prs2locks.h,v 1.9 91/01/09 18:59:18 sp Exp $
d255 1
@


1.9
log
@#defined 'PRS2_LOCK_TYPEID', i.e. the type id for rule locks.
@
text
@d6 1
a6 1
 *   $Header: RCS/prs2locks.h,v 1.8 90/08/19 15:29:55 sp Exp Locker: sp $
d190 14
d205 1
a205 2
#define RuleLockIsValid(x)	PointerIsValid(x)

@


1.8
log
@Moved some #defines from prs2.h to prs2locks.h +
added 'prs2RuleLockIsEmpty' + 'prs2GetNumberOfLocks' works
OK with NULL locks.
@
text
@d6 1
a6 1
 *   $Header: RCS/prs2locks.h,v 1.7 90/08/17 08:53:03 cimarron Exp Locker: sp $
d230 12
@


1.7
log
@added pathnames to #include statements
@
text
@d6 1
a6 1
 *   $Header: RCS/prs2locks.h,v 1.6 90/07/30 16:41:01 sp Version_2 Locker: cimarron $
d192 39
@


1.6
log
@A new ActionType (ActionTypeReplaceNew) is defined...
@
text
@d6 1
a6 1
 *   $Header: RCS/prs2locks.h,v 1.5 90/07/17 21:13:55 sp Exp Locker: sp $
d23 2
a24 9
#ifndef C_H
#include "c.h"
#endif
#ifndef POSTGRES_H
#include "postgres.h"
#endif
#ifndef ATTNUM_H
#include "attnum.h"
#endif
@


1.5
log
@Now we have 2 sets of LockTypes, one for the tuple-level system
and one for the query rewrite system.
@
text
@d6 1
a6 1
 *   $Header: RCS/prs2locks.h,v 1.4 90/04/19 19:43:05 sp Exp Locker: sp $
d65 4
d75 1
@


1.4
log
@A new type of lock: `LockTypeRetrieveRelation' needed 
by the "view" rules...
@
text
@d6 1
a6 1
 *   $Header: RCS/prs2locks.h,v 1.3 90/02/08 14:47:09 hong Exp Locker: sp $
d121 5
d131 13
@


1.3
log
@fix for hermes to reduce levels of #include nesting.
@
text
@d6 1
a6 1
 *   $Header: RCS/prs2locks.h,v 1.2 90/01/30 23:21:09 sp Exp $
d115 6
d134 1
@


1.2
log
@manychanges, the most significant is that 'Prs2Locks'
have been renamed, yes! 'RuleLocks' just like the old ones!
(so that I don't have to change the declarations in a zilion of
files...)
@
text
@d6 1
a6 1
 *   $Header: RCS/prs2locks.h,v 1.1 90/01/11 14:46:34 sp Exp $
d21 1
d23 1
d25 2
d28 2
d31 1
@


1.1
log
@Initial revision
@
text
@d6 1
a6 1
 *   $Header: RCS/prs2locks.h,v 1.3 90/01/11 00:22:59 sp Exp Locker: sp $
d23 2
d35 1
d45 23
d77 7
d86 8
a93 11
 * If the event specified in the event clause of a rule (i.e. the "on ..."
 * clause) is a replace, append or delete then the corresponding lock
 * type is LockTypeOnReplace, LockTypeOnAppend or LockTypeOnDelete.
 * If we are dealing with an 'on retrieve' rule, then we distinguish
 * between 2 cases:
 *  a) either the action is a retrieves that updates the current tuple
 *  (as for example in 'on retrieve to EMP.salary do instead retrieve ...'
 *  in which case the lock type is 'LockTypeWrite' (i.e. we have
 *  a kind of backward chaining)
 *  b) or we hace something like 'on retrieve ... do append ....'
 *  in which case we use a LockTypeOnRetrieve.
d95 13
d113 8
a120 5
#define LockTypeOnRetrieve		((Prs2LockType) 'r')
#define LockTypeOnAppend		((Prs2LockType) 'a')
#define LockTypeOnDelete		((Prs2LockType) 'd')
#define LockTypeOnReplace		((Prs2LockType) 'u')
#define LockTypeWrite			((Prs2LockType) 'w')
d157 1
a157 1
typedef Prs2LocksData	*Prs2Locks;
d160 2
a161 2
#define InvalidPrs2Locks	((Prs2Locks) NULL);
#define Prs2LocksIsValid(x)	PointerIsValid(x)
@
