'order by' works as filter when the field has an index with null value.
I'm using OrientDB 2.1.13. Here's simple sql that reproduces the problem.
CREATE CLASS Book EXTENDS V
CREATE PROPERTY Book.category string
CREATE INDEX Book.category NOTUNIQUE
CREATE VERTEX Book SET category='SF'
CREATE VERTEX Book SET category='Novel'
CREATE VERTEX Book
SELECT FROM Book ORDER BY category
I expected result like:
#12:2 | (null)
#12:0 | Novel
#12:1 | SF
But the record with null category was not listed.
It seems that order by relies on the index of the field, and the index doesn't contain null value by default.
I was able to get work-around like:
DROP INDEX Book.category
CREATE INDEX Book.category NOTUNIQUE METADATA {ignoreNullValues: false}
REBUILD INDEX Book.category
SELECT FROM Book ORDER BY category ASC
Now I can see all books in the Book class.
However, it still have a problem. order by doesn't care null value in sort order. No matter you set ASC or DESC, records with null value will be always at the bottom of the list.
I don't think I should create index with ignoreNullValues option.
order by should do 'sorting' not 'filtering'.
Also, null should be considered as 0 priority in sort order, and it should be comparable with other non-null values.
Hi @gongdo since 2.2 {ignoreNullValues: false} will be default setting. Do you agree that this fix issue ?
The key problem is unexpected filtering by 'order by' clause. If it filters null value with 'ignoreNullValues: true', I can say it doesn't fix the issue. Maybe I can accept it as a work-around.
Anyway I'll test this in 2.2 and feedback.
@laa I tested it on 2.2 beta2, and I found that {ignoreNullValues: false} doesn't fix the issue.
The null value always be at the bottom, regardless with ASC nor DESC.
Hello. I think ideally there should be at least following index options, including:
- default order [ ASC | DESC ]
- nulls ordering [ NULLS { FIRST | LAST } ] like in Postgres and it will be ok then.
So the syntax could become smth like:
CREATE INDEX
@luigidellaquila What's the default ODB index ordering "under the hood", by the way? Do I need to EXPLICITLY specify sort order in case when the SQL clause uses an index or the indexed results do appear already sorted?
Best Regards, S.