MySQL和Codeigniter加载非常慢

时间:2019-02-21 19:20:13

标签: mysql codeigniter

我已经开发了webshop项目,但是查询响应速度很慢。 我正在使用codeigniter框架,并且正在使用$this->output->enable_profiler(TRUE);

这是我得到的查询:

SELECT `products`.`id`, `products`.`image`, `products`.`onsale`, `products`.`folder`, `products`.`productRating`, `products`.`pro_vat`, `products`.`pro_code`, `products`.`quantity`, `products`.`shop_categorie`, `products_translations`.`title`, `products_translations`.`price`, `products_translations`.`pdv`, `products_translations`.`old_price`, `products_translations`.`description`, `products_translations`.`shortdescription`, `products`.`url`, `brands`.`image` as `bimage`
FROM `products`
LEFT JOIN `products_translations` ON `products_translations`.`for_id` = `products`.`id`
LEFT JOIN `brands` ON `brands`.`id` = `products`.`brand_id`
ORDER BY `position` ASC
LIMIT 20 

,并且需要6秒钟以上的时间来加载它。 只需提一下,我的产品表中就有大约2500个项目。

是否可以以某种方式减少加载时间?

1 个答案:

答案 0 :(得分:0)

我还要说,您应该先检查索引。
正如我所看到的,您仅在where子句中使用了ID。如果您以正确的方式设置主键,那么它们应该不是问题。

您检查服务器资源了吗?

如果服务器和索引没有问题,那么您应该开始在数据库中使用视图,以避免每次运行查询时出现“左联接”。

相关问题