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

Commit855195a

Browse files
committed
Kluge slot_compile_deform() to ignore incorrect attnotnull markings.
Since we mustn't force an initdb in released branches, there is nosimple way to correct the markings of pg_subscription.subslotnameand pg_subscription_rel.srsublsn as attnotnull in existing pre-v13installations.Fortunately, released branches don't rely on attnotnull being correctfor much. The planner looks at it in relation_excluded_by_constraints,but it'd be difficult to get that to matter for a query on a systemcatalog. The only place where it's really problematic is in JIT'sslot_compile_deform(), which can produce incorrect code that crashesif there are NULLs in an allegedly not-null column.Hence, hack up slot_compile_deform() to be specifically aware ofthese two incorrect markings and not trust them.This applies to v11 and v12; the JIT code didn't exist before that,and we've fixed the markings in v13.Discussion:https://postgr.es/m/229396.1595191345@sss.pgh.pa.us
1 parente8de627 commit855195a

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

‎src/backend/jit/llvm/llvmjit_deform.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,27 @@
2222

2323
#include"access/htup_details.h"
2424
#include"access/tupdesc_details.h"
25+
#include"catalog/pg_subscription.h"
26+
#include"catalog/pg_subscription_rel.h"
2527
#include"executor/tuptable.h"
2628
#include"jit/llvmjit.h"
2729
#include"jit/llvmjit_emit.h"
2830

2931

32+
/*
33+
* Through an embarrassing oversight, pre-v13 installations may have
34+
* pg_subscription.subslotname and pg_subscription_rel.srsublsn marked as
35+
* attnotnull, which they should not be. To avoid possible crashes, use
36+
* this macro instead of testing attnotnull directly.
37+
*/
38+
#defineATTNOTNULL(att) \
39+
((att)->attnotnull && \
40+
!(((att)->attrelid == SubscriptionRelationId && \
41+
(att)->attnum == Anum_pg_subscription_subslotname) || \
42+
((att)->attrelid == SubscriptionRelRelationId && \
43+
(att)->attnum == Anum_pg_subscription_rel_srsublsn)))
44+
45+
3046
/*
3147
* Create a function that deforms a tuple of type desc up to natts columns.
3248
*/
@@ -113,7 +129,7 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc, int natts)
113129
* it's guaranteed that all columns up to here exist at least in the
114130
* NULL bitmap.
115131
*/
116-
if (att->attnotnull)
132+
if (ATTNOTNULL(att))
117133
guaranteed_column_number=attnum;
118134
}
119135

@@ -376,7 +392,7 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc, int natts)
376392
* into account, because in case they're present the heaptuple's natts
377393
* would have indicated that a slot_getmissingattrs() is needed.
378394
*/
379-
if (!att->attnotnull)
395+
if (!ATTNOTNULL(att))
380396
{
381397
LLVMBasicBlockRefb_ifnotnull;
382398
LLVMBasicBlockRefb_ifnull;
@@ -557,7 +573,7 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc, int natts)
557573
known_alignment=-1;
558574
attguaranteedalign= false;
559575
}
560-
elseif (att->attnotnull&&attguaranteedalign&&known_alignment >=0)
576+
elseif (ATTNOTNULL(att)&&attguaranteedalign&&known_alignment >=0)
561577
{
562578
/*
563579
* If the offset to the column was previously known a NOT NULL &
@@ -567,7 +583,7 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc, int natts)
567583
Assert(att->attlen>0);
568584
known_alignment+=att->attlen;
569585
}
570-
elseif (att->attnotnull&& (att->attlen %alignto)==0)
586+
elseif (ATTNOTNULL(att)&& (att->attlen %alignto)==0)
571587
{
572588
/*
573589
* After a NOT NULL fixed-width column with a length that is a

‎src/test/regress/expected/subscription.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ DROP SUBSCRIPTION testsub;
147147
ERROR: DROP SUBSCRIPTION cannot run inside a transaction block
148148
COMMIT;
149149
ALTER SUBSCRIPTION testsub SET (slot_name = NONE);
150+
\dRs+
151+
List of subscriptions
152+
Name | Owner | Enabled | Publication | Synchronous commit | Conninfo
153+
---------+----------------------------+---------+---------------------+--------------------+----------------------
154+
testsub | regress_subscription_user2 | f | {testpub2,testpub3} | local | dbname=doesnotexist2
155+
(1 row)
156+
150157
-- now it works
151158
BEGIN;
152159
DROP SUBSCRIPTION testsub;

‎src/test/regress/sql/subscription.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ COMMIT;
109109

110110
ALTER SUBSCRIPTION testsubSET (slot_name= NONE);
111111

112+
\dRs+
113+
112114
-- now it works
113115
BEGIN;
114116
DROP SUBSCRIPTION testsub;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp