Refactor versioning from setup and store number internally.
authorGreg Sabino Mullane <greg@users.mediawiki.org>
Tue, 16 Jan 2007 04:04:55 +0000 (04:04 +0000)
committerGreg Sabino Mullane <greg@users.mediawiki.org>
Tue, 16 Jan 2007 04:04:55 +0000 (04:04 +0000)
Move tsearch indexes out of tables.sql and put into setup, so
that we can take advantage of GIN for >= 8.2

includes/DatabasePostgres.php
maintenance/postgres/tables.sql

index 628d528..70f60ad 100644 (file)
@@ -13,6 +13,7 @@
 class DatabasePostgres extends Database {
        var $mInsertId = NULL;
        var $mLastResult = NULL;
+       var $numeric_version = NULL;
 
        function DatabasePostgres($server = false, $user = false, $password = false, $dbName = false,
                $failFunction = false, $flags = 0 )
@@ -96,18 +97,13 @@ class DatabasePostgres extends Database {
                                $wgDBts2schema;
 
                        print "<li>Checking the version of Postgres...";
-                       $version = pg_fetch_result($this->doQuery("SELECT version()"),0,0);
-                       $thisver = array();
-                       if (!preg_match('/PostgreSQL (\d+\.\d+)(\S+)/', $version, $thisver)) {
-                               print "<b>FAILED</b> (could not determine the version)</li>\n";
-                               dieout("</ul>");
-                       }
+                       $version = $this->getServerVersion();
                        $PGMINVER = "8.1";
-                       if ($thisver[1] < $PGMINVER) {
-                               print "<b>FAILED</b>. Required version is $PGMINVER. You have $thisver[1]$thisver[2]</li>\n";
+                       if ($this->numeric_version < $PGMINVER) {
+                               print "<b>FAILED</b>. Required version is $PGMINVER. You have $this->numeric_version ($version)</li>\n";
                                dieout("</ul>");
                        }
-                       print "version $thisver[1]$thisver[2] is OK.</li>\n";
+                       print "version $this->numeric_version is OK.</li>\n";
 
                        $safeuser = $this->quote_ident($wgDBuser);
                        ## Are we connecting as a superuser for the first time?
@@ -721,10 +717,12 @@ class DatabasePostgres extends Database {
         * @return string Version information from the database
         */
        function getServerVersion() {
-               $res = $this->query( "SELECT version()" );
-               $row = $this->fetchRow( $res );
-               $version = $row[0];
-               $this->freeResult( $res );
+               $version = pg_fetch_result($this->doQuery("SELECT version()"),0,0);
+               $thisver = array();
+               if (!preg_match('/PostgreSQL (\d+\.\d+)(\S+)/', $version, $thisver)) {
+                       die("Could not determine the numeric version from $version!");
+               }
+               $this->numeric_version = $thisver[1];
                return $version;
        }
 
@@ -820,6 +818,16 @@ class DatabasePostgres extends Database {
 
                dbsource( "../maintenance/postgres/tables.sql", $this);
 
+               ## Version-specific stuff
+               if ($this->numeric_version == 8.1) {
+                       $this->doQuery("CREATE INDEX ts2_page_text ON pagecontent USING gist(textvector)");
+                       $this->doQuery("CREATE INDEX ts2_page_title ON page USING gist(titlevector)");
+               }
+               else {
+                       $this->doQuery("CREATE INDEX ts2_page_text ON pagecontent USING gin(textvector)");
+                       $this->doQuery("CREATE INDEX ts2_page_title ON page USING gin(titlevector)");
+               }
+
                ## Update version information
                $mwv = $this->addQuotes($wgVersion);
                $pgv = $this->addQuotes($this->getServerVersion());
index b2e659c..a7c7221 100644 (file)
@@ -439,7 +439,6 @@ CREATE INDEX job_cmd_namespace_title ON job (job_cmd, job_namespace, job_title);
 -- Tsearch2 2 stuff. Will fail if we don't have proper access to the tsearch2 tables
 
 ALTER TABLE page ADD titlevector tsvector;
-CREATE INDEX ts2_page_title ON page USING gist(titlevector);
 CREATE FUNCTION ts2_page_title() RETURNS TRIGGER LANGUAGE plpgsql AS
 $mw$
 BEGIN
@@ -457,7 +456,6 @@ CREATE TRIGGER ts2_page_title BEFORE INSERT OR UPDATE ON page
 
 
 ALTER TABLE pagecontent ADD textvector tsvector;
-CREATE INDEX ts2_page_text ON pagecontent USING gist(textvector);
 CREATE FUNCTION ts2_page_text() RETURNS TRIGGER LANGUAGE plpgsql AS
 $mw$
 BEGIN
@@ -473,6 +471,11 @@ $mw$;
 CREATE TRIGGER ts2_page_text BEFORE INSERT OR UPDATE ON pagecontent
   FOR EACH ROW EXECUTE PROCEDURE ts2_page_text();
 
+-- These are added by the setup script due to version compatibility issues
+-- If using 8.1, switch from "gin" to "gist"
+-- CREATE INDEX ts2_page_title ON page USING gin(titlevector);
+-- CREATE INDEX ts2_page_text ON pagecontent USING gin(textvector);
+
 CREATE FUNCTION add_interwiki (TEXT,INT,CHAR) RETURNS INT LANGUAGE SQL AS
 $mw$
   INSERT INTO interwiki (iw_prefix, iw_url, iw_local) VALUES ($1,$2,$3);