Here is the explain (‘idx_visit_type_id’ = ‘ix1’):
[
{
"plan": {
"#operator": "Sequence",
"~children": [
{
"#operator": "DistinctScan",
"scan": {
"#operator": "IndexScan",
"covers": [
"cover ((`visit`.`visitType`))",
"cover (ifmissing((`visit`.`isVoided`), \"\"))",
"cover ((`visit`.`visitId`))",
"cover ((meta(`visit`).`id`))"
],
"index": "idx_visit_type_id",
"index_id": "77d2fec4de56c10d",
"keyspace": "default",
"namespace": "default",
"spans": [
{
"Range": {
"High": [
"\"VT_PATIENT_EXTERNE\"",
"successor(false)"
],
"Inclusion": 1,
"Low": [
"\"VT_PATIENT_EXTERNE\"",
"false"
]
}
},
{
"Range": {
"High": [
"\"VT_PATIENT_EXTERNE\"",
"successor(\"\")"
],
"Inclusion": 1,
"Low": [
"\"VT_PATIENT_EXTERNE\"",
"\"\""
]
}
}
],
"using": "gsi"
}
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "IndexJoin",
"as": "event",
"for": "visit",
"keyspace": "default",
"namespace": "default",
"on_key": "(`event`.`visitId`)",
"scan": {
"index": "idx_visitId",
"index_id": "b6498c75045de40a",
"using": "gsi"
}
},
{
"#operator": "Filter",
"condition": "(((((cover ((`visit`.`visitType`)) = \"VT_PATIENT_EXTERNE\") and ((`event`.`dateTime`) is valued)) and (not ((split(cover ((meta(`visit`).`id`)), \":\")[0]) = \"_sync\"))) and (cover (ifmissing((`visit`.`isVoided`), \"\")) in [false, \"\"])) and ((`event`.`type`) = \"EVENT\"))"
},
{
"#operator": "InitialGroup",
"aggregates": [
"max((`event`.`dateTime`))"
],
"group_keys": [
"(`event`.`visitId`)"
]
}
]
}
},
{
"#operator": "IntermediateGroup",
"aggregates": [
"max((`event`.`dateTime`))"
],
"group_keys": [
"(`event`.`visitId`)"
]
},
{
"#operator": "FinalGroup",
"aggregates": [
"max((`event`.`dateTime`))"
],
"group_keys": [
"(`event`.`visitId`)"
]
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Filter",
"condition": "((`event`.`visitId`) is not missing)"
},
{
"#operator": "InitialProject",
"result_terms": [
{
"as": "dateTime",
"expr": "max((`event`.`dateTime`))"
},
{
"expr": "(`event`.`visitId`)"
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
},
"text": "SELECT MAX(event.dateTime) as dateTime, event.visitId FROM default visit\nJOIN default event ON KEY event.visitId FOR visit\nWHERE visit.visitType = \"VT_PATIENT_EXTERNE\"\nAND event.dateTime IS VALUED\nAND SPLIT(META(visit).`id`,':')[0] != \"_sync\"\nAND IFMISSING(visit.isVoided,\"\") IN [false , \"\"] AND\nevent.`type` = \"EVENT\"\nGROUP BY event.visitId HAVING event.visitId IS NOT MISSING"
}
]