Giter VIP home page Giter VIP logo

pg-magicplan's Introduction

pg-magicplan

Improve planning of EXISTS in PostgreSQL subquery. The optimizer, even in PostgreSQL 12 as of writing, does a very straight optimization decision when executing queries that have an EXISTS sublink: it considers that it will always be cheaper to transform the subquery into a join. But such a decision is not always the best choice, and there is a way to tell the optimizer not to do that, as documented in the optimizer source code (in function simplify_EXISTS_query), by adding an OFFSET 0 clause in the subquery. During the development and optimization of queries in a PeopleDoc project, we encountered a situation where such an OFFSET 0 would drastically improve performances for some customers, while destroying it for others, with no way for the application to know when to add that clause. We also realized that the PostgreSQL planner knew, in most situations, what was indeed the best plan: when planning with an added OFFSET 0, the cost would be lower than the pristine plan, and thus plan would indeed most of the time be a much better plan.

The only solution we found to fix that without adding massive hacks in the application was to add a planner hook in our database. Before executing the query, if it matches the expected 'layout', we try to inject OFFSET 0 clauses in every EXISTS subquery, and we execute only the best plan we found.

This solution is only a workaround. We are documenting the situation before doing a proper bugreport along with, if possible, a way to reproduce the issue.

Building debian package with new PG version

All these are done in the proper debian chroot.

  1. make sure you've updated your postgresql-common and postgresql-server-dev-all packages
  2. update the debian/pgversions file
  3. pg_buildext updatecontrol
  4. debuild -us -uc

pg-magicplan's People

Contributors

anayrat avatar pierreducroquet avatar rdunklau avatar rodo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

anayrat frbn

pg-magicplan's Issues

Add tests

We should add test, t could be useful if one day we want to change its behavior.

You have to change the Makefile and populate sql and expected folder:

TESTS        = $(wildcard sql/*.sql)
REGRESS      = $(patsubst sql/%.sql,%,$(TESTS))

See:

Furthermore, in order to test that this extension won't crash postgres, we can run postgres test suite https://www.postgresql.org/docs/10/regress-run.html (I used to test with make installcheck-world). And we can change a little bit the extension to force postgres to use a magic plan. For example with a GUC force_magic_plan.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.