mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-24 21:59:55 +09:00
Re-add missing support for index hints in XML query
This commit is contained in:
parent
2a5d99b2df
commit
a908cd9291
3 changed files with 82 additions and 0 deletions
|
|
@ -13,6 +13,7 @@ class Query extends VariableBase
|
|||
public $name;
|
||||
public $type;
|
||||
public $tables = array();
|
||||
public $index_hints = array();
|
||||
public $columns = array();
|
||||
public $conditions = array();
|
||||
public $groupby = null;
|
||||
|
|
@ -167,6 +168,14 @@ class Query extends VariableBase
|
|||
$result .= ' FROM ' . $tables;
|
||||
}
|
||||
}
|
||||
if (count($this->index_hints))
|
||||
{
|
||||
$index_hints = $this->_arrangeIndexHints($this->index_hints);
|
||||
if ($index_hints !== '')
|
||||
{
|
||||
$result .= ' ' . $index_hints;
|
||||
}
|
||||
}
|
||||
|
||||
// Compose the WHERE clause.
|
||||
if (count($this->conditions))
|
||||
|
|
@ -418,6 +427,37 @@ class Query extends VariableBase
|
|||
return implode('', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate index hints.
|
||||
*
|
||||
* @param array $index_hints
|
||||
* @return string
|
||||
*/
|
||||
protected function _arrangeIndexHints(array $index_hints): string
|
||||
{
|
||||
// Initialize the index list by type.
|
||||
$index_list = [];
|
||||
|
||||
// Group each index hint by type.
|
||||
foreach ($index_hints as $index_hint)
|
||||
{
|
||||
if (!count($index_hint->target_db) || isset($index_hint->target_db['mysql']))
|
||||
{
|
||||
$key = $index_hint->hint_type ?: 'USE';
|
||||
$index_list[$key] = $index_list[$key] ?? [];
|
||||
$index_list[$key][] = $index_hint->index_name;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a list of indexes for each group.
|
||||
$result = [];
|
||||
foreach ($index_list as $key => $val)
|
||||
{
|
||||
$result[] = sprintf('%s INDEX (%s)', $key, implode(', ', $val));
|
||||
}
|
||||
return implode(' ', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a WHERE clause from a list of conditions.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue