-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-5033: fix pushing of limits for simple ASK queries in FedX
This change makes sure to push limits for simple ASK queries with a single statement patterns into the query. The optimization is the same as applied for simple SELECT queries with a LIMIT. Rational: if the limit is not pushed, the federation engine will first fetch all data for the statement pattern and only then locally check if there is at least one, i.e it will cause performance issues and memory pressure when there are many triples matching the statement pattern (for instance millions of persons).
- Loading branch information
1 parent
1749af8
commit 099646a
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
tools/federation/src/test/java/org/eclipse/rdf4j/federated/LimitTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Eclipse RDF4J contributors. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Distribution License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*******************************************************************************/ | ||
package org.eclipse.rdf4j.federated; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.eclipse.rdf4j.model.vocabulary.FOAF; | ||
import org.eclipse.rdf4j.query.QueryResults; | ||
import org.eclipse.rdf4j.query.TupleQuery; | ||
import org.eclipse.rdf4j.repository.Repository; | ||
import org.eclipse.rdf4j.repository.RepositoryConnection; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class LimitTests extends SPARQLBaseTest { | ||
|
||
@Test | ||
public void testLimitPushing_Select_SingleStatement() throws Exception { | ||
|
||
// datsets contain both instances of foaf:Person | ||
prepareTest( | ||
Arrays.asList("/tests/data/data1.ttl", "/tests/data/data2.ttl")); | ||
|
||
Repository fedxRepo = fedxRule.getRepository(); | ||
|
||
try (RepositoryConnection conn = fedxRepo.getConnection()) { | ||
|
||
String query = "SELECT * WHERE { ?person a <" + FOAF.PERSON.stringValue() + "> } LIMIT 2"; | ||
TupleQuery tq = conn.prepareTupleQuery(query); | ||
Assertions.assertEquals(2, QueryResults.asList(tq.evaluate()).size()); | ||
|
||
// check that the query plan contains information about limit | ||
String queryPlan = fedxRule.getFederationContext().getQueryManager().getQueryPlan(query); | ||
Assertions.assertTrue(queryPlan.contains("Upper Limit: 2")); | ||
} | ||
} | ||
|
||
@Test | ||
public void testLimitPushing_Ask_SingleStatement() throws Exception { | ||
|
||
// datsets contain both instances of foaf:Person | ||
prepareTest( | ||
Arrays.asList("/tests/data/data1.ttl", "/tests/data/data2.ttl")); | ||
|
||
Repository fedxRepo = fedxRule.getRepository(); | ||
|
||
try (RepositoryConnection conn = fedxRepo.getConnection()) { | ||
|
||
String query = "ASK { ?person a <" + FOAF.PERSON.stringValue() + "> }"; | ||
Assertions.assertTrue(conn.prepareBooleanQuery(query).evaluate()); | ||
|
||
// check that the query plan contains information about limit | ||
String queryPlan = fedxRule.getFederationContext().getQueryManager().getQueryPlan(query); | ||
Assertions.assertTrue(queryPlan.contains("Upper Limit: 1")); | ||
|
||
// also run a query with no backing data | ||
query = "ASK { ?organization a <" + FOAF.ORGANIZATION.stringValue() + "> }"; | ||
Assertions.assertFalse(conn.prepareBooleanQuery(query).evaluate()); | ||
} | ||
} | ||
} |