From 113c198dfaceabdf1ffd377b991791a491249cbe Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Mon, 9 Sep 2024 06:47:32 +0000 Subject: [PATCH 01/25] Pick correct collation for Const Node Signed-off-by: Shameem Ahmed --- src/backend/parser/parse_type.c | 2 +- src/backend/utils/adt/like_support.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/parser/parse_type.c b/src/backend/parser/parse_type.c index 51645b6d0f0..83b44d617b9 100644 --- a/src/backend/parser/parse_type.c +++ b/src/backend/parser/parse_type.c @@ -656,7 +656,7 @@ typeTypeCollation(Type typ) if (handle_default_collation_hook) { - return (*handle_default_collation_hook)(typ, false); + return (*handle_default_collation_hook)(typ, true); } return typtup->typcollation; diff --git a/src/backend/utils/adt/like_support.c b/src/backend/utils/adt/like_support.c index 5fc6b3801e0..0461398f3e9 100644 --- a/src/backend/utils/adt/like_support.c +++ b/src/backend/utils/adt/like_support.c @@ -1771,7 +1771,7 @@ string_to_const(const char *str, Oid datatype) case TEXTOID: case VARCHAROID: case BPCHAROID: - collation = DEFAULT_COLLATION_OID; + collation = CLUSTER_COLLATION_OID(); constlen = -1; break; From 88ef54852fb1bccd9f26366eb30722eb0d448c39 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Tue, 10 Sep 2024 08:50:02 +0000 Subject: [PATCH 02/25] Update logic for dump restore Signed-off-by: Shameem Ahmed --- src/backend/parser/parse_collate.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/backend/parser/parse_collate.c b/src/backend/parser/parse_collate.c index 57c9cd88773..44e67c864ec 100644 --- a/src/backend/parser/parse_collate.c +++ b/src/backend/parser/parse_collate.c @@ -47,6 +47,7 @@ #include "parser/parse_collate.h" #include "parser/parser.h" /* only needed for GUC variables */ #include "utils/lsyscache.h" +#include "utils/guc.h" /* @@ -91,6 +92,8 @@ static void assign_hypothetical_collations(Aggref *aggref, avoid_collation_override_hook_type avoid_collation_override_hook = NULL; +static bool is_bbf_dump_restore = false; + /* * assign_query_collations() * Mark all expressions in the given Query with collation information. @@ -102,6 +105,10 @@ avoid_collation_override_hook_type avoid_collation_override_hook = NULL; void assign_query_collations(ParseState *pstate, Query *query) { + const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); + if (dump_restore && strcmp(dump_restore, "on") == 0) + is_bbf_dump_restore = true; + /* * We just use query_tree_walker() to visit all the contained expressions. * We can skip the rangetable and CTE subqueries, though, since RTEs and @@ -113,6 +120,8 @@ assign_query_collations(ParseState *pstate, Query *query) (void *) pstate, QTW_IGNORE_RANGE_TABLE | QTW_IGNORE_CTE_SUBQUERIES); + + is_bbf_dump_restore = false; } /* @@ -831,7 +840,7 @@ merge_collation_state(Oid collation, /* * Non-default implicit collation always beats default. */ - if (context->collation == CLUSTER_COLLATION_OID()) + if (context->collation == CLUSTER_COLLATION_OID() || is_bbf_dump_restore) { /* Override previous parent state */ context->collation = collation; From e9edf7fe27bfeeefb9ded5fb8294f143166d8f79 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Tue, 10 Sep 2024 08:54:45 +0000 Subject: [PATCH 03/25] Rerun tests From ccc1b67c9d18da9d8618d9b3e45e45c4607cb0da Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Tue, 10 Sep 2024 08:56:45 +0000 Subject: [PATCH 04/25] Fix build failure Signed-off-by: Shameem Ahmed --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 71ed5dccb29..ef9bac17196 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: clone-repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: install-dependencies run: | sudo apt update --fix-missing -y @@ -24,13 +24,13 @@ jobs: make check-world - name: upload-test-summary if: failure() - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: regression-summary path: src/test/regress/regression.out - name: upload-test-differences if: failure() - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: regression-differences path: src/test/regress/regression.diffs From f2dec323522fa2e0dd30541a1a3dd45b81bf5225 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Tue, 10 Sep 2024 09:19:41 +0000 Subject: [PATCH 05/25] Minor fix Signed-off-by: Shameem Ahmed --- src/backend/parser/parse_collate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/parser/parse_collate.c b/src/backend/parser/parse_collate.c index 44e67c864ec..fe3090b1873 100644 --- a/src/backend/parser/parse_collate.c +++ b/src/backend/parser/parse_collate.c @@ -866,7 +866,7 @@ merge_collation_state(Oid collation, /* We're still conflicted ... */ break; case COLLATE_EXPLICIT: - if (collation != context->collation) + if (collation != context->collation && !is_bbf_dump_restore) { /* * Oops, we have a conflict of explicit COLLATE clauses. From 5c5d89b825c0487316171b954a2222620ebfda2a Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Tue, 10 Sep 2024 09:53:44 +0000 Subject: [PATCH 06/25] Fix failures Signed-off-by: Shameem Ahmed --- src/backend/parser/parse_collate.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/backend/parser/parse_collate.c b/src/backend/parser/parse_collate.c index fe3090b1873..30310e9a29a 100644 --- a/src/backend/parser/parse_collate.c +++ b/src/backend/parser/parse_collate.c @@ -92,8 +92,6 @@ static void assign_hypothetical_collations(Aggref *aggref, avoid_collation_override_hook_type avoid_collation_override_hook = NULL; -static bool is_bbf_dump_restore = false; - /* * assign_query_collations() * Mark all expressions in the given Query with collation information. @@ -105,10 +103,6 @@ static bool is_bbf_dump_restore = false; void assign_query_collations(ParseState *pstate, Query *query) { - const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); - if (dump_restore && strcmp(dump_restore, "on") == 0) - is_bbf_dump_restore = true; - /* * We just use query_tree_walker() to visit all the contained expressions. * We can skip the rangetable and CTE subqueries, though, since RTEs and @@ -120,8 +114,6 @@ assign_query_collations(ParseState *pstate, Query *query) (void *) pstate, QTW_IGNORE_RANGE_TABLE | QTW_IGNORE_CTE_SUBQUERIES); - - is_bbf_dump_restore = false; } /* @@ -808,6 +800,7 @@ merge_collation_state(Oid collation, int location2, assign_collations_context *context) { + const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); /* * If the collation strength for this node is different from what's * already in *context, then this node either dominates or is dominated by @@ -840,7 +833,7 @@ merge_collation_state(Oid collation, /* * Non-default implicit collation always beats default. */ - if (context->collation == CLUSTER_COLLATION_OID() || is_bbf_dump_restore) + if (context->collation == CLUSTER_COLLATION_OID() || (dump_restore && strcmp(dump_restore, "on") == 0)) { /* Override previous parent state */ context->collation = collation; @@ -866,7 +859,7 @@ merge_collation_state(Oid collation, /* We're still conflicted ... */ break; case COLLATE_EXPLICIT: - if (collation != context->collation && !is_bbf_dump_restore) + if ((collation != context->collation) && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0))) { /* * Oops, we have a conflict of explicit COLLATE clauses. From 20937d19b8d828c5f07d80fc0927a2a354947986 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Wed, 11 Sep 2024 04:55:19 +0000 Subject: [PATCH 07/25] Remove redundant changes Signed-off-by: Shameem Ahmed --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ef9bac17196..2cc605420e9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: clone-repository - uses: actions/checkout@v4 + uses: actions/checkout@v2 - name: install-dependencies run: | sudo apt update --fix-missing -y From 592024e19186e892b73cc0095acab04d03085529 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Tue, 24 Sep 2024 06:30:06 +0000 Subject: [PATCH 08/25] Update logic Signed-off-by: Shameem Ahmed --- src/backend/parser/parse_collate.c | 38 +++++++++++++++++++----------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/backend/parser/parse_collate.c b/src/backend/parser/parse_collate.c index 30310e9a29a..c8dfa775cbc 100644 --- a/src/backend/parser/parse_collate.c +++ b/src/backend/parser/parse_collate.c @@ -833,7 +833,7 @@ merge_collation_state(Oid collation, /* * Non-default implicit collation always beats default. */ - if (context->collation == CLUSTER_COLLATION_OID() || (dump_restore && strcmp(dump_restore, "on") == 0)) + if (context->collation == CLUSTER_COLLATION_OID()) { /* Override previous parent state */ context->collation = collation; @@ -859,20 +859,30 @@ merge_collation_state(Oid collation, /* We're still conflicted ... */ break; case COLLATE_EXPLICIT: - if ((collation != context->collation) && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0))) + if ((collation != context->collation)) { - /* - * Oops, we have a conflict of explicit COLLATE clauses. - * Here we choose to throw error immediately; that is what - * the SQL standard says to do, and there's no good reason - * to be less strict. - */ - ereport(ERROR, - (errcode(ERRCODE_COLLATION_MISMATCH), - errmsg("collation mismatch between explicit collations \"%s\" and \"%s\"", - get_collation_name(context->collation), - get_collation_name(collation)), - parser_errposition(context->pstate, location))); + if (dump_restore && strcmp(dump_restore, "on") == 0) + { + context->collation = collation; + context->strength = strength; + context->location = location; + break; + } + else + { + /* + * Oops, we have a conflict of explicit COLLATE clauses. + * Here we choose to throw error immediately; that is what + * the SQL standard says to do, and there's no good reason + * to be less strict. + */ + ereport(ERROR, + (errcode(ERRCODE_COLLATION_MISMATCH), + errmsg("collation mismatch between explicit collations \"%s\" and \"%s\"", + get_collation_name(context->collation), + get_collation_name(collation)), + parser_errposition(context->pstate, location))); + } } break; } From 5fd91e645aa1239cc03115bfd5ec7f14aa9f376f Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Tue, 24 Sep 2024 10:04:46 +0000 Subject: [PATCH 09/25] Update logic for computed columns for babelfish objects Signed-off-by: Shameem Ahmed --- src/bin/pg_dump/pg_dump.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 2ff77304477..d298cdd7d01 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15851,8 +15851,12 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) if (print_default) { if (tbinfo->attgenerated[j] == ATTRIBUTE_GENERATED_STORED) - appendPQExpBuffer(q, " GENERATED ALWAYS AS (%s) STORED", - tbinfo->attrdefs[j]->adef_expr); + { + size_t len = strlen(tbinfo->attrdefs[j]->adef_expr); + if (!isBabelfishDatabase(fout) || (isBabelfishDatabase(fout) && tbinfo->attrdefs[j]->adef_expr[0] != '(' && tbinfo->attrdefs[j]->adef_expr[len-1] != ')')) + appendPQExpBuffer(q, " GENERATED ALWAYS AS (%s) STORED", + tbinfo->attrdefs[j]->adef_expr); + } else appendPQExpBuffer(q, " DEFAULT %s", tbinfo->attrdefs[j]->adef_expr); From 5dae2a5b8b0312ae28e07f2ccc7a6c489b4ba75e Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Tue, 24 Sep 2024 10:30:22 +0000 Subject: [PATCH 10/25] Update logic for computed columns for babelfish objects 2 Signed-off-by: Shameem Ahmed --- src/bin/pg_dump/pg_dump.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index d298cdd7d01..984a0d024f7 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15853,7 +15853,10 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) if (tbinfo->attgenerated[j] == ATTRIBUTE_GENERATED_STORED) { size_t len = strlen(tbinfo->attrdefs[j]->adef_expr); - if (!isBabelfishDatabase(fout) || (isBabelfishDatabase(fout) && tbinfo->attrdefs[j]->adef_expr[0] != '(' && tbinfo->attrdefs[j]->adef_expr[len-1] != ')')) + if(isBabelfishDatabase(fout) && tbinfo->attrdefs[j]->adef_expr[0] != '(' && tbinfo->attrdefs[j]->adef_expr[len-1] != ')') + appendPQExpBuffer(q, " GENERATED ALWAYS AS %s STORED", + tbinfo->attrdefs[j]->adef_expr); + else appendPQExpBuffer(q, " GENERATED ALWAYS AS (%s) STORED", tbinfo->attrdefs[j]->adef_expr); } From 87dcb04da48e4efb2f6420500dd68c0582456334 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Tue, 24 Sep 2024 11:31:05 +0000 Subject: [PATCH 11/25] Update logic for computed columns for babelfish objects 3 Signed-off-by: Shameem Ahmed --- src/bin/pg_dump/pg_dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 984a0d024f7..4add4c8e9cf 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15853,7 +15853,7 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) if (tbinfo->attgenerated[j] == ATTRIBUTE_GENERATED_STORED) { size_t len = strlen(tbinfo->attrdefs[j]->adef_expr); - if(isBabelfishDatabase(fout) && tbinfo->attrdefs[j]->adef_expr[0] != '(' && tbinfo->attrdefs[j]->adef_expr[len-1] != ')') + if(isBabelfishDatabase(fout) && tbinfo->attrdefs[j]->adef_expr[0] == '(' && tbinfo->attrdefs[j]->adef_expr[len-1] == ')') appendPQExpBuffer(q, " GENERATED ALWAYS AS %s STORED", tbinfo->attrdefs[j]->adef_expr); else From b1040d0df70d02bce5b9518bee4e3d84cd789872 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Tue, 24 Sep 2024 13:32:27 +0000 Subject: [PATCH 12/25] Update logic for computed columns for babelfish objects 4 Signed-off-by: Shameem Ahmed --- src/bin/pg_dump/dump_babel_utils.c | 44 ++++++++++++++++++++++++++++++ src/bin/pg_dump/dump_babel_utils.h | 1 + src/bin/pg_dump/pg_dump.c | 3 +- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/bin/pg_dump/dump_babel_utils.c b/src/bin/pg_dump/dump_babel_utils.c index 9d0a1968f3f..c3e7fdb9dc5 100644 --- a/src/bin/pg_dump/dump_babel_utils.c +++ b/src/bin/pg_dump/dump_babel_utils.c @@ -519,6 +519,50 @@ fixTsqlDefaultExpr(Archive *fout, AttrDefInfo *attrDefInfo) attrDefInfo->adef_expr = psprintf("(sys.%s(%s::text))::integer", runtimeErrFunc, runtimeErrStr); } +bool +fixComputedColumnParenthesis(Archive *fout, char *decompiled_string) +{ + int len = strlen(decompiled_string); + bool hasParentheses = false; + int balance = 0; + + if(!isBabelfishDatabase(fout)) + return false; + + for (int i = 0; i < len; i++) + { + if (decompiled_string[i] == '(' || decompiled_string[i] == ')') + { + hasParentheses = true; + break; + } + } + + if (!hasParentheses) + return true; + + // If the string is too short to be enclosed, return false + if (len < 2 || decompiled_string[0] != '(' || decompiled_string[len - 1] != ')') + return false; + + // Loop through the string (excluding the outermost parentheses) + for (int i = 1; i < len - 1; i++) + { + if (decompiled_string[i] == '(') + balance++; + else if (decompiled_string[i] == ')') + { + balance--; + // If balance goes negative, it means we have unmatched ')' + if (balance < 0) + return false; + } + } + + // If the balance is zero at the end, parentheses are balanced + return (balance == 0); +} + /* * fixTsqlTableTypeDependency: * Fixes following two types of dependency issues between T-SQL diff --git a/src/bin/pg_dump/dump_babel_utils.h b/src/bin/pg_dump/dump_babel_utils.h index 943d353e0ec..ec0bfc1353f 100644 --- a/src/bin/pg_dump/dump_babel_utils.h +++ b/src/bin/pg_dump/dump_babel_utils.h @@ -56,5 +56,6 @@ extern void babelfishDumpOpclassHelper(Archive *fout, const OpclassInfo *opcinfo extern bool bbfShouldDumpIndex(Archive *fout, const IndxInfo *indxinfo); extern void dumpBabelfishConstrIndex(Archive *fout, const IndxInfo *indxinfo, PQExpBuffer q, PQExpBuffer delq); +extern bool fixComputedColumnParenthesis(Archive *fout, char *decompiled_string); #endif diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 4add4c8e9cf..352cb60b675 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15852,8 +15852,7 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) { if (tbinfo->attgenerated[j] == ATTRIBUTE_GENERATED_STORED) { - size_t len = strlen(tbinfo->attrdefs[j]->adef_expr); - if(isBabelfishDatabase(fout) && tbinfo->attrdefs[j]->adef_expr[0] == '(' && tbinfo->attrdefs[j]->adef_expr[len-1] == ')') + if(fixComputedColumnParenthesis(fout, tbinfo->attrdefs[j]->adef_expr)) appendPQExpBuffer(q, " GENERATED ALWAYS AS %s STORED", tbinfo->attrdefs[j]->adef_expr); else From 51b5cd1a58ffba9df196b1fbb54e33b9e3803401 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Tue, 24 Sep 2024 14:23:17 +0000 Subject: [PATCH 13/25] Update logic for computed columns for babelfish objects 5 Signed-off-by: Shameem Ahmed --- src/bin/pg_dump/dump_babel_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/pg_dump/dump_babel_utils.c b/src/bin/pg_dump/dump_babel_utils.c index c3e7fdb9dc5..66d672b834e 100644 --- a/src/bin/pg_dump/dump_babel_utils.c +++ b/src/bin/pg_dump/dump_babel_utils.c @@ -539,7 +539,7 @@ fixComputedColumnParenthesis(Archive *fout, char *decompiled_string) } if (!hasParentheses) - return true; + return false; // If the string is too short to be enclosed, return false if (len < 2 || decompiled_string[0] != '(' || decompiled_string[len - 1] != ')') From d0549c8ece57df17726aa599fdd9f9f5259d955a Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Tue, 24 Sep 2024 17:07:01 +0000 Subject: [PATCH 14/25] Update logic for computed columns for babelfish objects 6 (may need to revert) Signed-off-by: Shameem Ahmed --- src/bin/pg_dump/dump_babel_utils.c | 36 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/bin/pg_dump/dump_babel_utils.c b/src/bin/pg_dump/dump_babel_utils.c index e14b0ada6c3..678c495cfaa 100644 --- a/src/bin/pg_dump/dump_babel_utils.c +++ b/src/bin/pg_dump/dump_babel_utils.c @@ -545,10 +545,12 @@ fixComputedColumnParenthesis(Archive *fout, char *decompiled_string) int len = strlen(decompiled_string); bool hasParentheses = false; int balance = 0; + int openParens = 0; // Count of valid outermost opening parentheses - if(!isBabelfishDatabase(fout)) + if (!isBabelfishDatabase(fout)) return false; + // Check if the string has parentheses for (int i = 0; i < len; i++) { if (decompiled_string[i] == '(' || decompiled_string[i] == ')') @@ -558,29 +560,33 @@ fixComputedColumnParenthesis(Archive *fout, char *decompiled_string) } } - if (!hasParentheses) + if (!hasParentheses) return false; // If the string is too short to be enclosed, return false if (len < 2 || decompiled_string[0] != '(' || decompiled_string[len - 1] != ')') return false; - // Loop through the string (excluding the outermost parentheses) - for (int i = 1; i < len - 1; i++) + // Count how many layers of enclosing parentheses are present + int start = 0, end = len - 1; + + while (start < end && decompiled_string[start] == '(' && decompiled_string[end] == ')') { - if (decompiled_string[i] == '(') - balance++; - else if (decompiled_string[i] == ')') - { - balance--; - // If balance goes negative, it means we have unmatched ')' - if (balance < 0) - return false; - } + openParens++; + start++; + end--; + } + + // If there is more than one layer of enclosing parentheses + if (openParens > 1) + { + // Shift the string inward to remove all but one outer layer of parentheses + memmove(decompiled_string, decompiled_string + openParens - 1, len - 2 * (openParens - 1)); + decompiled_string[len - 2 * (openParens - 1)] = '\0'; // Properly terminate the string + return true; } - // If the balance is zero at the end, parentheses are balanced - return (balance == 0); + return false; // No changes made if only one or zero layers of parentheses } /* From 90cba8ef651aad7f67b38239bf38692ae7307a25 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Tue, 24 Sep 2024 17:31:45 +0000 Subject: [PATCH 15/25] Update logic for computed columns for babelfish objects 6 (may need to revert) 2 Signed-off-by: Shameem Ahmed --- src/bin/pg_dump/dump_babel_utils.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/bin/pg_dump/dump_babel_utils.c b/src/bin/pg_dump/dump_babel_utils.c index 678c495cfaa..6d9ce26c2b5 100644 --- a/src/bin/pg_dump/dump_babel_utils.c +++ b/src/bin/pg_dump/dump_babel_utils.c @@ -544,8 +544,9 @@ fixComputedColumnParenthesis(Archive *fout, char *decompiled_string) { int len = strlen(decompiled_string); bool hasParentheses = false; - int balance = 0; int openParens = 0; // Count of valid outermost opening parentheses + // Count how many layers of enclosing parentheses are present + int start = 0, end = len - 1; if (!isBabelfishDatabase(fout)) return false; @@ -567,9 +568,6 @@ fixComputedColumnParenthesis(Archive *fout, char *decompiled_string) if (len < 2 || decompiled_string[0] != '(' || decompiled_string[len - 1] != ')') return false; - // Count how many layers of enclosing parentheses are present - int start = 0, end = len - 1; - while (start < end && decompiled_string[start] == '(' && decompiled_string[end] == ')') { openParens++; From 9b967abd83e449288c63ed4c4d776c008359e02b Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Wed, 25 Sep 2024 10:38:47 +0000 Subject: [PATCH 16/25] Remove unnecessary changes Signed-off-by: Shameem Ahmed --- src/bin/pg_dump/dump_babel_utils.c | 48 ------------------------------ src/bin/pg_dump/dump_babel_utils.h | 1 - src/bin/pg_dump/pg_dump.c | 2 +- 3 files changed, 1 insertion(+), 50 deletions(-) diff --git a/src/bin/pg_dump/dump_babel_utils.c b/src/bin/pg_dump/dump_babel_utils.c index 6d9ce26c2b5..0a94582d9c1 100644 --- a/src/bin/pg_dump/dump_babel_utils.c +++ b/src/bin/pg_dump/dump_babel_utils.c @@ -539,54 +539,6 @@ fixTsqlDefaultExpr(Archive *fout, AttrDefInfo *attrDefInfo) attrDefInfo->adef_expr = psprintf("(sys.%s(%s::text))::integer", runtimeErrFunc, runtimeErrStr); } -bool -fixComputedColumnParenthesis(Archive *fout, char *decompiled_string) -{ - int len = strlen(decompiled_string); - bool hasParentheses = false; - int openParens = 0; // Count of valid outermost opening parentheses - // Count how many layers of enclosing parentheses are present - int start = 0, end = len - 1; - - if (!isBabelfishDatabase(fout)) - return false; - - // Check if the string has parentheses - for (int i = 0; i < len; i++) - { - if (decompiled_string[i] == '(' || decompiled_string[i] == ')') - { - hasParentheses = true; - break; - } - } - - if (!hasParentheses) - return false; - - // If the string is too short to be enclosed, return false - if (len < 2 || decompiled_string[0] != '(' || decompiled_string[len - 1] != ')') - return false; - - while (start < end && decompiled_string[start] == '(' && decompiled_string[end] == ')') - { - openParens++; - start++; - end--; - } - - // If there is more than one layer of enclosing parentheses - if (openParens > 1) - { - // Shift the string inward to remove all but one outer layer of parentheses - memmove(decompiled_string, decompiled_string + openParens - 1, len - 2 * (openParens - 1)); - decompiled_string[len - 2 * (openParens - 1)] = '\0'; // Properly terminate the string - return true; - } - - return false; // No changes made if only one or zero layers of parentheses -} - /* * fixTsqlTableTypeDependency: * Fixes following two types of dependency issues between T-SQL diff --git a/src/bin/pg_dump/dump_babel_utils.h b/src/bin/pg_dump/dump_babel_utils.h index ec0bfc1353f..943d353e0ec 100644 --- a/src/bin/pg_dump/dump_babel_utils.h +++ b/src/bin/pg_dump/dump_babel_utils.h @@ -56,6 +56,5 @@ extern void babelfishDumpOpclassHelper(Archive *fout, const OpclassInfo *opcinfo extern bool bbfShouldDumpIndex(Archive *fout, const IndxInfo *indxinfo); extern void dumpBabelfishConstrIndex(Archive *fout, const IndxInfo *indxinfo, PQExpBuffer q, PQExpBuffer delq); -extern bool fixComputedColumnParenthesis(Archive *fout, char *decompiled_string); #endif diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 352cb60b675..ca49ef0220f 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15852,7 +15852,7 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) { if (tbinfo->attgenerated[j] == ATTRIBUTE_GENERATED_STORED) { - if(fixComputedColumnParenthesis(fout, tbinfo->attrdefs[j]->adef_expr)) + if(isBabelfishDatabase(fout)) appendPQExpBuffer(q, " GENERATED ALWAYS AS %s STORED", tbinfo->attrdefs[j]->adef_expr); else From 309d65b1cacbc06d877efe91dc042f570a6f3f7b Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Mon, 2 Dec 2024 06:14:55 +0000 Subject: [PATCH 17/25] Check behaviour Signed-off-by: Shameem Ahmed --- src/backend/utils/adt/ruleutils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index ba5e7a0001e..6be29d0fad7 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -10761,8 +10761,9 @@ get_const_collation(Const *constval, deparse_context *context) if (OidIsValid(constval->constcollid)) { Oid typcollation = get_typcollation(constval->consttype); + const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); - if (constval->constcollid != typcollation) + if (constval->constcollid != typcollation && !(dump_restore && strcmp(dump_restore, "on") == 0)) { appendStringInfo(buf, " COLLATE %s", generate_collation_name(constval->constcollid)); From be9be41e2f29997dbcc1850b036a7dd0b257078d Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Mon, 2 Dec 2024 08:09:10 +0000 Subject: [PATCH 18/25] Remove unnecessary changes Signed-off-by: Shameem Ahmed --- src/backend/parser/parse_collate.c | 37 +++++++++++------------------- src/backend/utils/adt/ruleutils.c | 2 +- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/backend/parser/parse_collate.c b/src/backend/parser/parse_collate.c index c8dfa775cbc..5dd04fa4ce2 100644 --- a/src/backend/parser/parse_collate.c +++ b/src/backend/parser/parse_collate.c @@ -800,7 +800,6 @@ merge_collation_state(Oid collation, int location2, assign_collations_context *context) { - const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); /* * If the collation strength for this node is different from what's * already in *context, then this node either dominates or is dominated by @@ -859,30 +858,20 @@ merge_collation_state(Oid collation, /* We're still conflicted ... */ break; case COLLATE_EXPLICIT: - if ((collation != context->collation)) + if (collation != context->collation) { - if (dump_restore && strcmp(dump_restore, "on") == 0) - { - context->collation = collation; - context->strength = strength; - context->location = location; - break; - } - else - { - /* - * Oops, we have a conflict of explicit COLLATE clauses. - * Here we choose to throw error immediately; that is what - * the SQL standard says to do, and there's no good reason - * to be less strict. - */ - ereport(ERROR, - (errcode(ERRCODE_COLLATION_MISMATCH), - errmsg("collation mismatch between explicit collations \"%s\" and \"%s\"", - get_collation_name(context->collation), - get_collation_name(collation)), - parser_errposition(context->pstate, location))); - } + /* + * Oops, we have a conflict of explicit COLLATE clauses. + * Here we choose to throw error immediately; that is what + * the SQL standard says to do, and there's no good reason + * to be less strict. + */ + ereport(ERROR, + (errcode(ERRCODE_COLLATION_MISMATCH), + errmsg("collation mismatch between explicit collations \"%s\" and \"%s\"", + get_collation_name(context->collation), + get_collation_name(collation)), + parser_errposition(context->pstate, location))); } break; } diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 6be29d0fad7..b05c3d65147 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -10763,7 +10763,7 @@ get_const_collation(Const *constval, deparse_context *context) Oid typcollation = get_typcollation(constval->consttype); const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); - if (constval->constcollid != typcollation && !(dump_restore && strcmp(dump_restore, "on") == 0)) + if (constval->constcollid != typcollation && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0))) { appendStringInfo(buf, " COLLATE %s", generate_collation_name(constval->constcollid)); From c3a09cadb3ae0afa346c3a8d64ccf220d2af8c61 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Mon, 2 Dec 2024 08:30:17 +0000 Subject: [PATCH 19/25] Minor change Signed-off-by: Shameem Ahmed --- src/bin/pg_dump/pg_dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 88e37810ca6..1dd833011e3 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15871,7 +15871,7 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(q, " NOT NULL"); /* Add collation if not default for the type */ - if (OidIsValid(tbinfo->attcollation[j])) + if (OidIsValid(tbinfo->attcollation[j]) && !isBabelfishDatabase(fout)) { CollInfo *coll; From 4894138893ee568a076c2aa7080226a9bfee1480 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Thu, 9 Jan 2025 10:37:48 +0000 Subject: [PATCH 20/25] Temporarily fix upgrade failure Signed-off-by: Shameem Ahmed --- src/backend/parser/parse_collate.c | 35 ++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/backend/parser/parse_collate.c b/src/backend/parser/parse_collate.c index 5dd04fa4ce2..390fb4531e3 100644 --- a/src/backend/parser/parse_collate.c +++ b/src/backend/parser/parse_collate.c @@ -800,6 +800,7 @@ merge_collation_state(Oid collation, int location2, assign_collations_context *context) { + const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); /* * If the collation strength for this node is different from what's * already in *context, then this node either dominates or is dominated by @@ -860,18 +861,28 @@ merge_collation_state(Oid collation, case COLLATE_EXPLICIT: if (collation != context->collation) { - /* - * Oops, we have a conflict of explicit COLLATE clauses. - * Here we choose to throw error immediately; that is what - * the SQL standard says to do, and there's no good reason - * to be less strict. - */ - ereport(ERROR, - (errcode(ERRCODE_COLLATION_MISMATCH), - errmsg("collation mismatch between explicit collations \"%s\" and \"%s\"", - get_collation_name(context->collation), - get_collation_name(collation)), - parser_errposition(context->pstate, location))); + if (dump_restore && strcmp(dump_restore, "on") == 0) + { + context->collation = collation; + context->strength = strength; + context->location = location; + break; + } + else + { + /* + * Oops, we have a conflict of explicit COLLATE clauses. + * Here we choose to throw error immediately; that is what + * the SQL standard says to do, and there's no good reason + * to be less strict. + */ + ereport(ERROR, + (errcode(ERRCODE_COLLATION_MISMATCH), + errmsg("collation mismatch between explicit collations \"%s\" and \"%s\"", + get_collation_name(context->collation), + get_collation_name(collation)), + parser_errposition(context->pstate, location))); + } } break; } From c628c3058db686c865cf2407bd698840a4168fda Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Fri, 10 Jan 2025 05:46:40 +0000 Subject: [PATCH 21/25] Test by removing maybe unnecessary change Signed-off-by: Shameem Ahmed --- src/backend/parser/parse_collate.c | 3 ++- src/backend/utils/adt/ruleutils.c | 5 +++-- src/bin/pg_dump/pg_dump.c | 11 ++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/backend/parser/parse_collate.c b/src/backend/parser/parse_collate.c index 390fb4531e3..cf13b2eea3e 100644 --- a/src/backend/parser/parse_collate.c +++ b/src/backend/parser/parse_collate.c @@ -800,7 +800,7 @@ merge_collation_state(Oid collation, int location2, assign_collations_context *context) { - const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); + const char *dump_restore; /* * If the collation strength for this node is different from what's * already in *context, then this node either dominates or is dominated by @@ -861,6 +861,7 @@ merge_collation_state(Oid collation, case COLLATE_EXPLICIT: if (collation != context->collation) { + dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); if (dump_restore && strcmp(dump_restore, "on") == 0) { context->collation = collation; diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 4c715e6cc79..8ad2159d818 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -10837,9 +10837,10 @@ get_const_collation(Const *constval, deparse_context *context) if (OidIsValid(constval->constcollid)) { Oid typcollation = get_typcollation(constval->consttype); - const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); + // const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); - if (constval->constcollid != typcollation && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0))) + // if (constval->constcollid != typcollation && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0))) + if (constval->constcollid != typcollation) { appendStringInfo(buf, " COLLATE %s", generate_collation_name(constval->constcollid)); diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index b0d4ed7a24d..f8caad615df 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15854,10 +15854,10 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) { if (tbinfo->attgenerated[j] == ATTRIBUTE_GENERATED_STORED) { - if(isBabelfishDatabase(fout)) - appendPQExpBuffer(q, " GENERATED ALWAYS AS %s STORED", - tbinfo->attrdefs[j]->adef_expr); - else + // if(isBabelfishDatabase(fout)) + // appendPQExpBuffer(q, " GENERATED ALWAYS AS %s STORED", + // tbinfo->attrdefs[j]->adef_expr); + // else appendPQExpBuffer(q, " GENERATED ALWAYS AS (%s) STORED", tbinfo->attrdefs[j]->adef_expr); } @@ -15871,7 +15871,8 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(q, " NOT NULL"); /* Add collation if not default for the type */ - if (OidIsValid(tbinfo->attcollation[j]) && !isBabelfishDatabase(fout)) + // if (OidIsValid(tbinfo->attcollation[j]) && !isBabelfishDatabase(fout)) + if (OidIsValid(tbinfo->attcollation[j])) { CollInfo *coll; From 854d013d6ba78a03f6c3fe007dcfc50dac7b6326 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Fri, 10 Jan 2025 09:05:13 +0000 Subject: [PATCH 22/25] Update engine logic for adding/not adding explicit COLLATE and parenthesis Signed-off-by: Shameem Ahmed --- src/backend/utils/adt/ruleutils.c | 6 +++--- src/bin/pg_dump/pg_dump.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 8ad2159d818..4efb6dec406 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -10837,10 +10837,10 @@ get_const_collation(Const *constval, deparse_context *context) if (OidIsValid(constval->constcollid)) { Oid typcollation = get_typcollation(constval->consttype); - // const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); + const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); - // if (constval->constcollid != typcollation && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0))) - if (constval->constcollid != typcollation) + if (constval->constcollid != typcollation && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0))) + // if (constval->constcollid != typcollation) { appendStringInfo(buf, " COLLATE %s", generate_collation_name(constval->constcollid)); diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index f8caad615df..fc28e37b755 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15854,10 +15854,10 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) { if (tbinfo->attgenerated[j] == ATTRIBUTE_GENERATED_STORED) { - // if(isBabelfishDatabase(fout)) - // appendPQExpBuffer(q, " GENERATED ALWAYS AS %s STORED", - // tbinfo->attrdefs[j]->adef_expr); - // else + if(isBabelfishDatabase(fout)) + appendPQExpBuffer(q, " GENERATED ALWAYS AS %s STORED", + tbinfo->attrdefs[j]->adef_expr); + else appendPQExpBuffer(q, " GENERATED ALWAYS AS (%s) STORED", tbinfo->attrdefs[j]->adef_expr); } @@ -15871,8 +15871,8 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(q, " NOT NULL"); /* Add collation if not default for the type */ - // if (OidIsValid(tbinfo->attcollation[j]) && !isBabelfishDatabase(fout)) - if (OidIsValid(tbinfo->attcollation[j])) + if (OidIsValid(tbinfo->attcollation[j]) && !isBabelfishDatabase(fout)) + // if (OidIsValid(tbinfo->attcollation[j])) { CollInfo *coll; From 25667ed93f06636baf1cabe29ae657b62b2f2019 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Fri, 10 Jan 2025 09:29:19 +0000 Subject: [PATCH 23/25] Update logic Signed-off-by: Shameem Ahmed --- src/bin/pg_dump/pg_dump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index fc28e37b755..1654a1ea8e0 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15871,8 +15871,8 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(q, " NOT NULL"); /* Add collation if not default for the type */ - if (OidIsValid(tbinfo->attcollation[j]) && !isBabelfishDatabase(fout)) - // if (OidIsValid(tbinfo->attcollation[j])) + // if (OidIsValid(tbinfo->attcollation[j]) && !isBabelfishDatabase(fout)) + if (OidIsValid(tbinfo->attcollation[j])) { CollInfo *coll; From 5306d85f3e215ddc64a9b8175e136c10be69c792 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Mon, 13 Jan 2025 08:10:28 +0000 Subject: [PATCH 24/25] Refractor code Signed-off-by: Shameem Ahmed --- src/backend/parser/parse_type.c | 2 +- src/backend/utils/cache/lsyscache.c | 2 +- src/bin/pg_dump/pg_dump.c | 9 ++------- src/include/parser/parse_type.h | 2 +- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/backend/parser/parse_type.c b/src/backend/parser/parse_type.c index 83b44d617b9..a3ac06b06f5 100644 --- a/src/backend/parser/parse_type.c +++ b/src/backend/parser/parse_type.c @@ -656,7 +656,7 @@ typeTypeCollation(Type typ) if (handle_default_collation_hook) { - return (*handle_default_collation_hook)(typ, true); + return (*handle_default_collation_hook)(typ); } return typtup->typcollation; diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 94bd4742035..b99137e7d18 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -3055,7 +3055,7 @@ get_typcollation(Oid typid) if (handle_default_collation_hook) { - result = (*handle_default_collation_hook)((Type) tp, true); + result = (*handle_default_collation_hook)((Type) tp); } ReleaseSysCache(tp); diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 1654a1ea8e0..9ffd74b9a0d 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15854,12 +15854,8 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) { if (tbinfo->attgenerated[j] == ATTRIBUTE_GENERATED_STORED) { - if(isBabelfishDatabase(fout)) - appendPQExpBuffer(q, " GENERATED ALWAYS AS %s STORED", - tbinfo->attrdefs[j]->adef_expr); - else - appendPQExpBuffer(q, " GENERATED ALWAYS AS (%s) STORED", - tbinfo->attrdefs[j]->adef_expr); + appendPQExpBuffer(q, " GENERATED ALWAYS AS (%s) STORED", + tbinfo->attrdefs[j]->adef_expr); } else appendPQExpBuffer(q, " DEFAULT %s", @@ -15871,7 +15867,6 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(q, " NOT NULL"); /* Add collation if not default for the type */ - // if (OidIsValid(tbinfo->attcollation[j]) && !isBabelfishDatabase(fout)) if (OidIsValid(tbinfo->attcollation[j])) { CollInfo *coll; diff --git a/src/include/parser/parse_type.h b/src/include/parser/parse_type.h index ed097c55709..0b2de4d8dcb 100644 --- a/src/include/parser/parse_type.h +++ b/src/include/parser/parse_type.h @@ -69,7 +69,7 @@ extern PGDLLEXPORT check_or_set_default_typmod_hook_type check_or_set_default_ty typedef void (*validate_var_datatype_scale_hook_type)(const TypeName *typeName, Type typ); extern PGDLLEXPORT validate_var_datatype_scale_hook_type validate_var_datatype_scale_hook; -typedef Oid (*handle_default_collation_hook_type) (Type typ, bool handle_pg_type); +typedef Oid (*handle_default_collation_hook_type) (Type typ); extern PGDLLEXPORT handle_default_collation_hook_type handle_default_collation_hook; #endif /* PARSE_TYPE_H */ From 0578d11387348863c0b5e7d8ecc7a7aff3c2d451 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Mon, 13 Jan 2025 08:45:48 +0000 Subject: [PATCH 25/25] Refractor code Signed-off-by: Shameem Ahmed --- src/backend/utils/adt/ruleutils.c | 4 +--- src/bin/pg_dump/pg_dump.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 4efb6dec406..5eebc9a169d 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -10837,10 +10837,8 @@ get_const_collation(Const *constval, deparse_context *context) if (OidIsValid(constval->constcollid)) { Oid typcollation = get_typcollation(constval->consttype); - const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); - if (constval->constcollid != typcollation && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0))) - // if (constval->constcollid != typcollation) + if (constval->constcollid != typcollation) { appendStringInfo(buf, " COLLATE %s", generate_collation_name(constval->constcollid)); diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 9ffd74b9a0d..e57d6e1038f 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15853,10 +15853,8 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) if (print_default) { if (tbinfo->attgenerated[j] == ATTRIBUTE_GENERATED_STORED) - { appendPQExpBuffer(q, " GENERATED ALWAYS AS (%s) STORED", - tbinfo->attrdefs[j]->adef_expr); - } + tbinfo->attrdefs[j]->adef_expr); else appendPQExpBuffer(q, " DEFAULT %s", tbinfo->attrdefs[j]->adef_expr);