?
Solved

query speed up

Posted on 2013-02-05
6
Medium Priority
?
271 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 38

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Accepted Solution

by:
Franck Pachot earned 2000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Suggested Courses

839 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