Skip to main content
added 226 characters in body
Source Link
ypercubeᵀᴹ
  • 98.7k
  • 13
  • 215
  • 305

Yes, it is supposed to be slow. Why?

  • There are multiple subqueries:
    • 3 levels of nested derived tables
    • 7 inline correlated subqueries that each join to a different table, using the userid which as you say is not indexed. One of the subqueries has a further nested derived table in its FROM clause.
  • There are WHERE conditios on un-indexed columns
  • There is an ORDER BYORDER BY clause - it always adds one more operation
  • There is a DISTINCT clauseDISTINCT quantifier - filtering out duplicates is a costly operation
  • There are some calculations being made

It really looks very bizarre. I guess it can be rewritten to a neat form using JOINs and it would run much faster. You would have to post the database structure and the result you want to achieve.

Yes, it is supposed to be slow. Why?

  • There are multiple subqueries
  • There is an ORDER BY clause - it always adds one more operation
  • There is a DISTINCT clause - filtering out duplicates is a costly operation
  • There are some calculations being made

It really looks very bizarre. I guess it can be rewritten to a neat form using JOINs and it would run much faster. You would have to post the database structure and the result you want to achieve.

Yes, it is supposed to be slow. Why?

  • There are multiple subqueries:
    • 3 levels of nested derived tables
    • 7 inline correlated subqueries that each join to a different table, using the userid which as you say is not indexed. One of the subqueries has a further nested derived table in its FROM clause.
  • There are WHERE conditios on un-indexed columns
  • There is an ORDER BY clause - it always adds one more operation
  • There is a DISTINCT quantifier - filtering out duplicates is a costly operation
  • There are some calculations being made

It really looks very bizarre. I guess it can be rewritten to a neat form using JOINs and it would run much faster. You would have to post the database structure and the result you want to achieve.

Source Link
Łukasz Kastelik
  • 1.4k
  • 2
  • 14
  • 23

Yes, it is supposed to be slow. Why?

  • There are multiple subqueries
  • There is an ORDER BY clause - it always adds one more operation
  • There is a DISTINCT clause - filtering out duplicates is a costly operation
  • There are some calculations being made

It really looks very bizarre. I guess it can be rewritten to a neat form using JOINs and it would run much faster. You would have to post the database structure and the result you want to achieve.