Optimization of SQL queries: fixed!

SVN:trunk[2486]
This commit is contained in:
Romain Quetiez
2012-11-30 16:26:53 +00:00
parent 78cb9f793a
commit 3784a41d9e
2 changed files with 13 additions and 15 deletions

View File

@@ -145,7 +145,7 @@ class Config
'type' => 'bool',
'description' => 'For developpers: format the SQL queries for human analysis',
'default' => false,
'value' => true,
'value' => false,
'source_of_value' => '',
'show_in_conf_sample' => false,
),

View File

@@ -2138,7 +2138,6 @@ abstract class MetaModel
}
$oSelect = self::MakeSelectStructure($oFilter, $aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, $iLimitCount, $iLimitStart, $bGetCount);
$oSelect = unserialize(serialize($oSelect));
$aScalarArgs = array_merge(self::PrepareQueryArguments($aArgs), $oFilter->GetInternalParams());
try
@@ -2245,8 +2244,8 @@ abstract class MetaModel
if (array_key_exists($sOqlId, self::$m_aQueryStructCache))
{
// hit!
$oSelect = clone self::$m_aQueryStructCache[$sOqlId];
// Note: cloning is not enough... should be replaced by unserialize(serialize()) !!!
$oSelect = unserialize(serialize(self::$m_aQueryStructCache[$sOqlId]));
// Note: cloning is not enough because the subtree is made of objects
}
elseif (self::$m_bUseAPCCache)
{
@@ -2284,6 +2283,16 @@ abstract class MetaModel
$oSelect->SetSelect($oBuild->m_oQBExpressions->GetSelect());
}
if (self::$m_bOptimizeQueries)
{
if ($bGetCount)
{
// Simplify the query if just getting the count
$oSelect->SetSelect(array());
}
$oSelect->OptimizeJoins();
}
$oKPI->ComputeStats('MakeQuery (select)', $sOqlQuery);
if (self::$m_bQueryCacheEnabled)
@@ -2297,17 +2306,6 @@ abstract class MetaModel
self::$m_aQueryStructCache[$sOqlId] = clone $oSelect;
}
if (self::$m_bOptimizeQueries)
{
// Simplify the query if just getting the count
//
if ($bGetCount)
{
$oSelect->SetSelect(array());
}
$oSelect->OptimizeJoins();
}
}
// Join to an additional table, if required...