aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/access/heap/heapam.c4
-rw-r--r--src/backend/access/transam.h11
-rw-r--r--src/backend/access/transam/varsup.c69
-rw-r--r--src/backend/commands/copy.c52
-rw-r--r--src/backend/commands/copy.h4
-rw-r--r--src/backend/nodes/parsenodes.h3
-rw-r--r--src/backend/parser/gram.y25
-rw-r--r--src/backend/parser/keywords.c3
-rw-r--r--src/backend/tcop/utility.c6
9 files changed, 138 insertions, 39 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 4bf31efd832..add8112710f 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.1.1.1 1996/07/09 06:21:11 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.2 1996/08/24 20:47:54 scrappy Exp $
*
*
* INTERFACE ROUTINES
@@ -1093,6 +1093,8 @@ heap_insert(Relation relation, HeapTuple tup)
tup->t_oid = newoid();
LastOidProcessed = tup->t_oid;
}
+ else
+ CheckMaxObjectId(tup->t_oid);
TransactionIdStore(GetCurrentTransactionId(), &(tup->t_xmin));
tup->t_cmin = GetCurrentCommandId();
diff --git a/src/backend/access/transam.h b/src/backend/access/transam.h
index 0f5a9724dc0..ca9a47e802b 100644
--- a/src/backend/access/transam.h
+++ b/src/backend/access/transam.h
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: transam.h,v 1.1.1.1 1996/07/09 06:21:09 scrappy Exp $
+ * $Id: transam.h,v 1.2 1996/08/24 20:47:42 scrappy Exp $
*
* NOTES
* Transaction System Version 101 now support proper oid
@@ -46,6 +46,14 @@
typedef unsigned char XidStatus; /* (2 bits) */
+/* ----------
+ * note: we reserve the first 16384 object ids for internal use.
+ * oid's less than this appear in the .bki files. the choice of
+ * 16384 is completely arbitrary.
+ * ----------
+ */
+#define BootstrapObjectIdData 16384
+
/* ----------------
* BitIndexOf computes the index of the Nth xid on a given block
* ----------------
@@ -182,6 +190,7 @@ extern void GetNewTransactionId(TransactionId *xid);
extern void UpdateLastCommittedXid(TransactionId xid);
extern void GetNewObjectIdBlock(Oid *oid_return, int oid_block_size);
extern void GetNewObjectId(Oid *oid_return);
+extern void CheckMaxObjectId(Oid assigned_oid);
/* ----------------
* global variable extern declarations
diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c
index a53cc7d35b1..5fc47b7228b 100644
--- a/src/backend/access/transam/varsup.c
+++ b/src/backend/access/transam/varsup.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.1.1.1 1996/07/09 06:21:13 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.2 1996/08/24 20:48:04 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -28,14 +28,6 @@
#include "catalog/catname.h"
-/* ----------
- * note: we reserve the first 16384 object ids for internal use.
- * oid's less than this appear in the .bki files. the choice of
- * 16384 is completely arbitrary.
- * ----------
- */
-#define BootstrapObjectIdData 16384
-
/* ---------------------
* spin lock for oid generation
* ---------------------
@@ -604,3 +596,62 @@ GetNewObjectId(Oid *oid_return) /* place to return the new object id */
next_prefetched_oid++;
prefetched_oid_count--;
}
+
+void
+CheckMaxObjectId(Oid assigned_oid)
+{
+Oid pass_oid;
+
+
+ if (prefetched_oid_count == 0) /* make sure next/max is set, or reload */
+ GetNewObjectId(&pass_oid);
+
+ /* ----------------
+ * If we are below prefetched limits, do nothing
+ * ----------------
+ */
+
+ if (assigned_oid < next_prefetched_oid)
+ return;
+
+ /* ----------------
+ * If we are here, we are coming from a 'copy from' with oid's
+ *
+ * If we are in the prefetched oid range, just bump it up
+ *
+ * ----------------
+ */
+
+ if (assigned_oid <= next_prefetched_oid + prefetched_oid_count - 1)
+ {
+ prefetched_oid_count -= assigned_oid - next_prefetched_oid + 1;
+ next_prefetched_oid = assigned_oid + 1;
+ return;
+ }
+
+ /* ----------------
+ * We have exceeded the prefetch oid range
+ *
+ * We should lock the database and kill all other backends
+ * but we are loading oid's that we can not guarantee are unique
+ * anyway, so we must rely on the user
+ *
+ *
+ * We now:
+ * set the variable relation with the new max oid
+ * force the backend to reload its oid cache
+ *
+ * We use the oid cache so we don't have to update the variable
+ * relation every time
+ *
+ * ----------------
+ */
+
+ pass_oid = assigned_oid;
+ VariableRelationPutNextOid(&pass_oid); /* not modified */
+ prefetched_oid_count = 0; /* force reload */
+ pass_oid = assigned_oid;
+ GetNewObjectId(&pass_oid); /* throw away returned oid */
+
+}
+
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index e17100a0fb0..109f36f3e52 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -6,7 +6,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.3 1996/08/14 05:33:04 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.4 1996/08/24 20:48:14 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -22,11 +22,13 @@
#include "catalog/pg_index.h"
#include "catalog/index.h"
+#include "storage/bufmgr.h"
#include "access/heapam.h"
#include "access/htup.h"
#include "access/itup.h"
#include "access/relscan.h"
#include "access/funcindex.h"
+#include "access/transam.h"
#include "access/tupdesc.h"
#include "nodes/execnodes.h"
#include "nodes/plannodes.h"
@@ -50,8 +52,8 @@
static bool reading_from_input = false;
/* non-export function prototypes */
-static void CopyTo(Relation rel, bool binary, FILE *fp, char *delim);
-static void CopyFrom(Relation rel, bool binary, FILE *fp, char *delim);
+static void CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim);
+static void CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim);
static Oid GetOutputFunction(Oid type);
static Oid GetTypeElement(Oid type);
static Oid GetInputFunction(Oid type);
@@ -59,14 +61,14 @@ static Oid IsTypeByVal(Oid type);
static void GetIndexRelations(Oid main_relation_oid,
int *n_indices,
Relation **index_rels);
-static char *CopyReadAttribute(int attno, FILE *fp, bool *isnull, char *delim);
+static char *CopyReadAttribute(FILE *fp, bool *isnull, char *delim);
static void CopyAttributeOut(FILE *fp, char *string, char *delim);
static int CountTuples(Relation relation);
extern FILE *Pfout, *Pfin;
void
-DoCopy(char *relname, bool binary, bool from, bool pipe, char *filename,
+DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, char *filename,
char *delim)
{
FILE *fp;
@@ -86,7 +88,7 @@ DoCopy(char *relname, bool binary, bool from, bool pipe, char *filename,
if (fp == NULL) {
elog(WARN, "COPY: file %s could not be open for reading", filename);
}
- CopyFrom(rel, binary, fp, delim);
+ CopyFrom(rel, binary, oids, fp, delim);
}else {
mode_t oumask = umask((mode_t) 0);
@@ -102,7 +104,7 @@ DoCopy(char *relname, bool binary, bool from, bool pipe, char *filename,
if (fp == NULL) {
elog(WARN, "COPY: file %s could not be open for writing", filename);
}
- CopyTo(rel, binary, fp, delim);
+ CopyTo(rel, binary, oids, fp, delim);
}
if (!pipe) {
fclose(fp);
@@ -113,7 +115,7 @@ DoCopy(char *relname, bool binary, bool from, bool pipe, char *filename,
}
static void
-CopyTo(Relation rel, bool binary, FILE *fp, char *delim)
+CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
{
HeapTuple tuple;
HeapScanDesc scandesc;
@@ -159,6 +161,11 @@ CopyTo(Relation rel, bool binary, FILE *fp, char *delim)
for (tuple = heap_getnext(scandesc, 0, NULL);
tuple != NULL;
tuple = heap_getnext(scandesc, 0, NULL)) {
+
+ if (oids && !binary) {
+ fputs(oidout(tuple->t_oid),fp);
+ fputc(delim[0], fp);
+ }
for (i = 0; i < attr_count; i++) {
value = (Datum)
@@ -197,6 +204,9 @@ CopyTo(Relation rel, bool binary, FILE *fp, char *delim)
length = tuple->t_len - tuple->t_hoff;
fwrite(&length, sizeof(int32), 1, fp);
+ if (oids)
+ fwrite((char *) &tuple->t_oid, sizeof(int32), 1, fp);
+
fwrite(&null_ct, sizeof(int32), 1, fp);
if (null_ct > 0) {
for (i = 0; i < attr_count; i++) {
@@ -222,7 +232,7 @@ CopyTo(Relation rel, bool binary, FILE *fp, char *delim)
}
static void
-CopyFrom(Relation rel, bool binary, FILE *fp, char *delim)
+CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
{
HeapTuple tuple;
IndexTuple ituple;
@@ -260,7 +270,8 @@ CopyFrom(Relation rel, bool binary, FILE *fp, char *delim)
int n_indices;
InsertIndexResult indexRes;
TupleDesc tupDesc;
-
+ Oid loaded_oid;
+
tupDesc = RelationGetTupleDescriptor(rel);
attr = tupDesc->attrs;
attr_count = tupDesc->natts;
@@ -374,8 +385,18 @@ CopyFrom(Relation rel, bool binary, FILE *fp, char *delim)
while (!done) {
if (!binary) {
+ if (oids) {
+ string = CopyReadAttribute(fp, &isnull, delim);
+ if (string == NULL)
+ done = 1;
+ else {
+ loaded_oid = oidin(string);
+ if (loaded_oid < BootstrapObjectIdData)
+ elog(WARN, "COPY TEXT: Invalid Oid");
+ }
+ }
for (i = 0; i < attr_count && !done; i++) {
- string = CopyReadAttribute(i, fp, &isnull, delim);
+ string = CopyReadAttribute(fp, &isnull, delim);
if (isnull) {
values[i] = PointerGetDatum(NULL);
nulls[i] = 'n';
@@ -401,6 +422,11 @@ CopyFrom(Relation rel, bool binary, FILE *fp, char *delim)
if (feof(fp)) {
done = 1;
}else {
+ if (oids) {
+ fread(&loaded_oid, sizeof(int32), 1, fp);
+ if (loaded_oid < BootstrapObjectIdData)
+ elog(WARN, "COPY BINARY: Invalid Oid");
+ }
fread(&null_ct, sizeof(int32), 1, fp);
if (null_ct > 0) {
for (i = 0; i < null_ct; i++) {
@@ -476,6 +502,8 @@ CopyFrom(Relation rel, bool binary, FILE *fp, char *delim)
tupDesc = CreateTupleDesc(attr_count, attr);
tuple = heap_formtuple(tupDesc, values, nulls);
+ if (oids)
+ tuple->t_oid = loaded_oid;
heap_insert(rel, tuple);
if (has_index) {
@@ -699,7 +727,7 @@ inString(char c, char* s)
*/
static char *
-CopyReadAttribute(int attno, FILE *fp, bool *isnull, char *delim)
+CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
{
static char attribute[EXT_ATTLEN];
char c;
diff --git a/src/backend/commands/copy.h b/src/backend/commands/copy.h
index ccd29555626..30b85058528 100644
--- a/src/backend/commands/copy.h
+++ b/src/backend/commands/copy.h
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: copy.h,v 1.1.1.1 1996/07/09 06:21:19 scrappy Exp $
+ * $Id: copy.h,v 1.2 1996/08/24 20:48:16 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -15,7 +15,7 @@
#include "postgres.h"
-void DoCopy(char *relname, bool binary, bool from, bool pipe, char *filename,
+void DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, char *filename,
char *delim);
#endif /* COPY_H */
diff --git a/src/backend/nodes/parsenodes.h b/src/backend/nodes/parsenodes.h
index 07f86b252ef..f2c7c591095 100644
--- a/src/backend/nodes/parsenodes.h
+++ b/src/backend/nodes/parsenodes.h
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: parsenodes.h,v 1.3 1996/08/06 16:37:53 scrappy Exp $
+ * $Id: parsenodes.h,v 1.4 1996/08/24 20:48:31 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -114,6 +114,7 @@ typedef struct CopyStmt {
NodeTag type;
bool binary; /* is a binary copy? */
char *relname; /* the relation to copy */
+ bool oids; /* copy oid's? */
int direction; /* TO or FROM */
char *filename; /* if NULL, use stdin/stdout */
char *delimiter; /* delimiter character, \t by default*/
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index b5c80f971cc..96dbc55cb70 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.7 1996/08/15 07:42:29 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.8 1996/08/24 20:48:44 scrappy Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -122,14 +122,14 @@ static Node *makeA_Expr(int op, char *opname, Node *lexpr, Node *rexpr);
%type <list> queryblock, relation_name_list, OptTableElementList,
tableElementList, OptInherit, definition,
- opt_with, def_args, def_name_list, func_argtypes, oper_argtypes,
+ opt_with_func, def_args, def_name_list, func_argtypes, oper_argtypes,
OptStmtList, OptStmtBlock, opt_column_list, columnList,
exprList, sort_clause, sortby_list, index_params,
name_list, from_clause, from_list, opt_array_bounds, nest_array_bounds,
expr_list, attrs, res_target_list, res_target_list2, def_list,
opt_indirection, group_clause, groupby_list, explain_options
-%type <boolean> opt_inh_star, opt_binary, opt_instead
+%type <boolean> opt_inh_star, opt_binary, opt_instead, opt_with_copy
%type <ival> copy_dirn, archive_type, OptArchiveType, OptArchiveLocation,
def_type, opt_direction, remove_type, opt_column, event
@@ -176,7 +176,7 @@ static Node *makeA_Expr(int op, char *opname, Node *lexpr, Node *rexpr);
HAVING, HEAVY, IN, INDEX, INHERITS, INSERT, INSTEAD, INTO, IS,
ISNULL, LANGUAGE, LIGHT, LISTEN, LOAD, MERGE, MOVE, NEW,
NONE, NOT, NOTHING, NOTIFY, NOTNULL,
- ON, OPERATOR, OPTION, OR, ORDER,
+ OIDS, ON, OPERATOR, OPTION, OR, ORDER,
PNULL, PRIVILEGES, PUBLIC, PURGE, P_TYPE,
RENAME, REPLACE, RETRIEVE, RETURNS, REVOKE, ROLLBACK, RULE,
SELECT, SET, SETOF, STDIN, STDOUT, STORE,
@@ -306,14 +306,15 @@ ClosePortalStmt: CLOSE opt_id
*
*****************************************************************************/
-CopyStmt: COPY opt_binary relation_name copy_dirn copy_file_name copy_delimiter
+CopyStmt: COPY opt_binary relation_name opt_with_copy copy_dirn copy_file_name copy_delimiter
{
CopyStmt *n = makeNode(CopyStmt);
n->binary = $2;
n->relname = $3;
- n->direction = $4;
- n->filename = $5;
- n->delimiter = $6;
+ n->oids = $4;
+ n->direction = $5;
+ n->filename = $6;
+ n->delimiter = $7;
$$ = (Node *)n;
}
;
@@ -338,6 +339,10 @@ opt_binary: BINARY { $$ = TRUE; }
| /*EMPTY*/ { $$ = FALSE; }
;
+opt_with_copy: WITH OIDS { $$ = TRUE; }
+ | /* EMPTY */ { $$ = FALSE; }
+ ;
+
/*
* the default copy delimiter is tab but the user can configure it
*/
@@ -725,7 +730,7 @@ RecipeStmt: EXECUTE RECIPE recipe_name
*****************************************************************************/
ProcedureStmt: CREATE FUNCTION def_name def_args
- RETURNS def_arg opt_with AS Sconst LANGUAGE Sconst
+ RETURNS def_arg opt_with_func AS Sconst LANGUAGE Sconst
{
ProcedureStmt *n = makeNode(ProcedureStmt);
n->funcname = $3;
@@ -737,7 +742,7 @@ ProcedureStmt: CREATE FUNCTION def_name def_args
$$ = (Node *)n;
};
-opt_with: WITH definition { $$ = $2; }
+opt_with_func: WITH definition { $$ = $2; }
| /* EMPTY */ { $$ = NIL; }
;
diff --git a/src/backend/parser/keywords.c b/src/backend/parser/keywords.c
index 80a18325753..31c035d42a5 100644
--- a/src/backend/parser/keywords.c
+++ b/src/backend/parser/keywords.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.2 1996/08/06 16:43:08 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.3 1996/08/24 20:48:46 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -103,6 +103,7 @@ static ScanKeyword ScanKeywords[] = {
{ "notify", NOTIFY },
{ "notnull", NOTNULL },
{ "null", PNULL },
+ { "oids", OIDS },
{ "on", ON },
{ "operator", OPERATOR },
{ "option", OPTION },
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index e12d18b91ee..a7df82c0ff4 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.1.1.1 1996/07/09 06:22:00 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.2 1996/08/24 20:49:03 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -199,6 +199,7 @@ ProcessUtility(Node *parsetree,
char *filename;
char *delim;
bool isBinary;
+ bool isOids;
bool isFrom;
bool pipe = false;
@@ -207,6 +208,7 @@ ProcessUtility(Node *parsetree,
relname = stmt->relname;
isBinary = stmt->binary;
+ isOids = stmt->oids;
isFrom = (bool)(stmt->direction == FROM);
filename = stmt->filename;
@@ -234,7 +236,7 @@ ProcessUtility(Node *parsetree,
if (pipe && IsUnderPostmaster) dest = CopyEnd;
- DoCopy(relname, isBinary, isFrom, pipe, filename, delim);
+ DoCopy(relname, isBinary, isOids, isFrom, pipe, filename, delim);
}
break;