[MDEV-10155] Autonomous transactions Created: 2016-05-31  Updated: 2019-04-26

Status: Open
Project: MariaDB Server
Component/s: None
Fix Version/s: None

Type: Task Priority: Major
Reporter: Michael Widenius Assignee: Unassigned
Resolution: Unresolved Votes: 8
Labels: Compatibility, procedures

Issue Links:
Duplicate
is duplicated by MDEV-9917 autonomous transaction Closed
Epic Link: Oracle Compatibility

 Description   

Add support for autonomous blocks in stored routines.

This would allow a stored routine marked with autonomous_transaction to commit
and rollback it's own work, independent of the work of the caller.

Oracle defines this as "PRAGMA AUTONOMOUS_TRANSACTION":
https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/autonotransaction_pragma.htm

This pragma can be applied to:

  • Top-level (not nested) anonymous PL/SQL blocks
  • Local, standalone, and packaged functions and procedures
  • Methods of a SQL object type
  • Database triggers

For the moment a workaround is to use the Aria storage engine for tables that should be persistent against ROLLBACK. Aria tables are never rollbacked
(except if the server crashes in the middle of a query).

The suggested implementation is to run the autonomous routine with it's own THD (== user), like it would be a new independent connection.

An example of an Oracle stored function using AUTONOMOUS_TRANSACTION:

DROP TABLE employees;
DROP FUNCTION raise_salary;
CREATE TABLE employees (   
  employee_id INT NOT NULL PRIMARY KEY,
  salary INT NOT NULL
);
INSERT INTO employees VALUES (1, 100);
CREATE FUNCTION raise_salary
                (emp_id NUMBER,
                 sal_raise NUMBER) RETURN NUMBER
IS
  PRAGMA AUTONOMOUS_TRANSACTION;
  new_sal NUMBER(8,2);
BEGIN
  UPDATE employees
    SET salary= salary + sal_raise
    WHERE employee_id = emp_id;   
  COMMIT;
  SELECT salary INTO new_sal FROM employees WHERE employee_id = emp_id;
  RETURN new_sal;
END raise_salary;
/
SELECT raise_salary(1, 10) FROM DUAL;

RAISE_SALARY(1,10)
------------------
	       110



 Comments   
Comment by Yuriy Kuleshov [ 2019-04-26 ]

When you plan to implement this feature? This will be a great thing in oracle compatibility and app design techniques.

Generated at Thu Feb 08 07:40:05 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.