Merge "Add pp_propname_page index to page_props"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 25 Feb 2013 22:54:48 +0000 (22:54 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 25 Feb 2013 22:54:48 +0000 (22:54 +0000)
1  2 
includes/installer/MysqlUpdater.php
includes/installer/PostgresUpdater.php
maintenance/postgres/tables.sql

@@@ -228,6 -228,7 +228,7 @@@ class MysqlUpdater extends DatabaseUpda
                        array( 'addField', 'uploadstash',      'us_props',      'patch-uploadstash-us_props.sql' ),
                        array( 'modifyField', 'user_groups', 'ug_group', 'patch-ug_group-length-increase-255.sql' ),
                        array( 'modifyField', 'user_former_groups', 'ufg_group', 'patch-ufg_group-length-increase-255.sql' ),
+                       array( 'addIndex', 'page_props', 'pp_propname_page',  'patch-page_props-propname-page-index.sql' ),
                );
        }
  
                }
  
                if( $this->applyPatch( 'patch-fix-il_from.sql', false, "Fixing ancient broken imagelinks table." ) ) {
 -                      $this->output("NOTE: you will have to run maintenance/refreshLinks.php after this." );
 +                      $this->output( "NOTE: you will have to run maintenance/refreshLinks.php after this." );
                }
        }
  
@@@ -90,7 -90,6 +90,7 @@@ class PostgresUpdater extends DatabaseU
                        array( 'addTable', 'uploadstash',       'patch-uploadstash.sql' ),
                        array( 'addTable', 'user_former_groups','patch-user_former_groups.sql' ),
                        array( 'addTable', 'external_user',     'patch-external_user.sql' ),
 +                      array( 'addTable', 'sites',             'patch-sites.sql' ),
  
                        # Needed before new field
                        array( 'convertArchive2' ),
                        array( 'addPgField', 'uploadstash',   'us_chunk_inx',         "INTEGER NULL" ),
                        array( 'addPgField', 'job',           'job_timestamp',        "TIMESTAMPTZ" ),
                        array( 'addPgField', 'job',           'job_random',           "INTEGER NOT NULL DEFAULT 0" ),
 +                      array( 'addPgField', 'job',           'job_attempts',         "INTEGER NOT NULL DEFAULT 0" ),
                        array( 'addPgField', 'job',           'job_token',            "TEXT NOT NULL DEFAULT ''" ),
                        array( 'addPgField', 'job',           'job_token_timestamp',  "TIMESTAMPTZ" ),
                        array( 'addPgField', 'job',           'job_sha1',             "TEXT NOT NULL DEFAULT ''" ),
                        array( 'addPgIndex', 'oldimage',      'oi_sha1',                '(oi_sha1)' ),
                        array( 'addPgIndex', 'page',          'page_mediawiki_title',   '(page_title) WHERE page_namespace = 8' ),
                        array( 'addPgIndex', 'pagelinks',     'pagelinks_title',        '(pl_title)' ),
+                       array( 'addPgIndex', 'page_props',    'pp_propname_page',       '(pp_propname, pp_page)' ),
                        array( 'addPgIndex', 'revision',      'rev_text_id_idx',        '(rev_text_id)' ),
                        array( 'addPgIndex', 'recentchanges', 'rc_timestamp_bot',       '(rc_timestamp) WHERE rc_bot = 0' ),
                        array( 'addPgIndex', 'templatelinks', 'templatelinks_from',     '(tl_from)' ),
                        array( 'addPgIndex', 'job',           'job_timestamp_idx',      '(job_timestamp)' ),
                        array( 'addPgIndex', 'job',           'job_sha1',               '(job_sha1)' ),
                        array( 'addPgIndex', 'job',           'job_cmd_token',          '(job_cmd, job_token, job_random)' ),
 +                      array( 'addPgIndex', 'job',           'job_cmd_token_id',       '(job_cmd, job_token, job_id)' ),
                        array( 'addPgIndex', 'filearchive',   'fa_sha1',                '(fa_sha1)' ),
  
                        array( 'checkIndex', 'pagelink_unique', array(
 -                              array('pl_from', 'int4_ops', 'btree', 0),
 -                              array('pl_namespace', 'int2_ops', 'btree', 0),
 -                              array('pl_title', 'text_ops', 'btree', 0),
 +                              array( 'pl_from', 'int4_ops', 'btree', 0 ),
 +                              array( 'pl_namespace', 'int2_ops', 'btree', 0 ),
 +                              array( 'pl_title', 'text_ops', 'btree', 0 ),
                        ),
                        'CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)' ),
                        array( 'checkIndex', 'cl_sortkey', array(
 -                              array('cl_to', 'text_ops', 'btree', 0),
 -                              array('cl_sortkey', 'text_ops', 'btree', 0),
 -                              array('cl_from', 'int4_ops', 'btree', 0),
 +                              array( 'cl_to', 'text_ops', 'btree', 0 ),
 +                              array( 'cl_sortkey', 'text_ops', 'btree', 0 ),
 +                              array( 'cl_from', 'int4_ops', 'btree', 0 ),
                        ),
                        'CREATE INDEX cl_sortkey ON "categorylinks" USING "btree" ("cl_to", "cl_sortkey", "cl_from")' ),
                        array( 'checkIndex', 'logging_times', array(
 -                              array('log_timestamp', 'timestamptz_ops', 'btree', 0),
 +                              array( 'log_timestamp', 'timestamptz_ops', 'btree', 0 ),
                        ),
                        'CREATE INDEX "logging_times" ON "logging" USING "btree" ("log_timestamp")' ),
                        array( 'dropIndex', 'oldimage', 'oi_name' ),
                        array( 'checkIndex', 'oi_name_archive_name', array(
 -                              array('oi_name', 'text_ops', 'btree', 0),
 -                              array('oi_archive_name', 'text_ops', 'btree', 0),
 +                              array( 'oi_name', 'text_ops', 'btree', 0 ),
 +                              array( 'oi_archive_name', 'text_ops', 'btree', 0 ),
                        ),
                        'CREATE INDEX "oi_name_archive_name" ON "oldimage" USING "btree" ("oi_name", "oi_archive_name")' ),
                        array( 'checkIndex', 'oi_name_timestamp', array(
 -                              array('oi_name', 'text_ops', 'btree', 0),
 -                              array('oi_timestamp', 'timestamptz_ops', 'btree', 0),
 +                              array( 'oi_name', 'text_ops', 'btree', 0 ),
 +                              array( 'oi_timestamp', 'timestamptz_ops', 'btree', 0 ),
                        ),
                        'CREATE INDEX "oi_name_timestamp" ON "oldimage" USING "btree" ("oi_name", "oi_timestamp")' ),
                        array( 'checkIndex', 'page_main_title', array(
 -                              array('page_title', 'text_pattern_ops', 'btree', 0),
 +                              array( 'page_title', 'text_pattern_ops', 'btree', 0 ),
                        ),
                        'CREATE INDEX "page_main_title" ON "page" USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 0)' ),
                        array( 'checkIndex', 'page_mediawiki_title', array(
 -                              array('page_title', 'text_pattern_ops', 'btree', 0),
 +                              array( 'page_title', 'text_pattern_ops', 'btree', 0 ),
                        ),
                        'CREATE INDEX "page_mediawiki_title" ON "page" USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 8)' ),
                        array( 'checkIndex', 'page_project_title', array(
 -                              array('page_title', 'text_pattern_ops', 'btree', 0),
 +                              array( 'page_title', 'text_pattern_ops', 'btree', 0 ),
                        ),
                        'CREATE INDEX "page_project_title" ON "page" USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 4)' ),
                        array( 'checkIndex', 'page_talk_title', array(
 -                              array('page_title', 'text_pattern_ops', 'btree', 0),
 +                              array( 'page_title', 'text_pattern_ops', 'btree', 0 ),
                        ),
                        'CREATE INDEX "page_talk_title" ON "page" USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 1)' ),
                        array( 'checkIndex', 'page_user_title', array(
 -                              array('page_title', 'text_pattern_ops', 'btree', 0),
 +                              array( 'page_title', 'text_pattern_ops', 'btree', 0 ),
                        ),
                        'CREATE INDEX "page_user_title" ON "page" USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 2)' ),
                        array( 'checkIndex', 'page_utalk_title', array(
 -                              array('page_title', 'text_pattern_ops', 'btree', 0),
 +                              array( 'page_title', 'text_pattern_ops', 'btree', 0 ),
                        ),
                        'CREATE INDEX "page_utalk_title" ON "page" USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 3)' ),
                        array( 'checkIndex', 'ts2_page_text', array(
 -                              array('textvector', 'tsvector_ops', 'gist', 0),
 +                              array( 'textvector', 'tsvector_ops', 'gist', 0 ),
                        ),
                        'CREATE INDEX "ts2_page_text" ON "pagecontent" USING "gist" ("textvector")' ),
                        array( 'checkIndex', 'ts2_page_title', array(
 -                              array('titlevector', 'tsvector_ops', 'gist', 0),
 +                              array( 'titlevector', 'tsvector_ops', 'gist', 0 ),
                        ),
                        'CREATE INDEX "ts2_page_title" ON "page" USING "gist" ("titlevector")' ),
  
                        array( 'checkRevUserFkey' ),
                        array( 'dropIndex', 'ipblocks', 'ipb_address'),
                        array( 'checkIndex', 'ipb_address_unique', array(
 -                              array('ipb_address', 'text_ops', 'btree', 0),
 -                              array('ipb_user',    'int4_ops', 'btree', 0),
 -                              array('ipb_auto',    'int2_ops', 'btree', 0),
 -                              array('ipb_anon_only', 'int2_ops', 'btree', 0),
 +                              array( 'ipb_address', 'text_ops', 'btree', 0 ),
 +                              array( 'ipb_user',    'int4_ops', 'btree', 0 ),
 +                              array( 'ipb_auto',    'int2_ops', 'btree', 0 ),
 +                              array( 'ipb_anon_only', 'int2_ops', 'btree', 0 ),
                        ),
                        'CREATE UNIQUE INDEX ipb_address_unique ON ipblocks (ipb_address,ipb_user,ipb_auto,ipb_anon_only)' ),
  
@@@ -509,7 -507,7 +510,7 @@@ END
                        $this->output( "Creating sequence $ns\n" );
                        $this->db->query( "CREATE SEQUENCE $ns" );
                        if( $pkey !== false ) {
 -                              $this->setDefault( $table,  $pkey, '"nextval"(\'"' . $ns . '"\'::"regclass")' );
 +                              $this->setDefault( $table, $pkey, '"nextval"(\'"' . $ns . '"\'::"regclass")' );
                        }
                }
        }
                }
        }
  
 -      protected function renameIndex( $table, $old, $new ) {
 -              if ( $this->db->indexExists( $table, $old ) ) {
 -                      $this->output( "Renaming index $old to $new\n" );
 -                      $this->db->query( "ALTER INDEX $old RENAME TO $new" );
 +      protected function renameIndex(
 +              $table, $old, $new, $skipBothIndexExistWarning = false, $a = false, $b = false
 +      ) {
 +              // First requirement: the table must exist
 +              if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
 +                      $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
 +                      return;
 +              }
 +
 +              // Second requirement: the new index must be missing
 +              if ( $this->db->indexExists( $table, $new, __METHOD__ ) ) {
 +                      $this->output( "...index $new already set on $table table.\n" );
 +                      if ( !$skipBothIndexExistWarning
 +                              && $this->db->indexExists( $table, $old, __METHOD__ ) )
 +                      {
 +                              $this->output( "...WARNING: $old still exists, despite it has been renamed into $new (which also exists).\n" .
 +                                      "            $old should be manually removed if not needed anymore.\n" );
 +                      }
 +                      return;
                }
 +
 +              // Third requirement: the old index must exist
 +              if ( !$this->db->indexExists( $table, $old, __METHOD__ ) ) {
 +                      $this->output( "...skipping: index $old doesn't exist.\n" );
 +                      return;
 +              }
 +
 +              $this->db->query( "ALTER INDEX $old RENAME TO $new" );
        }
  
        protected function addPgField( $table, $field, $type ) {
@@@ -154,6 -154,7 +154,7 @@@ CREATE TABLE page_props 
  );
  ALTER TABLE page_props ADD CONSTRAINT page_props_pk PRIMARY KEY (pp_page,pp_propname);
  CREATE INDEX page_props_propname ON page_props (pp_propname);
+ CREATE UNIQUE INDEX pp_propname_page ON page_props (pp_propname,pp_page);
  
  CREATE TABLE archive (
    ar_namespace      SMALLINT     NOT NULL,
@@@ -530,14 -531,12 +531,14 @@@ CREATE TABLE job 
    job_timestamp       TIMESTAMPTZ,
    job_params          TEXT      NOT NULL,
    job_random          INTEGER   NOT NULL DEFAULT 0,
 +  job_attempts        INTEGER   NOT NULL DEFAULT 0,
    job_token           TEXT      NOT NULL DEFAULT '',
    job_token_timestamp TIMESTAMPTZ,
    job_sha1            TEXT NOT NULL DEFAULT ''
  );
  CREATE INDEX job_sha1 ON job (job_sha1);
  CREATE INDEX job_cmd_token ON job (job_cmd, job_token, job_random);
 +CREATE INDEX job_cmd_token_id ON job (job_cmd, job_token, job_id);
  CREATE INDEX job_cmd_namespace_title ON job (job_cmd, job_namespace, job_title);
  CREATE INDEX job_timestamp_idx ON job (job_timestamp);
  
@@@ -699,35 -698,3 +700,35 @@@ CREATE TABLE module_deps 
    md_deps    TEXT  NOT NULL
  );
  CREATE UNIQUE INDEX md_module_skin ON module_deps (md_module, md_skin);
 +
 +CREATE SEQUENCE sites_site_id_seq;
 +CREATE TABLE sites (
 +  site_id           INTEGER     NOT NULL    PRIMARY KEY DEFAULT nextval('sites_site_id_seq'),
 +  site_global_key   TEXT        NOT NULL,
 +  site_type         TEXT        NOT NULL,
 +  site_group        TEXT        NOT NULL,
 +  site_source       TEXT        NOT NULL,
 +  site_language     TEXT        NOT NULL,
 +  site_protocol     TEXT        NOT NULL,
 +  site_domain       TEXT        NOT NULL,
 +  site_data         TEXT        NOT NULL,
 +  site_forward      SMALLINT    NOT NULL,
 +  site_config       TEXT        NOT NULL
 +);
 +CREATE UNIQUE INDEX site_global_key ON sites (site_global_key);
 +CREATE INDEX site_type ON sites (site_type);
 +CREATE INDEX site_group ON sites (site_group);
 +CREATE INDEX site_source ON sites (site_source);
 +CREATE INDEX site_language ON sites (site_language);
 +CREATE INDEX site_protocol ON sites (site_protocol);
 +CREATE INDEX site_domain ON sites (site_domain);
 +CREATE INDEX site_forward ON sites (site_forward);
 +
 +CREATE TABLE site_identifiers (
 +  si_site   INTEGER NOT NULL,
 +  si_type   TEXT    NOT NULL,
 +  si_key    TEXT    NOT NULL
 +);
 +CREATE UNIQUE INDEX si_type_key ON site_identifiers (si_type, si_key);
 +CREATE INDEX si_site ON site_identifiers (si_site);
 +CREATE INDEX si_key ON site_identifiers (si_key);