pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Alan Hodgson <ahodgson@lists.simkin.ca>
To: pgsql-general@lists.postgresql.org
Subject: Re: Query planner issue with preferring primary key over a better index when using ORDER BY and LIMIT
Date: Mon, 6 Dec 2021 10:07:57 -0800
Message-ID: <6b84dfe8-d13b-45b0-53e7-e9aadf1a1c4c@aklaver.com> (raw)
In-Reply-To: <222a1e5472e33656a1167facfccd722ddecfbc66.camel@lists.simkin.ca>
References: <bc47e9d0c490942eebb01dc1129097012005e1d2.camel@lists.simkin.ca>
	<b79bdc27-e816-90a8-de17-3dcbf335fc73@gmail.com>
	<222a1e5472e33656a1167facfccd722ddecfbc66.camel@lists.simkin.ca>

On 12/6/21 10:02, Alan Hodgson wrote:
> On Mon, 2021-12-06 at 10:19 -0700, Rob Sargent wrote:
>> To be clear, is it the devs or the ORM that's adding the ORDER  and the
>> LIMIT?  I'm betting on devs.  Do they need the smallest id (first
>> occurrance?) or do they need data common to all 5096 entries (Name?) and
>> any record will do?.  For the former they might be better off asking for
>> just the attributes they need and for the latter you need to provide an
>> option which gets them that single record.  Of course, If they have the
>> "smallest id" in hand they should request that.
> 
> That assumes I could figure what bit of ORM code is generating this, 
> talk to them, and then get them to actually think about what data 
> they're looking for and it's impact on the database. :/ Given my 25 year 
> track record with devs, I'm thinking of that as plan B. Hopefully though 
> if they're looking for something common to all the records they would 
> look at the parent table instead.
> 
> I do expect the dev actually specified the order/limit for some reason.

Maybe I'm silly, but why is asking them a Plan B?

> 
> Thank you for the suggestions.


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (13+ messages)  latest in thread

Message-ID: <6b84dfe8-d13b-45b0-53e7-e9aadf1a1c4c@aklaver.com>
Permalink:  ../6b84dfe8-d13b-45b0-53e7-e9aadf1a1c4c@aklaver.com/
Also on:    postgresql.org/message-id/6b84dfe8-d13b-45b0-53e7-e9aadf1a1c4c@aklaver.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: adrian.klaver@aklaver.com, ahodgson@lists.simkin.ca
  Subject: Re: Query planner issue with preferring primary key over a better index when using ORDER BY and LIMIT
  In-Reply-To: <6b84dfe8-d13b-45b0-53e7-e9aadf1a1c4c@aklaver.com>
  References: <bc47e9d0c490942eebb01dc1129097012005e1d2.camel@lists.simkin.ca> <b79bdc27-e816-90a8-de17-3dcbf335fc73@gmail.com> <222a1e5472e33656a1167facfccd722ddecfbc66.camel@lists.simkin.ca> <6b84dfe8-d13b-45b0-53e7-e9aadf1a1c4c@aklaver.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