Please suggest how can i optimise this n1ql and how OR operator can be avoided. Kindly suggest on optimised n1ql and index

please suggest how can i optimise this n1ql and how OR operator can be avoided. Kindly suggest on optimised n1ql and index

select meta().id as keyId, store.id as store_id, store.pin as store_pin from StorageWarehouse where store.id=“123” or store.pin =“456”;

Sample doc -
{
“name” : “david”
“store” :
{
“id”: “123”,
“pin”: “234”
}
}

If you need results either of the value matched only way is use OR CLAUSE.

create index ix1 on StorageWarehouse (store.id);
create index ix2 on StorageWarehouse (store.pin);

SELECT meta().id as keyId, store.id as store_id, store.pin as store_pin 
FROM StorageWarehouse AS s
WHERE  store.id="123" OR store.pin ="456";

OR

create index ix1 on StorageWarehouse (store.id, store.pin);
create index ix2 on StorageWarehouse (store.pin, store.id);

SELECT meta().id as keyId, store.id as store_id, store.pin as store_pin 
FROM StorageWarehouse AS s
WHERE  store.id="123" 
UNION
SELECT meta().id as keyId, store.id as store_id, store.pin as store_pin 
FROM StorageWarehouse AS s
WHERE   store.pin ="456";

It will use both the indexes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.