Sql查询性能慢 [英] Slow Performance of Sql Query

查看:35
本文介绍了Sql查询性能慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 SQL 查询,这给了我一个缓慢的性能.因此,它给了我 504 网关超时问题.请帮助我重新制作此查询,以便我的输出结果更快.我将把查询放在下面.

I am writing a SQL query which gives me a slow performance. Because of that it gives me 504 gateway timeout problem. Please help me to remake this query so that my output results faster. I will put the query below.

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

推荐答案

很可能是两个子查询,但我们没有关于您的架构的足够信息.

It's likely the two sub-queries, but we don't have enough information about your schema.

你应该通过 EXPLAIN 运行你的查询,看看它说了什么.

You should run your query though EXPLAIN and see what it says.

JOIN 可能会有所帮助,但同样,我们不能确定.

JOINs might help, but again, we can't tell for sure.

这篇关于Sql查询性能慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆