r69721 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69720‎ | r69721 | r69722 >
Date:08:52, 22 July 2010
Author:catrope
Status:resolved (Comments)
Tags:
Comment:
Rename the iwl_prefix_from_title index (again) to iwl_prefix_title_from and change the field order accordingly. Fixed r66892 which inserted iwl_from into the index (which was a good thing) but put it in the wrong place. I went out of my way to make sure the index isn't dropped and recreated needlessly, but since I don't know how to do the drop-index-if-exists thing in the Postgres updater, I left that out. The Postgres updater will now create the new index without dropping any old incarnations if present. I did create the patch files with the DROP INDEX statements to make it easier to add this behavior. Also tweak ApiQueryIWBacklinks to use this index properly.
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryIWBacklinks.php (modified) (history)
  • /trunk/phase3/includes/installer/MysqlUpdater.php (modified) (history)
  • /trunk/phase3/includes/installer/SqliteUpdater.php (modified) (history)
  • /trunk/phase3/maintenance/archives/patch-iwlinks.sql (modified) (history)
  • /trunk/phase3/maintenance/archives/patch-kill-iwl_pft.sql (added) (history)
  • /trunk/phase3/maintenance/archives/patch-kill-iwl_prefix.sql (added) (history)
  • /trunk/phase3/maintenance/archives/patch-rename-iwl_prefix.sql (modified) (history)
  • /trunk/phase3/maintenance/postgres/archives/patch-iwlinks.sql (modified) (history)
  • /trunk/phase3/maintenance/postgres/archives/patch-kill-iwl_pft.sql (added) (history)
  • /trunk/phase3/maintenance/postgres/archives/patch-kill-iwl_prefix.sql (added) (history)
  • /trunk/phase3/maintenance/postgres/archives/patch-rename-iwl_prefix.sql (modified) (history)
  • /trunk/phase3/maintenance/postgres/tables.sql (modified) (history)
  • /trunk/phase3/maintenance/sqlite/archives/patch-kill-iwl_pft.sql (added) (history)
  • /trunk/phase3/maintenance/sqlite/archives/patch-kill-iwl_prefix.sql (added) (history)
  • /trunk/phase3/maintenance/tables.sql (modified) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/archives/patch-rename-iwl_prefix.sql
@@ -1,5 +1,4 @@
22 --
 3+-- Recreates the iwl_prefix index for the iwlinks table
34 --
4 -DROP INDEX /*i*/iwl_prefix ON /*_*/iwlinks;
5 -CREATE INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);
\ No newline at end of file
 5+CREATE UNIQUE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);
Index: trunk/phase3/maintenance/archives/patch-kill-iwl_pft.sql
@@ -0,0 +1,7 @@
 2+--
 3+-- Kill the old iwl_prefix_from_title index, which may be present on some
 4+-- installs if they ran update.php between it being added and being renamed
 5+--
 6+
 7+DROP INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks;
 8+
Property changes on: trunk/phase3/maintenance/archives/patch-kill-iwl_pft.sql
___________________________________________________________________
Added: svn:eol-style
19 + native
Index: trunk/phase3/maintenance/archives/patch-iwlinks.sql
@@ -13,4 +13,4 @@
1414 ) /*$wgDBTableOptions*/;
1515
1616 CREATE UNIQUE INDEX /*i*/iwl_from ON /*_*/iwlinks (iwl_from, iwl_prefix, iwl_title);
17 -CREATE INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);
 17+CREATE UNIQUE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);
Index: trunk/phase3/maintenance/archives/patch-kill-iwl_prefix.sql
@@ -0,0 +1,7 @@
 2+--
 3+-- Kill the old iwl_prefix index, which may be present on some
 4+-- installs if they ran update.php between it being added and being renamed
 5+--
 6+
 7+DROP INDEX /*i*/iwl_prefix ON /*_*/iwlinks;
 8+
Index: trunk/phase3/maintenance/sqlite/archives/patch-kill-iwl_pft.sql
@@ -0,0 +1,7 @@
 2+--
 3+-- Kill the old iwl_prefix_from_title index, which may be present on some
 4+-- installs if they ran update.php between it being added and being renamed
 5+--
 6+
 7+DROP INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks;
 8+
Property changes on: trunk/phase3/maintenance/sqlite/archives/patch-kill-iwl_pft.sql
___________________________________________________________________
Added: svn:eol-style
19 + native
Index: trunk/phase3/maintenance/sqlite/archives/patch-kill-iwl_prefix.sql
@@ -0,0 +1,7 @@
 2+--
 3+-- Kill the old iwl_prefix index, which may be present on some
 4+-- installs if they ran update.php between it being added and being renamed
 5+--
 6+
 7+DROP INDEX /*i*/iwl_prefix ON /*_*/iwlinks;
 8+
Property changes on: trunk/phase3/maintenance/sqlite/archives/patch-kill-iwl_prefix.sql
___________________________________________________________________
Added: svn:eol-style
19 + native
Index: trunk/phase3/maintenance/postgres/archives/patch-kill-iwl_pft.sql
@@ -0,0 +1,7 @@
 2+--
 3+-- Kill the old iwl_prefix_from_title index, which may be present on some
 4+-- installs if they ran update.php between it being added and being renamed
 5+--
 6+
 7+DROP INDEX iwl_prefix_from_title;
 8+
Property changes on: trunk/phase3/maintenance/postgres/archives/patch-kill-iwl_pft.sql
___________________________________________________________________
Added: svn:eol-style
19 + native
Index: trunk/phase3/maintenance/postgres/archives/patch-kill-iwl_prefix.sql
@@ -0,0 +1,7 @@
 2+--
 3+-- Kill the old iwl_prefix index, which may be present on some
 4+-- installs if they ran update.php between it being added and being renamed
 5+--
 6+
 7+DROP INDEX iwl_prefix;
 8+
Property changes on: trunk/phase3/maintenance/postgres/archives/patch-kill-iwl_prefix.sql
___________________________________________________________________
Added: svn:eol-style
19 + native
Index: trunk/phase3/maintenance/postgres/archives/patch-rename-iwl_prefix.sql
@@ -1,2 +1,2 @@
22 DROP INDEX iwl_prefix;
3 -CREATE INDEX iwl_prefix_from_title ON iwlinks (iwl_prefix, iwl_from, iwl_title);
\ No newline at end of file
 3+CREATE UNIQUE INDEX iwl_prefix_title_from ON iwlinks (iwl_prefix, iwl_from, iwl_title);
Index: trunk/phase3/maintenance/postgres/archives/patch-iwlinks.sql
@@ -5,4 +5,4 @@
66 iwl_title TEXT NOT NULL DEFAULT ''
77 );
88 CREATE UNIQUE INDEX iwl_from ON iwlinks (iwl_from, iwl_prefix, iwl_title);
9 -CREATE INDEX iwl_prefix ON iwlinks (iwl_prefix, iwl_title);
 9+CREATE UNIQUE INDEX iwl_prefix_title_from ON iwlinks (iwl_prefix, iwl_title, iwl_from);
Index: trunk/phase3/maintenance/postgres/tables.sql
@@ -625,4 +625,4 @@
626626 iwl_title TEXT NOT NULL DEFAULT ''
627627 );
628628 CREATE UNIQUE INDEX iwl_from ON iwlinks (iwl_from, iwl_prefix, iwl_title);
629 -CREATE INDEX iwl_prefix_from_title ON iwlinks (iwl_prefix, iwl_from, iwl_title);
 629+CREATE UNIQUE INDEX iwl_prefix_title_from ON iwlinks (iwl_prefix, iwl_title, iwl_from);
Index: trunk/phase3/maintenance/updaters.inc
@@ -1508,6 +1508,7 @@
15091509 array( "watchlist", "wl_user", "(wl_user)" ),
15101510 array( "logging", "logging_user_type_time", "(log_user, log_type, log_timestamp)" ),
15111511 array( "logging", "logging_page_id_time", "(log_page,log_timestamp)" ),
 1512+ array( "iwlinks", "iwl_prefix_title_from", "(iwl_prefix, iwl_title, iwl_from)" ),
15121513 );
15131514
15141515 $newrules = array(
Index: trunk/phase3/maintenance/tables.sql
@@ -623,7 +623,7 @@
624624 ) /*$wgDBTableOptions*/;
625625
626626 CREATE UNIQUE INDEX /*i*/iwl_from ON /*_*/iwlinks (iwl_from, iwl_prefix, iwl_title);
627 -CREATE INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);
 627+CREATE UNIQUE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);
628628
629629
630630 --
Index: trunk/phase3/includes/installer/MysqlUpdater.php
@@ -149,9 +149,11 @@
150150 ),
151151 '1.17' => array(
152152 array( 'add_table', 'iwlinks', 'patch-iwlinks.sql' ),
153 - array( 'add_index', 'iwlinks', 'iwl_prefix_from_title', 'patch-rename-iwl_prefix.sql' ),
 153+ array( 'add_index', 'iwlinks', 'iwl_prefix_title_from', 'patch-rename-iwl_prefix.sql' ),
154154 array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ),
155155 array( 'add_field', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ),
 156+ array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix', 'patch-kill-iwl_prefix.sql' ),
 157+ array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix_from_title', 'patch-kill-iwl_pft.sql' ),
156158 ),
157159 );
158160 }
Index: trunk/phase3/includes/installer/SqliteUpdater.php
@@ -31,9 +31,11 @@
3232 ),
3333 '1.17' => array(
3434 array( 'add_table', 'iwlinks', 'patch-iwlinks.sql' ),
35 - array( 'add_index', 'iwlinks', 'iwl_prefix_from_title', 'patch-rename-iwl_prefix.sql' ),
 35+ array( 'add_index', 'iwlinks', 'iwl_prefix_title_from', 'patch-rename-iwl_prefix.sql' ),
3636 array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ),
3737 array( 'add_field', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ),
 38+ array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix', 'patch-kill-iwl_prefix.sql' ),
 39+ array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix_from_title', 'patch-kill-iwl_pft.sql' ),
3840 ),
3941 );
4042 }
Index: trunk/phase3/includes/api/ApiQueryIWBacklinks.php
@@ -53,15 +53,15 @@
5454 'original value returned by the previous query', '_badcontinue' );
5555 }
5656
57 - $from = intval( $cont[0] );
58 - $prefix = $this->getDB()->strencode( $cont[1] );
59 - $title = $this->getDB()->strencode( $this->titleToKey( $cont[2] ) );
 57+ $prefix = $this->getDB()->strencode( $cont[0] );
 58+ $title = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) );
 59+ $from = intval( $cont[2] );
6060 $this->addWhere(
61 - "iwl_from > $from OR " .
62 - "(iwl_from = $from AND " .
63 - "(iwl_prefix > '$prefix' OR " .
 61+ "iwl_prefix > '$prefix' OR " .
6462 "(iwl_prefix = '$prefix' AND " .
65 - "iwl_title >= '$title')))"
 63+ "(iwl_title > '$title' OR " .
 64+ "(iwl_title = '$title' AND " .
 65+ "iwl_from >= $from)))"
6666 );
6767 }
6868
@@ -73,14 +73,17 @@
7474
7575 if ( isset( $params['prefix'] ) ) {
7676 $this->addWhereFld( 'iwl_prefix', $params['prefix'] );
 77+ if ( isset( $params['title'] ) ) {
 78+ $this->addWhereFld( 'iwl_title', $params['title'] );
 79+ $this->addOption( 'ORDER BY', 'iwl_from' );
 80+ } else {
 81+ $this->addOption( 'ORDER BY', 'iwl_title, iwl_from' );
 82+ }
 83+ } else {
 84+ $this->addOption( 'ORDER BY', 'iwl_prefix, iwl_title, iwl_from' );
7785 }
78 -
79 - if ( isset( $params['title'] ) ) {
80 - $this->addWhereFld( 'iwl_title', $params['title'] );
81 - }
8286
8387 $this->addOption( 'LIMIT', $params['limit'] + 1 );
84 - $this->addOption( 'ORDER BY', 'iwl_from' );
8588
8689 $db = $this->getDB();
8790 $res = $this->select( __METHOD__ );
@@ -91,7 +94,7 @@
9295 if ( ++ $count > $params['limit'] ) {
9396 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
9497 // Continue string preserved in case the redirect query doesn't pass the limit
95 - $this->setContinueEnumParameter( 'continue', "{$row->iwl_from}|{$row->iwl_prefix}|{$row->iwl_title}" );
 98+ $this->setContinueEnumParameter( 'continue', "{$row->iwl_prefix}|{$row->iwl_title}|{$row->iwl_from}" );
9699 break;
97100 }
98101
@@ -107,7 +110,7 @@
108111
109112 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $entry );
110113 if ( !$fit ) {
111 - $this->setContinueEnumParameter( 'continue', "{$row->iwl_from}|{$row->iwl_prefix}|{$row->iwl_title}" );
 114+ $this->setContinueEnumParameter( 'continue', "{$row->iwl_prefix}|{$row->iwl_title}|{$row->iwl_from}" );
112115 break;
113116 }
114117 }
@@ -145,9 +148,9 @@
146149 public function getDescription() {
147150 return array( 'Find all pages that link to the given interwiki link.',
148151 'Can be used to find all links with a prefix, or',
149 - 'all links to a title (any prefix).',
 152+ 'all links to a title (with a given prefix).',
150153 'Using neither parameter is effectively "All IW Links"',
151 - );
 154+ );
152155 }
153156
154157 public function getPossibleErrors() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r75919Fix r69721: SQLite yells at you if you try to drop an index that doesn't exis...demon12:41, 3 November 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r66892Followup to r65105 after discussion with Roan...reedy20:37, 25 May 2010

Comments

#Comment by Nikerabbit (talk | contribs)   04:55, 5 August 2010

Fails on SQLite.

...iwlinks table already exists.
Adding iwl_prefix_title_from key to table iwlinks... A database query syntax error has occurred.
The last attempted database query was:
"DROP INDEX iwl_prefix
"
from within function "DatabaseBase::sourceStream".
Database returned error "1: no such index: iwl_prefix"

Status & tagging log