]> granicus.if.org Git - postgresql/commitdiff
Hello,
authorBruce Momjian <bruce@momjian.us>
Sun, 8 Oct 2000 03:18:57 +0000 (03:18 +0000)
committerBruce Momjian <bruce@momjian.us>
Sun, 8 Oct 2000 03:18:57 +0000 (03:18 +0000)
this is patch v 0.4 to support transactions with BLOBs.
All BLOBs are in one table. You need to make initdb.

--
Sincerely Yours,
Denis Perchine

src/backend/catalog/Makefile
src/backend/catalog/indexing.c
src/backend/catalog/pg_largeobject.c [new file with mode: 0644]
src/backend/libpq/be-fsstubs.c
src/backend/storage/large_object/inv_api.c
src/include/catalog/catname.h
src/include/catalog/indexing.h
src/include/catalog/pg_largeobject.h [new file with mode: 0644]
src/include/storage/large_object.h

index 4a1aa665a8c93a5344fd62967163456fcd5f0316..0ba3e9459a1a3daaa46e8aaa13a7804edaeb7f8b 100644 (file)
@@ -2,7 +2,7 @@
 #
 # Makefile for catalog
 #
-# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.25 2000/09/17 13:02:30 petere Exp $
+# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.26 2000/10/08 03:18:53 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -11,7 +11,8 @@ top_builddir = ../../..
 include $(top_builddir)/src/Makefile.global
 
 OBJS = catalog.o heap.o index.o indexing.o aclchk.o \
-       pg_aggregate.o pg_operator.o pg_proc.o pg_type.o
+       pg_aggregate.o pg_largeobject.o pg_operator.o pg_proc.o \
+       pg_type.o
 
 BKIFILES = global.bki template1.bki global.description template1.description
 
index c2980f6fefc10b831206a8b18bc8d90985ec0e3b..4c9a61ffbe95601533f0703b7f01174ff66d45c0 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.67 2000/07/14 22:17:41 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.68 2000/10/08 03:18:53 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -51,6 +51,8 @@ char     *Name_pg_inherits_indices[Num_pg_inherits_indices] =
 {InheritsRelidSeqnoIndex};
 char      *Name_pg_language_indices[Num_pg_language_indices] =
 {LanguageOidIndex, LanguageNameIndex};
+char      *Name_pg_largeobject_indices[Num_pg_largeobject_indices] =
+{LargeobjectLOIdIndex, LargeobjectLOIdPNIndex};
 char      *Name_pg_listener_indices[Num_pg_listener_indices] =
 {ListenerPidRelnameIndex};
 char      *Name_pg_opclass_indices[Num_pg_opclass_indices] =
diff --git a/src/backend/catalog/pg_largeobject.c b/src/backend/catalog/pg_largeobject.c
new file mode 100644 (file)
index 0000000..74bcfe0
--- /dev/null
@@ -0,0 +1,138 @@
+/*-------------------------------------------------------------------------
+ *
+ * pg_largeobject.c
+ *       routines to support manipulation of the pg_largeobject relation
+ *
+ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ *       $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.1 2000/10/08 03:18:53 momjian Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#include "postgres.h"
+
+#include "access/genam.h"
+#include "access/heapam.h"
+#include "access/itup.h"
+#include "catalog/catname.h"
+#include "catalog/indexing.h"
+#include "catalog/pg_largeobject.h"
+#include "miscadmin.h"
+#include "parser/parse_func.h"
+#include "utils/builtins.h"
+#include "utils/syscache.h"
+
+bytea *_byteain(const char *data, int32 size);
+
+bytea *_byteain(const char *data, int32 size) {
+       bytea   *result;
+
+       result = (bytea *)palloc(size + VARHDRSZ);
+       result->vl_len = size + VARHDRSZ;
+       if (size > 0)
+               memcpy(result->vl_dat, data, size);
+       
+       return result;
+}
+
+Oid LargeobjectCreate(Oid loid) {
+       Oid             retval;
+       Relation                pg_largeobject;
+       HeapTuple       ntup = (HeapTuple) palloc(sizeof(HeapTupleData));
+       Relation                idescs[Num_pg_largeobject_indices];
+       Datum           values[Natts_pg_largeobject];
+       char            nulls[Natts_pg_largeobject];
+       int             i;
+
+       for (i=0; i<Natts_pg_largeobject; i++) {
+               nulls[i] = ' ';
+               values[i] = (Datum)NULL;
+       }
+
+       i = 0;
+       values[i++] = ObjectIdGetDatum(loid);
+       values[i++] = Int32GetDatum(0);
+       values[i++] = (Datum) _byteain(NULL, 0);
+       
+       pg_largeobject = heap_openr(LargeobjectRelationName, RowExclusiveLock);
+       ntup = heap_formtuple(pg_largeobject->rd_att, values, nulls);
+       retval = heap_insert(pg_largeobject, ntup);
+
+       if (!IsIgnoringSystemIndexes()) {
+               CatalogOpenIndices(Num_pg_largeobject_indices, Name_pg_largeobject_indices, idescs);
+               CatalogIndexInsert(idescs, Num_pg_largeobject_indices, pg_largeobject, ntup);
+               CatalogCloseIndices(Num_pg_largeobject_indices, idescs);
+       }
+       
+       heap_close(pg_largeobject, RowExclusiveLock);
+       heap_freetuple(ntup);
+       
+       CommandCounterIncrement();
+
+       return retval;
+}
+
+void LargeobjectDrop(Oid loid) {
+       Relation        pg_largeobject;
+       Relation        pg_lo_id;
+       ScanKeyData     skey;
+       IndexScanDesc   sd = (IndexScanDesc) NULL;
+       RetrieveIndexResult     indexRes;
+       int     found = 0;
+
+       ScanKeyEntryInitialize(&skey,
+                                           (bits16) 0x0,
+                                           (AttrNumber) 1,
+                                           (RegProcedure) F_OIDEQ,
+                                           ObjectIdGetDatum(loid));
+
+       pg_largeobject = heap_openr(LargeobjectRelationName, RowShareLock);
+       pg_lo_id = index_openr(LargeobjectLOIdIndex);
+
+       sd = index_beginscan(pg_lo_id, false, 1, &skey);
+
+       while((indexRes = index_getnext(sd, ForwardScanDirection))) {
+               found++;
+               heap_delete(pg_largeobject, &indexRes->heap_iptr, NULL);
+               pfree(indexRes);
+       }
+
+       index_endscan(sd);
+
+       index_close(pg_lo_id);
+       heap_close(pg_largeobject, RowShareLock);
+       if (found == 0)
+               elog(ERROR, "LargeobjectDrop: large object %d not found", loid);
+}
+
+int LargeobjectFind(Oid loid) {
+       int     retval = 0;
+       Relation        pg_lo_id;
+       ScanKeyData     skey;
+       IndexScanDesc   sd = (IndexScanDesc) NULL;
+       RetrieveIndexResult     indexRes;
+
+       ScanKeyEntryInitialize(&skey,
+                                           (bits16) 0x0,
+                                           (AttrNumber) 1,
+                                           (RegProcedure) F_OIDEQ,
+                                           ObjectIdGetDatum(loid));
+
+       pg_lo_id = index_openr(LargeobjectLOIdIndex);
+
+       sd = index_beginscan(pg_lo_id, false, 1, &skey);
+
+       if ((indexRes = index_getnext(sd, ForwardScanDirection))) {
+               retval = 1;
+               pfree(indexRes);
+       }
+
+       index_endscan(sd);
+
+       index_close(pg_lo_id);
+       return retval;
+}
+
index 8d3af03664516475ed32c64723a4f1243423b60f..e2b24d78f9a32eee3de0e6bbe97340d6e66eee28 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.50 2000/07/17 03:04:54 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.51 2000/10/08 03:18:54 momjian Exp $
  *
  * NOTES
  *       This should be moved to a more appropriate place.  It is here
@@ -267,7 +267,7 @@ lo_creat(PG_FUNCTION_ARGS)
                PG_RETURN_OID(InvalidOid);
        }
 
-       lobjId = RelationGetRelid(lobjDesc->heap_r);
+       lobjId = lobjDesc->id;
 
        inv_close(lobjDesc);
 
@@ -512,8 +512,10 @@ lo_commit(bool isCommit)
        {
                if (cookies[i] != NULL)
                {
+/*
                        if (isCommit)
                                inv_cleanindex(cookies[i]);
+*/
                        cookies[i] = NULL;
                }
        }
index d8abfb4a2b7a23905b42f0d39f78a8091ab92270..54b5cf16325a2583be998266eb4d1f70fa92ced8 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.74 2000/07/14 22:17:48 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.75 2000/10/08 03:18:54 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -261,15 +261,11 @@ inv_close(LargeObjectDesc *obj_desc)
 {
        Assert(PointerIsValid(obj_desc));
 
-       if (obj_desc->iscan != (IndexScanDesc) NULL)
-       {
-               index_endscan(obj_desc->iscan);
-               obj_desc->iscan = NULL;
-       }
-
+       if (obj_desc->flags & IFS_WRLOCK)
+               heap_close(obj_desc->heap_r, RowExclusiveLock);
+       else if (obj_desc->flags & IFS_RDLOCK)
+               heap_close(obj_desc->heap_r, AccessShareLock);
        index_close(obj_desc->index_r);
-       heap_close(obj_desc->heap_r, AccessShareLock);
-
        pfree(obj_desc);
 }
 
index 368a05e474b9fb9f2daec796d72cfecd5af1b8d3..9829682be55b79b71e65ec59b0d55a233b22f80b 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: catname.h,v 1.12 2000/01/26 05:57:56 momjian Exp $
+ * $Id: catname.h,v 1.13 2000/10/08 03:18:55 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -29,6 +29,7 @@
 #define  InheritsRelationName "pg_inherits"
 #define  InheritancePrecidenceListRelationName "pg_ipl"
 #define  LanguageRelationName "pg_language"
+#define  LargeobjectRelationName "pg_largeobject"
 #define  ListenerRelationName "pg_listener"
 #define  LogRelationName "pg_log"
 #define  OperatorClassRelationName "pg_opclass"
index dfb05051cae58d4872234a52b27cb82a49fdcf76..8e42356d7a74d7318fdeb0eb093fa1b45c4a7c54 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: indexing.h,v 1.40 2000/06/17 04:56:30 tgl Exp $
+ * $Id: indexing.h,v 1.41 2000/10/08 03:18:55 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -31,6 +31,7 @@
 #define Num_pg_index_indices           2
 #define Num_pg_inherits_indices                1
 #define Num_pg_language_indices                2
+#define Num_pg_largeobject_indices             2
 #define Num_pg_listener_indices                1
 #define Num_pg_opclass_indices         2
 #define Num_pg_operator_indices                2
@@ -92,6 +93,7 @@ extern char *Name_pg_group_indices[];
 extern char *Name_pg_index_indices[];
 extern char *Name_pg_inherits_indices[];
 extern char *Name_pg_language_indices[];
+extern char *Name_pg_largeobject_indices[];
 extern char *Name_pg_listener_indices[];
 extern char *Name_pg_opclass_indices[];
 extern char *Name_pg_operator_indices[];
diff --git a/src/include/catalog/pg_largeobject.h b/src/include/catalog/pg_largeobject.h
new file mode 100644 (file)
index 0000000..f8f6509
--- /dev/null
@@ -0,0 +1,63 @@
+/*-------------------------------------------------------------------------
+ *
+ * pg_largeobject.h
+ *       definition of the system "largeobject" relation (pg_largeobject)
+ *       along with the relation's initial contents.
+ *
+ *
+ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * $Id: pg_largeobject.h,v 1.1 2000/10/08 03:18:56 momjian Exp $
+ *
+ * NOTES
+ *       the genbki.sh script reads this file and generates .bki
+ *       information from the DATA() statements.
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef PG_LARGEOBJECT_H
+#define PG_LARGEOBJECT_H
+
+/* ----------------
+ *             postgres.h contains the system type definintions and the
+ *             CATALOG(), BOOTSTRAP and DATA() sugar words so this file
+ *             can be read by both genbki.sh and the C compiler.
+ * ----------------
+ */
+
+/* ----------------
+ *             pg_largeobject definition.  cpp turns this into
+ *             typedef struct FormData_pg_largeobject. Large object id
+ *             is stored in loid;
+ * ----------------
+ */
+
+CATALOG(pg_largeobject)
+{
+       Oid                     loid;
+       int4                    pageno;
+       bytea                   data;
+} FormData_pg_largeobject;
+
+/* ----------------
+ *             Form_pg_largeobject corresponds to a pointer to a tuple with
+ *             the format of pg_largeobject relation.
+ * ----------------
+ */
+typedef FormData_pg_largeobject *Form_pg_largeobject;
+
+/* ----------------
+ *             compiler constants for pg_largeobject
+ * ----------------
+ */
+#define Natts_pg_largeobject                   3
+#define Anum_pg_largeobject_loid               1
+#define Anum_pg_largeobject_pageno             2
+#define Anum_pg_largeobject_data               3
+
+Oid LargeobjectCreate(Oid loid);
+void LargeobjectDrop(Oid loid);
+int LargeobjectFind(Oid loid);
+
+#endif  /* PG_LARGEOBJECT_H */
index 4aa151844c8c2f8274033d6b6cfe5ba3b9225aac..1157c5dc02e23749aab263660360a5718cd72718 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: large_object.h,v 1.13 2000/01/26 05:58:33 momjian Exp $
+ * $Id: large_object.h,v 1.14 2000/10/08 03:18:57 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
 /*
  * This structure will eventually have lots more stuff associated with it.
  */
-typedef struct LargeObjectDesc
-{
-       Relation        heap_r;                 /* heap relation */
-       Relation        index_r;                /* index relation on seqno attribute */
-       IndexScanDesc iscan;            /* index scan we're using */
-       TupleDesc       hdesc;                  /* heap relation tuple desc */
-       TupleDesc       idesc;                  /* index relation tuple desc */
-       uint32          lowbyte;                /* low byte on the current page */
-       uint32          highbyte;               /* high byte on the current page */
+typedef struct LargeObjectDesc {
+       Relation        heap_r;
+       Relation        index_r;
        uint32          offset;                 /* current seek pointer */
-       ItemPointerData htid;           /* tid of current heap tuple */
+       Oid             id;
 
 #define IFS_RDLOCK             (1 << 0)
 #define IFS_WRLOCK             (1 << 1)
@@ -55,7 +49,4 @@ extern int    inv_tell(LargeObjectDesc *obj_desc);
 extern int     inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes);
 extern int     inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes);
 
-/* added for buffer leak prevention [ PA ] */
-extern void inv_cleanindex(LargeObjectDesc *obj_desc);
-
 #endif  /* LARGE_OBJECT_H */