OrientDB中Index(索引)与Automatic Index(自动索引)的区别
Key Differences Between Index and Automatic Index in OrientDB
Great question—these two terms aren’t interchangeable, and understanding their differences will help you manage your OrientDB database more effectively. Let’s break them down:
1. Regular (Manual) Index
- Created by you, explicitly: You have to run a command like
CREATE INDEX user_name_idx ON User (name) NOTUNIQUEto set it up. No automatic creation here. - No automatic binding to properties: Unless you explicitly link it to a class property, the index won’t update when you modify records. If you do link it, you still might need to manually rebuild it if you make schema changes later.
- Full control over use cases: Perfect when you want to optimize specific queries (like frequent lookups on a non-unique property) or use custom index types (full-text, geospatial, etc.). You decide when to create, update, or delete it.
2. Automatic Index
- Auto-created by OrientDB: This index pops up automatically when you add constraints like
UNIQUE,UNIQUE_HASH_INDEX, orNOTNULLto a class property. For example, if you runALTER PROPERTY User.email SET UNIQUE, OrientDB will create an automatic index forUser.email. - Fully maintained by the database: Any time you insert, update, or delete a record with that property, OrientDB syncs the index automatically—no manual work needed from you.
- Tied directly to the constrained property: The index is named after the class and property (e.g.,
User.email) and can’t be easily repurposed for other properties. Its main job is to enforce the constraint (like ensuring no duplicate emails) while also speeding up queries on that property.
Quick Cheat Sheet for Comparison
| Aspect | Regular Index | Automatic Index |
|---|---|---|
| Creation Method | Manual CREATE INDEX command | Triggered by adding property constraints |
| Maintenance | Manual (or custom triggers) | Fully automatic by OrientDB |
| Property Binding | Optional, manual setup | Automatic, tied to the constrained property |
| Primary Goal | Query optimization, custom indexing | Data integrity enforcement + automatic query speedup |
If you’re ever unsure which one you’re looking at, check the index name and how it was created—automatic indexes almost always follow the ClassName.PropertyName naming pattern.
内容的提问来源于stack exchange,提问作者Rohan Shelar
相关产品推荐
相关产品推荐

