1. A method for optimizing a query in a database system, the method comprising: generating a database statistic for a number of related records for one or more entities for at least one tenant, wherein a related record comprises a record with a relationship to a shared record in a database table for an entity from the one or more entities; calculating a first cost for accessing the number of related records for at least one tenant; calculating a second cost for accessing a number of related records accessible to a user; performing a comparison of the first cost to the second cost to determine a data access path for retrieving accessible related records; and determining the data access path for retrieving accessible related records based upon the comparison.