Influencing the Choice of Reflections Used to Satisfy Queries
You can use Reflection hints to influence the process of determining which Reflections are substituted for tables and views to accelerate queries.
How Reflections are Substituted for Tables and Views
There are three phases in the determination of which plan to use for a query: Consider, Match, and Choose. The following sections describe how Reflections relate to these phases.
1. Consider
In this phase, the planner searches the existing Reflections for those that include columns that can satisfy the query. The planner also determines whether it can use a starflake Reflection.
2. Match
The planner generates replacement plans for the original user query. It searches through the Reflections from the Consider phase and tries to match each Reflection into alternative forms of the user query. Each successful match is then registered as a replacement plan. At this point, plan cost has not been considered, yet.
3. Choose
The planner explores all replacement sub-plans by using a dynamic programming approach with statistics, cost models and optimization rules as input. The lowest cost plan is chosen, where cost is a function of estimated row count, CPU, I/O, network, and memory.
Types of Reflection Hints
The types of hints are listed in the order in which they are applied.
consider_reflections
You can use a consider_reflection hint to reduce the amount of time spent devising query plans by restricting the number of Reflections that are considered to one or more. It causes the query planner to consider only the Reflections that you specify, rather than all existing Reflections. You pass in one or more Reflection IDs as parameters. If you do not pass in any Reflection IDs, the query planner considers all available Reflections.
This hint is ideal when the query planner must usually consider a large number of Reflections. You can speed up the planning process by providing a list of the only Reflections for the planner to consider. For example, after you run a query for the first time, you can look at the Acceleration section of the raw profile of the job that ran the query. Then, you can add the consider_reflection hint and provide the ID of the Reflection that was used the first time the query ran.
SELECT /*+ consider_reflections(“3dd4bd60-6a9e-422c-a4ee-556973223602”, "09638927-7d70-499f-89cc-7bd60dec50a8") */ pickup_datetime, passenger_count
FROM Samples."samples.dremio.com"."NYC-taxi-trips-iceberg";
exclude_reflections
You can use an exclude_reflections hint to reduce the amount of time spent devising query plans by preventing one or more Reflections from being considered. It causes the query planner to consider none of the Reflections that you specify. You pass in one or more Reflection IDs as parameters.
This hint is ideal when the cost-based optimizer has chosen a query plan that uses suboptimal Reflection and you want to direct the optimizer to generate a plan without it. For example, suppose that a particular Reflection is continually used to satisfy a query, even though you have created a Reflection that you want to use. You could use this hint to prevent the first Reflection from being considered.
Example of setting this hint for a single querySELECT /*+ exclude_reflections(“3dd4bd60-6a9e-422c-a4ee-556973223602”, "09638927-7d70-499f-89cc-7bd60dec50a8") */ pickup_datetime, passenger_count
FROM Samples."samples.dremio.com"."NYC-taxi-trips-iceberg";
no_reflections
You can use a no_reflections hint to prevent query plans from using Reflections. It causes the query planner not to consider any Reflections for a query.
SELECT /*+ no_reflections */ pickup_datetime, passenger_count
FROM Samples."samples.dremio.com"."NYC-taxi-trips-iceberg";
choose_reflections
You can use a choose_reflections hint to force the optimizer to choose query plans that use particular matched Reflections. It causes the optimizer to prioritize query plans that use one or more Reflections over all of the others. You pass in one or more Reflection IDs as parameters.
-
If any of the query plans passed to the optimizer are listed in the
choose_reflectionshint, the cost-based optimizer is forced to pick the lowest cost plan containing at least one of the listed Reflections. -
If none of the query plans passed to the optimizer are listed in the
choose_reflectionshint, the optimizer is free to pick the lowest cost plan. -
If no Reflections are listed in the
choose_reflectionshint, the optimizer is free to pick the lowest cost plan.
SELECT /*+ choose_reflections(“3dd4bd60-6a9e-422c-a4ee-556973223602”, "09638927-7d70-499f-89cc-7bd60dec50a8") */ pickup_datetime, passenger_count
FROM Samples."samples.dremio.com"."NYC-taxi-trips-iceberg";
current_iceberg_data_only
For Reflections created on tables in Iceberg format, you can use a current_iceberg_data_only hint to prevent query plans from using Reflections that are not updated to the same versions of base tables.
After an Iceberg table is updated, it may take up to 30 seconds for the Reflection manager to mark a Reflection as not-current based on the updated table and exclude the Reflection from queries. The Reflection manager marks Reflections as current again when they are refreshed.
Example of setting this hint for a single querySELECT /*+ current_iceberg_data_only */ pickup_datetime, passenger_count
FROM Samples."samples.dremio.com"."NYC-taxi-trips-iceberg";