Source:
<code>protected UnifyResult apply(UnifyRuleCall call) { final MutableSort query = (MutableSort) call.query; final MutableSort target = (MutableSort) call.target; final MutableProject queryProject = (MutableProject) query.getInput(); final MutableProject targetProject = (MutableProject) target.getInput(); <START> if (!queryProject.getInput().equals(targetProject.getInput())) { <END> return null; } if (query.fetch != null || query.offset != null || target.fetch != null || target.offset != null) { return null; } Mappings.TargetMapping queryProjectMapping = queryProject.getMapping(); Mappings.TargetMapping targetProjectMapping = targetProject.getMapping(); if (queryProjectMapping == null || targetProjectMapping == null) { return null; } final int queryFieldCount = query.rowType.getFieldCount(); final int targetFieldCount = target.rowType.getFieldCount(); Mappings.TargetMapping mapping = Mappings.create( MappingType.FUNCTION, queryFieldCount, targetFieldCount); List<Integer> posList = new ArrayList<>(); for (int ordinal = 0; ordinal < queryFieldCount; ordinal++) { int inputOrdinal = queryProjectMapping.getSourceOpt(ordinal); assert inputOrdinal >= 0; int targetOrdinal = targetProjectMapping.getTargetOpt(inputOrdinal); if (targetOrdinal < 0) { return null; } mapping.set(ordinal, targetOrdinal); posList.add(targetOrdinal); } RelCollation collation = RelCollations.permute(query.collation, mapping); if (!target.collation.satisfies(collation)) { return null; } MutableRel result = MutableRels.createProject(target, posList); return call.result(result); }</code><technical_language>Instead of equals, compare input's digest</technical_language>

Target:
protected UnifyResult apply(UnifyRuleCall call) { final MutableSort query = (MutableSort) call.query; final MutableSort target = (MutableSort) call.target; final MutableProject queryProject = (MutableProject) query.getInput(); final MutableProject targetProject = (MutableProject) target.getInput(); if (!queryProject.getInput().equals(targetProject.getInput())) { return null; } if (!Objects.equals(query.fetch, target.fetch) || !Objects.equals(query.offset, target.offset)) { return null; } Mappings.TargetMapping queryProjectMapping = queryProject.getMapping(); Mappings.TargetMapping targetProjectMapping = targetProject.getMapping(); if (queryProjectMapping == null || targetProjectMapping == null) { return null; } final int queryFieldCount = query.rowType.getFieldCount(); final int targetFieldCount = target.rowType.getFieldCount(); Mappings.TargetMapping mapping = Mappings.create( MappingType.FUNCTION, queryFieldCount, targetFieldCount); List<Integer> posList = new ArrayList<>(); for (int ordinal = 0; ordinal < queryFieldCount; ordinal++) { int inputOrdinal = queryProjectMapping.getSourceOpt(ordinal); assert inputOrdinal >= 0; int targetOrdinal = targetProjectMapping.getTargetOpt(inputOrdinal); if (targetOrdinal < 0) { return null; } mapping.set(ordinal, targetOrdinal); posList.add(targetOrdinal); } RelCollation collation = RelCollations.permute(query.collation, mapping); if (!target.collation.satisfies(collation)) { return null; } MutableRel result = MutableRels.createProject(target, posList); return call.result(result); }