|
71 | 71 | #ifdef_MSC_VER
|
72 | 72 | #include<float.h>/* for _isnan */
|
73 | 73 | #endif
|
| 74 | +#include<limits.h> |
74 | 75 | #include<math.h>
|
75 | 76 |
|
76 | 77 | #include"access/htup_details.h"
|
|
96 | 97 |
|
97 | 98 | #defineLOG2(x) (log(x) / 0.693147180559945)
|
98 | 99 |
|
| 100 | + |
99 | 101 | doubleseq_page_cost=DEFAULT_SEQ_PAGE_COST;
|
100 | 102 | doublerandom_page_cost=DEFAULT_RANDOM_PAGE_COST;
|
101 | 103 | doublecpu_tuple_cost=DEFAULT_CPU_TUPLE_COST;
|
102 | 104 | doublecpu_index_tuple_cost=DEFAULT_CPU_INDEX_TUPLE_COST;
|
103 | 105 | doublecpu_operator_cost=DEFAULT_CPU_OPERATOR_COST;
|
104 | 106 |
|
105 |
| -inteffective_cache_size=-1; |
| 107 | +inteffective_cache_size=-1;/* will get replaced */ |
106 | 108 |
|
107 | 109 | Costdisable_cost=1.0e10;
|
108 | 110 |
|
@@ -456,52 +458,6 @@ cost_index(IndexPath *path, PlannerInfo *root, double loop_count)
|
456 | 458 | path->path.total_cost=startup_cost+run_cost;
|
457 | 459 | }
|
458 | 460 |
|
459 |
| -void |
460 |
| -set_default_effective_cache_size(void) |
461 |
| -{ |
462 |
| -/* |
463 |
| - * If the value of effective_cache_size is -1, use the preferred |
464 |
| - * auto-tune value. |
465 |
| - */ |
466 |
| -if (effective_cache_size==-1) |
467 |
| -{ |
468 |
| -charbuf[32]; |
469 |
| - |
470 |
| -snprintf(buf,sizeof(buf),"%d",NBuffers*DEFAULT_EFFECTIVE_CACHE_SIZE_MULTI); |
471 |
| -SetConfigOption("effective_cache_size",buf,PGC_POSTMASTER,PGC_S_OVERRIDE); |
472 |
| -} |
473 |
| -Assert(effective_cache_size>0); |
474 |
| -} |
475 |
| - |
476 |
| -/* |
477 |
| - * GUC check_hook for effective_cache_size |
478 |
| - */ |
479 |
| -bool |
480 |
| -check_effective_cache_size(int*newval,void**extra,GucSourcesource) |
481 |
| -{ |
482 |
| -/* |
483 |
| - * -1 indicates a request for auto-tune. |
484 |
| - */ |
485 |
| -if (*newval==-1) |
486 |
| -{ |
487 |
| -/* |
488 |
| - * If we haven't yet changed the boot_val default of -1, just let it |
489 |
| - * be.We'll fix it later. |
490 |
| - */ |
491 |
| -if (effective_cache_size==-1) |
492 |
| -return true; |
493 |
| - |
494 |
| -/* Otherwise, substitute the auto-tune value */ |
495 |
| -*newval=NBuffers*DEFAULT_EFFECTIVE_CACHE_SIZE_MULTI; |
496 |
| -} |
497 |
| - |
498 |
| -/* set minimum? */ |
499 |
| -if (*newval<1) |
500 |
| -*newval=1; |
501 |
| - |
502 |
| -return true; |
503 |
| -} |
504 |
| - |
505 | 461 | /*
|
506 | 462 | * index_pages_fetched
|
507 | 463 | * Estimate the number of pages actually fetched after accounting for
|
@@ -4137,3 +4093,59 @@ page_size(double tuples, int width)
|
4137 | 4093 | {
|
4138 | 4094 | returnceil(relation_byte_size(tuples,width) /BLCKSZ);
|
4139 | 4095 | }
|
| 4096 | + |
| 4097 | +/* |
| 4098 | + * GUC check_hook for effective_cache_size |
| 4099 | + */ |
| 4100 | +bool |
| 4101 | +check_effective_cache_size(int*newval,void**extra,GucSourcesource) |
| 4102 | +{ |
| 4103 | +/* |
| 4104 | + * -1 is the documented way of requesting auto-tune, but we also treat |
| 4105 | + * zero as meaning that, since we don't consider zero a valid setting. |
| 4106 | + */ |
| 4107 | +if (*newval <=0) |
| 4108 | +{ |
| 4109 | +/* |
| 4110 | + * If we haven't yet changed the initial default of -1, just let it |
| 4111 | + * be.We'll fix it later on during GUC initialization, when |
| 4112 | + * set_default_effective_cache_size is called.(If we try to do it |
| 4113 | + * immediately, we may not be looking at the final value of NBuffers.) |
| 4114 | + */ |
| 4115 | +if (effective_cache_size==-1) |
| 4116 | +return true; |
| 4117 | + |
| 4118 | +/* |
| 4119 | + * Otherwise, substitute the auto-tune value, being wary of overflow. |
| 4120 | + */ |
| 4121 | +if (NBuffers<INT_MAX /4) |
| 4122 | +*newval=NBuffers*4; |
| 4123 | +else |
| 4124 | +*newval=INT_MAX; |
| 4125 | +} |
| 4126 | + |
| 4127 | +Assert(*newval>0); |
| 4128 | + |
| 4129 | +return true; |
| 4130 | +} |
| 4131 | + |
| 4132 | +/* |
| 4133 | + * initialize effective_cache_size at the end of GUC startup |
| 4134 | + */ |
| 4135 | +void |
| 4136 | +set_default_effective_cache_size(void) |
| 4137 | +{ |
| 4138 | +/* |
| 4139 | + * If the value of effective_cache_size is still -1 (or zero), replace it |
| 4140 | + * with the auto-tune value. |
| 4141 | + */ |
| 4142 | +if (effective_cache_size <=0) |
| 4143 | +{ |
| 4144 | +/* disable the short-circuit in check_effective_cache_size */ |
| 4145 | +effective_cache_size=0; |
| 4146 | +/* and let check_effective_cache_size() compute the setting */ |
| 4147 | +SetConfigOption("effective_cache_size","-1", |
| 4148 | +PGC_POSTMASTER,PGC_S_OVERRIDE); |
| 4149 | +} |
| 4150 | +Assert(effective_cache_size>0); |
| 4151 | +} |