Skip to content

Commit

Permalink
PMM-1035 Fix toast slice fetching with offset (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemgavrilov authored Sep 17, 2024
1 parent 4197530 commit 137a498
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
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

0 comments on commit 137a498

Please sign in to comment.