Hello,
Is it possible to create one index with two clauses “where” in the same bucket !
something like this : CREATE INDEX type ON default (type) where type = “rc-shop” and type = “rc-notification”;
query:
SELECT count(*)
FROM default as notif join default as shop
on keys “shop-” || TOSTRING(notif.fkidshop)
where ((notif.type = “rc-notification”) and (shop.type = “rc-shop”));
i’m traying to count shop with his notofications. (one shop can have a several notifications)
it the reason why i join notifications to shop.
the query works good but the probleme is time … it tooks 6 sec
i think that using secodry index will be better but for the moment i don’t find the magic recipe
Make LEFT side of join covered by using following index by including on keys.
CREATE INDEX idx_notif ON default (type,fkidshop) where type = “rc-notification”;
If you can add additional predicate you can remove type from index keys to make it LEAN.
CREATE INDEX idx_notif ON default (fkidshop) where type = “rc-notification”;
SELECT count(*)
FROM default as notif join default as shop
on keys “shop-” || TOSTRING(notif.fkidshop)
where notif.fkidshop is not null AND (notif.type = “rc-notification”) and (shop.type = “rc-shop”);
Hi @vsr1,
I tried LEFTjoin with this index (CREATE INDEX idx_notif ON default (type,fkidshop) where type = “rc-notification”)
but not better
the same with this index (CREATE INDEX idx_notif ON default (fkidshop) where type = “rc-notification”)
the query takes 5sec .
Hi @geraldss
I need to join notification to their shop. and select (shop and notification) ““count(*) was just un exmple””
the result is correct but it tooks a lotoff time and the explain is :
{
“#operator”: “Sequence”,
“~children”: [
{
“#operator”: “IndexScan”,
“index”: “notification”,
“index_id”: “b5bbe1a42b84828d”,
“keyspace”: “ruecentrale-main”,
“namespace”: “default”,
“spans”: [
{
“Range”: {
“High”: [
“"rc-notification"”
],
“Inclusion”: 3,
“Low”: [
“"rc-notification"”
]
}
}
],
“using”: “gsi”
},