pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter J. Holzer <hjp-pgsql@hjp.at>
Cc: Dirschel, Steve <steve.dirschel@thomsonreuters.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Tuning a query with ORDER BY and LIMIT
Date: Wed, 22 Jun 2022 19:22:13 -0400
Message-ID: <3695492.1655940133@sss.pgh.pa.us> (raw)
In-Reply-To: <20220622221321.vjrapfkid3rprun5@hjp.at>
References: <DM6PR03MB4332A41B10218AE854D63A72FAB29@DM6PR03MB4332.namprd03.prod.outlook.com>
	<20220622221321.vjrapfkid3rprun5@hjp.at>

"Peter J. Holzer" <hjp-pgsql@hjp.at> writes:
> On 2022-06-22 19:39:33 +0000, Dirschel, Steve wrote:
>> create index workflow_execution_initial_ui_tabs
>> on workflow_execution (workflow_id asc, status asc, result asc,
>> completed_datetime desc);
> [...]
>> explain (analyze, verbose, costs, buffers, timing, summary, hashes)
>> select * from workflow_execution
>> where workflow_id = 14560 and
>> status = 'COMPLETED' and
>> result = 'SUCCEEDED'
>> order by completed_datetime desc limit 50;

> This query should actually be able to use the index, since the first
> columns in the index are all compared to single values. So the you can
> just jump to the first matching index and then get the next 50 entries.

Yeah, that sure looks like it should work.  Since we've not been
shown the whole table's DDL, it's hard to guess at why it isn't;
maybe there's a data type issue?

>> Is Postgres unable to optimize the query similar to Oracle?  Is it possible
>> this is possible but we are running on too old of a version?

> PostgreSQL 10 is quite old, so that's a possibility.

That's worked for many ages.

			regards, tom lane





view thread (10+ messages)  latest in thread

Message-ID: <3695492.1655940133@sss.pgh.pa.us>
Permalink:  ../3695492.1655940133@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3695492.1655940133@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, hjp-pgsql@hjp.at, steve.dirschel@thomsonreuters.com
  Subject: Re: Tuning a query with ORDER BY and LIMIT
  In-Reply-To: <3695492.1655940133@sss.pgh.pa.us>
  References: <DM6PR03MB4332A41B10218AE854D63A72FAB29@DM6PR03MB4332.namprd03.prod.outlook.com> <20220622221321.vjrapfkid3rprun5@hjp.at> <3695492.1655940133@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