Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid dumping COLLATE default for const clause #1222

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/composite-actions/build-modified-postgres/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ inputs:
engine_branch:
description: 'Engine Branch'
required: no
default: 'latest'
default: 'jira-babel-3895-2x'
install_dir:
description: 'Engine install directory'
required: no
Expand All @@ -23,14 +23,14 @@ runs:

if [[ $GITHUB_EVENT_NAME == "pull_request" ]]; then
if [[ ${{inputs.engine_branch}} == "latest" ]]; then
ENGINE_BRANCH=$GITHUB_HEAD_REF
ENGINE_BRANCH='jira-babel-3895-2x'
else
ENGINE_BRANCH=${{inputs.engine_branch}}
fi
REPOSITORY_OWNER=$HEAD_OWNER
else
if [[ ${{inputs.engine_branch}} == "latest" ]]; then
ENGINE_BRANCH=$GITHUB_REF_NAME
ENGINE_BRANCH='jira-babel-3895-2x'
else
ENGINE_BRANCH=${{inputs.engine_branch}}
fi
Expand Down
4 changes: 4 additions & 0 deletions .github/scripts/clone_engine_repo
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ else
BRANCH_OPTION=''
fi
fi
if [ "$BRANCH" = "jira-babel-3895-2x" ]; then
BASE_URL=https://github.com/amazon-aurora/postgresql_modified_for_babelfish
BRANCH_OPTION="--branch $BRANCH"
fi
fi
GIT_URL=${BASE_URL}.git

Expand Down
4 changes: 4 additions & 0 deletions contrib/babelfishpg_common/src/babelfishpg_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "parser/parse_target.h"
#include "parser/scansup.h" /* downcase_identifier */
#include "utils/guc.h"
#include "utils/ruleutils.h"

#include "babelfishpg_common.h"
#include "collation.h"
Expand Down Expand Up @@ -131,6 +132,8 @@ _PG_init(void)

prev_PreCreateCollation_hook = PreCreateCollation_hook;
PreCreateCollation_hook = BabelfishPreCreateCollation_hook;

handle_const_collation_hook = print_const_collation;
Deepesh125 marked this conversation as resolved.
Show resolved Hide resolved
}
void
_PG_fini(void)
Expand All @@ -141,6 +144,7 @@ _PG_fini(void)
CLUSTER_COLLATION_OID_hook = prev_CLUSTER_COLLATION_OID_hook;
TranslateCollation_hook = prev_TranslateCollation_hook;
PreCreateCollation_hook = prev_PreCreateCollation_hook;
handle_const_collation_hook = NULL;
Deepesh125 marked this conversation as resolved.
Show resolved Hide resolved
}

common_utility_plugin *
Expand Down
23 changes: 23 additions & 0 deletions contrib/babelfishpg_common/src/collation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1517,4 +1517,27 @@ babelfish_update_server_collation_name(PG_FUNCTION_ARGS)
server_collation_name = pstrdup(babelfish_restored_server_collation_name);
MemoryContextSwitchTo(oldContext);
PG_RETURN_VOID();
}


/*
* print_const_collation - determines whether collation needs to be dumped or not
* for collatable data types such as varchar, char, nvarchar, nchar, etc.
*/
Deepesh125 marked this conversation as resolved.
Show resolved Hide resolved
bool
print_const_collation(Const *constval) {
Deepesh125 marked this conversation as resolved.
Show resolved Hide resolved
Oid typid = constval->consttype;
Oid constcollid = constval->constcollid;
Oid typcollation = get_typcollation(typid);

Deepesh125 marked this conversation as resolved.
Show resolved Hide resolved
if ((is_tsql_nvarchar_datatype(typid) ||
is_tsql_varchar_datatype(typid) ||
is_tsql_bpchar_datatype(typid) ||
is_tsql_nchar_datatype(typid)) &&
constcollid == DEFAULT_COLLATION_OID &&
Deepesh125 marked this conversation as resolved.
Show resolved Hide resolved
typcollation != DEFAULT_COLLATION_OID)
Deepesh125 marked this conversation as resolved.
Show resolved Hide resolved
{
return false;
}
return true;
}
2 changes: 2 additions & 0 deletions contrib/babelfishpg_common/src/collation.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,5 @@ BabelfishPreCreateCollation_hook(

extern TranslateCollation_hook_type prev_TranslateCollation_hook;
extern PreCreateCollation_hook_type prev_PreCreateCollation_hook;

extern bool print_const_collation(Const *constval);