在我的数据库 IM_0609 OrientDB 版本 2.0.8 中是一个 MARKS 类:
CALIBRATION_DATE:date.
DEVICE_MARK:string
DEVICE_NAME:string
END_MARK_NUM:decimal
MARK_NUM:decimal
PERIOD:decimal
SERIAL_NUM:string
在 42898973 行的 MARKS 类中,我创建了索引,如下所示:
在 MARKS(MARK_NUM,END_MARK_NUM) NOTUNIQUE 上创建索引 MARK_NUM_END_MARK_NUM
我快速运行以下查询:
select * from MARKS where (MARK_NUM =84278511 AND END_MARK_NUM
=84278511 AND END_MARK_NUM IS NOT NULL)
找到 1 项。查询在 0.097 秒内执行。
这需要创建索引或更新查询的请求:
select * from MARKS where MARK_NUM =84278511 AND END_MARK_NUM IS NULL
服务器显示以下消息:
2015-05-12 15:46:43:129 INFO {db=IM_0609} [TIP] Query 'select * from MARKS where MARK
_NUM =84278511 AND END_MARK_NUM IS NULL' fetched more than 50000 records: to speed up
the execution, create an index or change the query to use an existent index [OProfiler
]
问:为什么要运行第二个查询?
最佳答案
如果您没有明确表示这样做,Orientdb 不会保留空值的索引。为此,您必须按如下方式设置元数据标记:
CREATE INDEX addresses ON Employee (address) notunique METADATA {ignoreNullValues : false}
但是你的第一个查询
select * from MARKS where (MARK_NUM =84278511 AND END_MARK_NUM =84278511 AND END_MARK_NUM IS NOT NULL)
表示 END_MARK_NUM=84278511 的具体值,因此它可以使用索引并限制记录读取 < 50000
但是你的第二个查询
select * from MARKS where MARK_NUM =84278511 AND END_MARK_NUM IS NULL
没有说明 END_MARK_NUM 的具体值,因此它无法使用您的索引。因此,记录读取的数量增加,并给出提示“尝试减少 orientdb 必须执行的记录读取的数量”
编辑:ignoreNullValues 功能似乎存在错误。 (https://github.com/orientechnologies/orientdb/issues/4508)
关于orientdb - OrientDB 中为 Null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30192617/