Skip to content

Commit

Permalink
Merge pull request #1276 from tronprotocol/improve_index
Browse files Browse the repository at this point in the history
improve index query performance
  • Loading branch information
Yrp authored Aug 9, 2018
2 parents 71e7f2c + e71f74b commit 35b822b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/main/java/org/tron/core/db/api/StoreAPI.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -103,8 +100,7 @@ public List<Transaction> 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;
}
Expand All @@ -122,8 +118,7 @@ public List<Transaction> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class TransactionIndex extends AbstractIndex<TransactionCapsule, Transact
public static Attribute<WrappedByteArray, String> OWNERS;
public static Attribute<WrappedByteArray, String> TOS;
public static Attribute<WrappedByteArray, Long> TIMESTAMP;
public static Attribute<WrappedByteArray, Long> INDEX_CREATE_TIMESTAMP;

@Autowired
public TransactionIndex(
Expand All @@ -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
Expand All @@ -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());

}
}

0 comments on commit 35b822b

Please sign in to comment.