Change order of rules to reduce number of queries