Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6801385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:05:37+00:00 2026-05-26T19:05:37+00:00

I’ve written a query in SQL that selects some columns from a table.My problem

  • 0

I’ve written a query in SQL that selects some columns from a table.My problem is this,when I execute this query in Oracle 10g,it takes about 7 seconds, but next time it executes in a few milisecond.If I change the where clause, it takes more than 5 seconds again.
How can I speed up this query at first time?The query is like this :

SELECT Id,Qflag, LetterId, LetterNo, LetterDate, InstanceDate, ViewDate, DeadlineDate 
FROM VWLETTERINSTANCESEARCH 
WHERE ( QFLAG IS NULL OR QFLAG = 0 ) AND 
  EXISTS(SELECT * FROM VWLETTERINSTANCESEARCH VW 
         where PARENTINSTANCEID=VWLETTERINSTANCESEARCH.Id AND refSenderId=1947)AND 
  EXISTS(SELECT * FROM LetterInstances ChildInstance, Folders 
         WHERE ChildInstance.ParentInstanceId=VWLETTERINSTANCESEARCH.Id AND 
               ChildInstance.FolderId=Folders.Id AND Folders.OwnerId=23) AND 
  OwnerId IN (SELECT StaffId FROM vwStaffUsers WHERE UserId=2 AND Deleted=0)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:05:38+00:00Added an answer on May 26, 2026 at 7:05 pm

    The reason why it takes only a few millisecs to execute the query after the first run is that Oracle caches the results. If you change the SQL then Oracle considers it a different query and won’t serve the results from the cache but executes the new query.

    It is a hard question how to speed up first execution. You’ll need to post explain plan and probably you’ll have to answer further questions if you want to get help on that.

    My first try would be eliminate subqueries, although these days Oracle optimizes this quite well:

    SELECT DISTINCT VW1.Id, VW1.Qflag, VW1.LetterId, VW1.LetterNo, VW1.LetterDate, 
      VW1.InstanceDate, VW1.ViewDate, VW1.DeadlineDate 
    FROM 
      VWLETTERINSTANCESEARCH VW1,
      VWLETTERINSTANCESEARCH VW2,
      LetterInstances, ChildInstance, Folders, 
      vwStaffUsers SU
    WHERE ( QFLAG IS NULL OR QFLAG = 0 ) 
      AND (VW1.PARENTINSTANCEID=VW2.Id AND VW2.refSenderId=1947)
      AND (ChildInstance.ParentInstanceId=VW1.Id AND 
                   ChildInstance.FolderId=Folders.Id AND Folders.OwnerId=23) 
      AND (VW1.OwnerId = SU.StaffId AND SU.UserId=2 AND SU.Deleted=0)
    

    EDIT
    Also, I’d try to run the query only on the main table (i.e. VWLETTERINSTANCESEARCH VW1) and see if it is fast enough. Then I’d add the rest of the tables gradually, one by one, and see where the performance starts to degrade.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I have some data like this: 1 2 3 4 5 9 2 6
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.