Builds a query graph, partitions it and generates a dictionary and lookup table.