EXPLAIN Statements

    Java

    EXPLAIN statements can be executed with the method of the TableEnvironment. The executeSql() method returns explain result for a successful EXPLAIN operation, otherwise will throw an exception.

    The following examples show how to run an EXPLAIN statement in TableEnvironment.

    Scala

    EXPLAIN statements can be executed with the executeSql() method of the TableEnvironment. The executeSql() method returns explain result for a successful EXPLAIN operation, otherwise will throw an exception.

    The following examples show how to run an EXPLAIN statement in TableEnvironment.

    EXPLAIN statements can be executed with the execute_sql() method of the TableEnvironment. The execute_sql() method returns explain result for a successful EXPLAIN operation, otherwise will throw an exception.

    The following examples show how to run an EXPLAIN statement in TableEnvironment.

    SQL CLI

    EXPLAIN statements can be executed in SQL CLI.

    The following examples show how to run an EXPLAIN statement in SQL CLI.

    Java

    1. val env = StreamExecutionEnvironment.getExecutionEnvironment()
    2. val tEnv = StreamTableEnvironment.create(env)
    3. // register a table named "Orders"
    4. tEnv.executeSql("CREATE TABLE MyTable1 (`count` bigint, word VARCHAR(256)) WITH ('connector' = 'datagen')")
    5. tEnv.executeSql("CREATE TABLE MyTable2 (`count` bigint, word VARCHAR(256)) WITH ('connector' = 'datagen')")
    6. // explain SELECT statement through TableEnvironment.explainSql()
    7. val explanation = tEnv.explainSql(
    8. "SELECT `count`, word FROM MyTable1 WHERE word LIKE 'F%' " +
    9. "UNION ALL " +
    10. "SELECT `count`, word FROM MyTable2")
    11. println(explanation)
    12. // explain SELECT statement through TableEnvironment.executeSql()
    13. val tableResult = tEnv.executeSql(
    14. "EXPLAIN PLAN FOR " +
    15. "SELECT `count`, word FROM MyTable1 WHERE word LIKE 'F%' " +
    16. "UNION ALL " +
    17. "SELECT `count`, word FROM MyTable2")
    18. tableResult.print()
    19. "EXPLAIN ESTIMATED_COST, CHANGELOG_MODE, JSON_EXECUTION_PLAN " +
    20. "SELECT `count`, word FROM MyTable1 WHERE word LIKE 'F%' " +
    21. "UNION ALL " +
    22. "SELECT `count`, word FROM MyTable2")

    Python

    SQL CLI

    1. Flink SQL> CREATE TABLE MyTable1 (`count` bigint, word VARCHAR(256)) WITH ('connector' = 'datagen');
    2. [INFO] Table has been created.
    3. Flink SQL> CREATE TABLE MyTable2 (`count` bigint, word VARCHAR(256)) WITH ('connector' = 'datagen');
    4. [INFO] Table has been created.
    5. Flink SQL> EXPLAIN PLAN FOR SELECT `count`, word FROM MyTable1 WHERE word LIKE 'F%'
    6. > UNION ALL
    7. > SELECT `count`, word FROM MyTable2;
    8. Flink SQL> EXPLAIN ESTIMATED_COST, CHANGELOG_MODE, JSON_EXECUTION_PLAN SELECT `count`, word FROM MyTable1
    9. > WHERE word LIKE 'F%'
    10. > UNION ALL
    11. > SELECT `count`, word FROM MyTable2;

    The EXPLAIN result is:

    EXPLAIN PLAN

    EXPLAIN PLAN WITH DETAILS

    1. == Abstract Syntax Tree ==
    2. LogicalUnion(all=[true])
    3. :- LogicalProject(count=[$0], word=[$1])
    4. : +- LogicalFilter(condition=[LIKE($1, _UTF-16LE'F%')])
    5. : +- LogicalTableScan(table=[[default_catalog, default_database, MyTable1]])
    6. +- LogicalProject(count=[$0], word=[$1])
    7. +- LogicalTableScan(table=[[default_catalog, default_database, MyTable2]])
    8. == Optimized Physical Plan ==
    9. Union(all=[true], union=[count, word], changelogMode=[I]): rowcount = 1.05E8, cumulative cost = {3.1E8 rows, 3.05E8 cpu, 4.0E9 io, 0.0 network, 0.0 memory}
    10. :- Calc(select=[count, word], where=[LIKE(word, _UTF-16LE'F%')], changelogMode=[I]): rowcount = 5000000.0, cumulative cost = {1.05E8 rows, 1.0E8 cpu, 2.0E9 io, 0.0 network, 0.0 memory}
    11. : +- TableSourceScan(table=[[default_catalog, default_database, MyTable1]], fields=[count, word], changelogMode=[I]): rowcount = 1.0E8, cumulative cost = {1.0E8 rows, 1.0E8 cpu, 2.0E9 io, 0.0 network, 0.0 memory}
    12. +- TableSourceScan(table=[[default_catalog, default_database, MyTable2]], fields=[count, word], changelogMode=[I]): rowcount = 1.0E8, cumulative cost = {1.0E8 rows, 1.0E8 cpu, 2.0E9 io, 0.0 network, 0.0 memory}
    13. == Optimized Execution Plan ==
    14. Union(all=[true], union=[count, word])
    15. : +- TableSourceScan(table=[[default_catalog, default_database, MyTable1]], fields=[count, word])
    16. +- TableSourceScan(table=[[default_catalog, default_database, MyTable2]], fields=[count, word])
    17. == Physical Execution Plan ==
    18. {
    19. "nodes" : [ {
    20. "id" : 37,
    21. "type" : "Source: TableSourceScan(table=[[default_catalog, default_database, MyTable1]], fields=[count, word])",
    22. "pact" : "Data Source",
    23. "contents" : "Source: TableSourceScan(table=[[default_catalog, default_database, MyTable1]], fields=[count, word])",
    24. "parallelism" : 1
    25. }, {
    26. "id" : 38,
    27. "type" : "Calc(select=[count, word], where=[LIKE(word, _UTF-16LE'F%')])",
    28. "pact" : "Operator",
    29. "contents" : "Calc(select=[count, word], where=[LIKE(word, _UTF-16LE'F%')])",
    30. "parallelism" : 1,
    31. "predecessors" : [ {
    32. "id" : 37,
    33. "ship_strategy" : "FORWARD",
    34. "side" : "second"
    35. } ]
    36. }, {
    37. "id" : 39,
    38. "type" : "Source: TableSourceScan(table=[[default_catalog, default_database, MyTable2]], fields=[count, word])",
    39. "pact" : "Data Source",
    40. "contents" : "Source: TableSourceScan(table=[[default_catalog, default_database, MyTable2]], fields=[count, word])",
    41. "parallelism" : 1
    42. } ]
    1. EXPLAIN [([ExplainDetail[, ExplainDetail]*]) | PLAN FOR] <query_statement_or_insert_statement>

    For query syntax, please refer to page. For INSERT, please refer to INSERT page.