【问题标题】:Mysql & codeigniter load very slowMysql & codeigniter 加载速度很慢
【发布时间】:2019-02-21 19:20:12
【问题描述】:

我已经开发了网上商店项目,但我遇到了查询响应缓慢的问题。 我正在使用 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 秒。 顺便提一下,我在产品表中有大约 2.500 项。

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

【问题讨论】:

  • 您是否正确设置了索引?然后不按顺序尝试,看看瓶颈是否在那里
  • 什么意思?查询正常工作,问题在于加载时间
  • 让我看看是什么
  • 是的,我已经在所有表(产品、products_translations、品牌)的“id”列上设置了“主键”

标签: mysql codeigniter


【解决方案1】:

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

您检查过服务器资源吗?

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

【讨论】:

  • 您能否详细说明您的答案并解释为什么start using views in your database to avoid 'left joins' every time when you run a query 将有助于减少查询的执行时间?
猜你喜欢
  • 1970-01-01
  • 2013-04-20
  • 2015-05-15
  • 1970-01-01
  • 1970-01-01
  • 2018-08-08
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
相关资源
最近更新 更多