Skip to content
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

[Indexer] Optimize indexer like query to ensure all querys can use indexes #2352

Merged
merged 3 commits into from
Aug 3, 2024

Conversation

baichuan3
Copy link
Collaborator

Summary

Optimize indexer to ensure all querys can use indexes.

  1. Convert SQLite like query to Between And query, optimize table scan to index scan, and only take effect on the rightmost prefix.
  2. Adjust the index to support all queries can be index scan, not trigger a table scan.
  3. Support indexer metrics, statistics on indexer query time and write time cost.

Notice:

This operation requires rebuilding the index when the server is restarted, and the server will be unavailable during the index rebuild.

Copy link

vercel bot commented Aug 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rooch-portal ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 3, 2024 0:33am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
rooch ⬜️ Ignored (Inspect) Visit Preview Aug 3, 2024 0:33am

@baichuan3
Copy link
Collaborator Author

testnet indexer file size

du -sh *
21G    events
32K    events-shm
4.1M    events-wal
23G    object_states
3.9M    object_states-shm
2.0G    object_states-wal
4.2G    transactions
32K    transactions-shm
4.0M    transactions-wal

SQLite explain query plan

sqlite>
explain query plan select * from object_states  where owner="1" and object_type not like '0x1::0x111%';
QUERY PLAN
`--SEARCH object_states USING INDEX idx_object_states_owner_and_object_type (owner=?)

sqlite>
explain query plan select * from object_states  where owner="1" and object_type >= '0x1::0x111' and object_type < "0x0";
QUERY PLAN
`--SEARCH object_states USING INDEX idx_object_states_owner_and_object_type (owner=? AND object_type>? AND object_type<?)

sqlite>
explain query plan select * from object_states  where  object_type >= "0x1::0x111" and object_type < "0x01::0x2";
QUERY PLAN
`--SEARCH object_states USING INDEX idx_object_states_object_type (object_type>? AND object_type<?)

Copy link

github-actions bot commented Aug 3, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

Comment on lines +583 to +597
fn test_optimize_like_query() {
let gas_coin_object_type = "0x3::coin_store::CoinStore";
let (origin_bound, upper_bound) = optimize_like_query(gas_coin_object_type.to_string());
assert_eq!(origin_bound, gas_coin_object_type);
assert_eq!(upper_bound, "0x3::coin_store::CoinStorf");

let object_type2 =
"0x5350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000::custom::CustomZZZ";
let (origin_bound, upper_bound) = optimize_like_query(object_type2.to_string());
assert_eq!(origin_bound, object_type2);
assert_eq!(
upper_bound,
"0x5350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000::custom::CustomZZ["
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原来 indexer 的 like 有个 bug,比如搜索 0xabcd::test::Account, 期望是得到 Account 以及 Account, 但同时会搜索出来 0xabcd::test::AccountABC。这个问题现在这个方案还有吧?

@jolestar jolestar merged commit b5ccb7b into main Aug 3, 2024
8 checks passed
@jolestar jolestar deleted the opt_indexer_query branch August 3, 2024 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Metrics] SQLite Metrics
3 participants