Skip to content

Commit

Permalink
Added transaction commit, save, rollback in IOT
Browse files Browse the repository at this point in the history
Changed hook name for BBF

Task: BABEL-2170

Signed-off-by: Deepakshi Mittal <[email protected]>
  • Loading branch information
deepakshi-mittal committed Oct 9, 2023
1 parent 5981054 commit 03daff0
Show file tree
Hide file tree
Showing 7 changed files with 439 additions and 82 deletions.
17 changes: 10 additions & 7 deletions contrib/babelfishpg_tsql/src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static void pltsql_ExecutorStart(QueryDesc *queryDesc, int eflags);
static void pltsql_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count, bool execute_once);
static void pltsql_ExecutorFinish(QueryDesc *queryDesc);
static void pltsql_ExecutorEnd(QueryDesc *queryDesc);
static bool pltsql_ViewInsteadStmtTrigger(Relation view, CmdType event);
static bool pltsql_bbfViewHasInsteadofTrigger(Relation view, CmdType event);

static bool plsql_TriggerRecursiveCheck(ResultRelInfo *resultRelInfo);
static bool bbf_check_rowcount_hook(int es_processed);
Expand Down Expand Up @@ -202,7 +202,7 @@ static ExecutorFinish_hook_type prev_ExecutorFinish = NULL;
static ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
static GetNewObjectId_hook_type prev_GetNewObjectId_hook = NULL;
static inherit_view_constraints_from_table_hook_type prev_inherit_view_constraints_from_table = NULL;
static ViewInsteadStmtTrigger_hook_type prev_ViewInsteadStmtTrigger = NULL;
static bbfViewHasInsteadofTrigger_hook_type prev_bbfViewHasInsteadofTrigger_hook = NULL;
static detect_numeric_overflow_hook_type prev_detect_numeric_overflow_hook = NULL;
static match_pltsql_func_call_hook_type prev_match_pltsql_func_call_hook = NULL;
static insert_pltsql_function_defaults_hook_type prev_insert_pltsql_function_defaults_hook = NULL;
Expand Down Expand Up @@ -316,8 +316,8 @@ InstallExtendedHooks(void)
inherit_view_constraints_from_table_hook = preserve_view_constraints_from_base_table;
TriggerRecuresiveCheck_hook = plsql_TriggerRecursiveCheck;

prev_ViewInsteadStmtTrigger = ViewInsteadStmtTrigger_hook;
ViewInsteadStmtTrigger_hook = pltsql_ViewInsteadStmtTrigger;
prev_bbfViewHasInsteadofTrigger_hook = bbfViewHasInsteadofTrigger_hook;
bbfViewHasInsteadofTrigger_hook = pltsql_bbfViewHasInsteadofTrigger;

prev_detect_numeric_overflow_hook = detect_numeric_overflow_hook;
detect_numeric_overflow_hook = pltsql_detect_numeric_overflow;
Expand Down Expand Up @@ -426,7 +426,7 @@ UninstallExtendedHooks(void)
ExecutorEnd_hook = prev_ExecutorEnd;
GetNewObjectId_hook = prev_GetNewObjectId_hook;
inherit_view_constraints_from_table_hook = prev_inherit_view_constraints_from_table;
ViewInsteadStmtTrigger_hook = prev_ViewInsteadStmtTrigger;
bbfViewHasInsteadofTrigger_hook = prev_bbfViewHasInsteadofTrigger_hook;
detect_numeric_overflow_hook = prev_detect_numeric_overflow_hook;
match_pltsql_func_call_hook = prev_match_pltsql_func_call_hook;
insert_pltsql_function_defaults_hook = prev_insert_pltsql_function_defaults_hook;
Expand Down Expand Up @@ -706,10 +706,13 @@ plsql_TriggerRecursiveCheck(ResultRelInfo *resultRelInfo)
}

/**
* To allow rewriting view with base table if the view has an instead of trigger at statement level in BBF
* Hook function to skip rewriting VIEW with base table if the VIEW has an instead of trigger
* does view have an INSTEAD OF trigger at statement level
* If it does, we don't want to treat it as auto-updatable.
* Reference - src/backend/rewrite/rewriteHandler.c view_has_instead_trigger
*/
static bool
pltsql_ViewInsteadStmtTrigger(Relation view, CmdType event)
pltsql_bbfViewHasInsteadofTrigger(Relation view, CmdType event)
{
TriggerDesc *trigDesc = view->trigdesc;

Expand Down
13 changes: 6 additions & 7 deletions test/JDBC/expected/BABEL-2170-vu-cleanup.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- clean all objects in first database
-- clean all objects in first database
USE db1_BABEL2170;
GO

Expand All @@ -23,15 +23,14 @@ GO
DROP TABLE IF EXISTS babel_2170_vu_employees;
GO

USE MASTER;
DROP VIEW IF EXISTS babel_2170_vu_employees_view_txn;
GO

DROP DATABASE IF EXISTS db1_BABEL2170;
DROP TABLE IF EXISTS babel_2170_vu_employees_txn;
GO

SELECT name FROM sys.sysobjects WHERE name LIKE 'babel_2170%' ORDER BY name;
USE MASTER;
GO
~~START~~
varchar
~~END~~

DROP DATABASE IF EXISTS db1_BABEL2170;
GO
34 changes: 24 additions & 10 deletions test/JDBC/expected/BABEL-2170-vu-prepare.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ GO

INSERT INTO babel_2170_vu_employees VALUES(1, 'amber', '1st Street', '1000');
INSERT INTO babel_2170_vu_employees VALUES(2, 'angel', '1st Street', '2000');
INSERT INTO babel_2170_vu_employees VALUES(3, 'ana', '1st Street', '3000');
INSERT INTO babel_2170_vu_employees VALUES(4, 'adam', '1st Street', '4000');
GO
~~ROW COUNT: 1~~

~~ROW COUNT: 1~~

~~ROW COUNT: 1~~

~~ROW COUNT: 1~~


CREATE VIEW babel_2170_vu_employees_view AS
SELECT EmployeeID,
Expand Down Expand Up @@ -60,23 +54,43 @@ GO

INSERT INTO schema_2170.babel_2170_vu_employees VALUES(1, 'amber', '1st Street', '1000');
INSERT INTO schema_2170.babel_2170_vu_employees VALUES(2, 'angel', '1st Street', '2000');
INSERT INTO schema_2170.babel_2170_vu_employees VALUES(3, 'ana', '1st Street', '3000');
INSERT INTO schema_2170.babel_2170_vu_employees VALUES(4, 'adam', '1st Street', '4000');
GO
~~ROW COUNT: 1~~

~~ROW COUNT: 1~~


CREATE VIEW schema_2170.babel_2170_vu_employees_view AS
SELECT EmployeeID,
EmployeeName,
EmployeeAddress,
MonthSalary
FROM schema_2170.babel_2170_vu_employees
WHERE EmployeeName LIKE 'a%';
GO

CREATE TABLE babel_2170_vu_employees_txn
(
EmployeeID int NOT NULL,
EmployeeName VARCHAR(50),
EmployeeAddress VARCHAR(50),
MonthSalary NUMERIC(10, 2)
)
GO

INSERT INTO babel_2170_vu_employees_txn VALUES(1, 'amber', '1st Street', '1000');
INSERT INTO babel_2170_vu_employees_txn VALUES(2, 'angel', '1st Street', '2000');
GO
~~ROW COUNT: 1~~

~~ROW COUNT: 1~~


CREATE VIEW schema_2170.babel_2170_vu_employees_view AS
CREATE VIEW babel_2170_vu_employees_view_txn AS
SELECT EmployeeID,
EmployeeName,
EmployeeAddress,
MonthSalary
FROM schema_2170.babel_2170_vu_employees
FROM babel_2170_vu_employees_txn
WHERE EmployeeName LIKE 'a%';
GO
Loading

0 comments on commit 03daff0

Please sign in to comment.