pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: 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, 06 Dec 2021 10:02:44 -0800
Message-ID: <222a1e5472e33656a1167facfccd722ddecfbc66.camel@lists.simkin.ca> (raw)
In-Reply-To: <b79bdc27-e816-90a8-de17-3dcbf335fc73@gmail.com>
References: <bc47e9d0c490942eebb01dc1129097012005e1d2.camel@lists.simkin.ca>
	<b79bdc27-e816-90a8-de17-3dcbf335fc73@gmail.com>

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.

Thank you for the suggestions.

view thread (13+ messages)  latest in thread

Message-ID: <222a1e5472e33656a1167facfccd722ddecfbc66.camel@lists.simkin.ca>
Permalink:  ../222a1e5472e33656a1167facfccd722ddecfbc66.camel@lists.simkin.ca/
Also on:    postgresql.org/message-id/222a1e5472e33656a1167facfccd722ddecfbc66.camel@lists.simkin.ca

 · 

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: 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: <222a1e5472e33656a1167facfccd722ddecfbc66.camel@lists.simkin.ca>
  References: <bc47e9d0c490942eebb01dc1129097012005e1d2.camel@lists.simkin.ca> <b79bdc27-e816-90a8-de17-3dcbf335fc73@gmail.com> <222a1e5472e33656a1167facfccd722ddecfbc66.camel@lists.simkin.ca>

* 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