Ruben Vermeulen
Ruben Vermeulen

Reputation: 441

Query performance issues when using MATCH and SELECT together OrientDB

I'm facing a problem with a query in OrientDB.

SELECT FROM (
   MATCH 
      {class: article, as: article}.in('authorOf'){as: author} 
   RETURN article, author
) ORDER BY createdAt desc SKIP 0 LIMIT 50

As you see I want to fetch the last 50 most recent articles with their corresponding author. The problem I'm facing is that the subquery first iterates over all my articles then passes it down to the parent and then it gets filtered. This is obviously not very effective, because all the articles are loaded into memory when I only need 50 of them.

Does anyone know a better approach without having to use multiple queries.

Upvotes: 1

Views: 89

Answers (1)

Ivan Mainetti
Ivan Mainetti

Reputation: 1982

you could try with

select @rid as article,in('authorOf')[0] as author from article order by createdAt desc SKIP 0 LIMIT 50

With this one I'm getting a sligthly better performances, but nothing extreme.

EDIT following Luigi's comment

Create an index on createdAt property:

CREATE INDEX article.createdAt ON article (createdAt) NOTUNIQUE

PS

I'm not sure that the order by in your query is working well

Upvotes: 2

Related Questions