home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / planner / prep / archive.c next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  1.6 KB  |  75 lines

  1. /*
  2.  * $Header: /private/postgres/src/planner/prep/RCS/archive.c,v 1.4 1991/11/18 17:29:14 mer Exp $
  3.  *
  4.  *  archive.c -- Support for planning scans on archived relations
  5.  */
  6. #include <sys/types.h>        /* for u_int in relcache.h */
  7.  
  8. #include "tmp/c.h"
  9. #include "utils/rel.h"
  10. #include "utils/log.h"
  11. #include "utils/relcache.h"
  12. #include "catalog/pg_relation.h"
  13. #include "nodes/pg_lisp.h"
  14. #include "parser/parsetree.h"
  15.  
  16. void
  17. plan_archive(rt)
  18.     List rt;
  19. {
  20.     LispValue rtitem;
  21.     LispValue rte;
  22.     LispValue trange;
  23.     ObjectId reloid;
  24.     Relation r;
  25.  
  26.     foreach(rtitem, rt) {
  27.         rte = CAR(rtitem);
  28.         trange = rt_time(rte);
  29.         if (CAR(trange) != LispNil) {
  30.             reloid = CInteger(rt_relid(rte));
  31.             r = RelationIdGetRelation(reloid);
  32.             if (r->rd_rel->relarch != 'n') {
  33.                 rt_flags(rte) = lispCons(lispAtom("archive"),
  34.                              rt_flags(rte));
  35.             }
  36.         }
  37.     }
  38. }
  39.  
  40. /*
  41.  *  find_archive_rels -- Given a particular relid, find the archive
  42.  *             relation's relid.
  43.  */
  44.  
  45. LispValue
  46. find_archive_rels(relid)
  47.     LispValue relid;
  48. {
  49.     ObjectId roid;
  50.     Relation arel;
  51.     LispValue arelid;
  52.     Name arelname;
  53.  
  54.     /*
  55.      *  Archive relations are named a,XXXXX where XXXXX == the OID
  56.      *  of the relation they archive.  Create a string containing
  57.      *  this name and find the reldesc for the archive relation.
  58.      */
  59.  
  60.     roid = CInteger(relid);
  61.     arelname = (Name) palloc(sizeof(NameData));
  62.     sprintf(&arelname->data[0], "a,%ld", roid);
  63.     arel = RelationNameGetRelation(arelname);
  64.     pfree(arelname);
  65.  
  66.     /* got it, now build a LispValue to return */
  67.     arelid = lispList();
  68.     CAR(arelid) = lispInteger(arel->rd_id);
  69.     CDR(arelid) = lispList();
  70.     CAR(CDR(arelid)) = lispInteger(roid);
  71.     CDR(CDR(arelid)) = LispNil;
  72.  
  73.     return (arelid);
  74. }
  75.