Re: Please Help: PostgreSQL performance Optimization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jamal Ghaffour wrote:

CREATE TABLE cookies (
   domain varchar(50) NOT NULL,
   path varchar(50) NOT NULL,
   name varchar(50) NOT NULL,
   principalid varchar(50) NOT NULL,
   host text NOT NULL,
   value text NOT NULL,
   secure bool NOT NULL,
timestamp timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP+TIME '04:00:00',
   PRIMARY KEY  (domain,path,name,principalid)
)
[snip]
SELECT path, upper(name) AS name, value FROM cookies WHERE timestamp<CURRENT_TIMESTAMP AND principalid='192.168.8.219' AND secure=FALSE AND (domain='ping.icap-elios.com' OR domain='.icap-elios.com')

I think the problem here is that the column order in the index doesn't match the columns used in the WHERE clause criteria. Try adding an index on (domain,principalid) or (domain,principalid,timestamp). If these are your only queries, you can get the same effect by re-ordering the columns in the table so that this is the column order used by the primary key and its implicit index.

You should check up on EXPLAIN and EXPLAIN ANALYZE to help you debug slow queries.
begin:vcard
fn:Andrew Lazarus
n:Lazarus;Andrew
org:Pillette Investment Management;Research and Development
adr;dom:;;3028 Fillmore;San Francisco;CA;94123
email;internet:andrew@xxxxxxxxxxxx
title:Director
tel;work:800-366-0688
tel;fax:415-440-4093
url:http://www.pillette.com
version:2.1
end:vcard


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux