News for hackers. Stuff that matters.
Re:EventReduce: An algorithm to optimize database queries th... by rustyconover on Thursday April 16, 2020 @10:26AM (#22889682)
PostgreSQL does offer insights into the plan. Just put EXPLAIN before your query.
Re:EventReduce: An algorithm to optimize database queries th... by LunaSea on Thursday April 16, 2020 @10:38AM (#22889811)
Right but that's when you explicitly ask for it.

However, you can't ask ask PostgreSQL to run a query and also return the query plan used for said query.

Re:EventReduce: An algorithm to optimize database queries th... by theandrewbailey on Thursday April 16, 2020 @10:44AM (#22889869)
Unless there's some weird edge case that I'm not aware of, Postgres will execute what it's planner tells it to. Passing a query to EXPLAIN will show the plan.
Re:EventReduce: An algorithm to optimize database queries th... by LunaSea on Thursday April 16, 2020 @10:55AM (#22889974)
Query plans are based on database statistics.

Explain will calculate the query plan for a query.

Explain analyze will calculate the query plan, run the query and compare the query plan expectations to reality.

However, if statistics change, so does the query plan. So if you run a query then run the same query again with explain analyze, you don't have a guarantee of getting the same information back. And since explain analyze doesn't return the query results you are obligated to run two separated queries.

Re:EventReduce: An algorithm to optimize database queries th... by anarazel on Thursday April 16, 2020 @01:31PM (#22891626)
> However, if statistics change, so does the query plan. So if you run a query then run the same query again with explain analyze, you don't have a guarantee of getting the same information back. And since explain analyze doesn't return the query results you are obligated to run two separated queries.

If that's a problem you can use auto_explain.