Hi All I need your valuable support. I have a few buckets and i need to join data between them selecting some attributes from several buckets. Bucket zStore has 100k Docs with Type “ItemId” and 200 Docs with Type “ItemsGroupId” , zDB has 1 Doc with Type “CustomerId”, 1 Doc with Type “TagId” and 1 Doc with Type “DiscountId”
The problem that i need the pagination on filtered data which can be achieved with 2 ways
- with standard count(*) filters followed by selection of needed data with same filters, means 2 queries
- use meta.metrics.sortCount from meta on executed query
I prefer second way, but here is problem rises. if remove order by, the query is fast (150-250 ms) but sortCount is missing from meta, when the Order By is back it sortCount exists, but response time is 90-115 s. How I can improve the response time keeping pagination working and with performance maximum around 1 second?
Indexes:
CREATE INDEX i_ItemBrowser_Tags ON
zStore(DISTINCT ARRAY tag FOR tag IN ItemTags END, ItemTags, ItemsGroupId, CustomerId, DateCreated) WHERE Type = "ItemId"
CREATE INDEX i_ItemBrowser_DateCreated ON
zStore(DateCreated) WHERE Type = "ItemId"
CREATE INDEX i_ItemBrowser_CustomerId ON
zStore(CustomerId) WHERE Type = "ItemId"
Here is the N1QL:
SELECT zstore.*
customers.CustomerName CustomerName,
itemsgroups.ItemsGroupName ItemsGroupName,
ARRAY {discount.DiscountId, discount.Desc} FOR discount IN discounts END as Discounts ,
ARRAY {tag.TagId, tag.TagName} FOR tag IN tags END as Tags
FROM zStore zstore
LEFT JOIN zDB customers ON KEYS zstore.CustomerId
LEFT JOIN zStore itemsgroups ON KEYS zstore.ItemsGroupId
LEFT NEST zDB discount ON KEYS ARRAY x FOR x IN itemsgroups.Discounts END
LEFT NEST zDB tags ON KEYS ARRAY tag FOR tag IN zstore.ItemTags END
WHERE
zstore.Type = “ItemId”
AND zstore.ItemId IS NOT MISSING
AND zstore.ItemId IS NOT NULL
ORDER BY zstore.DateCreated ASC
LIMIT 10
Above Query uses only Primary index, none of created indexes.
Here is entities structure:
Item
{
“CustomerId”:“cid_6ecbc0dd-ef> a9-4c6c-a048-4c47fea6ef80”,
“DateCreated”:1526377962555,
“DateModified”:152637796255,
“ItemDescription”:“ItemDescription”,
“ItemId”:“ItemId_89125352587396737040”,
“ItemName”:“ItemName”,
“ItemOrder”:0,
“ItemTags”:[
“TagId_dfcd2db7-7fcd-4257-ad06-a5f446ef8478”
],
“ItemsGroupId”:“ItemsGroupId_2e966c6b-66c6-4116-8028-6e3666c68028”,
“Type”:“ItemId”
}
ItemGroupe
{
“CustomerId”:“cid_6ecbc0dd-efa9-4c6c-a048-4c47fea6ef80”,
“DateCreated”:1526377962155,
“DateModified”:1526377962155,
“ItemsGroupDescription”:“ItemsGroupDescription”,
“ItemsGroupName”:“ItemsGroupName”,
“Discounts”:[
“DiscId_dfcd2db7-7fcd-4257-ad06-a5f446ef8478”
],
“ItemsGroupId”:“ItemsGroupId_6e36ea01a314-66c6-4116-8028-2e938a8b”,
“Type”:“ItemsGroupId”
}
Discount
{
“DateCreated”:1526377961166,
“DateModified”:1526377961166,
“Desc”:“DESCRIPTION CONTENT”,
“DiscountId”:“DiscountId_2e938a8b-66c6-4116-8028-6e36ea01a314”,
“Type”:“DiscountId”
}
Tag
{
“DateCreated”:1526377962299,
“DateModified”:1526377962299,
“TagName”:“TagName”,
“TagId”:“TagId_dfcd2db7-7fcd-4257-ad06-a5f446ef8478”,
“Type”:“TagId”
}
Customer
{
“DateCreated”:1526377963377,
“DateModified”:1526377963377,
“CustomerName”:“CustomerName”,
“CustomerId”:“cid_6ecbc0dd-efa9-4c6c-a048-4c47fea6ef80”,
“Type”:“CustomerId”
}
Thanks for your time.