Commit 2e48fadd authored by Marcin's avatar Marcin
Browse files

new rewind algorithm

Previous rewind alghorithm required to use only DEFFERABLE constraints
even for CHECK, PK and UNIQUE contraints. It cannot be accepted since
'ON CONFLICT DO UPDATE' won't work with DEFFERABLE constraints. Current
algoritm, revert all operations one by one, is much more slower ( even
400x slower), but do not requires DEFFERABLE constaints on a single
tables. FOREIGN KEYs still need to be DEFFERABLE.
parent 2b98924b
......@@ -280,9 +280,7 @@ Disables triggers atatched to a register table. It is usefull for operation belo
when fork is impossible, then we don't want have trigger overhead for each edition of a table.
## Known Problems
1. Constraints like FK, UNIQUE, EXCLUDE must be DEFERRABLE, otherwise we cannot guarnteen success or rewinding changes - the process may temporary violates tables constraints.
Because PostgreSQL does not allow to create FK referenced to `DEFERRABLE` PRIMERY KEYS, it was decided to allow to use non-deferrable primary keys, but applications which modify
PK values are not supported, and rewind of their tables may fail.
1. Constraints FOREIGN KEY must be DEFERRABLE, otherwise we cannot guarnteen success or rewinding changes - the process may temporary violates tables constraints.
More informations about DEFERRABLE constraint can be found in PosgreSQL documentaion for [CREATE TABLE](https://www.postgresql.org/docs/10/sql-createtable.html)
and [SET CONSTRAINTS](https://www.postgresql.org/docs/10/sql-set-constraints.html)
......
DROP FUNCTION IF EXISTS hive.back_from_fork_one_table;
CREATE FUNCTION hive.back_from_fork_one_table( _table_schema TEXT, _table_name TEXT, _shadow_table_name TEXT, _columns TEXT[], _block_num_before_fork INT )
CREATE OR REPLACE FUNCTION hive.revert_insert( _table_schema TEXT, _table_name TEXT, _row_id BIGINT )
RETURNS void
LANGUAGE plpgsql
VOLATILE
AS
$BODY$
DECLARE
__columns TEXT = array_to_string( _columns, ',' );
BEGIN
-- First we find rows ids with lowest block num, then delete, insert or update these rows with rows ids
-- revert inserted rows
EXECUTE format(
'DELETE FROM %I.%I
WHERE %I.hive_rowid IN
(
SELECT st.hive_rowid FROM
(
SELECT DISTINCT ON ( st.hive_rowid ) st.hive_rowid, st.hive_operation_type
FROM hive.%I st
WHERE st.hive_block_num > %s
ORDER BY st.hive_rowid, st.hive_block_num
) as st
WHERE st.hive_operation_type = ''INSERT''
)'
'DELETE FROM %I.%I WHERE hive_rowid = %s'
, _table_schema
, _table_name
, _table_name
, _shadow_table_name
, _block_num_before_fork
, _row_id
);
END;
$BODY$
;
-- revert deleted rows
CREATE OR REPLACE FUNCTION hive.revert_delete( _table_schema TEXT, _table_name TEXT, _shadow_table_name TEXT, _operation_id BIGINT , _columns TEXT[] )
RETURNS void
LANGUAGE plpgsql
VOLATILE
AS
$BODY$
DECLARE
__columns TEXT = array_to_string( _columns, ',' );
BEGIN
EXECUTE format(
'INSERT INTO %I.%I( %s )
(
SELECT %s FROM
(
SELECT DISTINCT ON ( hive_rowid ) *
FROM hive.%I st
WHERE st.hive_block_num > %s
ORDER BY st.hive_rowid, st.hive_block_num
) as st
WHERE st.hive_operation_type = ''DELETE''
SELECT %s
FROM hive.%I st
WHERE st.hive_operation_id = %s
)'
, _table_schema
, _table_name
, __columns
, __columns
, _shadow_table_name
, _block_num_before_fork
, _operation_id
);
END;
$BODY$
;
-- update deleted rows
-- first remove rows
EXECUTE format(
'DELETE FROM %I.%I
WHERE %I.hive_rowid IN
(
SELECT st.hive_rowid FROM
(
SELECT DISTINCT ON ( st.hive_rowid ) st.hive_rowid, st.hive_operation_type
FROM hive.%I st
WHERE st.hive_block_num > %s
ORDER BY st.hive_rowid, st.hive_block_num
) as st
WHERE st.hive_operation_type = ''UPDATE''
)'
, _table_schema
, _table_name
, _table_name
, _shadow_table_name
, _block_num_before_fork
CREATE OR REPLACE FUNCTION hive.revert_update( _table_schema TEXT, _table_name TEXT, _shadow_table_name TEXT, _operation_id BIGINT, _columns TEXT[], _row_id BIGINT )
RETURNS void
LANGUAGE plpgsql
VOLATILE
AS
$BODY$
DECLARE
__columns TEXT = array_to_string( _columns, ',' );
BEGIN
EXECUTE format(
'UPDATE %I.%I as t SET ( %s ) = (
SELECT %s
FROM hive.%I st1
WHERE st1.hive_operation_id = %s
)
WHERE t.hive_rowid = %s'
, _table_schema
, _table_name
, __columns
, __columns
, _shadow_table_name
, _operation_id
, _row_id
);
END;
$BODY$
;
-- now insert old rows
DROP FUNCTION IF EXISTS hive.back_from_fork_one_table;
CREATE FUNCTION hive.back_from_fork_one_table( _table_schema TEXT, _table_name TEXT, _shadow_table_name TEXT, _columns TEXT[], _block_num_before_fork INT )
RETURNS void
LANGUAGE plpgsql
VOLATILE
AS
$BODY$
BEGIN
EXECUTE format(
'INSERT INTO %I.%I( %s )
(
SELECT %s FROM
(
SELECT DISTINCT ON ( hive_rowid ) *
FROM hive.%I st
WHERE st.hive_block_num > %s
ORDER BY hive_rowid, hive_block_num
) as st
WHERE st.hive_operation_type = ''UPDATE''
)'
, _table_schema
, _table_name
, __columns
, __columns
'SELECT
CASE st.hive_operation_type
WHEN ''INSERT'' THEN hive.revert_insert( ''%s'', ''%s'', st.hive_rowid )
WHEN ''DELETE'' THEN hive.revert_delete( ''%s'', ''%s'', ''%s'', st.hive_operation_id, ''%s'' )
WHEN ''UPDATE'' THEN hive.revert_update( ''%s'', ''%s'', ''%s'', st.hive_operation_id, ''%s'', st.hive_rowid )
END
FROM hive.%I st
WHERE st.hive_block_num > %s
ORDER BY st.hive_operation_id DESC'
, _table_schema, _table_name
, _table_schema, _table_name, _shadow_table_name, _columns
, _table_schema, _table_name, _shadow_table_name, _columns
, _shadow_table_name
, _block_num_before_fork
);
......
......@@ -13,13 +13,15 @@ BEGIN
WHERE constraint_catalog = current_database()
AND constraint_type != ''CHECK''
AND constraint_type != ''PRIMARY KEY''
AND constraint_type != ''UNIQUE''
AND constraint_type != ''EXCLUDE''
AND is_deferrable = ''NO''
AND table_schema=''%I'' AND table_name=''%I'' )'
, _table_schema, _table_name )
INTO __exists_non_defferable;
IF __exists_non_defferable = TRUE THEN
RAISE EXCEPTION 'A registered table cannot have non-deferrable constraints. Please check constraints on table %.%'
RAISE EXCEPTION 'A registered table cannot have non-deferrable referenced constraints. Please check constraints on table %.%'
, _table_schema, _table_name;
END IF;
END;
......
......@@ -9,12 +9,13 @@ DECLARE
__block_num_column_name TEXT := 'hive_block_num';
__operation_column_name TEXT := 'hive_operation_type';
__hive_rowid_column_name TEXT := 'hive_rowid';
__operation_id_column_name TEXT := 'hive_operation_id';
BEGIN
EXECUTE format('CREATE TABLE hive.%I AS TABLE %I.%I', __shadow_table_name, _table_schema, _table_name );
EXECUTE format('DELETE FROM hive.%I', __shadow_table_name ); --empty shadow table if origin table is not empty
EXECUTE format('ALTER TABLE hive.%I ADD COLUMN %I INTEGER NOT NULL', __shadow_table_name, __block_num_column_name );
EXECUTE format('ALTER TABLE hive.%I ADD COLUMN %I hive.TRIGGER_OPERATION NOT NULL', __shadow_table_name, __operation_column_name );
EXECUTE format('ALTER TABLE hive.%I ADD CONSTRAINT uk_%s UNIQUE( %I, %I )', __shadow_table_name, __shadow_table_name, __block_num_column_name, __hive_rowid_column_name );
EXECUTE format('ALTER TABLE hive.%I ADD COLUMN %I BIGSERIAL NOT NULL', __shadow_table_name, __operation_id_column_name );
RETURN __shadow_table_name;
END;
......
# Performance `OPTIMIZED REWIND` vs `ONE BY ONE REVERT`
To make a comparison tests test.funcional.fork_extension.performance_.* vs test.funcional.sql_fork_extension.performance_.*
## Results
| Test | OPTIMIZED REWIND [ms] | ONE BY ONE REVERT [ms] | OnybyOne/Optimized [-] |
| :------------------------ | :----------------------- | :--------------------------- | :------------------- |
| Insert 10k rows in one query| 55, 55, 55 **[55]** | 36, 37, 37 **[36.6]** | 0.67 |
| Insert 10k rows one by one | 285, 277, 282 **[281.3]** | 245, 244, 258 **[249]** | 0.89 |
| Delete 10k rows in one query| 20, 20, 22 **[20.6]** | 16, 16, 16 **[16] ** | 0.78 |
| Delete 10k rows one by one | 3670, 3635, 3688 **[3664.3]**| 3576, 3611, 3584 **[3590]** | 0.97 |
| Update 10k rows in one query| 56, 56, 57 **[57.6]** | 37, 37, 37 **[37]** | 0.64 |
| Update 10k rows one by one | 6368, 6478, 6494 **[6446.6]**| 6500, 6448, 6512 **[6486]** | 1 |
| Truncate 10k rows | 31, 31, 31 **[31]** | 12, 12, 12 **[12]** | 0.39 |
| Back from insert 10k rows | 23, 24, 23 **[23.3]** | 3188, 3173, 3152 **[3171]** | 135 |
| Back from delete 10k rows | 36, 35, 36 **[35.6]** | 8010, 8314, 8052 **[8152]** | 228 |
| Back from update 10k rows | 48, 48, 48 **[48]** | 13497, 13513, 13363 **[13457]** | 280 |
| Back from truncate 10k rows | 32, 31, 32 **[35.6]** | 8026, 8004, 8117 **[8049]** | 226 |
......@@ -73,8 +73,7 @@ ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_to_block_num_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_constraint_fk_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_constraint_unique_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/register_table_edit_negative_unique_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/register_table_negative_unique_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_constraint_pk_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_complex_type_update_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_complex_type_insert_test.sql )
......
......@@ -7,7 +7,20 @@ AS
$BODY$
BEGIN
PERFORM hive.context_create( 'context' );
CREATE TABLE table1( id SERIAL PRIMARY KEY, smth INTEGER, name TEXT ) INHERITS( hive.base );
CREATE TABLE table1(
id INTEGER NOT NULL
, smth TEXT NOT NULL
, CONSTRAINT pk_table1 PRIMARY KEY ( smth )
) INHERITS( hive.base );
PERFORM hive.context_next_block( 'context' );
INSERT INTO table1( id, smth ) VALUES( 1, 'A' );
INSERT INTO table1( id, smth ) VALUES( 2, 'B' );
TRUNCATE hive.shadow_public_table1; --to do not revert inserts
DELETE FROM table1 WHERE id=1;
UPDATE table1 SET id=1 WHERE id=2;
END;
$BODY$
;
......@@ -20,13 +33,9 @@ VOLATILE
AS
$BODY$
BEGIN
BEGIN
ALTER TABLE table1 ADD CONSTRAINT uq_table1 UNIQUE(smth);
ASSERT FALSE, 'Did not catch expected exception';
EXCEPTION WHEN OTHERS THEN
RETURN;
END;
END;
-- because table1 will be first rewinded table2 will stay with incorrect FK for tabe1(id)
PERFORM hive.context_back_from_fork( 'context' , -1 );
END
$BODY$
;
......@@ -38,11 +47,15 @@ STABLE
AS
$BODY$
BEGIN
-- nothing to check
END;
ASSERT ( SELECT COUNT(*) FROM table1 ) = 2, 'Deleted row was not reinserted';
ASSERT EXISTS ( SELECT FROM table1 WHERE id=1 AND smth='A' ), 'First row was not restored';
ASSERT EXISTS ( SELECT FROM table1 WHERE id=2 AND smth='B' ), 'Second row was not restored';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_public_table1 ) = 0, 'Shadow table is not empty';
END
$BODY$
;
SELECT test_given();
SELECT test_when();
SELECT test_then();
......@@ -10,7 +10,7 @@ BEGIN
CREATE TABLE table1(
id INTEGER NOT NULL
, smth TEXT NOT NULL
, CONSTRAINT uq_table1 UNIQUE ( smth ) DEFERRABLE
, CONSTRAINT uq_table1 UNIQUE ( smth )
) INHERITS( hive.base );
PERFORM hive.context_next_block( 'context' );
......@@ -18,8 +18,7 @@ BEGIN
INSERT INTO table1( id, smth ) VALUES( 124, 'blabla2' );
TRUNCATE hive.shadow_public_table1; --to do not revert inserts
-- it is tricky, because DELETE operations are reverted before updates, then row wich violates the unique role will be inserted
-- before the update which change the 'smth' to old name will solve the constraint violation
DELETE FROM table1 WHERE id=123;
UPDATE table1 SET smth='blabla1' WHERE id=124;
END;
......
DROP FUNCTION IF EXISTS test_given;
CREATE FUNCTION test_given()
RETURNS void
LANGUAGE 'plpgsql'
VOLATILE
AS
$BODY$
BEGIN
PERFORM hive.context_create( 'context' );
END;
$BODY$
;
DROP FUNCTION IF EXISTS test_when;
CREATE FUNCTION test_when()
RETURNS void
LANGUAGE 'plpgsql'
VOLATILE
AS
$BODY$
BEGIN
BEGIN
CREATE TABLE table1( id SERIAL PRIMARY KEY, smth INTEGER, name TEXT, CONSTRAINT uq_smth UNIQUE(smth) ) INHERITS( hive.base );
ASSERT FALSE, 'Did not catch expected exception';
EXCEPTION WHEN OTHERS THEN
RETURN;
END;
END;
$BODY$
;
DROP FUNCTION IF EXISTS test_then;
CREATE FUNCTION test_then()
RETURNS void
LANGUAGE 'plpgsql'
STABLE
AS
$BODY$
BEGIN
ASSERT NOT EXISTS ( SELECT * FROM information_schema.tables WHERE table_schema='public' AND table_name = 'table1' ), 'The table was created';
END;
$BODY$
;
SELECT test_given();
SELECT test_when();
SELECT test_then();
......@@ -42,6 +42,7 @@ BEGIN
ASSERT EXISTS ( SELECT FROM information_schema.tables WHERE table_schema='hive' AND table_name = 'shadow_a_table1' );
ASSERT EXISTS ( SELECT FROM information_schema.columns WHERE table_schema='hive' AND table_name='shadow_a_table1' AND column_name='hive_block_num' AND data_type='integer' );
ASSERT EXISTS ( SELECT FROM information_schema.columns WHERE table_schema='hive' AND table_name='shadow_a_table1' AND column_name='hive_operation_type' AND udt_name='trigger_operation' );
ASSERT EXISTS ( SELECT FROM information_schema.columns WHERE table_schema='hive' AND table_name='shadow_a_table1' AND column_name='hive_operation_id' AND data_type='bigint' );
ASSERT EXISTS ( SELECT FROM hive.registered_tables WHERE origin_table_schema='a' AND origin_table_name='table1' AND shadow_table_name='shadow_a_table1' );
ASSERT NOT EXISTS ( SELECT FROM hive.registered_tables WHERE origin_table_schema='a' AND origin_table_name='table_child' ), 'Table shall not be registerd';
......
......@@ -46,13 +46,13 @@ STABLE
AS
$BODY$
BEGIN
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table1 hs WHERE hs.id = 123 AND hs.smth='balbla1' AND hive_operation_type = 'DELETE' AND hive_rowid = 1 AND hive_block_num = 2 ), 'Lack of expected operation table1';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table1 hs WHERE hs.id = 123 AND hs.smth='balbla1' AND hive_operation_type = 'DELETE' AND hive_rowid = 1 AND hive_block_num = 2 AND hive_operation_id = 2 ), 'Lack of expected operation table1';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_public_table1 ) = 2, 'Too many rows in shadow table1';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table2 hs WHERE hs.id = 223 AND hs.smth='balbla2' AND hive_operation_type = 'DELETE' AND hive_rowid = 1 AND hive_block_num = 2 ), 'Lack of expected operation table2';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table2 hs WHERE hs.id = 223 AND hs.smth='balbla2' AND hive_operation_type = 'DELETE' AND hive_rowid = 1 AND hive_block_num = 2 AND hive_operation_id = 2 ), 'Lack of expected operation table2';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_public_table1 ) = 2, 'Too many rows in shadow table2';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table3 hs WHERE hs.id = 323 AND hs.smth='balbla3' AND hive_operation_type = 'DELETE' AND hive_rowid = 1 AND hive_block_num = 2 ), 'Lack of expected operation table3';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table3 hs WHERE hs.id = 323 AND hs.smth='balbla3' AND hive_operation_type = 'DELETE' AND hive_rowid = 1 AND hive_block_num = 2 AND hive_operation_id = 2 ), 'Lack of expected operation table3';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_public_table1 ) = 2, 'Too many rows in shadow table3';
END
$BODY$
......
......@@ -44,17 +44,17 @@ $BODY$
BEGIN
ASSERT ( SELECT COUNT(*) FROM hive.shadow_a_table1 hs WHERE hs.id = 123 AND hs.smth = 'blabla1' ) = 1, 'No expected id value in shadow table1';
ASSERT EXISTS ( SELECT FROM hive.shadow_a_table1 hs WHERE hs.id = 123 AND hs.smth = 'blabla1' AND hive_block_num = 2 ), 'Wrong block num table1';
ASSERT EXISTS ( SELECT FROM hive.shadow_a_table1 hs WHERE hs.id = 123 AND hs.smth = 'blabla1' AND hive_operation_type = 'INSERT' ), 'Wrong operation type table1';
ASSERT EXISTS ( SELECT FROM hive.shadow_a_table1 hs WHERE hs.id = 123 AND hs.smth = 'blabla1' AND hive_operation_type = 'INSERT' AND hive_operation_id = 1 ), 'Wrong operation type table1';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_a_table1 ) = 1, 'Too many rows in shadow table1';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_a_table2 hs WHERE hs.id = 223 AND hs.smth = 'blabla2' ) = 1, 'No expected id value in shadow table2';
ASSERT EXISTS ( SELECT FROM hive.shadow_a_table2 hs WHERE hs.id = 223 AND hs.smth = 'blabla2' AND hive_block_num = 2 ), 'Wrong block num table2';
ASSERT EXISTS ( SELECT FROM hive.shadow_a_table2 hs WHERE hs.id = 223 AND hs.smth = 'blabla2' AND hive_operation_type = 'INSERT' ), 'Wrong operation type table2';
ASSERT EXISTS ( SELECT FROM hive.shadow_a_table2 hs WHERE hs.id = 223 AND hs.smth = 'blabla2' AND hive_operation_type = 'INSERT' AND hive_operation_id = 1 ), 'Wrong operation type table2';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_a_table2 ) = 1, 'Too many rows in shadow table1';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_public_table3 hs WHERE hs.id = 323 AND hs.smth = 'blabla3' ) = 1, 'No expected id value in shadow table3';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table3 hs WHERE hs.id = 323 AND hs.smth = 'blabla3' AND hive_block_num = 2 ), 'Wrong block num table3';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table3 hs WHERE hs.id = 323 AND hs.smth = 'blabla3' AND hive_operation_type = 'INSERT' ), 'Wrong operation type table3';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table3 hs WHERE hs.id = 323 AND hs.smth = 'blabla3' AND hive_operation_type = 'INSERT' AND hive_operation_id = 1 ), 'Wrong operation type table3';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_public_table3 ) = 1, 'Too many rows in shadow table1';
END
$BODY$
......
......@@ -46,13 +46,13 @@ STABLE
AS
$BODY$
BEGIN
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table1 hs WHERE hs.id = 123 AND hs.smth='balbla1' AND hive_operation_type = 'DELETE' AND hive_rowid = 1 AND hive_block_num = 2 ), 'Lack of expected operation table1';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table1 hs WHERE hs.id = 123 AND hs.smth='balbla1' AND hive_operation_type = 'DELETE' AND hive_rowid = 1 AND hive_block_num = 2 AND hive_operation_id = 2 ), 'Lack of expected operation table1';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_public_table1 ) = 2, 'Too many rows in shadow table1';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table2 hs WHERE hs.id = 223 AND hs.smth='balbla2' AND hive_operation_type = 'DELETE' AND hive_rowid = 1 AND hive_block_num = 2 ), 'Lack of expected operation table2';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table2 hs WHERE hs.id = 223 AND hs.smth='balbla2' AND hive_operation_type = 'DELETE' AND hive_rowid = 1 AND hive_block_num = 2 AND hive_operation_id = 2 ), 'Lack of expected operation table2';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_public_table1 ) = 2, 'Too many rows in shadow table2';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table3 hs WHERE hs.id = 323 AND hs.smth='balbla3' AND hive_operation_type = 'DELETE' AND hive_rowid = 1 AND hive_block_num = 2 ), 'Lack of expected operation table3';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table3 hs WHERE hs.id = 323 AND hs.smth='balbla3' AND hive_operation_type = 'DELETE' AND hive_rowid = 1 AND hive_block_num = 2 AND hive_operation_id = 2 ), 'Lack of expected operation table3';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_public_table1 ) = 2, 'Too many rows in shadow table3';
END
$BODY$
......
......@@ -49,13 +49,13 @@ STABLE
AS
$BODY$
BEGIN
ASSERT ( SELECT COUNT(*) FROM hive.shadow_a_table1 hs WHERE hs.id = 123 AND hs.smth = 'blabla1' AND hs.hive_rowid=1 AND hs.hive_operation_type='UPDATE' ) = 1, 'No expected id value in shadow table1';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_a_table1 hs WHERE hs.id = 123 AND hs.smth = 'blabla1' AND hs.hive_rowid=1 AND hs.hive_operation_type='UPDATE' AND hive_operation_id = 2 ) = 1, 'No expected id value in shadow table1';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_a_table1 ) = 2, 'Too many rows in shadow table1';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_b_table2 hs WHERE hs.id = 223 AND hs.smth = 'blabla2' AND hs.hive_rowid=1 AND hs.hive_operation_type='UPDATE' ) = 1, 'No expected id value in shadow table2';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_b_table2 hs WHERE hs.id = 223 AND hs.smth = 'blabla2' AND hs.hive_rowid=1 AND hs.hive_operation_type='UPDATE' AND hive_operation_id = 2 ) = 1, 'No expected id value in shadow table2';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_b_table2 ) = 2, 'Too many rows in shadow table2';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_public_table3 hs WHERE hs.id = 323 AND hs.smth = 'blabla3' AND hs.hive_rowid=1 AND hs.hive_operation_type='UPDATE' ) = 1, 'No expected id value in shadow table2';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_public_table3 hs WHERE hs.id = 323 AND hs.smth = 'blabla3' AND hs.hive_rowid=1 AND hs.hive_operation_type='UPDATE' AND hive_operation_id = 2 ) = 1, 'No expected id value in shadow table2';
ASSERT ( SELECT COUNT(*) FROM hive.shadow_public_table3 ) = 2, 'Too many rows in shadow table3';
END
$BODY$
......
......@@ -38,7 +38,7 @@ AS
$BODY$
BEGIN
ASSERT ( SELECT COUNT(*) FROM hive.shadow_a_table1 hs WHERE hs.id = 123 AND hs.smth='balbla' ) = 2, 'No expected id value in shadow table';
ASSERT EXISTS ( SELECT FROM hive.shadow_a_table1 hs WHERE hs.id = 123 AND hs.smth='balbla' AND hs.hive_block_num = 2 AND hs.hive_operation_type = 'DELETE' ), 'Wrong block num';
ASSERT EXISTS ( SELECT FROM hive.shadow_a_table1 hs WHERE hs.id = 123 AND hs.smth='balbla' AND hs.hive_block_num = 2 AND hs.hive_operation_type = 'DELETE' AND hive_operation_id = 2 ), 'Wrong block num';
END
$BODY$
;
......
......@@ -37,7 +37,7 @@ $BODY$
BEGIN
ASSERT ( SELECT COUNT(*) FROM hive.shadow_public_table1 hs WHERE hs.id = 123 AND hs.smth = 'blabla' ) = 1, 'No expected id value in shadow table';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table1 hs WHERE hs.id = 123 AND hs.smth = 'blabla' AND hive_block_num = 2 ), 'Wrong block num';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table1 hs WHERE hs.id = 123 AND hs.smth = 'blabla' AND hive_operation_type = 'INSERT' ), 'Wrong operation type';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table1 hs WHERE hs.id = 123 AND hs.smth = 'blabla' AND hive_operation_type = 'INSERT' AND hive_operation_id = 1 ), 'Wrong operation type';
END
$BODY$
;
......
......@@ -37,7 +37,7 @@ AS
$BODY$
BEGIN
ASSERT ( SELECT COUNT(*) FROM hive.shadow_public_table1 hs WHERE hs.id = 123 AND hs.smth='balbla' ) = 2, 'No expected id value in shadow table';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table1 hs WHERE hs.id = 123 AND hs.smth='balbla' AND hive_block_num = 2 AND hive_operation_type = 'DELETE' ), 'Wrong block num';
ASSERT EXISTS ( SELECT FROM hive.shadow_public_table1 hs WHERE hs.id = 123 AND hs.smth='balbla' AND hive_block_num = 2 AND hive_operation_type = 'DELETE' AND hive_operation_id = 2 ), 'Wrong block num';
END
$BODY$
;
......
......@@ -38,7 +38,7 @@ AS
$BODY$
BEGIN
ASSERT ( SELECT COUNT(*) FROM hive.shadow_a_table1 hs WHERE hs.id = 123 AND hs.smth = 'blabla' ) = 2, 'No expected id value in shadow table';
ASSERT EXISTS ( SELECT FROM hive.shadow_a_table1 hs WHERE hs.id = 123 AND hs.smth = 'blabla' AND hive_block_num = 2 AND hive_operation_type = 'UPDATE' ), 'No expected row';
ASSERT EXISTS ( SELECT FROM hive.shadow_a_table1 hs WHERE hs.id = 123 AND hs.smth = 'blabla' AND hive_block_num = 2 AND hive_operation_type = 'UPDATE' AND hive_operation_id = 2 ), 'No expected row';
END
$BODY$
;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment