Performance on query PHP/POSTGRESQL

From: Date: Mon, 27 Nov 2000 20:39:21 +0000
Subject: Performance on query PHP/POSTGRESQL
Groups: php.db 
Request: Send a blank email to php-db+get-4777@lists.php.net to get a copy of this message
(postgres newbie question) I have a table defined so: CREATE TABLE measure_data ( company_code smallint not null, location_code varchar (10) not null, period_no smallint not null, measure_type varchar (50) not null, measure varchar (50) not null, measure_value decimal(12,2), year smallint not null, PRIMARY KEY (company_code, location_code, measure_type, measure, year, period_no) ); If I run a query: $SQL = "SELECT " . "M1.company_code, " . "M1.location_code," . "M1.period_no," . "M1.measure_type," . "M1.measure," . "M1.measure_value," . "M1.year" . "FROM measure_data M1 " . "WHERE " . "M1.measure_type = '" . $type . "' AND M1.measure = '" . $measure . "' AND M1.location_code != ''" . " AND M1.company_code = " . $company . " ORDER BY M1.location_code , M1.period_no"; The query runs fine in about 5 secs. If I then run the query $SQL = "SELECT " . "M1.company_code, " . "M1.location_code," . "M1.period_no," . "M1.measure_type," . "M1.measure," . "M1.measure_value," . "M1.year," . "M2.measure_value AS total_value " . "FROM measure_data M1," . " measure_data M2 " . "WHERE " . "M1.measure_type = '" . $type . "' AND M1.measure = '" . $measure . "' AND M1.location_code != ''" . " AND M1.company_code = " . $company . " AND M2.measure_type = 'All Assets'" . " AND M2.measure = M1.measure" . " AND M2.location_code = M1.location_code" . " AND M2.period_no = M1.period_no" . " AND M2.year = M1.year" . " AND M2.company_code = " . $company . " ORDER BY M1.location_code , M1.period_no"; The query takes 5 or 6 minutes to run. It's almost as if I am not using an index for the second query. Can anyone point me to a problem in my query? Thanks Mark

« previous php.db (#4777) next »