-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* PG-1056 Add failing test * PG-1056 Use proper AM in test * Fix UPDATE SET ... RETURNING processing for encrypted tuples If `get_heap_tuple` is NULL, the core uses `copy_heap_tuple` instead. The former returns a pointer to a tuple in the slot and the latter makes a copy of such a tuple. For UPDATE SET, the core uses the slot for INSERT and later for RETURNING processing. If we copy the tuple the next happens: 1. The core creates a slot with the generic tuple. 2. It passed to `pg_tdeam_tuple_update()` and it gets a copy of the tuple here [https://github.com/Percona-Lab/pg_tde/blob/6d4f7e5b7bd2507ce65deb315ea8d5647f474cf9/src17/access/pg_tdeam_handler.c#L336]. 3. This generic tuple is filled with the proper data and used for the update here [https://github.com/Percona-Lab/pg_tde/blob/6d4f7e5b7bd2507ce65deb315ea8d5647f474cf9/src17/access/pg_tdeam_handler.c#L343]. 4. Later on, RETURNING processing uses the slot's tuple but is still a generic unmodified one because of the copy. 5. That results in wrong RETURNING data. To avoid this, we should return a pointer to the slot's tuple instead of copying it. Fixes PG-1056 * PG-1056 Split 'update' testcase for tde_heap and tde_heap_basic --------- Co-authored-by: Andrew Pogrebnoy <absourd.noise@gmail.com>
- Loading branch information
1 parent
42b23bd
commit 3e4c889
Showing
8 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
\set tde_am tde_heap | ||
\i sql/update.inc | ||
CREATE EXTENSION pg_tde; | ||
SELECT pg_tde_add_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per'); | ||
pg_tde_add_key_provider_file | ||
------------------------------ | ||
1 | ||
(1 row) | ||
|
||
SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault'); | ||
pg_tde_set_principal_key | ||
-------------------------- | ||
t | ||
(1 row) | ||
|
||
CREATE TABLE update_test ( | ||
a INT DEFAULT 10, | ||
b INT, | ||
c TEXT | ||
) USING tde_heap_basic; | ||
CREATE TABLE upsert_test ( | ||
a INT PRIMARY KEY, | ||
b TEXT | ||
) USING tde_heap_basic; | ||
INSERT INTO update_test VALUES (5, 10, 'foo'); | ||
INSERT INTO update_test(b, a) VALUES (15, 10); | ||
INSERT INTO upsert_test VALUES (2, 'Beeble') ON CONFLICT(a) | ||
DO UPDATE SET (b, a) = (SELECT b || ', Excluded', a from upsert_test i WHERE i.a = excluded.a) | ||
RETURNING tableoid::regclass, xmin = pg_current_xact_id()::xid AS xmin_correct, xmax = 0 AS xmax_correct; | ||
tableoid | xmin_correct | xmax_correct | ||
-------------+--------------+-------------- | ||
upsert_test | t | t | ||
(1 row) | ||
|
||
-- currently xmax is set after a conflict - that's probably not good, | ||
-- but it seems worthwhile to have to be explicit if that changes. | ||
INSERT INTO upsert_test VALUES (2, 'Brox') ON CONFLICT(a) | ||
DO UPDATE SET (b, a) = (SELECT b || ', Excluded', a from upsert_test i WHERE i.a = excluded.a) | ||
RETURNING tableoid::regclass, xmin = pg_current_xact_id()::xid AS xmin_correct, xmax = pg_current_xact_id()::xid AS xmax_correct; | ||
tableoid | xmin_correct | xmax_correct | ||
-------------+--------------+-------------- | ||
upsert_test | t | t | ||
(1 row) | ||
|
||
DROP TABLE update_test; | ||
DROP TABLE upsert_test; | ||
DROP EXTENSION pg_tde; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
\set tde_am tde_heap_basic | ||
\i sql/update.inc | ||
CREATE EXTENSION pg_tde; | ||
SELECT pg_tde_add_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per'); | ||
pg_tde_add_key_provider_file | ||
------------------------------ | ||
1 | ||
(1 row) | ||
|
||
SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault'); | ||
pg_tde_set_principal_key | ||
-------------------------- | ||
t | ||
(1 row) | ||
|
||
CREATE TABLE update_test ( | ||
a INT DEFAULT 10, | ||
b INT, | ||
c TEXT | ||
) USING tde_heap_basic; | ||
CREATE TABLE upsert_test ( | ||
a INT PRIMARY KEY, | ||
b TEXT | ||
) USING tde_heap_basic; | ||
INSERT INTO update_test VALUES (5, 10, 'foo'); | ||
INSERT INTO update_test(b, a) VALUES (15, 10); | ||
INSERT INTO upsert_test VALUES (2, 'Beeble') ON CONFLICT(a) | ||
DO UPDATE SET (b, a) = (SELECT b || ', Excluded', a from upsert_test i WHERE i.a = excluded.a) | ||
RETURNING tableoid::regclass, xmin = pg_current_xact_id()::xid AS xmin_correct, xmax = 0 AS xmax_correct; | ||
tableoid | xmin_correct | xmax_correct | ||
-------------+--------------+-------------- | ||
upsert_test | t | t | ||
(1 row) | ||
|
||
-- currently xmax is set after a conflict - that's probably not good, | ||
-- but it seems worthwhile to have to be explicit if that changes. | ||
INSERT INTO upsert_test VALUES (2, 'Brox') ON CONFLICT(a) | ||
DO UPDATE SET (b, a) = (SELECT b || ', Excluded', a from upsert_test i WHERE i.a = excluded.a) | ||
RETURNING tableoid::regclass, xmin = pg_current_xact_id()::xid AS xmin_correct, xmax = pg_current_xact_id()::xid AS xmax_correct; | ||
tableoid | xmin_correct | xmax_correct | ||
-------------+--------------+-------------- | ||
upsert_test | t | t | ||
(1 row) | ||
|
||
DROP TABLE update_test; | ||
DROP TABLE upsert_test; | ||
DROP EXTENSION pg_tde; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
CREATE EXTENSION pg_tde; | ||
|
||
SELECT pg_tde_add_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per'); | ||
SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault'); | ||
|
||
|
||
CREATE TABLE update_test ( | ||
a INT DEFAULT 10, | ||
b INT, | ||
c TEXT | ||
) USING tde_heap_basic; | ||
|
||
CREATE TABLE upsert_test ( | ||
a INT PRIMARY KEY, | ||
b TEXT | ||
) USING tde_heap_basic; | ||
|
||
INSERT INTO update_test VALUES (5, 10, 'foo'); | ||
INSERT INTO update_test(b, a) VALUES (15, 10); | ||
|
||
INSERT INTO upsert_test VALUES (2, 'Beeble') ON CONFLICT(a) | ||
DO UPDATE SET (b, a) = (SELECT b || ', Excluded', a from upsert_test i WHERE i.a = excluded.a) | ||
RETURNING tableoid::regclass, xmin = pg_current_xact_id()::xid AS xmin_correct, xmax = 0 AS xmax_correct; | ||
-- currently xmax is set after a conflict - that's probably not good, | ||
-- but it seems worthwhile to have to be explicit if that changes. | ||
INSERT INTO upsert_test VALUES (2, 'Brox') ON CONFLICT(a) | ||
DO UPDATE SET (b, a) = (SELECT b || ', Excluded', a from upsert_test i WHERE i.a = excluded.a) | ||
RETURNING tableoid::regclass, xmin = pg_current_xact_id()::xid AS xmin_correct, xmax = pg_current_xact_id()::xid AS xmax_correct; | ||
|
||
DROP TABLE update_test; | ||
DROP TABLE upsert_test; | ||
|
||
DROP EXTENSION pg_tde; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
\set tde_am tde_heap | ||
\i sql/update.inc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
\set tde_am tde_heap_basic | ||
\i sql/update.inc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters