【发布时间】:2019-12-20 13:23:46
【问题描述】:
我有一个复杂的查询,它在 phpmyadmin 中可以正常工作,但是每当我尝试在 php 中使用它时,我都会收到一个错误,提示 LIMIT 和 UNION 不允许一起使用。 我添加了 LIMIT 以加快查询速度(因此子选择只会查找 100 行,而不是数千个可能的结果) - 这确实有效(它确实加快了查询速度)
现在我从 mysql 切换到 maria_Db,虽然查询在 phpmyadmin 上仍然有效(插入了 112 行),但它只是在 php 上显示一条错误消息
有什么想法吗?
insert ignore into paulsim2_dokumente_autofill.suche_intern_cache_helper select sysdate(), 'prometheus' as bb,
id, w_tit,w_key, w_uni,w_sim,w_pln,w_len, such_union, 100 from ( select distinct id, w_tit,w_key, w_uni,w_sim,w_pln,w_len, such_union
from ( ( SELECT a.ID as id, 'tit' as such_union, MATCH(a.titel_u8) AGAINST('>prometheus' IN BOOLEAN MODE)* MATCH(a.titel_u8) AGAINST('prometheus')+1 as w_tit, MATCH(a.keywords_titel_u8) AGAINST('prometheus')+1 as w_key, MATCH(a.keywords_uni_typ_cat_u8) AGAINST('prometheus')+1 as w_uni, MATCH(a.keywords_simple_u8) AGAINST('+prometheu' IN BOOLEAN MODE) *MATCH(a.keywords_simple_u8) AGAINST('prometheu') +1 as w_sim, 1 as w_pln, 10 as w_len from dokument as a where freigegeben in (1,3) and aktiv=1 and a.id <> -1 and MATCH(a.titel_u8) AGAINST('prometheus') > 1
LIMIT 0,100 ) UNION ( SELECT a.ID as id, 'key' as such_union, MATCH(a.titel_u8) AGAINST('>prometheus' IN BOOLEAN MODE)* MATCH(a.titel_u8) AGAINST('prometheus')+1 as w_tit, MATCH(a.keywords_titel_u8) AGAINST('prometheus')+1 as w_key, MATCH(a.keywords_uni_typ_cat_u8) AGAINST('prometheus')+1 as w_uni, MATCH(a.keywords_simple_u8) AGAINST('+prometheu' IN BOOLEAN MODE) *MATCH(a.keywords_simple_u8) AGAINST('prometheu') +1 as w_sim, 1 as w_pln, 10 as w_len from dokument as a where freigegeben in (1,3) and aktiv=1 and a.id <> -1 and MATCH(a.keywords_titel_u8) AGAINST('prometheus') > 1
LIMIT 0,100 ) UNION ( SELECT a.ID as id, 'uni' as such_union, MATCH(a.titel_u8) AGAINST('>prometheus' IN BOOLEAN MODE)* MATCH(a.titel_u8) AGAINST('prometheus')+1 as w_tit, MATCH(a.keywords_titel_u8) AGAINST('prometheus')+1 as w_key, MATCH(a.keywords_uni_typ_cat_u8) AGAINST('prometheus')+1 as w_uni, MATCH(a.keywords_simple_u8) AGAINST('+prometheu' IN BOOLEAN MODE) *MATCH(a.keywords_simple_u8) AGAINST('prometheu') +1 as w_sim, 1 as w_pln, 10 as w_len from dokument as a where freigegeben in (1,3) and aktiv=1 and a.id <> -1 and MATCH(a.keywords_uni_typ_cat_u8) AGAINST('prometheus') > 1
LIMIT 0,100 ) UNION ( SELECT a.ID as id, 'sim' as such_union, MATCH(a.titel_u8) AGAINST('>prometheus' IN BOOLEAN MODE)* MATCH(a.titel_u8) AGAINST('prometheus')+1 as w_tit, MATCH(a.keywords_titel_u8) AGAINST('prometheus')+1 as w_key, MATCH(a.keywords_uni_typ_cat_u8) AGAINST('prometheus')+1 as w_uni, MATCH(a.keywords_simple_u8) AGAINST('+prometheu' IN BOOLEAN MODE) *MATCH(a.keywords_simple_u8) AGAINST('prometheu') +1 as w_sim, 1 as w_pln, 10 as w_len from dokument as a where freigegeben in (1,3) and aktiv=1 and a.id <> -1 and MATCH(a.keywords_simple_u8) AGAINST('+prometheu' IN BOOLEAN MODE)
LIMIT 0,50 ) UNION ( SELECT a.ID as id, 'pln' as such_union, MATCH(a.titel_u8) AGAINST('>prometheus' IN BOOLEAN MODE)* MATCH(a.titel_u8) AGAINST('prometheus')+1 as w_tit, MATCH(a.keywords_titel_u8) AGAINST('prometheus')+1 as w_key, MATCH(a.keywords_uni_typ_cat_u8) AGAINST('prometheus')+1 as w_uni, MATCH(a.keywords_simple_u8) AGAINST('+prometheu' IN BOOLEAN MODE) *MATCH(a.keywords_simple_u8) AGAINST('prometheu') +1 as w_sim, MATCH(x.plain_u8) AGAINST('"prometheus"' IN BOOLEAN MODE) *MATCH(x.plain_u8) AGAINST('"prometheus"') +1 as w_pln, 10 as w_len from dokument as a, dokumente_text as x where freigegeben in (1,3) and aktiv=1 and a.id <> -1 and x.id = a.id and MATCH(x.plain_u8) AGAINST('"prometheus"')
LIMIT 0,50 ) UNION ( select 1 as id, 'dum' as such_union,-1 as w_tit,-1 as wkey, -1 as w_uni, -1 as w_sim, -1 as w_pln, -1 as w_len from dokument where 1 Limit 0,1 )
order by (w_tit)*(w_key)*w_uni*w_sim*w_pln desc Limit 0, 500 ) as tneu ) as tnx
【问题讨论】:
-
我只能建议您尝试简化当前查询并缩小语法中的确切问题(例如,只有一个联合)。
-
我可以,但我知道问题所在:在 phpmyadmin UNION + LIMIT 内是允许的 - 在 php 内它会产生一个错误。
-
该评论不适合我,假设两者最终都针对同一个数据库执行。