improve selecting shared mailboxes

Previous sql do full scan mailboxes table. This is very expensive.

I'm not cpp developer, but know something about sql.