very slow performance when using sum and group by
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: very slow performance when using sum and group by

Hybrid View

  1. #1
    Join Date
    Apr 2001
    Posts
    125

    very slow performance when using sum and group by

    Hi,

    I have a query which runs very very slow, it is doing a full table scan on tab1:

    select sum(col1)
    from tab1
    where col2 = 'x'
    group by col3

    There is an index on (col2, col3), the following query runs very fast:

    select *
    from tab1
    where col2 = 'x'

    I tried to change the index to (col1, col2, col3), but there is no improvement by doing that, how can I improve the performance of this query?

    Thanks

  2. #2
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,554
    Have you noticed you are grouping in the first query? you certainly can expect this query to be slower than the second one.

    By the way...
    What's the cardinality of "x" on col2?
    Do you have up-to-date stats?
    Please post Explain Plan for your two queries.
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width