pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: hubert depesz lubaczewski <depesz@depesz.com>
To: Frank Millman <frank@chagford.com>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: SELECT is faster on SQL Server
Date: Fri, 19 Mar 2021 12:04:38 +0100
Message-ID: <20210319110438.GA21117@depesz.com> (raw)
In-Reply-To: <5a6f07d7-1d0f-f685-6743-d4dbc1730177@chagford.com>
References: <d002a9e4-433c-3f44-90aa-46568db4bc00@chagford.com>
	<33b19e80-75da-a455-7e78-a01e14e4d4d6@gmx.net>
	<fbdd2bdd-1957-1b49-eeca-0278d43de71d@chagford.com>
	<CAFj8pRAU8N9hhotGhrxEcnae+tjy_CQoJA3fMYH9o58Du1SjLQ@mail.gmail.com>
	<c6befefe-a4ab-25ab-ceed-66d7d362de13@chagford.com>
	<CAFj8pRBLakshW08Har67iJcx=OnSsazqXb8CeY-k3dLUpqSrwQ@mail.gmail.com>
	<5a6f07d7-1d0f-f685-6743-d4dbc1730177@chagford.com>

On Fri, Mar 19, 2021 at 12:58:10PM +0200, Frank Millman wrote:
> On 2021-03-19 12:00 PM, Pavel Stehule wrote:
> 
>   In this query the most slow operation is query planning. You try to do tests on almost empty tables. This has no practical sense.
>   You should test queries on tables with size similar to production size.
> 
> Sorry about that. I hope this one is better. Same query, different data set.

For starters, I'm not really sure it makes sense to optimize a query
that runs in 3.5 miliseconds!

Having said that, after putting the plan on explain.depesz.com, I got:
https://explain.depesz.com/s/xZel

Which shows that ~ 50% of time was spent in scan on ar_totals and
sorting it.

You seem to have some really weird indexed on ar_totals created (mixed
of nulls ordering).

Why don't you start with simple:
create index q on ar_totals (ledger_row_id, tran_date) where deleted_id = 0;

But, again - either you're overthinking performance of a query that can
run over 200 times per second on single core, or you're testing it with
different data than the one that is really a problem.

Best regards,

depesz






view thread (18+ messages)  latest in thread

Message-ID: <20210319110438.GA21117@depesz.com>
Permalink:  ../20210319110438.GA21117@depesz.com/
Also on:    postgresql.org/message-id/20210319110438.GA21117@depesz.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: depesz@depesz.com, frank@chagford.com
  Subject: Re: SELECT is faster on SQL Server
  In-Reply-To: <20210319110438.GA21117@depesz.com>
  References: <d002a9e4-433c-3f44-90aa-46568db4bc00@chagford.com> <33b19e80-75da-a455-7e78-a01e14e4d4d6@gmx.net> <fbdd2bdd-1957-1b49-eeca-0278d43de71d@chagford.com> <CAFj8pRAU8N9hhotGhrxEcnae+tjy_CQoJA3fMYH9o58Du1SjLQ@mail.gmail.com> <c6befefe-a4ab-25ab-ceed-66d7d362de13@chagford.com> <CAFj8pRBLakshW08Har67iJcx=OnSsazqXb8CeY-k3dLUpqSrwQ@mail.gmail.com> <5a6f07d7-1d0f-f685-6743-d4dbc1730177@chagford.com> <20210319110438.GA21117@depesz.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