Re: PostgreSQL 12.3 slow index scan chosen

2020-06-22 Thread Tom Lane
Alvaro Herrera writes: > On 2020-Jun-20, Tom Lane wrote: >> You said you'd increased the stats target for >> objectcustomfieldvalues.objectid, but maybe the real problem is needing >> to increase the targets for content and largecontent, in hopes of driving >> down the estimate for how many rows w

Re: PostgreSQL 12.3 slow index scan chosen

2020-06-22 Thread Kenneth Marshall
On Mon, Jun 22, 2020 at 03:27:32PM -0400, Alvaro Herrera wrote: > On 2020-Jun-20, Tom Lane wrote: > > > I wrote: > > > ... oh, now I see: apparently, your filter condition is such that *no* > > > rows of the objectcustomfieldvalues table get past the filter: > > > > > > -> Index Sca

Re: PostgreSQL 12.3 slow index scan chosen

2020-06-22 Thread Alvaro Herrera
On 2020-Jun-20, Tom Lane wrote: > I wrote: > > ... oh, now I see: apparently, your filter condition is such that *no* > > rows of the objectcustomfieldvalues table get past the filter: > > > > -> Index Scan using objectcustomfieldvalues3 on > > objectcustomfieldvalues objectcustomf

Re: PostgreSQL 12.3 slow index scan chosen

2020-06-20 Thread Kenneth Marshall
On Sat, Jun 20, 2020 at 02:22:03PM -0400, Tom Lane wrote: > I wrote: > > ... oh, now I see: apparently, your filter condition is such that *no* > > rows of the objectcustomfieldvalues table get past the filter: > > > > -> Index Scan using objectcustomfieldvalues3 on > > objectcustom

Re: PostgreSQL 12.3 slow index scan chosen

2020-06-20 Thread Tom Lane
I wrote: > ... oh, now I see: apparently, your filter condition is such that *no* > rows of the objectcustomfieldvalues table get past the filter: > > -> Index Scan using objectcustomfieldvalues3 on > objectcustomfieldvalues objectcustomfieldvalues_1 (cost=0.56..807603.40 > rows=9

Re: PostgreSQL 12.3 slow index scan chosen

2020-06-19 Thread Tom Lane
[ please keep the mailing list cc'd ] Kenneth Marshall writes: > Here are the stats for articles.id: > 4,7,9,11,13,14,16,17,18,19,20,21,22,23, > 24,25,26,32,33,34,36,40,41,42,43,44,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,99,100,101,102,106,107,108,109,113,1 > > 14,115,116,117,118,119,120,

Re: PostgreSQL 12.3 slow index scan chosen

2020-06-19 Thread Kenneth Marshall
On Fri, Jun 19, 2020 at 05:25:33PM -0500, Kenneth Marshall wrote: > On Fri, Jun 19, 2020 at 06:10:34PM -0400, Tom Lane wrote: > > > max(objectcustomfieldvalues.objectid) = 28108423 and here is the > > > histogram for that column: > > > > ... 3304313,3693956,27667772} > > > > Hmm, does seem like

Re: PostgreSQL 12.3 slow index scan chosen

2020-06-19 Thread Tom Lane
Kenneth Marshall writes: > On Fri, Jun 19, 2020 at 06:10:34PM -0400, Tom Lane wrote: >> Hmm, does seem like you have some outlier keys. Are any of the keys in >> the column you're trying to join to larger than 27667772? > The only values above 27667772? for objectid are: Sorry, I meant the othe

Re: PostgreSQL 12.3 slow index scan chosen

2020-06-19 Thread Kenneth Marshall
On Fri, Jun 19, 2020 at 06:10:34PM -0400, Tom Lane wrote: > > max(objectcustomfieldvalues.objectid) = 28108423 and here is the > > histogram for that column: > > ... 3304313,3693956,27667772} > > Hmm, does seem like you have some outlier keys. Are any of the keys in > the column you're trying t

Re: PostgreSQL 12.3 slow index scan chosen

2020-06-19 Thread Tom Lane
Kenneth Marshall writes: > On Fri, Jun 19, 2020 at 04:59:15PM -0400, Tom Lane wrote: >> What's the actual maximum value of objectcustomfieldvalues.objectid, >> and how does that compare to the endpoint value in the pg_stats >> histogram for that column? If you've got one outlier in the table, >>

Re: PostgreSQL 12.3 slow index scan chosen

2020-06-19 Thread Kenneth Marshall
On Fri, Jun 19, 2020 at 04:59:15PM -0400, Tom Lane wrote: > > > Thank you for the information and suggestion. I tried bumping the > > statistics for the > > objectcustomfieldvalues.objectid column to 2k, 5k and 10k followed by an > > analyze and > > the query plan stayed the same. I also analyze

Re: PostgreSQL 12.3 slow index scan chosen

2020-06-19 Thread Tom Lane
Kenneth Marshall writes: > On Fri, Jun 19, 2020 at 04:11:10PM -0400, Tom Lane wrote: >> The reason for such an estimation error usually is that the maximum >> join key values recorded in pg_stats are off: the join side that is >> going to be exhausted is the one with the smaller max join key. >> "

Re: PostgreSQL 12.3 slow index scan chosen

2020-06-19 Thread Kenneth Marshall
On Fri, Jun 19, 2020 at 04:11:10PM -0400, Tom Lane wrote: > > It looks like the planner is being too optimistic about how quickly the > mergejoin will end: > > > -> Merge Join (cost=0.71..892.64 rows=1 width=137) (actual > > time=21165.453..21165.453 rows=0 loops=1) > >

Re: PostgreSQL 12.3 slow index scan chosen

2020-06-19 Thread Tom Lane
Kenneth Marshall writes: > I was looking at a slow query in our CMDB that using postgresql-12.3 as its > backend. I since I am using the pg_trgm extension elsewhere I decided to give > it a try. To my surprise, the query plan did not change. But when I disabled > the index scan I got the much, muc