Skip to content

Commit cf5a950

Browse files
committed
Hello,
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
1 parent d8e582e commit cf5a950

File tree

9 files changed

+226
-30
lines changed

9 files changed

+226
-30
lines changed

src/backend/catalog/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Makefile for catalog
44
#
5-
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.25 2000/09/17 13:02:30 petere Exp $
5+
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.26 2000/10/08 03:18:53 momjian Exp $
66
#
77
#-------------------------------------------------------------------------
88

@@ -11,7 +11,8 @@ top_builddir = ../../..
1111
include $(top_builddir)/src/Makefile.global
1212

1313
OBJS = catalog.o heap.o index.o indexing.o aclchk.o \
14-
pg_aggregate.o pg_operator.o pg_proc.o pg_type.o
14+
pg_aggregate.o pg_largeobject.o pg_operator.o pg_proc.o \
15+
pg_type.o
1516

1617
BKIFILES = global.bki template1.bki global.description template1.description
1718

src/backend/catalog/indexing.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.67 2000/07/14 22:17:41 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.68 2000/10/08 03:18:53 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -51,6 +51,8 @@ char *Name_pg_inherits_indices[Num_pg_inherits_indices] =
5151
{InheritsRelidSeqnoIndex};
5252
char *Name_pg_language_indices[Num_pg_language_indices] =
5353
{LanguageOidIndex, LanguageNameIndex};
54+
char *Name_pg_largeobject_indices[Num_pg_largeobject_indices] =
55+
{LargeobjectLOIdIndex, LargeobjectLOIdPNIndex};
5456
char *Name_pg_listener_indices[Num_pg_listener_indices] =
5557
{ListenerPidRelnameIndex};
5658
char *Name_pg_opclass_indices[Num_pg_opclass_indices] =

src/backend/catalog/pg_largeobject.c

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* pg_largeobject.c
4+
* routines to support manipulation of the pg_largeobject relation
5+
*
6+
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
*
10+
* IDENTIFICATION
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.1 2000/10/08 03:18:53 momjian Exp $
12+
*
13+
*-------------------------------------------------------------------------
14+
*/
15+
#include "postgres.h"
16+
17+
#include "access/genam.h"
18+
#include "access/heapam.h"
19+
#include "access/itup.h"
20+
#include "catalog/catname.h"
21+
#include "catalog/indexing.h"
22+
#include "catalog/pg_largeobject.h"
23+
#include "miscadmin.h"
24+
#include "parser/parse_func.h"
25+
#include "utils/builtins.h"
26+
#include "utils/syscache.h"
27+
28+
bytea *_byteain(const char *data, int32 size);
29+
30+
bytea *_byteain(const char *data, int32 size) {
31+
bytea *result;
32+
33+
result = (bytea *)palloc(size + VARHDRSZ);
34+
result->vl_len = size + VARHDRSZ;
35+
if (size > 0)
36+
memcpy(result->vl_dat, data, size);
37+
38+
return result;
39+
}
40+
41+
Oid LargeobjectCreate(Oid loid) {
42+
Oid retval;
43+
Relation pg_largeobject;
44+
HeapTuple ntup = (HeapTuple) palloc(sizeof(HeapTupleData));
45+
Relation idescs[Num_pg_largeobject_indices];
46+
Datum values[Natts_pg_largeobject];
47+
char nulls[Natts_pg_largeobject];
48+
int i;
49+
50+
for (i=0; i<Natts_pg_largeobject; i++) {
51+
nulls[i] = ' ';
52+
values[i] = (Datum)NULL;
53+
}
54+
55+
i = 0;
56+
values[i++] = ObjectIdGetDatum(loid);
57+
values[i++] = Int32GetDatum(0);
58+
values[i++] = (Datum) _byteain(NULL, 0);
59+
60+
pg_largeobject = heap_openr(LargeobjectRelationName, RowExclusiveLock);
61+
ntup = heap_formtuple(pg_largeobject->rd_att, values, nulls);
62+
retval = heap_insert(pg_largeobject, ntup);
63+
64+
if (!IsIgnoringSystemIndexes()) {
65+
CatalogOpenIndices(Num_pg_largeobject_indices, Name_pg_largeobject_indices, idescs);
66+
CatalogIndexInsert(idescs, Num_pg_largeobject_indices, pg_largeobject, ntup);
67+
CatalogCloseIndices(Num_pg_largeobject_indices, idescs);
68+
}
69+
70+
heap_close(pg_largeobject, RowExclusiveLock);
71+
heap_freetuple(ntup);
72+
73+
CommandCounterIncrement();
74+
75+
return retval;
76+
}
77+
78+
void LargeobjectDrop(Oid loid) {
79+
Relation pg_largeobject;
80+
Relation pg_lo_id;
81+
ScanKeyData skey;
82+
IndexScanDesc sd = (IndexScanDesc) NULL;
83+
RetrieveIndexResult indexRes;
84+
int found = 0;
85+
86+
ScanKeyEntryInitialize(&skey,
87+
(bits16) 0x0,
88+
(AttrNumber) 1,
89+
(RegProcedure) F_OIDEQ,
90+
ObjectIdGetDatum(loid));
91+
92+
pg_largeobject = heap_openr(LargeobjectRelationName, RowShareLock);
93+
pg_lo_id = index_openr(LargeobjectLOIdIndex);
94+
95+
sd = index_beginscan(pg_lo_id, false, 1, &skey);
96+
97+
while((indexRes = index_getnext(sd, ForwardScanDirection))) {
98+
found++;
99+
heap_delete(pg_largeobject, &indexRes->heap_iptr, NULL);
100+
pfree(indexRes);
101+
}
102+
103+
index_endscan(sd);
104+
105+
index_close(pg_lo_id);
106+
heap_close(pg_largeobject, RowShareLock);
107+
if (found == 0)
108+
elog(ERROR, "LargeobjectDrop: large object %d not found", loid);
109+
}
110+
111+
int LargeobjectFind(Oid loid) {
112+
int retval = 0;
113+
Relation pg_lo_id;
114+
ScanKeyData skey;
115+
IndexScanDesc sd = (IndexScanDesc) NULL;
116+
RetrieveIndexResult indexRes;
117+
118+
ScanKeyEntryInitialize(&skey,
119+
(bits16) 0x0,
120+
(AttrNumber) 1,
121+
(RegProcedure) F_OIDEQ,
122+
ObjectIdGetDatum(loid));
123+
124+
pg_lo_id = index_openr(LargeobjectLOIdIndex);
125+
126+
sd = index_beginscan(pg_lo_id, false, 1, &skey);
127+
128+
if ((indexRes = index_getnext(sd, ForwardScanDirection))) {
129+
retval = 1;
130+
pfree(indexRes);
131+
}
132+
133+
index_endscan(sd);
134+
135+
index_close(pg_lo_id);
136+
return retval;
137+
}
138+

src/backend/libpq/be-fsstubs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.50 2000/07/17 03:04:54 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.51 2000/10/08 03:18:54 momjian Exp $
1212
*
1313
* NOTES
1414
* This should be moved to a more appropriate place. It is here
@@ -267,7 +267,7 @@ lo_creat(PG_FUNCTION_ARGS)
267267
PG_RETURN_OID(InvalidOid);
268268
}
269269

270-
lobjId = RelationGetRelid(lobjDesc->heap_r);
270+
lobjId = lobjDesc->id;
271271

272272
inv_close(lobjDesc);
273273

@@ -512,8 +512,10 @@ lo_commit(bool isCommit)
512512
{
513513
if (cookies[i] != NULL)
514514
{
515+
/*
515516
if (isCommit)
516517
inv_cleanindex(cookies[i]);
518+
*/
517519
cookies[i] = NULL;
518520
}
519521
}

src/backend/storage/large_object/inv_api.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.74 2000/07/14 22:17:48 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.75 2000/10/08 03:18:54 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -261,15 +261,11 @@ inv_close(LargeObjectDesc *obj_desc)
261261
{
262262
Assert(PointerIsValid(obj_desc));
263263

264-
if (obj_desc->iscan != (IndexScanDesc) NULL)
265-
{
266-
index_endscan(obj_desc->iscan);
267-
obj_desc->iscan = NULL;
268-
}
269-
264+
if (obj_desc->flags & IFS_WRLOCK)
265+
heap_close(obj_desc->heap_r, RowExclusiveLock);
266+
else if (obj_desc->flags & IFS_RDLOCK)
267+
heap_close(obj_desc->heap_r, AccessShareLock);
270268
index_close(obj_desc->index_r);
271-
heap_close(obj_desc->heap_r, AccessShareLock);
272-
273269
pfree(obj_desc);
274270
}
275271

src/include/catalog/catname.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: catname.h,v 1.12 2000/01/26 05:57:56 momjian Exp $
10+
* $Id: catname.h,v 1.13 2000/10/08 03:18:55 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -29,6 +29,7 @@
2929
#define InheritsRelationName "pg_inherits"
3030
#define InheritancePrecidenceListRelationName "pg_ipl"
3131
#define LanguageRelationName "pg_language"
32+
#define LargeobjectRelationName "pg_largeobject"
3233
#define ListenerRelationName "pg_listener"
3334
#define LogRelationName "pg_log"
3435
#define OperatorClassRelationName "pg_opclass"

src/include/catalog/indexing.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: indexing.h,v 1.40 2000/06/17 04:56:30 tgl Exp $
11+
* $Id: indexing.h,v 1.41 2000/10/08 03:18:55 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -31,6 +31,7 @@
3131
#define Num_pg_index_indices 2
3232
#define Num_pg_inherits_indices 1
3333
#define Num_pg_language_indices 2
34+
#define Num_pg_largeobject_indices 2
3435
#define Num_pg_listener_indices 1
3536
#define Num_pg_opclass_indices 2
3637
#define Num_pg_operator_indices 2
@@ -92,6 +93,7 @@ extern char *Name_pg_group_indices[];
9293
extern char *Name_pg_index_indices[];
9394
extern char *Name_pg_inherits_indices[];
9495
extern char *Name_pg_language_indices[];
96+
extern char *Name_pg_largeobject_indices[];
9597
extern char *Name_pg_listener_indices[];
9698
extern char *Name_pg_opclass_indices[];
9799
extern char *Name_pg_operator_indices[];

src/include/catalog/pg_largeobject.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* pg_largeobject.h
4+
* definition of the system "largeobject" relation (pg_largeobject)
5+
* along with the relation's initial contents.
6+
*
7+
*
8+
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
9+
* Portions Copyright (c) 1994, Regents of the University of California
10+
*
11+
* $Id: pg_largeobject.h,v 1.1 2000/10/08 03:18:56 momjian Exp $
12+
*
13+
* NOTES
14+
* the genbki.sh script reads this file and generates .bki
15+
* information from the DATA() statements.
16+
*
17+
*-------------------------------------------------------------------------
18+
*/
19+
#ifndef PG_LARGEOBJECT_H
20+
#define PG_LARGEOBJECT_H
21+
22+
/* ----------------
23+
* postgres.h contains the system type definintions and the
24+
* CATALOG(), BOOTSTRAP and DATA() sugar words so this file
25+
* can be read by both genbki.sh and the C compiler.
26+
* ----------------
27+
*/
28+
29+
/* ----------------
30+
* pg_largeobject definition. cpp turns this into
31+
* typedef struct FormData_pg_largeobject. Large object id
32+
* is stored in loid;
33+
* ----------------
34+
*/
35+
36+
CATALOG(pg_largeobject)
37+
{
38+
Oid loid;
39+
int4 pageno;
40+
bytea data;
41+
} FormData_pg_largeobject;
42+
43+
/* ----------------
44+
* Form_pg_largeobject corresponds to a pointer to a tuple with
45+
* the format of pg_largeobject relation.
46+
* ----------------
47+
*/
48+
typedef FormData_pg_largeobject *Form_pg_largeobject;
49+
50+
/* ----------------
51+
* compiler constants for pg_largeobject
52+
* ----------------
53+
*/
54+
#define Natts_pg_largeobject 3
55+
#define Anum_pg_largeobject_loid 1
56+
#define Anum_pg_largeobject_pageno 2
57+
#define Anum_pg_largeobject_data 3
58+
59+
Oid LargeobjectCreate(Oid loid);
60+
void LargeobjectDrop(Oid loid);
61+
int LargeobjectFind(Oid loid);
62+
63+
#endif /* PG_LARGEOBJECT_H */

src/include/storage/large_object.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: large_object.h,v 1.13 2000/01/26 05:58:33 momjian Exp $
11+
* $Id: large_object.h,v 1.14 2000/10/08 03:18:57 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -22,17 +22,11 @@
2222
/*
2323
* This structure will eventually have lots more stuff associated with it.
2424
*/
25-
typedef struct LargeObjectDesc
26-
{
27-
Relation heap_r; /* heap relation */
28-
Relation index_r; /* index relation on seqno attribute */
29-
IndexScanDesc iscan; /* index scan we're using */
30-
TupleDesc hdesc; /* heap relation tuple desc */
31-
TupleDesc idesc; /* index relation tuple desc */
32-
uint32 lowbyte; /* low byte on the current page */
33-
uint32 highbyte; /* high byte on the current page */
25+
typedef struct LargeObjectDesc {
26+
Relation heap_r;
27+
Relation index_r;
3428
uint32 offset; /* current seek pointer */
35-
ItemPointerData htid; /* tid of current heap tuple */
29+
Oid id;
3630

3731
#define IFS_RDLOCK (1 << 0)
3832
#define IFS_WRLOCK (1 << 1)
@@ -55,7 +49,4 @@ extern int inv_tell(LargeObjectDesc *obj_desc);
5549
extern int inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes);
5650
extern int inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes);
5751

58-
/* added for buffer leak prevention [ PA ] */
59-
extern void inv_cleanindex(LargeObjectDesc *obj_desc);
60-
6152
#endif /* LARGE_OBJECT_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy