private void optimizeStagingTableAccess(RelationalNode node) throws QueryMetadataException, TeiidComponentException { checkNode(node); for (RelationalNode child : node.getChildren()) { if (child != null) { optimizeStagingTableAccess(child); } } }
static Boolean requiresTransaction(boolean transactionalReads, RelationalNode node) { Boolean requiresTxn = node.requiresTransaction(transactionalReads); if (Boolean.TRUE.equals(requiresTxn)) { return true; } boolean last = true; for (RelationalNode child : node.getChildren()) { if (child == null) { continue; } Boolean childRequires = requiresTransaction(transactionalReads, child); if (Boolean.TRUE.equals(childRequires)) { return true; } if (childRequires == null) { if (requiresTxn == null) { return true; } requiresTxn = null; last = true; } else { last = false; } } if (requiresTxn == null && !last) { return true; } return requiresTxn; }
static Boolean requiresTransaction(boolean transactionalReads, RelationalNode node) { Boolean requiresTxn = node.requiresTransaction(transactionalReads); if (Boolean.TRUE.equals(requiresTxn)) { return true; } boolean last = true; for (RelationalNode child : node.getChildren()) { if (child == null) { continue; } Boolean childRequires = requiresTransaction(transactionalReads, child); if (Boolean.TRUE.equals(childRequires)) { return true; } if (childRequires == null) { if (requiresTxn == null) { return true; } requiresTxn = null; last = true; } else { last = false; } } if (requiresTxn == null && !last) { return true; } return requiresTxn; }
static Boolean requiresTransaction(boolean transactionalReads, RelationalNode node) { Boolean requiresTxn = node.requiresTransaction(transactionalReads); if (Boolean.TRUE.equals(requiresTxn)) { return true; } boolean last = true; for (RelationalNode child : node.getChildren()) { if (child == null) { continue; } Boolean childRequires = requiresTransaction(transactionalReads, child); if (Boolean.TRUE.equals(childRequires)) { return true; } if (childRequires == null) { if (requiresTxn == null) { return true; } requiresTxn = null; last = true; } else { last = false; } } if (requiresTxn == null && !last) { return true; } return requiresTxn; }
static void connectExternal(RelationalNode node, CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) { node.initialize(context, bufferMgr, dataMgr); RelationalNode[] children = node.getChildren(); int childCount = node.getChildCount(); for(int i=0; i<childCount; i++) { if(children[i] != null) { connectExternal(children[i], context, dataMgr, bufferMgr); } else { break; } } }
static void connectExternal(RelationalNode node, CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) { node.initialize(context, bufferMgr, dataMgr); RelationalNode[] children = node.getChildren(); int childCount = node.getChildCount(); for(int i=0; i<childCount; i++) { if(children[i] != null) { connectExternal(children[i], context, dataMgr, bufferMgr); } else { break; } } }
static void connectExternal(RelationalNode node, CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) { node.initialize(context, bufferMgr, dataMgr); RelationalNode[] children = node.getChildren(); int childCount = node.getChildCount(); for(int i=0; i<childCount; i++) { if(children[i] != null) { connectExternal(children[i], context, dataMgr, bufferMgr); } else { break; } } }
private static void getAtomicCommands(RelationalNode node, Set<Command> atomicQueries) { if(node instanceof AccessNode) { AccessNode accessNode = (AccessNode) node; atomicQueries.add( accessNode.getCommand()); } // Recurse through children RelationalNode[] children = node.getChildren(); for(int i=0; i<children.length; i++) { if(children[i] != null) { getAtomicCommands(children[i], atomicQueries); } else { break; } } }
static void getDependentGroups(RelationalNode node, Set<String> depGroups, boolean depdenent) { if(node instanceof AccessNode) { if (node instanceof DependentAccessNode) { if (!depdenent) { return; } } else if (depdenent) { return; } AccessNode accessNode = (AccessNode)node; Command depCommand = accessNode.getCommand(); Collection<GroupSymbol> groupSymbols = GroupCollectorVisitor.getGroups(depCommand, true); for (GroupSymbol groupSymbol : groupSymbols) { depGroups.add(groupSymbol.getNonCorrelationName().toUpperCase()); } } // Recurse through children RelationalNode[] children = node.getChildren(); for(int i=0; i<children.length; i++) { if(children[i] != null) { getDependentGroups(node.getChildren()[i], depGroups, depdenent); } } }
/** * Because we lack a cost value based upon complexity the * heurstic is to look that the dependent set is fully pushed. * there are situations where it won't be fully pushed, but * for which it will still be a better plan and we'll reject */ private boolean isUsingDependentJoin(String id, RelationalNode rn) { if (rn instanceof DependentAccessNode) { DependentAccessNode dan = (DependentAccessNode)rn; Query qc = (Query) dan.getCommand(); Criteria c = qc.getCriteria(); for (Criteria crit : Criteria.separateCriteriaByAnd(c)) { if (crit instanceof DependentSetCriteria) { DependentSetCriteria dsc = (DependentSetCriteria)crit; if (dsc.getContextSymbol().equals(id)) { return true; } } } } RelationalNode[] children = rn.getChildren(); for (int i=0; i<rn.getChildCount(); i++) { if (isUsingDependentJoin(id, children[i])) { return true; } } return false; }
/** * Because we lack a cost value based upon complexity the * heurstic is to look that the dependent set is fully pushed. * there are situations where it won't be fully pushed, but * for which it will still be a better plan and we'll reject */ private boolean isUsingDependentJoin(String id, RelationalNode rn) { if (rn instanceof DependentAccessNode) { DependentAccessNode dan = (DependentAccessNode)rn; Query qc = (Query) dan.getCommand(); Criteria c = qc.getCriteria(); for (Criteria crit : Criteria.separateCriteriaByAnd(c)) { if (crit instanceof DependentSetCriteria) { DependentSetCriteria dsc = (DependentSetCriteria)crit; if (dsc.getContextSymbol().equals(id)) { return true; } } } } RelationalNode[] children = rn.getChildren(); for (int i=0; i<rn.getChildCount(); i++) { if (isUsingDependentJoin(id, children[i])) { return true; } } return false; }
private void helpAssertIsBatchedPlan(RelationalPlan plan, boolean isBatchedPlan) { RelationalNode node = plan.getRootNode(); if (node instanceof ProjectNode) { node = node.getChildren()[0]; } if (isBatchedPlan) { assertTrue("Plan should have been a batched", node instanceof BatchedUpdateNode); //$NON-NLS-1$ } else { assertTrue("Plan should not have been batched.", node instanceof AccessNode); //$NON-NLS-1$ } }
while(nextParent.getChildren()[0] != null) { nextParent = nextParent.getChildren()[0]; && childNode.getProperty(Info.SET_OPERATION) == planNode.getProperty(Info.SET_OPERATION) && childNode.getType() == NodeConstants.Types.SET_OP && childNode.hasBooleanProperty(Info.USE_ALL)) { for (RelationalNode grandChild : child.getChildren()) { if (grandChild != null) { nextParent.addChild(grandChild);
while(nextParent.getChildren()[0] != null) { nextParent = nextParent.getChildren()[0]; && childNode.getProperty(Info.SET_OPERATION) == planNode.getProperty(Info.SET_OPERATION) && childNode.getType() == NodeConstants.Types.SET_OP && childNode.hasBooleanProperty(Info.USE_ALL)) { for (RelationalNode grandChild : child.getChildren()) { if (grandChild != null) { nextParent.addChild(grandChild);
while(nextParent.getChildren()[0] != null) { nextParent = nextParent.getChildren()[0]; && childNode.getProperty(Info.SET_OPERATION) == planNode.getProperty(Info.SET_OPERATION) && childNode.getType() == NodeConstants.Types.SET_OP && childNode.hasBooleanProperty(Info.USE_ALL)) { for (RelationalNode grandChild : child.getChildren()) { if (grandChild != null) { nextParent.addChild(grandChild);
@Test public void testTextTableJoin() throws Exception { String sql = "select z.* from (select x.* from (select * from pm1.g1 where e1 = 'c') y, texttable(e1 || '\n' || e2 || '\n' || e3 COLUMNS x string) x) as z, " + "(select x.* from (select * from pm1.g1 where e1 = 'c') y, texttable(e1 || '\n' || e2 || '\n' || e3 COLUMNS x string) x) as z1 where z.x = z1.x"; List<?>[] expected = new List<?>[] { Arrays.asList("c"), Arrays.asList("1"), Arrays.asList("true"), }; FakeDataManager dataManager = new FakeDataManager(); sampleData1(dataManager); RelationalPlan plan = (RelationalPlan)helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached()); JoinNode join = (JoinNode) plan.getRootNode().getChildren()[0]; assertTrue(!(join.getJoinStrategy() instanceof NestedTableJoinStrategy)); helpProcess(plan, createCommandContext(), dataManager, expected); }
@Test public void testCopyCriteriaMultiway() throws Exception { String sql = "select bqt1.smalla.intkey, bqt2.smalla.intkey from bqt1.smalla, bqt2.smalla, bqt1.smallb where bqt1.smalla.intnum = bqt2.smalla.intnum and cast(bqt1.smalla.stringkey as integer) = coalesce(bqt2.smalla.intkey, bqt1.smallb.intkey) and bqt2.smalla.intkey = 1"; //$NON-NLS-1$ ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.exampleBQTCached(), new String[] {"SELECT g_0.IntKey FROM BQT1.SmallB AS g_0", "SELECT g_0.IntNum AS c_0, g_0.IntKey AS c_1 FROM BQT2.SmallA AS g_0 WHERE g_0.IntKey = 1 ORDER BY c_0", "SELECT g_0.IntNum AS c_0, g_0.StringKey AS c_1, g_0.IntKey AS c_2 FROM BQT1.SmallA AS g_0 ORDER BY c_0"}); RelationalPlan relationalPlan = (RelationalPlan)plan; JoinNode joinNode = (JoinNode) relationalPlan.getRootNode().getChildren()[0]; assertNotNull(joinNode.getJoinCriteria()); }
@Test public void testOuterJoinRemoval() throws Exception { BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, false); caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, false); ProcessorPlan plan = TestOptimizer.helpPlan("SELECT * from pm1.g1 inner join (pm1.g2 left outer join pm1.g3 on pm1.g2.e1=pm1.g3.e1) on pm1.g1.e1=pm1.g3.e1", //$NON-NLS-1$ RealMetadataFactory.example1Cached(), new String[] { "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm1.g2 AS g_0 ORDER BY c_0", "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm1.g3 AS g_0 ORDER BY c_0"}, new DefaultCapabilitiesFinder(caps), ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ RelationalNode node = ((RelationalPlan)plan).getRootNode().getChildren()[0]; assertTrue(node instanceof JoinNode); node = node.getChildren()[0]; assertTrue(node instanceof JoinNode); assertEquals(JoinType.JOIN_INNER, ((JoinNode)node).getJoinType()); }
while (root.getChildren() != null) { root = root.getChildren()[0];
@Test public void testManyJoinsGreedy() throws Exception { TransformationMetadata tm = example1(); RealMetadataFactory.setCardinality("pm1.g5", 1000000, tm); RealMetadataFactory.setCardinality("pm1.g4", 1000000, tm); RealMetadataFactory.setCardinality("pm1.g1", 10000000, tm); RealMetadataFactory.setCardinality("pm1.g8", 100, tm); RealMetadataFactory.setCardinality("pm1.g3", 10000, tm); RealMetadataFactory.setCardinality("pm1.g6", 100000, tm); ProcessorPlan plan = helpPlan("SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2, pm1.g3, pm1.g4, pm1.g5, pm1.g6, pm1.g7, pm1.g8 " + "WHERE pm1.g1.e1 = pm1.g2.e1 AND pm1.g2.e1 = pm1.g3.e1 AND pm1.g3.e1 = pm1.g4.e1 AND pm1.g4.e1 = pm1.g5.e1 AND pm1.g5.e1=pm1.g6.e1 AND pm1.g6.e1=pm1.g7.e1 AND pm1.g7.e1=pm1.g8.e1", //$NON-NLS-1$ tm, new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", //$NON-NLS-1$ "SELECT pm1.g2.e1 FROM pm1.g2", //$NON-NLS-1$ "SELECT pm1.g3.e1 FROM pm1.g3", //$NON-NLS-1$ "SELECT pm1.g4.e1 FROM pm1.g4", //$NON-NLS-1$ "SELECT pm1.g5.e1 FROM pm1.g5", //$NON-NLS-1$ "SELECT pm1.g6.e1 FROM pm1.g6", //$NON-NLS-1$ "SELECT pm1.g7.e1 FROM pm1.g7", //$NON-NLS-1$ "SELECT pm1.g8.e1 FROM pm1.g8", //$NON-NLS-1$ }, new DefaultCapabilitiesFinder(), ComparisonMode.CORRECTED_COMMAND_STRING ); //$NON-NLS-1$ RelationalPlan rp = (RelationalPlan)plan; //g1 should be last assertEquals("[pm1.g1.e1]", ((JoinNode)rp.getRootNode().getChildren()[0]).getRightExpressions().toString()); }