Re: Please help! Query jumps from 1s -> 4m

2020-05-13 Thread James Thompson
Just to follow up on this... Tried increasing stats targets last week + re-analyzing but the query was just as bad. Ended up increasing the prepareThreshold to prevent server-side prepares for now (and thus later generic statements). This 'fixed' the issue and had no noticeable negative effect for

Re: Please help! Query jumps from 1s -> 4m

2020-05-05 Thread Tom Lane
James Thompson writes: > The slowness occurs when the prepared statement changes to a generic plan. > Initial plan: > -> Index Only Scan using table1_typea_include_uniqueid_col16_idx on table1 > table1alias2 (cost=0.56..2549.70 rows=70 width=36) (actual > time=1.901..45.256 rows=65000 loops=1)

Re: Please help! Query jumps from 1s -> 4m

2020-05-05 Thread Justin Pryzby
On Tue, May 05, 2020 at 10:10:18PM +0100, James Thompson wrote: > I've managed to replicate this now with prepared statements. Thanks for all > the guidance so far. > > The slowness occurs when the prepared statement changes to a generic plan. > > Initial plan: > -> Index Only Scan using table1_

Re: Please help! Query jumps from 1s -> 4m

2020-05-05 Thread James Thompson
I've managed to replicate this now with prepared statements. Thanks for all the guidance so far. The slowness occurs when the prepared statement changes to a generic plan. Initial plan: -> Index Only Scan using table1_typea_include_uniqueid_col16_idx on table1 table1alias2 (cost=0.56..2549.70 r

Re: Please help! Query jumps from 1s -> 4m

2020-05-05 Thread Justin Pryzby
On Mon, May 04, 2020 at 02:12:01PM -0500, Justin Pryzby wrote: > On Mon, May 04, 2020 at 08:07:07PM +0100, Jamie Thompson wrote: > > Additionally, the execution plans for the 10th + following queries look > > fine, they have the same structure as if I run the query manually. It's not > > that the q

Re: Please help! Query jumps from 1s -> 4m

2020-05-05 Thread Laurenz Albe
On Mon, 2020-05-04 at 20:12 +0100, James Thompson wrote: > The change is abrupt, on the 10th execution (but I hadn't spotted it was > always after the > same number of executions until your suggestion - thanks for pointing me in > that direction). > > I don't see any custom configuration on our

Re: Please help! Query jumps from 1s -> 4m

2020-05-04 Thread James Thompson
The change is abrupt, on the 10th execution (but I hadn't spotted it was always after the same number of executions until your suggestion - thanks for pointing me in that direction). I don't see any custom configuration on our end that changes the threshold for this from 5->10. Debugging the query

Re: Please help! Query jumps from 1s -> 4m

2020-05-04 Thread David Rowley
On Mon, 4 May 2020 at 02:35, James Thompson wrote: > buffers do look different - but still, reading 42k doesn't seem like it would > cause a delay of 4m? You could do: SET track_io_timing TO on; then: EXPLAIN (ANALYZE, BUFFERS) your query and see if the time is spent doing IO. David

Re: Please help! Query jumps from 1s -> 4m

2020-05-04 Thread Justin Pryzby
On Mon, May 04, 2020 at 08:07:07PM +0100, Jamie Thompson wrote: > Additionally, the execution plans for the 10th + following queries look > fine, they have the same structure as if I run the query manually. It's not > that the query plan switches, it seems as though the same query plan is > just >

Re: Please help! Query jumps from 1s -> 4m

2020-05-03 Thread Justin Pryzby
On Sun, May 03, 2020 at 09:58:27AM +0100, James Thompson wrote: > Hi, > > Hoping someone can help with this performance issue that's been driving a > few of us crazy :-) Any guidance greatly appreciated. > > A description of what you are trying to achieve and what results you > expect.: > - I'd

Please help! Query jumps from 1s -> 4m

2020-05-03 Thread James Thompson
Hi, Hoping someone can help with this performance issue that's been driving a few of us crazy :-) Any guidance greatly appreciated. A description of what you are trying to achieve and what results you expect.: - I'd like to get an understanding of why the following query (presented in full, but