pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Accounting for between table correlation
Date: Fri, 15 Jan 2021 09:23:58 -0600
Message-ID: <b804bb4e-8f7b-d391-8827-a82b137321e8@gmail.com> (raw)
In-Reply-To: <CADDNc-B=spVE0FjJEOUEsGo+ChvvkPjyLZk+MV-YHz80Fo4BCw@mail.gmail.com>
References: <CADDNc-B=spVE0FjJEOUEsGo+ChvvkPjyLZk+MV-YHz80Fo4BCw@mail.gmail.com>

On 1/15/21 9:19 AM, Alexander Stoddard wrote:
> I am having ongoing trouble with a pair of tables, the design of which is 
> beyond my control.
>
> There is a 'primary' table with hundreds of millions of rows. There is 
> then a 'subclass' table ~ 10% of the primary which has additional fields. 
> The tables logically share a primary key field (although that is not 
> annotated in the schema).
>
> Membership of the subclass table has high correlation with fields in the 
> primary table - it is very much not random. It seems query plans where the 
> two tables are joined are 'unstable'. Over time very different plans can 
> resultĀ  even for unchanged queries and some plans are exceedingly inefficient.
>
> I think what is going on is that the query planner assumes many fewer rows 
> are going to join to the subtable than actually do (because of the strong 
> correlation).
>
> Can anyone offer any advice on dealing with this scenario (or better 
> diagnosing it)?

Do the tables get analyzed on a regular basis?

-- 
Angular momentum makes the world go 'round.





view thread (18+ messages)  latest in thread

Message-ID: <b804bb4e-8f7b-d391-8827-a82b137321e8@gmail.com>
Permalink:  ../b804bb4e-8f7b-d391-8827-a82b137321e8@gmail.com/
Also on:    postgresql.org/message-id/b804bb4e-8f7b-d391-8827-a82b137321e8@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: Accounting for between table correlation
  In-Reply-To: <b804bb4e-8f7b-d391-8827-a82b137321e8@gmail.com>
  References: <CADDNc-B=spVE0FjJEOUEsGo+ChvvkPjyLZk+MV-YHz80Fo4BCw@mail.gmail.com> <b804bb4e-8f7b-d391-8827-a82b137321e8@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox