Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit71d5d95

Browse files
committed
Update hash and join routines to use fd.c's new temp-file
code, instead of not-very-bulletproof stuff they had before.
1 parentc1167a0 commit71d5d95

File tree

6 files changed

+75
-243
lines changed

6 files changed

+75
-243
lines changed

‎src/backend/access/nbtree/nbtsort.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*
77
* IDENTIFICATION
8-
* $Id: nbtsort.c,v 1.37 1999/02/21 03:48:27 scrappy Exp $
8+
* $Id: nbtsort.c,v 1.38 1999/05/09 00:53:19 tgl Exp $
99
*
1010
* NOTES
1111
*
@@ -85,11 +85,9 @@ static void _bt_uppershutdown(Relation index, BTPageState *state);
8585

8686
#defineMAXTAPES(7)
8787
#defineTAPEBLCKSZ(BLCKSZ << 2)
88-
#defineTAPETEMP"pg_btsortXXXXXXX"
8988

9089
externintNDirectFileRead;
9190
externintNDirectFileWrite;
92-
externchar*mktemp(char*template);
9391

9492
/*
9593
* this is what we use to shovel BTItems in and out of memory.it's
@@ -107,7 +105,7 @@ extern char *mktemp(char *template);
107105
typedefstruct
108106
{
109107
intbttb_magic;/* magic number */
110-
intbttb_fd;/* file descriptor */
108+
Filebttb_fd;/* file descriptor */
111109
intbttb_top;/* top of free space within bttb_data */
112110
shortbttb_ntup;/* number of tuples in this block */
113111
shortbttb_eor;/* End-Of-Run marker */
@@ -380,7 +378,7 @@ _bt_tapereset(BTTapeBlock *tape)
380378
staticvoid
381379
_bt_taperewind(BTTapeBlock*tape)
382380
{
383-
FileSeek(tape->bttb_fd,0,SEEK_SET);
381+
FileSeek(tape->bttb_fd,0L,SEEK_SET);
384382
}
385383

386384
/*
@@ -411,7 +409,7 @@ _bt_tapeclear(BTTapeBlock *tape)
411409
* as well as opening a physical tape file.
412410
*/
413411
staticBTTapeBlock*
414-
_bt_tapecreate(char*fname)
412+
_bt_tapecreate(void)
415413
{
416414
BTTapeBlock*tape= (BTTapeBlock*)palloc(sizeof(BTTapeBlock));
417415

@@ -420,11 +418,7 @@ _bt_tapecreate(char *fname)
420418

421419
tape->bttb_magic=BTTAPEMAGIC;
422420

423-
#ifndef__CYGWIN32__
424-
tape->bttb_fd=FileNameOpenFile(fname,O_RDWR |O_CREAT |O_TRUNC,0600);
425-
#else
426-
tape->bttb_fd=FileNameOpenFile(fname,O_RDWR |O_CREAT |O_TRUNC |O_BINARY,0600);
427-
#endif
421+
tape->bttb_fd=OpenTemporaryFile();
428422
Assert(tape->bttb_fd >=0);
429423

430424
/* initialize the buffer */
@@ -467,7 +461,7 @@ _bt_tapewrite(BTTapeBlock *tape, int eor)
467461
staticint
468462
_bt_taperead(BTTapeBlock*tape)
469463
{
470-
intfd;
464+
Filefd;
471465
intnread;
472466

473467
if (tape->bttb_eor)
@@ -550,9 +544,8 @@ _bt_spoolinit(Relation index, int ntapes, bool isunique)
550544
{
551545
BTSpool*btspool= (BTSpool*)palloc(sizeof(BTSpool));
552546
inti;
553-
char*fname= (char*)palloc(sizeof(TAPETEMP)+1);
554547

555-
if (btspool== (BTSpool*)NULL||fname== (char*)NULL)
548+
if (btspool== (BTSpool*)NULL)
556549
elog(ERROR,"_bt_spoolinit: out of memory");
557550
MemSet((char*)btspool,0,sizeof(BTSpool));
558551
btspool->bts_ntapes=ntapes;
@@ -567,10 +560,9 @@ _bt_spoolinit(Relation index, int ntapes, bool isunique)
567560

568561
for (i=0;i<ntapes;++i)
569562
{
570-
btspool->bts_itape[i]=_bt_tapecreate(mktemp(strcpy(fname,TAPETEMP)));
571-
btspool->bts_otape[i]=_bt_tapecreate(mktemp(strcpy(fname,TAPETEMP)));
563+
btspool->bts_itape[i]=_bt_tapecreate();
564+
btspool->bts_otape[i]=_bt_tapecreate();
572565
}
573-
pfree((void*)fname);
574566

575567
_bt_isortcmpinit(index,btspool);
576568

‎src/backend/executor/nodeHash.c

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $Id: nodeHash.c,v 1.33 1999/05/06 00:30:46 tgl Exp $
9+
* $Id: nodeHash.c,v 1.34 1999/05/09 00:53:20 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -39,9 +39,6 @@
3939

4040
externintNBuffers;
4141

42-
#defineHJ_TEMP_NAMELEN 16/* max length for mk_hj_temp file names */
43-
44-
staticvoidmk_hj_temp(char*tempname);
4542
staticinthashFunc(Datumkey,intlen,boolbyVal);
4643
staticRelativeAddrhashTableAlloc(intsize,HashJoinTablehashtable);
4744
staticvoid*absHashTableAlloc(intsize,HashJoinTablehashtable);
@@ -72,7 +69,6 @@ ExecHash(Hash *node)
7269
RelativeAddr*batchPos;
7370
int*batchSizes;
7471
inti;
75-
RelativeAddr*innerbatchNames;
7672

7773
/* ----------------
7874
*get state info from node
@@ -91,8 +87,6 @@ ExecHash(Hash *node)
9187

9288
if (nbatch>0)
9389
{/* if needs hash partition */
94-
innerbatchNames= (RelativeAddr*)ABSADDR(hashtable->innerbatchNames);
95-
9690
/* --------------
9791
*allocate space for the file descriptors of batch files
9892
*then open the batch files in the current processes.
@@ -101,13 +95,7 @@ ExecHash(Hash *node)
10195
batches= (File*)palloc(nbatch*sizeof(File));
10296
for (i=0;i<nbatch;i++)
10397
{
104-
#ifndef__CYGWIN32__
105-
batches[i]=FileNameOpenFile(ABSADDR(innerbatchNames[i]),
106-
O_CREAT |O_RDWR,0600);
107-
#else
108-
batches[i]=FileNameOpenFile(ABSADDR(innerbatchNames[i]),
109-
O_CREAT |O_RDWR |O_BINARY,0600);
110-
#endif
98+
batches[i]=OpenTemporaryFile();
11199
}
112100
hashstate->hashBatches=batches;
113101
batchPos= (RelativeAddr*)ABSADDR(hashtable->innerbatchPos);
@@ -291,7 +279,7 @@ absHashTableAlloc(int size, HashJoinTable hashtable)
291279
* ----------------------------------------------------------------
292280
*/
293281
#defineNTUP_PER_BUCKET10
294-
#defineFUDGE_FAC1.5
282+
#defineFUDGE_FAC2.0
295283

296284
HashJoinTable
297285
ExecHashTableCreate(Hash*node)
@@ -310,12 +298,9 @@ ExecHashTableCreate(Hash *node)
310298
inttotalbuckets;
311299
intbucketsize;
312300
inti;
313-
RelativeAddr*outerbatchNames;
314301
RelativeAddr*outerbatchPos;
315-
RelativeAddr*innerbatchNames;
316302
RelativeAddr*innerbatchPos;
317303
int*innerbatchSizes;
318-
RelativeAddrtempname;
319304

320305
/* ----------------
321306
*Get information about the size of the relation to be hashed
@@ -425,46 +410,32 @@ ExecHashTableCreate(Hash *node)
425410
*allocate and initialize the outer batches
426411
* ---------------
427412
*/
428-
outerbatchNames= (RelativeAddr*)
429-
absHashTableAlloc(nbatch*sizeof(RelativeAddr),hashtable);
430413
outerbatchPos= (RelativeAddr*)
431414
absHashTableAlloc(nbatch*sizeof(RelativeAddr),hashtable);
432415
for (i=0;i<nbatch;i++)
433416
{
434-
tempname=hashTableAlloc(HJ_TEMP_NAMELEN,hashtable);
435-
mk_hj_temp(ABSADDR(tempname));
436-
outerbatchNames[i]=tempname;
437417
outerbatchPos[i]=-1;
438418
}
439-
hashtable->outerbatchNames=RELADDR(outerbatchNames);
440419
hashtable->outerbatchPos=RELADDR(outerbatchPos);
441420
/* ---------------
442421
*allocate and initialize the inner batches
443422
* ---------------
444423
*/
445-
innerbatchNames= (RelativeAddr*)
446-
absHashTableAlloc(nbatch*sizeof(RelativeAddr),hashtable);
447424
innerbatchPos= (RelativeAddr*)
448425
absHashTableAlloc(nbatch*sizeof(RelativeAddr),hashtable);
449426
innerbatchSizes= (int*)
450427
absHashTableAlloc(nbatch*sizeof(int),hashtable);
451428
for (i=0;i<nbatch;i++)
452429
{
453-
tempname=hashTableAlloc(HJ_TEMP_NAMELEN,hashtable);
454-
mk_hj_temp(ABSADDR(tempname));
455-
innerbatchNames[i]=tempname;
456430
innerbatchPos[i]=-1;
457431
innerbatchSizes[i]=0;
458432
}
459-
hashtable->innerbatchNames=RELADDR(innerbatchNames);
460433
hashtable->innerbatchPos=RELADDR(innerbatchPos);
461434
hashtable->innerbatchSizes=RELADDR(innerbatchSizes);
462435
}
463436
else
464437
{
465-
hashtable->outerbatchNames= (RelativeAddr)NULL;
466438
hashtable->outerbatchPos= (RelativeAddr)NULL;
467-
hashtable->innerbatchNames= (RelativeAddr)NULL;
468439
hashtable->innerbatchPos= (RelativeAddr)NULL;
469440
hashtable->innerbatchSizes= (RelativeAddr)NULL;
470441
}
@@ -886,15 +857,6 @@ ExecHashTableReset(HashJoinTable hashtable, int ntuples)
886857
hashtable->pcount=hashtable->nprocess;
887858
}
888859

889-
staticvoid
890-
mk_hj_temp(char*tempname)
891-
{
892-
staticinthjtmpcnt=0;
893-
894-
snprintf(tempname,HJ_TEMP_NAMELEN,"HJ%d.%d", (int)MyProcPid,hjtmpcnt);
895-
hjtmpcnt= (hjtmpcnt+1) %1000;
896-
}
897-
898860
void
899861
ExecReScanHash(Hash*node,ExprContext*exprCtxt,Plan*parent)
900862
{

‎src/backend/executor/nodeHashjoin.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.18 1999/05/06 00:30:47 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.19 1999/05/09 00:53:21 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -74,7 +74,6 @@ ExecHashJoin(HashJoin *node)
7474
intnbatch;
7575
intcurbatch;
7676
File*outerbatches;
77-
RelativeAddr*outerbatchNames;
7877
RelativeAddr*outerbatchPos;
7978
Var*innerhashkey;
8079
intbatch;
@@ -166,21 +165,10 @@ ExecHashJoin(HashJoin *node)
166165
*/
167166
innerhashkey=hashNode->hashkey;
168167
hjstate->hj_InnerHashKey=innerhashkey;
169-
outerbatchNames= (RelativeAddr*)
170-
ABSADDR(hashtable->outerbatchNames);
171-
outerbatches= (File*)
172-
palloc(nbatch*sizeof(File));
168+
outerbatches= (File*)palloc(nbatch*sizeof(File));
173169
for (i=0;i<nbatch;i++)
174170
{
175-
#ifndef__CYGWIN32__
176-
outerbatches[i]=FileNameOpenFile(
177-
ABSADDR(outerbatchNames[i]),
178-
O_CREAT |O_RDWR,0600);
179-
#else
180-
outerbatches[i]=FileNameOpenFile(
181-
ABSADDR(outerbatchNames[i]),
182-
O_CREAT |O_RDWR |O_BINARY,0600);
183-
#endif
171+
outerbatches[i]=OpenTemporaryFile();
184172
}
185173
hjstate->hj_OuterBatches=outerbatches;
186174

@@ -193,7 +181,6 @@ ExecHashJoin(HashJoin *node)
193181
}
194182
outerbatchPos= (RelativeAddr*)ABSADDR(hashtable->outerbatchPos);
195183
curbatch=hashtable->curbatch;
196-
outerbatchNames= (RelativeAddr*)ABSADDR(hashtable->outerbatchNames);
197184

198185
/* ----------------
199186
*Now get an outer tuple and probe into the hash table for matches

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp