pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: A Shaposhnikov <artyom@gmail.com>
To: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: increasing effective_cache_size slows down join queries by a factor of 4000x
Date: Fri, 4 Feb 2022 18:01:20 +0100
Message-ID: <d8b5f126-8043-4252-01fb-8684383fa1b2@enterprisedb.com> (raw)
In-Reply-To: <CA+1Wm9WQiZH6TOs5_mmCxDhXYVp=VZsWJqnAD5AdYKJt06E+cQ@mail.gmail.com>
References: <CA+1Wm9U_sP9237f7OH7O=-UTab71DWOO4Qc-vnC78DfsJQBCwQ@mail.gmail.com>
	<CAHOFxGqBXyC_OjrNbekaQGKC6=Xo-ac5L-aJxS5QASAsSVRyJg@mail.gmail.com>
	<CA+1Wm9XwEBvdUHWQawmji_Z4wMbCzfvqgmYg0QDMkR5Q_LtikA@mail.gmail.com>
	<d41dcd64-3ce0-4e75-7690-8ea056c5c9f4@enterprisedb.com>
	<CA+1Wm9VPLD1JwzT12=361Je0Jm4K9GXwGWMRLUyzfa5mg_zLzA@mail.gmail.com>
	<747d822c-eae1-df4e-f4c3-099a5a00a721@enterprisedb.com>
	<CA+1Wm9WQiZH6TOs5_mmCxDhXYVp=VZsWJqnAD5AdYKJt06E+cQ@mail.gmail.com>

On 2/4/22 05:21, A Shaposhnikov wrote:
> Tomas,
> 
> thank you! The query:
> 
> select 1 from data as d, data_class as dc
>      where dc.data_id = d.id and d.id > 205284974
>        and dc.data_id > 205284974     -- new condition
>     order by d.id
>     limit 1000;
> 
> totally solved it - it is now fast under all conditions! I thought
> that the optimizer would be able to infer it itself.
> 

Unfortunately, the optimizer is not that smart - we can do that for 
equality conditions, but not for other operators. There was actually a 
thread [1] exploring a possibility to extend this to inequalities, but 
it went nowhere so far. It also explains why it's done only for equality 
operators. In short, it's fairly expensive, makes costing of joins more 
difficult, and most queries can't benefit from it (because conditions on 
join keys are not that common).

BTW how does the final query plan look like? Is it using the merge sort 
of nested loop? I wonder if this might be formulated as a costing issue, 
pushing the planner to use the nested loop.


[1] 
https://www.postgresql.org/message-id/flat/CAFQUnFhqkWuPCwQ1NmHYrisHJhYx4DoJak-dV%2BFcjyY6scooYA%40m...


regards

-- 
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company





view thread (14+ messages)  latest in thread

Message-ID: <d8b5f126-8043-4252-01fb-8684383fa1b2@enterprisedb.com>
Permalink:  ../d8b5f126-8043-4252-01fb-8684383fa1b2@enterprisedb.com/
Also on:    postgresql.org/message-id/d8b5f126-8043-4252-01fb-8684383fa1b2@enterprisedb.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: tomas.vondra@enterprisedb.com, artyom@gmail.com
  Subject: Re: increasing effective_cache_size slows down join queries by a factor of 4000x
  In-Reply-To: <d8b5f126-8043-4252-01fb-8684383fa1b2@enterprisedb.com>
  References: <CA+1Wm9U_sP9237f7OH7O=-UTab71DWOO4Qc-vnC78DfsJQBCwQ@mail.gmail.com> <CAHOFxGqBXyC_OjrNbekaQGKC6=Xo-ac5L-aJxS5QASAsSVRyJg@mail.gmail.com> <CA+1Wm9XwEBvdUHWQawmji_Z4wMbCzfvqgmYg0QDMkR5Q_LtikA@mail.gmail.com> <d41dcd64-3ce0-4e75-7690-8ea056c5c9f4@enterprisedb.com> <CA+1Wm9VPLD1JwzT12=361Je0Jm4K9GXwGWMRLUyzfa5mg_zLzA@mail.gmail.com> <747d822c-eae1-df4e-f4c3-099a5a00a721@enterprisedb.com> <CA+1Wm9WQiZH6TOs5_mmCxDhXYVp=VZsWJqnAD5AdYKJt06E+cQ@mail.gmail.com> <d8b5f126-8043-4252-01fb-8684383fa1b2@enterprisedb.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