On Sunday, 27 June 2021 at 08:09:42 UTC+10, Derek Ignatius Asirvadem wrote:The point is this. You are thinking bottom-up. That is plain wrong in any kind of software development exercise. But you are forced into thinking bottom-up in the MV-non-CC context, it is consequent to that insanity. Give up the MV-non-CC insanity, and the bottom-up thinking that is demanded can then be released, so that you can start thinking as a human being, as a s/w developer, about reality. Which means top down; hierarchy; composition.
On Friday, 25 June 2021 at 23:58:38 UTC+10, daniel wrote:Whether it is a Key lock; or Update Lock; or Intent Lock, is a platform-specific thing (other platforms will do the same thing, but have different locks, or different names for similar locks). In the Sybase & MS case, yes, a Key Lock is distinctly more efficient, more rCLthinking aheadrCY. So for our purpose, understanding and writing code for an ACID RDBMS, do not concern yourself too much about the platform-specific type of lock, do concern yourself THAT it is locked and that it is some form of Exclusive Lock.
-- This KEY lock ensures that no other transactions running
Generically, it is an Intent lock, that you have found, and after the insert it is an Exclusive lock. Platform-specifically, it means SQL Server is ready and waiting to insert another row with that or similar Key, hence Key lock.
On Monday, 28 June 2021 at 11:26:56 UTC+10, Derek Ignatius Asirvadem wrote:Therefore, for the next increment of the OLTP/Transaction/ACID sproc template, as the first item in the Validate Block, add:
-- Transaction Processing --
-- Transaction rCo ACID Properties --
-- Transaction rCo ACID rCo Consistency -- -----------------------------------------------------
-- Transaction rCo ACID rCo Isolation -- -----------------------------------------------------
//The intermediate state of a transaction is invisible to [or isolated from] other transactions.
As a result, transactions that run concurrently appear to be serialized.//
----------
If you understand this, you will understand that there is only one level of depth in Transactions, either one Transaction or all Transactions in a system. The notion of rCLnested transactionsrCY is hysterically absurd.
EXEC sp_addmessage 20003, '%1!: is a transaction, which is Atomic. It has been called from within an open transaction, which would render it a non-transaction. That is not allowed.', "us_english", FALSE, "REPLACE"Sybase Transact-SQL, the original, convert to MS Transact-SQL
The reason for this is, if there is a conflict with any other active Transaction, it will be blocked at the highest level in the tree, and NOT proceed further (eg. to the next statement). This is by design, desired. If you do not go AHA!, if you do not appreciate the brilliance of this, please contemplate, and then ask /specific/ questions.It makes sense. It would remove the possibility of deadlock by ensuring that all locks are consistently acquired in the same order.
EXEC sp_addmessage 20004, '%1!: A transaction has been opened by the caller (but is declared NOT to be open).', "us_english", FALSE, "REPLACE"The other two made a lot of sense. But I'm not sure what you mean by 'declared to be'.
EXEC sp_addmessage 20005, '%1!: A transaction has NOT been opened by the caller (but is declared to be open).', "us_english", FALSE, "REPLACE"
On Tuesday, 29 June 2021 at 22:59:49 UTC+10, Daniel Loth rote:Good work.
Hi Derek,
I've posted some updated code here incorporating your feedback: https://gist.github.com/DanielLoth/a272a601e38c9c6f2c002956b08d534e
Microsoft recommend using the 'throw' operation instead of the older 'raiserror'. So I've incorporated the notion of an error, but it's in its own function.Horrible. MS has always had a special way of doing things, which is always more work; more code that can break; more things to go wrong; more things to administer. Have they taken away rCLuser definedrCY error messages ? What happened to good old backward-compatibility.
Transaction chaining - implicit transactions - is also a little different in MSSQL. So I've incorporated it as a 'set option' clause.Perfect.
---Yes. That is the only way to eliminate deadlocks. An overall Access Sequence, which has to be defined at the data modelling level. Here, it is a simple stepping through the hierarchy.
The reason for this is, if there is a conflict with any other active Transaction, it will be blocked at the highest level in the tree, and NOT proceed further (eg. to the next statement). This is by design, desired. If you do not go AHA!, if you do not appreciate the brilliance of this, please contemplate, and then ask /specific/ questions.It makes sense. It would remove the possibility of deadlock by ensuring that all locks are consistently acquired in the same order.
That is at the code level.
Also, even if for a moment there is contention (say, on dbo.Person in my example) it'll keep progressing immediately afterwards with a relatively good prospect of still succeeding.The prospects are always good, given the Validate block in both the client and the sproc.
Or if the circumstances have changed (e.g.: the transaction that blocked it actually removed the Person row), it'll quickly detect that the row is not there once unblocked, rollback, and then return control to the caller.Exactly.
---Mistake, copy-paste error. I should have excluded that. You can ignore it. But since it has been exposed, I will explain what I can without giving away the shop. Basically, I have a deeper level of Transaction control. If one implements such, it has to be immune to the nuances of Transaction control provided in the platform. Sometimes I have to work on a system in which the developers are hostile: they have implicit transactions and all manner of non-white filth, it will take six months to get them to replace it according to Standards. So the Transactions that my guys write have to operate in that mixed environment for a while, sometimes sabotaged by the calling code doing nasty things. My template catches all that, and these are the messages. The setting (declaration) is in connection memory, not in @variables or @@variables.
Question: What context are these two used in?
EXEC sp_addmessage 20004, '%1!: A transaction has been opened by the caller (but is declared NOT to be open).', "us_english", FALSE, "REPLACE"The other two made a lot of sense. But I'm not sure what you mean by 'declared to be'.
EXEC sp_addmessage 20005, '%1!: A transaction has NOT been opened by the caller (but is declared to be open).', "us_english", FALSE, "REPLACE"
Horrible. MS has always had a special way of doing things, which is always more work; more code that can break; more things to go wrong; more things to administer. Have they taken away rCLuser definedrCY error messages ? What happened to good old backward-compatibility.Having given it some thought, I don't think there's any need for XACT_ABORT in the code I've written. I've explicitly handled rollback. So it's probably quite safe for me to use RAISERROR and add the messages to sys.messages as originally proposed. Something for tomorrow.
Yes. That is the only way to eliminate deadlocks. An overall Access Sequence, which has to be defined at the data modelling level. Here, it is a simple stepping through the hierarchy.I've actually put an image of my data model diagram in that GitHub gist comment section. It's a work-in-progress, but it's an indication of what I'm going for with it. So far I think it has reasonable hierarchy to it. There are no cycles or anything like that.
But since it has been exposed, I will explain what I can without giving away the shop. Basically, I have a deeper level of Transaction control. If one implements such, it has to be immune to the nuances of Transaction control provided in the platform. Sometimes I have to work on a system in which the developers are hostile: they have implicit transactions and all manner of non-white filth, it will take six months to get them to replace it according to Standards. So the Transactions that my guys write have to operate in that mixed environment for a while, sometimes sabotaged by the calling code doing nasty things. My template catches all that, and these are the messages. The setting (declaration) is in connection memory, not in @variables or @@variables.That makes sense now. I hadn't considered hostility or saboteurs when looking at them before.
At the banks, they call it rCLhardeningrCY the server, making it immune to mischief or hack. SG complies with various finance industry standards, all the way down to the code.
The real problem, the core issue, is not MV-non-CC. It is the complete lack of understanding of Transactions; ACID Transactions; what the frog **ONLINE** means; what Online Transaction Processing means. Such is the state of academics, and has been for FIFTY YEARS. Such are the developers who code for MV-non-CC. Enabled by the pig poop eating academics and teachers. Empowered schizophrenia. Those developers, with their steadfast refusal to engage with reality, whose fantasy of safe isolation is their existential reality. That is the problem.I agree that there's a dearth of good content out there. For example, I'm not aware of any book that adequately covers. A lot of the mainstream books wind up going down the same path: Poor practice, little to no consideration of methodical design, and ultimately yielding a so-called database with little to no integrity.
For ease of viewing, I've published all of the code below on GitHub too:
https://gist.github.com/DanielLoth/76d241515655e76cadddef6ed2d373aa
__3 If exists Attendance[ OrganisationId, PersonId, AttendanceDate ] return 7 ____ HOLDLOCK
Nicola, note how that Batch Xact fits here. It needs to lock only the highest row in the hierarchy, and that will prevent any other OLTP
Xact from getting into the tree.
On Saturday, 3 July 2021 at 06:55:38 UTC+10, Nicola wrote:Great. I can see a lot a value in such a port, no argument, but the purpose is unclear. If I knew the purpose, my responses would be more specific.
On 2021-06-27, Derek Ignatius Asirvadem wrote:
For ease of viewing, I've published all of the code below on GitHub too: >> https://gist.github.com/DanielLoth/76d241515655e76cadddef6ed2d373aa Thanks. That's my attempt at porting to PostgreSQL:
https://gist.github.com/nv-uniud/dd0008c8684d9ff50fbc814466d09ff9
I see that you have continued your discussion on Github, but I haven'tWell, re this thread & subject, I think we are keeping the discussion here, the code (for you and Daniel) there. There is a separate discussion re DanrCOs DM there (the interface is better.)
kept up.
In chronological order.__3 If exists Attendance[ OrganisationId, PersonId, AttendanceDate ] return 7
____ HOLDLOCK
Why does this need holdlock, too? Locks on Organisation and Person have already been acquired at this point:
if exists (
select 1
from dbo.Attendance
with (holdlock)
where OrganisationId = @OrganisationId
and PersonId = @PersonId
and AttendanceDate = @AttendanceDate
)
begin
rollback;
return 7; -- Attendance on the given date has already been recorded.
end
Certainly, with these new threads I better understand your criticisms.Good. Please appreciate, when I give a course to developers, it is a fixed 3-day affair, with a full set of lecture notes, max six people. Sometimes 6 x half-days. For mucho lira. Of course that is a full course on OLTP, before we get to Sybase, before they can understand and use the SG OLTP Standard & sp template. I canrCOt do that here, I am answering questions only. So it is gearing you up in Transactions & OLTP, the hard way.
On Saturday, 3 July 2021 at 06:55:38 UTC+10, Nicola wrote:Discussion, not code.
https://gist.github.com/nv-uniud/dd0008c8684d9ff50fbc814466d09ff9
-- From https://www.postgresql.org/docs/current/xproc.html:So that is not a Transaction. That states that the freaky thing is always in a "transaction" mode of its own definition. This tells me that nothing has changed since V10. Functions (oopsey, the now sort-of stored procedure thingees) are "twunsackshunal". START TRANSACTION still does Fanny Adams.
-- A procedure can commit or roll back transactions during its execution (then
-- automatically beginning a new transaction),
On Saturday, 3 July 2021 at 06:55:38 UTC+10, Nicola wrote:
On 2021-06-27, Derek Ignatius Asirvadem wrote:
For ease of viewing, I've published all of the code below on GitHub too: >> >> https://gist.github.com/DanielLoth/76d241515655e76cadddef6ed2d373aa
Thanks. That's my attempt at porting to PostgreSQL:
https://gist.github.com/nv-uniud/dd0008c8684d9ff50fbc814466d09ff9
Great. I can see a lot a value in such a port, no argument, but the
purpose is unclear. If I knew the purpose, my responses would be more specific.
Why does this need holdlock, too? Locks on Organisation and Person have
already been acquired at this point:
if exists (
select 1
from dbo.Attendance
with (holdlock)
where OrganisationId = @OrganisationId
and PersonId = @PersonId
and AttendanceDate = @AttendanceDate
)
begin
rollback;
return 7; -- Attendance on the given date has already been recorded.
end
In chronological order.
- In Sybase at IL[3], it is an automatic HoldLock (hold page until end of Xact)
--- therefore if the Attendance row exists, the lock on the page is held until end of Xact
- MS/SQL was stolen from Sybase at V4.9.2, but MS have rewritten the
codeline several times, so while they are identical to a great degree, especially re the syntax, but at this level of detail they may not be.
So when discussing with Dan, to be clear, I indicated to him that we
want a HOLDLOCK in MS equivalent terms:. It is purely documentary.
That is for Organisation; Person; and Attendance, after the BEGIN
TRAN.
Put another way, in order to obtain a HOLDLOCK, one has to have
Isolation Level 3, which means one has to have a Transaction open.
And now, because you have ported the code, it is an indicator to you,
to do whatever is equivalent in your program suite.
__ https://help.sap.com/viewer/e0d4539d39c34f52ae9ef822c2060077/16.0.4.0/en-US/ab3e9a97bc2b10149c02ff1c52f92cb4.html
Certainly, with these new threads I better understand your criticisms.
It is not rCLcriticismrCY [of MV-non-CC]. It is a tutorial to drag
academics and developers out of the MV-non-CC/PusGres mindset, into
the Transaction Processing that we have had since the 1960rCOs (pre-Relational) and the 1980rCOs (Relational platforms).
On Saturday, 3 July 2021 at 06:55:38 UTC+10, Nicola wrote:
https://gist.github.com/nv-uniud/dd0008c8684d9ff50fbc814466d09ff9
Discussion, not code.
Nicola, would you like differences between SQL and the PoopGres syntax discussed here, or on GitHub ?
----------
-- From https://www.postgresql.org/docs/current/xproc.html:
-- A procedure can commit or roll back transactions during its execution (then
-- automatically beginning a new transaction),
So that is not a Transaction. That states that the freaky thing is
always in a "transaction" mode of its own definition. This tells me
that nothing has changed since V10. Functions (oopsey, the now
sort-of stored procedure thingees) are "twunsackshunal". START
TRANSACTION still does Fanny Adams.
And now, security xor "transactional-ness" is a binary choice.
On Sunday, 4 July 2021 at 20:08:34 UTC+10, Nicola wrote:
On 2021-07-03, Derek Ignatius Asirvadem wrote:
-- From https://www.postgresql.org/docs/current/xproc.html:
-- A procedure can commit or roll back transactions during its execution (then
-- automatically beginning a new transaction),
So that is not a Transaction. That states that the freaky thing is
always in a "transaction" mode of its own definition. This tells me
that nothing has changed since V10. Functions (oopsey, the now
sort-of stored procedure thingees) are "twunsackshunal". START
TRANSACTION still does Fanny Adams.
Can you elaborate on that? If I do:
start transaction;
-- Some stuff
commit;
select ...; -- (1)
insert ...; -- (2)
start transaction;
-- Some stuff
commit;
don't (1) and (2) constitute each a transaction?
On Sunday, 4 July 2021 at 20:08:34 UTC+10, Nicola wrote:
On 2021-07-03, Derek Ignatius Asirvadem wrote:
-- From https://www.postgresql.org/docs/current/xproc.html:
-- A procedure can commit or roll back transactions during its execution (then
-- automatically beginning a new transaction),
So that is not a Transaction. That states that the freaky thing is
always in a "transaction" mode of its own definition. This tells me
that nothing has changed since V10. Functions (oopsey, the now
sort-of stored procedure thingees) are "twunsackshunal". START
TRANSACTION still does Fanny Adams.
Can you elaborate on that? If I do:
Sure.
Before I do ...
start transaction;
-- Some stuff
commit;
select ...; -- (1)
insert ...; -- (2)
start transaction;
-- Some stuff
commit;
don't (1) and (2) constitute each a transaction?
What definition of "transaction" are you using ?
On Monday, 5 July 2021 at 02:02:33 UTC+10, Nicola wrote:All this time (two years) that we have been discussing these things, the context has been:
On 2021-07-04, Derek Ignatius Asirvadem wrote:
On Sunday, 4 July 2021 at 20:08:34 UTC+10, Nicola wrote:
On 2021-07-03, Derek Ignatius Asirvadem wrote:
-- From https://www.postgresql.org/docs/current/xproc.html:
-- A procedure can commit or roll back transactions during its execution (then
-- automatically beginning a new transaction),
So that is not a Transaction. That states that the freaky thing is
always in a "transaction" mode of its own definition. This tells me
that nothing has changed since V10. Functions (oopsey, the now
sort-of stored procedure thingees) are "twunsackshunal". START
TRANSACTION still does Fanny Adams.
Can you elaborate on that? If I do:
Sure.
Before I do ...
start transaction;
-- Some stuff
commit;
select ...; -- (1)
insert ...; -- (2)
start transaction;
-- Some stuff
commit;
don't (1) and (2) constitute each a transaction?
What definition of "transaction" are you using ?
A logical unit of processing that is executed atomically (either all the operations are carried out till the end or the database is not affected
in any way), does not violate the integrity constraints, does not
interfere with other transactions (in a way that produces results that
are incompatible with any serial execution of the same transactions),
and whose results are guaranteed to be persistent, unless the
transaction fails for some reason.
Syntactically, anything between "start transaction" and "commit". Single commands are run as if enclosed between "start transaction"/"commit".
If I understand correctly, by "transaction" you mean what is executed byI did not say anything, I just gave SQL Verbs. I did not define or redefine anything re "transaction", the notion of harbouring private definitions in a science, that has definitions, is too freaky for me. Please do not put words in my mouth. If you interpret something I wrote, please be responsible and own that interpretation.
the whole stored procedure, which according to your sketched template consists of several "transactions" in the sense above.
On Monday, 5 July 2021 at 08:01:02 UTC+10, Derek Ignatius Asirvadem wrote: the context has been:Further, note that Daniel started this thread, and the context [further to the above] is SQL platforms using a Lock Manager (not MVCC), and how to construct Transactions therein, properly.
__ database, specifically one that complies with Codd's /Relational Model/; __ SQL, specifically the Standard
__ ACID Transactions,
In this thread, it is ANSI/ISO/IEEEE SQL, and ACID only.
On Sunday, 4 July 2021 at 20:08:34 UTC+10, Nicola wrote:Whatever is meant by this:
On 2021-07-03, Derek Ignatius Asirvadem wrote:
And now, security xor "transactional-ness" is a binary choice.
I don't understand what this means.
-- -2A SECURITY DEFINER procedure cannot execute transaction control statementsand this:
-- (for example, COMMIT and ROLLBACK [rCa])-+
118 security invoker -- rCLsecurity definerrCY is not compatible with commit/rollback :(Since the rCLdevelopment teamrCY is spread across the galaxy (geographic as well as intellectual), in order to make any progress at all, each actual team develops one feature, in isolation from the rest of the codeline, and then anti-integrates it into the codeline, thus typically, in every progressive release of the program suite, the **use** of one feature destroys the use of some other feature. Or two. Common problem in freeware. Non-existent in commercial SQL Platforms.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 00:54:31 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
10 files (20,373K bytes) |
| Messages: | 264,187 |