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 6789251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:34:53+00:00 2026-05-26T17:34:53+00:00

I need some help working out how to make my query more efficient. I’m

  • 0

I need some help working out how to make my query more efficient. I’m by no means an expert with SQL but have read a fair bit regarding this but am at the point where I need to ask / discuss.

I have the following query:

SELECT * FROM
(
SELECT
a.seq_num seq_num_a,
a.record_length record_length_a,
b.record_length record_length_b,
c.record_length record_length_c
a.deleted deleted_a,
b.deleted deleted_b,
c.deleted deleted_c
FROM tableA a
INNER JOIN tableB b
ON a.reference = b.reference
AND a.run_id = b.run_id
INNER JOIN tableC c
ON a.reference = c.reference
AND a.run_id = c.run_id
WHERE a.run_id = 1
)
WHERE deleted_a = 'N'
AND deleted_b = 'N'
AND deleted_c = 'N'
ORDER BY seq_num_a;

The query is very slow once I check that deleted = ‘N’ – even for just tableA. I wrapped the whole query in a SELECT thinking that the subquery would return the dataset, then it would be a simple check and order against that. Note that there is no performance difference with the check within the subquery.

There are indexes against run_id and deleted in all tables, and against the seq_num in tableA. There are roughly 8000 rows in each table.

The query plan

--------------------------------------------------------------------------------------
| Id  | Operation                      |  Name               | Rows  | Bytes | Cost  |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT               |                     |     1 |   112 |     7 |
|   1 |  SORT ORDER BY                 |                     |     1 |   112 |     7 |
|   2 |   NESTED LOOPS                 |                     |     1 |   112 |     3 |
|   3 |    NESTED LOOPS                |                     |     1 |    79 |     2 |
|   4 |     TABLE ACCESS BY INDEX ROWID| TABLEC              |     1 |    33 |     2 |
|*  5 |      INDEX SKIP SCAN           | TABLEC_IDX2         |     1 |       |     2 |
|*  6 |     TABLE ACCESS BY INDEX ROWID| TABLEA              |     1 |    46 |       |
|*  7 |      INDEX RANGE SCAN          | TABLEA_IDX5         |     1 |       |       |
|*  8 |    TABLE ACCESS BY INDEX ROWID | TABLEB              |     1 |    33 |     1 |
|*  9 |     INDEX UNIQUE SCAN          | TABLEB_PK           |     1 |       |       |
--------------------------------------------------------------------------------------

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

   5 - access("C"."DELETED"='N')
       filter("C"."DELETED"='N')
   6 - filter("A"."REFERENCE"="C"."REFERENCE" AND 
              "A"."RUN_ID"="C"."RUN_ID")
   7 - access("A"."DELETED"='N')
   8 - filter("B"."DELETED"='N')
   9 - access("A"."RUN_ID"="B"."RUN_ID" AND 
              "A"."REFERENCE"="B"."REFERENCE")

Note: cpu costing is off
  • 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-26T17:34:54+00:00Added an answer on May 26, 2026 at 5:34 pm

    Not sure what value the outer select was providing.. depending on the version of oracle the explain plans can be different. but in older versions I found limiting the data before the joins improved performance dramatically.

    Thus starting with A and getting the least amount of records to join to b then to C was MUCH faster than starting with all of A, joining to all of b, and joining to all of C then reducing the results via where clause… However later verions of the query optimizer took this into account so no gain… So… what version of oracle?

    SELECT
    a.seq_num seq_num_a,
    a.record_length record_length_a,
    b.record_length record_length_b,
    c.record_length record_length_c
    a.deleted deleted_a,
    b.deleted deleted_b,
    c.deleted deleted_c
    FROM tableA a
    INNER JOIN tableB b
      ON a.reference = b.reference
      AND a.run_id = b.run_id
      AND a.deleted = 'N'
      and b.deleted = 'N'
      and a.run_ID = 1
    INNER JOIN tableC c
      ON a.reference = c.reference
      AND a.run_id = c.run_id
      and c.deleted = 'N'
    ORDER BY seq_num_a;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with jQuery for the first time and need some help. I have
I need some help from the shell-script gurus out there. I have a .txt
I really need some help in Regular Expressions, i'm working on a function like
Need some help about with Memcache. I have created a class and want to
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
Need some help assigning a mouseover event to display some icons that start out
I'm new to working with arrays so I need some help. With getting just
Okay, I am stumped on this one and need some quick help. I have

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.