Re: Query much slower from php than psql or dbeaver

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ekaterina Amez <ekaterina(dot)amez(at)zunibal(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Query much slower from php than psql or dbeaver
Date: 2022-01-20 18:00:17
Message-ID: 891559.1642701617@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ekaterina Amez <ekaterina(dot)amez(at)zunibal(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Garfield Lewis 2022-01-20 18:00:53 Re: [EXT] Re: Can we get the CTID value
Previous Message Rob Sargent 2022-01-20 17:56:59 Re: psql does not provide proper response