Fix relation change serialization, SQL optimizations