Manual:page table

From MediaWiki.org
(Redirected from Page table)
Jump to: navigation, search
Manual:Contents MediaWiki database layout page table


MediaWiki version: 1.5

The page table can be considered the "core of the wiki". Each page in a MediaWiki installation has an entry here which identifies it by title and contains some essential metadata. It was first introduced in r6710, in MediaWiki 1.5.

The text of the page itself is stored in the text table. To retrieve the text of an article, MediaWiki first searches for page_title in the page table. Then, page_latest is used to search the revision table for rev_id, and rev_text_id is obtained in the process. The value obtained for rev_text_id is used to search for old_id in the text table to retrieve the text. When a page is deleted, the revisions are moved to the archive table.

Note Note: If you want to completely delete a page manually from the database, be sure to delete the entry for the page in the page table, and for all the page's revisions in the revision table, and all of the text rows corresponding only to the page in the text table. This can be done by deleting the page row, then running maintenance/deleteOrphanedRevisions.php. See also title 'Deleting pages with their relationships in text and revision tables' below how to do.

Fields[edit | edit source]

page_id[edit | edit source]

Uniquely identifying primary key. This value is preserved across edits and renames. There is an analogous field to preserve this value in MediaWiki 1.11 and later; however, it is not used in Special:Undelete, the interface for undeleting pages used by project administrators. For example, for this page, page_id = 10501. [1][2]

page_namespace[edit | edit source]

A page name is broken into a namespace and a title. The namespace keys are UI-language-independent constants, defined in includes/Defines.php.

This field contains the number of the page's namespace. The values range from 0 to 15 for the standard namespaces, and from 100 to 2147483647 for custom namespaces.

page_title[edit | edit source]

The sanitized page title, without the title of its namespace with a maximum of 255 characters (binary), e.g. "[255 chars]" or "Talk:[255 chars]" or "Category discussion:[255 chars here]". It is stored as text, with spaces replaced by underscores. The real title shown in articles is just this title with underscores (_) converted to spaces ( ).

page_restrictions[edit | edit source]

MediaWiki version: 1.9

Comma-separated set of permission keys indicating who can move or edit the page. Edit and move sections are separated by a colon (e.g., "edit=autoconfirmed,sysop:move=sysop").

Note Note: Beginning with MediaWiki 1.10, page protection controls were moved to the page restrictions table, so this field will be empty in databases generated by more current versions of MediaWiki.

page_counter[edit | edit source]

Number of times this page has been viewed. Note that on some sites (e.g. Wikimedia sites) incrementing this field is disabled so as to increase performance - see the $wgDisableCounters global.

page_is_redirect[edit | edit source]

A value of 1 here indicates the article is a redirect; it is 0 in all other cases.

page_is_new[edit | edit source]

This field stores whether the page is a new entry or not; if the field contains a value of 1, then it indicates that the page is a new entry with only one edit. It is 0 in all other cases.

page_random[edit | edit source]

Random decimal value, between 0 and 1, used for Special:Random (see Manual:Random page for more details)

page_touched[edit | edit source]

This timestamp is updated whenever the page changes in a way requiring it to be re-rendered, invalidating caches. Aside from editing this includes permission changes, creation or deletion of linked pages, and alteration of contained templates.

page_latest[edit | edit source]

This is a foreign key to rev_id for the current revision. It may be 0 during page creation.

page_len[edit | edit source]

Uncompressed length in bytes of the page's current source text.

page_content_model[edit | edit source]

MediaWiki version: 1.21

Content model, see CONTENT_MODEL_XXX constants. Comparable to revision.rev_content_model.

Schema summary[edit | edit source]

MediaWiki version: 1.21
mysql> describe page;
+--------------------+---------------------+------+-----+----------------+----------------+
| Field              | Type                | Null | Key | Default        | Extra          |
+--------------------+---------------------+------+-----+----------------+----------------+
| page_id            | int(10) unsigned    | NO   | PRI | NULL           | auto_increment |
| page_namespace     | int(11)             | NO   | MUL | NULL           |                |
| page_title         | varbinary(255)      | NO   |     | NULL           |                |
| page_restrictions  | tinyblob            | NO   |     | NULL           |                |
| page_counter       | bigint(20) unsigned | NO   |     | 0              |                |
| page_is_redirect   | tinyint(3) unsigned | NO   | MUL | 0              |                |
| page_is_new        | tinyint(3) unsigned | NO   |     | 0              |                |
| page_random        | double unsigned     | NO   | MUL | NULL           |                |
| page_touched       | binary(14)          | NO   |     |                |                |
| page_latest        | int(10) unsigned    | NO   |     | NULL           |                |
| page_len           | int(10) unsigned    | NO   | MUL | NULL           |                |
| page_content_model | varbinary(32)       | YES  |     | NULL           |                |
+--------------------+---------------------+------+-----+----------------+----------------+
12 rows in set (0.00 sec)


MediaWiki versions: 1.18 – 1.19

DESCRIBE page; in MediaWiki 1.19 results in:

+-------------------+---------------------+------+-----+----------------+----------------+
| Field             | Type                | Null | Key | Default        | Extra          |
+-------------------+---------------------+------+-----+----------------+----------------+
| page_id           | int(10) unsigned    | NO   | PRI | NULL           | auto_increment |
| page_namespace    | int(11)             | NO   | MUL | NULL           |                |
| page_title        | varbinary(255)      | NO   |     | NULL           |                |
| page_restrictions | tinyblob            | NO   |     | NULL           |                |
| page_counter      | bigint(20) unsigned | NO   |     | 0              |                |
| page_is_redirect  | tinyint(3) unsigned | NO   | MUL | 0              |                |
| page_is_new       | tinyint(3) unsigned | NO   |     | 0              |                |
| page_random       | double unsigned     | NO   | MUL | NULL           |                |
| page_touched      | binary(14)          | NO   |     |                |                |
| page_latest       | int(10) unsigned    | NO   |     | NULL           |                |
| page_len          | int(10) unsigned    | NO   | MUL | NULL           |                |
+-------------------+---------------------+------+-----+----------------+----------------+
MediaWiki version: 1.12

DESCRIBE page; in MediaWiki 1.12 results in:

+-----------------------+---------------------+------+-----+---------+----------------+
| Field                 | Type                | Null | Key | Default | Extra          |
+-----------------------+---------------------+------+-----+---------+----------------+
| page_id               | int(8) unsigned     | NO   | PRI | NULL    | auto_increment |
| page_namespace        | int(11)             | NO   | MUL | NULL    |                |
| page_title            | varchar(255)        | NO   |     | NULL    |                |
| page_restrictions     | tinyblob            | NO   |     | NULL    |                |
| page_counter          | bigint(20) unsigned | NO   |     | 0       |                |
| page_is_redirect      | tinyint(1) unsigned | NO   |     | 0       |                |
| page_is_new           | tinyint(1) unsigned | NO   |     | 0       |                |
| page_random           | double unsigned     | NO   | MUL | NULL    |                |
| page_touched          | char(14)            | NO   |     | NULL    |                |
| page_latest           | int(8) unsigned     | NO   |     | NULL    |                |
| page_len              | int(8) unsigned     | NO   | MUL | NULL    |                |
+-----------------------+---------------------+------+-----+---------+----------------+
MediaWiki version: 1.11

DESCRIBE page; in MediaWiki 1.11 results in:

+-----------------------+---------------------+------+-----+---------+----------------+
| Field                 | Type                | Null | Key | Default | Extra          |
+-----------------------+---------------------+------+-----+---------+----------------+
| page_id               | int(10) unsigned    | NO   | PRI | NULL    | auto_increment |
| page_namespace        | int(11)             | NO   | MUL | NULL    |                |
| page_title            | varchar(255)        | NO   |     | NULL    |                |
| page_restrictions     | tinyblob            | NO   |     | NULL    |                |
| page_counter          | bigint(20) unsigned | NO   |     | 0       |                |
| page_is_redirect      | tinyint(3) unsigned | NO   |     | 0       |                |
| page_is_new           | tinyint(3) unsigned | NO   |     | 0       |                |
| page_random           | double unsigned     | NO   | MUL | NULL    |                |
| page_touched          | binary(14)          | NO   |     | NULL    |                |
| page_latest           | int(10) unsigned    | NO   |     | NULL    |                |
| page_len              | int(10) unsigned    | NO   | MUL | NULL    |                |
+-----------------------+---------------------+------+-----+---------+----------------+
MediaWiki version: 1.10

DESCRIBE page; in MediaWiki 1.5 through 1.10 results in:

+-----------------------+---------------------+------+-----+---------+----------------+
| Field                 | Type                | Null | Key | Default | Extra          |
+-----------------------+---------------------+------+-----+---------+----------------+
| page_id               | int(8) unsigned     | NO   | PRI | NULL    | auto_increment |
| page_namespace        | int(11)             | NO   | MUL | NULL    |                |
| page_title            | varchar(255)        | NO   |     | NULL    |                |
| page_restrictions     | tinyblob            | NO   |     | NULL    |                |
| page_counter          | bigint(20) unsigned | NO   |     | 0       |                |
| page_is_redirect      | tinyint(1) unsigned | NO   |     | 0       |                |
| page_is_new           | tinyint(1) unsigned | NO   |     | 0       |                |
| page_random           | double unsigned     | NO   | MUL | NULL    |                |
| page_touched          | char(14)            | NO   |     | NULL    |                |
| page_latest           | int(8) unsigned     | NO   |     | NULL    |                |
| page_len              | int(8) unsigned     | NO   | MUL | NULL    |                |
+-----------------------+---------------------+------+-----+---------+----------------+

Indices[edit | edit source]

MediaWiki version: 1.20
mysql> show index in page;
+-------+------------+-----------------------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name                    | Seq_in_index | Column_name      | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+-----------------------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| page  |          0 | PRIMARY                     |            1 | page_id          | A         |           1 |     NULL | NULL   |      | BTREE      |         |               |
| page  |          0 | name_title                  |            1 | page_namespace   | A         |           1 |     NULL | NULL   |      | BTREE      |         |               |
| page  |          0 | name_title                  |            2 | page_title       | A         |           1 |     NULL | NULL   |      | BTREE      |         |               |
| page  |          1 | page_random                 |            1 | page_random      | A         |           1 |     NULL | NULL   |      | BTREE      |         |               |
| page  |          1 | page_len                    |            1 | page_len         | A         |           1 |     NULL | NULL   |      | BTREE      |         |               |
| page  |          1 | page_redirect_namespace_len |            1 | page_is_redirect | A         |           1 |     NULL | NULL   |      | BTREE      |         |               |
| page  |          1 | page_redirect_namespace_len |            2 | page_namespace   | A         |           1 |     NULL | NULL   |      | BTREE      |         |               |
| page  |          1 | page_redirect_namespace_len |            3 | page_len         | A         |           1 |     NULL | NULL   |      | BTREE      |         |               |
+-------+------------+-----------------------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+

Sample MySQL code[edit | edit source]

Listing pages and relations with other essential tables[edit | edit source]

The following code will select the most recent versions of all articles from core tables: [page, revision, text]:

SELECT
    p.page_id AS "page_id",
    CAST(p.page_title AS CHAR(10000) CHARACTER SET utf8) AS "page_title",
    r.rev_text_id AS "revision_id",
    t.old_id AS "text_id"
FROM
    page p
        INNER JOIN revision r
            ON p.page_latest = r.rev_id
        INNER JOIN text t
            ON r.rev_text_id = t.old_id

Other important considerations:

  • to find undeleted pages add "r.rev_deleted = 0"
  • to find pages in namespace 0 add "p.page_namespace = 0"
  • to find pages that are not redirects add "p.page_is_redirect = 0"

These additional statements can be added either as conditions to a Where statement or as conditions on the appropriate Inner Join statement.

Deleting pages with their relationships in text and revision tables[edit | edit source]

The following shows a steps to run to help you delete pages and their children from the main pages in the page, revision and text tables.

Listing all related table keys

-- 
-- Listing page titles and related relationships to other tables (revision, text, page)
--
SELECT
    `p`.`page_id` AS "page_id",
    CAST(`p`.`page_title` AS CHAR(10000) CHARACTER SET utf8) AS "page_title",
    `r`.`rev_text_id` AS "revision_id",
    `t`.`old_id` AS "text_id"
FROM
    page p
        INNER JOIN `revision` r
            ON `p`.`page_id` = `r`.`rev_page`    -- Confirmed to be reference to page.page_id
        INNER JOIN `text` t
            ON `r`.`rev_text_id` = `t`.`old_id`  -- Confirmed to be reference to revision table
WHERE 
	`p`.`page_title` LIKE '%Tests/parent-a%';    -- Match with title of a parent page

Deleting from database the rows

-- 
-- Making a coma separated list of each table ids to delete, Will be used in a delete transaction
--
SELECT
    CONCAT('IN(', GROUP_CONCAT(`p`.`page_id`), ')') AS 'page',
    CONCAT('IN(', GROUP_CONCAT(`r`.`rev_text_id`), ')')  AS 'revision',
    CONCAT('IN(', GROUP_CONCAT(`t`.`old_id`), ')')  AS 'text'
FROM
    page p
        INNER JOIN `revision` r
            ON `p`.`page_id` = `r`.`rev_page`        -- Confirmed to be reference to page.page_id
        INNER JOIN text t
            ON `r`.`rev_text_id` = `t`.`old_id`      -- Confirmed to be reference to revision table
WHERE 
	p.page_title LIKE '%Tests/parent-a%';    -- Match with title of a parent page

You should have a result set like this

+--------------------------------------------------+--------------------------------------------------+--------------------------------------------------+
| page                                             | revision                                         | text                                             |
+--------------------------------------------------+--------------------------------------------------+--------------------------------------------------+
| IN(5530,5528,5529,5530,5529,5528,5532,5532,5532) | IN(9918,9921,9917,9919,9920,9916,9922,9915,9923) | IN(9918,9921,9917,9919,9920,9916,9922,9915,9923) |
+--------------------------------------------------+--------------------------------------------------+--------------------------------------------------+
1 ROW IN SET (0.07 sec)

Replace the concatenated id in the following query

-- 
-- DELETING pages in one transaction
-- NOTE: adjust the content IN(...) with your own :)
--
SET autocommit=0;
START TRANSACTION;
  DELETE FROM `page` WHERE page_id IN(5530,5528,5529,5530,5529,5528,5532,5532,5532);
  DELETE FROM `revision` WHERE rev_text_id IN(9918,9921,9917,9919,9920,9916,9922,9915,9923);
  DELETE FROM `text` WHERE old_id IN(9918,9921,9917,9919,9920,9916,9922,9915,9923);
COMMIT;

After, you can do some cleanup using this maintenance script:

php maintenance/deleteOrphanedRevisions.php

See also[edit | edit source]

Databases Engines: MySQLOraclePostgreSQLSQLite
Technical documentation: Schema (tables) – API property associationsField prefixesPrimary key storage in other fieldsWikimedia extension tables
Configuration: SettingsSharing
Development: AccessOptimizationPolicyUpdaterExtension schema updatesPatch file
Core tables: archivecategorycategorylinkschange_tagconfigexternallinksfilearchivehitcounterimageimagelinksinterwikiiwlinksipblocksjobl10n_cachelanglinkslogginglog_searchmsg_resourcemsg_resource_linksmodule_depsobjectcacheoldimagepagepagelinkspage_propspage_restrictionsprotected_titlesquerycachequerycachetwoquerycache_inforecentchangesredirectrevisionsearchindexsitessite_statstag_summarytemplatelinkstexttranscacheupdateloguploadstashuseruser_former_groupsuser_groupsuser_newtalkuser_propertiesvalid_tagwatchlist
Language: English  • 日本語