private SelectionSummary getReprocessSelectionSummary(final Collection<Condition> conditions,
                                                          final int offset,
                                                          final int numberOfRows,
                                                          final Set<Integer> usedValKeys) {
        return JooqUtil.contextResult(metaDbConnProvider, context ->
                        metaExpressionMapper.addJoins(context
                                                .select(
                                                        DSL.countDistinct(parent.ID),
                                                        DSL.countDistinct(parent.FEED_ID),
                                                        DSL.groupConcatDistinct(parentFeed.NAME)
                                                                .separator(GROUP_CONCAT_DELIMITER),
                                                        DSL.countDistinct(parent.TYPE_ID),
                                                        DSL.groupConcatDistinct(parentType.NAME)
                                                                .separator(GROUP_CONCAT_DELIMITER),
                                                        DSL.countDistinct(meta.PROCESSOR_ID),
                                                        DSL.countDistinct(metaProcessor.PIPELINE_UUID),
                                                        DSL.countDistinct(parent.STATUS),
                                                        DSL.groupConcatDistinct(parent.STATUS)
                                                                .separator(GROUP_CONCAT_DELIMITER),
                                                        DSL.min(parent.CREATE_TIME),
                                                        DSL.max(parent.CREATE_TIME)
                                                )
                                                .from(meta)
                                                .straightJoin(metaFeed).on(meta.FEED_ID.eq(metaFeed.ID))
                                                .straightJoin(metaType).on(meta.TYPE_ID.eq(metaType.ID))
                                                .leftOuterJoin(metaProcessor).on(meta.PROCESSOR_ID.eq(metaProcessor.ID))
                                                .leftOuterJoin(parent).on(meta.PARENT_ID.eq(parent.ID))
                                                .straightJoin(parentFeed).on(parent.FEED_ID.eq(parentFeed.ID))
                                                .straightJoin(parentType).on(parent.TYPE_ID.eq(parentType.ID)),
                                        meta.ID,
                                        usedValKeys)
                                .where(conditions)
                                .and(parent.ID.isNotNull())
                                .and(parent.STATUS.eq(MetaStatusId.getPrimitiveValue(Status.UNLOCKED)))
                                .limit(offset, numberOfRows)
                                .fetchOptional())
                .map(record -> {
                    final Set<String> distinctFeeds = splitGroupConcat(record.get(2, String.class));
                    final Set<String> distinctTypes = splitGroupConcat(record.get(4, String.class));
                    final Set<String> distinctStatuses = getDistinctStatuses(record.get(8, String.class));
                    return new SelectionSummary(
                            NullSafe.getInt(record.get(0, Integer.class)),
                            NullSafe.getInt(record.get(1, Integer.class)),
                            distinctFeeds,
                            NullSafe.getInt(record.get(3, Integer.class)),
                            distinctTypes,
                            NullSafe.getInt(record.get(5, Integer.class)),
                            NullSafe.getInt(record.get(6, Integer.class)),
                            NullSafe.getInt(record.get(7, Integer.class)),
                            distinctStatuses,
                            new Range<>((Long) record.get(9), (Long) record.get(10)));
                })
                .orElse(null);
    }
@return True if any term in any rule expression uses at least one of {@code fields}.
stroom-meta/stroom-meta-impl-db/src/main/java/stroom/meta/impl/db/MetaDaoImpl.java