Wiki source code of Optional MySQL Indexes

Last modified by Eleni Cojocariu on 2026/11/25 14:49

Show last authors
1 Each statement below indexes a column that XWiki reads but that its Hibernate mappings leave unindexed. The list is a menu rather than a checklist: measure the query that is slow, then add the one index that serves it. Create them as the wiki's own database user, and once per database, since XWiki gives every subwiki a database of its own.
2
3 === General indexes ===
4
5 |=Index|=Table and column|=What reads it
6 |##xwl_value##|##xwikilargestrings (xwl_value(50))##|The value of every Large String and TextArea object property. XWiki groups over this column when a Database List field offers the values already in use, and matches it with {{code language="none"}}like{{/code}} in the REST keyword search.
7 |##xwd_parent##|##xwikidoc (xwd_parent(50))##|The queries that list the children or the orphans of a page test it for equality.
8 |##xwd_class_xml##|##xwikidoc (xwd_class_xml(20))##|Listing the XClasses of a wiki tests this column for an XML prefix.
9 |##xda_docid1##|##xwikiattrecyclebin (xda_docid)##|Every listing of a page's deleted attachments filters on it, while its neighbours ##xda_filename##, ##xda_date## and ##xda_doc_name## are indexed by the mapping.
10 |##solr_iterate_all_documents##|##xwikidoc (XWD_WEB(500), XWD_NAME(253), XWD_LANGUAGE(5), XWD_VERSION(10))##|To work out which pages the Solr index is missing, XWiki walks the whole ##xwikidoc## table reading exactly these columns.
11
12 {{code language="sql"}}
13 create index xwl_value on xwikilargestrings (xwl_value(50));
14 create index xwd_parent on xwikidoc (xwd_parent(50));
15 create index xwd_class_xml on xwikidoc (xwd_class_xml(20));
16 create index xda_docid1 on xwikiattrecyclebin (xda_docid);
17 create index solr_iterate_all_documents on xwikidoc (XWD_WEB(500), XWD_NAME(253), XWD_LANGUAGE(5), XWD_VERSION(10));
18 {{/code}}
19
20 === Statistics indexes ===
21
22 XWiki's statistics module stores page views, referers and visits in three tables of its own, and storing them is switched off unless a wiki asks for it: the shipped ##xwiki.cfg## sets ##xwiki.stats.default=0##, because statistics cost space and write time. These nine indexes are therefore worth considering only on an instance that turned statistics on, and only once those three tables have grown.
23
24 |=Index|=Table and column
25 |##xws_number##|##xwikistatsdoc (XWS_NUMBER)##
26 |##xws_classname##|##xwikistatsdoc (XWS_CLASSNAME)##
27 |##xwr_number##|##xwikistatsreferer (XWR_NUMBER)##
28 |##xwr_classname##|##xwikistatsreferer (XWR_CLASSNAME)##
29 |##xwr_referer##|##xwikistatsreferer (XWR_REFERER(50))##
30 |##xwv_user_agent##|##xwikistatsvisit (XWV_USER_AGENT(255))##
31 |##xwv_cookie##|##xwikistatsvisit (XWV_COOKIE(255))##
32 |##xwv_classname##|##xwikistatsvisit (XWV_CLASSNAME)##
33 |##xwv_number##|##xwikistatsvisit (XWV_NUMBER)##
34
35 {{code language="sql"}}
36 create index xws_number on xwikistatsdoc (XWS_NUMBER);
37 create index xws_classname on xwikistatsdoc (XWS_CLASSNAME);
38 create index xwr_number on xwikistatsreferer (XWR_NUMBER);
39 create index xwr_classname on xwikistatsreferer (XWR_CLASSNAME);
40 create index xwr_referer on xwikistatsreferer (XWR_REFERER(50));
41 create index xwv_user_agent on xwikistatsvisit (XWV_USER_AGENT(255));
42 create index xwv_cookie on xwikistatsvisit (XWV_COOKIE(255));
43 create index xwv_classname on xwikistatsvisit (XWV_CLASSNAME);
44 create index xwv_number on xwikistatsvisit (XWV_NUMBER);
45 {{/code}}

Get Connected