Sql查询性能下降
问题描述:
我正在写一个SQL查询,它给我一个慢的性能。因为它给我504网关超时问题。请帮我重新制作这个查询,以便我的输出结果更快。我会把下面的查询。Sql查询性能下降
select
r.c1,
parent_item.c2,
parent_item.c3,
parent_item.c4,
parent_item.c5,
parent_item.c6,
parent_item.c7,
pt.c8,
child_item.c9,
t.c10,
child_item.c11,
from
table1 child_item,
table2 t,
table3 r,
table1 parent_item,
table4 pt
where
r.col1 = child_item.id and
t.id=child_item.typeid and
parent_item.id = r.parent_itemid and
pt.id = parent_item.typeid and parent_item.id=800 and
parent_item.id = (select
itemid
from
table5
where
itemid=parent_item.id
((10!= 1) ? and (holder_itemid in (10,100) and level > 0): "")) and
child_item.id = (select
itemid
from
table5
where
itemid=child_item.id
((10 != 1) ? and (holder_itemid in (10,100) and level > 0) : ""))
order by
r.parent_itemid,
r.relation_typeid,
r.ordinal
答
这可能是两个子查询,但我们没有足够的有关您的模式的信息。
您应该通过EXPLAIN运行查询并查看它说了什么。
JOIN可能会有帮助,但我们再次无法确定。
+0
我再次简化了这个查询,但仍然存在问题,我添加了简化的,你能否更加有效地简化它。 – user642378 2011-03-03 06:06:37
答
如果我们不知道数据库模式,就很难准确地指出性能问题。 (数据库模式意味着你的表定义,索引等)
此外,这个位应该做什么?
((10!= 1) ? and (holder_itemid in (10,100) and level > 0): ""))
AFAICS,这不是一个有效的SQL查询,并且会导致语法错误。
可能重复的[慢性能查询](http://stackoverflow.com/questions/5177323/slow-performance-of-query) – 2011-03-28 11:55:01