From bddf5aea31f3ed34b43d26133de1671b2acbcc46 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Wed, 27 Sep 2006 23:51:49 +0000 Subject: Add support for faster full count. --- .../com/amazon/carbonado/qe/FullScanQueryExecutor.java | 15 +++++++++++++++ .../com/amazon/carbonado/repo/indexed/IndexedStorage.java | 4 ++++ 2 files changed, 19 insertions(+) (limited to 'src/main') diff --git a/src/main/java/com/amazon/carbonado/qe/FullScanQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/FullScanQueryExecutor.java index dbf5690..b8035f0 100644 --- a/src/main/java/com/amazon/carbonado/qe/FullScanQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/FullScanQueryExecutor.java @@ -51,6 +51,15 @@ public class FullScanQueryExecutor extends AbstractQueryExec mSupport = support; } + @Override + public long count(FilterValues values) throws FetchException { + long count = mSupport.countAll(); + if (count == -1) { + count = super.count(values); + } + return count; + } + /** * Returns an open filter. */ @@ -82,6 +91,12 @@ public class FullScanQueryExecutor extends AbstractQueryExec public static interface Support { Class getStorableType(); + /** + * Counts all Storables. Implementation may return -1 to indicate that + * default count algorithm should be used. + */ + long countAll() throws FetchException; + /** * Perform a full scan of all Storables. */ diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java index 1fa1244..2901ea0 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java @@ -297,6 +297,10 @@ class IndexedStorage implements Storage, StorageAccess return new MergeSortBuffer(mRootStorage); } + public long countAll() throws FetchException { + return mMasterStorage.query().count(); + } + public Cursor fetchAll() throws FetchException { return mMasterStorage.query().fetch(); } -- cgit v1.2.3