on ‎2010 Jan 07 6:01 PM
We have recently upgraded our database from SQL Anywhere 5.5 to SQL Anywhere 11. Our users use applications written in Delphi to access the data in the database through ODBC. Needless to say, we are dealing with legacy code.
Since the changeover we have been encountering many locking issues that we did not use to have. These locking issues all revolve around intent locks that somehow get set and then don't disappear.
This recreates/illustrates the problem step by step using only Sybase tools:
Have a table ready with a few records in it. I'll call it "Test" from here on.
Open an Interactive SQL session (I'll call it ISQL1 from here on) under a user_id that only has this connection to the database.
Open a second Interactive SQL session (ISQL2) and run query "select * from sa_locks() where user_id = 'ISQL1_user_id'" (replace the ISQL1_user_id with the user used to connect to ISQL1)
In ISQL1 run "select * from Test". Run the query in ISQL2: 1 schema lock on the table.
In ISQL1, right click a row in the result set and select "edit row". Modify a value in the row. Now browse away from that row (for instance by clicking on the next record)
In ISQL2 run the query: you will see intent locks. I most often will see both a table and a row intent lock, but I've seen just a table one.
Questions: 1. Where did these intent locks come from? I did not ask for an intent lock in my query.
Why are they still here. Shouldn't the lock duration be until the end of a transaction. I should not be in a transaction anymore?
How do I get rid of them? I can actually re-execute the "select * from Test" query and still not loose that intent lock.
EDIT: I followed the exact steps above, except before step 2, in ISQL1 I chekc my isolation level by running: SELECT CONNECTION_PROPERTY('isolation_level'); which returns 0. I also check my locks for user Robert, and there aren't any. After step 5 I again run in ISQL1 SELECT CONNECTION_PROPERTY('isolation_level') to check my isolation level which again returns 0.
Here's the output of sa_locks in step 6 (and remember, I am not even looking at table TestRobert anymore in ISQL1, or anywhere else, as I just checked my isolation level)
conn_name,conn_id,user_id,table_type,creator,table_name,index_id,lock_class,lock_duration,lock_type SQL_DBC_1f738650,20540,robert,BASE,NTR,TestRobert,,Row,Transaction,Intent SQL_DBC_1f738650,20540,robert,BASE,NTR,TestRobert,,Row,Transaction,Write SQL_DBC_1f738650,20540,robert,BASE,NTR,TestRobert,,Schema,Transaction,Shared SQL_DBC_1f738650,20540,robert,BASE,NTR,TestRobert,,Table,Transaction,Intent
Request clarification before answering.
Your sa_locks() output looks normal for the operations you've just performed. You have:
So - nothing out of the ordinary here. We will need to more closely follow precisely what your application is doing to determine why you are seeing apparent differences in locking behaviour.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am also not entirely sure what you mean by the text behind 4. Are you saying that intent locks on tables are set to indicate that a row has been modified? That is what I am reading, but it is not one of the three reasons listed in the help on how you can obtain an intent lock (plus it seems counter intuitive)? However, it is the table intent locks that are plaguing us in our Delphi applications. Is there anywhere where I can read up on this functionality?
Yes, an intent table lock is acquired once a connection acquires a write row lock. However, I don't believe intent table locks are the problem - multiple intent table locks do not conflict with each other. Intent table locks conflict with shared and exclusive table locks, which are acquired using LOCK TABLE statements which I doubt you have in your application.
Both intent row locks, and intent table locks, once acquired are not released until COMMIT or ROLLBACK.
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.