Reputation: 41
OrientDB v2.1.1, I have tow class: NOrder and NPassenger, relationship 1 : n, so NOrder has a filed named "passengers",whose type is linklist.
I have two fields (NOrder order_id, NPassenger. Name) index is established
NOrder ducuments count is 3 millon .
I explain these query:
1)select from NOrder where passengers contains(name = 'xxx')
why this query not involved index .
2)select from NOrder where 'xxx' in passengers.name
this query involved indexeses
this query cost 120sec .
thanks
Upvotes: 2
Views: 214
Reputation: 3570
I have tried with this structure
create class NPassenger
create property NPassenger.name String
create index NPassenger.name on NPassenger (name) NOTUNIQUE_HASH_INDEX
create class NOrder
create property NOrder.order_id String
create property NOrder.passengers linklist NPassenger
create index NOrder.order_id on NOrder (order_id) UNIQUE_HASH_INDEX
insert into NPassenger(name) values ("xxx") // 12:0
insert into NPassenger(name) values ("Alessandro") //12:1
insert into NOrder(order_id,passengers) values ("order 1",[12:0])
insert into NOrder(order_id,passengers) values ("order 2",[12:1])
Query 1
explain select from NOrder where passengers contains(name = 'xxx')
Query 2
explain select from NOrder where 'xxx' in passengers.name
None of the two queries use the index because the class target is NOrder.
UPDATE
Now I have 50002 NOrder and 50002 NPassenger. If I execute the queries
explain select from NOrder where passengers contains(name = 'xxx')
and
explain select from NOrder where 'xxx' IN passengers.name'
I get
this is because no index on the name field is used (because the target class is the Norder class) and then the search is done on all 50002 records of the class Norder.
If I use the query
explain select from NPassenger where name = "xxx"
the index NPassenger.name is used because the target class is NPassenger
Upvotes: 0