Note that there are some explanatory texts on larger screens.

plurals
  1. POOracle query rewrite with virtual columns in the source table
    primarykey
    data
    text
    <p>I have a table, demo_fact in Oracle 11g and it has several virtual columns defined as such:</p> <pre><code>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); </code></pre> <p>Then I have a materialized view defined as</p> <pre><code>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 </code></pre> <p>Now I want Query Rewrite to kick in on the following query:</p> <pre><code>SELECT demo_dim_one, SUM(demo_measure_from_virtual) FROM demo_fact GROUP BY demo_dim_one </code></pre> <p>but it doesn't. I ran EXPLAIN_REWRITE on and here is the output:</p> <pre><code>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 </code></pre> <p>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)</p> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload