From 61de1b9006bd2b7fde19aa131e52e0280d0f40dd Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Thu, 22 Jul 2010 08:52:58 +0000 Subject: [PATCH] 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. --- includes/api/ApiQueryIWBacklinks.php | 35 ++++++++++--------- includes/installer/MysqlUpdater.php | 4 ++- includes/installer/SqliteUpdater.php | 4 ++- maintenance/archives/patch-iwlinks.sql | 2 +- maintenance/archives/patch-kill-iwl_pft.sql | 7 ++++ .../archives/patch-kill-iwl_prefix.sql | 7 ++++ .../archives/patch-rename-iwl_prefix.sql | 5 ++- .../postgres/archives/patch-iwlinks.sql | 2 +- .../postgres/archives/patch-kill-iwl_pft.sql | 7 ++++ .../archives/patch-kill-iwl_prefix.sql | 7 ++++ .../archives/patch-rename-iwl_prefix.sql | 2 +- maintenance/postgres/tables.sql | 2 +- .../sqlite/archives/patch-kill-iwl_pft.sql | 7 ++++ .../sqlite/archives/patch-kill-iwl_prefix.sql | 7 ++++ maintenance/tables.sql | 2 +- maintenance/updaters.inc | 1 + 16 files changed, 75 insertions(+), 26 deletions(-) create mode 100644 maintenance/archives/patch-kill-iwl_pft.sql create mode 100644 maintenance/archives/patch-kill-iwl_prefix.sql create mode 100644 maintenance/postgres/archives/patch-kill-iwl_pft.sql create mode 100644 maintenance/postgres/archives/patch-kill-iwl_prefix.sql create mode 100644 maintenance/sqlite/archives/patch-kill-iwl_pft.sql create mode 100644 maintenance/sqlite/archives/patch-kill-iwl_prefix.sql diff --git a/includes/api/ApiQueryIWBacklinks.php b/includes/api/ApiQueryIWBacklinks.php index ad4e7c1b42..fa41f97384 100644 --- a/includes/api/ApiQueryIWBacklinks.php +++ b/includes/api/ApiQueryIWBacklinks.php @@ -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() { diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index 07dad0ca00..f6db9f77e0 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -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' ), ), ); } diff --git a/includes/installer/SqliteUpdater.php b/includes/installer/SqliteUpdater.php index 2bace6e048..99a8f1245b 100644 --- a/includes/installer/SqliteUpdater.php +++ b/includes/installer/SqliteUpdater.php @@ -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' ), ), ); } diff --git a/maintenance/archives/patch-iwlinks.sql b/maintenance/archives/patch-iwlinks.sql index c1c2595e62..89b34cb1ab 100644 --- a/maintenance/archives/patch-iwlinks.sql +++ b/maintenance/archives/patch-iwlinks.sql @@ -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); diff --git a/maintenance/archives/patch-kill-iwl_pft.sql b/maintenance/archives/patch-kill-iwl_pft.sql new file mode 100644 index 0000000000..96e1435693 --- /dev/null +++ b/maintenance/archives/patch-kill-iwl_pft.sql @@ -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; + diff --git a/maintenance/archives/patch-kill-iwl_prefix.sql b/maintenance/archives/patch-kill-iwl_prefix.sql new file mode 100644 index 0000000000..1cd9b45416 --- /dev/null +++ b/maintenance/archives/patch-kill-iwl_prefix.sql @@ -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; + diff --git a/maintenance/archives/patch-rename-iwl_prefix.sql b/maintenance/archives/patch-rename-iwl_prefix.sql index df360299e6..4b11b36b87 100644 --- a/maintenance/archives/patch-rename-iwl_prefix.sql +++ b/maintenance/archives/patch-rename-iwl_prefix.sql @@ -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); \ No newline at end of file +CREATE UNIQUE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from); diff --git a/maintenance/postgres/archives/patch-iwlinks.sql b/maintenance/postgres/archives/patch-iwlinks.sql index a24154f3a2..db26eae41d 100644 --- a/maintenance/postgres/archives/patch-iwlinks.sql +++ b/maintenance/postgres/archives/patch-iwlinks.sql @@ -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); diff --git a/maintenance/postgres/archives/patch-kill-iwl_pft.sql b/maintenance/postgres/archives/patch-kill-iwl_pft.sql new file mode 100644 index 0000000000..4419d9e9a8 --- /dev/null +++ b/maintenance/postgres/archives/patch-kill-iwl_pft.sql @@ -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; + diff --git a/maintenance/postgres/archives/patch-kill-iwl_prefix.sql b/maintenance/postgres/archives/patch-kill-iwl_prefix.sql new file mode 100644 index 0000000000..8b6d108494 --- /dev/null +++ b/maintenance/postgres/archives/patch-kill-iwl_prefix.sql @@ -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; + diff --git a/maintenance/postgres/archives/patch-rename-iwl_prefix.sql b/maintenance/postgres/archives/patch-rename-iwl_prefix.sql index ebe0abcb1e..a4bdb6a913 100644 --- a/maintenance/postgres/archives/patch-rename-iwl_prefix.sql +++ b/maintenance/postgres/archives/patch-rename-iwl_prefix.sql @@ -1,2 +1,2 @@ DROP INDEX iwl_prefix; -CREATE INDEX iwl_prefix_from_title ON iwlinks (iwl_prefix, iwl_from, iwl_title); \ No newline at end of file +CREATE UNIQUE INDEX iwl_prefix_title_from ON iwlinks (iwl_prefix, iwl_from, iwl_title); diff --git a/maintenance/postgres/tables.sql b/maintenance/postgres/tables.sql index 5b100eeb3a..c38a56a16e 100644 --- a/maintenance/postgres/tables.sql +++ b/maintenance/postgres/tables.sql @@ -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); diff --git a/maintenance/sqlite/archives/patch-kill-iwl_pft.sql b/maintenance/sqlite/archives/patch-kill-iwl_pft.sql new file mode 100644 index 0000000000..96e1435693 --- /dev/null +++ b/maintenance/sqlite/archives/patch-kill-iwl_pft.sql @@ -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; + diff --git a/maintenance/sqlite/archives/patch-kill-iwl_prefix.sql b/maintenance/sqlite/archives/patch-kill-iwl_prefix.sql new file mode 100644 index 0000000000..1cd9b45416 --- /dev/null +++ b/maintenance/sqlite/archives/patch-kill-iwl_prefix.sql @@ -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; + diff --git a/maintenance/tables.sql b/maintenance/tables.sql index d3a12bdfb0..1e04c9b4c4 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -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); -- diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 246d6d6a1f..d81c3b11f0 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -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( -- 2.20.1