Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-6162

Add rule(s) to remove joins with constant single tuple relations

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.37.0
    • core

    Description

      In various cases SQL users tend to create joins even when it is not really necessary. One common pattern is creating joins (or cartesian products) with constant relations with exactly one tuple.

      Q1
      Before:

      select e.empno, e.ename, c.* from emp e cross join (select 5, current_timestamp) c;
      

      After:

      select e.empno, e.ename, 5, current_timestamp from emp e;
      

      Q2
      Before:

      select e.empno, e.ename, c.t from emp e inner join (select 7934 as ono, current_timestamp as t) c on e.empno=c.ono;
      

      After:

      select e.empno, e.ename, current_timestamp from emp e where e.empno=7934;
      

      In the queries outlined above the one side of the join is constant and has exactly one tuple so the join can be dropped.

      In a nutshell the new rule(s) should be able to transform the "Before" to "After" for the above queries.

      Attachments

        Issue Links

          Activity

            People

              hanu.ncr Hanumath Rao Maduri
              zabetak Stamatis Zampetakis
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: