我在Codeigniter(PHP Framework)工作。在我的网站上,我正在列出"用户列表"这是大约10,00,000条记录。我已经应用了每页限制10条记录的分页。当我加载网页时,我得到以下错误"致命错误:允许的内存大小为134217728字节用尽"。我有解决方案设置" ini_set(' Memory_limit',' -1');"在我的控制器中或在php.ini文件中配置。但现在问题是在配置" ini_set(' Memory_limit',' -1');"在我的控制器中,从服务器获取数据的响应时间太晚了。
我已经创建了动态查询来获取用户数据。它的外观如下所示:
SELECT DISTINCT (SELECT user_id from tbl_login_track WHERE user_id=U.user_id ORDER BY created_date desc LIMIT 1) as user,(SELECT created_date from tbl_login_track WHERE user_id=U.user_id ORDER BY created_date desc LIMIT 1) as user_login_date,DATEDIFF(CURRENT_TIMESTAMP,(SELECT created_date from tbl_login_track WHERE user_id=U.user_id ORDER BY created_date desc LIMIT 1)) as last_login,PP.product_plan_name , U.*,(SELECT COUNT(*) FROM tbl_product WHERE user_id = U.user_id) AS product_post_count FROM tbl_user as U JOIN tbl_product_plan as PP ON U.product_plan_id=PP.product_plan_id LEFT JOIN tbl_login_track as LT ON U.user_id=LT.user_id limit 0,10
必需:希望缩短查询结果时间。
提前致谢。
答案 0 :(得分:1)
我已经创建了动态查询来获取用户数据。它的外观如下所示:
SELECT DISTINCT (SELECT user_id from tbl_login_track WHERE user_id=U.user_id ORDER BY created_date desc LIMIT 1) as user,(SELECT created_date from tbl_login_track WHERE user_id=U.user_id ORDER BY created_date desc LIMIT 1) as user_login_date,DATEDIFF(CURRENT_TIMESTAMP,(SELECT created_date from tbl_login_track WHERE user_id=U.user_id ORDER BY created_date desc LIMIT 1)) as last_login,PP.product_plan_name , U.*,(SELECT COUNT(*) FROM tbl_product WHERE user_id = U.user_id) AS product_post_count FROM tbl_user as U JOIN tbl_product_plan as PP ON U.product_plan_id=PP.product_plan_id LEFT JOIN tbl_login_track as LT ON U.user_id=LT.user_id limit 0,10