r40515 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40514‎ | r40515 | r40516 >
Date:07:05, 6 September 2008
Author:tstarling
Status:old
Tags:
Comment:
Fixed bug 15148, total breakage of Special:BlockIP on PostgreSQL:

* Migrated to a unique index for IP block conflict detection, like we did for MySQL some aeons ago.
* Modified DatabasePostgres to return a correct affected row count for INSERT IGNORE. Tested for single and multi.
* Fixed an unrelated bug: duplicate index rc_timestamp in tables.sql
* Tested for install and upgrade on PG 8.3.

No changelog because I'll backport it to 1.13.
Modified paths:
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)
  • /trunk/phase3/maintenance/postgres/archives/patch-ipb_address_unique.sql (added) (history)
  • /trunk/phase3/maintenance/postgres/tables.sql (modified) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/postgres/archives/patch-ipb_address_unique.sql
@@ -0,0 +1,2 @@
 2+DROP INDEX IF EXISTS ipb_address;
 3+CREATE UNIQUE INDEX ipb_address_unique ON ipblocks (ipb_address,ipb_user,ipb_auto,ipb_anon_only);
Property changes on: trunk/phase3/maintenance/postgres/archives/patch-ipb_address_unique.sql
___________________________________________________________________
Added: svn:eol-style
14 + native
Index: trunk/phase3/maintenance/postgres/tables.sql
@@ -241,9 +241,8 @@
242242 ipb_range_end TEXT,
243243 ipb_deleted SMALLINT NOT NULL DEFAULT 0,
244244 ipb_block_email SMALLINT NOT NULL DEFAULT 0
245 -
246245 );
247 -CREATE INDEX ipb_address ON ipblocks (ipb_address);
 246+CREATE UNIQUE INDEX ipb_address_unique ON ipblocks (ipb_address,ipb_user,ipb_auto,ipb_anon_only);
248247 CREATE INDEX ipb_user ON ipblocks (ipb_user);
249248 CREATE INDEX ipb_range ON ipblocks (ipb_range_start,ipb_range_end);
250249
@@ -352,7 +351,7 @@
353352 rc_params TEXT
354353 );
355354 CREATE INDEX rc_timestamp ON recentchanges (rc_timestamp);
356 -CREATE INDEX rc_timestamp ON recentchanges (rc_timestamp) WHERE rc_bot = '0';
 355+CREATE INDEX rc_timestamp_bot ON recentchanges (rc_timestamp) WHERE rc_bot = '0';
357356 CREATE INDEX rc_namespace_title ON recentchanges (rc_namespace, rc_title);
358357 CREATE INDEX rc_cur_id ON recentchanges (rc_cur_id);
359358 CREATE INDEX new_name_timestamp ON recentchanges (rc_new, rc_namespace, rc_timestamp);
Index: trunk/phase3/maintenance/updaters.inc
@@ -1686,7 +1686,7 @@
16871687 $wgDatabase->query("CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)");
16881688 }
16891689 else
1690 - echo "... index \"pagelink_unique_index\" aready exists\n";
 1690+ echo "... index \"pagelink_unique_index\" already exists\n";
16911691
16921692 if (pg_fkey_deltype("revision_rev_user_fkey") == 'r') {
16931693 echo "... constraint \"revision_rev_user_fkey\" is ON DELETE RESTRICT\n";
@@ -1696,6 +1696,14 @@
16971697 dbsource(archive('patch-revision_rev_user_fkey.sql'));
16981698 }
16991699
 1700+ # Fix ipb_address index
 1701+ if (pg_index_exists('ipblocks', 'ipb_address_unique' )) {
 1702+ echo "... have ipb_address_unique\n";
 1703+ } else {
 1704+ echo "Adding ipb_address_unique index\n";
 1705+ dbsource(archive('patch-ipb_address_unique.sql'));
 1706+ }
 1707+
17001708 global $wgExtNewTables, $wgExtPGNewFields, $wgExtNewIndexes;
17011709 # Add missing extension tables
17021710 foreach ( $wgExtNewTables as $nt ) {
Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -72,6 +72,7 @@
7373 var $mInsertId = NULL;
7474 var $mLastResult = NULL;
7575 var $numeric_version = NULL;
 76+ var $mAffectedRows = NULL;
7677
7778 function DatabasePostgres($server = false, $user = false, $password = false, $dbName = false,
7879 $failFunction = false, $flags = 0 )
@@ -546,9 +547,11 @@
547548
548549 function doQuery( $sql ) {
549550 if (function_exists('mb_convert_encoding')) {
550 - return $this->mLastResult=pg_query( $this->mConn , mb_convert_encoding($sql,'UTF-8') );
 551+ $sql = mb_convert_encoding($sql,'UTF-8');
551552 }
552 - return $this->mLastResult=pg_query( $this->mConn , $sql);
 553+ $this->mLastResult = pg_query( $this->mConn, $sql);
 554+ $this->mAffectedRows = NULL; // use pg_affected_rows(mLastResult)
 555+ return $this->mLastResult;
553556 }
554557
555558 function queryIgnore( $sql, $fname = '' ) {
@@ -641,9 +644,12 @@
642645 }
643646
644647 function affectedRows() {
645 - if( !isset( $this->mLastResult ) or ! $this->mLastResult )
 648+ if ( !is_null( $this->mAffectedRows ) ) {
 649+ // Forced result for simulated queries
 650+ return $this->mAffectedRows;
 651+ }
 652+ if( empty( $this->mLastResult ) )
646653 return 0;
647 -
648654 return pg_affected_rows( $this->mLastResult );
649655 }
650656
@@ -809,7 +815,6 @@
810816
811817 $sql .= '(' . $this->makeList( $args ) . ')';
812818 $res = (bool)$this->query( $sql, $fname, $ignore );
813 -
814819 if ( $ignore ) {
815820 $bar = pg_last_error();
816821 if ($bar != false) {
@@ -821,13 +826,15 @@
822827 }
823828 }
824829 }
825 -
826830 if ( $ignore ) {
827831 $olde = error_reporting( $olde );
828832 if ($didbegin) {
829833 $this->commit();
830834 }
831835
 836+ // Set the affected row count for the whole operation
 837+ $this->mAffectedRows = $numrowsinserted;
 838+
832839 // IGNORE always returns true
833840 return true;
834841 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r40517Fixed bug 15148, Special:BlockIP broken for PostgreSQL. Backport of r40515.tstarling07:14, 6 September 2008

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r39763Force inserted bools to be ints, per Tim's suggestion on bug 15148....greg13:10, 21 August 2008