스크립트의 실행 시간에 약간의 문제가 있습니다. 쿼리에 많은 시간이 소요됩니다. 이 쿼리는 다음과 같습니다.쿼리 실행 시간 문제
select avg(price) from voiture where duration<30 AND make="Audi" AND model="A4"
+---+---+---+---+---+---+---+---+---+---+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+---+---+---+---+---+---+---+---+---+---+
| 1 | SIMPLE | voiture | ALL | NULL | NULL | NULL | NULL | 1376949 | Using where |
+---+---+---+---+---+---+---+---+---+---+
select price from voiture where duration<30 AND make="Audi" AND model="A4"
+---+---+---+---+---+---+---+---+---+---+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+---+---+---+---+---+---+---+---+---+---+
| 1 | SIMPLE | voiture | ALL | NULL | NULL | NULL | NULL | 1376949 | Using where |
+---+---+---+---+---+---+---+---+---+---+
이 쿼리는 phpMyAdmin 인터페이스에서 실행될 때 약 2 초가 걸립니다. 문제가 무엇인지 확인하려고 시도하고 평균 기능을 제거하면 쿼리가 0.0080 초 정도 지속됩니다.
나는 php 스크립트에서 평균을 계산하는 데 얼마나 걸릴지 자신에게 물어 보았지만, orouth와 avg를 함께 사용하는 쿼리에는 약 2 초가 걸렸다.
그래서 내 테이블의 모든 값을 가지고 스크립트의 처리를하기로 결정, 그래서이 쿼리를 사용하십시오 phpMyAdmin을 인터페이스에
select * from voiture where duration<30 AND make="Audi" AND model="A4"
+---+---+---+---+---+---+---+---+---+---+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+---+---+---+---+---+---+---+---+---+---+
| 1 | SIMPLE | voiture | ALL | NULL | NULL | NULL | NULL | 1376949 | Using where |
+---+---+---+---+---+---+---+---+---+---+
를, 그것은 0.0112 초 정도 걸립니다. 하지만 내 PHP 스크립트에서 25 초 걸립니다! carid 및 서비스 id에 대한 인덱스가있어
CREATE TABLE `voiture` (
`carid` bigint(9) NOT NULL,
`serviceid` bigint(9) NOT NULL,
`service` varchar(256) NOT NULL,
`model` varchar(256) DEFAULT NULL,
`gearingType` varchar(256) DEFAULT NULL,
`displacement` int(5) DEFAULT NULL,
`cylinders` int(2) DEFAULT NULL,
`fuel` varchar(32) DEFAULT NULL,
`mileage` int(7) DEFAULT NULL,
`existFlag` tinyint(1) DEFAULT NULL,
`lastUpdate` date DEFAULT NULL,
`version` varchar(256) DEFAULT NULL,
`bodyType` varchar(256) DEFAULT NULL,
`firstRegistration` date DEFAULT NULL,
`powerHp` int(4) DEFAULT NULL,
`powerKw` int(4) DEFAULT NULL,
`vat` varchar(256) DEFAULT NULL,
`price` decimal(12,2) DEFAULT NULL,
`duration` int(3) DEFAULT NULL,
`pageUrl` varchar(256) DEFAULT NULL,
`carImg` varchar(256) DEFAULT NULL,
`color` varchar(256) DEFAULT NULL,
`doors` int(1) DEFAULT NULL,
`seats` int(1) DEFAULT NULL,
`prevOwner` int(1) DEFAULT NULL,
`co2` varchar(256) DEFAULT NULL,
`consumption` varchar(256) DEFAULT NULL,
`gears` int(1) DEFAULT NULL,
`equipment` varchar(1024) NOT NULL,
`make` varchar(256) NOT NULL,
`country` varchar(3) NOT NULL
)
이
왜
$timestart2=microtime(true);
$querysec='select * from voiture where duration<30 AND make="Audi" AND model="A4"';
$requestsec=mysql_query($querysec) or die(mysql_error());
$timeend2=microtime(true);
$time2=$timeend2-$timestart2;
$page_load_time2 = number_format($time2, 9);
는 테이블 구조인가? 개선 할 수있는 방법이 있습니까?
실행 시간이 phpMyAdmin 및 PHP 스크립트와 다른 이유는 무엇입니까?
자세한 정보를 제공해야합니다. 테이블 구조는 무엇입니까? 색인을 생성하는 대상은 무엇입니까? 질의에 대해'EXPLAIN'을 실행 해 볼 수 있습니다. 출력물을 이해하지 못할 경우 질문에 추가하면 문제를 진단하는 데 도움이됩니다. –
''* from voiture where duration <30 AND make = "Audi"AND model = "A4"'로 얼마나 많은 행이 반환됩니까? – beingalex
[mysql_' 데이터베이스 확장 프로그램] (http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)을 사용하지 마십시오. 은 더 이상 사용되지 않습니다 (영원히 사라짐). PHP7에서) 특별히 PHP를 배우는 경우,'PDO' 데이터베이스 확장을 배우는 데 에너지를 소비하십시오. [여기에서 시작하십시오] (http://php.net/manual/en/book.pdo.php) 정말 쉽습니다. – RiggsFolly