Skip to content

Remove SimpleQueryEngine #2203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import com.google.firebase.database.collection.ImmutableSortedSet;
import com.google.firebase.firestore.auth.User;
import com.google.firebase.firestore.core.OnlineState;
import com.google.firebase.firestore.local.DefaultQueryEngine;
import com.google.firebase.firestore.local.LocalStore;
import com.google.firebase.firestore.local.MemoryPersistence;
import com.google.firebase.firestore.local.Persistence;
import com.google.firebase.firestore.local.SimpleQueryEngine;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.mutation.MutationBatchResult;
import com.google.firebase.firestore.testutil.IntegrationTestUtil;
Expand Down Expand Up @@ -74,7 +74,7 @@ public ImmutableSortedSet<DocumentKey> getRemoteKeysForTarget(int targetId) {
};

FakeConnectivityMonitor connectivityMonitor = new FakeConnectivityMonitor();
SimpleQueryEngine queryEngine = new SimpleQueryEngine();
DefaultQueryEngine queryEngine = new DefaultQueryEngine();
Persistence persistence = MemoryPersistence.createEagerGcMemoryPersistence();
persistence.start();
LocalStore localStore = new LocalStore(persistence, queryEngine, User.UNAUTHENTICATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import androidx.annotation.Nullable;
import com.google.firebase.database.collection.ImmutableSortedSet;
import com.google.firebase.firestore.local.DefaultQueryEngine;
import com.google.firebase.firestore.local.GarbageCollectionScheduler;
import com.google.firebase.firestore.local.IndexFreeQueryEngine;
import com.google.firebase.firestore.local.LocalStore;
import com.google.firebase.firestore.local.MemoryPersistence;
import com.google.firebase.firestore.local.Persistence;
Expand Down Expand Up @@ -49,7 +49,7 @@ protected EventManager createEventManager(Configuration configuration) {
@Override
protected LocalStore createLocalStore(Configuration configuration) {
return new LocalStore(
getPersistence(), new IndexFreeQueryEngine(), configuration.getInitialUser());
getPersistence(), new DefaultQueryEngine(), configuration.getInitialUser());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,25 @@
import java.util.Collections;
import java.util.Map;

// TOOD(b/140938512): Drop SimpleQueryEngine and rename IndexFreeQueryEngine.

/**
* A query engine that takes advantage of the target document mapping in the TargetCache. The
* IndexFreeQueryEngine optimizes query execution by only reading the documents that previously
* matched a query plus any documents that were edited after the query was last listened to.
* A query engine that takes advantage of the target document mapping in the TargetCache. Query
* execution is optimized by only reading the documents that previously matched a query plus any
* documents that were edited after the query was last listened to.
*
* <p>There are some cases where Index-Free queries are not guaranteed to produce the same results
* as full collection scans. In these cases, the IndexFreeQueryEngine falls back to full query
* processing. These cases are:
* <p>There are some cases where this optimization is not guaranteed to produce the same results as
* full collection scans. In these cases, query processing falls back to full scans. These cases
* are:
*
* <ol>
* <il>Limit queries where a document that matched the query previously no longer matches the
* query. <il> Limit queries where a document edit may cause the document to sort below another
* document that is in the local cache. <il>Queries that have never been CURRENT or free of Limbo
* documents.
* <li>Limit queries where a document that matched the query previously no longer matches the
* query.
* <li>Limit queries where a document edit may cause the document to sort below another document
* that is in the local cache.
* <li>Queries that have never been CURRENT or free of limbo documents.
* </ol>
*/
public class IndexFreeQueryEngine implements QueryEngine {
private static final String LOG_TAG = "IndexFreeQueryEngine";
public class DefaultQueryEngine implements QueryEngine {
private static final String LOG_TAG = "DefaultQueryEngine";

private LocalDocumentsView localDocumentsView;

Expand All @@ -62,7 +61,7 @@ public ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingQuery(
ImmutableSortedSet<DocumentKey> remoteKeys) {
hardAssert(localDocumentsView != null, "setLocalDocumentsView() not called");

// Queries that match all documents don't benefit from using IndexFreeQueries. It is more
// Queries that match all documents don't benefit from using key-based lookups. It is more
// efficient to scan all documents in a collection, rather than to perform individual lookups.
if (query.matchesAllDocuments()) {
return executeFullCollectionScan(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ ImmutableSortedMap<DocumentKey, MaybeDocument> getLocalViewOfDocuments(
return results;
}

// TODO: The Querying implementation here should move 100% to SimpleQueryEngine.
// TODO: The Querying implementation here should move 100% to the query engines.
// Instead, we should just provide a getCollectionDocuments() method here that return all the
// documents in a given collection so that SimpleQueryEngine can do that and then filter in
// documents in a given collection so that query engine can do that and then filter in
// memory.

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ public abstract class LocalStoreTestCase {
private @Nullable QueryResult lastQueryResult;
private int lastTargetId;

abstract QueryEngine getQueryEngine();

abstract Persistence getPersistence();

abstract boolean garbageCollectorIsEager();
Expand All @@ -113,7 +111,7 @@ public void setUp() {
lastTargetId = 0;

localStorePersistence = getPersistence();
queryEngine = new CountingQueryEngine(getQueryEngine());
queryEngine = new CountingQueryEngine(new DefaultQueryEngine());
localStore = new LocalStore(localStorePersistence, queryEngine, User.UNAUTHENTICATED);
localStore.start();
}
Expand Down Expand Up @@ -1023,7 +1021,7 @@ public void testHandlesSetMutationThenAckThenTransformMutationThenAckThenTransfo
@Test
public void testUsesTargetMappingToExecuteQueries() {
assumeFalse(garbageCollectorIsEager());
assumeTrue(queryEngine.getSubject() instanceof IndexFreeQueryEngine);
assumeTrue(queryEngine.getSubject() instanceof DefaultQueryEngine);

// This test verifies that once a target mapping has been written, only documents that match
// the query are read from the RemoteDocumentCache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,19 @@

package com.google.firebase.firestore.local;

import java.util.Arrays;
import java.util.Collection;
import org.junit.runner.RunWith;
import org.robolectric.ParameterizedRobolectricTestRunner;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

@RunWith(ParameterizedRobolectricTestRunner.class)
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class MemoryLocalStoreTest extends LocalStoreTestCase {

private QueryEngine queryEngine;

@ParameterizedRobolectricTestRunner.Parameters(name = "QueryEngine = {0}")
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[] {new SimpleQueryEngine()}, new Object[] {new IndexFreeQueryEngine()});
}

public MemoryLocalStoreTest(QueryEngine queryEngine) {
this.queryEngine = queryEngine;
}

@Override
Persistence getPersistence() {
return PersistenceTestHelpers.createEagerGCMemoryPersistence();
}

@Override
QueryEngine getQueryEngine() {
return this.queryEngine;
}

@Override
boolean garbageCollectorIsEager() {
return true;
Expand Down
Loading