Add pg_plan_advice contrib module. Provide a facility that (1) can be used to stabilize certain plan choices so that the planner cannot reverse course without authorization and (2) can be used by knowledgeable users to insist on plan choices contrary to what the planner believes best. In both cases, terrible outcomes are possible: users should think twice and perhaps three times before constraining the planner's ability to do as it thinks best; nevertheless, there are problems that are much more easily solved with these facilities than without them.
This patch takes the approach of analyzing a finished plan to produce textual output, which we call "plan advice", that describes key decisions made during plan; if that plan advice is provided during future planning cycles, it will force those key decisions to be made in the same way. Not all planner decisions can be controlled using advice; for example, decisions about how to perform aggregation are currently out of scope, as is choice of sort order. Plan advice can also be edited by the user, or even written from scratch in simple cases, making it possible to generate outcomes that the planner would not have produced. Partial advice can be provided to control some planner outcomes but not others. Currently, plan advice is focused only on specific outcomes, such as the choice to use a sequential scan for a particular relation, and not on estimates that might contribute to those outcomes, such as a possibly-incorrect selectivity estimate. While it would be useful to users to be able to provide plan advice that affects selectivity estimates or other aspects of costing, that is out of scope for this commit. Reviewed-by: Lukas Fittl <[email protected]> Reviewed-by: Jakub Wartak <[email protected]> Reviewed-by: Greg Burd <[email protected]> Reviewed-by: Jacob Champion <[email protected]> Reviewed-by: Haibo Yan <[email protected]> Reviewed-by: Dian Fay <[email protected]> Reviewed-by: Ajay Pal <[email protected]> Reviewed-by: John Naylor <[email protected]> Reviewed-by: Alexandra Wang <[email protected]> Discussion: http://postgr.es/m/CA+TgmoZ-Jh1T6QyWoCODMVQdhTUPYkaZjWztzP1En4=zhok...@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/5883ff30b02ceed3c5eabba4d9c09a7766f9a8fc Modified Files -------------- contrib/Makefile | 1 + contrib/meson.build | 1 + contrib/pg_plan_advice/.gitignore | 7 + contrib/pg_plan_advice/Makefile | 43 + contrib/pg_plan_advice/README | 260 +++ contrib/pg_plan_advice/expected/gather.out | 371 ++++ contrib/pg_plan_advice/expected/join_order.out | 500 +++++ contrib/pg_plan_advice/expected/join_strategy.out | 339 ++++ contrib/pg_plan_advice/expected/partitionwise.out | 426 ++++ contrib/pg_plan_advice/expected/prepared.out | 67 + contrib/pg_plan_advice/expected/scan.out | 757 +++++++ contrib/pg_plan_advice/expected/semijoin.out | 377 ++++ contrib/pg_plan_advice/expected/syntax.out | 192 ++ contrib/pg_plan_advice/meson.build | 66 + contrib/pg_plan_advice/pg_plan_advice.c | 456 +++++ contrib/pg_plan_advice/pg_plan_advice.h | 45 + contrib/pg_plan_advice/pgpa_ast.c | 351 ++++ contrib/pg_plan_advice/pgpa_ast.h | 185 ++ contrib/pg_plan_advice/pgpa_identifier.c | 481 +++++ contrib/pg_plan_advice/pgpa_identifier.h | 52 + contrib/pg_plan_advice/pgpa_join.c | 638 ++++++ contrib/pg_plan_advice/pgpa_join.h | 105 + contrib/pg_plan_advice/pgpa_output.c | 571 ++++++ contrib/pg_plan_advice/pgpa_output.h | 22 + contrib/pg_plan_advice/pgpa_parser.y | 301 +++ contrib/pg_plan_advice/pgpa_planner.c | 2198 +++++++++++++++++++++ contrib/pg_plan_advice/pgpa_planner.h | 19 + contrib/pg_plan_advice/pgpa_scan.c | 271 +++ contrib/pg_plan_advice/pgpa_scan.h | 85 + contrib/pg_plan_advice/pgpa_scanner.l | 297 +++ contrib/pg_plan_advice/pgpa_trove.c | 516 +++++ contrib/pg_plan_advice/pgpa_trove.h | 114 ++ contrib/pg_plan_advice/pgpa_walker.c | 1029 ++++++++++ contrib/pg_plan_advice/pgpa_walker.h | 141 ++ contrib/pg_plan_advice/sql/gather.sql | 86 + contrib/pg_plan_advice/sql/join_order.sql | 145 ++ contrib/pg_plan_advice/sql/join_strategy.sql | 84 + contrib/pg_plan_advice/sql/partitionwise.sql | 99 + contrib/pg_plan_advice/sql/prepared.sql | 37 + contrib/pg_plan_advice/sql/scan.sql | 195 ++ contrib/pg_plan_advice/sql/semijoin.sql | 118 ++ contrib/pg_plan_advice/sql/syntax.sql | 68 + doc/src/sgml/contrib.sgml | 1 + doc/src/sgml/filelist.sgml | 1 + doc/src/sgml/pgplanadvice.sgml | 813 ++++++++ src/tools/pgindent/typedefs.list | 33 + 46 files changed, 12964 insertions(+)
