sqlobjectquery.class.inc.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <?php
  2. // Copyright (C) 2015 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * SQLObjectQuery
  20. * build a mySQL compatible SQL query
  21. *
  22. * @copyright Copyright (C) 2015 Combodo SARL
  23. * @license http://opensource.org/licenses/AGPL-3.0
  24. */
  25. /**
  26. * SQLObjectQuery
  27. * build a mySQL compatible SQL query
  28. *
  29. * @package iTopORM
  30. */
  31. class SQLObjectQuery extends SQLQuery
  32. {
  33. private $m_SourceOQL = '';
  34. private $m_sTable = '';
  35. private $m_sTableAlias = '';
  36. private $m_aFields = array();
  37. private $m_aGroupBy = array();
  38. private $m_oConditionExpr = null;
  39. private $m_bToDelete = true; // The current table must be listed for deletion ?
  40. private $m_aValues = array(); // Values to set in case of an update query
  41. private $m_oSelectedIdField = null;
  42. private $m_aJoinSelects = array();
  43. private $m_bBeautifulQuery = false;
  44. // Data set by PrepareRendering()
  45. private $__aFrom;
  46. private $__aFields;
  47. private $__aGroupBy;
  48. private $__aDelTables;
  49. private $__aSetValues;
  50. private $__aSelectedIdFields;
  51. public function __construct($sTable, $sTableAlias, $aFields, $bToDelete = true, $aValues = array(), $oSelectedIdField = null)
  52. {
  53. parent::__construct();
  54. // This check is not needed but for developping purposes
  55. //if (!CMDBSource::IsTable($sTable))
  56. //{
  57. // throw new CoreException("Unknown table '$sTable'");
  58. //}
  59. // $aFields must be an array of "alias"=>"expr"
  60. // $oConditionExpr must be a condition tree
  61. // $aValues is an array of "alias"=>value
  62. $this->m_sTable = $sTable;
  63. $this->m_sTableAlias = $sTableAlias;
  64. $this->m_aFields = $aFields;
  65. $this->m_aGroupBy = null;
  66. $this->m_oConditionExpr = null;
  67. $this->m_bToDelete = $bToDelete;
  68. $this->m_aValues = $aValues;
  69. $this->m_oSelectedIdField = $oSelectedIdField;
  70. }
  71. public function GetTableAlias()
  72. {
  73. return $this->m_sTableAlias;
  74. }
  75. public function DisplayHtml()
  76. {
  77. if (count($this->m_aFields) == 0) $sFields = "";
  78. else
  79. {
  80. $aFieldDesc = array();
  81. foreach ($this->m_aFields as $sAlias => $oExpression)
  82. {
  83. $aFieldDesc[] = $oExpression->Render()." as <em>$sAlias</em>";
  84. }
  85. $sFields = " =&gt; ".implode(', ', $aFieldDesc);
  86. }
  87. echo "<b>$this->m_sTable</b>$sFields<br/>\n";
  88. // #@# todo - display html of an expression tree
  89. //$this->m_oConditionExpr->DisplayHtml()
  90. if (count($this->m_aJoinSelects) > 0)
  91. {
  92. echo "Joined to...<br/>\n";
  93. echo "<ul class=\"treeview\">\n";
  94. foreach ($this->m_aJoinSelects as $aJoinInfo)
  95. {
  96. $sJoinType = $aJoinInfo["jointype"];
  97. $oSQLQuery = $aJoinInfo["select"];
  98. if (isset($aJoinInfo["on_expression"]))
  99. {
  100. $sOnCondition = $aJoinInfo["on_expression"]->Render();
  101. echo "<li>Join '$sJoinType', ON ($sOnCondition)".$oSQLQuery->DisplayHtml()."</li>\n";
  102. }
  103. else
  104. {
  105. $sLeftField = $aJoinInfo["leftfield"];
  106. $sRightField = $aJoinInfo["rightfield"];
  107. $sRightTableAlias = $aJoinInfo["righttablealias"];
  108. echo "<li>Join '$sJoinType', $sLeftField, $sRightTableAlias.$sRightField".$oSQLQuery->DisplayHtml()."</li>\n";
  109. }
  110. }
  111. echo "</ul>";
  112. }
  113. $this->PrepareRendering();
  114. echo "From ...<br/>\n";
  115. echo "<pre style=\"font-size: smaller;\">\n";
  116. print_r($this->__aFrom);
  117. echo "</pre>";
  118. }
  119. public function SetSelect($aExpressions)
  120. {
  121. $this->m_aFields = $aExpressions;
  122. }
  123. public function AddSelect($sAlias, $oExpression)
  124. {
  125. $this->m_aFields[$sAlias] = $oExpression;
  126. }
  127. public function SetGroupBy($aExpressions)
  128. {
  129. $this->m_aGroupBy = $aExpressions;
  130. }
  131. public function SetCondition($oConditionExpr)
  132. {
  133. $this->m_oConditionExpr = $oConditionExpr;
  134. }
  135. public function AddCondition($oConditionExpr)
  136. {
  137. if (is_null($this->m_oConditionExpr))
  138. {
  139. $this->m_oConditionExpr = $oConditionExpr;
  140. }
  141. else
  142. {
  143. $this->m_oConditionExpr->LogAnd($oConditionExpr);
  144. }
  145. }
  146. private function AddJoin($sJoinType, $oSQLQuery, $sLeftField, $sRightField, $sRightTableAlias = '')
  147. {
  148. assert((get_class($oSQLQuery) == __CLASS__) || is_subclass_of($oSQLQuery, __CLASS__));
  149. // No need to check this here but for development purposes
  150. //if (!CMDBSource::IsField($this->m_sTable, $sLeftField))
  151. //{
  152. // throw new CoreException("Unknown field '$sLeftField' in table '".$this->m_sTable);
  153. //}
  154. if (empty($sRightTableAlias))
  155. {
  156. $sRightTableAlias = $oSQLQuery->m_sTableAlias;
  157. }
  158. // #@# Could not be verified here because the namespace is unknown - do we need to check it there?
  159. //
  160. // if (!CMDBSource::IsField($sRightTable, $sRightField))
  161. // {
  162. // throw new CoreException("Unknown field '$sRightField' in table '".$sRightTable."'");
  163. // }
  164. $this->m_aJoinSelects[] = array(
  165. "jointype" => $sJoinType,
  166. "select" => $oSQLQuery,
  167. "leftfield" => $sLeftField,
  168. "rightfield" => $sRightField,
  169. "righttablealias" => $sRightTableAlias
  170. );
  171. }
  172. public function AddInnerJoin($oSQLQuery, $sLeftField, $sRightField, $sRightTable = '')
  173. {
  174. $this->AddJoin("inner", $oSQLQuery, $sLeftField, $sRightField, $sRightTable);
  175. }
  176. public function AddInnerJoinTree($oSQLQuery, $sLeftFieldLeft, $sLeftFieldRight, $sRightFieldLeft, $sRightFieldRight, $sRightTableAlias = '', $iOperatorCode = TREE_OPERATOR_BELOW)
  177. {
  178. assert((get_class($oSQLQuery) == __CLASS__) || is_subclass_of($oSQLQuery, __CLASS__));
  179. if (empty($sRightTableAlias))
  180. {
  181. $sRightTableAlias = $oSQLQuery->m_sTableAlias;
  182. }
  183. $this->m_aJoinSelects[] = array(
  184. "jointype" => 'inner_tree',
  185. "select" => $oSQLQuery,
  186. "leftfield" => $sLeftFieldLeft,
  187. "rightfield" => $sLeftFieldRight,
  188. "rightfield_left" => $sRightFieldLeft,
  189. "rightfield_right" => $sRightFieldRight,
  190. "righttablealias" => $sRightTableAlias,
  191. "tree_operator" => $iOperatorCode);
  192. }
  193. public function AddLeftJoin($oSQLQuery, $sLeftField, $sRightField)
  194. {
  195. return $this->AddJoin("left", $oSQLQuery, $sLeftField, $sRightField);
  196. }
  197. public function AddInnerJoinEx(SQLQuery $oSQLQuery, Expression $oOnExpression)
  198. {
  199. $this->m_aJoinSelects[] = array(
  200. "jointype" => 'inner',
  201. "select" => $oSQLQuery,
  202. "on_expression" => $oOnExpression
  203. );
  204. }
  205. public function AddLeftJoinEx(SQLQuery $oSQLQuery, Expression $oOnExpression)
  206. {
  207. $this->m_aJoinSelects[] = array(
  208. "jointype" => 'left',
  209. "select" => $oSQLQuery,
  210. "on_expression" => $oOnExpression
  211. );
  212. }
  213. // Interface, build the SQL query
  214. public function RenderDelete($aArgs = array())
  215. {
  216. $this->PrepareRendering();
  217. // Target: DELETE myAlias1, myAlias2 FROM t1 as myAlias1, t2 as myAlias2, t3 as topreserve WHERE ...
  218. $sDelete = self::ClauseDelete($this->__aDelTables);
  219. $sFrom = self::ClauseFrom($this->__aFrom);
  220. // #@# safety net to redo ?
  221. /*
  222. if ($this->m_oConditionExpr->IsAny())
  223. -- if (count($aConditions) == 0) --
  224. {
  225. throw new CoreException("Building a request wich will delete every object of a given table -looks suspicious- please use truncate instead...");
  226. }
  227. */
  228. if (is_null($this->m_oConditionExpr))
  229. {
  230. // Delete all !!!
  231. }
  232. else
  233. {
  234. $sWhere = self::ClauseWhere($this->m_oConditionExpr, $aArgs);
  235. return "DELETE $sDelete FROM $sFrom WHERE $sWhere";
  236. }
  237. }
  238. /**
  239. * Needed for the unions
  240. */
  241. public function RenderSelectClause()
  242. {
  243. $this->PrepareRendering();
  244. $sSelect = self::ClauseSelect($this->__aFields);
  245. return $sSelect;
  246. }
  247. /**
  248. * Needed for the unions
  249. */
  250. public function RenderOrderByClause($aOrderBy)
  251. {
  252. $this->PrepareRendering();
  253. $sOrderBy = self::ClauseOrderBy($aOrderBy);
  254. return $sOrderBy;
  255. }
  256. // Interface, build the SQL query
  257. public function RenderUpdate($aArgs = array())
  258. {
  259. $this->PrepareRendering();
  260. $sFrom = self::ClauseFrom($this->__aFrom);
  261. $sValues = self::ClauseValues($this->__aSetValues);
  262. $sWhere = self::ClauseWhere($this->m_oConditionExpr, $aArgs);
  263. return "UPDATE $sFrom SET $sValues WHERE $sWhere";
  264. }
  265. // Interface, build the SQL query
  266. public function RenderSelect($aOrderBy = array(), $aArgs = array(), $iLimitCount = 0, $iLimitStart = 0, $bGetCount = false, $bBeautifulQuery = false)
  267. {
  268. $this->m_bBeautifulQuery = $bBeautifulQuery;
  269. $sLineSep = $this->m_bBeautifulQuery ? "\n" : '';
  270. $sIndent = $this->m_bBeautifulQuery ? " " : null;
  271. $this->PrepareRendering();
  272. $sFrom = self::ClauseFrom($this->__aFrom, $sIndent);
  273. $sWhere = self::ClauseWhere($this->m_oConditionExpr, $aArgs);
  274. if ($bGetCount)
  275. {
  276. if (count($this->__aSelectedIdFields) > 0)
  277. {
  278. $aCountFields = array();
  279. foreach ($this->__aSelectedIdFields as $sFieldExpr)
  280. {
  281. $aCountFields[] = "COALESCE($sFieldExpr, 0)"; // Null values are excluded from the count
  282. }
  283. $sCountFields = implode(', ', $aCountFields);
  284. $sSQL = "SELECT$sLineSep COUNT(DISTINCT $sCountFields) AS COUNT$sLineSep FROM $sFrom$sLineSep WHERE $sWhere";
  285. }
  286. else
  287. {
  288. $sSQL = "SELECT$sLineSep COUNT(*) AS COUNT$sLineSep FROM $sFrom$sLineSep WHERE $sWhere";
  289. }
  290. }
  291. else
  292. {
  293. $sSelect = self::ClauseSelect($this->__aFields);
  294. $sOrderBy = self::ClauseOrderBy($aOrderBy);
  295. if (!empty($sOrderBy))
  296. {
  297. $sOrderBy = "ORDER BY $sOrderBy$sLineSep";
  298. }
  299. if ($iLimitCount > 0)
  300. {
  301. $sLimit = 'LIMIT '.$iLimitStart.', '.$iLimitCount;
  302. }
  303. else
  304. {
  305. $sLimit = '';
  306. }
  307. $sSQL = "SELECT$sLineSep DISTINCT $sSelect$sLineSep FROM $sFrom$sLineSep WHERE $sWhere$sLineSep $sOrderBy $sLimit";
  308. }
  309. return $sSQL;
  310. }
  311. // Interface, build the SQL query
  312. public function RenderGroupBy($aArgs = array(), $bBeautifulQuery = false)
  313. {
  314. $this->m_bBeautifulQuery = $bBeautifulQuery;
  315. $sLineSep = $this->m_bBeautifulQuery ? "\n" : '';
  316. $sIndent = $this->m_bBeautifulQuery ? " " : null;
  317. $this->PrepareRendering();
  318. $sSelect = self::ClauseSelect($this->__aFields);
  319. $sFrom = self::ClauseFrom($this->__aFrom, $sIndent);
  320. $sWhere = self::ClauseWhere($this->m_oConditionExpr, $aArgs);
  321. $sGroupBy = self::ClauseGroupBy($this->__aGroupBy);
  322. $sSQL = "SELECT $sSelect,$sLineSep COUNT(*) AS _itop_count_$sLineSep FROM $sFrom$sLineSep WHERE $sWhere$sLineSep GROUP BY $sGroupBy";
  323. return $sSQL;
  324. }
  325. // Purpose: prepare the query data, once for all
  326. private function PrepareRendering()
  327. {
  328. if (is_null($this->__aFrom))
  329. {
  330. $this->__aFrom = array();
  331. $this->__aFields = array();
  332. $this->__aGroupBy = array();
  333. $this->__aDelTables = array();
  334. $this->__aSetValues = array();
  335. $this->__aSelectedIdFields = array();
  336. $this->PrepareSingleTable($this, $this->__aFrom, '', array('jointype' => 'first'));
  337. }
  338. }
  339. private function PrepareSingleTable(SQLObjectQuery $oRootQuery, &$aFrom, $sCallerAlias = '', $aJoinData)
  340. {
  341. $aTranslationTable[$this->m_sTable]['*'] = $this->m_sTableAlias;
  342. // Handle the various kinds of join (or first table in the list)
  343. //
  344. if (empty($aJoinData['righttablealias']))
  345. {
  346. $sRightTableAlias = $this->m_sTableAlias;
  347. }
  348. else
  349. {
  350. $sRightTableAlias = $aJoinData['righttablealias'];
  351. }
  352. switch ($aJoinData['jointype'])
  353. {
  354. case "first":
  355. $aFrom[$this->m_sTableAlias] = array("jointype"=>"first", "tablename"=>$this->m_sTable, "joincondition"=>"");
  356. break;
  357. case "inner":
  358. case "left":
  359. if (isset($aJoinData["on_expression"]))
  360. {
  361. $sJoinCond = $aJoinData["on_expression"]->Render();
  362. }
  363. else
  364. {
  365. $sJoinCond = "`$sCallerAlias`.`{$aJoinData['leftfield']}` = `$sRightTableAlias`.`{$aJoinData['rightfield']}`";
  366. }
  367. $aFrom[$this->m_sTableAlias] = array("jointype"=>$aJoinData['jointype'], "tablename"=>$this->m_sTable, "joincondition"=>"$sJoinCond");
  368. break;
  369. case "inner_tree":
  370. $sNodeLeft = "`$sCallerAlias`.`{$aJoinData['leftfield']}`";
  371. $sNodeRight = "`$sCallerAlias`.`{$aJoinData['rightfield']}`";
  372. $sRootLeft = "`$sRightTableAlias`.`{$aJoinData['rightfield_left']}`";
  373. $sRootRight = "`$sRightTableAlias`.`{$aJoinData['rightfield_right']}`";
  374. switch($aJoinData['tree_operator'])
  375. {
  376. case TREE_OPERATOR_BELOW:
  377. $sJoinCond = "$sNodeLeft >= $sRootLeft AND $sNodeLeft <= $sRootRight";
  378. break;
  379. case TREE_OPERATOR_BELOW_STRICT:
  380. $sJoinCond = "$sNodeLeft > $sRootLeft AND $sNodeLeft < $sRootRight";
  381. break;
  382. case TREE_OPERATOR_NOT_BELOW: // Complementary of 'BELOW'
  383. $sJoinCond = "$sNodeLeft < $sRootLeft OR $sNodeLeft > $sRootRight";
  384. break;
  385. case TREE_OPERATOR_NOT_BELOW_STRICT: // Complementary of BELOW_STRICT
  386. $sJoinCond = "$sNodeLeft <= $sRootLeft OR $sNodeLeft >= $sRootRight";
  387. break;
  388. case TREE_OPERATOR_ABOVE:
  389. $sJoinCond = "$sNodeLeft <= $sRootLeft AND $sNodeRight >= $sRootRight";
  390. break;
  391. case TREE_OPERATOR_ABOVE_STRICT:
  392. $sJoinCond = "$sNodeLeft < $sRootLeft AND $sNodeRight > $sRootRight";
  393. break;
  394. case TREE_OPERATOR_NOT_ABOVE: // Complementary of 'ABOVE'
  395. $sJoinCond = "$sNodeLeft > $sRootLeft OR $sNodeRight < $sRootRight";
  396. break;
  397. case TREE_OPERATOR_NOT_ABOVE_STRICT: // Complementary of ABOVE_STRICT
  398. $sJoinCond = "$sNodeLeft >= $sRootLeft OR $sNodeRight <= $sRootRight";
  399. break;
  400. }
  401. $aFrom[$this->m_sTableAlias] = array("jointype"=>$aJoinData['jointype'], "tablename"=>$this->m_sTable, "joincondition"=>"$sJoinCond");
  402. break;
  403. }
  404. // Given the alias, modify the fields and conditions
  405. // before adding them into the current lists
  406. //
  407. foreach($this->m_aFields as $sAlias => $oExpression)
  408. {
  409. $oRootQuery->__aFields["`$sAlias`"] = $oExpression->Render();
  410. }
  411. if ($this->m_aGroupBy)
  412. {
  413. foreach($this->m_aGroupBy as $sAlias => $oExpression)
  414. {
  415. $oRootQuery->__aGroupBy["`$sAlias`"] = $oExpression->Render();
  416. }
  417. }
  418. if ($this->m_bToDelete)
  419. {
  420. $oRootQuery->__aDelTables[] = "`{$this->m_sTableAlias}`";
  421. }
  422. foreach($this->m_aValues as $sFieldName=>$value)
  423. {
  424. $oRootQuery->__aSetValues["`{$this->m_sTableAlias}`.`$sFieldName`"] = $value; // quoted further!
  425. }
  426. if (!is_null($this->m_oSelectedIdField))
  427. {
  428. $oRootQuery->__aSelectedIdFields[] = $this->m_oSelectedIdField->Render();
  429. }
  430. // loop on joins, to complete the list of tables/fields/conditions
  431. //
  432. $aTempFrom = array(); // temporary subset of 'from' specs, to be grouped in the final query
  433. foreach ($this->m_aJoinSelects as $aJoinData)
  434. {
  435. $oRightSelect = $aJoinData["select"];
  436. $sJoinTableAlias = $oRightSelect->PrepareSingleTable($oRootQuery, $aTempFrom, $this->m_sTableAlias, $aJoinData);
  437. }
  438. $aFrom[$this->m_sTableAlias]['subfrom'] = $aTempFrom;
  439. return $this->m_sTableAlias;
  440. }
  441. public function OptimizeJoins($aUsedTables, $bTopCall = true)
  442. {
  443. if ($bTopCall)
  444. {
  445. // Top call: complete the list of tables absolutely required to perform the right query
  446. $this->CollectUsedTables($aUsedTables);
  447. }
  448. $aToDiscard = array();
  449. foreach ($this->m_aJoinSelects as $i => $aJoinInfo)
  450. {
  451. $oSQLQuery = $aJoinInfo["select"];
  452. $sTableAlias = $oSQLQuery->GetTableAlias();
  453. if ($oSQLQuery->OptimizeJoins($aUsedTables, false) && !array_key_exists($sTableAlias, $aUsedTables))
  454. {
  455. $aToDiscard[] = $i;
  456. }
  457. }
  458. foreach ($aToDiscard as $i)
  459. {
  460. unset($this->m_aJoinSelects[$i]);
  461. }
  462. return (count($this->m_aJoinSelects) == 0);
  463. }
  464. protected function CollectUsedTables(&$aTables)
  465. {
  466. $this->m_oConditionExpr->CollectUsedParents($aTables);
  467. foreach($this->m_aFields as $sFieldAlias => $oField)
  468. {
  469. $oField->CollectUsedParents($aTables);
  470. }
  471. if ($this->m_aGroupBy)
  472. {
  473. foreach($this->m_aGroupBy as $sAlias => $oExpression)
  474. {
  475. $oExpression->CollectUsedParents($aTables);
  476. }
  477. }
  478. if (!is_null($this->m_oSelectedIdField))
  479. {
  480. $this->m_oSelectedIdField->CollectUsedParents($aTables);
  481. }
  482. foreach ($this->m_aJoinSelects as $i => $aJoinInfo)
  483. {
  484. $oSQLQuery = $aJoinInfo["select"];
  485. if ($oSQLQuery->HasRequiredTables($aTables))
  486. {
  487. // There is something required in the branch, then this node is a MUST
  488. if (isset($aJoinInfo['righttablealias']))
  489. {
  490. $aTables[$aJoinInfo['righttablealias']] = true;
  491. }
  492. if (isset($aJoinInfo["on_expression"]))
  493. {
  494. $sJoinCond = $aJoinInfo["on_expression"]->CollectUsedParents($aTables);
  495. }
  496. }
  497. }
  498. return $aTables;
  499. }
  500. // Is required in the JOIN, and therefore we must ensure that the join expression will be valid
  501. protected function HasRequiredTables(&$aTables)
  502. {
  503. $bResult = false;
  504. if (array_key_exists($this->m_sTableAlias, $aTables))
  505. {
  506. $bResult = true;
  507. }
  508. foreach ($this->m_aJoinSelects as $i => $aJoinInfo)
  509. {
  510. $oSQLQuery = $aJoinInfo["select"];
  511. if ($oSQLQuery->HasRequiredTables($aTables))
  512. {
  513. // There is something required in the branch, then this node is a MUST
  514. if (isset($aJoinInfo['righttablealias']))
  515. {
  516. $aTables[$aJoinInfo['righttablealias']] = true;
  517. }
  518. if (isset($aJoinInfo["on_expression"]))
  519. {
  520. $sJoinCond = $aJoinInfo["on_expression"]->CollectUsedParents($aTables);
  521. }
  522. $bResult = true;
  523. }
  524. }
  525. // None of the tables is in the list of required tables
  526. return $bResult;
  527. }
  528. }