Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2Table.php |
— | — | @@ -46,7 +46,9 @@ |
47 | 47 | /** |
48 | 48 | * Strings of the form "field1,...,fieldN" for extra indexes that are to |
49 | 49 | * 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. |
51 | 53 | * |
52 | 54 | * @var array of string |
53 | 55 | */ |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLHelpers.php |
— | — | @@ -319,7 +319,8 @@ |
320 | 320 | * @param DatabaseBase or Database $db |
321 | 321 | */ |
322 | 322 | 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; |
324 | 325 | |
325 | 326 | $tableName = $db->tableName( $tableName ); |
326 | 327 | |
— | — | @@ -352,9 +353,20 @@ |
353 | 354 | } |
354 | 355 | } |
355 | 356 | |
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__ ); |
359 | 371 | } |
360 | 372 | } |
361 | 373 | } else { // MySQL |
— | — | @@ -382,9 +394,20 @@ |
383 | 395 | } |
384 | 396 | } |
385 | 397 | |
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__ ); |
389 | 412 | } |
390 | 413 | } |
391 | 414 | } |