Hi !
I have problem with locking concept in my application (ADO.NET , C#).
Application has several documents which looks like Order.
My question is what and how should I lock those documents.
1.Lock document as a whole (Order + OrderLines) so another user can't work
on this document (pessimistic lock)?
1.1. How to implement this on SQL server ?
2.Should I use optimistic locking on Order and OrderLines ?
3.If I use optimistic locking on OrderLines should I each time update
timestamp of Order
and by each insert, update and read of OrderLine check whether somebody
has changed this Order and/or OrderLine which is both possible ?
Any thoughts are appreciated!"Marek" <marek@.home.puton.cz> wrote in message
news:%23OCPpamIGHA.3192@.TK2MSFTNGP10.phx.gbl...
> Hi !
>
> I have problem with locking concept in my application (ADO.NET , C#).
> Application has several documents which looks like Order.
> My question is what and how should I lock those documents.
>
> 1.Lock document as a whole (Order + OrderLines) so another user can't work
> on this document (pessimistic lock)?
> 1.1. How to implement this on SQL server ?
my advice: forget about #1. what #1 really means? either selecting the data
with (updlock,holdlock) or something similar, and keeping the transaction
open for indefinite amount of time (no, no, no, and no), or setting some
flag, marking that the document is being edited by a client, which is
somewhat better, but still leaves you with the housekeeping problems that
have to be dealt with from the application (and relying on application to
take care of things is generally not a good idea).
> 2.Should I use optimistic locking on Order and OrderLines ?
i would. and i do.
> 3.If I use optimistic locking on OrderLines should I each time update
> timestamp of Order
> and by each insert, update and read of OrderLine check whether somebody
> has changed this Order and/or OrderLine which is both possible ?
a timestamp column will be updated automatically each time data in the row
is updated, you just have to check whether it's value is same as what it was
when the row was read.
it's just my opinion, of course..
dean|||
> a timestamp column will be updated automatically each time data in the row
> is updated, you just have to check whether it's value is same as what it
> was when the row was read.
> it's just my opinion, of course..
> dean
Tnx Dean, but I believe that you answer is over simplified
and does not address all the issues ...
What should happened when orderline is updated ?
should order also be touched (so timestamp can change)
Is this sequence right when updating Orderline ?
1.Get TimeStamp of Order
2. Get TimeStamp of OrderLine
3. User changes orderline
4. Check if Order was changed meanwhile
4. 1 If yes there is a conflict since somebody changed order while I was
updating OrderLine
5. Check if OrderLine was changed
5.1 If yes there is a conflict since somebody changed OrderLine line while I
was updating OrderLine
6. Update OrderLine
7. Touch Order
or there is not need to check for Order Timestamp
when updating OrderLine in this case|||If you acquire locks in the correct order and hold them until the end of the
transaction, no other user will be able to change any rows that you have
locked until the transaction is either committed or rolled back.
ML
http://milambda.blogspot.com/|||hi, marek
yes, it was somewhat simplified, i agree. the actual implementation depends
on the actual business requirements (eg, is it ok that two people work with
different lineitems of the same document?), so this sequence could be
right - provided that everything from (and including) #4 is isolated inside
a transaction.
dean
"Marek" <marek@.home.puton.cz> wrote in message
news:uQlLHnnIGHA.3060@.TK2MSFTNGP10.phx.gbl...
>
> Tnx Dean, but I believe that you answer is over simplified
> and does not address all the issues ...
> What should happened when orderline is updated ?
> should order also be touched (so timestamp can change)
> Is this sequence right when updating Orderline ?
> 1.Get TimeStamp of Order
> 2. Get TimeStamp of OrderLine
> 3. User changes orderline
> 4. Check if Order was changed meanwhile
> 4. 1 If yes there is a conflict since somebody changed order while I was
> updating OrderLine
> 5. Check if OrderLine was changed
> 5.1 If yes there is a conflict since somebody changed OrderLine line while
> I was updating OrderLine
> 6. Update OrderLine
> 7. Touch Order
> or there is not need to check for Order Timestamp
> when updating OrderLine in this case
>
>|||Well it's interesting how would you solve the problem
when two people must not work with 2 different Orderlines
of the same Order ? Should we use pessimistic locking than ?
Another question that arises when considering scenario below is
how many roundtrips to SQL requires such a solution ?
Steps 1,2 - one roundtrip
Steps 4,5 - one roundtrip
Steps 6,7 - one roundtrip
Can this be smaller number than 3 ?
> yes, it was somewhat simplified, i agree. the actual implementation
> depends on the actual business requirements (eg, is it ok that two people
> work with different lineitems of the same document?), so this sequence
> could be right - provided that everything from (and including) #4 is
> isolated inside a transaction.
>|||not more than 2 roundtrips - 1&2 is one, 4-7 the other one, inside a stored
procedure, inside a transaction.
dean
"Marek" <marek@.home.puton.cz> wrote in message
news:OIqObNoIGHA.524@.TK2MSFTNGP09.phx.gbl...
> Well it's interesting how would you solve the problem
> when two people must not work with 2 different Orderlines
> of the same Order ? Should we use pessimistic locking than ?
> Another question that arises when considering scenario below is
> how many roundtrips to SQL requires such a solution ?
> Steps 1,2 - one roundtrip
> Steps 4,5 - one roundtrip
> Steps 6,7 - one roundtrip
> Can this be smaller number than 3 ?
>
>
>|||Tnx. Dean
That looks like a reasonable solution
with minimum overhead on SQL server side.
And what would be theoretical scenario:
1. when two people must not work with 2 different Orderlines of the same
order
2. two people must work not with the same Order at all ?
Does this require pessimistic lock and an open connection during
order/orderline update or is there better simpler solution ?
I have two solutions on my mind:
1. Lock the whole Order and child Orderlines with hold lock so nobody
can update those records.
2. Create LockingTable (RecordId, UserId) and hold connection open
on this record in LockingTable so if program crashes
SQL server will release lock. Before reading record With 'SELECT (NOLOCK)'
read
wheather record is locked and if it is tell the user who locks the record.
But both solutions require open connection ?
I'm I missing something ?
"Dean" <dvitner@.nospam.gmail.com> wrote in message
news:uxNdmVoIGHA.1836@.TK2MSFTNGP11.phx.gbl...
> not more than 2 roundtrips - 1&2 is one, 4-7 the other one, inside a
> stored procedure, inside a transaction.
> dean
> "Marek" <marek@.home.puton.cz> wrote in message
> news:OIqObNoIGHA.524@.TK2MSFTNGP09.phx.gbl...
>|||hi again,
as i see it, this whole optimistic vs pessimistic thing is really a business
problem. in most cases, unless you're dealing with some very chaotic
organization, it is well known who can do what with what data. it is not
unusual to have an owner for the document, and only that person is permitted
to make updates to the specific document. this type of scenario (involving
update conflicts) is rather unlikely in the real world, imo. sometimes it's
practically impossible, sometimes it's desirable, even required (why not let
several people do the data entry on an inventory list?). to answer the
question 'how to deal with it?' is really up to your customers. ask them, is
it possible at all? how often could it happen? how severe will the
consequences be? most of them, in my experience, could live with an update
conflict here and there - as long as you can tell them what happened, and
who was competing with them. auditing is here much more important than
locking.
technically speaking, would you really want to let the user opet a
transaction, select the data and place and hold update lock on the data,
then keep the data locked for nobody knows how long (he might go to lunch,
or go home or whatever - you have no control over it), and eventually at
some point in time decide to end the transaction, with or without any
change? first of all, transactions should be short-lived - started as late
as possible, and ended as soon as possible. they eat up resorces on server,
and keep others from accessing data. i can't think of a real-world situation
that would justify such a scenario.
you have come to a rather good practical solution yourself (in your previous
post) - why not use it?
dean
"Marek" <marek@.home.puton.cz> wrote in message
news:eXoRwooIGHA.3144@.TK2MSFTNGP11.phx.gbl...
> Tnx. Dean
> That looks like a reasonable solution
> with minimum overhead on SQL server side.
> And what would be theoretical scenario:
> 1. when two people must not work with 2 different Orderlines of the same
> order
> 2. two people must work not with the same Order at all ?
> Does this require pessimistic lock and an open connection during
> order/orderline update or is there better simpler solution ?
> I have two solutions on my mind:
> 1. Lock the whole Order and child Orderlines with hold lock so nobody
> can update those records.
> 2. Create LockingTable (RecordId, UserId) and hold connection open
> on this record in LockingTable so if program crashes
> SQL server will release lock. Before reading record With 'SELECT (NOLOCK)'
> read
> wheather record is locked and if it is tell the user who locks the record.
> But both solutions require open connection ?
> I'm I missing something ?
>
>
> "Dean" <dvitner@.nospam.gmail.com> wrote in message
> news:uxNdmVoIGHA.1836@.TK2MSFTNGP11.phx.gbl...
>|||Thanks Dean !
I don't have such situation , but I was just thinking aloud.
Currently in my firm there is an old proprietary system which uses
pessimistic
locking and it works fine, so I was thinking how this can be implemented on
SQL server.
Since the whole architecture of ADO.NET does not encourage pessimistic
locking
and there is no business need to support it I will definitely use solution
to that we came up in previous posts. Thanky you again for a thoughtful
posts
that have broadened my "data access" sights !
"Dean" <dvitner@.nospam.gmail.com> wrote in message
news:unvH%23hqIGHA.2708@.tk2msftngp13.phx.gbl...
> hi again,
> as i see it, this whole optimistic vs pessimistic thing is really a
> business problem. in most cases, unless you're dealing with some very
> chaotic organization, it is well known who can do what with what data. it
> is not unusual to have an owner for the document, and only that person is
> permitted to make updates to the specific document. this type of scenario
> (involving update conflicts) is rather unlikely in the real world, imo.
> sometimes it's practically impossible, sometimes it's desirable, even
> required (why not let several people do the data entry on an inventory
> list?). to answer the question 'how to deal with it?' is really up to your
> customers. ask them, is it possible at all? how often could it happen? how
> severe will the consequences be? most of them, in my experience, could
> live with an update conflict here and there - as long as you can tell them
> what happened, and who was competing with them. auditing is here much more
> important than locking.
> technically speaking, would you really want to let the user opet a
> transaction, select the data and place and hold update lock on the data,
> then keep the data locked for nobody knows how long (he might go to lunch,
> or go home or whatever - you have no control over it), and eventually at
> some point in time decide to end the transaction, with or without any
> change? first of all, transactions should be short-lived - started as late
> as possible, and ended as soon as possible. they eat up resorces on
> server, and keep others from accessing data. i can't think of a real-world
> situation that would justify such a scenario.
> you have come to a rather good practical solution yourself (in your
> previous post) - why not use it?
> dean
> "Marek" <marek@.home.puton.cz> wrote in message
> news:eXoRwooIGHA.3144@.TK2MSFTNGP11.phx.gbl...
>
Showing posts with label documents. Show all posts
Showing posts with label documents. Show all posts
Friday, February 24, 2012
Sunday, February 12, 2012
Anyway to quick ntext Search
Helloo..
I there anyway to make ntext search faster'
I have a table of legal documents with 2 million text record, While no full
text index & search on text fields searching with "Like is very very slow".
I need anyway to make it faster using any techniques..
Do i need to use cursor or how can i solve this issue'
I can't use nvarchar coz of size limititionIslamegy wrote on Wed, 23 Nov 2005 14:18:28 +0200:
> Helloo..
> I there anyway to make ntext search faster'
> I have a table of legal documents with 2 million text record, While no
> full text index & search on text fields searching with "Like is very very
> slow". I need anyway to make it faster using any techniques..
> Do i need to use cursor or how can i solve this issue'
> I can't use nvarchar coz of size limitition
Any particular reason why you can't use Full Text Search?
Dan|||Because Full Text index dosn't apply of Text Fields of type "text",
"ntext"!!!
"Daniel Crichton" <msnews@.worldofspack.co.uk> wrote in message
news:ujyy8%23C8FHA.956@.TK2MSFTNGP10.phx.gbl...
> Islamegy wrote on Wed, 23 Nov 2005 14:18:28 +0200:
>
> Any particular reason why you can't use Full Text Search?
> Dan
>|||Islamegy wrote on Wed, 23 Nov 2005 15:27:02 +0200:
> Because Full Text index dosn't apply of Text Fields of type "text",
> "ntext"!!!
Yes it does. I'm using it on a text column in one of my databases!
Dan|||Yes, performing a non-indexed search on the text of 2 million documents is
going to be slow. I'm surprised that it's just optimization you are
concerned with and the actual feasability.
Of course, consider using the Full-Text feature.
If you must perform LIKE comparisons on the rows, perhaps it would be
possible to run a process that parses the text of each document and then
stores key words in something like a 120 length varchar column.
For example:
Jacobs;California;McNeal;disability;insu
rance;claim
Once done, this column could be used for LIKE searches.
"Islamegy" <NULL_Islamegy_NULL@.yahoo.com> wrote in message
news:OoYHFgC8FHA.1420@.TK2MSFTNGP09.phx.gbl...
> Helloo..
> I there anyway to make ntext search faster'
> I have a table of legal documents with 2 million text record, While no
> full text index & search on text fields searching with "Like is very very
> slow".
> I need anyway to make it faster using any techniques..
> Do i need to use cursor or how can i solve this issue'
> I can't use nvarchar coz of size limitition
>|||Why would you think that? It does in fact work on text and ntext columns.
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net
"Islamegy" <NULL_Islamegy_NULL@.yahoo.com> wrote in message
news:evIRZGD8FHA.2036@.TK2MSFTNGP14.phx.gbl...
> Because Full Text index dosn't apply of Text Fields of type "text",
> "ntext"!!!
> "Daniel Crichton" <msnews@.worldofspack.co.uk> wrote in message
> news:ujyy8%23C8FHA.956@.TK2MSFTNGP10.phx.gbl...
>|||How do u do it' When i try to use "Contain(Text column,"some words").. it
don't accept my query!!
As i know from my research it dosn't work on text..
Anyway my database is Arabic, so i thought ntext is ok but when i converted
it to text it became 20% faster.
Also finally i discovered that collation is work as a magic. When i switched
it from Arabic_CI_AI to Arabic_BIN this cut the search time to the half. for
now this is really so great success, if you have anyone have ideas for more
improvment plz let me now..
thanx
"Daniel Crichton" <msnews@.worldofspack.co.uk> wrote in message
news:%23wC2$MD8FHA.2676@.TK2MSFTNGP15.phx.gbl...
> Islamegy wrote on Wed, 23 Nov 2005 15:27:02 +0200:
>
> Yes it does. I'm using it on a text column in one of my databases!
> Dan
>|||Islamegy wrote on Wed, 23 Nov 2005 15:48:54 +0200:
> How do u do it' When i try to use "Contain(Text column,"some words").. it
> don't accept my query!!
> As i know from my research it dosn't work on text..
I'm guessing you haven't created the FTS index yet. Read BOL on how to do
this.
> Anyway my database is Arabic, so i thought ntext is ok but when i
> converted it to text it became 20% faster.
> Also finally i discovered that collation is work as a magic. When i
> switched it from Arabic_CI_AI to Arabic_BIN this cut the search time to
> the half. for now this is really so great success, if you have anyone have
> ideas for more improvment plz let me now..
Using FTS you might see a significant improvement. You'd do well to post
questions about it microsoft.public.sqlserver.fulltext
Dan|||Keep in mind that text stores text in ANSI (1 byte per character) and ntext
stores the text in Unicode (2 bytes per character) format. This is why ntext
will require more disk storage and operations on the data will be somewhat
slower. If the character set is Arabic, then you have no other choice but
the use Unicode.
"Islamegy" <NULL_Islamegy_NULL@.yahoo.com> wrote in message
news:OretoSD8FHA.1248@.TK2MSFTNGP14.phx.gbl...
> How do u do it' When i try to use "Contain(Text column,"some words").. it
> don't accept my query!!
> As i know from my research it dosn't work on text..
> Anyway my database is Arabic, so i thought ntext is ok but when i
> converted it to text it became 20% faster.
> Also finally i discovered that collation is work as a magic. When i
> switched it from Arabic_CI_AI to Arabic_BIN this cut the search time to
> the half. for now this is really so great success, if you have anyone have
> ideas for more improvment plz let me now..
> thanx
> "Daniel Crichton" <msnews@.worldofspack.co.uk> wrote in message
> news:%23wC2$MD8FHA.2676@.TK2MSFTNGP15.phx.gbl...
>
I there anyway to make ntext search faster'
I have a table of legal documents with 2 million text record, While no full
text index & search on text fields searching with "Like is very very slow".
I need anyway to make it faster using any techniques..
Do i need to use cursor or how can i solve this issue'
I can't use nvarchar coz of size limititionIslamegy wrote on Wed, 23 Nov 2005 14:18:28 +0200:
> Helloo..
> I there anyway to make ntext search faster'
> I have a table of legal documents with 2 million text record, While no
> full text index & search on text fields searching with "Like is very very
> slow". I need anyway to make it faster using any techniques..
> Do i need to use cursor or how can i solve this issue'
> I can't use nvarchar coz of size limitition
Any particular reason why you can't use Full Text Search?
Dan|||Because Full Text index dosn't apply of Text Fields of type "text",
"ntext"!!!
"Daniel Crichton" <msnews@.worldofspack.co.uk> wrote in message
news:ujyy8%23C8FHA.956@.TK2MSFTNGP10.phx.gbl...
> Islamegy wrote on Wed, 23 Nov 2005 14:18:28 +0200:
>
> Any particular reason why you can't use Full Text Search?
> Dan
>|||Islamegy wrote on Wed, 23 Nov 2005 15:27:02 +0200:
> Because Full Text index dosn't apply of Text Fields of type "text",
> "ntext"!!!
Yes it does. I'm using it on a text column in one of my databases!
Dan|||Yes, performing a non-indexed search on the text of 2 million documents is
going to be slow. I'm surprised that it's just optimization you are
concerned with and the actual feasability.
Of course, consider using the Full-Text feature.
If you must perform LIKE comparisons on the rows, perhaps it would be
possible to run a process that parses the text of each document and then
stores key words in something like a 120 length varchar column.
For example:
Jacobs;California;McNeal;disability;insu
rance;claim
Once done, this column could be used for LIKE searches.
"Islamegy" <NULL_Islamegy_NULL@.yahoo.com> wrote in message
news:OoYHFgC8FHA.1420@.TK2MSFTNGP09.phx.gbl...
> Helloo..
> I there anyway to make ntext search faster'
> I have a table of legal documents with 2 million text record, While no
> full text index & search on text fields searching with "Like is very very
> slow".
> I need anyway to make it faster using any techniques..
> Do i need to use cursor or how can i solve this issue'
> I can't use nvarchar coz of size limitition
>|||Why would you think that? It does in fact work on text and ntext columns.
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net
"Islamegy" <NULL_Islamegy_NULL@.yahoo.com> wrote in message
news:evIRZGD8FHA.2036@.TK2MSFTNGP14.phx.gbl...
> Because Full Text index dosn't apply of Text Fields of type "text",
> "ntext"!!!
> "Daniel Crichton" <msnews@.worldofspack.co.uk> wrote in message
> news:ujyy8%23C8FHA.956@.TK2MSFTNGP10.phx.gbl...
>|||How do u do it' When i try to use "Contain(Text column,"some words").. it
don't accept my query!!
As i know from my research it dosn't work on text..
Anyway my database is Arabic, so i thought ntext is ok but when i converted
it to text it became 20% faster.
Also finally i discovered that collation is work as a magic. When i switched
it from Arabic_CI_AI to Arabic_BIN this cut the search time to the half. for
now this is really so great success, if you have anyone have ideas for more
improvment plz let me now..
thanx
"Daniel Crichton" <msnews@.worldofspack.co.uk> wrote in message
news:%23wC2$MD8FHA.2676@.TK2MSFTNGP15.phx.gbl...
> Islamegy wrote on Wed, 23 Nov 2005 15:27:02 +0200:
>
> Yes it does. I'm using it on a text column in one of my databases!
> Dan
>|||Islamegy wrote on Wed, 23 Nov 2005 15:48:54 +0200:
> How do u do it' When i try to use "Contain(Text column,"some words").. it
> don't accept my query!!
> As i know from my research it dosn't work on text..
I'm guessing you haven't created the FTS index yet. Read BOL on how to do
this.
> Anyway my database is Arabic, so i thought ntext is ok but when i
> converted it to text it became 20% faster.
> Also finally i discovered that collation is work as a magic. When i
> switched it from Arabic_CI_AI to Arabic_BIN this cut the search time to
> the half. for now this is really so great success, if you have anyone have
> ideas for more improvment plz let me now..
Using FTS you might see a significant improvement. You'd do well to post
questions about it microsoft.public.sqlserver.fulltext
Dan|||Keep in mind that text stores text in ANSI (1 byte per character) and ntext
stores the text in Unicode (2 bytes per character) format. This is why ntext
will require more disk storage and operations on the data will be somewhat
slower. If the character set is Arabic, then you have no other choice but
the use Unicode.
"Islamegy" <NULL_Islamegy_NULL@.yahoo.com> wrote in message
news:OretoSD8FHA.1248@.TK2MSFTNGP14.phx.gbl...
> How do u do it' When i try to use "Contain(Text column,"some words").. it
> don't accept my query!!
> As i know from my research it dosn't work on text..
> Anyway my database is Arabic, so i thought ntext is ok but when i
> converted it to text it became 20% faster.
> Also finally i discovered that collation is work as a magic. When i
> switched it from Arabic_CI_AI to Arabic_BIN this cut the search time to
> the half. for now this is really so great success, if you have anyone have
> ideas for more improvment plz let me now..
> thanx
> "Daniel Crichton" <msnews@.worldofspack.co.uk> wrote in message
> news:%23wC2$MD8FHA.2676@.TK2MSFTNGP15.phx.gbl...
>
Subscribe to:
Posts (Atom)