replace minimal queries with sql-based queries.
determine heterogeneous children with sql.