SQL Hints

    SQL hints can be used with SQL statements to alter execution plans. This chapter explains how to use hints to force various approaches.

    • Enforce planner: there’s no perfect planner, so it makes sense to implement hints to allow user better control the execution;
    • Append meta data(or statistics): some statistics like “table index for scan” and “skew info of some shuffle keys” are somewhat dynamic for the query, it would be very convenient to config them with hints because our planning metadata from the planner is very often not that accurate;
    • Operator resource constraints: for many cases, we would give a default resource configuration for the execution operators, i.e. min parallelism or managed memory (resource consuming UDF) or special resource requirement (GPU or SSD disk) and so on, it would be very flexible to profile the resource with hints per query(instead of the Job).

    Dynamic table options allows to specify or override table options dynamically, different with static table options defined with SQL DDL or connect API, these options can be specified flexibly in per-table scope within each query.

    In order to not break the SQL compatibility, we use the Oracle style SQL hint syntax:

    Examples

    1. CREATE TABLE kafka_table1 (id BIGINT, name STRING, age INT) WITH (...);
    2. CREATE TABLE kafka_table2 (id BIGINT, name STRING, age INT) WITH (...);
    3. select id, name from kafka_table1 /*+ OPTIONS('scan.startup.mode'='earliest-offset') */;
    4. select * from
    5. join
    6. kafka_table2 /*+ OPTIONS('scan.startup.mode'='earliest-offset') */ t2
    7. on t1.id = t2.id;
    8. insert into kafka_table1 /*+ OPTIONS('sink.partitioner'='round-robin') */ select * from kafka_table2;