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.

This commit is contained in:
Roan Kattouw 2010-07-22 08:52:58 +00:00
parent 65ae4eed55
commit 61de1b9006
16 changed files with 75 additions and 26 deletions

View file

@ -53,15 +53,15 @@ class ApiQueryIWBacklinks extends ApiQueryBase {
'original value returned by the previous query', '_badcontinue' );
}
$from = intval( $cont[0] );
$prefix = $this->getDB()->strencode( $cont[1] );
$title = $this->getDB()->strencode( $this->titleToKey( $cont[2] ) );
$prefix = $this->getDB()->strencode( $cont[0] );
$title = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) );
$from = intval( $cont[2] );
$this->addWhere(
"iwl_from > $from OR " .
"(iwl_from = $from AND " .
"(iwl_prefix > '$prefix' OR " .
"iwl_prefix > '$prefix' OR " .
"(iwl_prefix = '$prefix' AND " .
"iwl_title >= '$title')))"
"(iwl_title > '$title' OR " .
"(iwl_title = '$title' AND " .
"iwl_from >= $from)))"
);
}
@ -73,14 +73,17 @@ class ApiQueryIWBacklinks extends ApiQueryBase {
if ( isset( $params['prefix'] ) ) {
$this->addWhereFld( 'iwl_prefix', $params['prefix'] );
}
if ( isset( $params['title'] ) ) {
$this->addWhereFld( 'iwl_title', $params['title'] );
if ( isset( $params['title'] ) ) {
$this->addWhereFld( 'iwl_title', $params['title'] );
$this->addOption( 'ORDER BY', 'iwl_from' );
} else {
$this->addOption( 'ORDER BY', 'iwl_title, iwl_from' );
}
} else {
$this->addOption( 'ORDER BY', 'iwl_prefix, iwl_title, iwl_from' );
}
$this->addOption( 'LIMIT', $params['limit'] + 1 );
$this->addOption( 'ORDER BY', 'iwl_from' );
$db = $this->getDB();
$res = $this->select( __METHOD__ );
@ -91,7 +94,7 @@ class ApiQueryIWBacklinks extends ApiQueryBase {
if ( ++ $count > $params['limit'] ) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
// Continue string preserved in case the redirect query doesn't pass the limit
$this->setContinueEnumParameter( 'continue', "{$row->iwl_from}|{$row->iwl_prefix}|{$row->iwl_title}" );
$this->setContinueEnumParameter( 'continue', "{$row->iwl_prefix}|{$row->iwl_title}|{$row->iwl_from}" );
break;
}
@ -107,7 +110,7 @@ class ApiQueryIWBacklinks extends ApiQueryBase {
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $entry );
if ( !$fit ) {
$this->setContinueEnumParameter( 'continue', "{$row->iwl_from}|{$row->iwl_prefix}|{$row->iwl_title}" );
$this->setContinueEnumParameter( 'continue', "{$row->iwl_prefix}|{$row->iwl_title}|{$row->iwl_from}" );
break;
}
}
@ -145,9 +148,9 @@ class ApiQueryIWBacklinks extends ApiQueryBase {
public function getDescription() {
return array( 'Find all pages that link to the given interwiki link.',
'Can be used to find all links with a prefix, or',
'all links to a title (any prefix).',
'all links to a title (with a given prefix).',
'Using neither parameter is effectively "All IW Links"',
);
);
}
public function getPossibleErrors() {

View file

@ -149,9 +149,11 @@ class MysqlUpdater extends DatabaseUpdater {
),
'1.17' => array(
array( 'add_table', 'iwlinks', 'patch-iwlinks.sql' ),
array( 'add_index', 'iwlinks', 'iwl_prefix_from_title', 'patch-rename-iwl_prefix.sql' ),
array( 'add_index', 'iwlinks', 'iwl_prefix_title_from', 'patch-rename-iwl_prefix.sql' ),
array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ),
array( 'add_field', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ),
array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix', 'patch-kill-iwl_prefix.sql' ),
array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix_from_title', 'patch-kill-iwl_pft.sql' ),
),
);
}

View file

@ -31,9 +31,11 @@ class SqliteUpdater extends DatabaseUpdater {
),
'1.17' => array(
array( 'add_table', 'iwlinks', 'patch-iwlinks.sql' ),
array( 'add_index', 'iwlinks', 'iwl_prefix_from_title', 'patch-rename-iwl_prefix.sql' ),
array( 'add_index', 'iwlinks', 'iwl_prefix_title_from', 'patch-rename-iwl_prefix.sql' ),
array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ),
array( 'add_field', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ),
array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix', 'patch-kill-iwl_prefix.sql' ),
array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix_from_title', 'patch-kill-iwl_pft.sql' ),
),
);
}

View file

@ -13,4 +13,4 @@ CREATE TABLE /*_*/iwlinks (
) /*$wgDBTableOptions*/;
CREATE UNIQUE INDEX /*i*/iwl_from ON /*_*/iwlinks (iwl_from, iwl_prefix, iwl_title);
CREATE INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);
CREATE UNIQUE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);

View file

@ -0,0 +1,7 @@
--
-- Kill the old iwl_prefix_from_title index, which may be present on some
-- installs if they ran update.php between it being added and being renamed
--
DROP INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks;

View file

@ -0,0 +1,7 @@
--
-- Kill the old iwl_prefix index, which may be present on some
-- installs if they ran update.php between it being added and being renamed
--
DROP INDEX /*i*/iwl_prefix ON /*_*/iwlinks;

View file

@ -1,5 +1,4 @@
--
-- Recreates the iwl_prefix for the iwlinks table
-- Recreates the iwl_prefix index for the iwlinks table
--
DROP INDEX /*i*/iwl_prefix ON /*_*/iwlinks;
CREATE INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);
CREATE UNIQUE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);

View file

@ -5,4 +5,4 @@ CREATE TABLE iwlinks (
iwl_title TEXT NOT NULL DEFAULT ''
);
CREATE UNIQUE INDEX iwl_from ON iwlinks (iwl_from, iwl_prefix, iwl_title);
CREATE INDEX iwl_prefix ON iwlinks (iwl_prefix, iwl_title);
CREATE UNIQUE INDEX iwl_prefix_title_from ON iwlinks (iwl_prefix, iwl_title, iwl_from);

View file

@ -0,0 +1,7 @@
--
-- Kill the old iwl_prefix_from_title index, which may be present on some
-- installs if they ran update.php between it being added and being renamed
--
DROP INDEX iwl_prefix_from_title;

View file

@ -0,0 +1,7 @@
--
-- Kill the old iwl_prefix index, which may be present on some
-- installs if they ran update.php between it being added and being renamed
--
DROP INDEX iwl_prefix;

View file

@ -1,2 +1,2 @@
DROP INDEX iwl_prefix;
CREATE INDEX iwl_prefix_from_title ON iwlinks (iwl_prefix, iwl_from, iwl_title);
CREATE UNIQUE INDEX iwl_prefix_title_from ON iwlinks (iwl_prefix, iwl_from, iwl_title);

View file

@ -625,4 +625,4 @@ CREATE TABLE iwlinks (
iwl_title TEXT NOT NULL DEFAULT ''
);
CREATE UNIQUE INDEX iwl_from ON iwlinks (iwl_from, iwl_prefix, iwl_title);
CREATE INDEX iwl_prefix_from_title ON iwlinks (iwl_prefix, iwl_from, iwl_title);
CREATE UNIQUE INDEX iwl_prefix_title_from ON iwlinks (iwl_prefix, iwl_title, iwl_from);

View file

@ -0,0 +1,7 @@
--
-- Kill the old iwl_prefix_from_title index, which may be present on some
-- installs if they ran update.php between it being added and being renamed
--
DROP INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks;

View file

@ -0,0 +1,7 @@
--
-- Kill the old iwl_prefix index, which may be present on some
-- installs if they ran update.php between it being added and being renamed
--
DROP INDEX /*i*/iwl_prefix ON /*_*/iwlinks;

View file

@ -623,7 +623,7 @@ CREATE TABLE /*_*/iwlinks (
) /*$wgDBTableOptions*/;
CREATE UNIQUE INDEX /*i*/iwl_from ON /*_*/iwlinks (iwl_from, iwl_prefix, iwl_title);
CREATE INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);
CREATE UNIQUE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);
--

View file

@ -1508,6 +1508,7 @@ function do_postgres_updates() {
array( "watchlist", "wl_user", "(wl_user)" ),
array( "logging", "logging_user_type_time", "(log_user, log_type, log_timestamp)" ),
array( "logging", "logging_page_id_time", "(log_page,log_timestamp)" ),
array( "iwlinks", "iwl_prefix_title_from", "(iwl_prefix, iwl_title, iwl_from)" ),
);
$newrules = array(