The query now took 8.5 seconds to run. Here is the EXPLAIN
:
{
"requestID": "dd8b1e3d-2e91-4103-b608-457cb8351972",
"clientContextID": "725b88a6-4e53-451e-8cee-f9aa79dff8cf",
"signature": "json",
"results": [
{
"plan": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Sequence",
"~children": [
{
"#operator": "IndexScan",
"index": "ix1",
"index_id": "1458255227e07249",
"keyspace": "default",
"namespace": "default",
"spans": [
{
"Range": {
"Inclusion": 1,
"Low": [
"\"1990-01-01\""
]
}
}
],
"using": "gsi"
},
{
"#operator": "Fetch",
"as": "users",
"keyspace": "default",
"namespace": "default"
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Unnest",
"as": "stores",
"expr": "(`users`.`stores`)"
}
]
}
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Filter",
"condition": "((((((`users`.`type`) = \"User\") and (\"1990-01-01\" <= (`users`.`birthday`))) and ((`stores`.`storeId`) = \"b44412f1-5595-44fc-a90d-0983fb60ec73\")) and any `v` in (`users`.`stores`) satisfies (\"2017-01-01\" <= (`v`.`signup`)) end) and (\"2017-01-01\" <= (`stores`.`signup`)))"
},
{
"#operator": "InitialProject",
"result_terms": [
{
"expr": "(`users`.`name`)"
},
{
"expr": "(`stores`.`signup`)"
}
]
}
]
}
}
]
},
{
"#operator": "Order",
"limit": "10",
"sort_terms": [
{
"desc": true,
"expr": "(`stores`.`signup`)"
}
]
},
{
"#operator": "Limit",
"expr": "10"
},
{
"#operator": "FinalProject"
}
]
},
"text": "SELECT users.name, stores.signup\nFROM default users USE INDEX(ix1)\nUNNEST users.stores AS stores\nWHERE users.type=\"User\" \nAND users.birthday >= \"1990-01-01\"\nAND stores.storeId=\"b44412f1-5595-44fc-a90d-0983fb60ec73\"\nAND ANY v IN users.stores SATISFIES v.signup>=\"2017-01-01\" END\nAND stores.signup >=\"2017-01-01\"\nORDER BY stores.signup DESC \nLIMIT 10"
}
],
"status": "success",
"metrics": {
"elapsedTime": "3.603619ms",
"executionTime": "3.55958ms",
"resultCount": 1,
"resultSize": 4568
}
}
The user document I have put here is a simplified version of the actual document. We are creating an index on the birthday
, but every user field could potentially be a part of the filter. Should we index all of those fields that can be a part of the filter?