pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Lucas Fairchild-Madar <lucas.madar@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Understanding query planner cpu usage
Date: Wed, 21 Feb 2018 22:28:05 -0500
Message-ID: <15586.1519270085@sss.pgh.pa.us> (raw)
In-Reply-To: <CAJmoq7NtboWu13rKznLgjSkud-soQwvth3XVgxyG2-psg5Mx-g@mail.gmail.com>
References: <CAJmoq7M4iFo3=W891x5H+N5+axSOh5biWesAmrHsjVMvaBuSYA@mail.gmail.com>
	<3615.1519258476@sss.pgh.pa.us>
	<CAJmoq7NtboWu13rKznLgjSkud-soQwvth3XVgxyG2-psg5Mx-g@mail.gmail.com>

Lucas Fairchild-Madar <lucas.madar@gmail.com> writes:
> On Wed, Feb 21, 2018 at 4:14 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> If so, this might be some manifestation of a problem we've seen before:
>> the planner tries to find out the current live max value of the column
>> by scanning the index, and that's really slow if there are a lot of
>> recently-dead entries at the index end, because each of them has to be
>> inspected and then hinted dead.

> I took a look further in this direction and found that our cleanup process
> and this analytical rollup both happened to run very close to each other
> twice a day. I moved the cleanup process to run at a time when it should
> never collide with analytical rollups and we'll see if the load spike
> happens again.

I'm thinking that will fix it for you.

> Perhaps this is a stupid question, but would creating the index in
> descending order solve this problem (as a unique index, not a primary key)?

I think most likely it'd just move the issue to the other end of the
index, though you could try.  See below.

> What is the planner doing when trying to find the current live max value of
> the column?

It's trying to estimate whether a mergejoin will be able to stop short of
reading all the tuples from the other side of the join.  (For instance,
if you've got 1,3,5 on one side, and 1,4,5,7,8,9,19 on the other, the
second input doesn't have to be read past "7" because once we run off the
end of the first input, we know we couldn't see any matches later on the
second input.  So the planner wants to compare the ending key value on
each side to the key distribution on the other side, to see what this might
save.)  Now, that's a unidirectional question for any particular mergejoin
plan, so that for any one cost estimate it's only going to need to look at
one end of the key range.  But I think it will consider merge joins with
both sort directions, so that both ends of the key range will get
investigated in this way.  I might be wrong though; it's late and I've
not looked at that code in awhile ...

			regards, tom lane




view thread (5+ messages)  latest in thread

Message-ID: <15586.1519270085@sss.pgh.pa.us>
Permalink:  ../15586.1519270085@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/15586.1519270085@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, lucas.madar@gmail.com
  Subject: Re: Understanding query planner cpu usage
  In-Reply-To: <15586.1519270085@sss.pgh.pa.us>
  References: <CAJmoq7M4iFo3=W891x5H+N5+axSOh5biWesAmrHsjVMvaBuSYA@mail.gmail.com> <3615.1519258476@sss.pgh.pa.us> <CAJmoq7NtboWu13rKznLgjSkud-soQwvth3XVgxyG2-psg5Mx-g@mail.gmail.com> <15586.1519270085@sss.pgh.pa.us>

* 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