Sql查询性能慢
我正在编写一个 SQL 查询,这给我带来了缓慢的性能。因此,它给我带来了 504 网关超时问题。请帮助我重新创建此查询,以便我的输出结果更快。我将把查询放在下面。
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是两个子查询,但我们没有足够的有关您的架构的信息。
您应该通过 EXPLAIN 运行查询并查看其内容。
JOIN 可能会有所帮助,但同样,我们无法确定。
It's likely the two sub-queries, but we don't have enough information about your schema.
You should run your query though EXPLAIN and see what it says.
JOINs might help, but again, we can't tell for sure.
如果我们不了解您的数据库架构,则很难准确指出性能问题。 (数据库模式意味着您的表定义、索引等)
另外,这个位应该做什么?
AFAICS,这不是有效的 SQL 查询,将导致语法错误。
It’s very difficult to accurately point out performance problems if we don’t know your database schema. (The database schema means your table definitions, indexes etc.)
Also, what is this bit supposed to do?
AFAICS, this is not a valid SQL query, and will result in a syntax error.