From: Tom Lane Date: Sun, 4 Jun 2017 17:34:05 +0000 (-0400) Subject: #ifdef out assorted unused GEQO code. X-Git-Tag: REL_10_BETA2~237 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9db7d47f909482ac2b76c28f5e9a2ef48fb19b9d;p=postgresql #ifdef out assorted unused GEQO code. I'd always assumed that backend/optimizer/geqo/'s remarkably poor showing on code coverage metrics was because we weren't exercising it much in the regression tests. But it turns out that a good chunk of the problem is that there's a bunch of code that is physically unreachable (because the calls to it are #ifdef'd out in geqo_main.c) but is being built anyway. Making the called code have #if guards similar to the calling code saves a couple of kilobytes of executable size and should make the coverage numbers more reflective of reality. It's arguable that we should just delete all the unused recombination mechanisms altogether, but I didn't feel a need to go that far today. --- diff --git a/src/backend/optimizer/geqo/geqo_cx.c b/src/backend/optimizer/geqo/geqo_cx.c index 9f6d5e478a..c72081e81a 100644 --- a/src/backend/optimizer/geqo/geqo_cx.c +++ b/src/backend/optimizer/geqo/geqo_cx.c @@ -38,6 +38,7 @@ #include "optimizer/geqo_recombination.h" #include "optimizer/geqo_random.h" +#if defined(CX) /* cx * @@ -119,3 +120,5 @@ cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, return num_diffs; } + +#endif /* defined(CX) */ diff --git a/src/backend/optimizer/geqo/geqo_erx.c b/src/backend/optimizer/geqo/geqo_erx.c index 133fe32348..173be44409 100644 --- a/src/backend/optimizer/geqo/geqo_erx.c +++ b/src/backend/optimizer/geqo/geqo_erx.c @@ -35,6 +35,7 @@ #include "optimizer/geqo_recombination.h" #include "optimizer/geqo_random.h" +#if defined(ERX) static int gimme_edge(PlannerInfo *root, Gene gene1, Gene gene2, Edge *edge_table); static void remove_gene(PlannerInfo *root, Gene gene, Edge edge, Edge *edge_table); @@ -466,3 +467,5 @@ edge_failure(PlannerInfo *root, Gene *gene, int index, Edge *edge_table, int num elog(ERROR, "no edge found"); return 0; /* to keep the compiler quiet */ } + +#endif /* defined(ERX) */ diff --git a/src/backend/optimizer/geqo/geqo_main.c b/src/backend/optimizer/geqo/geqo_main.c index 52bd428187..86213ac5a0 100644 --- a/src/backend/optimizer/geqo/geqo_main.c +++ b/src/backend/optimizer/geqo/geqo_main.c @@ -46,14 +46,14 @@ double Geqo_seed; static int gimme_pool_size(int nr_rel); static int gimme_number_generations(int pool_size); -/* define edge recombination crossover [ERX] per default */ +/* complain if no recombination mechanism is #define'd */ #if !defined(ERX) && \ !defined(PMX) && \ !defined(CX) && \ !defined(PX) && \ !defined(OX1) && \ !defined(OX2) -#define ERX +#error "must choose one GEQO recombination mechanism in geqo.h" #endif diff --git a/src/backend/optimizer/geqo/geqo_mutation.c b/src/backend/optimizer/geqo/geqo_mutation.c index 1a06d49775..c6af00a2a7 100644 --- a/src/backend/optimizer/geqo/geqo_mutation.c +++ b/src/backend/optimizer/geqo/geqo_mutation.c @@ -35,6 +35,8 @@ #include "optimizer/geqo_mutation.h" #include "optimizer/geqo_random.h" +#if defined(CX) /* currently used only in CX mode */ + void geqo_mutation(PlannerInfo *root, Gene *tour, int num_gene) { @@ -60,3 +62,5 @@ geqo_mutation(PlannerInfo *root, Gene *tour, int num_gene) num_swaps -= 1; } } + +#endif /* defined(CX) */ diff --git a/src/backend/optimizer/geqo/geqo_ox1.c b/src/backend/optimizer/geqo/geqo_ox1.c index fbf15282ad..891cfa2403 100644 --- a/src/backend/optimizer/geqo/geqo_ox1.c +++ b/src/backend/optimizer/geqo/geqo_ox1.c @@ -37,6 +37,7 @@ #include "optimizer/geqo_random.h" #include "optimizer/geqo_recombination.h" +#if defined(OX1) /* ox1 * @@ -90,3 +91,5 @@ ox1(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, } } + +#endif /* defined(OX1) */ diff --git a/src/backend/optimizer/geqo/geqo_ox2.c b/src/backend/optimizer/geqo/geqo_ox2.c index 01c55bea41..b43455d3eb 100644 --- a/src/backend/optimizer/geqo/geqo_ox2.c +++ b/src/backend/optimizer/geqo/geqo_ox2.c @@ -37,6 +37,7 @@ #include "optimizer/geqo_random.h" #include "optimizer/geqo_recombination.h" +#if defined(OX2) /* ox2 * @@ -107,3 +108,5 @@ ox2(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, } } + +#endif /* defined(OX2) */ diff --git a/src/backend/optimizer/geqo/geqo_pmx.c b/src/backend/optimizer/geqo/geqo_pmx.c index deb0f7b353..e9485cc8b5 100644 --- a/src/backend/optimizer/geqo/geqo_pmx.c +++ b/src/backend/optimizer/geqo/geqo_pmx.c @@ -37,6 +37,7 @@ #include "optimizer/geqo_random.h" #include "optimizer/geqo_recombination.h" +#if defined(PMX) /* pmx * @@ -219,3 +220,5 @@ pmx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene) pfree(indx); pfree(check_list); } + +#endif /* defined(PMX) */ diff --git a/src/backend/optimizer/geqo/geqo_px.c b/src/backend/optimizer/geqo/geqo_px.c index 99289bc11f..f7f615462c 100644 --- a/src/backend/optimizer/geqo/geqo_px.c +++ b/src/backend/optimizer/geqo/geqo_px.c @@ -37,6 +37,7 @@ #include "optimizer/geqo_random.h" #include "optimizer/geqo_recombination.h" +#if defined(PX) /* px * @@ -105,3 +106,5 @@ px(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, } } + +#endif /* defined(PX) */ diff --git a/src/backend/optimizer/geqo/geqo_recombination.c b/src/backend/optimizer/geqo/geqo_recombination.c index ef433e54e5..a61547c16d 100644 --- a/src/backend/optimizer/geqo/geqo_recombination.c +++ b/src/backend/optimizer/geqo/geqo_recombination.c @@ -58,6 +58,9 @@ init_tour(PlannerInfo *root, Gene *tour, int num_gene) } } +/* city table is used in these recombination methods: */ +#if defined(CX) || defined(PX) || defined(OX1) || defined(OX2) + /* alloc_city_table * * allocate memory for city table @@ -85,3 +88,5 @@ free_city_table(PlannerInfo *root, City *city_table) { pfree(city_table); } + +#endif /* CX || PX || OX1 || OX2 */ diff --git a/src/include/optimizer/geqo.h b/src/include/optimizer/geqo.h index 6b09c4e195..be65c054e1 100644 --- a/src/include/optimizer/geqo.h +++ b/src/include/optimizer/geqo.h @@ -31,7 +31,7 @@ #define GEQO_DEBUG */ -/* recombination mechanism */ +/* choose one recombination mechanism here */ /* #define ERX #define PMX