I'm pretty new to Drupal and am trying to get a handle on how the database works. I've been going through the latest system.install file in the system folder.
I see that the node table has a PRIMARY KEY comprised of both nid and vid. I see that nid is auto_incremented by node and so is generated when a row is added. Based on the code in node.module, it looks like node's vid comes from node_revisions. But although node_revisions has both vid and nid, only vid makes up the PRIMARY KEY, and it seems to come from somewhere else.
My questions are:
1) Where does vid ultimately originate and which tables use it?
2) Why isn't node_revisions' PRIMARY KEY also a combination of vid and nid? Isn't each row of node_revisions only associated with one node (nid)?
3) Is a unique node (ex. nid=22) actually a collection of nodes+revisions (ex. nid+vid=22+3, 22+2, 22+1)? Wait a minute - I just checked my database. It looks like for a particular node, that revisions start at that node's number. Is that right? What is the advantage of this? So my previous example would be 22+22, 22+23, 22+24... Nope. I guess vid is a running number which is really the total number of revisions on the site.
4) Are table column names reused where they actually don't mean the same thing? Ex. cid = comment id & cid = contact id??? Ex2. vid = reVision id & vid = vocabulary id??? That doesn't seem like a good idea. Especially since the DB isn't set up relationally (with foreign keys).