|
39 | 39 | import org.apache.drill.exec.physical.base.PhysicalOperator; |
40 | 40 | import org.apache.drill.exec.planner.fragment.Fragment; |
41 | 41 | import org.apache.drill.exec.planner.fragment.MakeFragmentsVisitor; |
| 42 | +import org.apache.drill.exec.planner.physical.PlannerSettings; |
42 | 43 | import org.apache.drill.exec.planner.sql.DirectPlan; |
43 | 44 | import org.apache.drill.exec.planner.sql.DrillSqlWorker; |
44 | 45 | import org.apache.drill.exec.proto.BitControl.PlanFragment; |
|
56 | 57 | import org.apache.drill.exec.rpc.UserClientConnection; |
57 | 58 | import org.apache.drill.exec.server.DrillbitContext; |
58 | 59 | import org.apache.drill.exec.server.FailureUtils; |
| 60 | +import org.apache.drill.exec.server.options.OptionManager; |
59 | 61 | import org.apache.drill.exec.server.options.OptionSet; |
60 | 62 | import org.apache.drill.exec.testing.ControlsInjector; |
61 | 63 | import org.apache.drill.exec.testing.ControlsInjectorFactory; |
@@ -595,23 +597,50 @@ private void logWorkUnit(QueryWorkUnit queryWorkUnit) { |
595 | 597 | queryId, queryWorkUnit.stringifyFragments())); |
596 | 598 | } |
597 | 599 |
|
598 | | - private void runSQL(final String sql) throws ExecutionSetupException { |
599 | | - final Pointer<String> textPlan = new Pointer<>(); |
| 600 | + private PhysicalPlan getOrBuildPlan(String sql, Pointer<String> textPlan, boolean planCacheEnabled) |
| 601 | + throws ExecutionSetupException { |
600 | 602 |
|
601 | | - PhysicalPlan plan = CustomCacheManager.getQueryPlan(sql); |
| 603 | + PhysicalPlan plan = null; |
| 604 | + |
| 605 | + if (planCacheEnabled) { |
| 606 | + logger.info("Cache enabled, checking entries"); |
| 607 | + plan = CustomCacheManager.getQueryPlan(sql); |
| 608 | + |
| 609 | + if (plan == null) { |
| 610 | + logger.info("Cache miss, generating new plan"); |
| 611 | + plan = DrillSqlWorker.getPlan(queryContext, sql, textPlan); |
| 612 | + |
| 613 | + if (isCacheableQuery(sql)) { |
| 614 | + CustomCacheManager.putQueryPlan(sql, plan); |
| 615 | + CustomCacheManager.logCacheStats(); |
| 616 | + } |
| 617 | + } else { |
| 618 | + logger.info("Using cached plan"); |
| 619 | + } |
602 | 620 |
|
603 | | - if (plan == null) { |
604 | | - logger.info("Cache miss, generating new plan"); |
605 | | - plan = DrillSqlWorker.getPlan(queryContext, sql, textPlan); |
606 | 621 | } else { |
607 | | - logger.info("Using cached plan"); |
| 622 | + plan = DrillSqlWorker.getPlan(queryContext, sql, textPlan); |
608 | 623 | } |
609 | 624 |
|
610 | | - if(sql.trim().startsWith("SELECT")) { |
611 | | - CustomCacheManager.putQueryPlan(sql, plan); |
612 | | - CustomCacheManager.logCacheStats(); |
| 625 | + return plan; |
| 626 | + } |
| 627 | + |
| 628 | + private boolean isCacheableQuery(String sql) { |
| 629 | + return sql.trim().toUpperCase().startsWith("SELECT"); |
| 630 | + } |
| 631 | + |
| 632 | + private void runSQL(final String sql) throws ExecutionSetupException { |
| 633 | + final Pointer<String> textPlan = new Pointer<>(); |
| 634 | + final OptionManager options = queryContext.getOptions(); |
| 635 | + final boolean planCacheEnabled = options.getOption(PlannerSettings.PLAN_CACHE); |
| 636 | + if (planCacheEnabled) { |
| 637 | + logger.info("PlanCache is enabled"); |
| 638 | + } else { |
| 639 | + logger.info("PlanCache is disabled"); |
613 | 640 | } |
614 | 641 |
|
| 642 | + PhysicalPlan plan = getOrBuildPlan(sql, textPlan, planCacheEnabled); |
| 643 | + |
615 | 644 | runPhysicalPlan(plan, textPlan); |
616 | 645 | } |
617 | 646 |
|
|
0 commit comments