Re: Slow query and wrong row estimates for CTE

2021-02-16 Thread Dane Foster
Short conclusion: Switching from CTEs to temporary tables and analyzing reduced the runtime from 15 minutes to about 1.5 minutes. Longer conclusion: @Justin Pryzby - I experimented w/ materializing the CTEs and it helped at the margins but did not significantly contribute to a reduction

Re: Query performance issue

2021-02-16 Thread Michael Lewis
What indexes exist on those tables? How many rows do you expect to get back in total? Is the last_contacted_anychannel_dttm clause restrictive, or does that include most of the prospect table (check pg_stats for the histogram if you don't know). and (a."shared_paddr_with_customer_ind" = 'N')

Re: Slow query and wrong row estimates for CTE

2021-02-16 Thread Dane Foster
On Tue, Feb 16, 2021 at 10:13 AM Michael Lewis wrote: >Sort Method: external >> merge Disk: 30760kB >>Worker 0: Sort >> Method: external merge Disk: 30760kB >>

Re: Slow query and wrong row estimates for CTE

2021-02-16 Thread Dane Foster
On Mon, Feb 15, 2021 at 5:32 PM Justin Pryzby wrote: > ... > > Without looking closely, an index might help: student_id,assignment_id > That'd avoid the sort, and maybe change the shape of the whole plan. > I tried that prior to posting on the forum and it didn't make a difference. 🙁 I'll try yo

Re: Slow query and wrong row estimates for CTE

2021-02-16 Thread Michael Lewis
> >Sort Method: external > merge Disk: 30760kB >Worker 0: Sort Method: > external merge Disk: 30760kB >Worker 1: Sort Method: > external me