Solved

query speed up

Posted on 2013-02-05
6
265 Views
Last Modified: 2013-02-11
Hi,
When i do expalin plan on below query it cost 20k and runs within 4-5 minutes

select count(*)

  from  "F_TEST" "F_TEST3"

  inner join "D_ACT_JUNK" "D_ACT_JUNK"

  on "D_ACT_JUNK"."JUNK_SK"="F_TEST3"."JUNK_SK"

 and "D_ACT_JUNK"."DOC_STATUS"='Y'

 inner join "D_POSTING"

  on "D_POSTING"."POSTING_SK"="F_TEST3"."POSTING_SK"

  inner join "D_GL_ACCT"

  on "F_TEST3"."GL_ACCT_SK"="D_GL_ACCT"."GL_ACCT_SK"

   inner join "D_ACT_TEXT"

  on "D_ACT_TEXT"."ACT_TEXT_SK"="F_TEST3"."ACT_TEXT_SK"

  inner join "D_COST_CNTR"

  on "D_COST_CNTR"."COST_CNTR_SK"="F_TEST3"."COST_CNTR_SK"

 ----- inner join "D_GL_HIER_NULLS"

-------on "D_GL_HIER_NULLS"."GL_ACCT_TCD"="D_GL_ACCT"."GL_ACCT_TCD"


When i remove  below comments  it take forvere and COST increases to 250 K

 ----- inner join "D_GL_HIER_NULLS"

-------on "D_GL_HIER_NULLS"."GL_ACCT_TCD"="D_GL_ACCT"."GL_ACCT_TCD"

This is star schema but below join is more like snow flake
GL_ACCT_TCD is indexed for both dimensions and stat is done for all tables too
Both columns are vachar(10) and it is one to many relationship
Any idea what can i do to speed it up?
0
Comment
Question by:sam2929
6 Comments
 
LVL 14

Expert Comment

by:ajexpert
ID: 38857839
Basics: are table stats up to date? How many records in these tables and how much % of recs are expected in output ?
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 38858333
what's in the explain plan ?
it helps to give ideas
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 38858348
How big are the tables and are they being archived on a regular basis to stop them from growing too big ? Reorganize the tables to release the high water mark is also an option to try if your tables have DML operations on them.

Does your tables have indexes which are shown as used in the explain plan ?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 15

Accepted Solution

by:
Franck Pachot earned 500 total points
ID: 38858804
Hi,
Only execution plans can show what's wrong. Better with executions stats (statistics_level=all and dbms_xplan.display_cursor ALLSTATS LAST) or SQL Monitoring ( if 11g and tuning pack ) or maybe tkprof.
Besides stats and indexes, constraints (not null, foreign keys) can help the optimizer.
An hypothesis: The STAR transformation may have occur in forst query, but cannot be done in snowflake.
Regards,
Franck.
0
 

Author Comment

by:sam2929
ID: 38864543
i think i found the problem once i do inner join to  "D_GL_HIER_NULLS"  the query start adding billion rows .

As i need only one distinct count i am thinking for doing subquery to "D_GL_HIER_NULLS"
to get just 1-1 match

how can i rewrite this query.


select count(*)

  from  "F_TEST" "F_TEST3"

  inner join "D_ACT_JUNK" "D_ACT_JUNK"

  on "D_ACT_JUNK"."JUNK_SK"="F_TEST3"."JUNK_SK"

 and "D_ACT_JUNK"."DOC_STATUS"='Y'

 inner join "D_POSTING"

  on "D_POSTING"."POSTING_SK"="F_TEST3"."POSTING_SK"

  inner join "D_GL_ACCT"

  on "F_TEST3"."GL_ACCT_SK"="D_GL_ACCT"."GL_ACCT_SK"

   inner join "D_ACT_TEXT"

  on "D_ACT_TEXT"."ACT_TEXT_SK"="F_TEST3"."ACT_TEXT_SK"

  inner join "D_COST_CNTR"

  on "D_COST_CNTR"."COST_CNTR_SK"="F_TEST3"."COST_CNTR_SK"

Below join should be in subquery to just get 1-1 match for GL_ACCT_TCD

 ----- inner join "D_GL_HIER_NULLS"

-------on "D_GL_HIER_NULLS"."GL_ACCT_TCD"="D_GL_ACCT"."GL_ACCT_TCD"
0
 

Author Comment

by:sam2929
ID: 38864754
i just do rewrite like below

select
count(*)
  from  "FINMARTADM"."D_GL_ACCT" a
  inner join ( select distinct b."GL_ACCT_TCD" from "FINMARTADM"."D_GL_HIER_NULLS" b)ss
on (a."GL_ACCT_TCD"=ss."GL_ACCT_TCD")
inner join FINMARTADM"."F_TXN_ACTUAL" b
on b."GL_ACCT_SK"=a."GL_ACCT_SK"

its not liking it please suggest
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
selective queries 7 37
Include a logo in email body using Oracle utl_mail 11 41
Not able to drop or recreate an Oracle stored procedure 1 39
Email query results in HTML 6 29
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question