initial steps for composite queries

NO NOT MERGE. Comments welcome.