Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-1035 Fix toast slice fetching with offset #282

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions expected/toast_extended_storage.out
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,27 @@ UPDATE indtoasttest SET cnt = cnt +1, f1 = f1||'' RETURNING substring(indtoastte

UPDATE indtoasttest SET f2 = '+'||f2||'-' ;
DROP TABLE indtoasttest;
-- Test substr with toasted externalized bytea values
CREATE TABLE toasttest(t bytea STORAGE EXTERNAL) using tde_heap_basic;
INSERT INTO toasttest VALUES (decode(repeat('1234567890',10000), 'escape'));
SET bytea_output = 'escape';
SELECT substring(t, 1, 10) FROM toasttest;
substring
------------
1234567890
(1 row)

SELECT substring(t, 50001, 10) FROM toasttest;
substring
------------
1234567890
(1 row)

SELECT substring(t, 99991) FROM toasttest;
substring
------------
1234567890
(1 row)

DROP TABLE toasttest;
DROP EXTENSION pg_tde;
11 changes: 11 additions & 0 deletions sql/toast_extended_storage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,15 @@ UPDATE indtoasttest SET f2 = '+'||f2||'-' ;

DROP TABLE indtoasttest;

-- Test substr with toasted externalized bytea values
CREATE TABLE toasttest(t bytea STORAGE EXTERNAL) using tde_heap_basic;
INSERT INTO toasttest VALUES (decode(repeat('1234567890',10000), 'escape'));

SET bytea_output = 'escape';
SELECT substring(t, 1, 10) FROM toasttest;
SELECT substring(t, 50001, 10) FROM toasttest;
SELECT substring(t, 99991) FROM toasttest;

DROP TABLE toasttest;

DROP EXTENSION pg_tde;
2 changes: 1 addition & 1 deletion src16/access/pg_tdetoast.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ tdeheap_fetch_toast_slice(Relation toastrel, Oid valueid, int32 attrsize,
}
/* Decrypt the data chunk by chunk here */

PG_TDE_DECRYPT_DATA(iv_prefix, (curchunk * TOAST_MAX_CHUNK_SIZE - sliceoffset) + encrypt_offset,
PG_TDE_DECRYPT_DATA(iv_prefix, (curchunk * TOAST_MAX_CHUNK_SIZE) + encrypt_offset,
chunkdata + chcpystrt,
(chcpyend - chcpystrt) + 1,
decrypted_data, key);
Expand Down
2 changes: 1 addition & 1 deletion src17/access/pg_tdetoast.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ tdeheap_fetch_toast_slice(Relation toastrel, Oid valueid, int32 attrsize,
}
/* Decrypt the data chunk by chunk here */

PG_TDE_DECRYPT_DATA(iv_prefix, (curchunk * TOAST_MAX_CHUNK_SIZE - sliceoffset) + encrypt_offset,
PG_TDE_DECRYPT_DATA(iv_prefix, (curchunk * TOAST_MAX_CHUNK_SIZE) + encrypt_offset,
chunkdata + chcpystrt,
(chcpyend - chcpystrt) + 1,
decrypted_data, key);
Expand Down
Loading