Skip to content

Commit 35b822b

Browse files
authored
Merge pull request #1276 from tronprotocol/improve_index
improve index query performance
2 parents 71e7f2c + e71f74b commit 35b822b

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/main/java/org/tron/core/db/api/StoreAPI.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package org.tron.core.db.api;
22

3-
import static com.googlecode.cqengine.query.QueryFactory.applyThresholds;
43
import static com.googlecode.cqengine.query.QueryFactory.ascending;
54
import static com.googlecode.cqengine.query.QueryFactory.equal;
65
import static com.googlecode.cqengine.query.QueryFactory.orderBy;
76
import static com.googlecode.cqengine.query.QueryFactory.queryOptions;
8-
import static com.googlecode.cqengine.query.QueryFactory.threshold;
9-
import static com.googlecode.cqengine.query.option.EngineThresholds.INDEX_ORDERING_SELECTIVITY;
107
import static org.tron.core.config.Parameter.DatabaseConstants.TRANSACTIONS_COUNT_LIMIT_MAX;
118

129
import com.google.common.collect.ImmutableList;
@@ -103,8 +100,7 @@ public List<Transaction> getTransactionsFromThis(String address, long offset, lo
103100
index.retrieve(
104101
equal(TransactionIndex.OWNERS, address),
105102
queryOptions(
106-
orderBy(ascending(TransactionIndex.TIMESTAMP)),
107-
applyThresholds(threshold(INDEX_ORDERING_SELECTIVITY, 1.0))))) {
103+
orderBy(ascending(TransactionIndex.INDEX_CREATE_TIMESTAMP))))) {
108104
if (limit > TRANSACTIONS_COUNT_LIMIT_MAX) {
109105
limit = TRANSACTIONS_COUNT_LIMIT_MAX;
110106
}
@@ -122,8 +118,7 @@ public List<Transaction> getTransactionsToThis(String address, long offset, long
122118
index.retrieve(
123119
equal(TransactionIndex.TOS, address),
124120
queryOptions(
125-
orderBy(ascending(TransactionIndex.TIMESTAMP)),
126-
applyThresholds(threshold(INDEX_ORDERING_SELECTIVITY, 1.0))))) {
121+
orderBy(ascending(TransactionIndex.INDEX_CREATE_TIMESTAMP))))) {
127122
if (limit > TRANSACTIONS_COUNT_LIMIT_MAX) {
128123
limit = TRANSACTIONS_COUNT_LIMIT_MAX;
129124
}

src/main/java/org/tron/core/db/api/index/TransactionIndex.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class TransactionIndex extends AbstractIndex<TransactionCapsule, Transact
2727
public static Attribute<WrappedByteArray, String> OWNERS;
2828
public static Attribute<WrappedByteArray, String> TOS;
2929
public static Attribute<WrappedByteArray, Long> TIMESTAMP;
30+
public static Attribute<WrappedByteArray, Long> INDEX_CREATE_TIMESTAMP;
3031

3132
@Autowired
3233
public TransactionIndex(
@@ -41,6 +42,7 @@ public void init() {
4142
index.addIndex(DiskIndex.onAttribute(OWNERS));
4243
index.addIndex(DiskIndex.onAttribute(TOS));
4344
index.addIndex(DiskIndex.onAttribute(TIMESTAMP));
45+
index.addIndex(DiskIndex.onAttribute(INDEX_CREATE_TIMESTAMP));
4446
}
4547

4648
@Override
@@ -64,6 +66,8 @@ protected void setAttribute() {
6466
.collect(Collectors.toList()));
6567
TIMESTAMP =
6668
attribute("timestamp", bytes -> getObject(bytes).getRawData().getTimestamp());
69+
INDEX_CREATE_TIMESTAMP =
70+
attribute("index create timestamp", bytes -> System.currentTimeMillis());
6771

6872
}
6973
}

0 commit comments

Comments
 (0)