我有一个 Drupal 6 应用程序需要比61 表连接mySQL限制允许的更多连接。我知道这是一个过多的数字,但它每天只运行一次,结果被缓存以供进一步参考。
是否有任何可能有帮助的 mySQL 配置参数,或者是否有任何其他方法可以改变收集数据背后的逻辑?
我的方法是将庞大的查询拆分为更小、更简单的查询,并使用临时表来存储中间步骤。我经常使用这种方法,它对我有很大帮助(有时创建一些临时表比在一个大查询中加入所有表更快)。
像这样的东西:
drop table if exists temp_step01;
create temporary table temp_step01
select t1.*, t2.someField
from table1 as t1 inner join table2 as t2 on t1.id = t2.table1_id;
-- Add the appropriate indexes to optimize the subsequent queries
alter table temp_step01
add index idx_1 (field1);
-- Create all the temp tables that you need, and finally show the results
select sXX.*
from temp_stepXX as sXX;
请记住:临时表仅对创建它们的连接可见。如果您需要使结果对其他连接可见,则需要创建一个“真实”表(当然,这仅在过程的最后一步才值得)。