query.bindValue("author", session.getValueFactory().createValue("author1")); validateQuery() .useNoIndexes() .validate(query, query.execute()); query.bindValue("author", session.getValueFactory().createValue("author2")); final List<String> expectedPaths = new ArrayList<>(Arrays.asList("/book1", "/book2")); validateQuery()
@FixFor( "MODE-2312" ) @Test public void shouldUseImplicitPathIndex() throws Exception { Node root = session().getRootNode(); Node newNode1 = root.addNode("nodeA"); newNode1.setProperty("foo", "X"); newNode1.addMixin("mix:referenceable"); Node newNode2 = root.addNode("nodeB"); newNode2.setProperty("foo", "Y"); session().save(); // print = true; // Compute a query plan that should use this index ... final String pathValue = newNode1.getPath(); Query query = jcrSql2Query("SELECT [jcr:path] FROM [nt:unstructured] WHERE [jcr:path] = '" + pathValue + "'"); validateQuery().rowCount(1L).useIndex(IndexPlanners.NODE_BY_PATH_INDEX_NAME).validate(query, query.execute()); query = jcrSql2Query("SELECT A.* FROM [nt:unstructured] AS A WHERE A.[jcr:path] = $pathValue"); query.bindValue("pathValue", valueFactory().createValue(pathValue)); validateQuery().rowCount(1L).useIndex(IndexPlanners.NODE_BY_PATH_INDEX_NAME).validate(query, query.execute()); }
@FixFor( "MODE-2307" ) @Test public void shouldUseSingleColumnStringIndexForQueryWithJoin() throws Exception { registerNodeType("nt:typeWithReference"); registerNodeType("nt:typeWithSysName"); registerValueIndex("refIndex", "nt:typeWithReference", null, "*", "referenceId", PropertyType.STRING); registerValueIndex("sysIndex", "nt:typeWithSysName", null, "*", "sysName", PropertyType.STRING); registerNodeTypeIndex("typesIndex", "nt:base", null, "*", "jcr:primaryType", PropertyType.STRING); // print = true; Node root = session().getRootNode(); Node newNode1 = root.addNode("nodeWithSysName", "nt:typeWithSysName"); newNode1.setProperty("sysName", "X"); newNode1.addMixin("mix:referenceable"); Node newNode2 = root.addNode("nodeWithReference", "nt:typeWithReference"); newNode2.setProperty("referenceId", newNode1.getIdentifier()); session.save(); // Compute a query plan that should use this index ... Query query = jcrSql2Query("SELECT A.* FROM [nt:typeWithReference] AS A " + "JOIN [nt:typeWithSysName] AS B ON A.referenceId = B.[jcr:uuid] " // + "WHERE B.sysName = $sysName"); query.bindValue("sysName", valueFactory().createValue("X")); validateQuery().rowCount(1L).considerIndexes("sysIndex", "refIndex", "typesIndex").validate(query, query.execute()); }
@FixFor( "MODE-2312" ) @Test public void shouldUseImplicitIdIndex() throws Exception { Node root = session().getRootNode(); Node newNode1 = root.addNode("nodeA"); newNode1.setProperty("foo", "X"); newNode1.addMixin("mix:referenceable"); Node newNode2 = root.addNode("nodeB"); newNode2.setProperty("foo", "Y"); session().save(); // print = true; // Compute a query plan that should use this index ... final String uuid = newNode1.getIdentifier(); Query query = jcrSql2Query("SELECT [jcr:path] FROM [nt:unstructured] WHERE [jcr:uuid] = '" + uuid + "'"); validateQuery().rowCount(1L).useIndex(IndexPlanners.NODE_BY_ID_INDEX_NAME).validate(query, query.execute()); query = jcrSql2Query("SELECT A.* FROM [nt:unstructured] AS A WHERE A.[jcr:uuid] = $uuidValue"); query.bindValue("uuidValue", valueFactory().createValue(uuid)); validateQuery().rowCount(1L).useIndex(IndexPlanners.NODE_BY_ID_INDEX_NAME).validate(query, query.execute()); }
query.bindValue("sysName", valueFactory().createValue(newNode1.getIdentifier())); validateQuery().rowCount(1L).useIndex("refIndex").validate(query, query.execute()); query.bindValue("sysName", valueFactory().createValue(newNode1.getIdentifier())); validateQuery().rowCount(1L).useIndex("refIndex").validate(query, query.execute()); query.bindValue("sysName", valueFactory().createValue("X")); validateQuery().rowCount(1L).useIndex("sysIndex").validate(query, query.execute()); query.bindValue("sysName", valueFactory().createValue("X")); validateQuery().rowCount(1L).considerIndexes("refIndex", "sysIndex").validate(query, query.execute());
query.bindValue("value", session().getValueFactory().createValue("value1")); validateQuery().rowCount(2L).useIndex("pathIndex").validate(query, query.execute()); query.bindValue("value", session().getValueFactory().createValue("value1")); validateQuery().rowCount(2L).useIndex("pathIndex").validate(query, query.execute());
@FixFor( "MODE-2314" ) @Test public void shouldIndexNodeAfterChange() throws Exception { // print = true; registerValueIndex("ref1", "nt:unstructured", "", null, "ref1", PropertyType.STRING); registerValueIndex("ref2", "nt:unstructured", "", null, "ref2", PropertyType.STRING); // Wait until all content has been indexed ... waitForIndexes(500L); Node newNode1 = session.getRootNode().addNode("nodeWithSysName", "nt:unstructured"); session.save(); // THIS IS CAUSING the node not being indexed printMessage("Node Created ..."); final String uuId1 = "cccccccccccccccccccccc-0000-1111-1234-123456789abcd"; newNode1.setProperty("ref1", uuId1); newNode1.setProperty("ref2", uuId1); session.save(); printMessage("Node updated ..."); Query query = jcrSql2Query("SELECT A.ref1 FROM [nt:unstructured] AS A WHERE A.ref2 = $ref2"); query.bindValue("ref2", session().getValueFactory().createValue(uuId1)); validateQuery().rowCount(1L).useIndex("ref2").onEachRow(new ValidateQuery.Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { if (rowNumber == 1) { assertThat(row.getValue("ref1").getString(), is(uuId1)); } } }).validate(query, query.execute()); }