/*-------------------------------------------------------------------------
*
- * chunk.c--
+ * chunk.c
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/chunk.c,v 1.11 1997/12/06 22:57:12 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/chunk.c,v 1.23 1999/07/17 20:17:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
-#include <libpq/be-fsstubs.h>
-#include "utils/memutils.h"
-#include "libpq/libpq-fs.h"
-
-#include "storage/fd.h" /* for SEEK_ */
-
#include "catalog/pg_type.h"
-
#include "fmgr.h"
-#include "utils/array.h"
-
+#include "libpq/be-fsstubs.h"
+#include "libpq/libpq-fs.h"
#include "optimizer/internal.h"
-#ifndef HAVE_MEMMOVE
-#include <regex/utils.h>
-#else
-#include <string.h>
-#endif
-
+#include "utils/array.h"
+#include "utils/memutils.h"
#define INFTY 500000000
#define MANY 10000
static CHUNK_INFO cInfo;
/* non-export function prototypes */
-static int
-_FindBestChunk(int size, int dmax[], int dbest[], int dim,
+static int _FindBestChunk(int size, int *dmax, int *dbest, int dim,
int A[MAXPAT][MAXDIM + 1], int N);
-static int get_next(int d[], int k, int C, int dmax[]);
-static void initialize_info(CHUNK_INFO *A, int ndim, int dim[], int chunk[]);
+static int get_next(int *d, int k, int C, int *dmax);
+static void initialize_info(CHUNK_INFO *A, int ndim, int *dim, int *chunk);
#ifdef LOARRAY
-static void
-_ConvertToChunkFile(int n, int baseSize, int dim[], int C[],
+static void _ConvertToChunkFile(int n, int baseSize, int *dim, int *C,
int srcfd, int destfd);
-static void
-read_chunk(int chunk_no[], int C[], char a_chunk[], int srcfd,
- int n, int baseSize, int PX[], int dist[]);
+static void read_chunk(int *chunk_no, int *C, char *a_chunk, int srcfd,
+ int n, int baseSize, int *PX, int *dist);
static int write_chunk(struct varlena * a_chunk, int ofile);
-static int seek_and_read(int pos, int size, char buff[], int fp, int from);
+static int seek_and_read(int pos, int size, char *buff, int fp, int from);
#endif
-static int
-GetChunkSize(FILE *fd, int ndim, int dim[MAXDIM], int baseSize,
+static int GetChunkSize(FILE *fd, int ndim, int dim[MAXDIM], int baseSize,
int d[MAXDIM]);
/*------------------------------------------------------------------------
* information about the chunked file
*-----------------------------------------------------------------------
*/
-char *
+char *
_ChunkArray(int fd,
FILE *afd,
int ndim,
- int dim[],
+ int *dim,
int baseSize,
int *nbytes,
char *chunkfile)
else
cfd = LOopen(chunkfile, O_RDONLY);
if (cfd < 0)
- elog(WARN, "Unable to open chunk file");
+ elog(ERROR, "Unable to open chunk file");
#endif
strcpy(cInfo.lo_name, chunkfile);
}
/*--------------------------------------------------------------------------
- * GetChunkSize --
+ * GetChunkSize
* given an access pattern and array dimensionality etc, this program
* returns the dimensions of the chunk in "d"
*-----------------------------------------------------------------------
*/
fscanf(fd, "%d", &N);
if (N > MAXPAT)
- elog(WARN, "array_in: too many access pattern elements");
+ elog(ERROR, "array_in: too many access pattern elements");
for (i = 0; i < N; i++)
for (j = 0; j < ndim + 1; j++)
if (fscanf(fd, "%d ", &(A[i][j])) == EOF)
- elog(WARN, "array_in: bad access pattern input");
+ elog(ERROR, "array_in: bad access pattern input");
/*
* estimate chunk size
}
/*-------------------------------------------------------------------------
- * _FindBestChunk --
+ * _FindBestChunk
* This routine does most of the number crunching to compute the
* optimal chunk shape.
* Called by GetChunkSize
*/
static int
_FindBestChunk(int size,
- int dmax[],
- int dbest[],
+ int *dmax,
+ int *dbest,
int dim,
int A[MAXPAT][MAXDIM + 1],
int N)
{
/*
- * compute the number of page fetches for a given chunk size (d[])
- * and access pattern (A[][])
+ * compute the number of page fetches for a given chunk size (*d)
+ * and access pattern (**A)
*/
- register int i,
+ int i,
j,
nc;
;
}
}
- return (mintc);
+ return mintc;
}
/*----------------------------------------------------------------------
- * get_next --
+ * get_next
* Called by _GetBestChunk to get the next tuple in the lexicographic order
*---------------------------------------------------------------------
*/
static int
-get_next(int d[], int k, int C, int dmax[])
+get_next(int *d, int k, int C, int *dmax)
{
- register int i,
+ int i,
j,
temp;
d[j] = min(temp, dmax[j]);
temp = max(1, temp / d[j]);
}
- return (1);
+ return 1;
}
for (j = 0, temp = 1; j < k; j++)
break;
}
if (i < 0)
- return (0);
+ return 0;
d[i]++;
j = C / temp;
d[j] = min(temp, dmax[j]);
temp = max(1, temp / d[j]);
}
- return (1);
+ return 1;
}
#ifdef LOARRAY
-static char a_chunk[BLCKSZ + VARHDRSZ];/* VARHDRSZ since a_chunk is in varlena format */
+static char a_chunk[BLCKSZ + VARHDRSZ]; /* VARHDRSZ since a_chunk is in
+ * varlena format */
#endif
static void
-initialize_info(CHUNK_INFO *A, int ndim, int dim[], int chunk[])
+initialize_info(CHUNK_INFO *A, int ndim, int *dim, int *chunk)
{
int i;
static void
_ConvertToChunkFile(int n,
int baseSize,
- int dim[],
- int C[],
+ int *dim,
+ int *C,
int srcfd,
int destfd)
{
*--------------------------------------------------------------------------
*/
static void
-read_chunk(int chunk_no[],
- int C[],
- char a_chunk[],
+read_chunk(int *chunk_no,
+ int *C,
+ char *a_chunk,
int srcfd,
int n,
int baseSize,
- int PX[],
- int dist[])
+ int *PX,
+ int *dist)
{
int i,
j,
#ifdef LOARRAY
got_n = LOwrite(ofile, a_chunk);
#endif
- return (got_n);
+ return got_n;
}
/*--------------------------------------------------------------------------
*--------------------------------------------------------------------------
*/
static int
-seek_and_read(int pos, int size, char buff[], int fp, int from)
+seek_and_read(int pos, int size, char *buff, int fp, int from)
{
struct varlena *v = NULL;
/* Assuming only one file */
if (lo_lseek(fp, pos, from) < 0)
- elog(WARN, "File seek error");
+ elog(ERROR, "File seek error");
#ifdef LOARRAY
v = (struct varlena *) LOread(fp, size);
#endif
if (VARSIZE(v) - VARHDRSZ < size)
- elog(WARN, "File read error");
+ elog(ERROR, "File read error");
memmove(buff, VARDATA(v), size);
pfree(v);
- return (1);
+ return 1;
}
-#endif /* LOARRAY */
+#endif /* LOARRAY */
/*----------------------------------------------------------------------------
- * _ReadChunkArray --
+ * _ReadChunkArray
* returns the subarray specified bu the range indices "st" and "endp"
* from the chunked array stored in file "fp"
*---------------------------------------------------------------------------
*/
int
-_ReadChunkArray(int st[],
- int endp[],
+_ReadChunkArray(int *st,
+ int *endp,
int bsize,
int fp,
char *destfp,
block_seek += (to_read / bsize);
/*
- * compute next tuple in range[]
+ * compute next tuple in *range
*/
{
int x;
range_end[i] = min((chunk_st[i] + chunk_off[i]) * C[i] + C[i] - 1, endp[i]);
}
} while (jj != -1);
- return (words_read);
+ return words_read;
}
/*------------------------------------------------------------------------
- * _ReadChunkArray1El --
+ * _ReadChunkArray1El
* returns one element of the chunked array as specified by the index "st"
* the chunked file descriptor is "fp"
*-------------------------------------------------------------------------
*/
struct varlena *
-_ReadChunkArray1El(int st[],
+_ReadChunkArray1El(int *st,
int bsize,
int fp,
ArrayType *array,