db design for query system