kadanis wrote:
> 
> Just wondering if anyone has any suggestions on this.
> 
> I'm using Cake for a current project and the project lead is insisting
> we use FORCE INDEX on the queries and table joins.
> 
> 

Recently I've play with it a little. My workaround is:

1. Create my own datasource - (in my case extending DboMysql)
data source has two tasks:

its overrides read method and checks if model has set useIndex field    

        if (!empty($model->useIndex)) {
                $this->useIndex = $model->useIndex;
        }

        return parent::read($model, $queryData);

and it overrides renderStatement method and if $model->useIndex field was
set, adding its value after  table alias in select statement.
        
if (strtolower($type) == 'select' && !empty($this->useIndex)) {
        $res = "SELECT {$fields} FROM {$table} {$alias} {$this->useIndex} 
{$joins}
{$conditions} {$group} {$order} {$limit}";
} else {
        $res = parent::renderStatement($type, $data);
}

$this->useIndex = null;
return $res;


2. Setting up model field whitch contains sql part of use index, force index
or ignore index

eg in controller:
$this->Task->useIndex = 'IGNORE INDEX(ind_usr_id)';
$this->paginate = array(
        'fields' => array('Task.id', 'Task.name','User.id', 'User.name'),
        'order' => 'Task.id',
        'limit' => 10
);
$this->paginate('Task');


To make it work, you should also set this datasource as datasource for your
model.

In fact, this is rather experimental and I didn't use it in production
environment yet :), but mayby it can help you.

-- 
Przemoo
-- 
View this message in context: 
http://cakephp.1045679.n5.nabble.com/Using-USE-INDEX-or-FORCE-INDEX-in-Model-find-relationships-tp3281552p3300205.html
Sent from the CakePHP mailing list archive at Nabble.com.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to