The context_rel table is a caching table built to allow the big SQL in load_user_capability() to be able to identify the pair of contexts that are related easily, (e.g. parent/child or grandparent/child), where you have an override at a lower context level, and an assignment at the higher context level.
The current issue we have is that the number of entries in context_rel table is normally a few times larger than the context table. Working with such a large table takes quite a bit of space and can potentially cause load_user_capability() to run slower.
However, there is no point (IMHO) to store the pair of contexts in the context_rel table if
1) There is no role assignment at the higher context OR
2) There is no role override in the lower context
Currently the context_rel table is populated whenever a new context is inserted. Given that the number of contexts with any overrides is much less than the number of contexts in which we have a direct role assignment, I propose we make the following changes
1) Do not populate the context_rel table upon context creation.
2) Populate the context_rel table whenever an override is added.
3) Take out entries from context_rel if the last override is removed.
4) build_context_rel() should loop all context and only populate contexts with overrides when users upgrades. (current, for users from 1.7 and below)
5) In 1.9, drop the context_rel table and call build_context_rel().