head	1.9;
access;
symbols
	Version_2_1:1.8
	Version_2:1.7
	C_Demo_1:1.3;
locks; strict;
comment	@ * @;


1.9
date	91.07.22.22.20.38;	author mao;	state Exp;
branches;
next	1.8;

1.8
date	90.08.08.08.35.46;	author cimarron;	state Exp;
branches;
next	1.7;

1.7
date	90.06.07.18.20.57;	author cimarron;	state Version_2;
branches;
next	1.6;

1.6
date	90.02.12.19.52.12;	author cimarron;	state Exp;
branches;
next	1.5;

1.5
date	89.10.07.11.08.17;	author hirohama;	state Exp;
branches;
next	1.4;

1.4
date	89.09.28.17.12.18;	author hirohama;	state Exp;
branches;
next	1.3;

1.3
date	89.09.05.16.54.50;	author mao;	state C_Demo_1;
branches;
next	1.2;

1.2
date	89.02.02.16.59.48;	author dillon;	state Stab;
branches;
next	1.1;

1.1
date	89.01.17.05.58.20;	author cimarron;	state Exp;
branches;
next	;


desc
@@


1.9
log
@jukebox storage manager installation
@
text
@/*
 * testpsort.c --
 *	Polyphase merge sort test code.
 */

#include <stdio.h>

#include "c.h"

RcsId("$Header: /users/mao/postgres/src/test/RCS/testpsort.c,v 1.8 1990/08/08 08:35:46 cimarron Exp mao $");

#include "aset.h"
#include "buf.h"
#include "catname.h"
#include "heapam.h"
#include "htup.h"
#include "log.h"
#include "oid.h"
#include "portal.h"	/* for {Start,End}PortalAllocMode */
#include "rel.h"
#include "relscan.h"
#include "skey.h"
#include "tqual.h"

#include "storage/smgr.h"

/*
 * DoSetSortParameters --
 *	Initializes the sort parameters.
 */
extern
void
DoSetSortParameters ARGS((
	void
));

/*
 * DoCreateNewRelation --
 *	Creates a result relation.
 */
extern
void
DoCreateNewRelation ARGS((
	void
));

/*
 * DoShowRelation --
 *	Displays the contents of a relation.
 */
extern
void
DoShowRelation ARGS((
	Relation	relation
));

/*
 * DoShowHeapTuple --
 *	Displays an heap tuple.
 */
extern
void
DoShowHeapTuple ARGS((
	HeapTuple	tuple,
	Buffer		buffer,
	Relation	relation
));

/*
 * DoShowAttributeValue --
 *	Displays an attribute value.
 */
extern
void
DoShowAttributeValue ARGS((
	char		*value,
	ObjectId	typeId
));

/*
 * DoQuit --
 *	Quit.
 */
extern
void
DoQuit ARGS((
	void
));

#define MAXKEYSIZE	16

static Relation		OldRelation;
static Relation		NewRelation;
static NameData		RelationNameData;
static ScanKeySize	NumberOfKeys;
static ScanKeyEntryData	KeyData[MAXKEYSIZE];
static ScanKey		Key = (ScanKey)KeyData;

TestMain()
{
	static	int			beenHere = 0;

	if (beenHere == 0) {
		beenHere = 1;

		StartTransactionCommand();
	} else {
		elog(FATAL, "testpsort: giving up!");
	}

	for (;;) {
		StartPortalAllocMode(StaticAllocMode);

		DoSetSortParameters();

		DoShowRelation(OldRelation);

		DoCreateNewRelation();

		psort(OldRelation, NewRelation, NumberOfKeys, Key);

		RelationCloseHeapRelation(OldRelation);

		setheapoverride(true);	/* XXX */
		DoShowRelation(NewRelation);
		setheapoverride(false);	/* XXX */

		RelationCloseHeapRelation(NewRelation);

		EndPortalAllocMode();

		CommitTransactionCommand();
		StartTransactionCommand();
	}
}

void
DoSetSortParameters()
{
	int		i;
	char		buf[120];

	printf("Please enter the name of an existant relation: ");
	if (scanf("%s", buf) < 1) {
		DoQuit();
	}
	strncpy(&RelationNameData, buf, 16);

	OldRelation = RelationNameOpenHeapRelation(&RelationNameData);

	printf("Please enter the name of an non-existant relation: ");
	if (scanf("%s", buf) < 1) {
		DoQuit();
	}
	strncpy(&RelationNameData, buf, 16);

	printf("Please enter the key size (<= %d): ", MAXKEYSIZE);
	if (scanf("%hd", &NumberOfKeys) < 1) {
		DoQuit();
	}
	if (NumberOfKeys < 1 || NumberOfKeys > MAXKEYSIZE) {
		fprintf(stderr, "Invalid key size %d\n", NumberOfKeys);
		exitpg(1);
	}

	printf("Please enter sets of attribute numbers, flags, and procedure ids\n");
	for (i = 0; i < NumberOfKeys; i += 1) {
		printf("Key %02d: ", i);
		if (scanf("%hd %hd %d", &KeyData[i].attributeNumber,
			&KeyData[i].flags, &KeyData[i].procedure) < 3) {
			DoQuit();
		}
	}
}

void
DoCreateNewRelation()
{
	RelationNameCreateHeapRelation(&RelationNameData, 'n',
		OldRelation->rd_rel->relnatts,
		DEFAULT_SMGR,
		RelationGetTupleDescriptor(OldRelation));
	setheapoverride(true);		/* XXX */
	NewRelation = RelationNameOpenHeapRelation(&RelationNameData);
	setheapoverride(false);		/* XXX */
}

void
DoShowRelation(relation)
	Relation	relation;
{
	HeapScanDesc	scan;
	HeapTuple	tuple;
	Buffer		buffer;

	printf("----START(%s)----\n", &relation->rd_rel->relname);

	scan = RelationBeginHeapScan(relation, 0, NowTimeQual, 0,
		(ScanKey)NULL);

	while (HeapTupleIsValid(tuple =
			HeapScanGetNextTuple(scan, 0, &buffer))) {

		DoShowHeapTuple(tuple, buffer, relation);
	}

	HeapScanEnd(scan);

	printf("----END(%s)----\n", &relation->rd_rel->relname);
}

void
DoShowHeapTuple(tuple, buffer, relation)
	HeapTuple	tuple;
	Buffer		buffer;
	Relation	relation;
{
	char		*value, *fmgr(), *amgetattr(), *abstimeout();
	Boolean		isnull;
	int		i, typeindex;

	printf("< ");

	for (i = 0; i < relation->rd_rel->relnatts; i++) {
		value = amgetattr(tuple, buffer, 1 + i,
			&relation->rd_att.data[0], &isnull);
		if (isnull) {
			printf("<NULL> ");
		} else {
			DoShowAttributeValue(value,
				relation->rd_att.data[i]->atttypid);
			printf(" ");
		}
	}
	printf(">\n");
}

void
DoShowAttributeValue(value, typeId)
	char		*value;
	ObjectId	typeId;
{
	HeapTuple		tuple;

	static struct catcache	*typeCache = NULL;
	extern HeapTuple	SearchSysCache();
	extern struct catcache	*InitSysCache();
	extern char		*fmgr();

	if (typeCache == NULL) {
		int	key = ObjectIdAttributeNumber;

		typeCache = InitSysCache(TypeRelationName, 1, &key);
	}

	tuple = SearchSysCache(typeCache, typeId);

	if (!HeapTupleIsValid(tuple)) {
		elog(WARN, "testbtree: unknown type #%ld\n", typeId);
	}
	value = fmgr(((struct type *)HeapTupleGetForm(tuple))->typoutput,
		value);
	printf("%s", value);
}

void
DoQuit()
{
	CommitTransactionCommand();

	printf("\nDone!\n");
	exitpg(0);
}
@


1.8
log
@reorganized some header files and fixed some problems with
old style use of datums.
@
text
@d10 1
a10 1
RcsId("$Header: RCS/testpsort.c,v 1.7 90/06/07 18:20:57 cimarron Version_2 Locker: cimarron $");
d25 2
d181 1
@


1.7
log
@made changes to simplify header include files
@
text
@d10 1
a10 1
RcsId("$Header: RCS/testpsort.c,v 1.6 90/02/12 19:52:12 cimarron Exp $");
a13 1
#include "cat.h"
@


1.6
log
@added buffer manager statistics and exitpg() stuff -cim
@
text
@d10 1
a10 1
RcsId("$Header: RCS/testpsort.c,v 1.5 89/10/07 11:08:17 hirohama Exp $");
d14 1
a14 1
#include "catalog.h"
@


1.5
log
@now commits its changes after each pass
@
text
@d10 1
a10 1
RcsId("$Header: RCS/testpsort.c,v 1.4 89/09/28 17:12:18 hirohama Exp Locker: hirohama $");
d162 1
a162 1
		exit(1);
d270 1
a270 1
	exit(0);
@


1.4
log
@made it up-to-date
@
text
@d10 1
a10 1
RcsId("$Header: RCS/testpsort.c,v 1.3 89/09/05 16:54:50 mao C_Demo_1 Locker: hirohama $");
d130 3
d267 2
@


1.3
log
@Working version of C-only demo
@
text
@a7 2
#include "fmgr.h"	/* XXX for M_STATIC */

d10 3
d20 1
d22 1
a25 2
RcsId("$Header: /usr6/postgres/mao/postgres/src/test/RCS/testpsort.c,v 1.2 89/02/02 16:59:48 dillon Stab $");

d111 1
a111 1
		startmmgr(M_STATIC);
d129 1
a129 1
		endmmgr(NULL);
d187 1
a187 1
	HeapScan	scan;
@


1.2
log
@Txfer from old tree
@
text
@d23 1
a23 1
RcsId("$Header: testpsort.c,v 1.2 88/07/20 23:36:21 dillon Locked $");
@


1.1
log
@Initial revision
@
text
@a0 1

a1 26
 * 
 * POSTGRES Data Base Management System
 * 
 * Copyright (c) 1988 Regents of the University of California
 * 
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for educational, research, and non-profit purposes and
 * without fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright notice and
 * this permission notice appear in supporting documentation, and that
 * the name of the University of California not be used in advertising
 * or publicity pertaining to distribution of the software without
 * specific, written prior permission.  Permission to incorporate this
 * software into commercial products can be obtained from the Campus
 * Software Office, 295 Evans Hall, University of California, Berkeley,
 * Ca., 94720 provided only that the the requestor give the University
 * of California a free licence to any derived software for educational
 * and research purposes.  The University of California makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 * 
 */



/*
d23 1
a23 1
RcsId("$Header: testpsort.c,v 1.1 88/11/11 16:41:49 postgres Exp $");
@
