Skip to content

Commit 0592389

Browse files
Fix motion toast error. (#436)
slot->tts_isnull cannot be read before invoking slot_getallattrs. Fix Github Issue 16906. Authored-by: wenxing.yaun <wenxing.yuan@esgyn.cn> Co-authored-by: HelloYJohn <xxdrywx@gmail.com>
1 parent 30da5b4 commit 0592389

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

src/backend/cdb/motion/tupser.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,11 @@ SerializeTuple(TupleTableSlot *slot, SerTupInfo *pSerInfo, struct directTranspor
412412
{
413413
Form_pg_attribute attr = TupleDescAttr(slot->tts_tupleDescriptor, i);
414414

415-
if (!attr->attisdropped && attr->attlen == -1 && !slot->tts_isnull[i])
415+
/*
416+
* Cannot access slot->tts_isnull before invoking slot_getallattrs.
417+
* See Github Issue 16906.
418+
*/
419+
if (!attr->attisdropped && attr->attlen == -1)
416420
{
417421
hasExternalAttr = true;
418422
break;

src/test/regress/expected/toast.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,19 @@ SELECT encode(substring(a from 521*26+1 for 26), 'escape') FROM toast_chunk_test
180180
abcdefghijklmnopqrstuvwxyz
181181
(1 row)
182182

183+
-- Test for Github Issue 16906
184+
create table t_16906(a int, b text) distributed by(a);
185+
-- Insert two rows and make sure they are in the same segment (same dist key)
186+
-- the 1st row's column b must be NULL;
187+
-- the 2nd row's column b must be a long string even after toast compression
188+
-- for details please refer to the issue page.
189+
insert into t_16906 values(1, null);
190+
insert into t_16906 values(1, randomtext(10240));
191+
-- Don't want actually fetch all data just need to test
192+
-- it does not hit assert fail or error. Using explain
193+
-- analyze might introduce a new ansfile for ORCA so here
194+
-- I decide to use \o.
195+
\o /tmp/t_16906.tmp
196+
select * from t_16906;
197+
\o
198+
drop table t_16906;

src/test/regress/sql/toast.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,23 @@ SELECT * FROM toast_chunk_test WHERE a <> repeat('abcdefghijklmnopqrstuvwxyz', 1
9595

9696
-- Random access into the toast table should work equally well.
9797
SELECT encode(substring(a from 521*26+1 for 26), 'escape') FROM toast_chunk_test;
98+
99+
-- Test for Github Issue 16906
100+
create table t_16906(a int, b text) distributed by(a);
101+
102+
-- Insert two rows and make sure they are in the same segment (same dist key)
103+
-- the 1st row's column b must be NULL;
104+
-- the 2nd row's column b must be a long string even after toast compression
105+
-- for details please refer to the issue page.
106+
insert into t_16906 values(1, null);
107+
insert into t_16906 values(1, randomtext(10240));
108+
109+
-- Don't want actually fetch all data just need to test
110+
-- it does not hit assert fail or error. Using explain
111+
-- analyze might introduce a new ansfile for ORCA so here
112+
-- I decide to use \o.
113+
\o /tmp/t_16906.tmp
114+
select * from t_16906;
115+
\o
116+
117+
drop table t_16906;

0 commit comments

Comments
 (0)