diff --git a/core/config.class.inc.php b/core/config.class.inc.php index e8be33615..d8135eadc 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -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, ), diff --git a/core/metamodel.class.php b/core/metamodel.class.php index dc1f49065..11269d27f 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -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...