TableSchemaManager and TableBuilder, which handle table creation, upgrades, and removal.
SPO pattern
Most SMW tables follow a subject-predicate-object (SPO) pattern. Table fields are named with prefixes that reflect their role:| Prefix | Role |
|---|---|
s_ | Subject (the page being annotated) |
p_ | Predicate (the property) |
o_ | Object (the value) |
Table types
SMW uses three categories of tables:| Category | Naming pattern | Description |
|---|---|---|
| Data tables | smw_* (various) | General-purpose tables that do not follow the SPO pattern: IDs, statistics, dependencies. |
| Common property tables | smw_di_* | SPO tables for user-defined properties with an assigned datatype. Include both p_id and s_id. |
| Fixed property tables | smw_fpt_* | SPO tables dedicated to one specific property. Omit p_id since the property is implicit. |
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:
| Field | Description |
|---|---|
smw_id | Auto-increment primary key used as the foreign key across all other SMW tables |
smw_title | Page title in DBkey format |
smw_namespace | MediaWiki namespace integer |
smw_iw | Interwiki prefix (empty for local pages) |
smw_subobject | Subobject name (empty for main page subjects) |
smw_sortkey | Sort key used for ordering |
smw_proptable_hash | Hash of the property tables used by this entity |
smw_query_links
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 bySpecial:Properties and the statistics API.
smw_ft_search
Contains full-text indexable text components when full-text search is enabled. Populated fromDIBlob 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 eachDataItem type. User-defined properties with the corresponding datatype store their values in the matching table.
| Field | Description |
|---|---|
s_id | Subject ID — foreign key into smw_object_ids.smw_id |
p_id | Property ID — foreign key into smw_object_ids.smw_id |
o_* | One or more object fields specific to the DataItem type |
smw_di_number:
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 | Description |
|---|---|
s_id | Subject ID — foreign key into smw_object_ids.smw_id |
o_* | Object fields specific to the property’s DataItem type |
Viewing the schema
Navigate toSpecial: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
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.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.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.Document the change
Add a note to
docs/RELEASE-NOTES.md and, for significant changes, to the changing the table schema guide.