Add tabled 'ancestoro logic.

This is slower than I'd like but tabling keeps the no-ancestor-found
case from taking eternity when run against the large test database.