Skip to main content
Semantic MediaWiki creates and manages its own set of database tables. It never modifies MediaWiki core tables. The schema is defined in code using TableSchemaManager and TableBuilder, which handle table creation, upgrades, and removal.
Never modify or query SMW tables directly from external code. Use the public SMW API (Store methods) to read and write semantic data. Direct table access bypasses caching, hook integration, and future schema migrations.

SPO pattern

Most SMW tables follow a subject-predicate-object (SPO) pattern. Table fields are named with prefixes that reflect their role:
PrefixRole
s_Subject (the page being annotated)
p_Predicate (the property)
o_Object (the value)

Table types

SMW uses three categories of tables:
CategoryNaming patternDescription
Data tablessmw_* (various)General-purpose tables that do not follow the SPO pattern: IDs, statistics, dependencies.
Common property tablessmw_di_*SPO tables for user-defined properties with an assigned datatype. Include both p_id and s_id.
Fixed property tablessmw_fpt_*SPO tables dedicated to one specific property. Omit p_id since the property is implicit.
Temporary tables used during query execution remain in memory and are dropped as soon as the query resolves.

Data tables

smw_object_ids

The central entity registry. Every wiki page, property, and subobject that SMW tracks receives an integer ID (smw_id) stored here. All other SMW tables reference this table via foreign keys. Key fields:
FieldDescription
smw_idAuto-increment primary key used as the foreign key across all other SMW tables
smw_titlePage title in DBkey format
smw_namespaceMediaWiki namespace integer
smw_iwInterwiki prefix (empty for local pages)
smw_subobjectSubobject name (empty for main page subjects)
smw_sortkeySort key used for ordering
smw_proptable_hashHash of the property tables used by this entity
Tracks embedded query dependencies. When a page contains an #ask query, the pages that the query result depends on are recorded here so that SMW can invalidate cached results when those pages change.

smw_prop_stats

Aggregates property usage statistics (count of value assignments per property). Used by Special:Properties and the statistics API. Contains full-text indexable text components when full-text search is enabled. Populated from DIBlob and DIUri values to support unstructured text search alongside structured queries.

smw_conc (concept cache)

Caches the results of SMW concept queries ([[Category:...]] defined via #concept). Concept results are pre-computed and stored here to avoid re-running expensive queries on every page load.

Common property tables (smw_di_*)

One table exists for each DataItem type. User-defined properties with the corresponding datatype store their values in the matching table.
[
    DataItem::TYPE_NUMBER    => 'smw_di_number',
    DataItem::TYPE_BLOB      => 'smw_di_blob',
    DataItem::TYPE_BOOLEAN   => 'smw_di_bool',
    DataItem::TYPE_URI       => 'smw_di_uri',
    DataItem::TYPE_TIME      => 'smw_di_time',
    DataItem::TYPE_GEO       => 'smw_di_coords',
    DataItem::TYPE_CONTAINER => 'smw_di_container',
    DataItem::TYPE_WIKIPAGE  => 'smw_di_wikipage',
    DataItem::TYPE_CONCEPT   => 'smw_conc',
]
All common property tables share the following field layout:
FieldDescription
s_idSubject ID — foreign key into smw_object_ids.smw_id
p_idProperty ID — foreign key into smw_object_ids.smw_id
o_*One or more object fields specific to the DataItem type
Example — smw_di_number:
CREATE TABLE smw_di_number (
    s_id  INT(8) UNSIGNED NOT NULL,
    p_id  INT(8) UNSIGNED NOT NULL,
    o_serialized VARCHAR(255) NOT NULL,  -- string form of the number
    o_sortkey    DOUBLE NOT NULL          -- floating-point value for range queries
);

Fixed property tables (smw_fpt_*)

Fixed property tables are dedicated to a single predefined property (e.g. _MDAT for modification date, _INST for category membership). Because the property is implicit, p_id is omitted, making lookups faster. Fixed table assignments come from two sources:
  • TypesRegistry.php — defines fixed tables for all built-in predefined properties.
  • $smwgFixedProperties — a configuration setting that lets administrators designate user-defined properties as fixed for performance reasons.
Field layout:
FieldDescription
s_idSubject ID — foreign key into smw_object_ids.smw_id
o_*Object fields specific to the property’s DataItem type

Viewing the schema

Navigate to Special:SemanticMediaWiki on any SMW wiki to inspect the current installation status and table configuration. The Settings tab lists all active property tables and their assignments.

Schema modification guidelines

1

Define changes in TableSchemaManager

All schema changes must be made through the TableSchemaManager class. Never issue raw ALTER TABLE or CREATE TABLE SQL outside the SMW schema management layer.
2

Support upgrades from existing installations

Store::setup() is called on both fresh installs and upgrades. Schema changes must be written so that TableBuilder can detect and apply them incrementally without data loss.
3

Never touch MediaWiki tables

SMW must not add columns to, drop columns from, or create indexes on any MediaWiki core table (e.g. page, revision, categorylinks). All SMW data lives in SMW’s own tables.
4

Document the change

Add a note to docs/RELEASE-NOTES.md and, for significant changes, to the changing the table schema guide.
5

Run the setup command after changes

Apply schema changes to a development wiki by running:
php maintenance/update.php
Or use the SMW-specific maintenance script:
php extensions/SemanticMediaWiki/maintenance/setupStore.php

Build docs developers (and LLMs) love