Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfb71329

Browse files
committed
Assert that we don't insert nulls into attnotnull catalog columns.
The executor checks for this error, and so does the bootstrap catalogloader, but we never checked for it in retail catalog manipulations.The folly of that has now been exposed, so let's add assertionschecking it. Checking in CatalogTupleInsert[WithInfo] andCatalogTupleUpdate[WithInfo] should be enough to cover this.Back-patch to v10; the aforesaid functions didn't exist before that,and it didn't seem worth adapting the patch to the oldest branches.But given the risk of JIT crashes, I think we certainly need thisas far back as v11.Pre-v13, we have to explicitly exclude pg_subscription.subslotnameand pg_subscription_rel.srsublsn from the checks, since they aremismarked. (Even if we change our mind about applying BKI_FORCE_NULLin the branch tips, it doesn't seem wise to have assertions thatwould fire in existing databases.)Discussion:https://postgr.es/m/298837.1595196283@sss.pgh.pa.us
1 parentae3d40b commitfb71329

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

‎src/backend/catalog/indexing.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include"access/htup_details.h"
1919
#include"catalog/index.h"
2020
#include"catalog/indexing.h"
21+
#include"catalog/pg_subscription.h"
22+
#include"catalog/pg_subscription_rel.h"
2123
#include"executor/executor.h"
2224
#include"utils/rel.h"
2325

@@ -163,6 +165,53 @@ CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
163165
ExecDropSingleTupleTableSlot(slot);
164166
}
165167

168+
/*
169+
* Subroutine to verify that catalog constraints are honored.
170+
*
171+
* Tuples inserted via CatalogTupleInsert/CatalogTupleUpdate are generally
172+
* "hand made", so that it's possible that they fail to satisfy constraints
173+
* that would be checked if they were being inserted by the executor. That's
174+
* a coding error, so we only bother to check for it in assert-enabled builds.
175+
*/
176+
#ifdefUSE_ASSERT_CHECKING
177+
178+
staticvoid
179+
CatalogTupleCheckConstraints(RelationheapRel,HeapTupletup)
180+
{
181+
/*
182+
* Currently, the only constraints implemented for system catalogs are
183+
* attnotnull constraints.
184+
*/
185+
if (HeapTupleHasNulls(tup))
186+
{
187+
TupleDesctupdesc=RelationGetDescr(heapRel);
188+
bits8*bp=tup->t_data->t_bits;
189+
190+
for (intattnum=0;attnum<tupdesc->natts;attnum++)
191+
{
192+
Form_pg_attributethisatt=TupleDescAttr(tupdesc,attnum);
193+
194+
/*
195+
* Through an embarrassing oversight, pre-v13 installations have
196+
* pg_subscription.subslotname and pg_subscription_rel.srsublsn
197+
* marked as attnotnull, which they should not be. Ignore those
198+
* flags.
199+
*/
200+
Assert(!(thisatt->attnotnull&&att_isnull(attnum,bp)&&
201+
!((thisatt->attrelid==SubscriptionRelationId&&
202+
thisatt->attnum==Anum_pg_subscription_subslotname)||
203+
(thisatt->attrelid==SubscriptionRelRelationId&&
204+
thisatt->attnum==Anum_pg_subscription_rel_srsublsn))));
205+
}
206+
}
207+
}
208+
209+
#else/* !USE_ASSERT_CHECKING */
210+
211+
#defineCatalogTupleCheckConstraints(heapRel,tup) ((void) 0)
212+
213+
#endif/* USE_ASSERT_CHECKING */
214+
166215
/*
167216
* CatalogTupleInsert - do heap and indexing work for a new catalog tuple
168217
*
@@ -181,6 +230,8 @@ CatalogTupleInsert(Relation heapRel, HeapTuple tup)
181230
CatalogIndexStateindstate;
182231
Oidoid;
183232

233+
CatalogTupleCheckConstraints(heapRel,tup);
234+
184235
indstate=CatalogOpenIndexes(heapRel);
185236

186237
oid=simple_heap_insert(heapRel,tup);
@@ -205,6 +256,8 @@ CatalogTupleInsertWithInfo(Relation heapRel, HeapTuple tup,
205256
{
206257
Oidoid;
207258

259+
CatalogTupleCheckConstraints(heapRel,tup);
260+
208261
oid=simple_heap_insert(heapRel,tup);
209262

210263
CatalogIndexInsert(indstate,tup);
@@ -228,6 +281,8 @@ CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
228281
{
229282
CatalogIndexStateindstate;
230283

284+
CatalogTupleCheckConstraints(heapRel,tup);
285+
231286
indstate=CatalogOpenIndexes(heapRel);
232287

233288
simple_heap_update(heapRel,otid,tup);
@@ -248,6 +303,8 @@ void
248303
CatalogTupleUpdateWithInfo(RelationheapRel,ItemPointerotid,HeapTupletup,
249304
CatalogIndexStateindstate)
250305
{
306+
CatalogTupleCheckConstraints(heapRel,tup);
307+
251308
simple_heap_update(heapRel,otid,tup);
252309

253310
CatalogIndexInsert(indstate,tup);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp