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
Attachments
Issue Links
- relates to
-
CALCITE-4087 Hoist, a utility to replace literals in a SQL string with placeholders
- Closed
- links to