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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:14:25+00:00 2026-05-19T17:14:25+00:00

I have a table, demo_fact in Oracle 11g and it has several virtual columns

  • 0

I have a table, demo_fact in Oracle 11g and it has several virtual columns defined as such:

ALTER TABLE demo_fact ADD (demo_measure_from_virtual NUMBER GENERATED ALWAYS AS
  (CASE WHEN  demo_category_column = 20 THEN demo_numericdata_column ELSE 0 END)
  VIRTUAL VISIBLE);

Then I have a materialized view defined as

CREATE MATERIALIZED VIEW demo_agg_mv 
REFRESH FORCE ON DEMAND
ENABLE QUERY REWRITE
AS 
SELECT
  demo_dim_one,
  demo_dim_two,
  SUM(demo_measure_from_virtual) demo_measure_from_virtual
  FROM demo_fact
  GROUP BY demo_dim_one, demo_dim_two

Now I want Query Rewrite to kick in on the following query:

SELECT demo_dim_one, SUM(demo_measure_from_virtual) 
FROM demo_fact
GROUP BY demo_dim_one

but it doesn’t. I ran EXPLAIN_REWRITE on and here is the output:

QSM-01150: query did not rewrite
QSM-01102: materialized view, DEMO_AGG_MV, requires join back to table, 
           DEMO_FACT, on column, DEMO_MEASURE_FROM_VIRTUAL
QSM-01082: Joining materialized view, DEMO_AGG_MV, with table, DEMO_FACT, 
           not possible
QSM-01102: materialized view, DEMO_AGG_MV, requires join back to table, 
           DEMO_FACT, on column, DEMO_NUMERICDATA_COLUMN

Backstory: I’m doing this with 70M rows and 50 virtual columns (all of them have the same structure, the simple case statement above, but with a different comparison column and a different result column)

This problem seems to only manifest when the fact table has virtual columns, but changing them to non-virtual would consume too much diskspace. Why isn’t Oracle rewriting the query? What can I do to fix it?

  • 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-19T17:14:26+00:00Added an answer on May 19, 2026 at 5:14 pm

    I don’t know how helpful this is for you but Oracle requires all columns that the materialzied view grouped on to be included in the statement to be rewritten. (edit at least in conjunction with virtual columns. This is probably “not by design”…)

    If you try to explain_rewrite on

     select
        demo_dim_one,
        sum(s)
     from (
        select 
          demo_dim_one,
          sum(demo_measure_from_virtual) s
        from 
           demo_fact
        group by
          demo_dim_one,
          demo_dim_two
     )
     group by demo_dim_one
    

    it should tell you that it has rewritten the query.

    This can be demonstrated like so:

    A table to on which the virtual column will be defined:

    create table tq84_virt_col (
      a  varchar2(2),
      b varchar2(2),
      c  number,
      d  number 
    );
    
    
    insert into tq84_virt_col values ('A', 'X',  1, 1);
    insert into tq84_virt_col values ('A', 'X',  2, 1);
    insert into tq84_virt_col values ('A', 'Y',  3, 0);
    insert into tq84_virt_col values ('A', 'Y',  4, 1);
    
    insert into tq84_virt_col values ('B', 'Y', 11, 1);
    insert into tq84_virt_col values ('B', 'X', 12, 0);
    insert into tq84_virt_col values ('B', 'X', 13, 1);
    

    The definition of the virtual column:

    alter table tq84_virt_col add (
      virt_col number generated always as (
        case when d = 1 then c else 0 end
      )
      virtual visible
    );
    

    The materialized view. Note: it groups on columns a and b:

    create materialized view tq84_mat_view
    refresh force on demand
    enable query rewrite
    as 
    select 
      a, b,
      sum(virt_col) sum_virt_col
    from
      tq84_virt_col
    group by 
      a,b 
    

    The materialized view will not be used, as you have observed:

    begin
      dbms_mview.explain_rewrite(
        'select a, sum(virt_col) from tq84_virt_col group by a'
      );
    end;
    /
    
    select message
    from rewrite_table;
    
    QSM-01150: query did not rewrite
    QSM-01102: materialized view, TQ84_MAT_VIEW, requires join back to table, TQ84_VIRT_COL, on column, VIRT_COL
    QSM-01082: Joining materialized view, TQ84_MAT_VIEW, with table, TQ84_VIRT_COL, not possible
    QSM-01102: materialized view, TQ84_MAT_VIEW, requires join back to table, TQ84_VIRT_COL, on column, C
    

    Now, both columns a and b are selected and grouped on (with an outer query to ensure the same result set):

    truncate table rewrite_table;
    
    begin
      dbms_mview.explain_rewrite(
        'select a, sum(s) from (select a, sum(virt_col) s from tq84_virt_col group by a, b) group by a'
      );
    end;
    /
    
    select message
    from rewrite_table;
    
    QSM-01151: query was rewritten
    QSM-01209: query rewritten with materialized view, TQ84_MAT_VIEW, using text match algorithm
    QSM-01219: no suitable materialized view found to rewrite this query
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two columns(column1, column2) in my oracle database table named as demo .
I have a table part with a few demo data as below in Oracle
I have this table: create table demo ( key number(10) not null, type varchar2(3)
I have a simple fixed width table. The first column has a fluid width
I have a table with these columns create table demo ( ID integer not
I have a table with some data values. I would like to add styles
I have a HTML table which consists of 5 columns. Above the HTML table,
I have a table with only two columns . i want to make first
I have a table that has some content in it. Not all rows has
I have the Demo Table which I can click on the cell(td tag) and

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.