Question

Performance Issue

Asked by: vadicherla

Hi

Foloowing two sql causing performance issue in production.

SELECT QUESTION_ID, OPTION_ID, COUNT (OPTION_ID) COUNT FROM RESPONSES WHERE SURVEY_ID = ? GROUP BY QUESTION_ID, OPTION_ID ORDER BY QUESTION_ID

From above query we  QUESTION_ID, OPTION_ID SURVEY_ID are foreign keys and each of this columns are  in seprate table

SELECT COUNT (SUBMISSION_ID) NUM_VOTES FROM SUBMISSIONS WHERE SURVEY_ID = ?

from above query SURVEY_ID  is foregn key

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-29 at 12:28:46ID24855922
Tags

oracle

,

Oracle SCM

Topics

Enterprise Software

,

Oracle Database

,

Oracle CRM

Participating Experts
6
Points
500
Comments
47

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Preventing multiple votes
    Wonder if this is possible and if so anyone could give me a bit of a hand. I am writing a voting system which uses cookies to prevent multiple votes, however we all know that if someone wants to cheat the system they can quite easily. Because of the number of votes every nig...
  2. using cookies to stop multiple voting
    ok, I've read a few other questions regarding this subject, but still trying to figure it out. I think I would need the code to be either javascript or coldfusion, my polling app is designed with cf. now, on my main page I have a poll where visitors can vote on a single pol...
  3. Survey Table Design
    Hello, I am working on an existing design for a survey database. Briefly: The main entities involved are Client, Survey and Questions. A client has many Surveys A survey has many questions. I am confused about the existing structure, specifically the reason why it was imp...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: mohammadzahidPosted on 2009-10-29 at 14:00:33ID: 25698218

Check to see if Survey_id is indexed?  
You can find this out by running a select statement against user_indexes or dba_indexes.

 

by: vadicherlaPosted on 2009-10-29 at 14:09:54ID: 25698294

Yes survey _id is indexed in both the tables. Survey_id is foregn key. Survey_id is indexed in base table and foregn table

 

by: virdi_dsPosted on 2009-10-29 at 15:51:05ID: 25699000

Now check for execution plan by using

set autotrace traceonly explain
SELECT QUESTION_ID, OPTION_ID, COUNT (OPTION_ID) COUNT FROM RESPONSES WHERE SURVEY_ID = ? GROUP BY QUESTION_ID, OPTION_ID ORDER BY QUESTION_ID ;

If oracle is not using index then either there stats are old or total number of rows which satisfied this condition is very high.

Please provide the output of the following query.

select SURVEY_ID, count(*) from RESPONSES group by SURVEY_ID;

select ini_trans from user_tables where table_name='RESPONSES'

While running this query, what is the text written in Event column while checking your session from Pl Developer?

 

by: ajexpertPosted on 2009-10-29 at 15:51:08ID: 25699002

Can you provide the explain plan of the query?

You might need to EXECUTE DBMS_STATS FOR responses and submissions tables

 

by: virdi_dsPosted on 2009-10-29 at 15:52:43ID: 25699010

Also provide the information
select index_name, column_name, position from user_ind_columns where table_name='RESPONSE';

 

by: vadicherlaPosted on 2009-10-29 at 15:59:43ID: 25699032

This output is from dev database

SQL> set autotrace traceonly explain

SQL> SELECT QUESTION_ID, OPTION_ID, COUNT (OPTION_ID) COUNT FROM RESPONSES WHERE SURVEY_ID = 200 GROUP BY QUESTION_ID, OPTION_ID ORDER BY QUESTION_ID ;

Execution Plan
----------------------------------------------------------
Plan hash value: 1063528983

--------------------------------------------------------------------------------
| Id  | Operation          | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |           |     2 |    20 |     4  (25)| 00:00:01 |
|   1 |  SORT GROUP BY     |           |     2 |    20 |     4  (25)| 00:00:01 |
|*  2 |   TABLE ACCESS FULL| RESPONSES |    10 |   100 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - filter("SURVEY_ID"=200)

SQL> select SURVEY_ID, count(*) from RESPONSES group by SURVEY_ID;

Execution Plan
----------------------------------------------------------
Plan hash value: 3565624577

--------------------------------------------------------------------------------
-------

| Id  | Operation            | Name           | Rows  | Bytes | Cost (%CPU)| Tim
e     |

--------------------------------------------------------------------------------
-------

|   0 | SELECT STATEMENT     |                |     1 |     3 |     1   (0)| 00:
00:01 |

|   1 |  SORT GROUP BY NOSORT|                |     1 |     3 |     1   (0)| 00:
00:01 |

|   2 |   INDEX FULL SCAN    | SURVEY_ID_RESP |    10 |    30 |     1   (0)| 00:
00:01 |

--------------------------------------------------------------------------------
-------


SQL> select ini_trans from user_tables where table_name='RESPONSES'
  2  ;

Execution Plan
----------------------------------------------------------
Plan hash value: 1430774513

--------------------------------------------------------------------------------
----------------------

| Id  | Operation                           | Name           | Rows  | Bytes | C
ost (%CPU)| Time     |

--------------------------------------------------------------------------------
----------------------

|   0 | SELECT STATEMENT                    |                |     1 |   162 |
   8  (13)| 00:00:01 |

|   1 |  NESTED LOOPS OUTER                 |                |     1 |   162 |
   8  (13)| 00:00:01 |

|   2 |   NESTED LOOPS OUTER                |                |     1 |   158 |
   7  (15)| 00:00:01 |

|   3 |    NESTED LOOPS OUTER               |                |     1 |   150 |
   6  (17)| 00:00:01 |

|   4 |     NESTED LOOPS OUTER              |                |     1 |   145 |
   6  (17)| 00:00:01 |

|   5 |      NESTED LOOPS                   |                |     1 |   134 |
   5  (20)| 00:00:01 |

|   6 |       NESTED LOOPS                  |                |     1 |   131 |
   4  (25)| 00:00:01 |

|   7 |        MERGE JOIN CARTESIAN         |                |     1 |    98 |
   3  (34)| 00:00:01 |

|*  8 |         HASH JOIN                   |                |     1 |    68 |
   1 (100)| 00:00:01 |

|*  9 |          FIXED TABLE FULL           | X$KSPPI        |     1 |    55 |
   0   (0)| 00:00:01 |

|  10 |          FIXED TABLE FULL           | X$KSPPCV       |   100 |  1300 |
   0   (0)| 00:00:01 |

|  11 |         BUFFER SORT                 |                |     1 |    30 |
   3  (34)| 00:00:01 |

|* 12 |          TABLE ACCESS BY INDEX ROWID| OBJ$           |     1 |    30 |
   2   (0)| 00:00:01 |

|* 13 |           INDEX RANGE SCAN          | I_OBJ2         |     1 |       |
   1   (0)| 00:00:01 |

|* 14 |        TABLE ACCESS CLUSTER         | TAB$           |     1 |    33 |
   1   (0)| 00:00:01 |

|* 15 |         INDEX UNIQUE SCAN           | I_OBJ#         |     1 |       |
   0   (0)| 00:00:01 |

|  16 |       TABLE ACCESS CLUSTER          | TS$            |     1 |     3 |
   1   (0)| 00:00:01 |

|* 17 |        INDEX UNIQUE SCAN            | I_TS#          |     1 |       |
   0   (0)| 00:00:01 |

|  18 |      TABLE ACCESS CLUSTER           | SEG$           |     1 |    11 |
   1   (0)| 00:00:01 |

|* 19 |       INDEX UNIQUE SCAN             | I_FILE#_BLOCK# |     1 |       |
   0   (0)| 00:00:01 |

|* 20 |     INDEX UNIQUE SCAN               | I_OBJ1         |     1 |     5 |
   0   (0)| 00:00:01 |

|  21 |    TABLE ACCESS BY INDEX ROWID      | OBJ$           |     1 |     8 |
   1   (0)| 00:00:01 |

|* 22 |     INDEX UNIQUE SCAN               | I_OBJ1         |     1 |       |
   0   (0)| 00:00:01 |

|  23 |   TABLE ACCESS CLUSTER              | USER$          |     1 |     4 |
   1   (0)| 00:00:01 |

|* 24 |    INDEX UNIQUE SCAN                | I_USER#        |     1 |       |
   0   (0)| 00:00:01 |

--------------------------------------------------------------------------------
----------------------


Predicate Information (identified by operation id):
---------------------------------------------------

   8 - access("KSPPI"."INDX"="KSPPCV"."INDX")
   9 - filter("KSPPI"."KSPPINM"='_dml_monitoring_enabled')
  12 - filter(BITAND("O"."FLAGS",128)=0)
  13 - access("O"."OWNER#"=USERENV('SCHEMAID') AND "O"."NAME"='RESPONSES')
  14 - filter(BITAND("T"."PROPERTY",1)=0)
  15 - access("O"."OBJ#"="T"."OBJ#")
  17 - access("T"."TS#"="TS"."TS#")
  19 - access("T"."TS#"="S"."TS#"(+) AND "T"."FILE#"="S"."FILE#"(+) AND
              "T"."BLOCK#"="S"."BLOCK#"(+))
  20 - access("T"."BOBJ#"="CO"."OBJ#"(+))
  22 - access("T"."DATAOBJ#"="CX"."OBJ#"(+))
  24 - access("CX"."OWNER#"="CU"."USER#"(+))

 

by: ajexpertPosted on 2009-10-29 at 16:02:49ID: 25699046

The explain plan indicates there is FULL TABLE scan on RESPONSES.

Try gathering statistics on RESPONSES by following query

<USER> should be the schema name

exec dbms_stats.gather_table_stats(<USER>, 'RESPONSES');

 

 

by: virdi_dsPosted on 2009-10-29 at 16:06:12ID: 25699063

can you provide the output of
set autotrace off
select ini_trans from user_tables where table_name='RESPONSES';

select index_name, column_name, position where table_name='RESPONSE';

 

by: vadicherlaPosted on 2009-10-29 at 16:15:58ID: 25699106

SQL> set autotrace off
SQL> select ini_trans from user_tables where table_name='RESPONSES';

 INI_TRANS
----------
         1
 
can you please check second sql syntax

 

by: sventhanPosted on 2009-10-29 at 16:33:28ID: 25699184

how many rows do you have on those tables?

Its ok to do full tablescan if the table are small.

 

 

by: markgeerPosted on 2009-10-30 at 07:04:00ID: 25703031

Do you have a job scheduled to calculate table statistics regularly? (Usually weekly is enough.)
Which version of Oracle do you have?
What is your initialization parameter: OPTIMIZER_MODE set to?

 

by: virdi_dsPosted on 2009-10-30 at 07:23:53ID: 25703215

I am sorry here are the queries.

select index_name, column_name, COLUMN_POSITION from user_ind_columns where table_name='RESPONSE';

select count(*) from RESPONSE;


 

by: vadicherlaPosted on 2009-10-30 at 08:40:55ID: 25704044

Here is output from last_analyzed. Do you think we still run dbms_stats on this tables??

select table_name,num_rows,avg_row_len, last_analyzed from dba_tables where table_name in ('RESPONSES')

TABLE_NAME     NUM_ROWS    AVG_ROW_LEN          LAST_ANALYZED
RESPONSES      120780         19                            10/15/2009 10:00:05 PM
RESPONSES       0                 0                              10/5/2009  10:01:23 PM
RESPONSES     176680         19                           10/28/2009 10:01:39 PM
RESPONSES     2159746       20                            2/10/2009 10:00:54 PM


TABLE_NAME         NUM_ROWS       AVG_ROW_LEN           LAST_ANALYZED
SUBMISSIONS          120660               22                           10/15/2009 10:00:08 PM
SUBMISSIONS           0                      0                               10/5/2009 10:01:23 PM
SUBMISSIONS        176280                 22                           10/28/2009 10:01:44 PM
SUBMISSIONS       2172426                23                           2/10/2009 10:02:08 PM




OPTIONS_ID_RESP OPTION_ID 1
IDX_SUBMISSION_ID_REP SUBMISSION_ID 1
SURVEY_ID_RESP SURVEY_ID 1
QUESTION_ID_RESP QUESTION_ID 1
SYS_C004910 RESPONSE_ID 1


total records
191957

 

by: markgeerPosted on 2009-10-30 at 10:33:00ID: 25705155

Four rows returned for each table?  That surprises me!

Can you run that query this way (to include the table owner):

select owner, table_name,num_rows,avg_row_len, last_analyzed from dba_tables where table_name in ('RESPONSES','SUBMISSIONS')

 

by: vadicherlaPosted on 2009-10-30 at 11:40:12ID: 25705714

Here you go

OWNER         TABLE_NAME      NUM_ROWS      AVG_ROW_LEN            LAST_ANALYZED
DX_ATLAS         SUBMISSIONS      176280                           22                                    10/28/2009 22:01
DX_ATLAS    RESPONSES      176680                        19                                    10/28/2009 22:01

 

by: markgeerPosted on 2009-10-30 at 11:58:18ID: 25705861

Why is there only one row for each table now, but four rows earlier?  Do these two tables exist in other schemas in your database also (as the earlier results indicate, with different values for each of the rows)?

Which owner/schema does your applciation use?  Does it always use the same one?  Or, is it possible that some users connect to one schema, but other users connect to different one?

 

by: vadicherlaPosted on 2009-10-30 at 12:00:34ID: 25705880

this is correct data and this is the only schema used in production. You can ignore preview one. This is only schema used

 

by: markgeerPosted on 2009-10-30 at 12:07:23ID: 25705940

Try that first query like this:

SELECT /*+RULE */QUESTION_ID, OPTION_ID, COUNT (OPTION_ID) COUNT FROM RESPONSES WHERE SURVEY_ID = ? GROUP BY QUESTION_ID, OPTION_ID ORDER BY QUESTION_ID

This will instruct Oracle to use the older rule-based optimizer, instead of the (newer, more-complex, but usually better) cost-based optimizer.  The cost-based optimizer requires up-to-date table statistics, but you have those.  Are you sure that the survey_id column is indexed in that table, and that it is either the only or the first column in the index?

 

by: virdi_dsPosted on 2009-10-30 at 12:08:11ID: 25705944

Since there are nearly .17 milions record in RESPONSE table, full table scan is not good for Online.
Please provide the output of
select owner, index_name, column_name, COLUMN_POSITION from user_ind_columns where table_name='RESPONSE';

 

by: markgeerPosted on 2009-10-30 at 12:08:57ID: 25705948

Sorry, there should be space between "*/" and "QUESTION_ID" in that query.

 

by: vadicherlaPosted on 2009-10-30 at 12:23:51ID: 25706060

OUTPUT

INDEX_NAME               COLUMN_NAME               COLUMN_POSITION      
OPTIONS_ID_RESP                    OPTION_ID                                1      
IDX_SUBMISSION_ID_REP    SUBMISSION_ID                1      
SURVEY_ID_RESP                   SURVEY_ID                               1      
QUESTION_ID_RESP      QUESTION_ID              1      
SYS_C004910                RESPONSE_ID                             1      

 

by: vadicherlaPosted on 2009-10-30 at 12:27:17ID: 25706083

Here is create table script for responses table

CREATE TABLE RESPONSES
(
  RESPONSE_ID    NUMBER(10)                     NOT NULL,
  SURVEY_ID      NUMBER(10)                     NOT NULL,
  SUBMISSION_ID  NUMBER(10)                     NOT NULL,
  QUESTION_ID    NUMBER(10)                     NOT NULL,
  OPTION_ID      NUMBER(10)
)
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;


CREATE INDEX OPTIONS_ID_RESP ON RESPONSES
(OPTION_ID)
LOGGING
NOPARALLEL;


CREATE INDEX IDX_SUBMISSION_ID_REP ON RESPONSES
(SUBMISSION_ID)
LOGGING
NOPARALLEL;


CREATE INDEX SURVEY_ID_RESP ON RESPONSES
(SURVEY_ID)
LOGGING
NOPARALLEL;


CREATE INDEX QUESTION_ID_RESP ON RESPONSES
(QUESTION_ID)
LOGGING
NOPARALLEL;


CREATE UNIQUE INDEX RESPONSES_PK ON RESPONSES
(RESPONSE_ID)
LOGGING
NOPARALLEL;


ALTER TABLE RESPONSES ADD (
  CONSTRAINT RESPONSES_PK
 PRIMARY KEY
 (RESPONSE_ID));


ALTER TABLE RESPONSES ADD (
  CONSTRAINT QUESTIONS_RESPONSESS_FK
 FOREIGN KEY (QUESTION_ID)
 REFERENCES QUESTIONS (QUESTION_ID));

ALTER TABLE RESPONSES ADD (
  CONSTRAINT OPTIONS_RESPONSES_FK
 FOREIGN KEY (OPTION_ID)
 REFERENCES OPTIONS (OPTION_ID));

ALTER TABLE RESPONSES ADD (
  CONSTRAINT SUBMISSION_RESPONSES_FK4
 FOREIGN KEY (SUBMISSION_ID)
 REFERENCES SUBMISSIONS (SUBMISSION_ID));

ALTER TABLE RESPONSES ADD (
  CONSTRAINT SURVEYS_RESPONSES_FK
 FOREIGN KEY (SURVEY_ID)
 REFERENCES SURVEYS (SURVEY_ID));

 

by: markgeerPosted on 2009-10-30 at 12:33:10ID: 25706125

OK, that query indicates that you have a single-column index named: "SURVEY_ID_RESP' for the column: "SURVEY_ID" in the RESPONSES table.  For some reason though, the "explain plan" showed a full-table scan.  That is not good.  Did you try the query I suggested with the /*+RULE */ hint?  That way, it should use an index range scan.

 

by: vadicherlaPosted on 2009-10-30 at 12:38:13ID: 25706162

No perforemance improvement even with below sql

SELECT /*+RULE */ QUESTION_ID, OPTION_ID, COUNT (OPTION_ID) COUNT FROM RESPONSES WHERE SURVEY_ID = 200 GROUP BY QUESTION_ID, OPTION_ID ORDER BY QUESTION_ID

 

by: virdi_dsPosted on 2009-10-30 at 12:59:10ID: 25706311

I have another question. I want to know the highest count for each survery_id. Please provide the following query result. I don't want full output, but first 2 records.

set autotrace on
select survery_id, count(*) from response group by survery_id order by 2 desc;
select survery_id, count(*) from response group by survery_id order by 2 ;

Now we can see whats going on. First query will tell which survey_id has lots of records, and second query will tell least.
Is this query is running inside the loop?
Did you analyzed this table to collect histograms?

If you are using histograms, then possible, there is  one term called Bind Peaking, which may cause to choose wrong plan.
Just try to reanalyze the table without histograms ie by using 'column size 1' then retry executing this query.

 

by: vadicherlaPosted on 2009-10-30 at 13:34:35ID: 25706578

Does adding some compound index for these columns improve performance ??

 

by: virdi_dsPosted on 2009-10-30 at 14:00:12ID: 25706767

Since you are getting records from one table using one column, in this case, compound index will not help. I am interested in why oracle is not picking right index even if index is present.
There are many reason, why oracle is not picking an index, therefore I want you to provide survery_id with count(*).
Its not true that index will always improve performance. Therefore by calculating count on survery, we can understand why oracle is bypassing index.
secondly if you fire sql in pattern in such a way that query has to do full scan, then its possible next time oracle may not use hint. This feature is called bind peaking and you can do this experiment by creating procedure and trace your session.

 

by: markgeerPosted on 2009-10-30 at 14:39:49ID: 25706994

If there are lots of records (like 15% of the total, or more) that have the same value for survey_id, and if these records are scattered physically into many different blocks in the table, then possibly a full-table scan is the most efficient path that Oracle can choose.  (The queries that virdi_vs gave you that include "count(*)" will tell us that.)

 

by: vadicherlaPosted on 2009-10-30 at 15:12:09ID: 25707129

Pleae find below
select survery_id, count(*) from response group by survery_id order by 2 desc;
 
100;     120780
200;       74805

select survery_id, count(*) from response group by survery_id order by 2 ;

200;        74808
100;         120780

 

by: virdi_dsPosted on 2009-10-30 at 15:39:46ID: 25707228

As per data, I believe you have only two survery_id 100 and 200. Using index on any of them will degrade performance because for each row of index, oracle has to scan table, therefore there are nearly 2 IOs involved for each record.
Since you want data in online, you can go for full table scan with DB_FILE_MULTIBLOCK_READ_COUNT=0 before running this query or set appropriate value for this parameter at session or use PARALLEL hint.
Third option is to reorganize your table and create two partitions. Then you can speedup the query by scaning only one partion.
Right now oracle has to scan all blocks.

 

by: vadicherlaPosted on 2009-10-30 at 15:44:01ID: 25707247

This quries are called from java code. we have lot of data in this tables which we never deleted.  May this is reason it causing the issue.

If we delete old data from these tables which is no use will fix the issue??

 

by: virdi_dsPosted on 2009-10-30 at 15:51:13ID: 25707270

Yes, less data will always give good performance. But if management wants to keep old data for 2 years, then you have to move this data either to some other table or just create another partition and move to that partition.
Syntax for partition scan is
select * from table_name partition(partition_name);
and this statement can be easily control from java code. Based on data, java can rewrite the query to use appropriate partition.

 

by: vadicherlaPosted on 2009-10-30 at 15:51:23ID: 25707271

Survey id is for foregn key. You want to delete index in this table or primary table  for survey id??

 

by: virdi_dsPosted on 2009-10-30 at 15:57:03ID: 25707299

Deleting foreign key index creates other problem. So do not delete any index, any point of time you may need index. For data consistency, keep PK and FK as well.
Do not change constraints/indexes. My point is first delete unwanted records from Parent and Child tables. if management doesn't allow you to delete, then second option is to reorganize primary/child table with 3 partitions. First for survey_id 100, second for 200 and third for old data. This way you can save Full table scan.
By doing this you all constraints/indexes can be maintained as well.

 

by: vadicherlaPosted on 2009-10-30 at 16:10:06ID: 25707356

The survey_id table have only two records 100 and 200.  This is seed data. and table name is survey. So we dont have anyting to delete as it got only seed data

 

by: markgeerPosted on 2009-10-30 at 17:53:01ID: 25707835

"If we delete old data from these tables which is no use will fix the issue??"
No.

A delete by itself will not improve performance at all.  But, if you then do an "alter table ... move...", or export the remaining data, then truncate the table, then import the data you exported, you will get better performance because those actions will reset the "high water mark" for the table.  That, is the number of blocks that have been used for data.  Simply doing a delete does not ever move this lower, so in a full-table scan, Oracle still has to read all of the blocks up to the high-water mark, even if some of them are now empty.

 

by: vadicherlaPosted on 2009-10-30 at 19:07:35ID: 25708060

In 10g we have  shrink command which can do this operation instead of moving the data to duplicate table.

 

by: virdi_dsPosted on 2009-10-31 at 08:26:44ID: 25710100

Now you have lots of tuning option for this query.
1. removal of old data, and (truncate or shrink or rebuild)
2. make partion on survey_id
3. use of parallel hint.

 

by: vadicherlaPosted on 2009-10-31 at 12:49:28ID: 25711245

If i execute the query from toad in production server the cost is only 150 and query runs very fast. This sql query is coming from java code so we need to make code in java, it involved lot of process and approvals.

Do we have any option to fix at database level apart form truncate or shrink Also can you give some example for partion and parallel hit syntax statement

 

by: vadicherlaPosted on 2009-11-01 at 10:59:35ID: 25714899

From belwo output we can see survey_id 100  is having more number of records compare to survey_id 200. Now we are not using this survey_id 100 and this data can be deleted from production. Once we delete this data and cleaning up water mark by running shink command. Does this improve performance of query ??
Pleae find below
select survery_id, count(*) from response group by survery_id order by 2 desc;
 
100;     120780
200;       74805

select survery_id, count(*) from response group by survery_id order by 2 ;

200;        74808
100;         120780

 

by: markgeerPosted on 2009-11-02 at 06:00:01ID: 25719287

Yes, if you delete the records for survey _id 100, then shrink the table, or do an "alter table ... move..." command, you will get better performance.  Another option that may be even faster, but that will require a little bit (maybe a couple minutes) of application downtime would be to:
1. create a script to recreate the grants, constraints, default values and triggers on the current table (or do a no-rows  export of the table)
2. rename the current table
3. create a new table as "select * from [renamed_table] where survy_id = 100"
4. drop the original table
5. run the script to create the grants, constraints, default values and triggers (or run import to do that)

 

by: virdi_dsPosted on 2009-11-02 at 08:36:09ID: 25720869

Remember if you are deleting records, it is possible that one of the required record is very near to HWM and therefore to avoide any internal fragmentation you have to rebuild the table using Move or Rebuild command of alter table.

 

by: vadicherlaPosted on 2009-11-03 at 12:33:11ID: 25733267

Hey markqeer

Can you please tell me more about trigger approach. So u want trigger in place for inserting or something ??
Thanks

 

by: sventhanPosted on 2009-11-03 at 13:14:49ID: 25733744

@ vadicherla:

Did you get what mark had said? Just make a copy of your db objects related to that table you're rebuilding. If it has triggers just make a copy of it, so it could help.

Just try to close the thread you've already got all you wanted.

 

by: markgeerPosted on 2009-11-03 at 13:35:11ID: 25734028

No.  I just mentioned triggers along with constraints, default values, indexes and grants as things that you have to recreate manually *IF* you use the approach of creating a new table to hold the records for survey_id 200.  I don't know if your table has any of these or not, but if it does, you need to copy them to the new table.

I also see a mistake in that 5-step plan that I suggested.  Step 3 should be:
3. create a new table as "select * from [renamed_table] where survey_id = 200"

 

by: x77Posted on 2009-11-05 at 10:02:38ID: 25752116

You are a Join (View) then Group Information.
To obtain best performance, you need Group Information of related table then do the Join.
Using the view, the query is correct, no performance can gain.
Note that use of indexes to Join are not mandatory, you can use
   (Select key,Count(*) From Table1 [where Filter Condition] group by Key) T
as a Subquery to the join

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...