SQL_BIG_SELECTS 错误
Posted
技术标签:
【中文标题】SQL_BIG_SELECTS 错误【英文标题】:SQL_BIG_SELECTS error 【发布时间】:2017-08-22 11:07:20 【问题描述】:更新
现在我可以通过删除 ORDER BY... 来使其工作...不确定这是正确的做法,但必须这样做。
首先,这是我要加入数据库的所有表中的所有字段(列)
突出显示的字段是我要选择的字段。
所以,我写了 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 附近使用的正确语法 SELECT country_policies.policyname, country_policies.co' 在第 1 行
也尝试过 SET SESSION/SET OPTION 但都不起作用 我仍然无法解决这个问题。 mysql版本是5.6.32
有人可以帮忙吗?谢谢
【问题讨论】:
***.com/questions/950465/mysql-sql-big-selects 这些表有多大?我从来没有遇到过too-large-for-select 错误,但我可以建议您尝试改写您的查询以避免有这么多的中间行。您打算返回多少行?如果远小于阈值,那么也许您可以重写您的查询。 @TimBiegeleisen 我认为会超过 10,000 行 【参考方案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;
我也将 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;
注意:我还将布局更改为我觉得更容易调试的样式。
如果您有任何问题或cmets,请随时发表相应的评论。
【讨论】:
【参考方案2】:SET max_join_size=18446744073709551615
那么你可能会输掉大选择。
【讨论】:
对 ON 子句中使用的列进行索引更合乎逻辑,因为我很确定那些没有被索引..以上是关于SQL_BIG_SELECTS 错误的主要内容,如果未能解决你的问题,请参考以下文章
无法克隆 <select> 并出现“.select2 不是函数”错误
Rails 5 和 select2 错误,select2 不是函数