head	1.18;
access;
symbols
	release_4_2:1.18
	aix_ok:1.17
	Version_2_1:1.12
	C_Demo_1:1.8
	Retrieve_x_qual:1.6
	Retrieve_x_all:1.5
	Retrieve_x_1:1.4;
locks; strict;
comment	@ * @;


1.18
date	93.10.24.08.11.57;	author aoki;	state Exp;
branches;
next	1.17;

1.17
date	93.02.17.01.31.31;	author olson;	state Exp;
branches;
next	1.16;

1.16
date	91.11.18.17.29.14;	author mer;	state Exp;
branches;
next	1.15;

1.15
date	91.11.07.01.34.10;	author hong;	state Exp;
branches;
next	1.14;

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

1.13
date	91.05.23.18.33.40;	author kemnitz;	state Exp;
branches;
next	1.12;

1.12
date	90.09.25.16.37.34;	author kemnitz;	state Exp;
branches;
next	1.11;

1.11
date	90.06.05.16.22.01;	author hong;	state Exp;
branches;
next	1.10;

1.10
date	90.05.25.14.09.08;	author mao;	state Exp;
branches;
next	1.9;

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

1.8
date	89.09.05.17.18.40;	author mao;	state C_Demo_1;
branches;
next	1.7;

1.7
date	89.08.23.16.05.33;	author ong;	state Exp;
branches;
next	1.6;

1.6
date	89.08.04.14.26.32;	author goh;	state Exp;
branches;
next	1.5;

1.5
date	89.08.04.13.30.44;	author goh;	state Exp;
branches;
next	1.4;

1.4
date	89.08.01.14.41.10;	author goh;	state Exp;
branches;
next	1.3;

1.3
date	89.07.28.12.12.13;	author goh;	state Exp;
branches;
next	1.2;

1.2
date	89.07.24.10.38.18;	author ong;	state Exp;
branches;
next	1.1;

1.1
date	89.07.24.08.49.41;	author goh;	state Exp;
branches;
next	;


desc
@@


1.18
log
@indexinfo interface should be array of long (for alpha)
@
text
@
/*     
 *      FILE
 *     	cfi
 *     
 *      DESCRIPTION
 *     	All planner routines that (directly) call C routines.
 *     
 *	$Header: /faerie/aoki/postgres/src/backend/planner/sys/RCS/cfi.c,v 1.17 1993/02/17 01:31:31 olson Exp aoki $
 *      EXPORTS
 *     		intermediate-rule-lock-data
 *     		intermediate-rule-lock
 *     		print-rule-lock-intermediate
 *     		rule-insert-catalog
 *     		relation-info
 *     		index-info
 *     		index-selectivity
 *     		restriction-selectivity
 *     		join-selectivity
 *     		find-inheritance-children
 *     		find-version-parents
 *     		function-index-info
 */

#include <stdio.h>

#include "tmp/c.h"
#include "nodes/pg_lisp.h"
#include "planner/internal.h"
#include "planner/plancat.h"

/*    
 *    	index-info
 *    
 *    	Retrieves catalog information on an index on a given relation.
 *    
 *    	The index relation is opened on the first invocation of
 *    	util/plancat.c:IndexCatalogInformation.  The current call retrieves
 *    	the next index relation within the catalog that has not already been
 *    	retrieved by a previous call.  The index catalog is closed by
 *    	IndexCatalogInformation when no more indices for 'relid' can be
 *    	found.
 *    
 *    	See util/plancat.c:IndexCatalogInformation for the format of 
 *    	'indexinfo'.
 *    
 *    	'not-first' is 0 if this is the first call 
 *    	'relid' is the OID of the relation for which indices are being located
 *    
 *    	Returns the list of index info.
 *    
 */

/*  .. find-secondary-index    */


List
index_info (not_first,relid)
     bool not_first;
     ObjectId  relid ;
{
    long indexinfo[32];
    int i = 0;
    LispValue ikey = LispNil;
    LispValue iord = LispNil;
    LispValue am_ops = LispNil;
    List returnList;
    
    /*    Retrieve information for a single index (if there is another one). */
    if(1 == IndexCatalogInformation (not_first,
				     CInteger(getrelid(relid,
						       _query_range_table_)),
				     _query_is_archival_,indexinfo)) {
	/*    First extract the index OID and the basic statistics (pages,
	 *     tuples, and indexrelid), then collect the index keys, operators,
	 *     and operator classes into lists.  Only include the 
	 *     actual keys in the list, i.e., no 0's.
	 */
	
	/*    Keys over which we're indexing: */
	
	for (i = _MAX_KEYS_+2 ; i > 2; --i ) 
	  ikey = lispCons(lispInteger(indexinfo[i]),ikey);
	
	/*    Operators used by the index (for ordering purposes): */
	
	for (i = _MAX_KEYS_+10 ; i > 10; --i ) 
	  iord = lispCons(lispInteger(indexinfo[i]),iord);
	
	/*    Classes of the AM operators used by index: */
	
	for (i = _MAX_KEYS_+18 ; i > 18; --i ) 
	  am_ops = lispCons(lispInteger(indexinfo[i]),am_ops);

	/*
	 * Cons up a list the old fashioned way -- with an intermediate
	 * variable.  I just could not get the old statement to stop screen
	 * wrapping and becoming unreadable.  -mer
	 */
	returnList = lispCons(indexinfo[28], LispNil); /* predicate */
	returnList = lispCons(lispInteger(indexinfo[27]), returnList);
	returnList = lispCons(am_ops, returnList);
	returnList = lispCons(iord, returnList);
	returnList = lispCons(ikey, returnList);
	returnList = lispCons(lispInteger(indexinfo[2]), returnList);
	returnList = lispCons(lispInteger(indexinfo[1]), returnList);
	returnList = lispCons(lispInteger(indexinfo[0]), returnList);

	return (returnList);
    }
    return(NULL);
}
	       
/*    
 *    	index-selectivity
 *    
 *    	Call util/plancat.c:IndexSelectivity with the indicated arguments.
 *    
 *    	'indid' is the index OID
 *    	'classes' is a list of index key classes
 *    	'opnos' is a list of index key operator OIDs
 *    	'relid' is the OID of the relation indexed
 *    	'attnos' is a list of the relation attnos which the index keys over
 *    	'values' is a list of the values of the clause's constants
 *    	'flags' is a list of fixnums which describe the constants
 *    	'nkeys' is the number of index keys
 *    
 *    	Returns a list of two floats: index pages and index selectivity.
 *    
 */

/*  .. best-or-subclause-index, create_index_path, index-innerjoin
 */
List
index_selectivity (indid,classes,opnos,relid,attnos,values,flags,nkeys)
     ObjectId 	indid,relid;
     List	attnos;
     List 	values;
     List	opnos;
     List	classes;
     List	flags;
     int32	nkeys ;
{
    int *class_array,*opno_array,*attno_array,*value_array,*flag_array;

    if (nkeys == length (opnos)  &&
       nkeys == length (attnos) &&
       nkeys == length (values) && 
       nkeys == length (flags)) {
	
	float param[2];
	int i = 0;
	LispValue xclass,xopno,xattno,value,flag;

	class_array = (int *)palloc(_MAX_KEYS_*sizeof(ObjectId));
	opno_array = (int *)palloc(nkeys*sizeof(ObjectId));
	attno_array = (int *)palloc(nkeys*sizeof(int32));
	value_array = (int *)palloc(nkeys*sizeof(char *));
	flag_array = (int *)palloc(nkeys*sizeof(int32));

	foreach(xclass,classes) {
	    class_array[i++] = CInteger(CAR(xclass));
	}
	i = 0;
	foreach(xopno,opnos) {
	    opno_array[i++] = LISPVALUE_INTEGER(xopno);
	}
	  i = 0;
	foreach(xattno,attnos) {
	    attno_array[i++] = CInteger(CAR(xattno));
	}
	i = 0;
	foreach(value,values) {
	    if (IsA(CAR(value),LispStr))
		value_array[i++] = (int)CString(CAR(value));
	    else
	        value_array[i++] = CInteger(CAR(value));
	}
	i = 0;
	foreach(flag,flags) {
	    flag_array[i++] = CInteger(CAR(flag));
	}

	IndexSelectivity (indid,relid,nkeys,
			  (ObjectId *)class_array,
			  (ObjectId *)opno_array,
			  attno_array,
			  (char **)value_array,
			  flag_array,
			  param);
	
	return (lispCons(lispFloat(param[0]),
			 lispCons(lispFloat(param[1]),LispNil)));
    } else 
      return(lispCons(lispFloat(0.0),
		      lispCons(lispFloat(1.0),LispNil)));
}

/*    
 *    	restriction-selectivity  
 *    
 *    	Returns the selectivity of an operator, given the restriction clause
 *    	information.
 *      The routine is now merged with 
 *      RestrictionClauseSelectivity as defined in plancat.c
 *
 *      This routine is called by comput_selec
 */

/*    
 *    	join-selectivity
 *    
 *    	Returns the selectivity of an operator, given the join clause
 *    	information.
 *
 *      Similarly, this routine is merged with JoinClauseSelectivity in
 *      plancat.c
 *      Routin is used in compute_selec.
 */


/*    
 *    	find-version-parents
 *    
 *    	Returns all relations that are base relations for the version relation
 *    	represented by 'relation-oid'.
 *    
 */

/*  .. plan-union-queries
 */
LispValue
find_version_parents (relation_oid)
     LispValue relation_oid ;
{
    return( VersionGetParents (relation_oid,
				    lispList()));
}

/*    
 *    	function-index-info		XXX FUNCS
 *    
 *    	Returns an integer iff 'function-oid' and 'index-oid' correspond
 *    	to a valid function-index mapping.
 *    
 */
#ifdef funcindex
/*  .. function-index-clause-p     */

int32
function_index_info (function_oid,index_oid)
     int32 function_oid,index_oid ;
{
     int32      info[4];
     if (!zerop (FunctionIndexInformation (index_oid,info)) && 
	 info[0] == function_oid)
       return(function_oid);

}
#endif
#ifndef funcindex

/*  .. function-index-clause-p    */

int32
function_index_info (function_oid,index_oid)
     int32 function_oid,index_oid ;
{
     return((int32)LispNil);
}
#endif
 
@


1.17
log
@support use of partial indexes
@
text
@d9 1
a9 1
 *	$Header: /private/src/postgres/src/backend/planner/sys/RCS/cfi.c,v 1.16 1991/11/18 17:29:14 mer Exp olson $
d62 1
a62 1
    int indexinfo[32];
d100 1
a100 1
	returnList = lispCons(indexinfo[28], LispNil);
@


1.16
log
@prototype changes (the last?)
@
text
@d9 1
a9 1
 *	$Header: /users/mer/postgres/src/planner/sys/RCS/cfi.c,v 1.15 1991/11/07 01:34:10 hong Exp mer $
d100 2
a101 1
	returnList = lispCons(lispInteger(indexinfo[27]), LispNil);
@


1.15
log
@fixed a satanic bug that corrupts portal heap memory queue
and cause large leaks.
also fixed a bug that misconstructs am_ops for index
@
text
@d9 1
a9 1
 *	$Header: RCS/cfi.c,v 1.14 91/10/16 23:08:49 mer Exp $
d184 2
a185 2
			  class_array,
			  opno_array,
d187 1
a187 1
			  value_array,
@


1.14
log
@add support for functional indices and cleaned the affected routine
@
text
@d9 1
a9 1
 *	$Header: /users/mer/postgres/src/planner/sys/RCS/cfi.c,v 1.13 1991/05/23 18:33:40 kemnitz Exp mer $
d93 1
a93 1
	  am_ops = lispCons(lispInteger(indexinfo[i]),iord);
d154 1
a154 1
	class_array = (int *)palloc(nkeys*sizeof(ObjectId));
@


1.13
log
@got rid of lint warning "has return(e); and return;"
@
text
@d9 1
a9 1
 *	$Header: RCS/cfi.c,v 1.12 90/09/25 16:37:34 kemnitz Exp Locker: kemnitz $
d67 1
d94 15
a108 10
	
	return(lispCons (lispInteger(indexinfo[0]),
			 lispCons(lispInteger(indexinfo[1]),
				  lispCons(lispInteger(indexinfo[2]),
					   lispCons(ikey,
						    lispCons(iord,
							     lispCons
							     (am_ops,
							      LispNil)
							     ))))));
@


1.12
log
@Updating from revision 1.11 to revision 1.12
@
text
@d9 1
a9 1
 *	$Header: RCS/cfi.c,v 1.12 90/08/14 12:14:04 cimarron Exp $
d104 1
@


1.11
log
@fix for index join
@
text
@d9 1
a9 1
 *	$Header: RCS/cfi.c,v 1.10 90/05/25 14:09:08 mao Exp Locker: hong $
d26 3
a28 1
#include "pg_lisp.h"
a29 1
#include "c.h"
a30 1

@


1.10
log
@func that computes index selectivity now works.
@
text
@d9 1
a9 1
 *	$Header: RCS/cfi.c,v 1.9 90/01/30 23:32:59 sp Exp Locker: mao $
d127 1
a127 1
index_selectivity (indid,classes,opnos,relid,flags,attnos,values,nkeys)
d166 4
a169 1
	    value_array[i++] = CInteger(CAR(value));
@


1.9
log
@removed some obsolete old rule system routines...
@
text
@d9 1
a9 1
 *	$Header: RCS/cfi.c,v 1.8 89/09/05 17:18:40 mao C_Demo_1 Locker: ong $
d127 1
a127 1
index_selectivity (indid,classes,opnos,relid,attnos,values,flags,nkeys)
d137 2
a138 2
    if(nkeys == length (classes) &&
       nkeys == length (opnos)  &&
d158 1
a158 1
	    opno_array[i++] = CInteger(CAR(xopno));
d172 1
a172 1
	
@


1.8
log
@Working version of C-only demo
@
text
@d9 1
a9 1
 *	$Header: RCS/cfi.c,v 1.7 89/08/23 16:05:33 ong Exp Locker: ong $
a30 49

/*    
 *    	intermediate-rule-lock-data
 *    	intermediate-rule-lock
 *    	print-rule-lock-intermediate
 *    	rule-insert-catalog
 *    
 *    	Return pointers to malloc'd copies of the appropriate rule lock
 *    	structures.
 *    
 */

/*  .. exec-make-intermediate-locks, make-rule-locks     */

LispValue
intermediate_rule_lock_data (type,attribute,plan)
     LispValue type,attribute,plan ;
{
    MakeRuleLockIntermediateLock (type,attribute,plan);
}

/*  .. exec-make-intermediate-locks, make-rule-locks
 */
LispValue
intermediate_rule_lock (rule_id,priority,type,is_early,
			rule_lock_intermediate_data_list)
     LispValue rule_id,priority,type,is_early,
     rule_lock_intermediate_data_list ;
{
    MakeRuleLockIntermediate (rule_id,priority,type,is_early,
			      rule_lock_intermediate_data_list);
}

/*  .. print_rtentries
 */
LispValue
print_rule_lock_intermediate (rule_lock_intermediate)
     LispValue rule_lock_intermediate ;
{
     RuleLockIntermediateDump (rule_lock_intermediate);
}

/*  .. make-rule-locks
 */
LispValue
rule_insert_catalog ()
{
    RuleInsertCatalog ();
}
@


1.7
log
@planner supports all but rules and mergesort
@
text
@d9 1
a9 1
 *	$Header: /n/postgres/a/postgres/ong/postgres/src/planner/sys/RCS/cfi.c,v 1.6 89/08/04 14:26:32 goh Exp $
@


1.6
log
@reorganised header files
@
text
@d9 1
a9 1
 *	$Header: cfi.c,v 1.5 89/08/04 13:30:44 goh Locked $
d109 1
a109 1
     int  relid ;
d112 5
a116 2
    int i;
    LispValue ikey, iord, am_ops;
d119 2
a120 1
				     getrelid (relid,_query_range_table_),
d130 1
a130 1
	for (i = _MAX_KEYS_+3 ; i > 2; --i ) 
d135 1
a135 1
	for (i = _MAX_KEYS_+18 ; i > 10; --i ) 
d140 1
a140 1
	for (i = _MAX_KEYS_+25 ; i > 18; --i ) 
d144 8
a151 5
		 lispCons(lispInteger(indexinfo[1]),
		  lispCons(lispInteger(indexinfo[2]),
		   lispCons(lispInteger(indexinfo[3]),
		    lispCons(ikey,lispCons(iord,lispCons(am_ops,LispNil)
					   )))))));
d177 6
a182 4
     ObjectId 	indid, classes,opnos,relid;
     int32	attnos[];
     char 	*values[];
     int32	flags;
d185 10
a194 5
     if(nkeys == length (classes) &&
	nkeys == length (opnos)  &&
	nkeys == length (attnos) &&
	nkeys == length (values) && 
	nkeys == length (flags)) {
d196 5
a200 1
	  float param[2];
d202 33
a234 8
	  IndexSelectivity (indid,relid,nkeys,
			    classes,opnos,attnos,values,flags,param);
	  
	  return (lispCons(lispFloat(param[0]),
			   lispCons(lispFloat(param[1]),LispNil)));
     } else 
       return(lispCons(lispFloat(0.0),
		       lispCons(lispFloat(1.0),LispNil)));
a260 19
 *    	find-inheritance-children
 *    
 *    	Returns all relations that directly inherit from the relation
 *    	represented by 'relation-oid'.
 *
 *      Maybe we can merge the 2 functions    
 */

/*  .. find-all-inheritors     */

LispValue
find_inheritance_children (relation_oid)
     LispValue relation_oid ;
{
    return( CAR (InheritanceGetChildren (relation_oid,
					 lispList())));
}

/*    
d274 2
a275 2
    return( CAR (VersionGetParents (relation_oid,
				    lispList())));
@


1.5
log
@checkin for retrieve (x.all)
@
text
@d9 1
a9 1
 *	$Header: cfi.c,v 1.4 89/08/01 14:41:10 goh Locked $
d27 1
a27 1
#include "internal.h"
d29 1
a29 1
#include "plancat.h"
@


1.4
log
@retrieve (x=1) checkin
@
text
@d9 1
a9 1
 *	$Header: cfi.c,v 1.2 89/07/24 10:38:18 ong Exp $
d109 1
a109 1
     ObjectId relid ;
@


1.3
log
@phase 2/3 checkin
@
text
@d25 1
d123 1
a123 1
	 
d125 2
a126 2

	 for (i = _MAX_KEYS_+3 ; i > 2; --i ) 
d128 1
a128 1

d130 1
a130 1

d133 1
a133 1

d135 1
a135 1

d138 7
a144 5

	return(list (lispInteger(indexinfo[0]),
		     lispInteger(indexinfo[1]),
		     lispInteger(indexinfo[2]),
		     lispInteger(indexinfo[3]),ikey,iord,am_ops));
d232 2
a233 2
     CAR (InheritanceGetChildren (relation_oid,
				  list (LispNil)));
d250 2
a251 2
     CAR (VersionGetParents (relation_oid,
			     list (LispNil)));
@


1.2
log
@Phase II.
NOTE:  some of the routines have been merged with those in 
plancat.c .  There are still some routines the seem to be 
mergeable.
@
text
@d9 1
a9 1
 *	$Header: cfi.c,v 1.1 89/07/24 08:49:41 ong Locked $
d184 2
a185 2
	  return (list(lispDouble(param[0]),
		       lispDouble(param[1])));
d187 2
a188 2
       return(lispCons(lispDouble(0.0),
		       lispCons(lispDouble(1.0))));
@


1.1
log
@Initial revision
@
text
@d9 1
a9 1
 *	$Header:$
d24 2
d28 1
a28 1
#include "pg_lisp.h"
d42 2
a43 2
/*  .. exec-make-intermediate-locks, make-rule-locks
 */
d67 1
a67 1
LispValue rule_lock_intermediate ;
d69 1
a69 1
    RuleLockIntermediateDump (rule_lock_intermediate);
d102 1
a102 2
/*  .. find-secondary-index
 */
d104 1
d111 2
d118 5
a122 5
	      tuples, and indexrelid), then collect the index keys, operators,
	      and operator classes into lists.  Only include the 
	      actual keys in the list, i.e., no 0's.
	      */

d125 1
a125 1
	for (i = _MAX_KEYS_+3 ; i > 2; --i ) 
d136 1
a136 1
	  iord = lispCons(lispInteger(indexinfo[i]),iord);
d168 1
a168 1
     int 32	attnos[];
d173 5
a177 5
    if(nkeys == length (classes) &&
       nkeys == length (opnos)  &&
       nkeys == length (attnos) &&
       nkeys == length (values) && 
       nkeys == length (flags)) {
d179 1
a179 1
	float param[2];
d181 8
a188 8
	IndexSelectivity (indid,relid,nkeys,
			  classes,opnos,attnos,values,flags,param);

	return (list(lispDouble(param[0]),
		     lispDouble(param[1]));
    } else 
      return(lispCons(lispDouble(0.0),
		      lispCons(lispDouble(1.0))));
d192 1
a192 1
 *    	restriction-selectivity
d196 4
a199 1
 *    
a201 9
/*  .. compute_selec
 */
LispValue
restriction_selectivity (oprrest,operator,relation,attribute_number,value,flags)
LispValue oprrest,operator,relation,attribute_number,value,flags ;
{
RestrictionClauseSelectivity (oprrest,operator,relation,attribute_number,value,flags);
}

d207 4
a210 1
 *    
a212 8
/*  .. compute_selec
 */
LispValue
join_selectivity (oprjoin,operator,relation1,attribute_number1,relation2,attribute_number2)
LispValue oprjoin,operator,relation1,attribute_number1,relation2,attribute_number2 ;
{
JoinClauseSelectivity (oprjoin,operator,relation1,attribute_number1,relation2,attribute_number2);
}
d219 2
a220 1
 *    
d223 2
a224 2
/*  .. find-all-inheritors
 */
d227 1
a227 1
LispValue relation_oid ;
d229 2
a230 1
car (InheritanceGetChildren (relation_oid,list (nil)));
d245 1
a245 1
LispValue relation_oid ;
d247 2
a248 1
car (VersionGetParents (relation_oid,list (nil)));
d258 2
a259 2
#ifdef 
funcindex;
d261 1
a261 6
#endif
;

/*  .. function-index-clause-p
 */
LispValue
d263 1
a263 1
LispValue function_oid,index_oid ;
d265 5
a269 4
/* XXX - let form, maybe incorrect */
LispValue info = new_vectori_long (4);
and (not (zerop (FunctionIndexInformation (index_oid,info))),vrefi_long (info,0) == function_oid);
;
a270 3
#ifndef 
funcindex;

d272 1
a272 1
;
d274 3
a276 3
/*  .. function-index-clause-p
 */
LispValue
d278 1
a278 1
LispValue function_oid,index_oid ;
d280 1
a280 1
nil;
d282 2
@
