pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ekaterina Amez <ekaterina.amez@zunibal.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Query much slower from php than psql or dbeaver
Date: Thu, 20 Jan 2022 13:00:17 -0500
Message-ID: <891559.1642701617@sss.pgh.pa.us> (raw)
In-Reply-To: <CAFijohhPt+KAb+HPfWhkYvhNWhFGE3iCD_sn_88AsfUFyZ8ECQ@mail.gmail.com>
References: <CAFijohhPt+KAb+HPfWhkYvhNWhFGE3iCD_sn_88AsfUFyZ8ECQ@mail.gmail.com>

Ekaterina Amez <ekaterina.amez@zunibal.com> writes:
> I've tested the query with psql and DBeaver and it takes only milliseconds:
> it returns 39 records and now there's only 16000 records on the table but
> I've tested it with <100K. When I've tested my php script the same query
> takes 14 minutes to return (more or less).

A plausible theory is that it's not really the same query, but differs
in having some values presented as parameters not literal constants.
Depending on exactly how you do it, that can confuse the planner
leading to a poor execution plan and a long runtime.

I'd first try enabling log_statement on the server to see if the
query is really being presented exactly the same way.  Another
thing worth trying is auto_explain, to capture the plans actually
being used.

			regards, tom lane





view thread (4+ messages)  latest in thread

Message-ID: <891559.1642701617@sss.pgh.pa.us>
Permalink:  ../891559.1642701617@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/891559.1642701617@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, ekaterina.amez@zunibal.com
  Subject: Re: Query much slower from php than psql or dbeaver
  In-Reply-To: <891559.1642701617@sss.pgh.pa.us>
  References: <CAFijohhPt+KAb+HPfWhkYvhNWhFGE3iCD_sn_88AsfUFyZ8ECQ@mail.gmail.com> <891559.1642701617@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