Query planner should factor out common table expressions within queries so they are only executed once. See https://community.jboss.org/message/742355 for more context.