Dynamic index query - no results

111 views
Skip to first unread message

Alexander Sidorov

unread,
Feb 2, 2012, 4:10:07 AM2/2/12
to rav...@googlegroups.com
I have a simple query like this: _documentSession.Query<SomeDocument>().Where(x => x.Id == "SomeDocuments/1").Single()

According to RavenServer console output, RavenDb uses dynamic index for SomeDocument but:
1. I don't see this index in Ravin Silverlight UI
2. Query returns no results (while there actually are documents of this type in database)

If I specify index manually, it works as it actually should. Looks like some kind of dynamic index problem. Is it a known problem or should I create a failing test?

Itamar Syn-Hershko

unread,
Feb 2, 2012, 4:23:58 AM2/2/12
to rav...@googlegroups.com
To get documents by ID, use Load

Can you provide a failing test showing this behavior for an attribute other than the Id?

Alexander Sidorov

unread,
Feb 2, 2012, 4:42:52 AM2/2/12
to rav...@googlegroups.com
Changed from Where to Load - problem gone. Thank you!

By the way, I think it should work with Where or at least throw some specific exception.

2012/2/2 Itamar Syn-Hershko <ita...@hibernatingrhinos.com>

Oren Eini (Ayende Rahien)

unread,
Feb 2, 2012, 4:46:36 AM2/2/12
to rav...@googlegroups.com
It _does_ work with the query, that is why we asked for a failing test.

Alexander Sidorov

unread,
Feb 2, 2012, 4:48:11 AM2/2/12
to rav...@googlegroups.com
But you asked for failing test with any other field except Id

2012/2/2 Oren Eini (Ayende Rahien) <aye...@ayende.com>

Oren Eini (Ayende Rahien)

unread,
Feb 2, 2012, 5:10:57 AM2/2/12
to rav...@googlegroups.com
sorry, that was a mistake. A failing test for id would be good.

Alexander Sidorov

unread,
Feb 2, 2012, 5:43:32 AM2/2/12
to rav...@googlegroups.com
Here is a failing test:

    public class Tests
    {
        [Test]
        public void QueryById()
        {
            var documentStore = new DocumentStore() { Url = "http://localhost:8081", Conventions = { DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites } };
            documentStore.Initialize();

            var documentSession = documentStore.OpenSession();

            var casino = new Casino("Cities/123456", "address", "name");
            documentSession.Store(casino);
            documentSession.SaveChanges();

            var casinoFromDb = documentSession.Query<Casino>().Where(x => x.Id == casino.Id).Single();
        }
    }

    public class Casino
    {
        public string Id { get; set; }
        public DateTime AdditionDate { get; set; }
        public string CityId { get; set; }
        public string Address { get; set; }
        public string Title { get; set; }
        public CasinoStatus Status { get; set; }
        public IList<Comment> Comments { get; set; }
        public IList<Suspension> Suspensions { get; set; }

        private Casino()
        {
            Status = CasinoStatus.Opened;
        }

        public Casino(string cityId, string address, string name)
            : this()
        {
            AdditionDate = DateTime.UtcNow;
            CityId = cityId;
            Address = address;
            Title = name;

            Comments = new List<Comment>();
            Suspensions = new List<Suspension>();
        }
    }

    public enum CasinoStatus
    {
        Opened = 1,
        Closed = 2
    }

    public class Comment
    {
        public DateTime DateTime { get; set; }
        public string Author { get; set; }
        public string Text { get; set; }

        public Comment(string author, string text)
        {
            DateTime = DateTime.UtcNow;
            Author = author;
            Text = text;
        }
    }

    public class Suspension
    {
        public DateTime DateTime { get; set; }
        public IList<Exemption> Exemptions { get; set; }

        public Suspension()
        {
            Exemptions = new List<Exemption>();
        }

        public Suspension(DateTime dateTime, IList<Exemption> exemptions)
        {
            DateTime = dateTime;
            Exemptions = exemptions;
        }
    }

    public class Exemption
    {
        public ExemptionItemType ItemType { get; set; }
        public long Quantity { get; set; }

        public Exemption(ExemptionItemType itemType, long quantity)
        {
            ItemType = itemType;
            Quantity = quantity;
        }
    }

    public enum ExemptionItemType
    {
        Unknown = 1,
        Pc = 2,
        SlotMachine = 3,
        Table = 4,
        Terminal = 5

Oren Eini (Ayende Rahien)

unread,
Feb 2, 2012, 12:40:10 PM2/2/12
to rav...@googlegroups.com
Hi,
Using the current build, this test passes.

Alexander Sidorov

unread,
Feb 2, 2012, 12:47:36 PM2/2/12
to rav...@googlegroups.com
Do you mean stable build? I was running on 616.

2012/2/3 Oren Eini (Ayende Rahien) <aye...@ayende.com>

Oren Eini (Ayende Rahien)

unread,
Feb 2, 2012, 12:49:26 PM2/2/12
to rav...@googlegroups.com
I just run this test on build-638 (which is very close to 616), and it passed.

Alexander Sidorov

unread,
Feb 2, 2012, 1:14:40 PM2/2/12
to rav...@googlegroups.com
Looks like this behaviour is somehow specific to my development database. I have created a fresh database and executed the test - it became green. I can make my development database dump and send it to you by email.

Alexander Sidorov

unread,
Feb 2, 2012, 1:46:44 PM2/2/12
to rav...@googlegroups.com
By the way, it is the same database on which I have reproduced this behaviour:  http://stackoverflow.com/questions/8667102/ravendb-skips-items-when-there-are-no-filtering-conditions (I guess these two bugs(?) may be related)

2012/2/3 Alexander Sidorov <alex...@gmail.com>

Alexander Sidorov

unread,
Feb 5, 2012, 1:45:06 PM2/5/12
to rav...@googlegroups.com
Have you succeeded to reproduce behaviour I was talking about?

2012/2/3 Alexander Sidorov <alex...@gmail.com>

Oren Eini (Ayende Rahien)

unread,
Feb 6, 2012, 6:35:23 AM2/6/12
to rav...@googlegroups.com
No

Alexander Sidorov

unread,
Feb 7, 2012, 4:52:25 AM2/7/12
to rav...@googlegroups.com
I have prepared a project with specific database on which described behaviour is reproduced. You download it here: http://dl.dropbox.com/u/957029/RavenDb/RavenDbFilterBug.7z

2012/2/6 Oren Eini (Ayende Rahien) <aye...@ayende.com>

Oren Eini (Ayende Rahien)

unread,
Feb 7, 2012, 5:44:59 AM2/7/12
to rav...@googlegroups.com
In the future, note that you can just send the actual file, no need for the full project.
Another thing to note is that the I converted the test to RavenDB format and using the current codebase, it passes.

Finally, this:

var casinoFromDb = documentSession.Query<Casino>().Where(x => x.Id == casino.Id).Single();

Is _not_ the right way to do this, you should be calling documentSession.Load<Casino>(casino.Id);
Alexander.cs

Alexander Sidorov

unread,
Feb 7, 2012, 6:12:37 AM2/7/12
to rav...@googlegroups.com
As I said above, this bug is not reproduced on fresh database. That's why I have provided the whole project (including database). I guess you have tested on the fresh database, but not database I have included in the project. I have updated to version 940 - and test still does not pass.

2012/2/7 Oren Eini (Ayende Rahien) <aye...@ayende.com>

Oren Eini (Ayende Rahien)

unread,
Feb 7, 2012, 4:28:39 PM2/7/12
to rav...@googlegroups.com
I see, sorry about that, I'll test with your database to see what is going on there.

Oren Eini (Ayende Rahien)

unread,
Feb 11, 2012, 6:42:02 AM2/11/12
to rav...@googlegroups.com
Okay, reproduced, the problem as this index: CasinosCommentsIndex

For some reason it is being selected to answer this query. 
Checking into it, but basically this is an issue with the query optimize selecting the wrong index.

Oren Eini (Ayende Rahien)

unread,
Feb 11, 2012, 7:01:42 AM2/11/12
to rav...@googlegroups.com
Fixed now, will be in the next build 

Alexander Sidorov

unread,
Feb 11, 2012, 7:03:34 AM2/11/12
to rav...@googlegroups.com
Glad to hear. Thank you!

2012/2/11 Oren Eini (Ayende Rahien) <aye...@ayende.com>
Reply all
Reply to author
Forward
0 new messages