SQL_BIG_SELECTS错误

时间:2017-03-29 05:56:01

标签: mysql sql database phpmyadmin

更新

现在我可以通过删除ORDER BY来使它工作......不确定这是正确的事情,但必须这样做。

首先,这是我要在数据库中加入的所有表中的所有字段(列)

enter image description here

,突出显示的字段是我想要选择的字段。

所以,我写了sql语法来加入像这样的所有表

SELECT country_policies.policyname,
       country_policies.countryname,
       section_data_structure.data_name,
       section_data_content_p.dropname,
       section_data_content_p.comment,
       date_format(section_data_content_p.start_date,'%Y-%m-%d') as start_date,
       date_format(section_data_content_p.end_date,'%Y-%m-%d') as end_date,
       section_data_content_p.policy_id,
       section_data_content_p.country_id,
       sections_content.section_id,
       sections_content.statecode
FROM
(
    (country_policies
     INNER JOIN section_data_content_p
         ON country_policies.policyid = section_data_content_p.policy_id AND
            country_policies.countryid = section_data_content_p.country_id
    )
    INNER JOIN section_data_structure
        ON section_data_content_p.data_structure_id = section_data_structure.id
    INNER JOIN sections_content
        ON section_data_content_p.state_id = sections_content.statecode
)
order by section_data_content_p.dropname;

然后我收到了这个错误

  

ER_TOO_BIG_SELECT:SELECT将检查超过MAX_JOIN_SIZE行;检查你的WHERE并使用SET SQL_BIG_SELECTS = 1或SET MAX_JOIN_SIZE =#如果SELECT没问题

所以我尝试添加SET SQL_BIG_SELECTS = 1;像这样的顶部

SET SQL_BIG_SELECTS= 1 ;
SELECT country_policies.policyname, country_policies.countryname, section_data_structure.data_name, section_data_content_p.dropname, section_data_content_p.comment, date_format(section_data_content_p.start_date,'%Y-%m-%d') as start_date, date_format(section_data_content_p.end_date,'%Y-%m-%d') as end_date,section_data_content_p.policy_id,section_data_content_p.country_id,sections_content.section_id,sections_content.statecode
FROM  ((country_policies
INNER JOIN section_data_content_p ON country_policies.policyid = section_data_content_p.policy_id AND country_policies.countryid = section_data_content_p.country_id)
INNER JOIN section_data_structure ON section_data_content_p.data_structure_id = section_data_structure.id
INNER JOIN sections_content ON section_data_content_p.state_id = sections_content.statecode) order by section_data_content_p.dropname;

然后我又出错了

  

ER_PARSE_ERROR:您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在'SET SQL_BIG_SELECTS = 1附近使用正确的语法   在第1行选择country_policies.policyname,country_policies.co'

也试过了SET SESSION / SET OPTION,但一切都行不通 而我仍然无法解决这个问题。 mysql版本是5.6.32

任何人都可以帮忙吗?感谢

2 个答案:

答案 0 :(得分:0)

我已经整理了两个代码示例中的一些括号用法。第一个是现在......

SELECT country_policies.policyname,
       country_policies.countryname,
       section_data_structure.data_name,
       section_data_content_p.dropname,
       section_data_content_p.comment,
       DATE_FORMAT( section_data_content_p.start_date,
                    '%Y-%m-%d' ) AS start_date,
       DATE_FORMAT( section_data_content_p.end_date,
                    '%Y-%m-%d' ) AS end_date,
       section_data_content_p.policy_id,
       section_data_content_p.country_id,
       sections_content.section_id,
       sections_content.statecode
FROM country_policies
     INNER JOIN section_data_content_p ON ( country_policies.policyid = section_data_content_p.policy_id AND country_policies.countryid = section_data_content_p.country_id )
     INNER JOIN section_data_structure ON section_data_content_p.data_structure_id = section_data_structure.id
     INNER JOIN sections_content ON section_data_content_p.state_id = sections_content.statecode
ORDER BY section_data_content_p.dropname;

我还在SQL_BIG_SELECT中设置了一个会话变量,根据改变的第二段代码中的MySQL - SQL_BIG_SELECTS,如下所示......

SET SESSION SQL_BIG_SELECTS = 1;
SELECT country_policies.policyname,
       country_policies.countryname,
       section_data_structure.data_name,
       section_data_content_p.dropname,
       section_data_content_p.comment,
       DATE_FORMAT( section_data_content_p.start_date,
                    '%Y-%m-%d' ) AS start_date,
       DATE_FORMAT( section_data_content_p.end_date,
                    '%Y-%m-%d' ) AS end_date,
       section_data_content_p.policy_id,
       section_data_content_p.country_id,
       sections_content.section_id,
       sections_content.statecode
FROM country_policies
     INNER JOIN section_data_content_p ON ( country_policies.policyid = section_data_content_p.policy_id AND country_policies.countryid = section_data_content_p.country_id )
     INNER JOIN section_data_structure ON section_data_content_p.data_structure_id = section_data_structure.id
     INNER JOIN sections_content ON section_data_content_p.state_id = sections_content.statecode
ORDER BY section_data_content_p.dropname;

注意:我还将布局更改为我觉得更容易调试的样式。

如果您有任何问题或意见,请随时发表评论。

答案 1 :(得分:0)

SET max_join_size=18446744073709551615,那么您可能会失去大选择。