?
Solved

query speed up

Posted on 2013-02-05
6
Medium Priority
?
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to recover a database from a user managed backup
Suggested Courses

764 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