Efficient and scalable techniques for minimization and rewriting of conjunctive queries