r25975 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25974‎ | r25975 | r25976 >
Date:21:15, 20 September 2007
Author:erik
Status:old
Tags:
Comment:
Port & commit Berto's changes to use UNIONs instead of IN() for atomic caching.
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php
@@ -10,47 +10,59 @@
1111 require_once('DefinedMeaningModel.php');
1212 require_once('ViewInformation.php');
1313
 14+
1415 function getSynonymSQLForLanguage($languageId, array &$definedMeaningIds) {
1516 $dc=wdGetDataSetContext();
16 -
17 - return
18 - "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " .
 17+
 18+ # Query building
 19+ $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " .
1920 " FROM {$dc}_defined_meaning, {$dc}_syntrans, {$dc}_expression " .
20 - " WHERE {$dc}_defined_meaning.defined_meaning_id IN (" . implode(", ", $definedMeaningIds) . ")" .
21 - " AND " . getLatestTransactionRestriction("{$dc}_syntrans") .
 21+ " WHERE " . getLatestTransactionRestriction("{$dc}_syntrans") .
2222 " AND " . getLatestTransactionRestriction("{$dc}_expression") .
2323 " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning") .
2424 " AND {$dc}_expression.language_id=" . $languageId .
2525 " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id " .
2626 " AND {$dc}_defined_meaning.defined_meaning_id={$dc}_syntrans.defined_meaning_id " .
2727 " AND {$dc}_syntrans.identical_meaning=1 " .
28 - " GROUP BY {$dc}_defined_meaning.defined_meaning_id";
 28+ " AND {$dc}_defined_meaning.defined_meaning_id = ";
 29+
 30+ # Build atomic queries
 31+ $definedMeaningIdsCopy = $definedMeaningIds;
 32+ foreach ($definedMeaningIdsCopy as &$value) {$value = $frontQuery . $value; }
 33+ unset($value);
 34+ # Union of the atoms
 35+ return implode(' UNION ',$definedMeaningIdsCopy);
2936 }
3037
3138 function getSynonymSQLForAnyLanguage(array &$definedMeaningIds) {
3239 $dc=wdGetDataSetContext();
3340
34 - return
35 - "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " .
 41+ # Query building
 42+ $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " .
3643 " FROM {$dc}_defined_meaning, {$dc}_syntrans, {$dc}_expression " .
37 - " WHERE {$dc}_defined_meaning.defined_meaning_id IN (" . implode(", ", $definedMeaningIds) . ")" .
38 - " AND " . getLatestTransactionRestriction("{$dc}_syntrans") .
 44+ " WHERE " . getLatestTransactionRestriction("{$dc}_syntrans") .
3945 " AND " . getLatestTransactionRestriction("{$dc}_expression") .
4046 " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning") .
4147 " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id " .
4248 " AND {$dc}_defined_meaning.defined_meaning_id={$dc}_syntrans.defined_meaning_id " .
4349 " AND {$dc}_syntrans.identical_meaning=1 " .
44 - " GROUP BY {$dc}_defined_meaning.defined_meaning_id";
 50+ " AND {$dc}_defined_meaning.defined_meaning_id = ";
 51+
 52+ # Build atomic queries
 53+ $definedMeaningIdsCopy = $definedMeaningIds;
 54+ foreach ($definedMeaningIdsCopy as &$value) {$value = $frontQuery . $value; }
 55+ unset($value);
 56+ # Union of the atoms
 57+ return implode(' UNION ',$definedMeaningIdsCopy);
4558 }
4659
4760 function getDefiningSQLForLanguage($languageId, array &$definedMeaningIds) {
4861 $dc=wdGetDataSetContext();
4962
50 - return
51 - "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " .
 63+ # Query building
 64+ $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " .
5265 " FROM {$dc}_defined_meaning, {$dc}_syntrans, {$dc}_expression " .
53 - " WHERE {$dc}_defined_meaning.defined_meaning_id IN (" . implode(", ", $definedMeaningIds) . ")" .
54 - " AND " . getLatestTransactionRestriction("{$dc}_syntrans") .
 66+ " WHERE ". getLatestTransactionRestriction("{$dc}_syntrans") .
5567 " AND " . getLatestTransactionRestriction("{$dc}_expression") .
5668 " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning") .
5769 " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id " .
@@ -58,9 +70,17 @@
5971 " AND {$dc}_syntrans.identical_meaning=1 " .
6072 " AND {$dc}_defined_meaning.expression_id={$dc}_expression.expression_id " .
6173 " AND {$dc}_expression.language_id=" . $languageId .
62 - " GROUP BY {$dc}_defined_meaning.defined_meaning_id";
 74+ " AND {$dc}_defined_meaning.defined_meaning_id = ";
 75+
 76+ # Build atomic queries
 77+ $definedMeaningIdsCopy = $definedMeaningIds;
 78+ foreach ($definedMeaningIdsCopy as &$value) {$value = $frontQuery . $value; }
 79+ unset($value);
 80+ # Union of the atoms
 81+ return implode(' UNION ',$definedMeaningIdsCopy);
6382 }
6483
 84+
6585 function fetchDefinedMeaningReferenceRecords($sql, array &$definedMeaningIds, array &$definedMeaningReferenceRecords, $usedAs='defined-meaning') {
6686 $dc=wdGetDataSetContext();
6787
@@ -88,22 +108,32 @@
89109 $definedMeaningIds = array_diff($definedMeaningIds, $foundDefinedMeaningIds);
90110 }
91111
 112+
92113 function fetchDefinedMeaningDefiningExpressions(array &$definedMeaningIds, array &$definedMeaningReferenceRecords) {
93 -
94114 $o=OmegaWikiAttributes::getInstance();
95115
96116 $dc=wdGetDataSetContext();
97117
98118 $dbr =& wfGetDB(DB_SLAVE);
99 - $queryResult = $dbr->query(
100 - "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling" .
 119+
 120+ # Query building
 121+ $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling" .
101122 " FROM {$dc}_defined_meaning, {$dc}_expression " .
102123 " WHERE {$dc}_defined_meaning.expression_id={$dc}_expression.expression_id " .
103124 " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning") .
104125 " AND " . getLatestTransactionRestriction("{$dc}_expression") .
105 - " AND {$dc}_defined_meaning.defined_meaning_id IN (". implode(", ", $definedMeaningIds) .")"
106 - );
 126+ " AND {$dc}_defined_meaning.defined_meaning_id = ";
107127
 128+ # Build atomic queries
 129+ $definedMeaningIdsCopy = $definedMeaningIds;
 130+ unset($value);
 131+ foreach ($definedMeaningIdsCopy as &$value) {$value = $frontQuery . $value; }
 132+ unset($value);
 133+ # Union of the atoms
 134+ $finalQuery = implode(' UNION ',$definedMeaningIdsCopy);
 135+
 136+ $queryResult = $dbr->query($finalQuery);
 137+
108138 while ($row = $dbr->fetchObject($queryResult)) {
109139 $definedMeaningReferenceRecord = $definedMeaningReferenceRecords[$row->defined_meaning_id];
110140
@@ -115,7 +145,7 @@
116146 }
117147
118148 $definedMeaningReferenceRecord->definedMeaningDefiningExpression = $row->spelling;
119 - }
 149+ }
120150 }
121151
122152 function getNullDefinedMeaningReferenceRecord() {
@@ -227,18 +257,25 @@
228258 function getExpressionReferenceRecords($expressionIds) {
229259
230260 $o=OmegaWikiAttributes::getInstance();
231 -
232261 $dc=wdGetDataSetContext();
233262
234263 if (count($expressionIds) > 0) {
235264 $dbr =& wfGetDB(DB_SLAVE);
236 - $queryResult = $dbr->query(
237 - "SELECT expression_id, language_id, spelling" .
 265+
 266+ # Query building
 267+ $frontQuery = "SELECT expression_id, language_id, spelling" .
238268 " FROM {$dc}_expression" .
239 - " WHERE expression_id IN (". implode(', ', $expressionIds) .")" .
240 - " AND ". getLatestTransactionRestriction("{$dc}_expression")
241 - );
 269+ " WHERE expression_id = ";
 270+ $queueQuery = " AND ". getLatestTransactionRestriction("{$dc}_expression");
 271+
 272+ # Build atomic queries
 273+ foreach ($expressionIds as &$value) {$value = $frontQuery . $value . $queueQuery; }
 274+ unset($value);
 275+ # Union of the atoms
 276+ $finalQuery = implode(' UNION ',$expressionIds);
242277
 278+ $queryResult = $dbr->query($finalQuery);
 279+
243280 $result = array();
244281
245282 while ($row = $dbr->fetchObject($queryResult)) {
@@ -270,20 +307,22 @@
271308 }
272309
273310 function getExpressionSpellings(array $expressionIds) {
274 -
275 - $o=OmegaWikiAttributes::getInstance();
276 -
277311 $dc=wdGetDataSetContext();
278312
279313 if (count($expressionIds) > 0) {
280314 $dbr =& wfGetDB(DB_SLAVE);
281 - $queryResult = $dbr->query(
282 - "SELECT expression_id, spelling" .
283 - " FROM {$dc}_expression" .
284 - " WHERE expression_id IN (". implode(', ', $expressionIds) .")" .
285 - " AND ". getLatestTransactionRestriction("{$dc}_expression")
286 - );
287315
 316+ # Prepare steady components
 317+ $frontQuery = "SELECT expression_id, spelling FROM {$dc}_expression WHERE expression_id =";
 318+ $queueQuery = " AND ". getLatestTransactionRestriction("{$dc}_expression");
 319+ # Build atomic queries
 320+ foreach ($expressionIds as &$value) {$value = $frontQuery . $value . $queueQuery; }
 321+ unset($value);
 322+ # Union of the atoms
 323+ $finalQuery = implode(' UNION ',$expressionIds);
 324+
 325+ $queryResult = $dbr->query($finalQuery);
 326+
288327 $result = array();
289328
290329 while ($row = $dbr->fetchObject($queryResult))
@@ -313,12 +352,20 @@
314353 $dc=wdGetDataSetContext();
315354 if (count($textIds) > 0) {
316355 $dbr =& wfGetDB(DB_SLAVE);
317 - $queryResult = $dbr->query(
318 - "SELECT text_id, text_text" .
 356+
 357+ # Query building
 358+ $frontQuery = "SELECT text_id, text_text" .
319359 " FROM {$dc}_text" .
320 - " WHERE text_id IN (". implode(', ', $textIds) .")"
321 - );
 360+ " WHERE text_id = ";
 361+
 362+ # Build atomic queries
 363+ foreach ($textIds as &$value) {$value = $frontQuery . $value; }
 364+ unset($value);
 365+ # Union of the atoms
 366+ $finalQuery = implode(' UNION ',$textIds);
322367
 368+ $queryResult = $dbr->query($finalQuery);
 369+
323370 $result = array();
324371
325372 while ($row = $dbr->fetchObject($queryResult))

Status & tagging log