diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-03-16 23:15:08 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-03-16 23:15:08 +0000 |
| commit | 787eba734be8e1fb8c5fdb101a02e826cccec3e9 (patch) | |
| tree | 511dc9dc0fc8e2f04c2e4862eb9e8348ee87396a /src/include | |
| parent | ec6550c6c06ba3a0cf4df31d1016aa8eb8716ddb (diff) | |
When creating a large hash index, pre-sort the index entries by estimated
bucket number, so as to ensure locality of access to the index during the
insertion step. Without this, building an index significantly larger than
available RAM takes a very long time because of thrashing. On the other
hand, sorting is just useless overhead when the index does fit in RAM.
We choose to sort when the initial index size exceeds effective_cache_size.
This is a revised version of work by Tom Raney and Shreya Bhargava.
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/access/hash.h | 12 | ||||
| -rw-r--r-- | src/include/utils/tuplesort.h | 18 |
2 files changed, 23 insertions, 7 deletions
diff --git a/src/include/access/hash.h b/src/include/access/hash.h index fd7b68e9aeb..34275ad9d60 100644 --- a/src/include/access/hash.h +++ b/src/include/access/hash.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/access/hash.h,v 1.85 2008/03/15 20:46:31 tgl Exp $ + * $PostgreSQL: pgsql/src/include/access/hash.h,v 1.86 2008/03/16 23:15:08 tgl Exp $ * * NOTES * modeled after Margo Seltzer's hash implementation for unix. @@ -298,7 +298,7 @@ extern void _hash_dropbuf(Relation rel, Buffer buf); extern void _hash_wrtbuf(Relation rel, Buffer buf); extern void _hash_chgbufaccess(Relation rel, Buffer buf, int from_access, int to_access); -extern void _hash_metapinit(Relation rel, double num_tuples); +extern uint32 _hash_metapinit(Relation rel, double num_tuples); extern void _hash_pageinit(Page page, Size size); extern void _hash_expandtable(Relation rel, Buffer metabuf); @@ -313,6 +313,14 @@ extern bool _hash_next(IndexScanDesc scan, ScanDirection dir); extern bool _hash_first(IndexScanDesc scan, ScanDirection dir); extern bool _hash_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir); +/* hashsort.c */ +typedef struct HSpool HSpool; /* opaque struct in hashsort.c */ + +extern HSpool *_h_spoolinit(Relation index, uint32 num_buckets); +extern void _h_spooldestroy(HSpool *hspool); +extern void _h_spool(IndexTuple itup, HSpool *hspool); +extern void _h_indexbuild(HSpool *hspool); + /* hashutil.c */ extern bool _hash_checkqual(IndexScanDesc scan, IndexTuple itup); extern uint32 _hash_datum2hashkey(Relation rel, Datum key); diff --git a/src/include/utils/tuplesort.h b/src/include/utils/tuplesort.h index f552de91dba..7bd497092ed 100644 --- a/src/include/utils/tuplesort.h +++ b/src/include/utils/tuplesort.h @@ -13,7 +13,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/tuplesort.h,v 1.28 2008/01/01 19:45:59 momjian Exp $ + * $PostgreSQL: pgsql/src/include/utils/tuplesort.h,v 1.29 2008/03/16 23:15:08 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -41,16 +41,24 @@ typedef struct Tuplesortstate Tuplesortstate; * rather than forming actual HeapTuples (which'd have to be converted to * MinimalTuples). * - * Yet a third slightly different interface supports sorting bare Datums. + * The IndexTuple case is itself broken into two subcases, one for btree + * indexes and one for hash indexes; the latter variant actually sorts + * the tuples by hash code. The API is the same except for the "begin" + * routine. + * + * Yet another slightly different interface supports sorting bare Datums. */ extern Tuplesortstate *tuplesort_begin_heap(TupleDesc tupDesc, int nkeys, AttrNumber *attNums, Oid *sortOperators, bool *nullsFirstFlags, int workMem, bool randomAccess); -extern Tuplesortstate *tuplesort_begin_index(Relation indexRel, - bool enforceUnique, - int workMem, bool randomAccess); +extern Tuplesortstate *tuplesort_begin_index_btree(Relation indexRel, + bool enforceUnique, + int workMem, bool randomAccess); +extern Tuplesortstate *tuplesort_begin_index_hash(Relation indexRel, + uint32 hash_mask, + int workMem, bool randomAccess); extern Tuplesortstate *tuplesort_begin_datum(Oid datumType, Oid sortOperator, bool nullsFirstFlag, int workMem, bool randomAccess); |
