• Batch Transaction

    From Derek Ignatius Asirvadem@derek.asirvadem@gmail.com to comp.databases.theory on Wed Jun 16 15:36:11 2021
    From Newsgroup: comp.databases.theory

    Nicola
    On Thursday, 17 June 2021 at 05:45:09 UTC+10, Nicola wrote:
    On 2021-06-16, Derek Ignatius Asirvadem wrote:
    Suppose that, for some reason, one needs to update one HotelChain,
    changing the value of HotelChain from ABC to H-ABC. If I understand
    correctly, you would start by (optimistically) locking the record with
    HotelChain = ABC.

    Yes.
    And leave it locked for the duration, it will be the last deleted.


    (optimistically)

    Because I know that you guys do not understand Locking, let alone Optimistic Locking, note this this is not an act within that [generic, theoretical] framework. This is a data-level lock (if you have row locking, and a row locking command, you do not have ACID *and* you
    have broken a cardinal rule of OLTP).

    Let me see whether we are on the same tune. While you are performing the batch transaction we are talking about, another transaction may also
    attempt to update the record with HotelChain = ABC (and specifically
    update the HotelChain field). Is it correct that this second transaction will be allowed to perform the update, and that first (batch
    transaction) will detect at the next commit that the "top" row has been overwritten, and rollback (at least rollback the running ACID
    transaction)?

    Because that is my understanding of "optimistic". But the rest of your
    post, (and the remark above) make me doubt that we agree on this
    meaning.
    No, that is not correct.
    Yes, you do *not* have a correct understanding of Optimistic Locking, none of the academics do, they have only the Stonebraker MVCC Kool Aid, and they have been drinking it and circle-jerking while chanting the *Mantra* for decades. As I have tried to explain, Optimistic Locking is completely different to the Straw Man that academics erect as rCLoptimistic lockingrCY. This point (your question) has nothing to do with Optimistic Locking.
    It has to do with how to construct a Batch Transaction (MonthEnd Procedure at a bank or Move OldKey to NewKey).

    1. Lock top-most <Table>[ <OldKey> ]
    For the duration of the Batch Transaction.
    <<<<

    You need some column that indicates a data-level lock. Standard columns include CreatedDtm; UpdatedDtm; etc, that can be used for this purpose [eg. set CreatedDtm to TODAY+1 or other fixed value [it is temporal, yes] ). You may have IsDeleted to support SoftDeletes. LetrCOs use the easy one, and say you have Soft Deletes. For clarity, you need a condition [ IsLocked ], and you implement that as indicated in one of the above columns, if not, you have a column [ IsLocked ].
    The fact that there is such a column, and that contention is understood and consciously minimised, *is* part of Optimistic Locking, part of the OLTP Standard.
    <<<<
    But this is not an ACID Transaction, it is a Batch Transaction. Of course, we use the column that is there for OLTP purposes, for the now Batch purpose.
    In this case, that means:
    -- UPDATE HotelChain.IsDeleted[ ABC ] = 1
    ---- WHERE HotelChain.IsDeleted[ ABC ] = 0
    or
    -- UPDATE HotelChain.IsLocked[ ABC ] = 1
    ---- WHERE HotelChain.IsLocked[ ABC ] = 0
    That prevents both [a] and [b] in this:
    another transaction may also attempt to
    (a) update the record with HotelChain = ABC
    (b) (and specifically update the HotelChain field)
    (Which row is meant by rCLrecordrCY is not clear, but it doesnrCOt matter for the answer: all rows from top to bottom that belong to [ ABC ] are locked.)
    Separate point. That rCLanother transactionrCY sounds suspiciously like another instance of the same transaction, using the same key. That doesnrCOt happen in the real world because the person who administers the first instance of changing ABC is one and the same person who administers the second instance of changing ABC. This sort of insanity is /also/ prevented by proper GUI design (a Tree with no circular references).
    It also prevents:
    -- UPDATE Hotel.NumStar[]
    or
    -- UPDATE HotelRoomType.Description[]
    --------
    To be clear, this is answering your question, which is you trying to understand Batch Transaction structure in an OLTP environment, (a) from the bottom up, and (b) with the known-to-be-straw-man concept of Optimistic Locking. This is *not* answering the question /what is Optimistic Locking/, which would be a top-down lecture, and include the considerations for genuine OLTP.
    Cheers
    Derek
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Derek Ignatius Asirvadem@derek.asirvadem@gmail.com to comp.databases.theory on Wed Jun 16 17:57:49 2021
    From Newsgroup: comp.databases.theory

    Nicola
    On Thursday, 17 June 2021 at 08:36:12 UTC+10, Derek Ignatius Asirvadem wrote:
    --------------------------
    -- 1 Correction --
    --------------------------
    In this case, that means:
    -- UPDATE HotelChain.IsDeleted[ ABC ] = 1
    ---- WHERE HotelChain.IsDeleted[ ABC ] = 0
    or
    -- UPDATE HotelChain.IsLocked[ ABC ] = 1
    ---- WHERE HotelChain.IsLocked[ ABC ] = 0

    ...

    It also prevents:
    -- UPDATE Hotel.NumStar[]
    or
    -- UPDATE HotelRoomType.Description[]
    Mistake, sorry, that should be:
    It also prevents any Transaction containing:
    -- UPDATE Hotel.NumStar[ ABC ]
    or
    -- UPDATE HotelRoomType.Description[ ABC ]
    or
    -- INSERT <AnyTableInHierarchy>[ ABC ]
    or
    -- DELETE <AnyTableInHierarchy>[ ABC ]
    ----------------------------
    -- 2 Impediment --
    ----------------------------
    Yes, you do *not* have a correct understanding of Optimistic Locking, none of the academics do, they have only the Stonebraker MVCC Kool Aid, and they have been drinking it and circle-jerking while chanting the *Mantra* for decades. As I have tried to explain, Optimistic Locking is completely different to the Straw Man that academics erect as rCLoptimistic lockingrCY. This point (your question) has nothing to do with Optimistic Locking.
    The term Optimistic Locking and the method (Standard) that it defines, is IBM [360] CICS/TCP from the early 1960rCOs. That is science. That is truth that does not change.
    Any use of the term to mean anything other than that, is fraudulent; dishonest conduct; anti-science.
    Which filth Stonebraker; Ellison; Date; Darwen; Fagin; etc, all engage in, in their suppression of the /RM/ and their promotion of RFS as rCLRelationalrCY, their suppression of SQL and their promotion of non-sql as rCLSQLrCY.
    You canrCOt understand
    __ Optimistic Locking
    (the OLTP requirement; two non-server deployments) while holding on to any shred of the rCLoptimistic lockingrCY Straw Man that is heavily established in academia over the decades.
    You canrCOt understand
    __ server-level Locking
    or
    __ data-level Locking
    while holding on to any shred of the rCL2PLrCY; rCLS2PLrCY; rCLC2PLrCY; SS2PLrCY; etc, fantasies that is heavily established in academia over the decades. Even the rCLdefinitionsrCY are unscientific nonsense, and ever-changing. You would not accept such unscientific nonsense from me, but somehow you accept that filth from Stomebraker and his cult.
    You canrCOt understand
    __ server-level Locking
    or
    __ data-level Locking
    while holding on to any shred of the MVCC fantasy that is heavily established in academia over the decades.
    MVCC is anti-ACID, it will never work. The evidenced fact that every single Orable and PusGres rCLdatabaserCY suffers massive problems due to the MVCC mindset is denied, an act that is enabled by repeating the totally fictitious *mantra* /Readers don't block writers, writers don't block readers/. the declaration is stupid, ridiculous, but hey, everyone is doing it; doing it; doing it.
    (If you wish to get into this issue seriously, there is a separate thread open, pleaseengage over there.)
    This thread is:
    It has to do with how to construct a Batch Transaction (MonthEnd Procedure at a bank or Move OldKey to NewKey).
    But of course, we canrCOt help touching OLTP structures, because it is an OLTP environment, and that is the over-arching requirement.
    -----------------------------
    -- 3 Three Shells --
    -----------------------------
    See if you can step back and understand this.
    A. Ten years ago, when you started interacting with me, your notion of a database, as programmed by academia, was:
    __ the result of a collection of SQL command, and SQL is broken
    __ literally, the physical only
    __ ERD
    B. As a consequence of that interaction, slowly, over time, it has progressed to:
    __ the result of constraints, specified in SQL, and SQL may not be broken
    __ introduction of some Logic
    __ IDEF1X (ERD is anti-Relational)
    C. And now recently:
    __ the result of Predicates, specified in SQL, and SQL is not broken
    __ introduction of essential Logic
    Whereas [A] is one shell or core, with horrendous problems, [C] is an outer shell, that secures [A] in terms of data integrity, somewhat.
    Likewise, as programmed by academia, you were stuck in
    __ Suppress ACID
    ____ Erect Straw Men to make ACID and 1PL to look and smell bad
    __ Elevate the fantasy of MVCC
    ____ thereby entirely denying the normal considerations for OLTP; ACID
    We are just now starting to deal with a third shell [D], that further secures [A] rCLtransactionallyrCY, in terms of data integrity, completely.
    This is totally new to academia, to you because you are the first and only academic trying to cross the chasm of ignorance of the industry, that the industry is, and has been since 1984 [as I know it]:
    D.
    __ OLTP Mindset (since 1960rCOs)
    ____ ACID Transactions only (since 1960rCOs, implement in all commercial SQL Platforms)
    ______ ACID in the server
    ______ ACID in every Transaction
    ____ Optimistic Locking
    ______ Optimistic Locking in each table
    ______ Optimistic Locking in every Transaction
    You need to appreciate that as long as you harbour [2 Impediment] the Straw Men, there is no way that you can understand the [3 Three Shells] of protection, the third shell, the ACID Transaction context that has protected industry databases since the 1960rCOs.
    Cheers
    Derek
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Derek Ignatius Asirvadem@derek.asirvadem@gmail.com to comp.databases.theory on Wed Jun 16 22:19:37 2021
    From Newsgroup: comp.databases.theory

    Nicola
    On Thursday, 17 June 2021 at 08:36:12 UTC+10, Derek Ignatius Asirvadem wrote:
    --------------------------
    -- 1 Correction --
    --------------------------
    In this case, that means:
    -- UPDATE HotelChain.IsDeleted[ ABC ] = 1
    ---- WHERE HotelChain.IsDeleted[ ABC ] = 0
    or
    -- UPDATE HotelChain.IsLocked[ ABC ] = 1
    ---- WHERE HotelChain.IsLocked[ ABC ] = 0

    ...

    It also prevents:
    -- UPDATE Hotel.NumStar[]
    or
    -- UPDATE HotelRoomType.Description[]
    Mistake, sorry, that should be:
    It also prevents any Transaction containing:
    -- UPDATE Hotel.NumStar[ ABC ]
    or
    -- UPDATE HotelRoomType.Description[ ABC ]
    or
    -- INSERT <AnyTableInHierarchy>[ ABC ]
    or
    -- DELETE <AnyTableInHierarchy>[ ABC ]
    ----------------------------
    -- 2 Impediment --
    ----------------------------
    Yes, you do *not* have a correct understanding of Optimistic Locking, none of the academics do, they have only the Stonebraker MVCC Kool Aid, and they have been drinking it and circle-jerking while chanting the *Mantra* for decades. As I have tried to explain, Optimistic Locking is completely different to the Straw Man that academics erect as rCLoptimistic lockingrCY. This point (your question) has nothing to do with Optimistic Locking.
    The term Optimistic Locking and the method (Standard) that it defines, is IBM [360] CICS/TCP from the early 1960rCOs. That is science. That is truth that does not change.
    Any use of the term to mean anything other than that, is fraudulent; dishonest conduct; anti-science.
    Which filth Stonebraker; Ellison; Date; Darwen; Fagin; etc, all engage in, in their suppression of the /RM/ and their promotion of RFS as rCLRelationalrCY, their suppression of SQL and their promotion of non-sql as rCLSQLrCY.
    You canrCOt understand
    __ Optimistic Locking
    (the OLTP requirement; two non-server deployments) while holding on to any shred of the rCLoptimistic lockingrCY Straw Man that is heavily established in academia over the decades.
    You canrCOt understand
    __ server-level Locking
    or
    __ data-level Locking
    while holding on to any shred of the rCL2PLrCY; rCLS2PLrCY; rCLC2PLrCY; SS2PLrCY; etc, fantasies that is heavily established in academia over the decades. Even the rCLdefinitionsrCY are unscientific nonsense, and ever-changing. You would not accept such unscientific nonsense from me, but somehow you accept that filth from Stomebraker and his cult.
    You canrCOt understand
    __ server-level Locking
    or
    __ data-level Locking
    while holding on to any shred of the MVCC fantasy that is heavily established in academia over the decades.
    MVCC is anti-ACID, it will never work. The evidenced fact that every single Orable and PusGres rCLdatabaserCY suffers massive problems due to the MVCC mindset is denied, an act that is enabled by repeating the totally fictitious *mantra* /Readers don't block writers, writers don't block readers/. the declaration is stupid, ridiculous, but hey, everyone is doing it; doing it; doing it.
    (If you wish to get into this issue seriously, there is a separate thread open, pleaseengage over there.)
    This thread is:
    It has to do with how to construct a Batch Transaction (MonthEnd Procedure at a bank or Move OldKey to NewKey).
    But of course, we canrCOt help touching OLTP structures, because it is an OLTP environment, and that is the over-arching requirement.
    -----------------------------
    -- 3 Three Shells --
    -----------------------------
    See if you can step back and understand this.
    A. Ten years ago, when you started interacting with me, your notion of a database, as programmed by academia, was:
    __ the result of a collection of SQL command, and SQL is broken
    __ literally, the physical only
    __ ERD
    A.2 As a consequence of that interaction, slowly, over time, it has progressed to:
    __ the result of constraints, specified in SQL, and SQL may not be broken
    __ introduction of some Logic
    __ IDEF1X (ERD is anti-Relational)
    B. And now recently:
    __ the result of Predicates, specified in SQL, and SQL is not broken
    __ introduction of essential Logic
    Whereas [A] is one shell or core, with horrendous problems, [B] is an outer shell, that secures [A] in terms of data integrity, somewhat.
    Likewise, as programmed by academia, you were stuck in
    __ Suppress ACID
    ____ Erect Straw Men to make ACID and 1PL to look and smell bad
    __ Elevate the fantasy of MVCC
    ____ thereby entirely denying the normal considerations for OLTP; ACID
    We are just now starting to deal with a third shell [C], that further secures [A] rCLtransactionallyrCY, in terms of data integrity, completely.
    This is totally new to academia, to you because you are the first and only academic trying to cross the chasm of ignorance of the industry, that the industry is, and has been since 1984 [as I know it]:
    C.
    __ OLTP Mindset (since 1960rCOs)
    ____ ACID Transactions only (since 1960rCOs, implement in all commercial SQL Platforms)
    ______ ACID in the server
    ______ ACID in every Transaction
    ____ Optimistic Locking
    ______ Optimistic Locking in each table
    ______ Optimistic Locking in every Transaction
    You need to appreciate that as long as you harbour [2 Impediment] the Straw Men for rCLACIDrCY instead of ACID, there is no way that you can understand the [3 Three Shells] of protection, the third shell, the ACID Transaction context that has protected industry databases since the 1960rCOs.
    Cheers
    Derek
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Nicola@nicola@nohost.org to comp.databases.theory on Thu Jun 17 09:27:14 2021
    From Newsgroup: comp.databases.theory

    On 2021-06-16, Derek Ignatius Asirvadem <derek.asirvadem@gmail.com> wrote:
    No, that is not correct.

    As expected.


    You need some column that indicates a data-level lock. Standard
    columns include CreatedDtm; UpdatedDtm; etc, that can be used for this purpose [eg. set CreatedDtm to TODAY+1 or other fixed value [it is
    temporal, yes] ). You may have IsDeleted to support SoftDeletes.
    LetrCOs use the easy one, and say you have Soft Deletes. For clarity,
    you need a condition [ IsLocked ], and you implement that as indicated
    in one of the above columns, if not, you have a column [ IsLocked ].

    The fact that there is such a column, and that contention is
    understood and consciously minimised, *is* part of Optimistic Locking,
    part of the OLTP Standard.

    That starts to sound vaguely familiar.

    But this is not an ACID Transaction, it is a Batch Transaction. Of
    course, we use the column that is there for OLTP purposes, for the now
    Batch purpose.

    In this case, that means:
    -- UPDATE HotelChain.IsDeleted[ ABC ] = 1
    ---- WHERE HotelChain.IsDeleted[ ABC ] = 0
    or
    -- UPDATE HotelChain.IsLocked[ ABC ] = 1
    ---- WHERE HotelChain.IsLocked[ ABC ] = 0

    That prevents both [a] and [b] in this:
    another transaction may also attempt to
    (a) update the record with HotelChain = ABC
    (b) (and specifically update the HotelChain field)

    Is it because each transaction checks UpdatedDtm and finds that it is
    equal to TODAY+1, hence it immediately aborts?

    It also prevents any Transaction containing:
    -- UPDATE Hotel.NumStar[ ABC ]
    or
    -- UPDATE HotelRoomType.Description[ ABC ]
    or
    -- INSERT <AnyTableInHierarchy>[ ABC ]
    or
    -- DELETE <AnyTableInHierarchy>[ ABC ]

    Such transactions perform the same check, right? And they abort
    immediately, I assume, when they find that the top row has been marked
    as deleted by the transaction that set UpdatedDtm. Is that correct?

    Separate point. That rCLanother transactionrCY sounds suspiciously like another instance of the same transaction, using the same key. That
    doesnrCOt happen in the real world because the person who administers
    the first instance of changing ABC is one and the same person who
    administers the second instance of changing ABC. This sort of
    insanity is /also/ prevented by proper GUI design (a Tree with no
    circular references).

    It may not happen under normal conditions. But I'd be very worried if
    "it cannot happen" relies on correct (human or machine) behaviour.
    A system should be resilient to improper and malicious behaviour as
    well.

    Nicola
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Derek Ignatius Asirvadem@derek.asirvadem@gmail.com to comp.databases.theory on Thu Jun 17 03:54:51 2021
    From Newsgroup: comp.databases.theory

    Nicola
    On Thursday, 17 June 2021 at 19:27:16 UTC+10, Nicola wrote:
    On 2021-06-16, Derek Ignatius Asirvadem wrote:
    No, that is not correct.
    As expected.

    You need some column that indicates a data-level lock. Standard
    columns include CreatedDtm; UpdatedDtm; etc, that can be used for this purpose [eg. set CreatedDtm to TODAY+1 or other fixed value [it is temporal, yes] ). You may have IsDeleted to support SoftDeletes.
    LetrCOs use the easy one, and say you have Soft Deletes. For clarity,
    you need a condition [ IsLocked ], and you implement that as indicated
    in one of the above columns, if not, you have a column [ IsLocked ].

    The fact that there is such a column, and that contention is
    understood and consciously minimised, *is* part of Optimistic Locking, part of the OLTP Standard.
    That starts to sound vaguely familiar.
    But this is not an ACID Transaction, it is a Batch Transaction. Of
    course, we use the column that is there for OLTP purposes, for the now Batch purpose.

    In this case, that means:
    -- UPDATE HotelChain.IsDeleted[ ABC ] = 1
    ---- WHERE HotelChain.IsDeleted[ ABC ] = 0
    or
    -- UPDATE HotelChain.IsLocked[ ABC ] = 1
    ---- WHERE HotelChain.IsLocked[ ABC ] = 0

    That prevents both [a] and [b] in this:
    another transaction may also attempt to
    (a) update the record with HotelChain = ABC
    (b) (and specifically update the HotelChain field)

    Is it because each transaction checks UpdatedDtm and finds that it is
    equal to TODAY+1, hence it immediately aborts?
    The /Today+1/ is for temporal tables, wherein a current SELECT does WHERE UpdatedDtm = MAX( UpdatedDtm) less-than-or-equal to today. It is just the standard method or construct to grab only the current row (exclude historic rows). (Whereas a temporal SELECT would grab the particular historic row.) I expect everyone who implements a temporal table [using CoddrCOs temporal definition, not the massive TwiddleDee & TwidleDumb monstrosity] to know that.
    The /Today+1/ just makes the affected row (and the hierarchy below it) invisible to other users, a form of ISOLATION. Heck, we are on a planet named ACID, we are performing an [I]solation. DonrCOt let that confuse you. If the column is there, use it.
    If IsDeleted is there, use it.
    Else implement IsLocked, and use it.
    Since God carved onto the OLTP stone tablet:
    __ THOU SHALT NOT ATTEMPT ANYTHING THAT IS IMPOSSIBLE
    yes, every Transaction (both ACID and this one) validates everything it will attempt, before attempting it, before the BEGIN TRAN. In our case, HotelChain is first. Because it is caught in the VALIDATE block, before the BEGIN TRAN, there is no rCLabortrCY or ROLLBACK TRAN.
    The corollary to that Commandment is of course:
    __ Thous Shalt Not Begin Anything That Will Fail, That Thou Canst Not Complete. I am scared of fire and brimstone. The CICS/TCP guys taught me this when I was still loading COBOL programs into a mainframe, in the form of punch-card decks.
    What you guys call rCL2 phaserCY is anti-ACID, it starts a transaction and then fiddles and farts while rambling, meaning time spans between requests. As per the wiki cesspool article, in the rCLSS2PLrCY that we have, there is only one rCLphaserCY. But we donrCOt start that rCLphaserCY until the previous rCLphaserCY of VALIDATE completes successfully. And we have no time spans in-between operations.
    I expect that you understand the following:
    __ in order to comply with [A]tomic, the BEGIN and COMMIT/ROLLBACK must be in one code block in a stored proc, never in the client
    __ the caller of the Transaction must execute the exact same VALIDATE block, before calling the Transaction
    --------
    It also prevents any Transaction containing:
    -- UPDATE Hotel.NumStar[ ABC ]
    or
    -- UPDATE HotelRoomType.Description[ ABC ]
    or
    -- INSERT <AnyTableInHierarchy>[ ABC ]
    or
    -- DELETE <AnyTableInHierarchy>[ ABC ]

    Such transactions perform the same check, right? And they abort
    immediately, I assume, when they find that the top row has been marked
    as deleted by the transaction that set UpdatedDtm. Is that correct?
    Yes.
    Every Transaction that touches the HotelChain hierarchy, any level.
    As detailed above, not rCLabortrCY, but never start.
    Not necessarily rCLdeletedrCY (which depends on the column that is available to be used for this purpose), but ISOLATED for the duration of the Transaction. When it has completed, the entire NewKey hierarchy is available.
    Separate point. That rCLanother transactionrCY sounds suspiciously like another instance of the same transaction, using the same key. That doesnrCOt happen in the real world because the person who administers
    the first instance of changing ABC is one and the same person who administers the second instance of changing ABC. This sort of
    insanity is /also/ prevented by proper GUI design (a Tree with no
    circular references).

    It may not happen under normal conditions. But I'd be very worried if
    "it cannot happen" relies on correct (human or machine) behaviour.
    A system should be resilient to improper and malicious behaviour as
    well.
    Absolutely. I did not say rCLit cannot happenrCY. It is prevented from happening, by the Transaction standard. That was an explanation, that it is actually prevented at a higher level (in any proper GUI), before the Transaction is called. Therefore rCL/also/rCL.
    Cheers
    Derek
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Nicola@nicola@nohost.org to comp.databases.theory on Fri Jun 18 14:22:22 2021
    From Newsgroup: comp.databases.theory

    On 2021-06-17, Derek Ignatius Asirvadem <derek.asirvadem@gmail.com> wrote:
    The /Today+1/ is for temporal tables, wherein a current SELECT does
    WHERE UpdatedDtm = MAX( UpdatedDtm) less-than-or-equal to today. It
    is just the standard method or construct to grab only the current row (exclude historic rows). (Whereas a temporal SELECT would grab the particular historic row.) I expect everyone who implements a temporal
    table [using CoddrCOs temporal definition, not the massive TwiddleDee
    & TwidleDumb monstrosity] to know that.

    The /Today+1/ just makes the affected row (and the hierarchy below
    it) invisible to other users, a form of ISOLATION. Heck, we are on
    a planet named ACID, we are performing an [I]solation. DonrCOt let that confuse you. If the column is there, use it.

    If IsDeleted is there, use it.

    Else implement IsLocked, and use it.

    Since God carved onto the OLTP stone tablet:
    __ THOU SHALT NOT ATTEMPT ANYTHING THAT IS IMPOSSIBLE
    yes, every Transaction (both ACID and this one) validates everything
    it will attempt, before attempting it, before the BEGIN TRAN. In our
    case, HotelChain is first. Because it is caught in the VALIDATE
    block, before the BEGIN TRAN, there is no rCLabortrCY or ROLLBACK TRAN.

    Wait, what is a VALIDATE block? If an atomic processing unit is
    delimited by BEGIN TRAN...COMMIT, how can something before BEGIN TRAN be considered part of that unit? If it is not, then how do you ensure that
    nothing happens between the instant VALIDATE completes and the instant
    BEGIN TRAN is executed?

    And I have a couple more questions, if you don't mind:

    1. What you are describing is built on top of the standard locking
    mechanism provided by the DBMS. If I understand correctly, it requires
    the transactions to be coded to perform explicit checks before accessing
    the data. At the outset, that sounds like something that can become very complicated and error-prone. E.g., it seems that a transaction to insert
    a new ReadingMeasure should check many things (HotelChain, CountryCode,
    ..., Application) before proceeding.

    Or, wait, such a transaction would be coded in a "simple" way (insert
    into Reading, insert into ReadingMeasure) and then two things may
    happen: it is either executed before the batch transaction has "reached" Reading, in which case it would succeed (and then it would be updated by
    the batch transaction); or it is executed after the batch transaction
    has updated Reading, hence inserting the new reading would raise
    a foreign key violation (and it should be retried with the new key).

    Or something else?

    2. You are describing an OLTP context, but you have claimed several
    times that the same database can serve both OLTP and OLAP workloads. Do
    you code analytic queries along the same principles to avoid
    locking too many records?

    The corollary to that Commandment is of course:
    __ Thous Shalt Not Begin Anything That Will Fail, That Thou Canst Not Complete.

    That is worth the "optimistic" label!

    What you guys call rCL2 phaserCY is anti-ACID, it starts a transaction and then fiddles and farts while rambling, meaning time spans between
    requests. As per the wiki cesspool article, in the rCLSS2PLrCY that we
    have, there is only one rCLphaserCY.

    Ok.

    But we donrCOt start that rCLphaserCY until the previous rCLphaserCY of VALIDATE
    completes successfully. And we have no time spans in-between
    operations.

    See above. Not clear how you'd achieve that.

    Nicola
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Derek Ignatius Asirvadem@derek.asirvadem@gmail.com to comp.databases.theory on Sat Jun 19 00:52:16 2021
    From Newsgroup: comp.databases.theory

    Nicola
    On Saturday, 19 June 2021 at 17:20:51 UTC+10, Derek Ignatius Asirvadem wrote: Read locks
    The previous post is a bit long, and that item was addressed in a few places. In case it isn't clear:
    __ Read locks outside a Transaction are transient, held for the duration of the read operation
    __ Read locks inside a Transaction are held until COMMIT/ROLLBACK
    ____ that is the SQL requirement, to support ACID
    ("MVCC" systems do none of that ... and try to desperately clean up a mountain of false versions of rows (not even pages!), that are distributed across the entire file space, when one person hits the [Save] button. And contrary to the cult hymn, it produces conditions that cannot be resolved, and resorts to "2PL". And yet still produces failures akin to deadlock. But the cult love their denial, and just sing the hymn louder.)
    As stated in:
    ____ https://www.softwaregems.com.au/Documents/Article/Sybase%20Lock%20Manager/Sybase%20Lock%20Manager.pdf
    Cheers
    Derek
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Derek Ignatius Asirvadem@derek.asirvadem@gmail.com to comp.databases.theory on Sat Jun 19 01:31:21 2021
    From Newsgroup: comp.databases.theory

    Nicola
    On Saturday, 19 June 2021 at 17:52:18 UTC+10, Derek Ignatius Asirvadem wrote:
    On Saturday, 19 June 2021 at 17:20:51 UTC+10, Derek Ignatius Asirvadem wrote:
    Sorry, stuffed up yet again. It has been at least 12 years since the last time I explained this.
    Read locks
    __ Read locks outside a Transaction are transient, held for the duration of the read operation
    No. This:
    __ Read locks outside a Transaction are transient, held for the duration of the Statement

    Of course, that is for reports. That is so that the entire ResultSet or SELECT set is not affected by Transactions. Yet another ACID SQL requirement, that MVCC doesn't even try to achieve. Oracle has made some improvements over the decades, which they falsely say is fixed, but it is still not compliant.
    Cheers
    Derek
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Nicola@nicola@nohost.org to comp.databases.theory on Tue Jun 22 10:35:03 2021
    From Newsgroup: comp.databases.theory

    On 2021-06-19, Derek Ignatius Asirvadem <derek.asirvadem@gmail.com> wrote:
    __________________
    1. VALIDATE Block
    Code:
    rCo Read all rows that must exist, in order for the intended rows (INSERT/UPDATE/DELETE) to succeed.
    __rCo RETURN on any failure.
    rCo Check NOT_EXISTS all rows that must not exist, in order for the intended rows (INSERT/UPDATE/DELETE) to succeed.
    __rCo RETURN on any failure.
    rCo Transaction NOT yet started
    rCo All locking is transient and very short duration
    rCo TransactionLog is not touched
    rCo Fall into ...

    Ok.

    __________________
    2. EXECUTE Block
    * BEGIN TRAN
    rCo TransactionLog activity commenced for this xact
    rCo Read all rows that must exist, in order for the intended rows (INSERT/UPDATE/DELETE) to succeed.
    __rCo ROLLBACK & RETURN on any failure.
    __rCo the only relevant locking starts here
    __rCo if blocked by another xact, you are blocked here (NOT after the first verb below)
    __rCo the longest wait is for the longest xact in the system that touches the page

    So here we code each SELECT as:
    __ IF EXISTS (
    ____ SELECT ...
    ______ FROM Hotel
    ______ WHERE ...
    ______ { FOR UPDATE | HOLDLOCK } -- platform-specific syntax, rCLbeyondrCY SQL
    ____ )

    __rCo <-[2.1]

    rCo Check NOT_EXISTS all rows that must not exist, in order for the
    intended rows (INSERT/UPDATE/DELETE) to succeed.
    __rCo ROLLBACK & RETURN on any failure.
    rCo (INSERT/UPDATE/DELETE)
    __rCo ROLLBACK & RETURN on any failure.

    rCo COMMIT TRAN
    rCo TransactionLog is released.

    Ok.

    ___________________
    3. CLEAN-UP Block
    rCo All error handling
    rCo ROLLBACK TRAN (if structured, the only ROLLBACK)
    rCo <-[3.1]
    rCo RETURN (if structured, the only RETURN)

    Ok.

    ______
    Client
    There is ordinary interplay between the Client and the Server. The
    client may now be a GUI or a webpage or middleware in an app server.

    The VALIDATE block [1] is repeated in the client.

    I assume that this means validating data without interacting with the
    database, e.g., to check that the input data is within valid ranges,
    etc.

    how do you ensure that
    nothing happens between the instant VALIDATE completes and the instant
    BEGIN TRAN is executed?

    That duration between instants is:
    a. not relevant [assuming you understand the above], and
    b. microseconds, because it is between two consecutive steps inside
    a contiguous stored proc, which is running as object + plan code
    (compiled and a full resource plan established), and

    That guarantees that interference is unlikely, but not impossible.
    Otherwise, you would not need this:

    * BEGIN TRAN
    rCo TransactionLog activity commenced for this xact
    rCo Read all rows that must exist, in order for the intended rows (INSERT/UPDATE/DELETE) to succeed.
    __rCo ROLLBACK & RETURN on any failure.

    c. harmless because no resources are held.

    That is an interesting approach. It is not obvious, IMO, that validating
    the data the way you suggest is advantageous (I am not saying that it is
    not, mind you!). Whether it is or not, it seems to depend on a number of factors, such as number of concurrent transactions, duration of
    transactions, number of touched resources, etc.

    Validation introduces an overhead, but it prevents transactions to start
    and acquire locks unless there is a very good chance to acquire them
    all, so overall it may be a win.

    To summarize, you could implement transactions in at least three ways:

    (1) just BEGIN TRAN; INSERT/UPDATE/DELETE; END TRAN:
    (2) BEGIN TRAN; SELECT FOR UPDATE; INSERT/UPDATE/DELETE; END TRAN;
    (3) VALIDATE, then (2).

    And in your experience (3) is the best approach.

    Batch Transaction

    Add:

    2.1 Add the data-level lock
    ___ BEGIN TRAN
    ___ UPDATE HotelChainIsDeleted[ @HotelChain ] = 1
    ___ COMMIT TRAN

    Ok.

    3.1 Remove the data-level lock (in our example this ois not required, because it is the last row deleted).
    ___ BEGIN TRAN
    ___ UPDATE HotelChainIsDeleted[ @HotelChain ] = 0
    ___ COMMIT TRAN

    Ok.

    You may consider the BEGIN-COMMIT TRAN superfluous. No, They are
    demanded by the standard. Further, they are anchors for code
    investigation, and on the server vis-a-vis monitoring metrics.

    Ok.

    1. What you are describing is built on top of the standard locking
    mechanism provided by the DBMS.

    If you mean the normal ACID Transaction in the full OLTP Context, no.
    It is aware of, and implicitly uses the locking in the server
    (whatever that is).

    If you mean the Batch Transaction, yes. I said so at the start. That
    is why I call it a data-level lock, it has to be done in data, we have
    no direct access to the locks, and we never do idiotic things such as:
    __ LOCK TABLE

    Ok, that is all pretty clear now.

    OLAP Reports
    Why do you worry about locks in OLAP reports ?
    Who cares.
    Read locks are extremely short, and transient (held for the duration
    of the read operation, not the Transaction). We canrCOt control Read
    locks, even implicitly

    Are you saying that OLAP queries run in a lower isolation level (say,
    READ COMMITTED)?

    But still, that is not Optimistic Locking. And in this post, there is nothing about Optimistic Locking.

    Agreed.

    Thanks,
    Nicola
    --- Synchronet 3.21d-Linux NewsLink 1.2