Re: bad JIT decision

2020-08-03 Thread David Rowley
On Wed, 29 Jul 2020 at 09:28, Andres Freund wrote: > FWIW, I created a demo workload for this, and repro'ed the issue with > that. Those improvements does make a very significant difference: > Before: > Timing: Generation 335.345 ms, Inlining 51.025 ms, Optimization 11967.776 > ms, Emission

Re: bad JIT decision

2020-08-02 Thread David Rowley
On Wed, 29 Jul 2020 at 09:07, Andres Freund wrote: > On 2020-07-28 11:54:53 +1200, David Rowley wrote: > > Is there some reason that we can't consider jitting on a more granular > > basis? > > There's a substantial "constant" overhead of doing JIT. And that it's > nontrival to determine which

Re: bad JIT decision

2020-07-28 Thread Andres Freund
Hi, On 2020-07-28 14:07:48 -0700, Andres Freund wrote: > (I'm rebasing my tree that tries to reduce the overhead / allow caching > / increase efficiency to current PG, but it's a fair bit of work) FWIW, I created a demo workload for this, and repro'ed the issue with that. Those improvements does

Re: bad JIT decision

2020-07-28 Thread Andres Freund
Hi, On 2020-07-28 11:54:53 +1200, David Rowley wrote: > Is there some reason that we can't consider jitting on a more granular > basis? There's a substantial "constant" overhead of doing JIT. And that it's nontrival to determine which parts of the query should be JITed in one part, and which

Re: bad JIT decision

2020-07-28 Thread Tom Lane
Andres Freund writes: > On 2020-07-27 19:02:56 -0400, Alvaro Herrera wrote: >>> I don't quite understand why is it that a table with 1000 partitions >>> means that JIT compiles the thing 1000 times. Sure, it is possible that >>> some partitions have a different column layout, but it seems an

Re: bad JIT decision

2020-07-28 Thread Andres Freund
Hi, On 2020-07-27 19:02:56 -0400, Alvaro Herrera wrote: > On 2020-Jul-27, Scott Ribe wrote: > > > > On Jul 27, 2020, at 4:00 PM, Alvaro Herrera > > > wrote: > > > > > > I don't quite understand why is it that a table with 1000 partitions > > > means that JIT compiles the thing 1000 times.

Re: bad JIT decision

2020-07-27 Thread David Rowley
On Tue, 28 Jul 2020 at 11:00, Andres Freund wrote: > > On 2020-07-25 10:54:18 -0400, Tom Lane wrote: > > David Rowley writes: > > > ... nested at the bottom level join, about 6 joins deep. The lack of > > > any row being found results in upper level joins not having to do > > > anything, and

Re: bad JIT decision

2020-07-27 Thread Alvaro Herrera
On 2020-Jul-27, Scott Ribe wrote: > > On Jul 27, 2020, at 4:00 PM, Alvaro Herrera > > wrote: > > > > I don't quite understand why is it that a table with 1000 partitions > > means that JIT compiles the thing 1000 times. Sure, it is possible that > > some partitions have a different column

Re: bad JIT decision

2020-07-27 Thread Andres Freund
Hi, On 2020-07-25 10:54:18 -0400, Tom Lane wrote: > David Rowley writes: > > ... nested at the bottom level join, about 6 joins deep. The lack of > > any row being found results in upper level joins not having to do > > anything, and the majority of the plan is (never executed). > > On

Re: bad JIT decision

2020-07-27 Thread Scott Ribe
> On Jul 27, 2020, at 4:00 PM, Alvaro Herrera wrote: > > I don't quite understand why is it that a table with 1000 partitions > means that JIT compiles the thing 1000 times. Sure, it is possible that > some partitions have a different column layout, but it seems an easy bet > that most cases

Re: bad JIT decision

2020-07-27 Thread Alvaro Herrera
On 2020-Jul-24, Andres Freund wrote: > I think the issue is more that we need to take into accoutn that the > overhead of JITing scales ~linearly with the number of JITed > expressions. And that's not done right now. I've had a patch somewhere > that had a prototype implementation of changing

Re: bad JIT decision

2020-07-25 Thread David Rowley
On Sun, 26 Jul 2020 at 02:54, Tom Lane wrote: > > David Rowley writes: > > ... nested at the bottom level join, about 6 joins deep. The lack of > > any row being found results in upper level joins not having to do > > anything, and the majority of the plan is (never executed). > > On re-reading

Re: bad JIT decision

2020-07-25 Thread David Rowley
On Sun, 26 Jul 2020 at 02:23, Tom Lane wrote: > > Andres Freund writes: > > On 2020-07-24 18:37:02 -0400, Tom Lane wrote: > >> Yeah. I'm fairly convinced that the v12 defaults are far too low, > >> because we are constantly seeing complaints of this sort. > > > I think the issue is more that we

Re: bad JIT decision

2020-07-25 Thread David Rowley
On Sun, 26 Jul 2020 at 02:17, Tom Lane wrote: > > David Rowley writes: > > On Sat, 25 Jul 2020 at 10:42, David Rowley wrote: > >> I think plan cost overestimation is a common cause of unwanted jit too. > >> It would be good to see the EXPLAIN ANALYZE so we knew if that was the > >> case here. >

Re: bad JIT decision

2020-07-25 Thread Tom Lane
David Rowley writes: > ... nested at the bottom level join, about 6 joins deep. The lack of > any row being found results in upper level joins not having to do > anything, and the majority of the plan is (never executed). On re-reading this, that last point struck me forcibly. If most of the

Re: bad JIT decision

2020-07-25 Thread Tom Lane
Andres Freund writes: > On 2020-07-24 18:37:02 -0400, Tom Lane wrote: >> Yeah. I'm fairly convinced that the v12 defaults are far too low, >> because we are constantly seeing complaints of this sort. > I think the issue is more that we need to take into accoutn that the > overhead of JITing

Re: bad JIT decision

2020-07-25 Thread Tom Lane
David Rowley writes: > On Sat, 25 Jul 2020 at 10:42, David Rowley wrote: >> I think plan cost overestimation is a common cause of unwanted jit too. >> It would be good to see the EXPLAIN ANALYZE so we knew if that was the >> case here. > So Scott did send me the full EXPLAIN ANALYZE for this

Re: bad JIT decision

2020-07-25 Thread David Rowley
On Sat, 25 Jul 2020 at 10:42, David Rowley wrote: > > On Sat, 25 Jul 2020 at 10:37, Tom Lane wrote: > > > > David Rowley writes: > > > However, for now, you might just want to try raising various jit > > > thresholds so that it only is enabled for more expensive plans. > > > > Yeah. I'm fairly

Re: bad JIT decision

2020-07-24 Thread Andres Freund
Hi, On Fri, Jul 24, 2020, at 15:32, Scott Ribe wrote: > > On Jul 24, 2020, at 4:26 PM, David Rowley wrote: > > > > It does not really take into account the cost of jitting. > > That is what I was missing. > > I read about JIT when 12 was pre-release; in re-reading after my post I > see that

Re: bad JIT decision

2020-07-24 Thread Andres Freund
Hi, On 2020-07-24 18:37:02 -0400, Tom Lane wrote: > David Rowley writes: > > However, for now, you might just want to try raising various jit > > thresholds so that it only is enabled for more expensive plans. > > Yeah. I'm fairly convinced that the v12 defaults are far too low, > because we

Re: bad JIT decision

2020-07-24 Thread Scott Ribe
> On Jul 24, 2020, at 4:37 PM, Tom Lane wrote: > > Yeah. I'm fairly convinced that the v12 defaults are far too low, > because we are constantly seeing complaints of this sort. They are certainly too low for our case; not sure if for folks who are not partitioning if they're way too low.

Re: bad JIT decision

2020-07-24 Thread David Rowley
On Sat, 25 Jul 2020 at 10:37, Tom Lane wrote: > > David Rowley writes: > > However, for now, you might just want to try raising various jit > > thresholds so that it only is enabled for more expensive plans. > > Yeah. I'm fairly convinced that the v12 defaults are far too low, > because we are

Re: bad JIT decision

2020-07-24 Thread Tom Lane
David Rowley writes: > However, for now, you might just want to try raising various jit > thresholds so that it only is enabled for more expensive plans. Yeah. I'm fairly convinced that the v12 defaults are far too low, because we are constantly seeing complaints of this sort.

Re: bad JIT decision

2020-07-24 Thread Scott Ribe
> On Jul 24, 2020, at 4:26 PM, David Rowley wrote: > > It does not really take into account the cost of jitting. That is what I was missing. I read about JIT when 12 was pre-release; in re-reading after my post I see that it does not attempt to estimate JIT cost. And in thinking about it, I

Re: bad JIT decision

2020-07-24 Thread David Rowley
On Sat, 25 Jul 2020 at 08:46, Scott Ribe wrote: > Given the magnitude of the miss in using JIT here, I am wondering: is it > possible that the planner does not properly take into account the cost of > JIT'ing a function for multiple partitions? Or is it that the planner doesn't > have enough