⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chunk.c

📁 关系型数据库 Postgresql 6.5.2
💻 C
📖 第 1 页 / 共 2 页
字号:
	int			start_pos,				pos[MAXDIM];	int			indx[MAXDIM];	int			fpOff;	for (i = start_pos = 0; i < n; i++)	{		pos[i] = chunk_no[i] * C[i];		start_pos += pos[i] * PX[i];	}	start_pos *= baseSize;	/* Read a block of dimesion C starting at co-ordinates pos */	unit_transfer = C[n - 1] * baseSize;	for (i = 0; i < n; indx[i++] = 0)		;	fpOff = start_pos;	seek_and_read(fpOff, unit_transfer, a_chunk, srcfd, SEEK_SET);	fpOff += unit_transfer;	cp = unit_transfer;	while ((j = next_tuple(n - 1, indx, C)) != -1)	{		fpOff += dist[j];		seek_and_read(fpOff, unit_transfer, &(a_chunk[cp]), srcfd, SEEK_SET);		cp += unit_transfer;		fpOff += unit_transfer;	}}/*-------------------------------------------------------------------------- * write_chunk() *	  writes a chunk of size csize into the output file *-------------------------------------------------------------------------- */static intwrite_chunk(struct varlena * a_chunk, int ofile){	int			got_n = 0;#ifdef LOARRAY	got_n = LOwrite(ofile, a_chunk);#endif	return got_n;}/*-------------------------------------------------------------------------- * seek_and_read() *	  seeks to the asked location in the input file and reads the *	  appropriate number of blocks *	 Called By: read_chunk() *-------------------------------------------------------------------------- */static intseek_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(ERROR, "File seek error");#ifdef LOARRAY	v = (struct varlena *) LOread(fp, size);#endif	if (VARSIZE(v) - VARHDRSZ < size)		elog(ERROR, "File read error");	memmove(buff, VARDATA(v), size);	pfree(v);	return 1;}#endif	 /* LOARRAY *//*---------------------------------------------------------------------------- * _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,				int bsize,				int fp,				char *destfp,				ArrayType *array,				int isDestLO,				bool *isNull){	int			i,				j,				jj;	int			n,				temp,				words_read;	int			chunk_span[MAXDIM],				chunk_off[MAXDIM];	int			chunk_st[MAXDIM],				chunk_end[MAXDIM];	int			block_seek;	int			bptr,			   *C,				csize,			   *dim,			   *lb;	int			range_st[MAXDIM],				range_end[MAXDIM],				range[MAXDIM],				array_span[MAXDIM];	int			PA[MAXDIM],				PCHUNK[MAXDIM],				PC[MAXDIM];	int			to_read;	int			cdist[MAXDIM],				adist[MAXDIM];	int			dist[MAXDIM],				temp_seek;	int			srcOff;			/* Needed since LO don't understand								 * SEEK_CUR */	char	   *baseDestFp = (char *) destfp;	CHUNK_INFO *A = (CHUNK_INFO *) ARR_DATA_PTR(array);	n = ARR_NDIM(array);	dim = ARR_DIMS(array);	lb = ARR_LBOUND(array);	C = A->C;	csize = C[n - 1];	PC[n - 1] = 1;	temp = dim[n - 1] / C[n - 1];	for (i = n - 2; i >= 0; i--)	{		PC[i] = PC[i + 1] * temp;		temp = dim[i] / C[i];		csize *= C[i];	}	for (i = 0; i < n; st[i] -= lb[i], endp[i] -= lb[i], i++)		;	mda_get_prod(n, C, PCHUNK);	mda_get_range(n, array_span, st, endp);	mda_get_prod(n, array_span, PA);	array2chunk_coord(n, C, st, chunk_st);	array2chunk_coord(n, C, endp, chunk_end);	mda_get_range(n, chunk_span, chunk_st, chunk_end);	mda_get_offset_values(n, dist, PC, chunk_span);	for (i = 0; i < n; i++)	{		range_st[i] = st[i];		range_end[i] = min(chunk_st[i] * C[i] + C[i] - 1, endp[i]);	}	for (i = j = 0; i < n; i++)		j += chunk_st[i] * PC[i];	temp_seek = srcOff = j * csize * bsize;	if (lo_lseek(fp, srcOff, SEEK_SET) < 0)		RETURN_NULL;	jj = n - 1;	for (i = 0; i < n; chunk_off[i++] = 0)		;	words_read = 0;	temp_seek = 0;	do	{		/* Write chunk (chunk_st) to output buffer */		mda_get_range(n, array_span, range_st, range_end);		mda_get_offset_values(n, adist, PA, array_span);		mda_get_offset_values(n, cdist, PCHUNK, array_span);		for (i = 0; i < n; range[i] = range_st[i] - st[i], i++);		bptr = tuple2linear(n, range, PA);		for (i = 0; i < n; range[i++] = 0);		j = n - 1;		bptr *= bsize;		if (isDestLO)		{			if (lo_lseek((int) destfp, bptr, SEEK_SET) < 0)				RETURN_NULL;		}		else			destfp = baseDestFp + bptr;		for (i = 0, block_seek = 0; i < n; i++)			block_seek += (range_st[i] - (chunk_st[i] + chunk_off[i])						   * C[i]) * PCHUNK[i];		if (dist[jj] + block_seek + temp_seek)		{			temp = (dist[jj] * csize + block_seek + temp_seek) * bsize;			srcOff += temp;			if (lo_lseek(fp, srcOff, SEEK_SET) < 0)				RETURN_NULL;		}		for (i = n - 1, to_read = bsize; i >= 0;			 to_read *= min(C[i], array_span[i]), i--)			if (cdist[i] || adist[i])				break;		do		{			if (cdist[j])			{				srcOff += (cdist[j] * bsize);				if (lo_lseek(fp, srcOff, SEEK_SET) < 0)					RETURN_NULL;			}			block_seek += cdist[j];			bptr += adist[j] * bsize;			if (isDestLO)			{				if (lo_lseek((int) destfp, bptr, SEEK_SET) < 0)					RETURN_NULL;			}			else				destfp = baseDestFp + bptr;			temp = _LOtransfer((char **) &destfp, to_read, 1, (char **) &fp, 1, isDestLO);			if (temp < to_read)				RETURN_NULL;			srcOff += to_read;			words_read += to_read;			bptr += to_read;			block_seek += (to_read / bsize);			/*			 * compute next tuple in *range			 */			{				int			x;				if (!(i + 1))					j = -1;				else				{					range[i] = (range[i] + 1) % array_span[i];					for (x = i; x * (!range[x]); x--)						range[x - 1] = (range[x - 1] + 1) % array_span[x - 1];					if (x)						j = x;					else					{						if (range[0])							j = 0;						else							j = -1;					}				}			}			/*			 * end of compute next tuple -- j is set to -1 if tuple			 * generation is over			 */		} while (j != -1);		block_seek = csize - block_seek;		temp_seek = block_seek;		jj = next_tuple(n, chunk_off, chunk_span);		if (jj == -1)			break;		range_st[jj] = (chunk_st[jj] + chunk_off[jj]) * C[jj];		range_end[jj] = min(range_st[jj] + C[jj] - 1, endp[jj]);		for (i = jj + 1; i < n; i++)		{			range_st[i] = st[i];			range_end[i] = min((chunk_st[i] + chunk_off[i]) * C[i] + C[i] - 1, endp[i]);		}	} while (jj != -1);	return words_read;}/*------------------------------------------------------------------------ * _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,				   int bsize,				   int fp,				   ArrayType *array,				   bool *isNull){	int			i,				j,				n,				temp,				srcOff;	int			chunk_st[MAXDIM];	int		   *C,				csize,			   *dim,			   *lb;	int			PCHUNK[MAXDIM],				PC[MAXDIM];	CHUNK_INFO *A = (CHUNK_INFO *) ARR_DATA_PTR(array);	n = ARR_NDIM(array);	lb = ARR_LBOUND(array);	C = A->C;	dim = ARR_DIMS(array);	csize = C[n - 1];	PC[n - 1] = 1;	temp = dim[n - 1] / C[n - 1];	for (i = n - 2; i >= 0; i--)	{		PC[i] = PC[i + 1] * temp;		temp = dim[i] / C[i];		csize *= C[i];	}	for (i = 0; i < n; st[i] -= lb[i], i++);	mda_get_prod(n, C, PCHUNK);	array2chunk_coord(n, C, st, chunk_st);	for (i = j = 0; i < n; i++)		j += chunk_st[i] * PC[i];	srcOff = j * csize;	for (i = 0; i < n; i++)		srcOff += (st[i] - chunk_st[i] * C[i]) * PCHUNK[i];	srcOff *= bsize;	if (lo_lseek(fp, srcOff, SEEK_SET) < 0)		RETURN_NULL;#ifdef LOARRAY	return (struct varlena *) LOread(fp, bsize);#endif	return (struct varlena *) 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -