Hi Garren,

Thanks for input. Very helpful. I will try to formalize and play a bit with
Explain feature to understand what actually it gives me.

Thanks,
Piotr

śr., 10 cze 2020 o 13:11 Garren Smith <[email protected]> napisał(a):

> Hi Piotr,
>
> If you have the above two indexes. If you specify docType and Age. It will
> use the index that has docType and Age. If you only specify age it will use
> all_docs because you do not have a suitable index. If you select only
> doctype it will use the index with docType. The _explain endpoint will give
> you some ideas on how it works.
>
> What is nice about Mango is in the beginning you don't have to create any
> indexes. You can just use it. So while you are building an application
> using the Mango endpoints rather don't create indexes and rather figure out
> the type of queries you want to do. Once you are further along and you know
> exactly the type of queries you want to perform with it. Then create
> indexes.
>
> I hope that helps a bit.
>
> Cheers
> Garren
>
>
> On Wed, Jun 10, 2020 at 8:33 AM Piotr Zarzycki <[email protected]>
> wrote:
>
> > Hi ermouth,
> >
> > Many Thanks for your suggestion regarding Help feature. I will go with
> that
> > for sure!
> >
> > Piotr
> >
> > wt., 9 cze 2020 o 14:27 ermouth <[email protected]> napisał(a):
> >
> > > > Just remember to ask the selector in the same order as they are
> indexed
> > >
> > > It doesn’t guarantee appropriate index will be used, however providing
> > > use_index param might help.
> > >
> > >
> >
> https://docs.couchdb.org/en/2.3.1/api/database/find.html?highlight=use_index
> > >
> > > ermouth
> > >
> > >
> > > вт, 9 июн. 2020 г. в 15:18, Andrea Brancatelli
> > > <[email protected]>:
> > >
> > > > 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>*
> >
>


-- 

Piotr Zarzycki

Patreon: *https://www.patreon.com/piotrzarzycki
<https://www.patreon.com/piotrzarzycki>*

Reply via email to