Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2025
  • Last Modified:

how to improve performance when using "group by" ?

the below query never returns (atleast for 3 minutes), there are about 1.2 million rows on which the above  pl/sql is grouping by.
actual std_deatails contains about 25 million rows.
 
std_id, std_name, std_key, std_cat (all have indexes on them).
 
should I add an composite index for the key (std_key & std_cat) to improve this query? how can I improve the performance of
the above query ?


 
select std_id,std_name, std_key||'.'||std_cat as std_cat_key, fees_cat from (
select  std_id, std_name, std_key, std_cat, sum(fees) as fees_cat
from std_details_f 
  inner join cat_users on std_details.category_id = cat_users.category_id 
  where cat_users.auth_user = 'testuser'
group by std_id, std_name, std_key , std_cat) A

Open in new window

0
tech_question
Asked:
tech_question
  • 3
  • 3
1 Solution
 
sdstuberCommented:
composite index on auth_user and category_id for the cat_users table.

index on category_id for std_details
0
 
tech_questionAuthor Commented:
I am sorry category_id index on std_details was already present. I did add a composite key for auth_user and category_id for cat_users , still not getting the results in 3 minutes or less.
0
 
tech_questionAuthor Commented:
one more important thing is that the table std_details_f is partitioned based on fiscal_key. does this make any difference on the query ?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
sdstuberCommented:
no, syntax wise it makes no difference.

performance wise, it could,  you can get parallel threads searching each partition, which may help you.  But your partition key isn't part of your query so you won't get any partition pruning.

In the grand schema of things, no, it probably won't make much of a visible difference.
0
 
tech_questionAuthor Commented:
should I do an ETL do get the group by results into one more table and run the ETL every night so that I can query this table directly. Our team is disinclined to use Materialized views. So I guess the only option left is an ETL or are there any other options ?
0
 
sdstuberCommented:
"ETL do get the group by results into one more table and run the ETL every night so that I can query this table directly."

That's a materialzed view.  Maybe you're not using Oracle's built in functionality but that's what it is.

Is cat_users acting as a filter or as a lookup in this query?

Which columns are coming from which table?

0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now