Uniqe Index in SubClasses

27 views
Skip to first unread message

hartmut bischoff

unread,
Jul 28, 2016, 1:07:05 AM7/28/16
to OrientDB
As mentioned before, my test-suite-Vertices have the following structure:
- V
  - - - Contract
    - - ContractDetail
    - - Sector
      - - Category
        - Industry
        - Subcategory

Contracts got an unique Index "Con_id" and Sector "name".


names are unique on class-level only.
My "quick&dirty" solution was to extend the index on Sector to "name, k", where k is a shortcut of the class.

 93         orientdb.create_properties( :Sector, name: {type: :string}, k: {type: :string})
 94         orientdb.create_index( :Sector,  name: 'sectorindex', on: [:name, :k], type: :unique  )




Then I can use the atomic upsert  (with ruby code:)

136             sub_cat_record = ActiveOrient::Model::Subcategory.upsert( set: { :k => 'S' },
137                                  where: { :name => contract.contract_detail.subcategory }) do | new_sub_cat |
138                 category_record =  ActiveOrient::Model::Category.upsert( set: { :k => 'C' },
139                                         where: { :name => contract.contract_detail.category }) do | new_category |
140                         industry_record = ActiveOrient::Model::Industry.upsert( set: { :k => 'I' },
141                                               where: { :name => contract.contract_detail.industry }) do | new_industry |


Obviously this is a sloppy workaround.

Is there a way to specify an Index which is unique on class-level ? 

Luigi Dell'Aquila

unread,
Jul 28, 2016, 2:15:35 AM7/28/16
to orient-...@googlegroups.com
Hi Hartmut,

There is no specific configuration to specify that an index is unique at class level, but you can just avoid to define the index on the superclass, as the query engine will use the subclasses index if needed (first level inheritance only)

Thanks

Luigi



--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hartmut bischoff

unread,
Jul 28, 2016, 2:48:02 AM7/28/16
to OrientDB
Thanks for the quick response.

Unfortunately, this leads to other Questions, probably due to a lac of skills on my side
  
1. How does this affect queries based on the superclass?
The Match-Query presented in another topic is already slow. 

2. Do I have to define two indexes, one on the superclass (non-unique) and in addition one on every Subclass (unique). 

3. Can I use the same name for the indexes on the subclass-level and are they  combined if a query on the superclass is performed. in case there is no index defined for the superclass?



Luigi Dell'Aquila

unread,
Jul 28, 2016, 2:58:17 AM7/28/16
to orient-...@googlegroups.com
There is just no need to define indexes on the parent class, as long as you have indexes on the same properties on the subclass.
Eg. if you have a class A with two subclasses A1 and A2 and both subclasses have an index on "name", if you do a 

SELECT FROM A WHERE name = 'foo'

it will use the indexes on the subclasses

Thanks

Luigi


Luigi Dell'Aquila

unread,
Jul 28, 2016, 2:58:57 AM7/28/16
to orient-...@googlegroups.com
Of course this is true only if the parent class is empty, otherwise you have to define a non-unique index on the parent class as well

Thanks

Luigi

Reply all
Reply to author
Forward
0 new messages