Because I felt the badges having these optimizations are essential if you have a lot of badges, I'll paste the optimizations I felt were useful to me while creating the 6.x update. Someone who knows how to create indexes in pgsql would be of help here ^_^:
function user_badges_install() {
$ret = array();
$ret[] = db_query("CREATE TABLE {user_badges_badges} (
bid int(10) NOT NULL default '0',
name varchar(50) NOT NULL default '',
image varchar(80) NOT NULL default '',
weight int(2) NOT NULL default '0',
PRIMARY KEY (bid),
KEY bid_weight_name(bid, weight, name),
KEY weight_name(weight, name)
) /*!40100 DEFAULT CHARACTER SET utf8 */;");
$ret[] = db_query("CREATE TABLE {user_badges_product} (
bid int(10) NOT NULL default '0',
nid int(10) NOT NULL default '0'
PRIMARY KEY (bid, nid),
) /*!40100 DEFAULT CHARACTER SET utf8 */;");
$ret[] = db_query("CREATE TABLE {user_badges_roles} (
rid int(10) NOT NULL default '0',
bid int(10) NOT NULL default '0'
PRIMARY KEY (bid, rid),
) /*!40100 DEFAULT CHARACTER SET utf8 */;");
$ret[] = db_query("CREATE TABLE {user_badges_user} (
uid int(10) NOT NULL default '0',
bid int(10) NOT NULL default '0',
type varchar(20) NOT NULL default ''
PRIMARY KEY (bid, uid),
KEY type(type),
) /*!40100 DEFAULT CHARACTER SET utf8 */;");
return $ret;
}
function user_badges_update_1() {
$ret = array();
update_convert_table_utf8('user_badges_badges');
update_convert_table_utf8('user_badges_product');
update_convert_table_utf8('user_badges_roles');
update_convert_table_utf8('user_badges_user');
$ret[] = update_query("ALTER TABLE {user_badges_badges} ADD PRIMARY KEY(bid), ADD INDEX bid_weight_name (bid, weight, name), ADD INDEX weight_name (weight, name)");
$ret[] = update_query("ALTER TABLE {user_badges_product} ADD PRIMARY KEY (bid, nid)");
$ret[] = update_query("ALTER TABLE {user_badges_roles} ADD PRIMARY KEY (bid, rid)");
$ret[] = update_query("ALTER TABLE {user_badges_user} ADD PRIMARY KEY(bid, uid), ADD INDEX type (type)");
return $ret;
}
Note the tables are also converted to utf8 (basically applies to user_badges_badges and user_badges_user but ran through all in case of future updates).
Comments
Comment #1
btmash commentedBecause I felt the badges having these optimizations are essential if you have a lot of badges, I'll paste the optimizations I felt were useful to me while creating the 6.x update. Someone who knows how to create indexes in pgsql would be of help here ^_^:
Note the tables are also converted to utf8 (basically applies to user_badges_badges and user_badges_user but ran through all in case of future updates).
Comment #2
btmash commentedI added some more keys (though to the 6.x version - I'll post the schema so it can be seen clearly.
Comment #3
nunoveloso commented