From e71f74b6b7cc4da72573cd0a19e5da0f9ab16258 Mon Sep 17 00:00:00 2001 From: Matt Yue Date: Thu, 9 Aug 2018 14:22:11 +0800 Subject: [PATCH] improve index query performance --- src/main/java/org/tron/core/db/api/StoreAPI.java | 9 ++------- .../org/tron/core/db/api/index/TransactionIndex.java | 4 ++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/tron/core/db/api/StoreAPI.java b/src/main/java/org/tron/core/db/api/StoreAPI.java index 8c170c9ad75..3c8633ae946 100644 --- a/src/main/java/org/tron/core/db/api/StoreAPI.java +++ b/src/main/java/org/tron/core/db/api/StoreAPI.java @@ -1,12 +1,9 @@ package org.tron.core.db.api; -import static com.googlecode.cqengine.query.QueryFactory.applyThresholds; import static com.googlecode.cqengine.query.QueryFactory.ascending; import static com.googlecode.cqengine.query.QueryFactory.equal; import static com.googlecode.cqengine.query.QueryFactory.orderBy; import static com.googlecode.cqengine.query.QueryFactory.queryOptions; -import static com.googlecode.cqengine.query.QueryFactory.threshold; -import static com.googlecode.cqengine.query.option.EngineThresholds.INDEX_ORDERING_SELECTIVITY; import static org.tron.core.config.Parameter.DatabaseConstants.TRANSACTIONS_COUNT_LIMIT_MAX; import com.google.common.collect.ImmutableList; @@ -103,8 +100,7 @@ public List getTransactionsFromThis(String address, long offset, lo index.retrieve( equal(TransactionIndex.OWNERS, address), queryOptions( - orderBy(ascending(TransactionIndex.TIMESTAMP)), - applyThresholds(threshold(INDEX_ORDERING_SELECTIVITY, 1.0))))) { + orderBy(ascending(TransactionIndex.INDEX_CREATE_TIMESTAMP))))) { if (limit > TRANSACTIONS_COUNT_LIMIT_MAX) { limit = TRANSACTIONS_COUNT_LIMIT_MAX; } @@ -122,8 +118,7 @@ public List getTransactionsToThis(String address, long offset, long index.retrieve( equal(TransactionIndex.TOS, address), queryOptions( - orderBy(ascending(TransactionIndex.TIMESTAMP)), - applyThresholds(threshold(INDEX_ORDERING_SELECTIVITY, 1.0))))) { + orderBy(ascending(TransactionIndex.INDEX_CREATE_TIMESTAMP))))) { if (limit > TRANSACTIONS_COUNT_LIMIT_MAX) { limit = TRANSACTIONS_COUNT_LIMIT_MAX; } diff --git a/src/main/java/org/tron/core/db/api/index/TransactionIndex.java b/src/main/java/org/tron/core/db/api/index/TransactionIndex.java index 41c04661df3..e4dc8af78ca 100644 --- a/src/main/java/org/tron/core/db/api/index/TransactionIndex.java +++ b/src/main/java/org/tron/core/db/api/index/TransactionIndex.java @@ -27,6 +27,7 @@ public class TransactionIndex extends AbstractIndex OWNERS; public static Attribute TOS; public static Attribute TIMESTAMP; + public static Attribute INDEX_CREATE_TIMESTAMP; @Autowired public TransactionIndex( @@ -41,6 +42,7 @@ public void init() { index.addIndex(DiskIndex.onAttribute(OWNERS)); index.addIndex(DiskIndex.onAttribute(TOS)); index.addIndex(DiskIndex.onAttribute(TIMESTAMP)); + index.addIndex(DiskIndex.onAttribute(INDEX_CREATE_TIMESTAMP)); } @Override @@ -64,6 +66,8 @@ protected void setAttribute() { .collect(Collectors.toList())); TIMESTAMP = attribute("timestamp", bytes -> getObject(bytes).getRawData().getTimestamp()); + INDEX_CREATE_TIMESTAMP = + attribute("index create timestamp", bytes -> System.currentTimeMillis()); } }