Jump to content

Sample MySQL syntax for creating the 'cur' table

From Meta, a Wikimedia project coordination wiki

From maintenance/tables.sql:

CREATE TABLE /*$wgDBprefix*/cur (
  cur_id int(8) unsigned NOT NULL auto_increment,
  cur_namespace tinyint(2) unsigned NOT NULL default '0',
  cur_title varchar(255) binary NOT NULL default '',
  cur_text mediumtext NOT NULL default '',
  cur_comment tinyblob NOT NULL default '',
  cur_user int(5) unsigned NOT NULL default '0',
  cur_user_text varchar(255) binary NOT NULL default '',
  cur_timestamp char(14) binary NOT NULL default '',
  cur_restrictions tinyblob NOT NULL default '',
  cur_counter bigint(20) unsigned NOT NULL default '0',
  cur_is_redirect tinyint(1) unsigned NOT NULL default '0',
  cur_minor_edit tinyint(1) unsigned NOT NULL default '0',
  cur_is_new tinyint(1) unsigned NOT NULL default '0',
  cur_random real unsigned NOT NULL,
  cur_touched char(14) binary NOT NULL default '',
  inverse_timestamp char(14) binary NOT NULL default '',
  PRIMARY KEY cur_id (cur_id),
  UNIQUE INDEX name_title (cur_namespace,cur_title),
  
  -- Is this one necessary?
  INDEX cur_title (cur_title(20)),
  
  INDEX cur_timestamp (cur_timestamp),
  INDEX (cur_random),
  INDEX name_title_timestamp (cur_namespace,cur_title,inverse_timestamp),
  INDEX user_timestamp (cur_user,inverse_timestamp),
  INDEX usertext_timestamp (cur_user_text,inverse_timestamp),
  INDEX namespace_redirect_timestamp(cur_namespace,cur_is_redirect,cur_timestamp),
  INDEX id_title_ns_red (cur_id,cur_title,cur_namespace,Cur_is_redirect)
);

Worked for me:

CREATE TABLE cur ( cur_id int(8) unsigned PRIMARY KEY auto_increment, 
cur_namespace tinyint(2) unsigned DEFAULT 0,
cur_title varchar(255) binary,
cur_text mediumtext,
cur_comment tinyblob,
cur_user int(5) unsigned DEFAULT 0,
cur_user_text varchar(255) binary DEFAULT 0,
cur_timestamp varchar(14) binary,
cur_restrictions tinyblob,
cur_counter bigint(20) unsigned DEFAULT 0,
cur_is_redirect tinyint(1) unsigned DEFAULT 0,
cur_minor_edit tinyint(1) unsigned DEFAULT 0,
cur_is_new tinyint(1) unsigned DEFAULT 0,
cur_random double unsigned DEFAULT 0,
inverse_timestamp varchar(14) binary,
cur_touched varchar(14) binary);
ALTER TABLE cur ADD INDEX wiki_index0 (cur_namespace);
ALTER TABLE cur ADD INDEX wiki_index1 (cur_title);
ALTER TABLE cur ADD INDEX wiki_index2 (cur_user);
ALTER TABLE cur ADD INDEX wiki_index3 (cur_user_text);
ALTER TABLE cur ADD INDEX wiki_index4 (cur_timestamp);
ALTER TABLE cur ADD INDEX wiki_index5 (cur_random);