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

  • Home
  • SEARCH
  • 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 8251349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:12:27+00:00 2026-06-08T00:12:27+00:00

I had the following query: SELECT nvl(sum(adjust1),0) FROM ( SELECT ManyOperationsOnFieldX adjust1, a, b,

  • 0

I had the following query:

SELECT nvl(sum(adjust1),0)
FROM (
  SELECT
    ManyOperationsOnFieldX adjust1,
    a, b, c, d, e
  FROM (
    SELECT
      a, b, c, d, e,
      SubStr(balance, INSTR(balance, '[&&2~', 1, 1)) X
    FROM
      table
    WHERE
      a >= To_Date('&&1','YYYYMMDD')
      AND a < To_Date('&&1','YYYYMMDD')+1
  )
)
WHERE
  b LIKE ...
  AND e IS NULL
  AND adjust1>0
  AND (b NOT IN ('...','...','...'))
  OR  (b = '... AND c <> NULL)

I tried to change it to this:

SELECT nvl(sum(adjust1),0)
FROM (
  SELECT
    ManyOperationsOnFieldX adjust1
  FROM (
    SELECT
      SubStr(balance, INSTR(balance, '[&&2~', 1, 1)) X
    FROM
      table
    WHERE
      a >= To_Date('&&1','YYYYMMDD')
      AND a < To_Date('&&1','YYYYMMDD')+1
      AND b LIKE '..'
      AND e IS NULL
      AND (b NOT IN ('..','..','..'))
      OR  (b='..' AND c <> NULL)
  )
)
WHERE
  adjust1>0

Mi intention was to have all the filtering in the innermost query, and only give to the outer ones the field X which is the one I have to operate a lot. However, the firts (original) query takes a couple of seconds to execute, while the second one won’t even finish. I waited for almost 20 minutes and still I wouldn’t get the answer.

Is there an obvious reason for this to happen that I might be overlooking?

These are the plans for each of them:

SELECT STATEMENT optimizer=all_rows (cost = 973 Card = 1 bytes = 288)
  SORT (aggregate)
    PARTITION RANGE (single) (cost=973 Card = 3 bytes = 864)
      TABLE ACCESS (full) OF "table" #3 TABLE Optimizer = analyzed(cost=973 Card = 3 bytes=564)


SELECT STATEMENT optimizer=all_rows (cost = 750.354 Card = 1 bytes = 288)
  SORT (aggregate)
    PARTITION RANGE (ALL) (cost=759.354 Cart = 64.339 bytes = 18.529.632)
      TABLE ACCESS (full) OF "table" #3 TABLE Optimizer = analyzed(cost=750.354 Card = 64.339 bytes=18.529.632)
  • 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-06-08T00:12:29+00:00Added an answer on June 8, 2026 at 12:12 am

    It is all about your OR… Try this:

    SELECT nvl(sum(adjust1),0)
    FROM (
      SELECT
        ManyOperationsOnFieldX adjust1
      FROM (
        SELECT
          SubStr(balance, INSTR(balance, '[&&2~', 1, 1)) X
        FROM
          table
        WHERE
          a >= To_Date('&&1','YYYYMMDD')
          AND a < To_Date('&&1','YYYYMMDD')+1
          AND (
              b LIKE '..'
              AND e IS NULL
              AND (b NOT IN ('..','..','..'))
              OR  (b='..' AND c <> NULL)
          )
      )
    )
    WHERE
      adjust1>0
    

    Because you have the OR inline with the rest of your AND statements with no parenthesis, the 2nd version isn’t limiting the data checked to just the rows that fall in the date filter. For more info, see the documentation of Condition Precedence

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

Sidebar

Related Questions

If I had the following query: select some cols from tbl_a INNER JOIN tbl_b
I have the following query (MySQL): SELECT col1, col2 FROM database1.table ->WHERE col3 !=
For example, if I had the following query: select * from msgs as e
By taking reference from here I had made the following query: SELECT INSTITUTE.ID INST_ID,
I'm trying to do MySQL fulltext search using the following query: SELECT * FROM
I have the following piece of sql query: Sql += SELECT ISNULL(SUM(COALESCE (a.currency, 0)),
I have the following query: SELECT * FROM my_users as U RIGHT JOIN subscribers
I had run following query in Oracle Database and produces following output: Query: select
I have the following query: SELECT location, step, COUNT(*), AVG(foo), YEAR(start), MONTH(start), DAY(start) FROM
I have the following query: SELECT patient_id FROM patient_visit where visit_type in ('A', 'B',

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.