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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:38:25+00:00 2026-06-18T20:38:25+00:00

I have a query that I would like to save as a view: WITH

  • 0

I have a query that I would like to save as a view:

WITH subquery AS ( SELECT aaa_id, ... FROM table_aaa ... )
SELECT subquery.aaa_id, ... FROM table_bbb JOIN subquery USING ( ... )
;

[NOTE: In real-life, my query is much more complicated than this, with several WITH sub-queries, many performing JOINS, all being JOINed together. But I’m looking for general guidance that I can use to work into my problem.]

The execution for this query include full table scans. This makes sense since there are no criteria included in a WHERE clause. However, I can eliminate most of the full table scans by including such a clause:

WITH subquery AS ( SELECT aaa_id, ... FROM table_aaa ... WHERE aaa_id = :id)
SELECT subquery.aaa_id, ... FROM table_bbb JOIN subquery USING ( ... )
;

However, it doesn’t seem that I have the option of putting the WHERE condition in the right place when I create the view:

CREATE OR REPLACE VIEW vw_my_view AS
WITH subquery AS ( SELECT aaa_id, ... FROM table_aaa ... )
SELECT subquery.aaa_id, ... FROM table_bbb JOIN subquery USING ( ... )
;

SELECT ... FROM vw_my_view WHERE aaa_id = :id
;

In this case, the execute plan still contains the full table scans. Is there a way for me to hint that the WHERE clause can actually be inserted into the WITH sub-query?

  • 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-18T20:38:27+00:00Added an answer on June 18, 2026 at 8:38 pm

    I’ve had similar experiences and while I have no general solution, I would suggest the following:

    • run “SELECT * FROM v$parameter2;” and make sure that _complex_view_merging is on. There was a nasty bug in one of the early 10g releases that was related to it so some dbas turned it off and might have forgotten to turn it back on once it was fixed.

    • Leave all consideration about hints as a last measure. In my experience, they’re rarely useful for preventing full table scans because the optimizer is already doing everything it can to avoid them.

    • If you have a base table whose primary key is what you’re ultimately going to be filtering the view on, try to set things up so that your view’s main query starts with that and then joins to your complicated with clause queries, even if that join is completely redundant (i.e. give oracle a chance to do easy filtering on that base table before joining to the complicated bits). Make sure that the columns that the view is going to be filtered on are selected directly from that base table and not the complicated_query. So something like

    .

         with (complicated_query)
         select base_table.key1, complicated_query.*
         from base_table
         join complicated_query on base_table.key1 = complicated_query.key1;
    
    • If you have filters that use an uncorrelated subquery, try switching them to a correlated equivalent (and vice versa).

    • Play around with the order of your join statements and/or which table you start out with in your FROM clause, even if logically it will not make a difference to the outcome. This is a bit of a desperate gambit, but I’ve definitely had execution plans change for the better by doing this. Optimizing Oracle queries is not always a rational process.

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

Sidebar

Related Questions

I have a query that looks like this SELECT * from myTable WHERE Date
I have a MySQL query that I would like to optimize a little bit.
I have the following query that works well. SELECT DISTINCT city,region1,region2 from static_geo_world where
i have a query that goes like this: $get_feed_amount = mysql_query( SELECT COUNT(*) as
I have a query that aggregates and groupes from 2 different tables: SELECT co.name
I have an application that allows users to save events. I would like to
I have a query that always returns one row, with many columns. I would
I am using in C# MYsql .I have query that works if I run
I have a query that successfully grabs the unique products from my products table
I have a query that basically combines tables of actions and selects from them

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.