From: legrand legrand <legrand_legrand@hotmail.com>
To: pgsql-general@postgresql.org
Subject: Re: Adding LEFT JOIN to a query has increased execution time 10 times
Date: Sun, 6 Jan 2019 13:37:45 -0700 (MST)
Message-ID: <1546807065242-0.post@n3.nabble.com> (raw)
In-Reply-To: <CAADeyWgOOKMyyhEm1DV5btpZ_0+dGdqAsMcA7HuWF4-nXFeq_g@mail.gmail.com>
References: <CAADeyWhxj4Pmwaa0EcjkMRPOydZTYOTyESqzPoFfe-Xj4mri0Q@mail.gmail.com>
<87r2dqrisj.fsf@news-spur.riddles.org.uk>
<CAADeyWh5jLcRViB2rqYOiehVA1e0k0FD3oL19oGqLo6Z2TSuKg@mail.gmail.com>
<CAADeyWgOOKMyyhEm1DV5btpZ_0+dGdqAsMcA7HuWF4-nXFeq_g@mail.gmail.com>
Alexander Farber wrote
> Good evening, thank you for the useful hints!
>
> With the further help of the IRC folks the query has been optimized (7-10
> seconds -> 0.3 second) by adding the following indices:
>
> CREATE INDEX ON words_games (player1, COALESCE(finished, 'INFINITY'));
> CREATE INDEX ON words_games (player2, COALESCE(finished, 'INFINITY'));
> CREATE INDEX ON words_moves (gid, played DESC);
> CREATE INDEX ON words_social (uid, stamp DESC);
> CREATE INDEX ON words_geoip USING SPGIST (block);
>
> and switching to LEFT JOIN LATERAL for finding the most recent records in
> words_moves and words_social tables:
>
> [...]
>
> Planning time: 0.587 ms
> Execution time: 0.367 ms
> (36 rows)
>
> I was told that it still could be improved (by rearranging WHERE clauses?)
>
> Regards
> Alex
Hi Alexander,
It seems that you have done a very nice tuning exercise with this query,
that finishes now in less than 1 ms !!!
and I have learned about LEFT JOIN LATERAL syntax too !
As you didn't spoke about DML activity ... May I suggest you to take some
time to monitor the
application before to continue optimizing this query ?
Take time to check that:
- the result is ok,
- performances are stable,
- there is no regression on other queries,
- inserts,updates, deletes, copy are still working fast,
- size of added objects are coherent and stable,
- query complexity stay manageable,
- there is no other application part to optimize,
- ...
Regards
PAscal
--
Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
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: legrand_legrand@hotmail.com
Subject: Re: Adding LEFT JOIN to a query has increased execution time 10 times
In-Reply-To: <1546807065242-0.post@n3.nabble.com>
References: <CAADeyWhxj4Pmwaa0EcjkMRPOydZTYOTyESqzPoFfe-Xj4mri0Q@mail.gmail.com> <87r2dqrisj.fsf@news-spur.riddles.org.uk> <CAADeyWh5jLcRViB2rqYOiehVA1e0k0FD3oL19oGqLo6Z2TSuKg@mail.gmail.com> <CAADeyWgOOKMyyhEm1DV5btpZ_0+dGdqAsMcA7HuWF4-nXFeq_g@mail.gmail.com> <1546807065242-0.post@n3.nabble.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