I have 2 buckets (dossier: 280.000 records and execution: 898.000 records).
When I perform a query with a join, the performance is very slow (17s).
dossier is indexed on primary
execution has a property dossierId that contains the reference to dossier.
execution has an index on ‘procedure.id’
Example queries (just to show the issue, the queries are different in the app):
select count()
from execution execution
where execution.procedure
.id=1
==> 350 ms, this is fast
select count()
from execution execution
left outer join dossier d on keys execution.dossierId
where execution.procedure
.id=1
==> 17s, very slow
In this case, the count is exactly the same (it should be).
Another example:
select count()
from execution execution
inner join dossier dossier on keys execution.dossierId
where execution.procedure
.id=1
and dossier.naam=‘Hilay’
=> 17s
And there is an index on dossier.naam, but that index is not used.
Explain:
[
{
“plan”: {
"#operator": “Sequence”,
"~children": [
{
"#operator": “IndexScan”,
“index”: “execution_procedureId”,
“index_id”: “a5ee4ba1318c93ec”,
“keyspace”: “execution”,
“namespace”: “default”,
“spans”: [
{
“Range”: {
“High”: [
“1”
],
“Inclusion”: 3,
“Low”: [
“1”
]
}
}
],
“using”: “gsi”
},
{
"#operator": “Parallel”,
"~child": {
"#operator": “Sequence”,
"~children": [
{
"#operator": “Fetch”,
“as”: “execution”,
“keyspace”: “execution”,
“namespace”: “default”
},
{
"#operator": “Join”,
“as”: “dossier”,
“keyspace”: “dossier”,
“namespace”: “default”,
“on_keys”: “(execution
.dossierId
)”
},
{
"#operator": “Filter”,
“condition”: “((((execution
.procedure
).id
) = 1) and ((dossier
.naam
) = “Hilay”))”
},
{
"#operator": “InitialGroup”,
“aggregates”: [
"count()"
],
“group_keys”: []
}
]
}
},
{
"#operator": “IntermediateGroup”,
“aggregates”: [
“count()"
],
“group_keys”: []
},
{
"#operator": “FinalGroup”,
“aggregates”: [
"count()”
],
“group_keys”: []
},
{
"#operator": “Parallel”,
"~child": {
"#operator": “Sequence”,
"~children": [
{
"#operator": “InitialProject”,
“result_terms”: [
{
“expr”: “count()"
}
]
},
{
"#operator": “FinalProject”
}
]
}
}
]
},
“text”: "\nselect count()\nfrom execution execution\ninner join dossier dossier on keys execution.dossierId\nwhere execution.procedure
.id=1\nand dossier.naam=‘Hilay’”
}
]