diff --git a/src/backend/cdb/motion/tupser.c b/src/backend/cdb/motion/tupser.c index df1ab4f2f2e..b0a7bb065f7 100644 --- a/src/backend/cdb/motion/tupser.c +++ b/src/backend/cdb/motion/tupser.c @@ -412,7 +412,11 @@ SerializeTuple(TupleTableSlot *slot, SerTupInfo *pSerInfo, struct directTranspor { Form_pg_attribute attr = TupleDescAttr(slot->tts_tupleDescriptor, i); - if (!attr->attisdropped && attr->attlen == -1 && !slot->tts_isnull[i]) + /* + * Cannot access slot->tts_isnull before invoking slot_getallattrs. + * See Github Issue 16906. + */ + if (!attr->attisdropped && attr->attlen == -1) { hasExternalAttr = true; break; diff --git a/src/test/regress/expected/toast.out b/src/test/regress/expected/toast.out index abf5136fd4a..9d97ab868c5 100644 --- a/src/test/regress/expected/toast.out +++ b/src/test/regress/expected/toast.out @@ -180,3 +180,19 @@ SELECT encode(substring(a from 521*26+1 for 26), 'escape') FROM toast_chunk_test abcdefghijklmnopqrstuvwxyz (1 row) +-- Test for Github Issue 16906 +create table t_16906(a int, b text) distributed by(a); +-- Insert two rows and make sure they are in the same segment (same dist key) +-- the 1st row's column b must be NULL; +-- the 2nd row's column b must be a long string even after toast compression +-- for details please refer to the issue page. +insert into t_16906 values(1, null); +insert into t_16906 values(1, randomtext(10240)); +-- Don't want actually fetch all data just need to test +-- it does not hit assert fail or error. Using explain +-- analyze might introduce a new ansfile for ORCA so here +-- I decide to use \o. +\o /tmp/t_16906.tmp +select * from t_16906; +\o +drop table t_16906; diff --git a/src/test/regress/sql/toast.sql b/src/test/regress/sql/toast.sql index 7b3cfe7d204..a35cb77e4b7 100644 --- a/src/test/regress/sql/toast.sql +++ b/src/test/regress/sql/toast.sql @@ -95,3 +95,23 @@ SELECT * FROM toast_chunk_test WHERE a <> repeat('abcdefghijklmnopqrstuvwxyz', 1 -- Random access into the toast table should work equally well. SELECT encode(substring(a from 521*26+1 for 26), 'escape') FROM toast_chunk_test; + +-- Test for Github Issue 16906 +create table t_16906(a int, b text) distributed by(a); + +-- Insert two rows and make sure they are in the same segment (same dist key) +-- the 1st row's column b must be NULL; +-- the 2nd row's column b must be a long string even after toast compression +-- for details please refer to the issue page. +insert into t_16906 values(1, null); +insert into t_16906 values(1, randomtext(10240)); + +-- Don't want actually fetch all data just need to test +-- it does not hit assert fail or error. Using explain +-- analyze might introduce a new ansfile for ORCA so here +-- I decide to use \o. +\o /tmp/t_16906.tmp +select * from t_16906; +\o + +drop table t_16906;