Re: PHP Postgres query slower then PgAdmin - Mailing list pgsql-performance

From Tom Kincaid
Subject Re: PHP Postgres query slower then PgAdmin
Date
Msg-id CAKPRjUM-DbwS+_iTJ+hw+kg54+1wEYbuLg5tftT3r3Cj4GGtHw@mail.gmail.com
Whole thread Raw
In response to Re: PHP Postgres query slower then PgAdmin  (Emrah Mehmedov <emrah.mehmedov@x3mlabs.com>)
List pgsql-performance

Just rule out something weird;

Can you determine if you are getting the same query plan in both cases? Use "explain analyze" from the command line and turn on auto.explain via postgresql.conf to log what the plan is for the php case.


Tom Kincaid
EnterpriseDB



On Wed, Jun 5, 2013 at 7:15 AM, Emrah Mehmedov <emrah.mehmedov@x3mlabs.com> wrote:
I notice something in CMD, first time query is executing same time like from php all the time, but on the rest of the time that i will execute the query is faster from cmd, php is keeping the same execution time.
i also change the connection string (i remove host and port) and nothing changed.


On Wed, Jun 5, 2013 at 1:11 PM, Bob Jolliffe <bobjolliffe@gmail.com> wrote:
Most probably.  If your existing connection string specifies something like "host=localhost port=5432 ..." just remove the host and port parameters and php will by default try to connect with unix domain socket.


On 5 June 2013 12:02, Emrah Mehmedov <emrah.mehmedov@x3mlabs.com> wrote:
Can we modify php connection?


On Wed, Jun 5, 2013 at 1:01 PM, Bob Jolliffe <bobjolliffe@gmail.com> wrote:
Is php connecting through tcp whilst pgadmin is using unix domain socket?  Probably the query time is the same, but returning the result over tcp will be slower.


On 5 June 2013 11:18, Emrah Mehmedov <emrah.mehmedov@x3mlabs.com> wrote:
Hello,

I'm using php5.4.12 with extension=php_pgsql.dll enabled but the query that i'm trying to execute is faster on PgAdmin app.

SELECT title, ts_rank_cd(vector, query) AS rank FROM links, to_tsquery('english', 'risk') query WHERE query @@ vector ORDER BY rank DESC;

I'm not sure, what can i do to increase the speed of execution from php:

$start_time = microtime(true);
$query = "SELECT title, url, ts_rank_cd(vector, query) AS rank FROM links, to_tsquery('english', 'risk') query WHERE query @@ vector ORDER BY rank DESC LIMIT 10;";
$result = pg_query($connection, $query);
$end_time = microtime(true);

persistant connections are enabled in php.ini but i calculate only execution time from start to end.

Thanks, Emrah.

--
Best regards, Emrah Mehmedov
Software Developer @ X3M Labs
http://www.extreme-labs.com




--
Best regards, Emrah Mehmedov
Software Developer @ X3M Labs
http://www.extreme-labs.com




--
Best regards, Emrah Mehmedov
Software Developer @ X3M Labs
http://www.extreme-labs.com



--
Thomas John

pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: Weird, bad 0.5% selectivity estimate for a column equal to itself
Next
From: Marcin Mańk
Date:
Subject: Re: PHP Postgres query slower then PgAdmin