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

Hoist literals

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None

    Description

      Convert literals into (internal) bind variables so that statements that differ only in literal values can be executed using the same plan.

      In mail thread Homer wrote:

      Imagine that it is common to run a large number of very similar machine generated queries that just change the literals in the sql query.

      For example (the real queries would be much more complex):

      Select * from emp where empno = 1;
      Select * from emp where empno = 2;
      etc.

      The plan that is likely being generated for these kind of queries is going to be very much the same each time, so to save some time, I would like to recognize that the literals are all that have changed in a query and use the previously optimized execution plan and just replace the literals.

      I think this could be done as a transform on the initial RelNode tree. It would find literals (RexLiteral), replace them with bind variables (RexDynamicParam) and write the value into a pool. The next statement would go through the same process and the RelNode tree would be identical, but with possibly different values for the bind variables.

      The bind variables are of course internal; not visible from JDBC. When the statement is executed, the bind variables are implicitly bound.

      Statements would be held in a Guava cache.

      This would be enabled by a config parameter. Unfortunately I don't think we could do this by default – we'd lose optimization power because we would no longer be able to do constant reduction.

      Attachments

        1. HoistedVariables.png
          6 kB
          Scott Reynolds

        Issue Links

          Activity

            People

              julianhyde Julian Hyde
              julianhyde Julian Hyde
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h