Jonathan Walther wrote:
CREATE TABLE archive (
ar_namespace tinyint(2) unsigned NOT NULL default '0',
ar_title varchar(255) binary NOT NULL default '',
ar_text mediumtext NOT NULL,
ar_comment tinyblob NOT NULL,
ar_user int(5) unsigned NOT NULL default '0',
ar_user_text varchar(255) binary NOT NULL default '',
ar_timestamp varchar(14) binary NOT NULL default '',
ar_minor_edit tinyint(1) NOT NULL default '0',
ar_flags tinyblob NOT NULL
) TYPE=MyISAM PACK_KEYS=1;
1) What is the "archive" table for? Is that where articles are stored?
That's where "deleted" articles are stored, so they can be
"undeleted".
That table will have to be flushed from time to time in the future.
The current articles are in the "cur" table, the old revisions in
"old".
2) Why is there a separate ar_user_text property? Is
it because MySQL
doesn't support subqueries?
3) What is ar_flags used for? And why is it a tinyblob?
I'm not sure myself about these, as I didn't really work with that table
before. "tinyblob" is the same as "tinytext", but with case-sensitive
search (basically).
4) Could we save a lot of disk space by replacing
ar_title with
article_id, and having all the article titles and their corresponding
ids in a separate table?
No.
CREATE TABLE brokenlinks (
bl_from int(8) unsigned NOT NULL default '0',
bl_to varchar(255) binary NOT NULL default '',
KEY bl_from (bl_from),
KEY bl_to (bl_to(10))
) TYPE=MyISAM;
5) Why is a broken link table necessary? Couldn't it be sufficient to
do a query to find out which links are broken? Or is this another "we
have no subqueries" issue?
It is very useful for the "most wanted" page, among other things.
6) I notice bl_from is an integer, while bl_to is a
string; why the
difference? I thought articles didn't have identifying id numbers; if
so, what is bl_from then?
Say, article A links to non-existing article B. bl_from is the cur_id of
A, and bl_to is the name of the non-existent article B.
CREATE TABLE 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,
cur_comment tinyblob NOT NULL,
cur_user int(5) unsigned NOT NULL default '0',
cur_user_text varchar(255) binary NOT NULL default '',
cur_timestamp varchar(14) binary NOT NULL default '',
cur_restrictions tinyblob NOT NULL,
cur_counter bigint(20) unsigned NOT NULL default '0',
cur_ind_title varchar(255) NOT NULL default '',
cur_ind_text mediumtext NOT NULL,
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',
UNIQUE KEY cur_id (cur_id),
KEY cur_namespace (cur_namespace),
KEY cur_title (cur_title(20)),
KEY cur_timestamp (cur_timestamp),
FULLTEXT KEY cur_ind_title (cur_ind_title),
FULLTEXT KEY cur_ind_text (cur_ind_text)
) TYPE=MyISAM PACK_KEYS=1;
7) What is the table cur for? I find myself understanding nothing about
it; I even looked at the 3 default entries that are inserted, and they
didn't clue me in.
Current article versions.
CREATE TABLE image (
img_name varchar(255) binary NOT NULL default '',
img_size int(8) unsigned NOT NULL default '0',
img_description tinyblob NOT NULL,
img_user int(5) unsigned NOT NULL default '0',
img_user_text varchar(255) binary NOT NULL default '',
img_timestamp varchar(14) binary NOT NULL default '',
KEY img_name (img_name(10)),
KEY img_size (img_size),
KEY img_timestamp (img_timestamp)
) TYPE=MyISAM PACK_KEYS=1;
8) Is img_user_text present for the "MySQL has no subquery
functionality" reason?
That table is Lee's invention. img_user_text contains thename of the
user who uploaded it.
9) What format are timestamps in?
UNIX, I think.
10) Is there special PHP code that ensures an image
with the same name,
but differing descriptions or img_user properties are present in the
table? Does MySQL not have the "UNIQUE" keyword which could eliminate
all need for that code, or is it wanted to have a record of all changes
to the description of an image? If so, I would recommend a slightly
different solution, similar to that for the articles table.
I'm not sure I understand that question. If there's an image "A", and
you upload a new image "A", you'll do the same as saving a new version
of an article.
CREATE TABLE imagelinks (
il_from varchar(255) binary NOT NULL default '',
il_to varchar(255) binary NOT NULL default '',
KEY il_from (il_from(10)),
KEY il_to (il_to(10))
) TYPE=MyISAM;
11) Surely we could save space by using integer article ids?
I guess so. But, the totally saved space would probably be less than a
single "old" revision of a long article. Not worth the bother, I'd say.
CREATE TABLE ipblocks (
ipb_address varchar(40) binary NOT NULL default '',
ipb_user int(8) unsigned NOT NULL default '0',
ipb_by int(8) unsigned NOT NULL default '0',
ipb_reason tinyblob NOT NULL,
ipb_timestamp varchar(14) binary NOT NULL default '',
KEY ipb_address (ipb_address),
KEY ipb_user (ipb_user)
) TYPE=MyISAM PACK_KEYS=1;
12) No questions, but why is the KEY keyword used? Is this a MySQL
trigger for making indexes? Also, theres a bunch of things that could
use the UNIQUE keyword to save php code.
You're probably right on both.
CREATE TABLE links (
l_from varchar(255) binary NOT NULL default '',
l_to int(8) unsigned NOT NULL default '0',
KEY l_from (l_from(10)),
KEY l_to (l_to)
) TYPE=MyISAM;
13) Similar to the question about the orphanedlinks table, why is l_from
a string, while l_to is an integer?
I think l_from could be an integer as well. Would probably increase
lookup speed, and save memory. Some things might get more complicated,
though, like "what links here".
CREATE TABLE old (
old_id int(8) unsigned NOT NULL auto_increment,
old_namespace tinyint(2) unsigned NOT NULL default '0',
old_title varchar(255) binary NOT NULL default '',
old_text mediumtext NOT NULL,
old_comment tinyblob NOT NULL,
old_user int(5) unsigned NOT NULL default '0',
old_user_text varchar(255) binary NOT NULL default '',
old_timestamp varchar(14) binary NOT NULL default '',
old_minor_edit tinyint(1) NOT NULL default '0',
old_flags tinyblob NOT NULL,
UNIQUE KEY old_id (old_id),
KEY old_title (old_title(20)),
KEY old_timestamp (old_timestamp)
) TYPE=MyISAM PACK_KEYS=1;
14) What is table "old" used for? Deleted articles? Versions of
articles that are no longer "the most current"?
The latter. Deleted articles go into "archive".
CREATE TABLE oldimage (
oi_name varchar(255) binary NOT NULL default '',
oi_archive_name varchar(255) binary NOT NULL default '',
oi_size int(8) unsigned NOT NULL default '0',
oi_description tinyblob NOT NULL,
oi_user int(5) unsigned NOT NULL default '0',
oi_user_text varchar(255) binary NOT NULL default '',
oi_timestamp varchar(14) binary NOT NULL default '',
KEY oi_name (oi_name(10))
) TYPE=MyISAM PACK_KEYS=1;
15) So, history IS stored for each image? Then I recommend the scheme
of having a separate table for unique image names, and their
corresponding "image id"
That's what "Image" does...
CREATE TABLE random (
ra_current tinyint(1) unsigned NOT NULL default '0',
ra_title varchar(255) binary NOT NULL default ''
) TYPE=MyISAM PACK_KEYS=1;
16) What is this "random" table for?
You got me there. Could be a relict. Lee once tried some stunts to get a
faster "random page". If that's where it comes from, it's obsolete now.
CREATE TABLE recentchanges (
rc_timestamp varchar(14) binary NOT NULL default '',
rc_cur_time varchar(14) binary NOT NULL default '',
rc_user int(10) unsigned NOT NULL default '0',
rc_user_text varchar(255) binary NOT NULL default '',
rc_namespace tinyint(3) unsigned NOT NULL default '0',
rc_title varchar(255) binary NOT NULL default '',
rc_comment varchar(255) binary NOT NULL default '',
rc_minor tinyint(3) unsigned NOT NULL default '0',
rc_new tinyint(3) unsigned NOT NULL default '0',
rc_cur_id int(10) unsigned NOT NULL default '0',
rc_this_oldid int(10) unsigned NOT NULL default '0',
rc_last_oldid int(10) unsigned NOT NULL default '0'
) TYPE=MyISAM PACK_KEYS=1;
17) Could the recent changes table be replaced with an appropriately
defined "view"? Or are views something MySQL doesn't do very well?
That table is pretty new. I think Lee's still working on it, probably
Brion as well.
CREATE TABLE site_stats (
ss_row_id int(8) unsigned NOT NULL default '0',
ss_total_views bigint(20) unsigned default '0',
ss_total_edits bigint(20) unsigned default '0',
ss_good_articles bigint(20) unsigned default '0',
UNIQUE KEY ss_row_id (ss_row_id)
) TYPE=MyISAM;
18) What is ss_row_id and ss_good_articles? How does this table work?
Does it contain stats for each article? Shouldn't that go in the table
that already contains the info for an article? That would lessen the
number of SQL updates, collapsing two UPDATE statements into one.
That's where the "overall statistics" are parked. ss_good_articles is
the number of articles you see on the Main Page.
CREATE TABLE user (
user_id int(5) unsigned NOT NULL auto_increment,
user_name varchar(255) binary NOT NULL default '',
user_rights tinyblob NOT NULL,
user_password tinyblob NOT NULL,
user_newpassword tinyblob NOT NULL,
user_email tinytext NOT NULL,
user_options blob NOT NULL,
user_watch mediumblob NOT NULL,
user_newtalk tinyint(1) unsigned NOT NULL default '1',
UNIQUE KEY user_id (user_id),
KEY user_name (user_name(10))
) TYPE=MyISAM PACK_KEYS=1;
19) Does user_rights correspond to ar_flags?
May be. I'm not that familiar with the archive table.
20) What is "newpassword" for?
When you let the system mail you a new password, you can log in with
both the old and the new one, until you use the new one, which then
becomes the "standard".
21) Are all the "options" really necessary?
Yes!
22) It might be the SQL way to make a
"watchlist" table, where each row
contains a user id, and an article id. Or maybe this would be useless
in a database that doesn't have subqueries.
You're right on this one. Guess noone really paid attention to that
before...
23) What is the user_newtalk field?
When your talk page was edited, that flag is set, so it displays a "*"
next to your talk link when you're logged in.
Hope that helps,
Magnus