gpt4 book ai didi

php - 我怎样才能使我的数据库响应时间和渲染时间更好?

转载 作者:行者123 更新时间:2023-11-30 22:55:07 25 4
gpt4 key购买 nike

我工作的公司对我们的网站有一个内部管理方面。我注意到它的运行速度很慢,我假设这不是因为我们数据库的一侧,而是因为我们进行调用并将它们呈现到屏幕上的方式。我将列出我们渲染内容的过程示例,希望有人能告诉我我们在哪些方面效率低下,以帮助加快渲染加载时间。

//Student Page:
Avg. Loading Time: 5 - 6 seconds

//table_user:
Columns Records
45 16,412

//table_use_course:
Columns Records
22 18,623

//Indexing:
Comment: We use plesk (phpmyadmin) and this is where I did the indexing.
I indexed all primary and foreign keys and it looks like this:

enter image description here

//Query: 
SELECT a.account_id, user_id, user_first_name, user_last_name
FROM table_user a
INNER JOIN table_user_course b ON a.account_id = b.account_id
WHERE user_active = 'yes' AND b.product_type_id = '1'
ORDER BY user_first_name ASC LIMIT 0, 30


//Query Results:
Columns Records
4 30


//How we render:
if(is_array($query_results)){
foreach($querY_results as $student){
$text .= $student['user_first_name'], $student['user_last_name'], etc.
}
}

其他想法:

我们确实有一个具有相同代码和数据库结构的测试站点,只是数据库中的数据少了很多。测试站点运行得更快,这让我想到我们如何从数据库中提取它。另一方面,16k - 18k 的记录并没有那么多,我很惊讶测试站点和实时站点之间的加载时间差异。

任何有关如何使事情运行得更快的帮助或建议将不胜感激!

最佳答案

在编制索引时,需要关注 inner 部分中使用的列......在您的情况下:

table_user.account_id
table_user_course.account_id

在两个表中。尝试一下并澄清您是否已经完成

示例:

ALTER TABLE `TABLE_NAME` ADD INDEX `INDEX_NAME` (`COLUMN_NAME`) 

来源:How do I add indices to MySQL tables?

对于你的情况,使用:

SHOW INDEX FROM [TABLE_NAME]; (For checking the indexes in your tables)

并添加(仅当它们尚不存在时):

ALTER TABLE `table_user` ADD INDEX `INDEX_NAME` (`account_id`);
ALTER TABLE `table_user_course` ADD INDEX `INDEX_NAME` (`account_id`);

关于php - 我怎样才能使我的数据库响应时间和渲染时间更好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26768337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com