diff options
| author | Neil Conway <neilc@samurai.com> | 2005-06-15 07:27:44 +0000 |
|---|---|---|
| committer | Neil Conway <neilc@samurai.com> | 2005-06-15 07:27:44 +0000 |
| commit | c119c5bd49baa424480bd9e8f9dda69a09f5a572 (patch) | |
| tree | c9466886d6e4b74506ce7f6fe190efb34d63dd2e /src/include/nodes/execnodes.h | |
| parent | 4aaff553597222467769dd3b26e0d56c9c4a9b09 (diff) | |
| download | postgresql-c119c5bd49baa424480bd9e8f9dda69a09f5a572.tar.gz | |
Change the implementation of hash join to attempt to avoid unnecessary
work if either of the join relations are empty. The logic is:
(1) if the inner relation's startup cost is less than the outer
relation's startup cost and this is not an outer join, read
a single tuple from the inner relation via ExecHash()
- if NULL, we're done
(2) read a single tuple from the outer relation
- if NULL, we're done
(3) build the hash table on the inner relation
- if hash table is empty and this is not an outer join,
we're done
(4) otherwise, do hash join as usual
The implementation uses the new MultiExecProcNode API, per a
suggestion from Tom: invoking ExecHash() now produces the first
tuple from the Hash node's child node, whereas MultiExecHash()
builds the hash table.
I had to put in a bit of a kludge to get the row count returned
for EXPLAIN ANALYZE to be correct: since ExecHash() is invoked to
return a tuple, and then MultiExecHash() is invoked, we would
return one too many tuples to EXPLAIN ANALYZE. I hacked around
this by just manually detecting this situation and subtracting 1
from the EXPLAIN ANALYZE row count.
Diffstat (limited to 'src/include/nodes/execnodes.h')
| -rw-r--r-- | src/include/nodes/execnodes.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index b92eb1722f..19f264119c 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.133 2005/05/14 21:29:23 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.134 2005/06/15 07:27:44 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -1218,6 +1218,7 @@ typedef struct HashState HashJoinTable hashtable; /* hash table for the hashjoin */ List *hashkeys; /* list of ExprState nodes */ /* hashkeys is same as parent's hj_InnerHashKeys */ + TupleTableSlot *firstTuple; /* tuple produced by ExecHash() */ } HashState; /* ---------------- |
