Fix plan query