r66916 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66915‎ | r66916 | r66917 >
Date:14:05, 26 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added support for custom index types to the SQL store
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLHelpers.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2Table.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2Table.php
@@ -46,7 +46,9 @@
4747 /**
4848 * Strings of the form "field1,...,fieldN" for extra indexes that are to
4949 * be built for this table. All tables have indexes on subject column(s)
50 - * and property column (if any).
 50+ * and property column (if any). Items can also be an array with the column
 51+ * name as first element, and a index type as second elemet to allow for
 52+ * custom index types.
5153 *
5254 * @var array of string
5355 */
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLHelpers.php
@@ -319,7 +319,8 @@
320320 * @param DatabaseBase or Database $db
321321 */
322322 public static function setupIndex( $tableName, array $columns, $db ) {
323 - global $wgDBtype, $verbose;
 323+ // TODO: $verbose is not a good global name!
 324+ global $wgDBtype, $verbose;
324325
325326 $tableName = $db->tableName( $tableName );
326327
@@ -352,9 +353,20 @@
353354 }
354355 }
355356
356 - foreach ( $columns as $key => $column ) { // Ddd the remaining indexes.
357 - if ( $column != false ) {
358 - $db->query( "CREATE INDEX " . $tableName . "_index" . $key . " ON " . $tableName . " USING btree(" . $column . ")", __METHOD__ );
 357+ foreach ( $columns as $key => $index ) { // Ddd the remaining indexes.
 358+ if ( $index != false ) {
 359+ $type = 'INDEX';
 360+
 361+ // If the index is an array, it'll contain the column name as first element, and index type as second one.
 362+ if ( is_array( $index ) ) {
 363+ $column = $index[0];
 364+ if ( count( $index ) > 1 ) $type = $index[1];
 365+ }
 366+ else {
 367+ $column = $index;
 368+ }
 369+
 370+ $db->query( "CREATE $type {$tableName}_index{$key} ON $tableName USING btree(" . $column . ")", __METHOD__ );
359371 }
360372 }
361373 } else { // MySQL
@@ -382,9 +394,20 @@
383395 }
384396 }
385397
386 - foreach ( $columns as $key => $column ) { // Ddd the remaining indexes.
387 - if ( $column != false ) {
388 - $db->query( "ALTER TABLE $tableName ADD INDEX ( $column )", __METHOD__ );
 398+ foreach ( $columns as $key => $index ) { // Add the remaining indexes.
 399+ if ( $index != false ) {
 400+ $type = 'INDEX';
 401+
 402+ // If the index is an array, it'll contain the column name as first element, and index type as second one.
 403+ if ( is_array( $index ) ) {
 404+ $column = $index[0];
 405+ if ( count( $index ) > 1 ) $type = $index[1];
 406+ }
 407+ else {
 408+ $column = $index;
 409+ }
 410+
 411+ $db->query( "ALTER TABLE $tableName ADD $type ( $column )", __METHOD__ );
389412 }
390413 }
391414 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r66917Follow up to r66916jeroendedauw14:06, 26 May 2010

Status & tagging log