remove unnecessary materialization of intermediate result set