有办法在CodeIgniter中指定“使用索引”或“强制索引”吗
16lz
2021-01-22
Is it possible to specify "USE INDEX" or "FORCE INDEX" in CodeIgniter, other than using
除了使用之外,是否可以在CodeIgniter中指定“使用索引”或“强制索引”
$this->db->query()
What I mean is if it's possible to insert "FORCE INDEX" somewhere in one of ActiveRecord's methods.
我的意思是,如果可以在ActiveRecord的某个方法中插入“FORCE INDEX”。
1 个解决方案
#1
4
You can use the from()
active record method to add this in queries like this:
您可以使用from()活动记录方法在如下查询中添加:
$this->db->like('name', 'user', 'after')->from('users use index (name)')->get();
produces sql query like this:
生成如下sql查询:
SELECT * FROM (`users` use index (name)) WHERE `name` LIKE 'user%'
One caveat is that the from()
method tries to find identifiers and multiple tables so adding one or more ,
to it's input is most likely to end up as an SQL syntax error.
需要注意的一点是,from()方法试图查找标识符和多个表,因此向其输入添加一个或多个表很可能会导致SQL语法错误。
更多相关文章
- php使用mysql数据库时中文不显示或显示异常解决方法
- 保存在Java桌面应用程序应用程序和网站上使用的个人用户设置的最
- MySQL 存储过程查询远程数据库的方法
- 深入理解Mysql索引底层数据结构与算法
- 为什么MySQL查询优化器会选择聚集主索引上的二级索引?
- 有没有更好的方法来编写这个MySQL查询?
- 计算机管理没有mysql服务项的解决方法
- Mysql索引基础原理
- mysql 批量更新与批量更新多条记录的不同值实现方法