r23939 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23938‎ | r23939 | r23940 >
Date:07:22, 10 July 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Avoid a lot of unneeded joins. Faster querying.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php
@@ -845,17 +845,19 @@
846846 * wrt. the category table.
847847 */
848848 protected function getCategoryTable($catname, &$db) {
849 - if (array_key_exists($catname, SMWSQLStore::$m_categorytables)) {
850 - return SMWSQLStore::$m_categorytables[$catname];
851 - }
852 -
853849 global $wgDBname, $smwgIQSubcategoryInclusions;
854850
855 - // Create multiple temporary tables for recursive computation
856851 $tablename = 'cats' . SMWSQLStore::$m_tablenum++;
857852 $db->query( 'CREATE TEMPORARY TABLE ' . $wgDBname . '.' . $tablename .
858853 '( cat_name VARCHAR(255) NOT NULL )
859854 TYPE=MEMORY', 'SMW::getCategoryTable' );
 855+ if (array_key_exists($catname, SMWSQLStore::$m_categorytables)) { // just copy known result
 856+ $db->insertSelect($tablename, array(SMWSQLStore::$m_categorytables[$catname]),
 857+ array('cat_name' => 'cat_name'),'*', 'SMW::getCategoryTable');
 858+ return $tablename;
 859+ }
 860+
 861+ // Create multiple temporary tables for recursive computation
860862 $db->query( 'CREATE TEMPORARY TABLE smw_newcats
861863 ( cat_name VARCHAR(255) NOT NULL )
862864 TYPE=MEMORY', 'SMW::getCategoryTable' );
@@ -1011,8 +1013,7 @@
10121014 global $smwgIQSubcategoryInclusions;
10131015 if ($smwgIQSubcategoryInclusions > 0) {
10141016 $ct = $this->getCategoryTable($description->getCategory()->getDBKey(), $db);
1015 - $ctalias = 'cl' . SMWSQLStore::$m_tablenum++;
1016 - $from .= " INNER JOIN $ct AS $ctalias ON $ctalias.cat_name=" . $curtables['CATS'] . '.cl_to';
 1017+ $from .= " INNER JOIN $ct ON $ct.cat_name=" . $curtables['CATS'] . '.cl_to';
10171018 } else {
10181019 $where .= $curtables['CATS'] . '.cl_to=' . $db->addQuotes($description->getCategory()->getDBKey());
10191020 }
@@ -1082,7 +1083,9 @@
10831084 foreach ($description->getDescriptions() as $subdesc) {
10841085 /// TODO: this is not optimal -- we drop more table aliases than needed, but its hard to find out what is feasible in recursive calls ...
10851086 $nexttables = array();
1086 - if (array_key_exists('PAGE',$curtables)) {
 1087+ // pull in page to prevent every child description pulling it seperately!
 1088+ /// TODO: willl be obsolete when PREVREL provides page indices
 1089+ if ($this->addInnerJoin('PAGE', $from, $db, $curtables)) {
10871090 $nexttables['PAGE'] = $curtables['PAGE'];
10881091 }
10891092 if (array_key_exists('PREVREL',$curtables)) {

Status & tagging log