public function visit(Constraint $constraint)
    {
        $sql = $this->doVisit($constraint);

        $return = [$sql, $this->values];
        $this->values = [];
        $this->paramCounter = 0;
        $select = [
            'run.id',
            'run.uuid',
            'run.tag',
            'run.date',
            'subject.benchmark',
            'subject.name',
            'subject.id',
            'variant.id',
            'variant.sleep',
            'variant.output_time_unit',
            'variant.output_time_precision',
            'variant.output_mode',
            'variant.revolutions',
            'variant.retry_threshold',
            'variant.warmup',
            'iteration.time',
            'iteration.memory',
            'iteration.reject_count',
        ];

        $extraJoins = [];
        $fieldNames = $this->getFieldNames($constraint);

        if (in_array('group', $fieldNames)) {
            $extraJoins[] = 'LEFT JOIN sgroup_subject ON sgroup_subject.subject_id = subject.id';
            $select[] = 'sgroup_subject.sgroup';
        }

        if (in_array('param', $fieldNames)) {
            $extraJoins[] = 'LEFT JOIN variant_parameter ON variant_parameter.variant_id = variant.id';
            $extraJoins[] = 'LEFT JOIN parameter ON variant_parameter.parameter_id = parameter.id';
            $select[] = 'parameter.pkey';
            $select[] = 'parameter.value';
        }

        $selectSql = <<<'EOT'
SELECT 
    %s
    FROM iteration
    LEFT JOIN variant ON iteration.variant_id = variant.id
    LEFT JOIN subject ON variant.subject_id = subject.id
    LEFT JOIN run ON variant.run_id = run.id
    %s
WHERE

EOT;

        $select = array_map(function ($value) {
            return sprintf('%s AS "%s"', $value, $value);
        }, $select);

        $selectSql = sprintf(
            $selectSql,
            implode(', ', $select),
            implode(' ', $extraJoins)
        );
        $return[0] = $selectSql . $return[0];

        return $return;
    }