Hi Andrea, Even that empiric usage is really helpful and helps formalize some plan on that. I hope someone with CouchDb code knowledge will answer and shed even more light on that.
Thank you so much, Piotr wt., 9 cze 2020 o 14:18 Andrea Brancatelli <[email protected]> napisał(a): > As ermouth said the best approach is to use the explain feature of Fauxton > / Photon. > Couch tries to guess what's the best index to use for any case so you > don't necessarily need to build complex indexes, if you ask for more > selectors than the indexed ones usually it picks an index and then scan the > documents to apply the subselectors. > > Yet I must admit I feel the logic behind it a bit entropic and cumbersome. > > Just remember to ask the selector in the same order as they are indexed, > even for partial indexes. > > Like a select for { fieldA, fieldB, fieldC } and an index for { fieldA, > fieldB } would work as you expect, but if the index was on { fieldA, fieldC > } it won't get used. > > On the contrary I don't think Couch is (yet?) able to to Union between > indexes, so if you have index { fieldA } index { fieldB } and ask for > select { fieldA, fieldB } only index { fieldA } will be used and then all > the documents will be processed to find the subset. > > That's my empiric deduction from some usage, but someone with the hands on > the code can probably correct me. > > > --- > > *Andrea Brancatelli > > * > > On 2020-06-09 13:21, Piotr Zarzycki wrote: > > Hi Aurélien, > > It is not actually about any specific case. My questions are just helpers > to truly understand what approach we should take in our database. I just > have hope that I will get more understanding to get answer to some cases. > > Answer to your questions inline. > > wt., 9 cze 2020 o 13:04 Aurélien Bénel <[email protected]> napisał(a): > > Hi Piotr, > > Let's say that I have created two indexes for fields "docType" and "age": > (...) > My question is - How CouchDb will behave in case when I'm searching my db > using both fields when there are two indexes which contains the same > fields? > > > To answer your question (at least with js views, I don't use Mango but I > suppose it to be similar), > we need more details: > > - Are both fields variable parameters ? Or is one of them a constant? > > > I think both cases I would consider. However the first one would be that > I'm searching using both fields as a variable parameters. I'm not sure > about constant question. I think non of those fields are constant - I mean > from the database point of view docType won't change in the document that's > for sure. > > > - Will both parameters be always set ? If not, which one might be unset? > > Let's assume that it always will, but like I said what if I'm looking only > > and searching/querying using docType only ? > > > > Regards, > > Aurélien > > > -- Piotr Zarzycki Patreon: *https://www.patreon.com/piotrzarzycki <https://www.patreon.com/piotrzarzycki>*
