Source:
<code>public Set<MetricNameDto> getCustomMetricsNamesOldModel(List<TaskDataDto> tests) { Set<Long> taskIds = new HashSet<Long>(); Set<String> sessionIds = new HashSet<String>(); for (TaskDataDto tdd : tests) { taskIds.addAll(tdd.getIds()); sessionIds.addAll(tdd.getSessionIds()); } long temp = System.currentTimeMillis(); List<Object[]> metricNames = entityManager.createNativeQuery( "select dre.name, selected.id from DiagnosticResultEntity dre join " + " (" + " select wd.workloaddataID, td.id from " + " (" + <START> " select distinct wd.id as workloaddataID, wd.sessionId, wd.taskId from WorkloadData wd where wd.sessionId in (:sessionIds)" + <END> " ) as wd join " + " ( " + " select td.taskId, td.sessionId, td.id from TaskData td where td.id in (:taskIds)" + " ) as td on wd.taskId=td.taskId and wd.sessionId=td.sessionId" + " ) as selected on dre.workloadData_id=selected.workloaddataID") .setParameter("taskIds", taskIds) .setParameter("sessionIds", sessionIds) .getResultList(); if (metricNames.isEmpty()) { return Collections.EMPTY_SET; } Set<MetricNameDto> metrics = new HashSet<MetricNameDto>(metricNames.size()); log.debug("{} ms spent for fetching custom metrics", System.currentTimeMillis() - temp, metricNames.size()); for (Object[] name : metricNames){ if (name == null || name[0] == null) continue; for (TaskDataDto td : tests) { if (td.getIds().contains(((BigInteger)name[1]).longValue())) { MetricNameDto metric = new MetricNameDto(); metric.setTest(td); metric.setMetricName((String) name[0]); metric.setOrigin(MetricNameDto.Origin.METRIC); metrics.add(metric); break; } } } return metrics; }</code><technical_language>remove distinct</technical_language>

Target:
public Set<MetricNameDto> getCustomMetricsNamesOldModel(List<TaskDataDto> tests) { Set<Long> taskIds = new HashSet<Long>(); Set<String> sessionIds = new HashSet<String>(); for (TaskDataDto tdd : tests) { taskIds.addAll(tdd.getIds()); sessionIds.addAll(tdd.getSessionIds()); } long temp = System.currentTimeMillis(); List<Object[]> metricNames = entityManager.createNativeQuery( "select dre.name, selected.id from DiagnosticResultEntity dre join " + " (" + " select wd.workloaddataID, td.id from " + " (" + " select wd.id as workloaddataID, wd.sessionId, wd.taskId from WorkloadData wd where wd.sessionId in (:sessionIds)" + " ) as wd join " + " ( " + " select td.taskId, td.sessionId, td.id from TaskData td where td.id in (:taskIds)" + " ) as td on wd.taskId=td.taskId and wd.sessionId=td.sessionId" + " ) as selected on dre.workloadData_id=selected.workloaddataID") .setParameter("taskIds", taskIds) .setParameter("sessionIds", sessionIds) .getResultList(); if (metricNames.isEmpty()) { return Collections.EMPTY_SET; } Set<MetricNameDto> metrics = new HashSet<MetricNameDto>(metricNames.size()); log.debug("{} ms spent for fetching custom metrics", System.currentTimeMillis() - temp, metricNames.size()); for (Object[] name : metricNames){ if (name == null || name[0] == null) continue; for (TaskDataDto td : tests) { if (td.getIds().contains(((BigInteger)name[1]).longValue())) { MetricNameDto metric = new MetricNameDto(); metric.setTest(td); metric.setMetricName((String) name[0]); metric.setOrigin(MetricNameDto.Origin.METRIC); metrics.add(metric); break; } } } return metrics; }