Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

After moving our product from SA10.0.1 to SA12 (12.0.1 EBF 3311(Linux); 3324(Windows) we encountered with problem which haven't been appears in SA10. In case long Select(few hours report) from table A , Load Table statement from file in the same table A cannot be done and wait till Select will be finished. Select(report) is done from Java server application connection to DB by jconnect(jdbc3) or Insert from Select is done from T-SQL stored procedure.

Question which change between SA10 and SA12 is done regarding to Lock table mechanism and what can be done to solve this problem!?

asked 28 Feb '12, 04:25

HBrener's gravatar image

HBrener
426232535
accept rate: 0%

edited 28 Feb '12, 15:00

Volker%20Barth's gravatar image

Volker Barth
40.2k361550822


LOAD TABLE has always required an exclusive lock on a base table -- that is not new behaviour in SA12. You could use LOAD TABLE to put the data into a temporary table and then use 'insert ... from select ...' to put it into the base table but it is extra processing and requires temp space proportional to the size of the file you are loading.

permanent link

answered 28 Feb '12, 05:24

John%20Smirnios's gravatar image

John Smirnios
12.0k396166
accept rate: 37%

1

Oh, you can alsu use INSERT FROM ... OPENSTRING rather than using a temp table. INSERT will add locks and have the undo-log and redo-log overhead of regular inserts but it doesn't require an exclusive schema lock.

(29 Feb '12, 07:23) John Smirnios

Does your app use different isolation levels with v10 and v12? Or different transaction processing (fewer commits, longer transactions)?

As to the docs, the exclusive table lock used by the LOAD TABLE statement (AFAIK!) should not prevent a transaction on isolation level 0 to read from that table - but it would block transactions running on higher isolation levels, and vice versa...

permanent link

answered 28 Feb '12, 05:58

Volker%20Barth's gravatar image

Volker Barth
40.2k361550822
accept rate: 34%

edited 28 Feb '12, 06:00

May be in SA12 SELECT statement from jconnect(jdbc3) or T-SQL have been changed isolation level!?

(28 Feb '12, 07:55) HBrener
Replies hidden

There have been no changes to the default isolation level for either cmdseq or TDS connections (ie jConnect).

(28 Feb '12, 09:17) Glenn Paulley

LOAD TABLE acquires an exclusive schema lock and always has done so.

(28 Feb '12, 09:50) John Smirnios

OK, then I stand corrected, and then even at isolation level 0, another connection would be unable to read from that table. So my suggestions above are moot...


FWIW: The LOAD TABLE statement docs are not that clear: To cite:

LOAD TABLE places a write lock on the whole table.
...
Requires an exclusive lock on the table.

That (and the fact that LOAD TABLE don't do schema changes) has made me think it would just use an exclusive table lock and no exclusive schema lock.

(28 Feb '12, 10:11) Volker Barth
(28 Feb '12, 11:10) HBrener
Replies hidden
1

You're right that the doc is not being very explicit about the types of locks acquired. Even the SA doc referenced by the link you provided with your first comment is poorly worded:

"An exclusive table lock prevents any other transaction from accessing the table for any operation (reads, ..."

followed by

"transactions executing at isolation level 0 can still read the rows in a table whose table lock is held exclusively. "

Those are contradictory. The first statement should use "locking" rather than "accessing" but the subtleties of schema vs table locks still aren't incredibly clear with that change.

(28 Feb '12, 11:28) John Smirnios

Following John's explanation, I don't think so: As LOAD TABLE locks the table exclusively, it shouldn't matter whether your jConnect connection uses isolation 0 or 1: It should block when trying to read from that table. (But as this discussion shows, I'm surely not the expert here...)

(28 Feb '12, 12:10) Volker Barth

The problem is not from LOAD TABLE side but from SELECT side what prevent from LOAD TABLE work properly

(28 Feb '12, 12:18) HBrener
Replies hidden

The problem isn't on any single side -- it's both together. SELECT needs a read-only schema lock and LOAD TABLE need an exclusive schema lock. Those two cannot coexist so the statements execute in series.

(28 Feb '12, 13:00) John Smirnios

These comments keep referring to schema locks... Why would a schema lock prevent reads? Don't they just block changes to the schema?

(28 Feb '12, 14:21) Breck Carter

Well, it's all about exclusive schema locks - and that means the lock is used to prevent other connections from reading a table that is about to be altered.

That's clearly a neccessity for ALTER TABLE. What I do not understand is why LOAD TABLE would need that type of lock (instead of an exclusive table lock) - but John will know.

(28 Feb '12, 15:07) Volker Barth
1

LOAD TABLE uses an exclusive schema lock because it uses page-level undo. If the LOAD fails, modified table & index pages are restored from the checkpoint log to return them to how they were at the beginning of the LOAD. The pages are restored in arbitrary order as they come out of the checkpoint log and even an isolation level 0 scan couldn't cope with that,

(29 Feb '12, 07:13) John Smirnios

John, if I understand you right, in case of long SELECT on table A even with isolation level 0, LOAD TABLE statement into table A will wait until SELECT statement will be finish!?

(29 Feb '12, 12:56) HBrener
Replies hidden

That is correct. Similarly, if a LOAD is in progress, the select will wait for the LOAD to finish. This behaviour is not new to SA12.

(29 Feb '12, 13:04) John Smirnios

As this is starting to become a "Locking" class, would snapshot isolation be of help here?

I.e. would a SELECT on table A with isolation level "snapshot" (or its variants) still block the LOAD TABLE and vice versa?

Again, the docs are not very clear on this advanced topic, as they primarily explain that snapshot isolation prevents read locks...

(29 Feb '12, 13:24) Volker Barth

Yes, the LOAD TABLE would block snapshot scans too. Any time a table is referenced, a shared schema lock is required (so that the schema can't change (though we use it for a different purpose for LOAD). Since LOAD gets an exclusive schema lock, nothing else can access the table at all.

(01 Mar '12, 10:10) John Smirnios

But would the opposite be true: Would an uncommitted snapshot isolation SELECT block the LOAD TABLE?

(Not that I would think this possible difference would matter much in practise...)

(01 Mar '12, 10:48) Volker Barth

In general using LOAD TABLE statement for quick data insert to table which could be used for long SELECT(reports generation) looks problematic, one of way is detect connection block LOAD TABLE connection and than drop this block connection.

(01 Mar '12, 16:35) HBrener

Well, if "quick data insert" refers to "not too big amount of data" - instead of "huge amount, which takes too long to insert via INSERT" - then I strongly would follow John's advice (see his answer) to LOAD into a temporary table and then INSERT into the real table from the temporary one. That won't block any readers unnecessarily, and you won't have to drop connections...

(02 Mar '12, 03:40) Volker Barth

Yes. Snapshots still get a shared schema lock, LOAD TABLE gets an exclusive one. They cannot coexist. It would be the same as for ALTER TABLE.

(02 Mar '12, 09:08) John Smirnios

Or use INSERT FROM ... OPENSTRING.

(02 Mar '12, 09:09) John Smirnios
showing 4 of 21 show all flat view
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×438
×59
×21
×18

question asked: 28 Feb '12, 04:25

question was seen: 3,163 times

last updated: 02 Mar '12, 09:09