1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* hashjoin.h
|
1999-05-18 23:33:06 +02:00
|
|
|
* internal structures for hash joins
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
2001-01-24 20:43:33 +01:00
|
|
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2001-11-05 18:46:40 +01:00
|
|
|
* $Id: hashjoin.h,v 1.25 2001/11/05 17:46:33 momjian Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef HASHJOIN_H
|
1996-07-09 08:22:35 +02:00
|
|
|
#define HASHJOIN_H
|
|
|
|
|
1999-05-18 23:33:06 +02:00
|
|
|
#include "access/htup.h"
|
1999-10-13 17:02:32 +02:00
|
|
|
#include "storage/buffile.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1999-05-18 23:33:06 +02:00
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
* hash-join hash table structures
|
|
|
|
*
|
|
|
|
* Each active hashjoin has a HashJoinTable control block which is
|
2000-07-12 04:37:39 +02:00
|
|
|
* palloc'd in the executor's per-query context. All other storage needed
|
|
|
|
* for the hashjoin is kept in private memory contexts, two for each hashjoin.
|
1999-05-18 23:33:06 +02:00
|
|
|
* This makes it easy and fast to release the storage when we don't need it
|
|
|
|
* anymore.
|
|
|
|
*
|
2000-08-22 06:06:22 +02:00
|
|
|
* The hashtable contexts are made children of the per-query context, ensuring
|
2000-06-28 05:33:33 +02:00
|
|
|
* that they will be discarded at end of statement even if the join is
|
1999-05-18 23:33:06 +02:00
|
|
|
* aborted early by an error. (Likewise, any temporary files we make will
|
|
|
|
* be cleaned up by the virtual file manager in event of an error.)
|
1999-05-06 02:30:47 +02:00
|
|
|
*
|
1999-05-18 23:33:06 +02:00
|
|
|
* Storage that should live through the entire join is allocated from the
|
2000-06-28 05:33:33 +02:00
|
|
|
* "hashCxt", while storage that is only wanted for the current batch is
|
|
|
|
* allocated in the "batchCxt". By resetting the batchCxt at the end of
|
|
|
|
* each batch, we free all the per-batch storage reliably and without tedium.
|
1999-05-18 23:33:06 +02:00
|
|
|
* ----------------------------------------------------------------
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
|
1999-05-18 23:33:06 +02:00
|
|
|
typedef struct HashJoinTupleData
|
|
|
|
{
|
1999-05-25 18:15:34 +02:00
|
|
|
struct HashJoinTupleData *next; /* link to next tuple in same
|
|
|
|
* bucket */
|
|
|
|
HeapTupleData htup; /* tuple header */
|
1999-05-26 00:43:53 +02:00
|
|
|
} HashJoinTupleData;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1999-05-18 23:33:06 +02:00
|
|
|
typedef HashJoinTupleData *HashJoinTuple;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct HashTableData
|
|
|
|
{
|
1999-05-18 23:33:06 +02:00
|
|
|
int nbuckets; /* buckets in use during this batch */
|
|
|
|
int totalbuckets; /* total number of (virtual) buckets */
|
1999-05-25 18:15:34 +02:00
|
|
|
HashJoinTuple *buckets; /* buckets[i] is head of list of tuples */
|
1999-05-18 23:33:06 +02:00
|
|
|
/* buckets array is per-batch storage, as are all the tuples */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1999-05-18 23:33:06 +02:00
|
|
|
int nbatch; /* number of batches; 0 means 1-pass join */
|
|
|
|
int curbatch; /* current batch #, or 0 during 1st pass */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1999-05-25 18:15:34 +02:00
|
|
|
/*
|
|
|
|
* all these arrays are allocated for the life of the hash join, but
|
|
|
|
* only if nbatch > 0:
|
1999-05-18 23:33:06 +02:00
|
|
|
*/
|
1999-05-25 18:15:34 +02:00
|
|
|
BufFile **innerBatchFile; /* buffered virtual temp file per batch */
|
|
|
|
BufFile **outerBatchFile; /* buffered virtual temp file per batch */
|
|
|
|
long *outerBatchSize; /* count of tuples in each outer batch
|
|
|
|
* file */
|
|
|
|
long *innerBatchSize; /* count of tuples in each inner batch
|
|
|
|
* file */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-07-12 04:37:39 +02:00
|
|
|
/*
|
2001-03-22 05:01:46 +01:00
|
|
|
* Info about the datatype being hashed. We assume that the inner and
|
|
|
|
* outer sides of the hash are the same type, or at least
|
2000-07-12 04:37:39 +02:00
|
|
|
* binary-compatible types.
|
|
|
|
*/
|
2000-11-16 23:30:52 +01:00
|
|
|
int16 typLen;
|
2000-07-12 04:37:39 +02:00
|
|
|
bool typByVal;
|
|
|
|
|
1999-05-25 18:15:34 +02:00
|
|
|
/*
|
|
|
|
* During 1st scan of inner relation, we get tuples from executor. If
|
|
|
|
* nbatch > 0 then tuples that don't belong in first nbuckets logical
|
|
|
|
* buckets get dumped into inner-batch temp files. The same statements
|
|
|
|
* apply for the 1st scan of the outer relation, except we write
|
|
|
|
* tuples to outer-batch temp files. If nbatch > 0 then we do the
|
|
|
|
* following for each batch: 1. Read tuples from inner batch file,
|
|
|
|
* load into hash buckets. 2. Read tuples from outer batch file, match
|
|
|
|
* to hash buckets and output.
|
1999-05-18 23:33:06 +02:00
|
|
|
*/
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1999-05-25 18:15:34 +02:00
|
|
|
MemoryContext hashCxt; /* context for whole-hash-join storage */
|
|
|
|
MemoryContext batchCxt; /* context for this-batch-only storage */
|
1999-05-18 23:33:06 +02:00
|
|
|
} HashTableData;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1999-05-18 23:33:06 +02:00
|
|
|
typedef HashTableData *HashJoinTable;
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* HASHJOIN_H */
|