Skip to content

COUNT return nothing when no line match the criteria #8280

@jxerome

Description

@jxerome

OrientDB Version: 3.0.1, 3.0.0RC2

Java Version: 1.8.0_162

Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

OS: MacOSX 10.13.4

Expected behavior

When counting elements of a class with a restriction

select count(*) from foo where name = 'bar'

I expect to get a single result with the count value event if no foo object has the name 'bar'.
In this case, the value of count should be 0.

Actual behavior

When the restriction is empty, count has no result at all.

Note, when there is no restriction but the class is empty, the query bahave has expected.

Note: the problem seams to come from a premature optimisation of the query plan that dump the result when the restriction is empty.

Steps to reproduce

Here is a scenario from the console 3.0.1. The same behavior happens in the java driver.

orientdb> create database memory:test

Creating database [memory:test] using the storage type [MEMORY]...
Database created successfully.

Current database is: memory:test
orientdb {db=test}> create class a

Class created successfully.

orientdb {db=test}> create property a.name string

Property created successfully.

orientdb {db=test}> select count(*) from a

+----+--------+
|#   |count(*)|
+----+--------+
|0   |0       |
+----+--------+

1 item(s) found. Query executed in 0.004 sec(s).

orientdb {db=test}> insert into a (name) values ('a')

Inserted record '[a#25:0{name:a} v1]' in 0,009000 sec(s).

orientdb {db=test}> insert into a (name) values ('b')

Inserted record '[a#26:0{name:b} v1]' in 0,001000 sec(s).

orientdb {db=test}> insert into a (name) values ('c')

Inserted record '[a#27:0{name:c} v1]' in 0,001000 sec(s).

orientdb {db=test}> select count(*) from a

+----+--------+
|#   |count(*)|
+----+--------+
|0   |3       |
+----+--------+

1 item(s) found. Query executed in 0.005 sec(s).
orientdb {db=test}> select count(*) from a where name = 'a'

+----+--------+
|#   |count(*)|
+----+--------+
|0   |1       |
+----+--------+

1 item(s) found. Query executed in 0.013 sec(s).
orientdb {db=test}> select count(*) from a where name = 'd'


0 item(s) found. Query executed in 0.002 sec(s).
orientdb {db=test}>

The last command should return an item with 0.

Metadata

Metadata

Labels

buglegacy not used anymore

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions