N1QL select with type filtering

Hello,

I’m new to Couchbase but I’ve some little experience with CouchDB.

I’m really impressed by N1QL and I’d like to know if there is any performance difference between:

select * from bucket where meta().id between 'type::' and 'type::\ufff0'

select * from bucket where meta().id like 'type::%'

select * from bucket where type = 'type' (with a secondary index)

Thank you.

Hi @renato, all three forms can use an index, so they have the same performance profile. The first two query are roughly equivalent. The third query can be faster if it matches fewer documents than the other two.

Thanks for your impressions :slight_smile:

Thanks @geraldss.

If every id starting with ‘something::’ has a type: something attribute, the three queries will run in the same time (negligible difference)?

I prefer not storing the type attribute redundantly, so I’ll continue my tests using the like approach.

Thank you!