On Wed, 2008-12-17 at 21:26 +0000, Simon Riggs wrote:
> Hot Standby won't work with hash indexes because they are
> non-recoverable.
> 
> We have a number of ways of dealing with this:

> 2. Specific Solution: make hashcostestimate() massively increase cost of
> scans during recovery so that they will very seldom be picked and make
> hashbeginscan() refuse scans during recovery in case they do happen

> (2) seems most appropriate, since it will last only until (1) is
> complete in a later release.

Code *fragment* enclosed here for discussion. (Not an independent patch)

-- 
 Simon Riggs           www.2ndQuadrant.com
 PostgreSQL Training, Services and Support
Index: src/backend/access/hash/hash.c
===================================================================
RCS file: /home/sriggs/pg/REPOSITORY/pgsql/src/backend/access/hash/hash.c,v
retrieving revision 1.107
diff -c -r1.107 hash.c
*** src/backend/access/hash/hash.c	13 Nov 2008 17:42:10 -0000	1.107
--- src/backend/access/hash/hash.c	17 Dec 2008 22:46:43 -0000
***************
*** 341,346 ****
--- 341,357 ----
  	IndexScanDesc scan;
  	HashScanOpaque so;
  
+ 	/* 
+ 	 * Hash indexes are not recoverable, so should not be used
+ 	 * during recovery mode. We try to avoid this by tweaking the 
+ 	 * cost of hash index scans during recovery (see selfuncs.c),
+ 	 * but we may still get called, so specifically prevent scans here.
+ 	 * This is a reasonably ugly hack that we expect to remove again
+ 	 * as soon as hash indexes write WAL records.
+ 	 */
+ 	if (IsRecoveryProcessingMode())
+ 		elog(ERROR, "Cannot use hash index while recovery is in progress");
+ 
  	scan = RelationGetIndexScan(rel, keysz, scankey);
  	so = (HashScanOpaque) palloc(sizeof(HashScanOpaqueData));
  	so->hashso_bucket_valid = false;
Index: src/backend/utils/adt/selfuncs.c
===================================================================
RCS file: /home/sriggs/pg/REPOSITORY/pgsql/src/backend/utils/adt/selfuncs.c,v
retrieving revision 1.257
diff -c -r1.257 selfuncs.c
*** src/backend/utils/adt/selfuncs.c	23 Oct 2008 00:24:50 -0000	1.257
--- src/backend/utils/adt/selfuncs.c	17 Dec 2008 22:41:17 -0000
***************
*** 5911,5919 ****
  	Selectivity *indexSelectivity = (Selectivity *) PG_GETARG_POINTER(6);
  	double	   *indexCorrelation = (double *) PG_GETARG_POINTER(7);
  
  	genericcostestimate(root, index, indexQuals, outer_rel, 0.0,
  						indexStartupCost, indexTotalCost,
! 						indexSelectivity, indexCorrelation);
  
  	PG_RETURN_VOID();
  }
--- 5911,5929 ----
  	Selectivity *indexSelectivity = (Selectivity *) PG_GETARG_POINTER(6);
  	double	   *indexCorrelation = (double *) PG_GETARG_POINTER(7);
  
+ 	/* 
+ 	 * Hash indexes are not recoverable, so should not be used
+ 	 * during recovery mode. Dissuade attempts to use them by adding
+ 	 * the same disableCost as if enable_indexscan = off was selected.
+ 	 * This is a reasonably ugly hack that we expect to remove again
+ 	 * as soon as hash indexes write WAL records.
+ 	 */
+ 	if (IsRecoveryProcessingMode())
+ 		*indexStartupCost += 100000000.0;
+ 
  	genericcostestimate(root, index, indexQuals, outer_rel, 0.0,
  						indexStartupCost, indexTotalCost,
! 						indexSelectivity, indexCorrelation);		
  
  	PG_RETURN_VOID();
  }
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to