Actually, I may have found something. A row is added to mdl_context for each user as the user is created, like so:
id: 23
contextlevel: 30
instanceid: 25
path: /1/23
depth: 2
So the "path" for the context of a specific user is always /1/[mdl_context.id], yes?
And so when a user is given a role relative to another user, the user assigned that role (the "parent" in my case) is assigned the role (in mdl_role_assignments), the contextid in that row refers to the mdl_context.id of the other user (the "student" in my case).
Is that it? Am I overlooking anything?