private SelectionSummary getSelectionSummary(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(meta.ID),
                                                        DSL.countDistinct(metaFeed.NAME),
                                                        DSL.groupConcatDistinct(metaFeed.NAME)
                                                                .separator(GROUP_CONCAT_DELIMITER),
                                                        DSL.countDistinct(metaType.NAME),
                                                        DSL.groupConcatDistinct(metaType.NAME)
                                                                .separator(GROUP_CONCAT_DELIMITER),
                                                        DSL.countDistinct(metaProcessor.PROCESSOR_UUID),
                                                        DSL.countDistinct(metaProcessor.PIPELINE_UUID),
                                                        DSL.countDistinct(meta.STATUS),
                                                        DSL.groupConcatDistinct(meta.STATUS)
                                                                .separator(GROUP_CONCAT_DELIMITER),
                                                        DSL.min(meta.CREATE_TIME),
                                                        DSL.max(meta.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)),
                                        meta.ID,
                                        usedValKeys)
                                .where(conditions)
                                .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