ravendb icon indicating copy to clipboard operation
ravendb copied to clipboard

More ordering bugs

Open glen-84 opened this issue 1 year ago • 5 comments

  1. As I mentioned here, ordering by a 2nd property is still broken in 6.0.105.
  2. Additionally, I noticed that if you order by properties on a nullable object, the whole record is omitted. I've updated my reproduction repository.

With ravendb/ravendb:5.4-ubuntu-latest:

Foo.BarBool: True, Foo.BarShort: 14
Foo.BarBool: True, Foo.BarShort: 12
Foo.BarBool: False, Foo.BarShort: 13
Foo.BarBool: , Foo.BarShort:

With ravendb/ravendb:6.0-ubuntu-latest:

Foo.BarBool: False, Foo.BarShort: 13   # BarBool should be ordered descending, so `True` first.
Foo.BarBool: True, Foo.BarShort: 14
Foo.BarBool: True, Foo.BarShort: 12
# Missing 4th record.

glen-84 avatar Jul 23 '24 18:07 glen-84

It's an issue with comparators that we're currently fixing in https://github.com/ravendb/ravendb/pull/18864. The ordering is already fixed there, but handling the case where the object is null isn't ready yet.

Lwiel avatar Jul 24 '24 11:07 Lwiel

The issue with document that has Foo equal to null is that both BarShort and BarBool don't exist.

Lucene has a different approach to indexing than Corax - it gathers all documents stored inside index and then loads all the terms under specific field. Because it gathers documents first, it can return documents even when the term doesn't exist. On the other hand, Corax takes leverage of internal index tree, which contains already sorted documents (by terms). It can return sorted results just by crawling the tree, which is significantly faster. For the previously mentioned document the term doesn't exist, so it's not stored in any internal index structure and the document is not returned in query results.

Dealing with nested properties inside auto index can be tricky, because if we detect it doesn't exists in particular document, we don't index implicit nulls. In such case you should create static index where you can explicitly handle such case. However, if all your fields are null, you have to set Indexing.IndexMissingFieldsAsNull configuration option to true, so such document isn't skipped.

Lwiel avatar Jul 26 '24 12:07 Lwiel

Are you suggesting that this is something that may not be fixed?

The null Foo object is included in our test snapshots for Marten, MongoDB, and SQLite.

glen-84 avatar Jul 28 '24 09:07 glen-84

That wasn't an indication on why it won't be fixed, but rather an explanation on the root cause of the bug. We'll be fixing that as part of https://github.com/ravendb/ravendb/pull/18864

ayende avatar Jul 28 '24 11:07 ayende

Handling documents with missing fields will be fixed in separate ticket because of a different root cause.

Lwiel avatar Jul 30 '24 10:07 Lwiel

PR with fix has been merged and will be included in the next stable 6.0 version, which will be released in about two weeks

Lwiel avatar Aug 30 '24 12:08 Lwiel

It's fixed in RavenDB 6.0.106 which has been just released. Please note that it requires a Corax index to be reset first.

arekpalinski avatar Sep 17 '24 10:09 arekpalinski