Getting Doctrine to use MySQL quot;FORCE INDEXquot;(让 Doctrine 使用 MySQL “FORCE INDEX)
问题描述
我在 Doctrine 的 DQL 中有一个查询,需要能够使用 MySQL 的FORCE INDEX".功能,以大大减少查询时间.下面是查询在普通 SQL 中的基本样子:
I have a query in Doctrine's DQL that needs to be able to use MySQL's "FORCE INDEX" functionality in order to massively reduce the query time. Below is what the query basically looks like in plain SQL:
SELECT id FROM items FORCE INDEX (best_selling_idx)
WHERE price = ... (etc)
LIMIT 200;
我假设我必须扩展一些 Doctrine 组件才能使用 DQL 执行此操作(或者有没有办法将任意 SQL 注入到 Doctrin 的查询之一中?).有人有什么想法吗?
I assume I have to extend some Doctrine component to be able to do this with DQL (or is there a way to inject arbitrary SQL into one of Doctrin's queries?). Anyone have any ideas?
推荐答案
我在网上找到了很少有帮助的 Doctrine_RawSql 示例,所以这就是我最终创建查询的方法.
I've found very few helpful Doctrine_RawSql examples online, so here's what I ended up doing to create my query.
$q = new Doctrine_RawSql();
$q->select('{b.id}, {b.description}, {c.description}')
->from('table1 b FORCE INDEX(best_selling_idx) INNER JOIN table2 c ON b.c_id = c.id')
->addComponent('b', 'Table1 b')
->addComponent('c', 'b.Table2 c');
这篇关于让 Doctrine 使用 MySQL “FORCE INDEX"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:让 Doctrine 使用 MySQL “FORCE INDEX"


基础教程推荐
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- php中的PDF导出 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- php中的foreach复选框POST 2021-01-01
- 将变量从树枝传递给 js 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- Web 服务器如何处理请求? 2021-01-01