Sql查询性能慢

发布于 2024-10-20 07:58:16 字数 1138 浏览 1 评论 0原文

我正在编写一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烦人精 2024-10-27 07:58:16

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

您应该通过 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.

你是年少的欢喜 2024-10-27 07:58:16

如果我们不了解您的数据库架构,则很难准确指出性能问题。 (数据库模式意味着您的表定义、索引等)

另外,这个位应该做什么?

((10!= 1) ?  and (holder_itemid in (10,100) and level > 0): ""))

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?

((10!= 1) ?  and (holder_itemid in (10,100) and level > 0): ""))

AFAICS, this is not a valid SQL query, and will result in a syntax error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文