diff --git a/contrib/babelfishpg_common/src/collation.c b/contrib/babelfishpg_common/src/collation.c index 0ece7a78ab..ca7947fc98 100644 --- a/contrib/babelfishpg_common/src/collation.c +++ b/contrib/babelfishpg_common/src/collation.c @@ -1326,6 +1326,24 @@ has_ilike_node(Node *expr) return false; } +bool +has_like_node(Node *expr) +{ + OpExpr *op; + + Assert(IsA(expr, OpExpr)); + + op = (OpExpr *) expr; + for (int i = 0; i < TOTAL_LIKE_OP_COUNT; i++) + { + if (strcmp(get_opname(op->opno), like_ilike_table[i].like_op_name) == 0) + { + return true; + } + } + return false; +} + Datum is_collated_ci_as_internal(PG_FUNCTION_ARGS) { @@ -1625,6 +1643,7 @@ get_collation_callbacks(void) collation_callbacks_var.find_cs_as_collation_internal = &find_cs_as_collation; collation_callbacks_var.find_collation_internal = &find_collation; collation_callbacks_var.has_ilike_node = &has_ilike_node; + collation_callbacks_var.has_like_node = &has_like_node; collation_callbacks_var.translate_bbf_collation_to_tsql_collation = &translate_bbf_collation_to_tsql_collation; collation_callbacks_var.translate_tsql_collation_to_bbf_collation = &translate_tsql_collation_to_bbf_collation; collation_callbacks_var.set_db_collation = &set_db_collation; diff --git a/contrib/babelfishpg_common/src/collation.h b/contrib/babelfishpg_common/src/collation.h index 87d9c014dd..c060814bfc 100644 --- a/contrib/babelfishpg_common/src/collation.h +++ b/contrib/babelfishpg_common/src/collation.h @@ -113,6 +113,8 @@ typedef struct collation_callbacks bool (*has_ilike_node) (Node *expr); + bool (*has_like_node) (Node *expr); + const char *(*translate_bbf_collation_to_tsql_collation) (const char *collname); const char *(*translate_tsql_collation_to_bbf_collation) (const char *collname); @@ -147,6 +149,7 @@ extern const char *translate_bbf_collation_to_tsql_collation(const char *collnam extern const char *translate_tsql_collation_to_bbf_collation(const char *collname); Oid get_oid_from_collidx(int collidx); extern bool has_ilike_node(Node *expr); +extern bool has_like_node(Node *expr); extern Oid babelfish_define_type_default_collation(Oid typeNamespace); extern void set_db_collation(Oid db_coll); diff --git a/contrib/babelfishpg_tsql/src/collation.c b/contrib/babelfishpg_tsql/src/collation.c index 77efb4ea44..1210aa93a4 100644 --- a/contrib/babelfishpg_tsql/src/collation.c +++ b/contrib/babelfishpg_tsql/src/collation.c @@ -942,9 +942,14 @@ transform_likenode(Node *node) * by a user. So, it is safe to go ahead with replacing the ci_as * collation with a corresponding cs_as one if an ILIKE node is found * during dump and restore. + * For CS_AI collation, we keep the LIKE operator but convert it to + * CS_AS by adding a call to remove_accents_internal*. During restore, + * it will take the same code path and will try to add a new call to + * remove_accents_internal* on top of current node. So, we take care + * of that case here. */ init_and_check_collation_callbacks(); - if ((*collation_callbacks_ptr->has_ilike_node) (node) && babelfish_dump_restore) + if (babelfish_dump_restore && ((*collation_callbacks_ptr->has_ilike_node) (node) || (*collation_callbacks_ptr->has_like_node) (node))) { int collidx_of_cs_as; @@ -965,6 +970,13 @@ transform_likenode(Node *node) /* If a collation is not specified, use the default one */ op->inputcollid = DEFAULT_COLLATION_OID; } + + /* + * If this has a like node, then it is CS collation + * So we can return from here directly + */ + if ((*collation_callbacks_ptr->has_like_node) (node)) + return node; } if (OidIsValid(like_entry.like_oid) && diff --git a/contrib/babelfishpg_tsql/src/collation.h b/contrib/babelfishpg_tsql/src/collation.h index 671ab0d8e9..671f0064d9 100644 --- a/contrib/babelfishpg_tsql/src/collation.h +++ b/contrib/babelfishpg_tsql/src/collation.h @@ -82,6 +82,8 @@ typedef struct collation_callbacks bool (*has_ilike_node) (Node *expr); + bool (*has_like_node) (Node *expr); + const char *(*translate_bbf_collation_to_tsql_collation) (const char *collname); const char *(*translate_tsql_collation_to_bbf_collation) (const char *collname);