Added support for index hinting.

This commit is contained in:
Josh Sherman 2010-11-26 23:16:56 -05:00
parent c32ee1a12e
commit 7e1a45e9cb

View file

@ -110,6 +110,14 @@ class Model extends Object
*/
protected $joins = false; // JOIN
/**
* [Index] Hints
*
* @access protected
* @var mixed
*/
protected $hints = false; // USE INDEX
/**
* Conditions
*
@ -414,6 +422,33 @@ class Model extends Object
}
}
// Adds the index hints
if ($this->hints != false)
{
if (is_array($this->hints))
{
foreach ($this->hints as $hint => $columns)
{
if (is_array($columns))
{
$this->sql[] = $hint . ' (' . implode(', ', $columns) . ')';
}
else
{
$format = (stripos($columns, 'USE ') === false);
$this->sql[] = ($format == true ? 'USE INDEX (' : '') . $columns . ($format == true ? ')' : '');
}
}
}
else
{
$format = (stripos($this->hints, 'USE ') === false);
$this->sql[] = ($format == true ? 'USE INDEX (' : '') . $this->hints . ($format == true ? ')' : '');
}
}
// Adds the WHERE conditionals
if ($this->conditions != false)
{