diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index e292e21b7afdf8b65778a273d85a5099b0a38074..0ffaa5330ec68a1c61654971aecf6d1b24eaede3 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -5,7 +5,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Id: nbtsort.c,v 1.26 1998/01/07 21:01:59 momjian Exp $
+ *	  $Id: nbtsort.c,v 1.27 1998/01/13 04:03:41 scrappy Exp $
  *
  * NOTES
  *
@@ -49,13 +49,12 @@
 
 #include <fcntl.h>
 
-#include <postgres.h>
-
-#include <utils/memutils.h>
-#include <storage/bufpage.h>
-#include <access/nbtree.h>
-#include <storage/bufmgr.h>
+#include "postgres.h"
 
+#include "access/nbtree.h"
+#include "storage/bufmgr.h"
+#include "storage/bufpage.h"
+#include "utils/memutils.h"
 
 #ifndef HAVE_MEMMOVE
 #include <regex/utils.h>
@@ -64,7 +63,7 @@
 #endif
 
 #ifdef BTREE_BUILD_STATS
-#include <tcop/tcopprot.h>
+#include "tcop/tcopprot.h"
 extern int	ShowExecutorStats;
 
 #endif
@@ -85,7 +84,7 @@ static void _bt_uppershutdown(Relation index, BTPageState *state);
 #define FASTBUILD_MERGE
 
 #define MAXTAPES		(7)
-#define TAPEBLCKSZ		(MAXBLCKSZ << 2)
+#define TAPEBLCKSZ		(BLCKSZ << 2)
 #define TAPETEMP		"pg_btsortXXXXXX"
 
 extern int	NDirectFileRead;
@@ -458,7 +457,7 @@ _bt_tapewrite(BTTapeBlock *tape, int eor)
 {
 	tape->bttb_eor = eor;
 	FileWrite(tape->bttb_fd, (char *) tape, TAPEBLCKSZ);
-	NDirectFileWrite += TAPEBLCKSZ / MAXBLCKSZ;
+	NDirectFileWrite += TAPEBLCKSZ / BLCKSZ;
 	_bt_tapereset(tape);
 }
 
@@ -496,7 +495,7 @@ _bt_taperead(BTTapeBlock *tape)
 		return (0);
 	}
 	Assert(tape->bttb_magic == BTTAPEMAGIC);
-	NDirectFileRead += TAPEBLCKSZ / MAXBLCKSZ;
+	NDirectFileRead += TAPEBLCKSZ / BLCKSZ;
 	return (1);
 }
 
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 749c3cf0d971f9088b2dc0d3fed15ebf91608640..7336a5ac3eeddbc25a61b0d44ef71895596267e4 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.33 1998/01/06 19:42:29 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.34 1998/01/13 04:03:45 scrappy Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -23,34 +23,33 @@
  *
  *-------------------------------------------------------------------------
  */
-#include <postgres.h>
-
-#include <catalog/pg_proc.h>
-#include <storage/bufmgr.h>
-#include <fmgr.h>
-#include <access/genam.h>
-#include <access/heapam.h>
-#include <access/istrat.h>
-#include <access/xact.h>
-#include <bootstrap/bootstrap.h>
-#include <catalog/catname.h>
-#include <catalog/catalog.h>
-#include <catalog/indexing.h>
-#include <catalog/heap.h>
-#include <catalog/index.h>
-#include <catalog/pg_type.h>
-#include <executor/executor.h>
-#include <miscadmin.h>
-#include <optimizer/clauses.h>
-#include <optimizer/prep.h>
-#include <parser/parse_func.h>
-#include <storage/lmgr.h>
-#include <storage/smgr.h>
-#include <utils/builtins.h>
-#include <utils/mcxt.h>
-#include <utils/relcache.h>
-#include <utils/syscache.h>
-#include <utils/tqual.h>
+#include "postgres.h"
+#include "fmgr.h"
+
+#include "access/genam.h"
+#include "access/heapam.h"
+#include "access/istrat.h"
+#include "access/xact.h"
+#include "bootstrap/bootstrap.h"
+#include "catalog/catalog.h"
+#include "catalog/catname.h"
+#include "catalog/heap.h"
+#include "catalog/index.h"
+#include "catalog/indexing.h"
+#include "catalog/pg_proc.h"
+#include "catalog/pg_type.h"
+#include "executor/executor.h"
+#include "miscadmin.h"
+#include "optimizer/clauses.h"
+#include "optimizer/prep.h"
+#include "parser/parse_func.h"
+#include "storage/lmgr.h"
+#include "storage/smgr.h"
+#include "utils/builtins.h"
+#include "utils/mcxt.h"
+#include "utils/relcache.h"
+#include "utils/syscache.h"
+#include "utils/tqual.h"
 
 #ifndef HAVE_MEMMOVE
 #include <regex/utils.h>
diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c
index 8914b9d4873007cb8a2958803f8fe550a66c13cc..26930f84842805a398b5c4f3a33d6099d634d3cf 100644
--- a/src/backend/executor/nodeHash.c
+++ b/src/backend/executor/nodeHash.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/executor/nodeHash.c,v 1.15 1998/01/07 21:02:52 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/executor/nodeHash.c,v 1.16 1998/01/13 04:03:53 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -31,15 +31,11 @@
 
 #include "postgres.h"
 
-
-#include "storage/fd.h"			/* for SEEK_ */
-#include "storage/ipc.h"
-#include "storage/bufmgr.h"		/* for BLCKSZ */
+#include "executor/execdebug.h"
 #include "executor/executor.h"
 #include "executor/nodeHash.h"
 #include "executor/nodeHashjoin.h"
-#include "executor/execdebug.h"
-#include "utils/palloc.h"
+#include "storage/ipc.h"
 #include "utils/hsearch.h"
 
 extern int	NBuffers;
diff --git a/src/backend/executor/nodeHashjoin.c b/src/backend/executor/nodeHashjoin.c
index 0ef0c28ee1446e48f7ebb04b6c105a4f7a1b8f08..c5fa8a092de0d0d153640a19bc83a2c2e3ffb042 100644
--- a/src/backend/executor/nodeHashjoin.c
+++ b/src/backend/executor/nodeHashjoin.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.8 1997/09/08 21:43:12 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.9 1998/01/13 04:03:58 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,21 +17,14 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
-
-
 #include "postgres.h"
-#include "storage/bufmgr.h"		/* for BLCKSZ */
-#include "storage/fd.h"			/* for SEEK_ */
-#include "executor/executor.h"
+
 #include "executor/execdebug.h"
+#include "executor/executor.h"
 #include "executor/nodeHash.h"
 #include "executor/nodeHashjoin.h"
-
 #include "optimizer/clauses.h"	/* for get_leftop */
 
-
-#include "utils/palloc.h"
-
 static TupleTableSlot *
 			ExecHashJoinOuterGetTuple(Plan *node, Plan *parent, HashJoinState *hjstate);
 
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index adaca39a902f5a57a18f20a34e6e6513509941ff..b86e727da464e83dfe7f3d3b4fdc7ec6f73a671e 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -7,15 +7,15 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.19 1997/09/08 21:44:50 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.20 1998/01/13 04:04:06 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
 
 #include "postgres.h"
-#include "config.h"
 
 #include <math.h>
+
 #ifdef HAVE_LIMITS_H
 #include <limits.h>
 #ifndef MAXINT
@@ -27,15 +27,12 @@
 #endif
 #endif
 
-#include <utils/lsyscache.h>
 #include "nodes/relation.h"
-
 #include "optimizer/cost.h"
 #include "optimizer/internal.h"
 #include "optimizer/keys.h"
 #include "optimizer/tlist.h"
-
-#include "storage/bufmgr.h"		/* for BLCKSZ */
+#include "utils/lsyscache.h"
 
 extern int	NBuffers;
 
diff --git a/src/backend/optimizer/path/xfunc.c b/src/backend/optimizer/path/xfunc.c
index 4e74de508fbb99ef2857189900485810f6420c98..cf23b2251037ee0a90bfcf7f14ba12169b3705db 100644
--- a/src/backend/optimizer/path/xfunc.c
+++ b/src/backend/optimizer/path/xfunc.c
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/xfunc.c,v 1.11 1998/01/07 21:03:56 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/xfunc.c,v 1.12 1998/01/13 04:04:07 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -19,29 +19,26 @@
 #include <string.h>
 
 #include "postgres.h"
-#include "nodes/pg_list.h"
+
+#include "access/heapam.h"
+#include "catalog/pg_language.h"
+#include "catalog/pg_proc.h"
+#include "catalog/pg_type.h"
+#include "lib/lispsort.h"
 #include "nodes/nodes.h"
+#include "nodes/pg_list.h"
 #include "nodes/primnodes.h"
 #include "nodes/relation.h"
-#include "utils/elog.h"
-#include "utils/palloc.h"
-#include "utils/syscache.h"
-#include "catalog/pg_proc.h"
-#include "catalog/pg_type.h"
-#include "utils/syscache.h"
-#include "catalog/pg_language.h"
-#include "optimizer/xfunc.h"
 #include "optimizer/clauses.h"
-#include "optimizer/pathnode.h"
-#include "optimizer/internal.h"
 #include "optimizer/cost.h"
+#include "optimizer/internal.h"
 #include "optimizer/keys.h"
-#include "optimizer/tlist.h"
-#include "lib/lispsort.h"
-#include "access/heapam.h"
-#include "tcop/dest.h"
+#include "optimizer/pathnode.h"
+#include "optimizer/tlist.h"			/* for get_expr */
+#include "optimizer/xfunc.h"
 #include "storage/buf_internals.h"		/* for NBuffers */
-#include "optimizer/tlist.h"	/* for get_expr */
+#include "tcop/dest.h"
+#include "utils/syscache.h"
 
 #define ever ; 1 ;
 
diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c
index c95be222a939461ea4e0d87c0d8547c1fed2be2b..3997ad3f391cecc924131fbe7b65f75d16681b17 100644
--- a/src/backend/rewrite/rewriteDefine.c
+++ b/src/backend/rewrite/rewriteDefine.c
@@ -7,29 +7,28 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.13 1998/01/07 21:04:32 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.14 1998/01/13 04:04:12 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include <stdio.h>
 #include <string.h>
+
 #include "postgres.h"
 
-#include "utils/rel.h"			/* for Relation stuff */
 #include "access/heapam.h"		/* access methods like amopenr */
-#include "utils/builtins.h"
-#include "utils/elog.h"			/* for elog */
-#include "utils/palloc.h"
-#include "utils/lsyscache.h"	/* for get_typlen */
-#include "nodes/pg_list.h"		/* for Lisp support */
 #include "nodes/parsenodes.h"
+#include "nodes/pg_list.h"		/* for Lisp support */
 #include "parser/parse_relation.h"
-
 #include "rewrite/locks.h"
 #include "rewrite/rewriteDefine.h"
 #include "rewrite/rewriteRemove.h"
 #include "rewrite/rewriteSupport.h"
 #include "tcop/tcopprot.h"
+#include "utils/builtins.h"
+#include "utils/lsyscache.h"	/* for get_typlen */
+#include "utils/rel.h"			/* for Relation stuff */
+
 
 Oid			LastOidProcessed = InvalidOid;
 
@@ -39,7 +38,7 @@ Oid			LastOidProcessed = InvalidOid;
  *
  * should this be smaller?
  */
-#define RULE_PLAN_SIZE 8192
+#define RULE_PLAN_SIZE BLCKSZ
 
 static void
 strcpyq(char *dest, char *source)
diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c
index 72005129818e8d738db0a67d79ba1c63efd81417..8c13462167b7242c31c362e563094bcda9b99929 100644
--- a/src/backend/storage/buffer/localbuf.c
+++ b/src/backend/storage/buffer/localbuf.c
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.16 1998/01/07 21:04:54 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.17 1998/01/13 04:04:20 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -39,7 +39,6 @@
 #include "storage/spin.h"
 #include "storage/smgr.h"
 #include "storage/lmgr.h"
-#include "storage/buf_internals.h"
 #include "miscadmin.h"
 #include "utils/builtins.h"
 #include "utils/hsearch.h"
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 49b2956d98182ae7068cb72d8132ff10b04e7845..fe12e1cc5f38eac741a9a7bf0d64345c4cf4a362 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.26 1998/01/07 21:05:44 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.27 1998/01/13 04:04:31 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -20,14 +20,12 @@
 #include "postgres.h"
 #include "miscadmin.h"			/* for DataDir */
 
+#include "catalog/catalog.h"
 #include "storage/block.h"
 #include "storage/fd.h"
 #include "storage/smgr.h"		/* where the declarations go */
-#include "storage/fd.h"
 #include "utils/mcxt.h"
 #include "utils/rel.h"
-#include "utils/palloc.h"
-#include "catalog/catalog.h"
 
 #undef DIAGNOSTIC
 
@@ -59,7 +57,22 @@ static MemoryContext MdCxt;
 #define MDFD_DIRTY		(uint16) 0x01
 #define MDFD_FREE		(uint16) 0x02
 
-#define RELSEG_SIZE		262144	/* (2 ** 31) / 8192 -- 2GB file */
+/*
+ * RELSEG_SIZE appears to be the number of segments that can
+ * be in a disk file.  It was defined as 262144 based on 8k
+ * blocks, but now that the block size can be changed, this
+ * has to be calculated at compile time.  Otherwise, the file
+ * size limit would not work out to 2-gig (2147483648).
+ *
+ * The number needs to be (2 ** 31) / BLCKSZ, but to be keep
+ * the math under MAXINT, pre-divide by 256 and use ...
+ *
+ *           (((2 ** 23) / BLCKSZ) * (2 ** 8))
+ *
+ * 07 Jan 98  darrenk
+ */
+
+#define RELSEG_SIZE		((8388608 / BLCKSZ) * 256)
 
 /* routines declared here */
 static MdfdVec *_mdfd_openseg(Relation reln, int segno, int oflags);
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 31da750ffe570794349d6f9c106f9d9a3598a29a..d823dbb5a65af2e167a687a3eedf6b6bfee01d93 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.60 1998/01/09 05:48:22 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.61 1998/01/13 04:04:36 scrappy Exp $
  *
  * NOTES
  *	  this is the "main" module of the postgres backend and
@@ -40,54 +40,48 @@
 
 #include "postgres.h"
 #include "miscadmin.h"
-#include "catalog/catname.h"
-#include "access/xact.h"
-
-#include "lib/dllist.h"
+#include "fmgr.h"
 
+#include "access/xact.h"
+#include "catalog/catname.h"
 #include "commands/async.h"
-#include "tcop/tcopprot.h"		/* where declarations for this file go */
+#include "executor/execdebug.h"
+#include "executor/executor.h"
+#include "lib/dllist.h"
+#include "libpq/libpq.h"
+#include "libpq/pqsignal.h"
+#include "nodes/pg_list.h"
+#include "nodes/print.h"
+#include "optimizer/cost.h"
 #include "optimizer/planner.h"
+#include "optimizer/prep.h"
 #include "parser/parser.h"
-
-#include "tcop/tcopprot.h"
+#include "rewrite/rewriteHandler.h"		/* for QueryRewrite() */
+#include "storage/bufmgr.h"
+#include "tcop/dest.h"
+#include "tcop/fastpath.h"
+#include "tcop/pquery.h"
 #include "tcop/tcopdebug.h"
+#include "tcop/tcopprot.h"		/* where declarations for this file go */
+#include "tcop/utility.h"
+#include "utils/mcxt.h"
+#include "utils/rel.h"
 
-#include "executor/execdebug.h"
-#include "executor/executor.h"
 #if FALSE
 #include "nodes/relation.h"
 #endif
-#include "nodes/print.h"
 
-#include "optimizer/cost.h"
-#include "optimizer/planner.h"
 #if 0
 #include "optimizer/xfunc.h"
 #endif
-#include "optimizer/prep.h"
+
 #if FALSE
 #include "nodes/plannodes.h"
 #endif
 
-#include "storage/bufmgr.h"
-#include "fmgr.h"
-#include "utils/palloc.h"
-#include "utils/rel.h"
-
-#include "nodes/pg_list.h"
-#include "tcop/dest.h"
 #if FALSE
 #include "nodes/memnodes.h"
 #endif
-#include "utils/mcxt.h"
-#include "tcop/pquery.h"
-#include "tcop/utility.h"
-#include "tcop/fastpath.h"
-
-#include "libpq/libpq.h"
-#include "libpq/pqsignal.h"
-#include "rewrite/rewriteHandler.h"		/* for QueryRewrite() */
 
 static void quickdie(SIGNAL_ARGS);
 
@@ -1123,7 +1117,7 @@ PostgresMain(int argc, char *argv[])
 					int S;
 					
 					S = atoi(optarg);
-					if ( S >= 4*MAXBLCKSZ/1024 )
+					if ( S >= 4*BLCKSZ/1024 )
 						SortMem = S;
 				}
 				break;
@@ -1387,7 +1381,7 @@ PostgresMain(int argc, char *argv[])
 	if (IsUnderPostmaster == false)
 	{
 		puts("\nPOSTGRES backend interactive interface");
-		puts("$Revision: 1.60 $ $Date: 1998/01/09 05:48:22 $");
+		puts("$Revision: 1.61 $ $Date: 1998/01/13 04:04:36 $");
 	}
 
 	/* ----------------
diff --git a/src/backend/utils/adt/chunk.c b/src/backend/utils/adt/chunk.c
index 24c701177917b9dadb03620790df27d2fcdc09c2..b75317fcfc327d32857c6c5ed72a292fae92d350 100644
--- a/src/backend/utils/adt/chunk.c
+++ b/src/backend/utils/adt/chunk.c
@@ -6,7 +6,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/chunk.c,v 1.13 1998/01/05 16:39:46 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/chunk.c,v 1.14 1998/01/13 04:04:47 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -15,26 +15,21 @@
 #include <fcntl.h>
 
 #include "postgres.h"
-
-#include <libpq/be-fsstubs.h>
-#include "utils/memutils.h"
-#include "libpq/libpq-fs.h"
-
-#include "storage/fd.h"			/* for SEEK_ */
+#include "fmgr.h"
 
 #include "catalog/pg_type.h"
-
-#include "fmgr.h"
+#include "libpq/be-fsstubs.h"
+#include "libpq/libpq-fs.h"
+#include "optimizer/internal.h"
 #include "utils/array.h"
+#include "utils/memutils.h"
 
-#include "optimizer/internal.h"
 #ifndef HAVE_MEMMOVE
 #include <regex/utils.h>
 #else
 #include <string.h>
 #endif
 
-
 #define INFTY 500000000
 #define MANY  10000
 #define MAXPAT 20
diff --git a/src/backend/utils/sort/psort.c b/src/backend/utils/sort/psort.c
index d6220db9e2da90edd801bd0d763984da5f8810ce..682e2534ff4cf921ad87846ca3128816b3da9243 100644
--- a/src/backend/utils/sort/psort.c
+++ b/src/backend/utils/sort/psort.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/psort.c,v 1.30 1998/01/07 21:06:39 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/psort.c,v 1.31 1998/01/13 04:04:57 scrappy Exp $
  *
  * NOTES
  *		Sorts the first relation into the second relation.
@@ -40,27 +40,22 @@
 #include <unistd.h>
 
 #include "postgres.h"
+#include "miscadmin.h"
 
-#include "executor/execdebug.h"
 #include "access/heapam.h"
 #include "access/htup.h"
 #include "access/relscan.h"
 #include "access/skey.h"
-#include "storage/buf.h"
-#include "storage/bufmgr.h"		/* for BLCKSZ */
-#include "utils/portal.h"		/* for {Start,End}PortalAllocMode */
-#include "utils/elog.h"
-#include "utils/rel.h"
-
+#include "executor/execdebug.h"
+#include "executor/executor.h"
 #include "nodes/execnodes.h"
 #include "nodes/plannodes.h"
-#include "executor/executor.h"
-
+#include "storage/buf.h"
+#include "storage/fd.h"
 #include "utils/lselect.h"
+#include "utils/portal.h"		/* for {Start,End}PortalAllocMode */
 #include "utils/psort.h"
-
-#include "miscadmin.h"
-#include "storage/fd.h"
+#include "utils/rel.h"
 
 static bool createfirstrun(Sort * node);
 static bool createrun(Sort * node, FILE * file);
@@ -250,7 +245,7 @@ inittapes(Sort * node)
 
 #define USEMEM(NODE,AMT)		PS(node)->treeContext.sortMem -= (AMT)
 #define FREEMEM(NODE,AMT)		PS(node)->treeContext.sortMem += (AMT)
-#define LACKMEM(NODE)			(PS(node)->treeContext.sortMem <= MAXBLCKSZ)	/* not accurate */
+#define LACKMEM(NODE)			(PS(node)->treeContext.sortMem <= BLCKSZ)	/* not accurate */
 #define TRACEMEM(FUNC)
 #define TRACEOUT(FUNC, TUP)
 
diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h
index e9afc2e7e12bcb897d4b9acf31e6beb2c6b2a7ee..744b5ead14ae7167debd1b8f9bb8c9c11a0493d5 100644
--- a/src/include/storage/bufmgr.h
+++ b/src/include/storage/bufmgr.h
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: bufmgr.h,v 1.15 1997/09/08 21:54:18 momjian Exp $
+ * $Id: bufmgr.h,v 1.16 1998/01/13 04:05:09 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -26,11 +26,15 @@
  * in theory this could be anything, but in practice this is actually
  * limited to 2^13 bytes because we have limited ItemIdData.lp_off and
  * ItemIdData.lp_len to 13 bits (see itemid.h).
+ *
+ * limit is now 2^15.  Took four bits from ItemIdData.lp_flags and gave
+ * two apiece to ItemIdData.lp_len and lp_off. darrenk 01/06/98
+ *
  */
-#define MAXBLCKSZ		8192
 
-typedef void *Block;
+#define MAXBLCKSZ		32768
 
+typedef void *Block;
 
 /* special pageno for bget */
 #define P_NEW	InvalidBlockNumber		/* grow the file to get a new page */
diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h
index befb6b0849c9ecb1d0c8ef812e63f2af968ff9fc..6df6cdf734a8e8aea86ca6cb705e4c481c039046 100644
--- a/src/include/storage/bufpage.h
+++ b/src/include/storage/bufpage.h
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: bufpage.h,v 1.13 1997/09/08 21:54:20 momjian Exp $
+ * $Id: bufpage.h,v 1.14 1998/01/13 04:05:11 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -86,6 +86,9 @@
  *
  * note that this is actually limited to 2^13 because we have limited
  * ItemIdData.lp_off and ItemIdData.lp_len to 13 bits (see itemid.h).
+ *
+ * uint16 is still valid, but the limit has been raised to 15 bits.
+ * 06 Jan 98 - darrenk
  */
 typedef uint16 LocationIndex;
 
@@ -98,6 +101,9 @@ typedef uint16 LocationIndex;
  *						  page header, opaque space and a minimal tuple;
  *						  on the high end, we can only support pages up
  *						  to 8KB because lp_off/lp_len are 13 bits.
+ *
+ *						  see above comment.  Now use 15 bits and pages
+ *						  up to 32KB at your own risk.
  */
 typedef struct OpaqueData
 {
@@ -191,8 +197,11 @@ typedef enum
  *
  * XXX currently all page sizes are "valid" but we only actually
  *	   use BLCKSZ.
+ *
+ * 01/06/98 Now does something useful.  darrenk
+ *
  */
-#define PageSizeIsValid(pageSize) 1
+#define PageSizeIsValid(pageSize) ((pageSize) == BLCKSZ)
 
 /*
  * PageGetPageSize --
diff --git a/src/include/storage/itemid.h b/src/include/storage/itemid.h
index c6b0abc19bda97a51bb4ffcdea509491bec12fb9..7b683ab68c56837aec1ef31f7dc5cb2cfb8079fe 100644
--- a/src/include/storage/itemid.h
+++ b/src/include/storage/itemid.h
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: itemid.h,v 1.4 1997/09/08 21:54:24 momjian Exp $
+ * $Id: itemid.h,v 1.5 1998/01/13 04:05:12 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -22,10 +22,10 @@ typedef bits16 ItemIdFlags;
 
 typedef struct ItemIdData
 {								/* line pointers */
-	unsigned	lp_off:13,		/* offset to find tup */
+	unsigned	lp_off:15,		/* offset to find tup */
 	/* can be reduced by 2 if necc. */
-				lp_flags:6,		/* flags on tuple */
-				lp_len:13;		/* length of tuple */
+				lp_flags:2,		/* flags on tuple */
+				lp_len:15;		/* length of tuple */
 } ItemIdData;
 
 typedef struct ItemIdData *ItemId;