Solved

query speed up

Posted on 2013-02-05
6
260 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 36

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.

Join & Write a Comment

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…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

758 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now