1 /*-------------------------------------------------------------------------
2  *
3  * blcost.c
4  *		Cost estimate function for bloom indexes.
5  *
6  * Copyright (c) 2016-2018, PostgreSQL Global Development Group
7  *
8  * IDENTIFICATION
9  *	  contrib/bloom/blcost.c
10  *
11  *-------------------------------------------------------------------------
12  */
13 #include "postgres.h"
14 
15 #include "fmgr.h"
16 #include "optimizer/cost.h"
17 #include "utils/selfuncs.h"
18 
19 #include "bloom.h"
20 
21 /*
22  * Estimate cost of bloom index scan.
23  */
24 void
25 blcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
26 			   Cost *indexStartupCost, Cost *indexTotalCost,
27 			   Selectivity *indexSelectivity, double *indexCorrelation,
28 			   double *indexPages)
29 {
30 	IndexOptInfo *index = path->indexinfo;
31 	List	   *qinfos;
32 	GenericCosts costs;
33 
34 	/* Do preliminary analysis of indexquals */
35 	qinfos = deconstruct_indexquals(path);
36 
37 	MemSet(&costs, 0, sizeof(costs));
38 
39 	/* We have to visit all index tuples anyway */
40 	costs.numIndexTuples = index->tuples;
41 
42 	/* Use generic estimate */
43 	genericcostestimate(root, path, loop_count, qinfos, &costs);
44 
45 	*indexStartupCost = costs.indexStartupCost;
46 	*indexTotalCost = costs.indexTotalCost;
47 	*indexSelectivity = costs.indexSelectivity;
48 	*indexCorrelation = costs.indexCorrelation;
49 	*indexPages = costs.numIndexPages;
50 }
51