added more SQL, now building base tables informed by _index contents