yanwei
yanwei

Reputation: 41

OrientDB query too slow

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

Answers (1)

Alessandro Rota
Alessandro Rota

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')

enter image description here

Query 2

explain select from NOrder where 'xxx' in passengers.name

enter image description here

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

enter image description here

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"

enter image description here

the index NPassenger.name is used because the target class is NPassenger

Upvotes: 0

Related Questions