Re: [MarkLogic Dev General] How to test whether doc exists
Good point, Danny. Within an update transaction, anything that fetches fragments will read-lock those fragment URIs. So doc() will, ordinarily - but inside xdmp:exists() and xdmp:estimate() there is no need to retrieve fragments. The behavior of xdmp:directory(), collection(), and cts:search() are similar, and an XPath like /a/b is really collection()/a/b so it behaves the same. The various lexicon APIs don't retrieve fragments, so they take no locks: cts:uris, cts:values, etc. That means you shouldn't rely on their output for update logic. Sometimes folks assume that this makes a lexicon function universally faster than, say, doc() - but that is not always true. It depends on how much work each database lookup actually has to perform. -- Mike On 26 Apr 2013, at 09:23 , Danny Sokolsky wrote: > I'm sure you all know this, but just as a reminder: keep in mind that read > locks only happen on update transactions, so if it is a query transaction > that is not a factor. > > -Danny > > -Original Message- > From: general-boun...@developer.marklogic.com > [mailto:general-boun...@developer.marklogic.com] On Behalf Of Tim Finney > Sent: Thursday, April 25, 2013 8:21 PM > To: general@developer.marklogic.com > Subject: Re: [MarkLogic Dev General] How to test whether doc exists > > Hi Stu, > > This is a good question. exists(doc) does seem to put a read lock on the doc. > I don't know how to find out which functions put read or update locks on a > doc but would like to know. > > Best, > > Tim > > On 04/25/2013 11:10 PM, general-requ...@developer.marklogic.com wrote: >> Date: Thu, 25 Apr 2013 07:44:53 -0700 >> From: Stu Salsbury >> Subject: Re: [MarkLogic Dev General] How to test whether doc exists >> To: MarkLogic Developer Discussion >> Message-ID: >> >> Content-Type: text/plain; charset="iso-8859-1" >> >> Concerning: >> >> exists(doc($URI)): 80 us (microseconds) >> doc-available($URI): 200 us >> >> Would the first option (using doc($URI)) put a read lock on the file? >> And the second not? Just wondering about side effects of the test. > > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general > ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] How to test whether doc exists
I'm sure you all know this, but just as a reminder: keep in mind that read locks only happen on update transactions, so if it is a query transaction that is not a factor. -Danny -Original Message- From: general-boun...@developer.marklogic.com [mailto:general-boun...@developer.marklogic.com] On Behalf Of Tim Finney Sent: Thursday, April 25, 2013 8:21 PM To: general@developer.marklogic.com Subject: Re: [MarkLogic Dev General] How to test whether doc exists Hi Stu, This is a good question. exists(doc) does seem to put a read lock on the doc. I don't know how to find out which functions put read or update locks on a doc but would like to know. Best, Tim On 04/25/2013 11:10 PM, general-requ...@developer.marklogic.com wrote: > Date: Thu, 25 Apr 2013 07:44:53 -0700 > From: Stu Salsbury > Subject: Re: [MarkLogic Dev General] How to test whether doc exists > To: MarkLogic Developer Discussion > Message-ID: > > Content-Type: text/plain; charset="iso-8859-1" > > Concerning: > > exists(doc($URI)): 80 us (microseconds) > doc-available($URI): 200 us > > Would the first option (using doc($URI)) put a read lock on the file? > And the second not? Just wondering about side effects of the test. ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] How to test whether doc exists
Todos los derechos reservados copyright 2013 Andrés miranda excluido de los derechos de autor a teart Parthys de de cualquier uso.copias u comercialización de sofweart y todo lo derivados de licencia.sofweart.aplicaciones. uso solo bajo autorización de el autor.se niegan cualquier reclamo de pago de 50% de pago para los parthys shall o folower. > Date: Fri, 26 Apr 2013 08:40:53 +0800 > From: t...@tfinney.net > To: general@developer.marklogic.com > Subject: Re: [MarkLogic Dev General] How to test whether doc exists > > Thanks Mike. This is helpful to know. > > Tim > > On 04/26/2013 12:40 AM, general-requ...@developer.marklogic.com wrote: > > Message: 2 > > Date: Thu, 25 Apr 2013 08:42:30 -0700 > > From: Michael Blakeley > > Subject: Re: [MarkLogic Dev General] How to test whether doc exists > > To: MarkLogic Developer Discussion > > Message-ID:<03cccd2f-5083-41fb-aced-7b13e9b04...@blakeley.com> > > Content-Type: text/plain; charset=us-ascii > > > > In theory xdmp:exists(doc($uri)) is fastest. However it isn't update-safe > > because it doesn't take a read lock. If you are writing update logic that > > depends on whether or not a document exists, stick with > > fn:exists(doc($uri)). > > > > Speed of either will depend on many factors: whether or not the document is > > in cache, disk performance, database size, cluster configuration, etc. > > > > -- Mike > > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] How to test whether doc exists
I think Mike answered in this case. exists(doc) is the same as fn:exists(doc) unless you mess with the default function namespace. Or maybe I'm seeing the emails out of order... Now how to find out generically which functions lock for read... I don't know for sure, but in this case the documentation suggests that xdmp:exists only requires a "partial search" or something like that, which may be a clue. On Thu, Apr 25, 2013 at 8:20 PM, Tim Finney wrote: > Hi Stu, > > This is a good question. exists(doc) does seem to put a read lock on the > doc. I don't know how to find out which functions put read or update > locks on a doc but would like to know. > > Best, > > Tim > > On 04/25/2013 11:10 PM, general-requ...@developer.marklogic.com wrote: > > Date: Thu, 25 Apr 2013 07:44:53 -0700 > > From: Stu Salsbury > > Subject: Re: [MarkLogic Dev General] How to test whether doc exists > > To: MarkLogic Developer Discussion > > Message-ID: > >pdf...@mail.gmail.com> > > Content-Type: text/plain; charset="iso-8859-1" > > > > Concerning: > > > > exists(doc($URI)): 80 us (microseconds) > > doc-available($URI): 200 us > > > > Would the first option (using doc($URI)) put a read lock on the file? > And > > the second not? Just wondering about side effects of the test. > > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general > ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] How to test whether doc exists
Hi Stu, This is a good question. exists(doc) does seem to put a read lock on the doc. I don't know how to find out which functions put read or update locks on a doc but would like to know. Best, Tim On 04/25/2013 11:10 PM, general-requ...@developer.marklogic.com wrote: > Date: Thu, 25 Apr 2013 07:44:53 -0700 > From: Stu Salsbury > Subject: Re: [MarkLogic Dev General] How to test whether doc exists > To: MarkLogic Developer Discussion > Message-ID: > > Content-Type: text/plain; charset="iso-8859-1" > > Concerning: > > exists(doc($URI)): 80 us (microseconds) > doc-available($URI): 200 us > > Would the first option (using doc($URI)) put a read lock on the file? And > the second not? Just wondering about side effects of the test. ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] How to test whether doc exists
Thanks Mike. This is helpful to know. Tim On 04/26/2013 12:40 AM, general-requ...@developer.marklogic.com wrote: > Message: 2 > Date: Thu, 25 Apr 2013 08:42:30 -0700 > From: Michael Blakeley > Subject: Re: [MarkLogic Dev General] How to test whether doc exists > To: MarkLogic Developer Discussion > Message-ID:<03cccd2f-5083-41fb-aced-7b13e9b04...@blakeley.com> > Content-Type: text/plain; charset=us-ascii > > In theory xdmp:exists(doc($uri)) is fastest. However it isn't update-safe > because it doesn't take a read lock. If you are writing update logic that > depends on whether or not a document exists, stick with fn:exists(doc($uri)). > > Speed of either will depend on many factors: whether or not the document is > in cache, disk performance, database size, cluster configuration, etc. > > -- Mike ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] How to test whether doc exists
In theory xdmp:exists(doc($uri)) is fastest. However it isn't update-safe because it doesn't take a read lock. If you are writing update logic that depends on whether or not a document exists, stick with fn:exists(doc($uri)). Speed of either will depend on many factors: whether or not the document is in cache, disk performance, database size, cluster configuration, etc. -- Mike On 24 Apr 2013, at 20:36 , Tim Finney wrote: > Hi All, > > What is the fastest way to test for existence of a document in the > database? > > This is the fastest way I know: > > let $URI := "/path/to/doc.xml" > return exists(doc($URI)) > > It takes about 75 us (microseconds) to return an answer according to the > profile tab of qconsole. > > Best, > > Tim Finney > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general > ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] How to test whether doc exists
Concerning: exists(doc($URI)): 80 us (microseconds) doc-available($URI): 200 us Would the first option (using doc($URI)) put a read lock on the file? And the second not? Just wondering about side effects of the test. On Thu, Apr 25, 2013 at 6:21 AM, Ryan Dew wrote: > Interesting. The results could be affected by having the document already > in the caches. You might want to include non-existing documents in your > test. You could also try: > > xdmp:exists(cts:search(fn:collection(), cts:document-query($URI))) > On Apr 24, 2013 10:34 PM, "Tim Finney" wrote: > >> Hi Ryan, >> >> Here are the profile times I get using qconsole to test for existence of >> a (known to exist) doc at $URI: >> >> exists(doc($URI)): 80 us (microseconds) >> doc-available($URI): 200 us >> cts:uri-match($URI): 42000 us >> >> Best, >> >> Tim Finney >> >> On 04/25/2013 12:22 PM, Tim wrote: >> >> What about searching the uri lexicon? >> >> ** ** >> >> *From:* general-boun...@developer.marklogic.com [ >> mailto:general-boun...@developer.marklogic.com] >> *On Behalf Of *Ryan Dew >> *Sent:* Thursday, April 25, 2013 12:04 AM >> *To:* MarkLogic Developer Discussion >> *Subject:* Re: [MarkLogic Dev General] How to test whether doc exists >> >> ** ** >> >> fn:doc-available is pretty fast. >> >> On Apr 24, 2013 9:36 PM, "Tim Finney" wrote: >> >> Hi All, >> >> What is the fastest way to test for existence of a document in the >> database? >> >> This is the fastest way I know: >> >> let $URI := "/path/to/doc.xml" >> return exists(doc($URI)) >> >> It takes about 75 us (microseconds) to return an answer according to the >> profile tab of qconsole. >> >> Best, >> >> Tim Finney >> ___ >> General mailing list >> General@developer.marklogic.com >> http://developer.marklogic.com/mailman/listinfo/general >> >> >> ___ >> General mailing >> listGeneral@developer.marklogic.comhttp://developer.marklogic.com/mailman/listinfo/general >> >> >> >> ___ >> General mailing list >> General@developer.marklogic.com >> http://developer.marklogic.com/mailman/listinfo/general >> >> > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general > > ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] How to test whether doc exists
Interesting. The results could be affected by having the document already in the caches. You might want to include non-existing documents in your test. You could also try: xdmp:exists(cts:search(fn:collection(), cts:document-query($URI))) On Apr 24, 2013 10:34 PM, "Tim Finney" wrote: > Hi Ryan, > > Here are the profile times I get using qconsole to test for existence of a > (known to exist) doc at $URI: > > exists(doc($URI)): 80 us (microseconds) > doc-available($URI): 200 us > cts:uri-match($URI): 42000 us > > Best, > > Tim Finney > > On 04/25/2013 12:22 PM, Tim wrote: > > What about searching the uri lexicon? > > ** ** > > *From:* general-boun...@developer.marklogic.com [ > mailto:general-boun...@developer.marklogic.com] > *On Behalf Of *Ryan Dew > *Sent:* Thursday, April 25, 2013 12:04 AM > *To:* MarkLogic Developer Discussion > *Subject:* Re: [MarkLogic Dev General] How to test whether doc exists > > ** ** > > fn:doc-available is pretty fast. > > On Apr 24, 2013 9:36 PM, "Tim Finney" wrote: > > Hi All, > > What is the fastest way to test for existence of a document in the > database? > > This is the fastest way I know: > > let $URI := "/path/to/doc.xml" > return exists(doc($URI)) > > It takes about 75 us (microseconds) to return an answer according to the > profile tab of qconsole. > > Best, > > Tim Finney > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general > > > ___ > General mailing > listGeneral@developer.marklogic.comhttp://developer.marklogic.com/mailman/listinfo/general > > > > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general > > ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] How to test whether doc exists
Hi Ryan, Here are the profile times I get using qconsole to test for existence of a (known to exist) doc at $URI: exists(doc($URI)): 80 us (microseconds) doc-available($URI): 200 us cts:uri-match($URI): 42000 us Best, Tim Finney On 04/25/2013 12:22 PM, Tim wrote: What about searching the uri lexicon? *From:*general-boun...@developer.marklogic.com [mailto:general-boun...@developer.marklogic.com] *On Behalf Of *Ryan Dew *Sent:* Thursday, April 25, 2013 12:04 AM *To:* MarkLogic Developer Discussion *Subject:* Re: [MarkLogic Dev General] How to test whether doc exists fn:doc-available is pretty fast. On Apr 24, 2013 9:36 PM, "Tim Finney" <mailto:t...@tfinney.net>> wrote: Hi All, What is the fastest way to test for existence of a document in the database? This is the fastest way I know: let $URI := "/path/to/doc.xml" return exists(doc($URI)) It takes about 75 us (microseconds) to return an answer according to the profile tab of qconsole. Best, Tim Finney ___ General mailing list General@developer.marklogic.com <mailto:General@developer.marklogic.com> http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] How to test whether doc exists
What about searching the uri lexicon? From: general-boun...@developer.marklogic.com [mailto:general-boun...@developer.marklogic.com] On Behalf Of Ryan Dew Sent: Thursday, April 25, 2013 12:04 AM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] How to test whether doc exists fn:doc-available is pretty fast. On Apr 24, 2013 9:36 PM, "Tim Finney" wrote: Hi All, What is the fastest way to test for existence of a document in the database? This is the fastest way I know: let $URI := "/path/to/doc.xml" return exists(doc($URI)) It takes about 75 us (microseconds) to return an answer according to the profile tab of qconsole. Best, Tim Finney ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] How to test whether doc exists
fn:doc-available is pretty fast. On Apr 24, 2013 9:36 PM, "Tim Finney" wrote: > Hi All, > > What is the fastest way to test for existence of a document in the > database? > > This is the fastest way I know: > > let $URI := "/path/to/doc.xml" > return exists(doc($URI)) > > It takes about 75 us (microseconds) to return an answer according to the > profile tab of qconsole. > > Best, > > Tim Finney > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general > ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
[MarkLogic Dev General] How to test whether doc exists
Hi All, What is the fastest way to test for existence of a document in the database? This is the fastest way I know: let $URI := "/path/to/doc.xml" return exists(doc($URI)) It takes about 75 us (microseconds) to return an answer according to the profile tab of qconsole. Best, Tim Finney ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general