in reply to dbic multiple joins

Since disk space is relatively cheap, maybe the best way to solve these "multi-level marketing" type problems is to construct a fully-exploded mapping, e.g. in a separate table. Presumably the memberships don't change that often, whereas lookups happen constantly and time is of the essence. Trade space for time. Do the work ahead of time so that you can always get the answer with one query.