Re: Query much slower from php than psql or dbeaver - Mailing list pgsql-general

From Tom Lane
Subject Re: Query much slower from php than psql or dbeaver
Date
Msg-id 891559.1642701617@sss.pgh.pa.us
Whole thread Raw
In response to Query much slower from php than psql or dbeaver  (Ekaterina Amez <ekaterina.amez@zunibal.com>)
Responses Re: Query much slower from php than psql or dbeaver  (Michael Lewis <mlewis@entrata.com>)
List pgsql-general
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



pgsql-general by date:

Previous
From: Rob Sargent
Date:
Subject: Re: psql does not provide proper response
Next
From: Garfield Lewis
Date:
Subject: Re: [EXT] Re: Can we get the CTID value