From 153e82e75dd989c3227471617dcdc071f9df6634 Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Tue, 16 Jan 2007 04:04:55 +0000 Subject: [PATCH] Refactor versioning from setup and store number internally. 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 | 34 ++++++++++++++++++++------------- maintenance/postgres/tables.sql | 7 +++++-- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/includes/DatabasePostgres.php b/includes/DatabasePostgres.php index 628d5282ad..70f60ad65d 100644 --- a/includes/DatabasePostgres.php +++ b/includes/DatabasePostgres.php @@ -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 "
  • 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 "FAILED (could not determine the version)
  • \n"; - dieout(""); - } + $version = $this->getServerVersion(); $PGMINVER = "8.1"; - if ($thisver[1] < $PGMINVER) { - print "FAILED. Required version is $PGMINVER. You have $thisver[1]$thisver[2]\n"; + if ($this->numeric_version < $PGMINVER) { + print "FAILED. Required version is $PGMINVER. You have $this->numeric_version ($version)\n"; dieout(""); } - print "version $thisver[1]$thisver[2] is OK.\n"; + print "version $this->numeric_version is OK.\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()); diff --git a/maintenance/postgres/tables.sql b/maintenance/postgres/tables.sql index b2e659cda1..a7c72212aa 100644 --- a/maintenance/postgres/tables.sql +++ b/maintenance/postgres/tables.sql @@ -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); -- 2.20.1