Hi,
I have below query:
SELECT a.data_number AS dataNumber
FROM mybucket a
WHERE a.type_ = 'TEST'
AND a.group_number = '1'
AND a.accounting_year = 2021
AND a.accounting_month = 1
AND a.transaction_code = 'xxx'
AND a.transaction_date IS NOT MISSING
ORDER BY a.transaction_date
LIMIT 10 OFFSET 10
CREATE INDEX `idx-mybucket-TEST-01-Group` ON `mybucket`(`type_`,`group_number`,`accounting_year`,`accounting_month`,`total`,`premium_category`,`billing_frequency`,`counter`,`data_number`,`currency`,`transaction_code`,`transaction_date`) PARTITION BY hash(`accounting_year`,`accounting_month`) WHERE (`type_` = "TEST") WITH { "defer_build":true, "num_partition":8 }
I’ve found although I limit to 10 rows, the itemsOut is around 17k data that makes it slow during the process:
{
"#operator": "Sequence",
"#stats": {
"#phaseSwitches": 1,
"execTime": "5.429µs"
},
"~children": [
{
"#operator": "Authorize",
"#stats": {
"#phaseSwitches": 3,
"execTime": "24.508µs",
"servTime": "2.261147ms"
},
"privileges": {
"List": [
{
"Target": "default:mybucket",
"Priv": 7
}
]
},
"~child": {
"#operator": "Sequence",
"#stats": {
"#phaseSwitches": 1,
"execTime": "10.001µs"
},
"~children": [
{
"#operator": "Sequence",
"#stats": {
"#phaseSwitches": 1,
"execTime": "3.297µs"
},
"~children": [
{
"#operator": "IndexScan3",
"#stats": {
"#itemsOut": 17590,
"#phaseSwitches": 70363,
"execTime": "112.942389ms",
"kernTime": "10.93407ms",
"servTime": "196.44694ms"
},
"as": "a",
"covers": [
"cover ((`a`.`type_`))",
"cover ((`a`.`group_number`))",
"cover ((`a`.`accounting_year`))",
"cover ((`a`.`accounting_month`))",
"cover ((`a`.`total`))",
"cover ((`a`.`premium_category`))",
"cover ((`a`.`billing_frequency`))",
"cover ((`a`.`counter`))",
"cover ((`a`.`data_number`))",
"cover ((`a`.`currency`))",
"cover ((`a`.`transaction_code`))",
"cover ((`a`.`transaction_date`))",
"cover ((meta(`a`).`id`))"
],
"filter_covers": {
"cover ((`a`.`type_`))": "TEST"
},
"index": "idx-mybucket-TEST-01-Group",
"index_id": "6c3926823f85f417",
"index_projection": {
"entry_keys": [
0,
1,
2,
3,
8,
10,
11
]
},
"keyspace": "mybucket",
"namespace": "default",
"spans": [
{
"exact": true,
"range": [
{
"high": "\"TEST\"",
"inclusion": 3,
"low": "\"TEST\""
},
{
"high": "\"1\"",
"inclusion": 3,
"low": "\"1\""
},
{
"high": "2021",
"inclusion": 3,
"low": "2021"
},
{
"high": "1",
"inclusion": 3,
"low": "1"
},
{
"inclusion": 0
},
{
"inclusion": 0
},
{
"inclusion": 0
},
{
"inclusion": 0
},
{
"inclusion": 0
},
{
"inclusion": 0
},
{
"high": "\"xxx\"",
"inclusion": 3,
"low": "\"xxx\""
},
{
"inclusion": 1,
"low": "null"
}
]
}
],
"using": "gsi",
"#time_normal": "00:00.309",
"#time_absolute": 0.30938932900000005
},
{
"#operator": "Sequence",
"#stats": {
"#phaseSwitches": 1,
"execTime": "2.943µs"
},
"~children": [
{
"#operator": "Filter",
"#stats": {
"#itemsIn": 17590,
"#itemsOut": 17590,
"#phaseSwitches": 70363,
"execTime": "109.082068ms",
"kernTime": "211.354155ms"
},
"condition": "((((((cover ((`a`.`type_`)) = \"TEST\") and (cover ((`a`.`group_number`)) = \"1\")) and (cover ((`a`.`accounting_year`)) = 2021)) and (cover ((`a`.`accounting_month`)) = 1)) and (cover ((`a`.`transaction_code`)) = \"xxx\")) and (cover ((`a`.`transaction_date`)) is not missing))",
"#time_normal": "00:00.109",
"#time_absolute": 0.109082068
},
{
"#operator": "InitialProject",
"#stats": {
"#itemsIn": 17590,
"#itemsOut": 17590,
"#phaseSwitches": 70363,
"execTime": "82.005176ms",
"kernTime": "238.496995ms"
},
"result_terms": [
{
"as": "dataNumber",
"expr": "cover ((`a`.`data_number`))"
}
],
"#time_normal": "00:00.082",
"#time_absolute": 0.082005176
}
],
"#time_normal": "00:00.000",
"#time_absolute": 0.000002943
}
],
"#time_normal": "00:00.000",
"#time_absolute": 0.000003297
},
{
"#operator": "Order",
"#stats": {
"#itemsIn": 17590,
"#itemsOut": 20,
"#phaseSwitches": 35205,
"execTime": "25.402968ms",
"kernTime": "295.21339ms"
},
"limit": "10",
"offset": "10",
"sort_terms": [
{
"expr": "cover ((`a`.`transaction_date`))"
}
],
"#time_normal": "00:00.025",
"#time_absolute": 0.025402968
},
{
"#operator": "Offset",
"#stats": {
"#itemsIn": 20,
"#itemsOut": 10,
"#phaseSwitches": 31,
"execTime": "13.572µs"
},
"expr": "10",
"#time_normal": "00:00.000",
"#time_absolute": 0.000013572
},
{
"#operator": "Limit",
"#stats": {
"#itemsIn": 10,
"#itemsOut": 10,
"#phaseSwitches": 21,
"execTime": "7.677µs"
},
"expr": "10",
"#time_normal": "00:00.000",
"#time_absolute": 0.000007677
},
{
"#operator": "FinalProject",
"#stats": {
"#itemsIn": 10,
"#itemsOut": 10,
"#phaseSwitches": 31,
"execTime": "9.742µs",
"kernTime": "121.047µs"
},
"#time_normal": "00:00.000",
"#time_absolute": 0.000009742000000000001
}
],
"#time_normal": "00:00.000",
"#time_absolute": 0.000010001
},
"#time_normal": "00:00.002",
"#time_absolute": 0.0022856549999999997
},
{
"#operator": "Stream",
"#stats": {
"#itemsIn": 10,
"#itemsOut": 10,
"#phaseSwitches": 23,
"execTime": "97.627µs",
"kernTime": "323.01018ms"
},
"#time_normal": "00:00.000",
"#time_absolute": 0.00009762699999999999
}
],
"~versions": [
"6.5.0-N1QL",
"6.5.1-6299-enterprise"
],
"#time_normal": "00:00.000",
"#time_absolute": 0.000005429
}
What do I missed in here? Why total itemsOut is still 17k instead of 10?
Do I need to create another indexes to fasten the query performance?
Thanks