数据库中有 700,000 个元素我在 id 上有一个索引我也有一个关于省的索引,长度为 30 的 varchar(尽管我认为最大省的名称长度为 12)
所以
Create table (
id serial primary key watever,
price double not null,
address varchar(200)not null,
province varchar(30)not null,
description text not null,
status varchar(8) not null,
type varchar(30) not null,
category text not null,
size int(11) not null,
bultin int(4),
bed int(2),
bath int(2),
extras text,
posted_by int foregin key(user.id or whatever)
);
此页面大约需要约 2 秒
$sqlquery = "SELECT DESCRIPTION, ADDRESS, SIZE, BUILTIN, BED, BATH, PRICE
FROM listings
WHERE PRICE BETWEEN $min and $max AND BED between $minbr AND $maxbr AND CATEGORY =
'$cat' AND TYPE = '$type' AND PROVINCE like '%$province%'";
while ($row = mysqli_fetch_array($listings)) {
echo $row['DESCRIPTION'] . " Located at " . $row['ADDRESS'] . " " . $province. " "
. $row['SIZE'] . " sqft" . ", built in " . $row['BUILTIN'] . " " . $row['BED'] . "Bedroom, "
. $row['BATH'] . " Bathroom for $" . $row['PRICE'] . "
<br>
";
我已经阅读了一些关于提高 SQL 查询效率的教程,但是它们根本没有改变正在发生的事情的速度。(也许所有损失的速度都在 PHP 中?!?我认为这很有可能,如果是这样,我该如何优化 php?)
编辑:在 phpmyadmin 上,我运行了查询,它需要运行 php 页面所需的时间。问题显然是查询而不是 PHP。