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 6 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;

get_tsql_const_collation_hook = get_tsql_const_collation;
}
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;
get_tsql_const_collation_hook = NULL;
}

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


/*
* get_tsql_const_collation - determines whether collation needs to be dumped or not
* for collatable data types such as varchar, char, nvarchar, nchar, etc for Const clause.
*
* This would be required to handle clause like default clause, check constraints, etc in case
Deepesh125 marked this conversation as resolved.
Show resolved Hide resolved
* of if the server is already upgraded to version > 14.6 (Babelfish v2.3.0) via minor Version
* Upgrade and Major Version Upgrade from version > 14.6 (Babelfish v2.3.0) to 15.1 or later
* is being performed because the default collation of collatable data types is fixed during Babelfish
* v2.3.0 ie., default collation would now be same as T-SQL collation which was DEFAULT_COLLATION_OID
* previously. And all the existing const clause like default clause and check constraint clause might
* still be pointing to PG's default collation. So this function will help to avoid dumping COLLATE
* clause in such cases.
*/
Deepesh125 marked this conversation as resolved.
Show resolved Hide resolved
bool
get_tsql_const_collation(Const *constval) {
Oid typid = constval->consttype;
Oid typcollation = get_typcollation(typid);

Deepesh125 marked this conversation as resolved.
Show resolved Hide resolved
if (typcollation != DEFAULT_COLLATION_OID &&
Deepesh125 marked this conversation as resolved.
Show resolved Hide resolved
(is_tsql_nvarchar_datatype(typid) ||
is_tsql_varchar_datatype(typid) ||
is_tsql_bpchar_datatype(typid) ||
is_tsql_nchar_datatype(typid)))
{
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 get_tsql_const_collation(Const *constval);