From ff4d989173084431914220d1a66646a332fa9d71 Mon Sep 17 00:00:00 2001 From: Pavel Borisov Date: Thu, 25 Apr 2024 15:36:38 +0400 Subject: [PATCH v1 5/5] Rename checkunique parameter for amcheck and pg_amcheck Use more user friendly naming: --check-unique for pg_amcheck command line, check_unique for amcheck sql functions Reported-by: Peter Eisentraut --- contrib/amcheck/amcheck--1.3--1.4.sql | 4 +-- contrib/amcheck/expected/check_btree.out | 12 +++---- contrib/amcheck/sql/check_btree.sql | 12 +++---- contrib/amcheck/verify_nbtree.c | 38 +++++++++++----------- doc/src/sgml/amcheck.sgml | 8 ++--- doc/src/sgml/ref/pg_amcheck.sgml | 4 +-- src/bin/pg_amcheck/pg_amcheck.c | 20 ++++++------ src/bin/pg_amcheck/t/003_check.pl | 20 ++++++------ src/bin/pg_amcheck/t/005_opclass_damage.pl | 4 +-- 9 files changed, 61 insertions(+), 61 deletions(-) diff --git a/contrib/amcheck/amcheck--1.3--1.4.sql b/contrib/amcheck/amcheck--1.3--1.4.sql index 75574eaa64..e0d4f92085 100644 --- a/contrib/amcheck/amcheck--1.3--1.4.sql +++ b/contrib/amcheck/amcheck--1.3--1.4.sql @@ -11,7 +11,7 @@ -- bt_index_parent_check() -- CREATE FUNCTION bt_index_parent_check(index regclass, - heapallindexed boolean, rootdescend boolean, checkunique boolean) + heapallindexed boolean, rootdescend boolean, check_unique boolean) RETURNS VOID AS 'MODULE_PATHNAME', 'bt_index_parent_check' LANGUAGE C STRICT PARALLEL RESTRICTED; @@ -19,7 +19,7 @@ LANGUAGE C STRICT PARALLEL RESTRICTED; -- bt_index_check() -- CREATE FUNCTION bt_index_check(index regclass, - heapallindexed boolean, checkunique boolean) + heapallindexed boolean, check_unique boolean) RETURNS VOID AS 'MODULE_PATHNAME', 'bt_index_check' LANGUAGE C STRICT PARALLEL RESTRICTED; diff --git a/contrib/amcheck/expected/check_btree.out b/contrib/amcheck/expected/check_btree.out index e7fb5f5515..ebb91d5d78 100644 --- a/contrib/amcheck/expected/check_btree.out +++ b/contrib/amcheck/expected/check_btree.out @@ -200,25 +200,25 @@ SELECT bt_index_check('bttest_a_expr_idx', true); (1 row) -- UNIQUE constraint check -SELECT bt_index_check('bttest_a_idx', heapallindexed => true, checkunique => true); +SELECT bt_index_check('bttest_a_idx', heapallindexed => true, check_unique => true); bt_index_check ---------------- (1 row) -SELECT bt_index_check('bttest_b_idx', heapallindexed => false, checkunique => true); +SELECT bt_index_check('bttest_b_idx', heapallindexed => false, check_unique => true); bt_index_check ---------------- (1 row) -SELECT bt_index_parent_check('bttest_a_idx', heapallindexed => true, rootdescend => true, checkunique => true); +SELECT bt_index_parent_check('bttest_a_idx', heapallindexed => true, rootdescend => true, check_unique => true); bt_index_parent_check ----------------------- (1 row) -SELECT bt_index_parent_check('bttest_b_idx', heapallindexed => true, rootdescend => false, checkunique => true); +SELECT bt_index_parent_check('bttest_b_idx', heapallindexed => true, rootdescend => false, check_unique => true); bt_index_parent_check ----------------------- @@ -227,14 +227,14 @@ SELECT bt_index_parent_check('bttest_b_idx', heapallindexed => true, rootdescend -- Check that null values in an unique index are not treated as equal CREATE TABLE bttest_unique_nulls (a serial, b int, c int UNIQUE); INSERT INTO bttest_unique_nulls VALUES (generate_series(1, 10000), 2, default); -SELECT bt_index_check('bttest_unique_nulls_c_key', heapallindexed => true, checkunique => true); +SELECT bt_index_check('bttest_unique_nulls_c_key', heapallindexed => true, check_unique => true); bt_index_check ---------------- (1 row) CREATE INDEX on bttest_unique_nulls (b,c); -SELECT bt_index_check('bttest_unique_nulls_b_c_idx', heapallindexed => true, checkunique => true); +SELECT bt_index_check('bttest_unique_nulls_b_c_idx', heapallindexed => true, check_unique => true); bt_index_check ---------------- diff --git a/contrib/amcheck/sql/check_btree.sql b/contrib/amcheck/sql/check_btree.sql index 0793dbfeeb..f9ae33a6a4 100644 --- a/contrib/amcheck/sql/check_btree.sql +++ b/contrib/amcheck/sql/check_btree.sql @@ -136,17 +136,17 @@ CREATE INDEX bttest_a_expr_idx ON bttest_a ((ifun(id) + ifun(0))) SELECT bt_index_check('bttest_a_expr_idx', true); -- UNIQUE constraint check -SELECT bt_index_check('bttest_a_idx', heapallindexed => true, checkunique => true); -SELECT bt_index_check('bttest_b_idx', heapallindexed => false, checkunique => true); -SELECT bt_index_parent_check('bttest_a_idx', heapallindexed => true, rootdescend => true, checkunique => true); -SELECT bt_index_parent_check('bttest_b_idx', heapallindexed => true, rootdescend => false, checkunique => true); +SELECT bt_index_check('bttest_a_idx', heapallindexed => true, check_unique => true); +SELECT bt_index_check('bttest_b_idx', heapallindexed => false, check_unique => true); +SELECT bt_index_parent_check('bttest_a_idx', heapallindexed => true, rootdescend => true, check_unique => true); +SELECT bt_index_parent_check('bttest_b_idx', heapallindexed => true, rootdescend => false, check_unique => true); -- Check that null values in an unique index are not treated as equal CREATE TABLE bttest_unique_nulls (a serial, b int, c int UNIQUE); INSERT INTO bttest_unique_nulls VALUES (generate_series(1, 10000), 2, default); -SELECT bt_index_check('bttest_unique_nulls_c_key', heapallindexed => true, checkunique => true); +SELECT bt_index_check('bttest_unique_nulls_c_key', heapallindexed => true, check_unique => true); CREATE INDEX on bttest_unique_nulls (b,c); -SELECT bt_index_check('bttest_unique_nulls_b_c_idx', heapallindexed => true, checkunique => true); +SELECT bt_index_check('bttest_unique_nulls_b_c_idx', heapallindexed => true, check_unique => true); -- Check support of both 1B and 4B header sizes of short varlena datum CREATE TABLE varlena_bug (v text); diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c index dfc9ed769f..3b673bac95 100644 --- a/contrib/amcheck/verify_nbtree.c +++ b/contrib/amcheck/verify_nbtree.c @@ -83,7 +83,7 @@ typedef struct BtreeCheckState /* Also making sure non-pivot tuples can be found by new search? */ bool rootdescend; /* Also check uniqueness constraint if index is unique */ - bool checkunique; + bool check_unique; /* Per-page context */ MemoryContext targetcontext; /* Buffer access strategy */ @@ -159,12 +159,12 @@ PG_FUNCTION_INFO_V1(bt_index_parent_check); static void bt_index_check_internal(Oid indrelid, bool parentcheck, bool heapallindexed, bool rootdescend, - bool checkunique); + bool check_unique); static inline void btree_index_checkable(Relation rel); static inline bool btree_index_mainfork_expected(Relation rel); static void bt_check_every_level(Relation rel, Relation heaprel, bool heapkeyspace, bool readonly, bool heapallindexed, - bool rootdescend, bool checkunique); + bool rootdescend, bool check_unique); static BtreeLevel bt_check_level_from_leftmost(BtreeCheckState *state, BtreeLevel level); static bool bt_leftmost_ignoring_half_dead(BtreeCheckState *state, @@ -223,7 +223,7 @@ static inline ItemPointer BTreeTupleGetHeapTIDCareful(BtreeCheckState *state, static inline ItemPointer BTreeTupleGetPointsToTID(IndexTuple itup); /* - * bt_index_check(index regclass, heapallindexed boolean, checkunique boolean) + * bt_index_check(index regclass, heapallindexed boolean, check_unique boolean) * * Verify integrity of B-Tree index. * @@ -236,20 +236,20 @@ bt_index_check(PG_FUNCTION_ARGS) { Oid indrelid = PG_GETARG_OID(0); bool heapallindexed = false; - bool checkunique = false; + bool check_unique = false; if (PG_NARGS() >= 2) heapallindexed = PG_GETARG_BOOL(1); if (PG_NARGS() == 3) - checkunique = PG_GETARG_BOOL(2); + check_unique = PG_GETARG_BOOL(2); - bt_index_check_internal(indrelid, false, heapallindexed, false, checkunique); + bt_index_check_internal(indrelid, false, heapallindexed, false, check_unique); PG_RETURN_VOID(); } /* - * bt_index_parent_check(index regclass, heapallindexed boolean, rootdescend boolean, checkunique boolean) + * bt_index_parent_check(index regclass, heapallindexed boolean, rootdescend boolean, check_unique boolean) * * Verify integrity of B-Tree index. * @@ -263,16 +263,16 @@ bt_index_parent_check(PG_FUNCTION_ARGS) Oid indrelid = PG_GETARG_OID(0); bool heapallindexed = false; bool rootdescend = false; - bool checkunique = false; + bool check_unique = false; if (PG_NARGS() >= 2) heapallindexed = PG_GETARG_BOOL(1); if (PG_NARGS() >= 3) rootdescend = PG_GETARG_BOOL(2); if (PG_NARGS() == 4) - checkunique = PG_GETARG_BOOL(3); + check_unique = PG_GETARG_BOOL(3); - bt_index_check_internal(indrelid, true, heapallindexed, rootdescend, checkunique); + bt_index_check_internal(indrelid, true, heapallindexed, rootdescend, check_unique); PG_RETURN_VOID(); } @@ -282,7 +282,7 @@ bt_index_parent_check(PG_FUNCTION_ARGS) */ static void bt_index_check_internal(Oid indrelid, bool parentcheck, bool heapallindexed, - bool rootdescend, bool checkunique) + bool rootdescend, bool check_unique) { Oid heapid; Relation indrel; @@ -394,7 +394,7 @@ bt_index_check_internal(Oid indrelid, bool parentcheck, bool heapallindexed, /* Check index, possibly against table it is an index on */ bt_check_every_level(indrel, heaprel, heapkeyspace, parentcheck, - heapallindexed, rootdescend, checkunique); + heapallindexed, rootdescend, check_unique); } /* Roll back any GUC changes executed by index functions */ @@ -496,7 +496,7 @@ btree_index_mainfork_expected(Relation rel) static void bt_check_every_level(Relation rel, Relation heaprel, bool heapkeyspace, bool readonly, bool heapallindexed, bool rootdescend, - bool checkunique) + bool check_unique) { BtreeCheckState *state; Page metapage; @@ -528,7 +528,7 @@ bt_check_every_level(Relation rel, Relation heaprel, bool heapkeyspace, state->readonly = readonly; state->heapallindexed = heapallindexed; state->rootdescend = rootdescend; - state->checkunique = checkunique; + state->check_unique = check_unique; state->snapshot = InvalidSnapshot; if (state->heapallindexed) @@ -592,7 +592,7 @@ bt_check_every_level(Relation rel, Relation heaprel, bool heapkeyspace, * performance take it once per index check. If snapshot already taken * reuse it. */ - if (state->checkunique) + if (state->check_unique) { state->indexinfo = BuildIndexInfo(state->rel); if (state->indexinfo->ii_Unique) @@ -1770,7 +1770,7 @@ bt_target_page_check(BtreeCheckState *state) * If the index is unique verify entries uniqueness by checking the * heap tuples visibility. */ - if (state->checkunique && state->indexinfo->ii_Unique && + if (state->check_unique && state->indexinfo->ii_Unique && P_ISLEAF(topaque) && !skey->anynullkeys && (BTreeTupleIsPosting(itup) || ItemPointerIsValid(lVis.tid))) { @@ -1778,7 +1778,7 @@ bt_target_page_check(BtreeCheckState *state) unique_checked = true; } - if (state->checkunique && state->indexinfo->ii_Unique && + if (state->check_unique && state->indexinfo->ii_Unique && P_ISLEAF(topaque) && OffsetNumberNext(offset) <= max) { /* Save current scankey tid */ @@ -1873,7 +1873,7 @@ bt_target_page_check(BtreeCheckState *state) * If index has unique constraint make sure that no more than one * found equal items is visible. */ - if (state->checkunique && state->indexinfo->ii_Unique && + if (state->check_unique && state->indexinfo->ii_Unique && rightkey && P_ISLEAF(topaque) && !P_RIGHTMOST(topaque)) { BlockNumber rightblock_number = topaque->btpo_next; diff --git a/doc/src/sgml/amcheck.sgml b/doc/src/sgml/amcheck.sgml index 3af065615b..3464ab5e76 100644 --- a/doc/src/sgml/amcheck.sgml +++ b/doc/src/sgml/amcheck.sgml @@ -61,7 +61,7 @@ - bt_index_check(index regclass, heapallindexed boolean, checkunique boolean) returns void + bt_index_check(index regclass, heapallindexed boolean, check_unique boolean) returns void bt_index_check @@ -118,7 +118,7 @@ ORDER BY c.relpages DESC LIMIT 10; that span child/parent relationships, but will verify the presence of all heap tuples as index tuples within the index when heapallindexed is - true. When checkunique + true. When check_unique is true bt_index_check will check that no more than one among duplicate entries in unique index is visible. When a routine, lightweight test for @@ -132,7 +132,7 @@ ORDER BY c.relpages DESC LIMIT 10; - bt_index_parent_check(index regclass, heapallindexed boolean, rootdescend boolean, checkunique boolean) returns void + bt_index_parent_check(index regclass, heapallindexed boolean, rootdescend boolean, check_unique boolean) returns void bt_index_parent_check @@ -145,7 +145,7 @@ ORDER BY c.relpages DESC LIMIT 10; Optionally, when the heapallindexed argument is true, the function verifies the presence of all heap tuples that should be found within the - index. When checkunique + index. When check_unique is true bt_index_parent_check will check that no more than one among duplicate entries in unique index is visible. When the optional rootdescend diff --git a/doc/src/sgml/ref/pg_amcheck.sgml b/doc/src/sgml/ref/pg_amcheck.sgml index 067c806b46..0837045632 100644 --- a/doc/src/sgml/ref/pg_amcheck.sgml +++ b/doc/src/sgml/ref/pg_amcheck.sgml @@ -434,12 +434,12 @@ PostgreSQL documentation - + For each index with unique constraint checked, verify that no more than one among duplicate entries is visible in the index using 's - option. + option. diff --git a/src/bin/pg_amcheck/pg_amcheck.c b/src/bin/pg_amcheck/pg_amcheck.c index 7e3101704d..3aaf69a3b4 100644 --- a/src/bin/pg_amcheck/pg_amcheck.c +++ b/src/bin/pg_amcheck/pg_amcheck.c @@ -102,7 +102,7 @@ typedef struct AmcheckOptions bool parent_check; bool rootdescend; bool heapallindexed; - bool checkunique; + bool check_unique; /* heap and btree hybrid option */ bool no_btree_expansion; @@ -133,7 +133,7 @@ static AmcheckOptions opts = { .parent_check = false, .rootdescend = false, .heapallindexed = false, - .checkunique = false, + .check_unique = false, .no_btree_expansion = false }; @@ -270,7 +270,7 @@ main(int argc, char *argv[]) {"heapallindexed", no_argument, NULL, 11}, {"parent-check", no_argument, NULL, 12}, {"install-missing", optional_argument, NULL, 13}, - {"checkunique", no_argument, NULL, 14}, + {"check-unique", no_argument, NULL, 14}, {NULL, 0, NULL, 0} }; @@ -439,7 +439,7 @@ main(int argc, char *argv[]) opts.install_schema = pg_strdup(optarg); break; case 14: - opts.checkunique = true; + opts.check_unique = true; break; default: /* getopt_long already emitted a complaint */ @@ -602,7 +602,7 @@ main(int argc, char *argv[]) * constraint check with warning if it is not yet supported by * amcheck. */ - if (opts.checkunique == true) + if (opts.check_unique == true) { /* * Now amcheck has only major and minor versions in the string but @@ -617,11 +617,11 @@ main(int argc, char *argv[]) sscanf(amcheck_version, "%d.%d.%d", &vmaj, &vmin, &vrev); /* - * checkunique option is supported in amcheck since version 1.4 + * check_unique option is supported in amcheck since version 1.4 */ if ((vmaj == 1 && vmin < 4) || vmaj == 0) { - pg_log_warning("--checkunique option is not supported by amcheck " + pg_log_warning("--check-unique option is not supported by amcheck " "version \"%s\"", amcheck_version); dat->is_checkunique = false; } @@ -895,7 +895,7 @@ prepare_btree_command(PQExpBuffer sql, RelationInfo *rel, PGconn *conn) rel->datinfo->amcheck_schema, (opts.heapallindexed ? "true" : "false"), (opts.rootdescend ? "true" : "false"), - (rel->datinfo->is_checkunique ? ", checkunique := true" : ""), + (rel->datinfo->is_checkunique ? ", check_unique := true" : ""), rel->reloid); else appendPQExpBuffer(sql, @@ -909,7 +909,7 @@ prepare_btree_command(PQExpBuffer sql, RelationInfo *rel, PGconn *conn) "AND i.indisready AND i.indisvalid AND i.indislive", rel->datinfo->amcheck_schema, (opts.heapallindexed ? "true" : "false"), - (rel->datinfo->is_checkunique ? ", checkunique := true" : ""), + (rel->datinfo->is_checkunique ? ", check_unique := true" : ""), rel->reloid); } @@ -1208,7 +1208,7 @@ help(const char *progname) printf(_(" --heapallindexed check that all heap tuples are found within indexes\n")); printf(_(" --parent-check check index parent/child relationships\n")); printf(_(" --rootdescend search from root page to refind tuples\n")); - printf(_(" --checkunique check unique constraint if index is unique\n")); + printf(_(" --check-unique check unique constraint if index is unique\n")); printf(_("\nConnection options:\n")); printf(_(" -h, --host=HOSTNAME database server host or socket directory\n")); printf(_(" -p, --port=PORT database server port\n")); diff --git a/src/bin/pg_amcheck/t/003_check.pl b/src/bin/pg_amcheck/t/003_check.pl index 4b16bda6a4..0a8cf8bced 100644 --- a/src/bin/pg_amcheck/t/003_check.pl +++ b/src/bin/pg_amcheck/t/003_check.pl @@ -523,35 +523,35 @@ $node->command_checks_all( $node->command_checks_all( [ @cmd, '-s', 's1', '-i', 't1_btree', '--parent-check', - '--checkunique', 'db1' + '--check-unique', 'db1' ], 2, [$index_missing_relation_fork_re], [$no_output_re], - 'pg_amcheck smoke test --parent-check --checkunique'); + 'pg_amcheck smoke test --parent-check --check-unique'); $node->command_checks_all( [ @cmd, '-s', 's1', '-i', 't1_btree', '--heapallindexed', - '--rootdescend', '--checkunique', 'db1' + '--rootdescend', '--check-unique', 'db1' ], 2, [$index_missing_relation_fork_re], [$no_output_re], - 'pg_amcheck smoke test --heapallindexed --rootdescend --checkunique'); + 'pg_amcheck smoke test --heapallindexed --rootdescend --check-unique'); $node->command_checks_all( [ - @cmd, '--checkunique', '-d', 'db1', '-d', 'db2', + @cmd, '--check-unique', '-d', 'db1', '-d', 'db2', '-d', 'db3', '-S', 's*' ], 0, [$no_output_re], [$no_output_re], - 'pg_amcheck excluding all corrupt schemas with --checkunique option'); + 'pg_amcheck excluding all corrupt schemas with --check-unique option'); # -# Smoke test for checkunique option for not supported versions. +# Smoke test for check-unique option for not supported versions. # $node->safe_psql( 'db3', q( @@ -560,11 +560,11 @@ $node->safe_psql( )); $node->command_checks_all( - [ @cmd, '--checkunique', 'db3' ], + [ @cmd, '--check-unique', 'db3' ], 0, [$no_output_re], [ - qr/pg_amcheck: warning: --checkunique option is not supported by amcheck version "1.3"/ + qr/pg_amcheck: warning: --check-unique option is not supported by amcheck version "1.3"/ ], - 'pg_amcheck smoke test --checkunique'); + 'pg_amcheck smoke test --check-unique'); done_testing(); diff --git a/src/bin/pg_amcheck/t/005_opclass_damage.pl b/src/bin/pg_amcheck/t/005_opclass_damage.pl index 1eea215227..0db58dee5b 100644 --- a/src/bin/pg_amcheck/t/005_opclass_damage.pl +++ b/src/bin/pg_amcheck/t/005_opclass_damage.pl @@ -90,7 +90,7 @@ $node->safe_psql( # We should get no corruptions $node->command_like( - [ 'pg_amcheck', '--checkunique', '-p', $node->port, 'postgres' ], + [ 'pg_amcheck', '--check-unique', '-p', $node->port, 'postgres' ], qr/^$/, 'pg_amcheck all schemas, tables and indexes reports no corruption'); @@ -116,7 +116,7 @@ $node->safe_psql( # Unique index corruption should now be reported $node->command_checks_all( - [ 'pg_amcheck', '--checkunique', '-p', $node->port, 'postgres' ], + [ 'pg_amcheck', '--check-unique', '-p', $node->port, 'postgres' ], 2, [qr/index uniqueness is violated for index "bttest_unique_idx"/], [], -- 2.34.1