我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

LIMIT替代品

When I run this query and $from has a really big value, it takes too much in returning the answer (more than 30 secs).

Is there any way to go directly to the $from row and return $users_per_page amount of records without go through the whole database?

$query = 'SELECT * FROM users ORDER BY user_id LIMIT ' . $from. ' , '. $users_per_page;

Adding an index on user_id will prevent a table scan. As long as users_per_page is small then the query will be fast.

CREATE INDEX index_users_on_user_id ON users (user_id);

近期文章

  • CakePHP保存具有类似数据的模型
  • 使用PDO / PHP获取数据和循环[关闭]
  • 无法将PHP数组传递给jquery:JSON数据后出现意外的非空白字符
  • 如何在PHP中绘制图形? [关闭]
  • 确定值是否在表中的最有效方法
  • 无法在无脂肪框架3中创建分页
  • 如何使用jquery发布到新的php页面
  • 从AJAX调用中加载knock中的knockout.js形式
  • 使用YII框架提交表单后更新会话中的值
  • 循环遍历DISTINCT行
  • 无法获得功能,尝试过一切。 涉及剥离标点符号和空格
  • 如果比较两个变量php
  • 从多维数组值创建字符串
  • 检查while循环完成php的时间
  • 如何删除脚本标记,如{audio} {/ audio}或{youtube} {/ youtube}
  • Solr在多个集合中搜索
  • 将多个DB字段条目分配给单个变量
  • 根据数据头排序数据
  • sqlsrv_fetch_array()期望参数1是资源
  • Wordpress - 具有3个输入字段和自定义帖子类型

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华