query speed up

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?
sam2929Asked:
Who is Participating?
 
Franck PachotCommented:
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
 
ajexpertCommented:
Basics: are table stats up to date? How many records in these tables and how much % of recs are expected in output ?
0
 
Geert GOracle dbaCommented:
what's in the explain plan ?
it helps to give ideas
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Naveen KumarProduction Manager / Application Support ManagerCommented:
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
 
sam2929Author Commented:
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
 
sam2929Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.