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

Commita82ee7e

Browse files
committed
Check if ii_AmCache is NULL in aminsertcleanup
Fix a bug introduced byc1ec02b. It may happen that the executoropens indexes on the result relation, but no rows end up being inserted.Then the index_insert_cleanup still gets executed, but passes down NULLto the AM callback. The AM callback may not expect this, as is the caseof brininsertcleanup, leading to a crash.Fixed by only calling the cleanup callback if (ii_AmCache != NULL). Thisway the AM can simply assume to only see a valid cache.Reported-by: Richard GuoDiscussion:https://postgr.es/m/CAMbWs4-w9qC-o9hQox9UHvdVZAYTp8OrPQOKtwbvzWaRejTT=Q@mail.gmail.com
1 parent1f39535 commita82ee7e

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

‎src/backend/access/index/indexam.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ index_insert_cleanup(Relation indexRelation,
207207
RELATION_CHECKS;
208208
Assert(indexInfo);
209209

210-
if (indexRelation->rd_indam->aminsertcleanup)
210+
if (indexRelation->rd_indam->aminsertcleanup&&indexInfo->ii_AmCache)
211211
indexRelation->rd_indam->aminsertcleanup(indexInfo);
212212
}
213213

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,9 @@ CREATE UNLOGGED TABLE brintest_unlogged (n numrange);
572572
CREATE INDEX brinidx_unlogged ON brintest_unlogged USING brin (n);
573573
INSERT INTO brintest_unlogged VALUES (numrange(0, 2^1000::numeric));
574574
DROP TABLE brintest_unlogged;
575+
-- test that the insert optimization works if no rows end up inserted
576+
CREATE TABLE brin_insert_optimization (a int);
577+
INSERT INTO brin_insert_optimization VALUES (1);
578+
CREATE INDEX ON brin_insert_optimization USING brin (a);
579+
UPDATE brin_insert_optimization SET a = a;
580+
DROP TABLE brin_insert_optimization;

‎src/test/regress/sql/brin.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,3 +515,10 @@ CREATE UNLOGGED TABLE brintest_unlogged (n numrange);
515515
CREATEINDEXbrinidx_unloggedON brintest_unlogged USING brin (n);
516516
INSERT INTO brintest_unloggedVALUES (numrange(0,2^1000::numeric));
517517
DROPTABLE brintest_unlogged;
518+
519+
-- test that the insert optimization works if no rows end up inserted
520+
CREATETABLEbrin_insert_optimization (aint);
521+
INSERT INTO brin_insert_optimizationVALUES (1);
522+
CREATEINDEXON brin_insert_optimization USING brin (a);
523+
UPDATE brin_insert_optimizationSET a= a;
524+
DROPTABLE brin_insert_optimization;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp