Using Apache Hive
Also available as:
PDF

Manage rewriting of a query

You can use a Hive query to stop or start the optimizer from rewriting a query based on a materialized view, and as administrator, you can globally enable or disable rewriting of all queries based on materialized views.

By default, the optimizer can rewrite a query based on a materialized view. If you want a query executed without regard to a materialized view, for example to measure the execution time difference, you can disable rewriting and then enable it again.

  1. Disable rewriting of a query based on a materialized view named mv1 in the default database.
    ALTER MATERIALIZED VIEW default.mv1 DISABLE REWRITE;
  2. Enable rewriting of a query based on materialized view mv1.
    ALTER MATERIALIZED VIEW default.mv1 ENABLE REWRITE;
  3. Globally disable rewriting of queries based on materialized views by setting a global property.
    SET hive.materializedview.rewriting=true;