Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-11020

Reorder joins only to eliminate cross joins

    XMLWordPrintableJSON

Details

    Description

      Currently, we don't reorder join and rely on the order provided by the user. This is fine for most of the cases, however, it limits the set of supported SQL queries.

      Example:

      val streamUtil: StreamTableTestUtil = streamTestUtil()
      streamUtil.addTable[(Int, String, Long)]("MyTable", 'a, 'b, 'c.rowtime, 'proctime.proctime)
      streamUtil.addTable[(Int, String, Long)]("MyTable2", 'a, 'b, 'c.rowtime, 'proctime.proctime)
      streamUtil.addTable[(Int, String, Long)]("MyTable3", 'a, 'b, 'c.rowtime, 'proctime.proctime)
      val sqlQuery =
            """
              |SELECT t1.a, t3.b
              |FROM MyTable3 t3, MyTable2 t2, MyTable t1
              |WHERE t1.a = t3.a AND t1.a = t2.a
              |""".stripMargin
      
      streamUtil.printSql(sqlQuery)
      

      Given the current rule sets, this query produces a cross join which is not supported and thus leads to:

      org.apache.flink.table.api.TableException: Cannot generate a valid execution plan for the given query: 
      
      LogicalProject(a=[$8], b=[$1])
        LogicalFilter(condition=[AND(=($8, $0), =($8, $4))])
          LogicalJoin(condition=[true], joinType=[inner])
            LogicalJoin(condition=[true], joinType=[inner])
              LogicalTableScan(table=[[_DataStreamTable_2]])
              LogicalTableScan(table=[[_DataStreamTable_1]])
            LogicalTableScan(table=[[_DataStreamTable_0]])
      
      This exception indicates that the query uses an unsupported SQL feature.
      Please check the documentation for the set of currently supported SQL features.
      

      Introducing JoinPushThroughJoinRule would help but should only be applied if a cross join is the only alternative.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              twalthr Timo Walther
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: