I have the following indices set up on a class in orientDB:
INDEXES (3 altogether)
-------------------------------+----------------+
NAME | PROPERTIES |
-------------------------------+----------------+
opponentId | accountId (+) |
| opponentId |
noiseId | noiseId |
protocolId | accountId (+) |
| protocolId |
and I'm trying to execute the following query:
explain select * from method where accountId=1 and protocolId=1 and noiseId=1
I got weird results:
1) Instead of using the ''noiseId'' index or the ''protocolId'' index, orient chose to use the ''opponentId'' index
2) Here's explain's raw output:
{
"@type": "d",
"@version": 0,
"fullySortedByIndex": false,
"compositeIndexUsed": 1,
"involvedIndexes": ["opponentId"],
"limit": -1,
"fetchingFromTargetElapsed": 0,
"indexIsUsedInOrderBy": false,
"elapsed": 0.195936,
"resultType": "collection",
"resultSize": 0,
"@fieldTypes": "compositeIndexUsed=l,involvedIndexes=e,fetchingFromTargetElapsed=l,elapsed=f"
}
3) All the fields here are numbers (accountId=long and the rest are integers). The index is of type SBTREE and is NOTUNIQUE
Is there anything I'm doing wrong here? Can someone shed some light on OrientDB's indexing logic?
I tried your case with this structure:
select from Method
----+-----+------+---------+-------+----------+----------
# |@RID |@CLASS|accountId|noiseId|opponentId|protocolId
----+-----+------+---------+-------+----------+----------
0 |#21:0|Method|0 |0 |0 |0
1 |#21:1|Method|4 |4 |4 |4
2 |#21:2|Method|8 |8 |8 |8
3 |#22:0|Method|1 |1 |1 |1
4 |#22:1|Method|5 |5 |5 |5
5 |#22:2|Method|9 |9 |9 |9
6 |#23:0|Method|2 |2 |2 |2
7 |#23:1|Method|6 |6 |6 |6
8 |#24:0|Method|3 |3 |3 |3
9 |#24:1|Method|7 |7 |7 |7
----+-----+------+---------+-------+----------+----------
and these are my indexes :
NAME | TYPE | FIELDS
-------------|-------------|----------------------------
opponentId | UNIQUE | ["accountId","opponentId"]
noiseId | UNIQUE | ["noiseId"]
protocolId | UNIQUE | ["accountId","protocolId"]
If I execute your query
explain select * from method where accountId=1 and protocolId=1 and noiseId=1
effectivly only the opponentId
is shown
{
"result": [
{
"@type": "d",
"@version": 0,
"documentReads": 1,
"fullySortedByIndex": false,
"compositeIndexUsed": 1,
"current": "#22:0",
"documentAnalyzedCompatibleClass": 1,
"recordReads": 1,
"involvedIndexes": [
"opponentId"
],
"limit": -1,
"fetchingFromTargetElapsed": 0,
"indexIsUsedInOrderBy": false,
"evaluated": 1,
"elapsed": 1.696754,
"resultType": "collection",
"resultSize": 1,
"@fieldTypes": "documentReads=l,compositeIndexUsed=l,current=x,documentAnalyzedCompatibleClass=l,recordReads=l,involvedIndexes=e,fetchingFromTargetElapsed=l,evaluated=l,elapsed=f"
}
],
"notification": "Query executed in 0.047 sec. Returned 1 record(s)"
}
In this post https://groups.google.com/forum/#!topic/orient-database/f7bd3s4f3Jo seems that the OrientDB query executor cannot manage multiple indexes in the usage of multiple AND
conditions, but you can use a LET
statement in your query to use the indexes correctly.
Query :
select expand(intersect($a,$b,$c))
let $a = (select from Method where accountId=1),
$b = (select from Method where protocolId=1),
$c = (select from Method where noiseId=1)
Output :
----+-----+------+---------+-------+----------+----------
# |@RID |@CLASS|accountId|noiseId|opponentId|protocolId
----+-----+------+---------+-------+----------+----------
0 |#22:0|Method|1 |1 |1 |1
----+-----+------+---------+-------+----------+----------
Hope it helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.