From 0e83e71504a6e637eeca9997a33306d531d1770f Mon Sep 17 00:00:00 2001 From: Ankit Mittal Date: Thu, 17 Nov 2022 12:40:03 -0500 Subject: [PATCH 1/7] Add a where clause --- bin/pg_repack.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 5bcee125..69f2b0b6 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -944,7 +944,13 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize) /* Craft Copy SQL */ initStringInfo(©_sql); appendStringInfoString(©_sql, table.copy_data); - if (!orderby) + + /* soft delete recognition */ + appendStringInfoString(©_sql, " WHERE "); + appendStringInfoString(©_sql, "deleted_at IS NULL"); +// table.create_table = sql.data; + + if (!orderby) { if (ckey != NULL) From 80eea4bfbf11dcd8ea082b2487aeab4db3a2430c Mon Sep 17 00:00:00 2001 From: Ankit <573824+ankitml@users.noreply.github.com> Date: Thu, 17 Nov 2022 12:43:39 -0500 Subject: [PATCH 2/7] Update pg_repack.c --- bin/pg_repack.c | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 69f2b0b6..e92f47ac 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -948,7 +948,6 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize) /* soft delete recognition */ appendStringInfoString(©_sql, " WHERE "); appendStringInfoString(©_sql, "deleted_at IS NULL"); -// table.create_table = sql.data; if (!orderby) From 5406f2f2fba5e4867b9849144c0d16bed00a8fa5 Mon Sep 17 00:00:00 2001 From: Ankit Mittal Date: Thu, 17 Nov 2022 12:57:37 -0500 Subject: [PATCH 3/7] variable --- bin/pg_repack.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 69f2b0b6..a3cd854d 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -213,9 +213,9 @@ static bool is_superuser(void); static void check_tablespace(void); static bool preliminary_checks(char *errbuf, size_t errsize); static bool is_requested_relation_exists(char *errbuf, size_t errsize); -static void repack_all_databases(const char *order_by); -static bool repack_one_database(const char *order_by, char *errbuf, size_t errsize); -static void repack_one_table(repack_table *table, const char *order_by); +static void repack_all_databases(const char *order_by, const char *where_clause); +static bool repack_one_database(const char *order_by, char *errbuf, size_t errsize, const char *where_clause); +static void repack_one_table(repack_table *table, const char *order_by, const char *where_clause); static bool repack_table_indexes(PGresult *index_details); static bool repack_all_indexes(char *errbuf, size_t errsize); static void repack_cleanup(bool fatal, const repack_table *table); @@ -245,6 +245,7 @@ static SimpleStringList parent_table_list = {NULL, NULL}; static SimpleStringList table_list = {NULL, NULL}; static SimpleStringList schema_list = {NULL, NULL}; static char *orderby = NULL; +static char *where_clause = NULL; static char *tablespace = NULL; static bool moveidx = false; static SimpleStringList r_index = {NULL, NULL}; @@ -274,6 +275,7 @@ static pgut_option options[] = { 'l', 'c', "schema", &schema_list }, { 'b', 'n', "no-order", &noorder }, { 'b', 'N', "dry-run", &dryrun }, + { 's', 'w', "where-clause", &where_clause }, { 's', 'o', "order-by", &orderby }, { 's', 's', "tablespace", &tablespace }, { 'b', 'S', "moveidx", &moveidx }, @@ -381,11 +383,11 @@ main(int argc, char *argv[]) ereport(ERROR, (errcode(EINVAL), errmsg("cannot repack specific schema(s) in all databases"))); - repack_all_databases(orderby); + repack_all_databases(orderby, where_clause); } else { - if (!repack_one_database(orderby, errbuf, sizeof(errbuf))) + if (!repack_one_database(orderby, errbuf, sizeof(errbuf)), where_clause) ereport(ERROR, (errcode(ERROR), errmsg("%s failed with error: %s", PROGRAM_NAME, errbuf))); } @@ -675,7 +677,7 @@ is_requested_relation_exists(char *errbuf, size_t errsize){ * Call repack_one_database for each database. */ static void -repack_all_databases(const char *orderby) +repack_all_databases(const char *orderby, const char *where_clause) { PGresult *result; int i; @@ -699,7 +701,7 @@ repack_all_databases(const char *orderby) elog(INFO, "repacking database \"%s\"", dbname); if (!dryrun) { - ret = repack_one_database(orderby, errbuf, sizeof(errbuf)); + ret = repack_one_database(orderby, errbuf, sizeof(errbuf), where_clause); if (!ret) elog(INFO, "database \"%s\" skipped: %s", dbname, errbuf); } @@ -731,7 +733,7 @@ getoid(PGresult *res, int row, int col) * Call repack_one_table for the target tables or each table in a database. */ static bool -repack_one_database(const char *orderby, char *errbuf, size_t errsize) +repack_one_database(const char *orderby, char *errbuf, size_t errsize, const char *where_clause) { bool ret = false; PGresult *res = NULL; From 2a50665d5f91189b3f3ca3f917d0121f8219bbd2 Mon Sep 17 00:00:00 2001 From: Ankit Mittal Date: Thu, 17 Nov 2022 13:36:22 -0500 Subject: [PATCH 4/7] it compiles --- bin/pg_repack.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 01b3ddb4..f92e4ce7 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -215,7 +215,7 @@ static bool preliminary_checks(char *errbuf, size_t errsize); static bool is_requested_relation_exists(char *errbuf, size_t errsize); static void repack_all_databases(const char *order_by, const char *where_clause); static bool repack_one_database(const char *order_by, char *errbuf, size_t errsize, const char *where_clause); -static void repack_one_table(repack_table *table, const char *order_by, const char *where_clause); +static void repack_one_table(repack_table *table, const char *order_by); static bool repack_table_indexes(PGresult *index_details); static bool repack_all_indexes(char *errbuf, size_t errsize); static void repack_cleanup(bool fatal, const repack_table *table); @@ -387,7 +387,7 @@ main(int argc, char *argv[]) } else { - if (!repack_one_database(orderby, errbuf, sizeof(errbuf)), where_clause) + if (!repack_one_database(orderby, errbuf, sizeof(errbuf), where_clause)) ereport(ERROR, (errcode(ERROR), errmsg("%s failed with error: %s", PROGRAM_NAME, errbuf))); } From 175ae198c8e057b6c271a04bdd175925cad7a356 Mon Sep 17 00:00:00 2001 From: Ankit Mittal Date: Fri, 18 Nov 2022 12:59:20 -0500 Subject: [PATCH 5/7] updated --- bin/pg_repack.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index f92e4ce7..a6af00c5 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -948,11 +948,11 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize, const cha appendStringInfoString(©_sql, table.copy_data); /* soft delete recognition */ - appendStringInfoString(©_sql, " WHERE "); - appendStringInfoString(©_sql, "deleted_at IS NULL"); - + if (where_clause) { + appendStringInfoString(©_sql, " WHERE "); + appendStringInfoString(©_sql, where_clause); + } if (!orderby) - { if (ckey != NULL) { From d0c6bf6b5f5a745bb5301061c881c59d3d111e00 Mon Sep 17 00:00:00 2001 From: Ankit Mittal Date: Tue, 22 Nov 2022 16:51:08 -0500 Subject: [PATCH 6/7] changed the flag --- bin/.idea/workspace.xml | 320 ++++++++++++++++++++++++++++++++++++++++ bin/pg_repack.c | 2 +- 2 files changed, 321 insertions(+), 1 deletion(-) create mode 100644 bin/.idea/workspace.xml diff --git a/bin/.idea/workspace.xml b/bin/.idea/workspace.xml new file mode 100644 index 00000000..18ccf134 --- /dev/null +++ b/bin/.idea/workspace.xml @@ -0,0 +1,320 @@ + + + + + { + "useNewFormat": true +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "RunOnceActivity.cidr.known.project.marker": "true", + "WebServerToolWindowFactoryState": "false", + "cf.first.check.clang-format": "false", + "cidr.known.project.marker": "true", + "last_opened_file_path": "/Users/ankitmittal/Documents/repos/pg_repack/bin", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)" + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1668703520542 + + + + + + + + + \ No newline at end of file diff --git a/bin/pg_repack.c b/bin/pg_repack.c index a6af00c5..4f6f4cd1 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -275,7 +275,7 @@ static pgut_option options[] = { 'l', 'c', "schema", &schema_list }, { 'b', 'n', "no-order", &noorder }, { 'b', 'N', "dry-run", &dryrun }, - { 's', 'w', "where-clause", &where_clause }, + { 's', 'X', "where-clause", &where_clause }, { 's', 'o', "order-by", &orderby }, { 's', 's', "tablespace", &tablespace }, { 'b', 'S', "moveidx", &moveidx }, From 89dfa96a348db47b3cbd4cca95484c047d1c0ccd Mon Sep 17 00:00:00 2001 From: Ankit <573824+ankitml@users.noreply.github.com> Date: Mon, 1 May 2023 15:49:16 -0400 Subject: [PATCH 7/7] Delete workspace.xml --- bin/.idea/workspace.xml | 320 ---------------------------------------- 1 file changed, 320 deletions(-) delete mode 100644 bin/.idea/workspace.xml diff --git a/bin/.idea/workspace.xml b/bin/.idea/workspace.xml deleted file mode 100644 index 18ccf134..00000000 --- a/bin/.idea/workspace.xml +++ /dev/null @@ -1,320 +0,0 @@ - - - - - { - "useNewFormat": true -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - { - "keyToString": { - "RunOnceActivity.OpenProjectViewOnStart": "true", - "RunOnceActivity.ShowReadmeOnStart": "true", - "RunOnceActivity.cidr.known.project.marker": "true", - "WebServerToolWindowFactoryState": "false", - "cf.first.check.clang-format": "false", - "cidr.known.project.marker": "true", - "last_opened_file_path": "/Users/ankitmittal/Documents/repos/pg_repack/bin", - "node.js.detected.package.eslint": "true", - "node.js.detected.package.tslint": "true", - "node.js.selected.package.eslint": "(autodetect)", - "node.js.selected.package.tslint": "(autodetect)" - } -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1668703520542 - - - - - - - - - \ No newline at end of file