MySQL-ORDER BY子句导致选择SQL_CALC_FOUND_ROWS不返回数据

时间:2019-05-07 20:38:03

标签: mysql sql-order-by sql-calc-found-rows

我在centos 6机器上使用MySQL 5.6(MySQL Ver 14.14 Distrib 5.6.44,对于Linux(i686)使用EditLine包装器)

我有一个带有多个内部联接的查询。我已经确定,当将ORDER BY子句与SQL_CALC_FOUND_ROWS一起使用时,不会返回任何数据。查询对消息说“确定”,并且我有一个查询所用时间的持续时间,但是什么也没有返回。

如果删除“ SQL_CALC_FOUND_ROWS”,则会得到行。 在MySQL工作台内部,我可以看到一个持续时间,但是在“获取”时间下,它甚至没有尝试获取。

查询为:

SELECT SQL_CALC_FOUND_ROWS
    l.id AS licensee_id,
    l.agency_id,
    l.licensee_fname,
    l.licensee_name,
    l.licensee_lname,
    l.licensee_email,
    licensee_certs.cert_number,
    agency.agency_name,
    licensee_cert_types.cert_name,
    licensee_certs.cert_issue_date AS approval_timestamp,
    licensee_certs.cert_issue_date AS issue_timestamp,
    licensee_certs.cert_expiration_date AS expire_timestamp,
    licensee_certs.cert_status AS licensee_status,
    licensee_certs.cert_status,
    (licensee_certs.cert_expiration_date - UNIX_TIMESTAMP()) AS days_remaining,
    h_cache.acquired AS total_hours,
    h_cache.pending AS pending_hours,
    CONCAT(IFNULL(licensee_cert_types.cert_name, ''),
            ' ',
            IFNULL(licensee_certs.cert_number, ''),
            ' ',
            IFNULL(licensee_certs.cert_status, ''),
            ' ',
            IFNULL(l.licensee_fname, ''),
            ' ',
            IFNULL(l.licensee_lname, ''),
            ' ',
            IFNULL(l.licensee_email, ''),
            ' ',
            IFNULL(agency.agency_name, ''),
            ' ',
            IFNULL(agency.agency_abbr, '')) AS search
FROM
    licensee AS l
        LEFT JOIN
    licensee_certs ON l.id = licensee_certs.licensee_id
        AND licensee_certs.agency_id = l.agency_id
        LEFT JOIN
    agency ON agency.id = l.agency_id
        LEFT JOIN
    licensee_cert_hour_cache AS h_cache ON h_cache.licensee_id = l.id
        AND h_cache.agency_id = l.agency_id
        AND h_cache.licensee_cert_type_id = licensee_certs.cert_type
        INNER JOIN
    licensee_cert_types ON licensee_certs.cert_type = licensee_cert_types.id
GROUP BY licensee_certs.id
ORDER BY l.licensee_fname ASC
limit 5

如果我删除订单,则得到5行。 或者,如果删除“ SQL_CALC_FOUND_ROWS”,则会得到5行。

为什么不能同时执行by和SQL calc?

我认为同样重要的是要注意,这个确切的查询在MySQL 5.5上运行得很好。我升级到5.6.44并得到了这种行为。

在运行5.6.42-的生产服务器上,此查询没有问题。

更新: 似乎是上述特定查询。 如果我使用SQL_CALC + ORDER BY运行其他查询,则会得到结果,即:

SELECT SQL_CALC_FOUND_ROWS
    p.*,
    a.agency_name,
    (SELECT 
            COUNT(*)
        FROM
            providership_notes
        WHERE
            providership_notes.provider_id = p.id) AS note_count,
    (SELECT 
            `user_id`
        FROM
            `user_entity_relations`
        WHERE
            `instance_id` = p.id
                AND `entity_type_id` = 2
        LIMIT 1) AS `user_id`,
    CONCAT(IFNULL(providership_name, ''),
            ' ',
            IFNULL(providership_abbr, ''),
            ' ',
            IFNULL(agency_name, ''),
            ' ',
            IFNULL(providership_state, '')) AS search
FROM
    providership AS p
        LEFT JOIN
    agency_providership_relations AS r ON r.providership_id = p.id
        AND `r`.`status` = 'approved'
        LEFT JOIN
    agency AS a ON r.agency_id = a.id
GROUP BY p.id
ORDER BY providership_name ASC
LIMIT 0 , 10```

1 个答案:

答案 0 :(得分:1)

所以...不好意思地说我的硬盘空间不足。我有大约5mB的可用空间,但除此以外,其他所有查询都可以正常工作。

我清理了一些空间,像魔术一样po琐,一切正常。