> My question is: when a user submits a new comment, how does the new
> "cid" get computed?  Do you go through all the existing comments to
> determine the highest cid, and then add 1, or is the value cached
> somewhere?  (Neither the code nor the SQL tables are well documented, so
> it's hard to figure this out).

Most databases have an AUTO_INCREMENT function, so I imagine that in the
table definition, the sql definition of the cid is probably something like

cid INT NOT NULL AUTO_INCREMENT

the AUTO_INCREMENT is what increases the counter.  It is up to the
database software to track the counters (not sure how that is done)

>
> (If possible, point me to the appropriate file/linenumber where this
> action takes place).
>

It is in the definition of the table in the database