private void setAnalysisRecords(ResultsMessage response) { if(analysisRecord != null) { if (requestMsg.getShowPlan() != ShowPlan.OFF) { if (processor != null) { PlanNode node = processor.getProcessorPlan().getDescriptionProperties(); node.addProperty(AnalysisRecord.PROP_DATA_BYTES_SENT, String.valueOf(dataBytes.get())); if (planningEnd != 0) { node.addProperty(AnalysisRecord.PROP_PLANNING_TIME, String.valueOf(planningEnd - planningStart)); } response.setPlanDescription(node); } if (analysisRecord.getAnnotations() != null && !analysisRecord.getAnnotations().isEmpty()) { response.setAnnotations(analysisRecord.getAnnotations()); analysisRecord.getAnnotations().clear(); } } if (requestMsg.getShowPlan() == ShowPlan.DEBUG) { response.setDebugLog(analysisRecord.getDebugLog()); analysisRecord.stopDebugLog(); } } }
private void setAnalysisRecords(ResultsMessage response) { if(analysisRecord != null) { if (requestMsg.getShowPlan() != ShowPlan.OFF) { if (processor != null) { PlanNode node = processor.getProcessorPlan().getDescriptionProperties(); node.addProperty(AnalysisRecord.PROP_DATA_BYTES_SENT, String.valueOf(dataBytes.get())); if (planningEnd != 0) { node.addProperty(AnalysisRecord.PROP_PLANNING_TIME, String.valueOf(planningEnd - planningStart)); } response.setPlanDescription(node); } if (analysisRecord.getAnnotations() != null && !analysisRecord.getAnnotations().isEmpty()) { response.setAnnotations(analysisRecord.getAnnotations()); analysisRecord.getAnnotations().clear(); } } if (requestMsg.getShowPlan() == ShowPlan.DEBUG) { response.setDebugLog(analysisRecord.getDebugLog()); analysisRecord.stopDebugLog(); } } }
private void setAnalysisRecords(ResultsMessage response) { if(analysisRecord != null) { if (requestMsg.getShowPlan() != ShowPlan.OFF) { if (processor != null) { PlanNode node = processor.getProcessorPlan().getDescriptionProperties(); node.addProperty(AnalysisRecord.PROP_DATA_BYTES_SENT, String.valueOf(dataBytes.get())); if (planningEnd != 0) { node.addProperty(AnalysisRecord.PROP_PLANNING_TIME, String.valueOf(planningEnd - planningStart)); } response.setPlanDescription(node); } if (analysisRecord.getAnnotations() != null && !analysisRecord.getAnnotations().isEmpty()) { response.setAnnotations(analysisRecord.getAnnotations()); analysisRecord.getAnnotations().clear(); } } if (requestMsg.getShowPlan() == ShowPlan.DEBUG) { response.setDebugLog(analysisRecord.getDebugLog()); analysisRecord.stopDebugLog(); } } }
@Test public void testMultiAccessPatternWithCriteria() throws Exception { String sql = "SELECT pm1.g1.* FROM pm4.g1, pm5.g1, pm1.g1 where pm4.g1.e1 = pm1.g1.e1 and pm5.g1.e1 = pm1.g1.e1 and pm5.g1.e2 like '%x' "; //$NON-NLS-1$ QueryMetadataInterface metadata = RealMetadataFactory.example1Cached(); AnalysisRecord record = new AnalysisRecord(true, true); TestOptimizer.helpPlanCommand(TestOptimizer.helpGetCommand(sql, metadata), metadata, TestOptimizer.getGenericFinder(false), record, new String[] { "SELECT g_0.e2, g_0.e1 FROM pm5.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)", //$NON-NLS-1$ "SELECT g_0.e1, g_0.e2, g_0.e3, g_0.e4 FROM pm1.g1 AS g_0", //$NON-NLS-1$ "SELECT g_0.e1 FROM pm4.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ assertTrue(record.getAnnotations().toString().contains("access pattern not satisfied by join")); }
public void testAnnotations() { AnalysisRecord rec = new AnalysisRecord(true, false); assertTrue(rec.recordAnnotations()); Annotation ann1 = new Annotation("cat", "ann", "res", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ Annotation ann2 = new Annotation("cat2", "ann2", "res2", Priority.HIGH); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ rec.addAnnotation(ann1); rec.addAnnotation(ann2); Collection<Annotation> annotations = rec.getAnnotations(); assertEquals(2, annotations.size()); assertTrue(annotations.contains(ann1)); assertTrue(annotations.contains(ann2)); }
@Test public void testMaterializedTransformationNoCache2() throws Exception { String userSql = "SELECT MATVIEW.E1 FROM MATVIEW OPTION NOCACHE"; //$NON-NLS-1$ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView(); AnalysisRecord analysis = new AnalysisRecord(true, DEBUG); Command command = helpGetCommand(userSql, metadata); TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] {"SELECT g_0.x FROM MatSrc.MatSrc AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ Collection<Annotation> annotations = analysis.getAnnotations(); assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$ assertTrue("Expected one annotation", annotations.size() == 1); //$NON-NLS-1$ assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$ }
@Test public void testMaterializedTransformation() throws Exception { String userSql = "SELECT MATVIEW.E1 FROM MATVIEW"; //$NON-NLS-1$ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView(); AnalysisRecord analysis = new AnalysisRecord(true, DEBUG); Command command = helpGetCommand(userSql, metadata); TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] {"SELECT g_0.e1 FROM MatTable.MatTable AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ Collection<Annotation> annotations = analysis.getAnnotations(); assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$ assertTrue("Expected one annotation", annotations.size() == 1); //$NON-NLS-1$ assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$ }
@Test public void testMaterializedTransformationNoCache() throws Exception { String userSql = "SELECT MATVIEW.E1 FROM MATVIEW OPTION NOCACHE MatView.MatView"; //$NON-NLS-1$ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView(); AnalysisRecord analysis = new AnalysisRecord(true, DEBUG); Command command = helpGetCommand(userSql, metadata); TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] {"SELECT g_0.x FROM MatSrc.MatSrc AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ Collection<Annotation> annotations = analysis.getAnnotations(); assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$ assertTrue("Expected one annotation", annotations.size() == 1); //$NON-NLS-1$ assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$ }
@Test public void testNoCacheCascadeSubquery() throws Exception { String userSql = "SELECT (select MATVIEW1.E1 FROM MATVIEW1) from MatSrc option nocache"; //$NON-NLS-1$ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView(); AnalysisRecord analysis = new AnalysisRecord(true, DEBUG); Command command = helpGetCommand(userSql, metadata); TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] {"SELECT (SELECT g_0.x FROM MatSrc.MatSrc AS g_0 WHERE g_0.x = '1') FROM MatSrc.MatSrc AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ Collection<Annotation> annotations = analysis.getAnnotations(); assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$ assertEquals("Expected one annotation",3, annotations.size()); //$NON-NLS-1$ assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$ }
@Ignore("we no longer auto detect this case, if we need this logic it will have to be added to the rewriter since it changes select into to an insert") @Test public void testMaterializedTransformationLoading() throws Exception { String userSql = "SELECT MATVIEW.E1 INTO MatTable.MatStage FROM MATVIEW"; //$NON-NLS-1$ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView(); AnalysisRecord analysis = new AnalysisRecord(true, DEBUG); Command command = helpGetCommand(userSql, metadata); TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] {"SELECT g_0.x FROM MatSrc.MatSrc AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ Collection<Annotation> annotations = analysis.getAnnotations(); assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$ assertTrue("Expected one annotation", annotations.size() == 1); //$NON-NLS-1$ assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$ }
@Test public void testManagedMaterializedTransformation() throws Exception { String userSql = "SELECT * FROM ManagedMatView"; //$NON-NLS-1$ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView(); AnalysisRecord analysis = new AnalysisRecord(true, DEBUG); Command command = helpGetCommand(userSql, metadata); RelationalPlan plan = (RelationalPlan) TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] { "SELECT g_0.e1 FROM MatTable.MatTable AS g_0 WHERE mvstatus('MatView', 'ManagedMatView') = 1" }, //$NON-NLS-1$ ComparisonMode.EXACT_COMMAND_STRING); Collection<Annotation> annotations = analysis.getAnnotations(); assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$ assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$ }
@Test public void testPlanNodeAnnotation() throws Exception { PlanNode pn = new PlanNode(); TransformationMetadata metadata = RealMetadataFactory.example1Cached(); Object modelID = metadata.getMetadataStore().getSchema("pm1"); AnalysisRecord record = new AnalysisRecord(true, true); pn.recordDebugAnnotation("hello", modelID, "world", record, metadata); assertEquals("[LOW [Relational Planner] hello pm1 - world Unknown: 0(groups=[]]", record.getAnnotations().toString()); }
LogManager.log(requestMsg.getShowPlan()==ShowPlan.DEBUG?MessageLevel.INFO:MessageLevel.TRACE, LogConstants.CTX_QUERY_PLANNER, debugLog); if (analysisRecord.recordAnnotations() && analysisRecord.getAnnotations() != null && !analysisRecord.getAnnotations().isEmpty()) { LogManager.logDetail(LogConstants.CTX_QUERY_PLANNER, analysisRecord.getAnnotations());
LogManager.log(requestMsg.getShowPlan()==ShowPlan.DEBUG?MessageLevel.INFO:MessageLevel.TRACE, LogConstants.CTX_QUERY_PLANNER, debugLog); if (analysisRecord.recordAnnotations() && analysisRecord.getAnnotations() != null && !analysisRecord.getAnnotations().isEmpty()) { LogManager.logDetail(LogConstants.CTX_QUERY_PLANNER, analysisRecord.getAnnotations());
LogManager.log(requestMsg.getShowPlan()==ShowPlan.DEBUG?MessageLevel.INFO:MessageLevel.TRACE, LogConstants.CTX_QUERY_PLANNER, debugLog); if (analysisRecord.recordAnnotations() && analysisRecord.getAnnotations() != null && !analysisRecord.getAnnotations().isEmpty()) { LogManager.logDetail(LogConstants.CTX_QUERY_PLANNER, analysisRecord.getAnnotations());
@Test public void testDefaultMaterialization() throws Exception { String userSql = "SELECT * from vgroup2"; //$NON-NLS-1$ TransformationMetadata metadata = RealMetadataFactory.exampleMaterializedView(); AnalysisRecord analysis = new AnalysisRecord(true, DEBUG); Command command = helpGetCommand(userSql, metadata); CommandContext cc = new CommandContext(); GlobalTableStoreImpl gts = new GlobalTableStoreImpl(null, metadata.getVdbMetaData(), metadata); cc.setGlobalTableStore(gts); ProcessorPlan plan = TestOptimizer.getPlan(command, metadata, getGenericFinder(), analysis, true, cc); TestOptimizer.checkAtomicQueries(new String[] {"SELECT #MAT_MATVIEW.VGROUP2.x FROM #MAT_MATVIEW.VGROUP2"}, plan); Collection<Annotation> annotations = analysis.getAnnotations(); assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$ assertEquals("Expected one annotation", 1, annotations.size()); //$NON-NLS-1$ assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$ }
@Test public void testDefaultMaterializationWithCacheHint() throws Exception { String userSql = "SELECT * from vgroup4"; //$NON-NLS-1$ TransformationMetadata metadata = RealMetadataFactory.exampleMaterializedView(); AnalysisRecord analysis = new AnalysisRecord(true, DEBUG); Command command = helpGetCommand(userSql, metadata); CommandContext cc = new CommandContext(); GlobalTableStoreImpl gts = new GlobalTableStoreImpl(null, metadata.getVdbMetaData(), metadata); cc.setGlobalTableStore(gts); ProcessorPlan plan = TestOptimizer.getPlan(command, metadata, getGenericFinder(), analysis, true, cc); TestOptimizer.checkAtomicQueries(new String[] {"SELECT #MAT_MATVIEW.VGROUP4.x FROM #MAT_MATVIEW.VGROUP4"}, plan); Collection<Annotation> annotations = analysis.getAnnotations(); assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$ assertEquals("Expected one annotation", 1, annotations.size()); //$NON-NLS-1$ assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$ }
@Test public void testManagedMaterializedTransformationInsert() throws Exception { String userSql = "insert into MatTable1 SELECT * FROM ManagedMatView option nocache ManagedMatView"; //$NON-NLS-1$ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView(); AnalysisRecord analysis = new AnalysisRecord(true, DEBUG); Command command = helpGetCommand(userSql, metadata); BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities(); RelationalPlan plan = (RelationalPlan) TestOptimizer.helpPlanCommand(command, metadata, new DefaultCapabilitiesFinder(bsc), analysis, new String[] { "SELECT g_0.e1 FROM MatTable.MatTable AS g_0 WHERE mvstatus('MatView', 'ManagedMatView') = 1" }, //$NON-NLS-1$ ComparisonMode.EXACT_COMMAND_STRING); bsc.setCapabilitySupport(Capability.INSERT_WITH_QUERYEXPRESSION, true); plan = (RelationalPlan) TestOptimizer.helpPlanCommand(command, metadata, new DefaultCapabilitiesFinder(bsc), analysis, new String[] { "INSERT INTO MatTable1 (e1) SELECT g_0.e1 FROM MatTable.MatTable AS g_0 WHERE mvstatus('MatView', 'ManagedMatView') = 1" }, //$NON-NLS-1$ ComparisonMode.EXACT_COMMAND_STRING); Collection<Annotation> annotations = analysis.getAnnotations(); assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$ assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$ }
@Test public void testDefaultMaterializationWithPK() throws Exception { String userSql = "SELECT * from vgroup3 where x = 'foo'"; //$NON-NLS-1$ TransformationMetadata metadata = RealMetadataFactory.exampleMaterializedView(); AnalysisRecord analysis = new AnalysisRecord(true, DEBUG); Command command = helpGetCommand(userSql, metadata); CommandContext cc = new CommandContext(); GlobalTableStoreImpl gts = new GlobalTableStoreImpl(null, metadata.getVdbMetaData(), metadata); cc.setGlobalTableStore(gts); RelationalPlan plan = (RelationalPlan)TestOptimizer.getPlan(command, metadata, getGenericFinder(), analysis, true, cc); assertEquals(1f, plan.getRootNode().getEstimateNodeCardinality()); TestOptimizer.checkAtomicQueries(new String[] {"SELECT #MAT_MATVIEW.VGROUP3.x, #MAT_MATVIEW.VGROUP3.y FROM #MAT_MATVIEW.VGROUP3 WHERE #MAT_MATVIEW.VGROUP3.x = 'foo'"}, plan); Collection<Annotation> annotations = analysis.getAnnotations(); assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$ assertEquals("Expected one annotation", 1, annotations.size()); //$NON-NLS-1$ assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$ }