获得学说使用MySQL“FORCE INDEX” [英] Getting Doctrine to use MySQL "FORCE INDEX"

查看:162
本文介绍了获得学说使用MySQL“FORCE INDEX”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Doctrine的DQL中有一个查询,需要能够使用MySQL的FORCE INDEX功能,以便大大减少查询时间。以下是在纯SQL中基本上看起来的内容:

  SELECT id FROM items FORCE INDEX(best_selling_idx)
WHERE price = ...(etc)
LIMIT 200;

我假设我必须扩展一些Doctrine组件才能使用DQL(或者在那里)一种将任意SQL注入到Doctrin的查询之一中的方法)。任何人都有任何想法?



谢谢!

解决方案

发现很少有用的Doctrine_RawSql示例在线,所以这里是我最后做的来创建我的查询。

  $ 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' ;


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;

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?

Thanks!

解决方案

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');

这篇关于获得学说使用MySQL“FORCE INDEX”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆