mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-10 20:44:28 +09:00
parent
0c6bc8fbb1
commit
03e5909036
6 changed files with 81 additions and 4 deletions
|
|
@ -11,4 +11,5 @@ class IndexHint
|
||||||
public $hint_type = '';
|
public $hint_type = '';
|
||||||
public $index_name = '';
|
public $index_name = '';
|
||||||
public $table_name = '';
|
public $table_name = '';
|
||||||
|
public $var;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -469,7 +469,14 @@ class Query extends VariableBase
|
||||||
{
|
{
|
||||||
$key = $index_hint->hint_type ?: 'USE';
|
$key = $index_hint->hint_type ?: 'USE';
|
||||||
$index_list[$key] = $index_list[$key] ?? [];
|
$index_list[$key] = $index_list[$key] ?? [];
|
||||||
$index_list[$key][] = $index_hint->index_name;
|
if ($index_hint->var && isset($this->_args[$index_hint->var]))
|
||||||
|
{
|
||||||
|
$index_list[$key][] = self::quoteName($this->_args[$index_hint->var]);
|
||||||
|
}
|
||||||
|
elseif ($index_hint->index_name)
|
||||||
|
{
|
||||||
|
$index_list[$key][] = self::quoteName($index_hint->index_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -477,7 +484,10 @@ class Query extends VariableBase
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($index_list as $key => $val)
|
foreach ($index_list as $key => $val)
|
||||||
{
|
{
|
||||||
$result[] = sprintf('%s INDEX (%s)', $key, implode(', ', $val));
|
if (count($val))
|
||||||
|
{
|
||||||
|
$result[] = sprintf('%s INDEX (%s)', $key, implode(', ', $val));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return implode(' ', $result);
|
return implode(' ', $result);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,15 @@ class DBQueryParser extends BaseParser
|
||||||
$index_hint->hint_type = strtoupper(trim($tag['type'])) ?: 'USE';
|
$index_hint->hint_type = strtoupper(trim($tag['type'])) ?: 'USE';
|
||||||
$index_hint->index_name = trim($tag['name']) ?: '';
|
$index_hint->index_name = trim($tag['name']) ?: '';
|
||||||
$index_hint->table_name = trim($tag['table']) ?: '';
|
$index_hint->table_name = trim($tag['table']) ?: '';
|
||||||
if ($index_hint->index_name)
|
if (isset($tag['var']) && trim($tag['var']))
|
||||||
|
{
|
||||||
|
$index_hint->var = trim($tag['var']);
|
||||||
|
}
|
||||||
|
if (isset($tag['default']) && trim($tag['default']))
|
||||||
|
{
|
||||||
|
$index_hint->index_name = trim($tag['default']);
|
||||||
|
}
|
||||||
|
if ($index_hint->index_name || $index_hint->var)
|
||||||
{
|
{
|
||||||
$query->index_hints[] = $index_hint;
|
$query->index_hints[] = $index_hint;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
tests/_data/dbquery/indexHintTest1.xml
Normal file
17
tests/_data/dbquery/indexHintTest1.xml
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<query id="indexHintTest1" action="select">
|
||||||
|
<tables>
|
||||||
|
<table name="documents" />
|
||||||
|
</tables>
|
||||||
|
<index_hint for="MYSQL">
|
||||||
|
<index name="idx_module_srl" type="USE" />
|
||||||
|
</index_hint>
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="module_srl" var="module_srl" filter="number" notnull="notnull" />
|
||||||
|
</conditions>
|
||||||
|
<navigation>
|
||||||
|
<index var="sort_index" default="list_order" order="desc" />
|
||||||
|
<list_count var="list_count" default="20" />
|
||||||
|
<page_count var="page_count" default="10" />
|
||||||
|
<page var="page" default="1" />
|
||||||
|
</navigation>
|
||||||
|
</query>
|
||||||
18
tests/_data/dbquery/indexHintTest2.xml
Normal file
18
tests/_data/dbquery/indexHintTest2.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<query id="indexHintTest2" action="select">
|
||||||
|
<tables>
|
||||||
|
<table name="documents" />
|
||||||
|
</tables>
|
||||||
|
<index_hint for="ALL">
|
||||||
|
<index var="index_hint1" type="FORCE" />
|
||||||
|
<index var="index_hint2" default="idx_module_list_order" type="USE" />
|
||||||
|
</index_hint>
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="module_srl" var="module_srl" filter="number" notnull="notnull" />
|
||||||
|
</conditions>
|
||||||
|
<navigation>
|
||||||
|
<index var="sort_index" default="list_order" order="desc" />
|
||||||
|
<list_count var="list_count" default="20" />
|
||||||
|
<page_count var="page_count" default="10" />
|
||||||
|
<page var="page" default="1" />
|
||||||
|
</navigation>
|
||||||
|
</query>
|
||||||
|
|
@ -271,7 +271,30 @@ class DBQueryParserTest extends \Codeception\TestCase\Test
|
||||||
$sql = $query->getQueryString('rx_', ['document_srl_list' => [100, 110, 120]], [], true);
|
$sql = $query->getQueryString('rx_', ['document_srl_list' => [100, 110, 120]], [], true);
|
||||||
$this->assertEquals('SELECT COUNT(*) AS `count` FROM (SELECT DISTINCT `module_srl` FROM `rx_documents` AS `documents` ' .
|
$this->assertEquals('SELECT COUNT(*) AS `count` FROM (SELECT DISTINCT `module_srl` FROM `rx_documents` AS `documents` ' .
|
||||||
'WHERE `document_srl` IN (?, ?, ?)) AS `subquery`', $sql);
|
'WHERE `document_srl` IN (?, ?, ?)) AS `subquery`', $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testIndexHintQuery()
|
||||||
|
{
|
||||||
|
$query = Rhymix\Framework\Parsers\DBQueryParser::loadXML(\RX_BASEDIR . 'tests/_data/dbquery/indexHintTest1.xml');
|
||||||
|
$sql = $query->getQueryString('rx_', ['module_srl' => 82]);
|
||||||
|
$this->assertEquals('SELECT * FROM `rx_documents` AS `documents` USE INDEX (`idx_module_srl`) ' .
|
||||||
|
'WHERE `module_srl` = ? ORDER BY `list_order` DESC LIMIT 20', $sql);
|
||||||
|
|
||||||
|
$query = Rhymix\Framework\Parsers\DBQueryParser::loadXML(\RX_BASEDIR . 'tests/_data/dbquery/indexHintTest2.xml');
|
||||||
|
$sql = $query->getQueryString('rx_', ['module_srl' => 82]);
|
||||||
|
$this->assertEquals('SELECT * FROM `rx_documents` AS `documents` USE INDEX (`idx_module_list_order`) ' .
|
||||||
|
'WHERE `module_srl` = ? ORDER BY `list_order` DESC LIMIT 20', $sql);
|
||||||
|
|
||||||
|
$query = Rhymix\Framework\Parsers\DBQueryParser::loadXML(\RX_BASEDIR . 'tests/_data/dbquery/indexHintTest2.xml');
|
||||||
|
$sql = $query->getQueryString('rx_', ['module_srl' => 82, 'index_hint1' => 'idx_regdate']);
|
||||||
|
$this->assertEquals('SELECT * FROM `rx_documents` AS `documents` FORCE INDEX (`idx_regdate`) USE INDEX (`idx_module_list_order`) ' .
|
||||||
|
'WHERE `module_srl` = ? ORDER BY `list_order` DESC LIMIT 20', $sql);
|
||||||
|
|
||||||
|
$query = Rhymix\Framework\Parsers\DBQueryParser::loadXML(\RX_BASEDIR . 'tests/_data/dbquery/indexHintTest2.xml');
|
||||||
|
$sql = $query->getQueryString('rx_', ['module_srl' => 82, 'index_hint1' => 'idx_regdate', 'index_hint2' => 'idx_member_srl']);
|
||||||
|
$this->assertEquals('SELECT * FROM `rx_documents` AS `documents` FORCE INDEX (`idx_regdate`) USE INDEX (`idx_member_srl`) ' .
|
||||||
|
'WHERE `module_srl` = ? ORDER BY `list_order` DESC LIMIT 20', $sql);
|
||||||
|
}
|
||||||
|
|
||||||
public function testInsertQuery()
|
public function testInsertQuery()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue