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

[CBRD-24600] Problem with creating the same index with different names #4020

Merged
merged 4 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
166 changes: 75 additions & 91 deletions src/object/class_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ static SM_FUNCTION_INFO *classobj_make_function_index_info (DB_SEQ * func_seq);
static DB_SEQ *classobj_make_function_index_info_seq (SM_FUNCTION_INFO * func_index_info);
static SM_CONSTRAINT_COMPATIBILITY classobj_check_index_compatibility (SM_CLASS_CONSTRAINT * constraints,
const DB_CONSTRAINT_TYPE constraint_type,
const SM_PREDICATE_INFO * filter_predicate,
const SM_FUNCTION_INFO * func_index_info,
const SM_CLASS_CONSTRAINT * existing_con,
SM_CLASS_CONSTRAINT ** primary_con);
static int classobj_check_function_constraint_info (DB_SEQ * constraint_seq, bool * has_function_constraint);
Expand Down Expand Up @@ -4059,7 +4057,8 @@ classobj_find_cons_index2_col_type_list (SM_CLASS_CONSTRAINT * cons, OID * root_
*/
SM_CLASS_CONSTRAINT *
classobj_find_constraint_by_attrs (SM_CLASS_CONSTRAINT * cons_list, DB_CONSTRAINT_TYPE new_cons, const char **att_names,
const int *asc_desc, const SM_PREDICATE_INFO * filter_predicate)
const int *asc_desc, const SM_PREDICATE_INFO * filter_predicate,
const SM_FUNCTION_INFO * func_index_info)
{
SM_CLASS_CONSTRAINT *cons;
SM_ATTRIBUTE **attp;
Expand Down Expand Up @@ -4103,6 +4102,11 @@ classobj_find_constraint_by_attrs (SM_CLASS_CONSTRAINT * cons_list, DB_CONSTRAIN
{
continue;
}
if (((filter_predicate && !cons->filter_predicate) || (!filter_predicate && cons->filter_predicate))
|| ((func_index_info && !cons->func_index_info) || (!func_index_info && cons->func_index_info)))
{
continue;
}

len = 0; /* init */
while (*attp && *namep && !intl_identifier_casecmp ((*attp)->header.name, *namep))
Expand All @@ -4112,50 +4116,53 @@ classobj_find_constraint_by_attrs (SM_CLASS_CONSTRAINT * cons_list, DB_CONSTRAIN
len++; /* increase name number */
}

if (!*attp && !*namep && !classobj_is_possible_constraint (cons->type, new_cons))
if (*attp || *namep || classobj_is_possible_constraint (cons->type, new_cons))
{
for (i = 0; i < len; i++)
continue;
}

for (i = 0; i < len; i++)
{
/* if not specified, ascending order */
order = (asc_desc ? asc_desc[i] : 0);
assert (order == 0 || order == 1);
if (order != cons->asc_desc[i])
{
/* if not specified, ascending order */
order = (asc_desc ? asc_desc[i] : 0);
assert (order == 0 || order == 1);
if (order != cons->asc_desc[i])
{
break; /* not match */
}
break; /* not match */
}
}

if (i == len)
{
if (filter_predicate)
{
if (!cons->filter_predicate)
{
continue;
}
if (i != len)
{
continue;
}

if (!filter_predicate->pred_string || !cons->filter_predicate->pred_string)
{
continue;
}
if (filter_predicate)
{
Comment on lines -4129 to +4141
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking cons->filter_predicate seems to be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the conditions added to the 4105 line,
If filter_predicate is not NULL, cons->filter_predicate is also determined to be NULL.

(filter_predicate && !cons->filter_predicate) || (!filter_predicate && cons->filter_predicate)

if (!filter_predicate->pred_string || !cons->filter_predicate->pred_string)
{
continue;
}

if (strcmp (filter_predicate->pred_string, cons->filter_predicate->pred_string))
{
continue;
}
}
else
{
if (cons->filter_predicate)
{
continue;
}
}
if (strcmp (filter_predicate->pred_string, cons->filter_predicate->pred_string))
{
continue;
}
}

return cons;
if (func_index_info)
{
/* expr_str are printed tree, identifiers are already lower case */
if ((func_index_info->attr_index_start != cons->func_index_info->attr_index_start)
|| (func_index_info->col_id != cons->func_index_info->col_id)
|| (func_index_info->fi_domain->is_desc != cons->func_index_info->fi_domain->is_desc)
|| (strcmp (func_index_info->expr_str, cons->func_index_info->expr_str) != 0))
{
continue;
}
}

return cons;
}
}

Expand Down Expand Up @@ -7947,7 +7954,9 @@ classobj_make_descriptor (MOP class_mop, SM_CLASS * classobj, SM_COMPONENT * com
* share : share index with existed index;
* new idx: create new index;
* error : not share index and return error msg.
* 3 filter_predicate and func_index_info should be checked.
* 3. filter_predicate and func_index_info were checked in classbj_find_constraint_by_attors().
* 4. The fact that existing_con is not NULL means that there are the same indexes,
* from the count and order of attributes, order direction, function index composition, and filter conditions.
* +---------------+-------------------------------------------------------+
* | | Existed constraint or index |
* | +----------+-----------+---------+----------+-----------+
Expand All @@ -7972,9 +7981,7 @@ classobj_make_descriptor (MOP class_mop, SM_CLASS * classobj, SM_COMPONENT * com
*/
static SM_CONSTRAINT_COMPATIBILITY
classobj_check_index_compatibility (SM_CLASS_CONSTRAINT * constraints, const DB_CONSTRAINT_TYPE constraint_type,
const SM_PREDICATE_INFO * filter_predicate,
const SM_FUNCTION_INFO * func_index_info, const SM_CLASS_CONSTRAINT * existing_con,
SM_CLASS_CONSTRAINT ** primary_con)
const SM_CLASS_CONSTRAINT * existing_con, SM_CLASS_CONSTRAINT ** primary_con)
{
SM_CONSTRAINT_COMPATIBILITY ret;

Expand All @@ -7995,65 +8002,41 @@ classobj_check_index_compatibility (SM_CLASS_CONSTRAINT * constraints, const DB_
return SM_CREATE_NEW_INDEX;
}

if (DB_IS_CONSTRAINT_UNIQUE_FAMILY (constraint_type) && SM_IS_CONSTRAINT_UNIQUE_FAMILY (existing_con->type))
{
ret = SM_SHARE_INDEX;
goto check_filter_function;
}

if (constraint_type == DB_CONSTRAINT_FOREIGN_KEY)
switch (constraint_type)
{
case DB_CONSTRAINT_PRIMARY_KEY:
case DB_CONSTRAINT_UNIQUE:
case DB_CONSTRAINT_REVERSE_UNIQUE:
if (SM_IS_CONSTRAINT_UNIQUE_FAMILY (existing_con->type))
{
return SM_CREATE_NEW_INDEX;
return SM_SHARE_INDEX;
}
else if (existing_con->type == SM_CONSTRAINT_INDEX)
break;

case DB_CONSTRAINT_FOREIGN_KEY:
if (SM_IS_CONSTRAINT_UNIQUE_FAMILY (existing_con->type))
{
ret = SM_SHARE_INDEX;
if (existing_con->filter_predicate != NULL || existing_con->func_index_info != NULL)
{
ret = SM_CREATE_NEW_INDEX;
}
return ret;
return SM_CREATE_NEW_INDEX;
}
}
else if (constraint_type == DB_CONSTRAINT_INDEX && existing_con->type == SM_CONSTRAINT_FOREIGN_KEY)
{
ret = SM_SHARE_INDEX;
if (filter_predicate != NULL || func_index_info != NULL)
else if (existing_con->type == SM_CONSTRAINT_INDEX || existing_con->type == DB_CONSTRAINT_REVERSE_INDEX)
{
ret = SM_CREATE_NEW_INDEX;
return SM_SHARE_INDEX;
}
return ret;
}

ret = SM_NOT_SHARE_INDEX_AND_WARNING;
break;

check_filter_function:
if (func_index_info && existing_con->func_index_info)
{
/* expr_str are printed tree, identifiers are already lower case */
if (!strcmp (func_index_info->expr_str, existing_con->func_index_info->expr_str)
&& (func_index_info->attr_index_start == existing_con->func_index_info->attr_index_start)
&& (func_index_info->col_id == existing_con->func_index_info->col_id)
&& (func_index_info->fi_domain->is_desc == existing_con->func_index_info->fi_domain->is_desc))
case DB_CONSTRAINT_INDEX:
case DB_CONSTRAINT_REVERSE_INDEX:
if (existing_con->type == SM_CONSTRAINT_FOREIGN_KEY)
{
return ret;
return SM_SHARE_INDEX;
}
else
{
return SM_CREATE_NEW_INDEX;
}
}
if ((func_index_info != NULL) && (existing_con->func_index_info == NULL))
{
return SM_CREATE_NEW_INDEX;
}
if ((func_index_info == NULL) && (existing_con->func_index_info != NULL))
{
return SM_CREATE_NEW_INDEX;
break;

default:
break;
}
return ret;

return SM_NOT_SHARE_INDEX_AND_WARNING;
}

/*
Expand Down Expand Up @@ -8092,7 +8075,9 @@ classobj_check_index_exist (SM_CLASS_CONSTRAINT * constraints, char **out_shared
return error;
}

existing_con = classobj_find_constraint_by_attrs (constraints, constraint_type, att_names, asc_desc, filter_index);
existing_con =
classobj_find_constraint_by_attrs (constraints, constraint_type, att_names, asc_desc, filter_index,
func_index_info);
#if defined (ENABLE_UNUSED_FUNCTION) /* to disable TEXT */
if (existing_con != NULL)
{
Expand All @@ -8104,8 +8089,7 @@ classobj_check_index_exist (SM_CLASS_CONSTRAINT * constraints, char **out_shared
}
#endif /* ENABLE_UNUSED_FUNCTION */

compat_state = classobj_check_index_compatibility (constraints, constraint_type, filter_index, func_index_info,
existing_con, &prim_con);
compat_state = classobj_check_index_compatibility (constraints, constraint_type, existing_con, &prim_con);
switch (compat_state)
{
case SM_CREATE_NEW_INDEX:
Expand Down
3 changes: 2 additions & 1 deletion src/object/class_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,8 @@ extern SM_CLASS_CONSTRAINT *classobj_find_constraint_by_name (SM_CLASS_CONSTRAIN
extern SM_CLASS_CONSTRAINT *classobj_find_constraint_by_attrs (SM_CLASS_CONSTRAINT * cons_list,
DB_CONSTRAINT_TYPE new_cons, const char **att_names,
const int *asc_desc,
const SM_PREDICATE_INFO * filter_predicate);
const SM_PREDICATE_INFO * filter_predicate,
const SM_FUNCTION_INFO * func_index_info);
extern TP_DOMAIN *classobj_find_cons_index2_col_type_list (SM_CLASS_CONSTRAINT * cons, OID * root_oid);
extern void classobj_remove_class_constraint_node (SM_CLASS_CONSTRAINT ** constraints, SM_CLASS_CONSTRAINT * node);

Expand Down