0
votes

I have read a lot of times that RavenDb doesn't do any computation during query time. For example here is the quote from Ayende's article "The Pain of Implementing LINQ Providers"

One of the features of RavenDB is that it performs absolutely no computation during queries; all the data for the query is already prepared. That means that we can achieve very good querying speeds.

But at the same time there is Live Projections feature which allows to make some computations during query. For example, here I use sorting and sum calculation:

TransformResults = (database, post) => from post in posts
                                       order by post.DateTime
                                       select new
                                                {
                                                  Id = post.Id,
                                                  CommentsCount = post.Comments.Sum()
                                                }

So RavenDb allows to make computations on the fly, doesn't it?

Update. I decided to provide one more example where you actually have to compute (sort) things during query time. Task: select 10 last post comments for specific BlogId (assume we have a lot of blogs on our blogging system):

public class LastPostsCommentsIndex: AbstractIndexCreationTask<Post>
{
    public class IndexResult
    {
        public string BlogId {get; set;}
    }

    public class PostComment
    {
        public string PostId { get; set; }
        public DateTime DateTime { get; set; }
        public string Author { get; set; }
        public string Text { get; set; }
    }

    public LastPostsCommentsIndex()
    {
        Map = posts => from post in posts
                       select new { BlogId = post.BlogId };

        TransformResults = (database, posts) => from post in posts
                                                from comment in post.Comments
                                                orderby comment.DateTime descending
                                                select new { PostId = post.Id, DateTime = comment.DateTime, Author = comment.Author, Text = comment.Text };
    }
}

In this case we are not able to sort Map index results - we have to sort results on the fly.

1

1 Answers

2
votes

Yes, you are right. But this is nit picking, isn't it?

When someone speaks about "computation" in this context, it is computation (like Sum, Avg, Count) across several documents, what is meant.