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-25719] Fix an issue where [user_schema] was incorrectly stored or missing in the condition and action_definition columns of the db_trigger catalog during trigger creation or loaddb execution with legacy unload files #5729

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from

Conversation

jongmin-won
Copy link
Contributor

@jongmin-won jongmin-won commented Dec 19, 2024

http://jira.cubrid.org/browse/CBRD-25719

Purpose

  1. CREATE TRIGGER 실행 시, SP가 포함된 경우 db_trigger 카탈로그의 action 및 condition 컬럼에 [user_schema]가 추가되지 않는 문제를 수정합니다.
  2. 과거의 unload 파일을 loaddb --no-user-specified-name 유틸리티를 사용해 트리거를 생성할 때, 실제 소유자를 찾아 db_trigger 카탈로그에 저장하도록 수정합니다.

Implementation

CREATE TRIGGER 동작 순서 수정

  1. Trigger 구문
CREATE TRIGGER [example]
BEFORE UPDATE ON [history](score)
EXECUTE INSERT INTO [update_logs] VALUES ([obj].[event_code], [obj].[score], '2024-12-11');
  1. Trigger 파싱 이후, Query Rewrite 수행 결과
insert into [dba.update_logs] values ([obj].[event_code], [obj].[score], '2024-12-11')
  1. Action(PT_SCOPE) 파싱 결과
  • 수정 전: 아래 SCOPE 구문이 에러 없이 정상적으로 컴파일된 경우, 2번에서 Rewrite된 구문을 카탈로그에 저장함.
SCOPE___ insert into [dba.update_logs] values ([obj].[event_code], [obj].[score], '2024-12-11') FROM ON  [public.history] obj, [public.history] new
  1. Action(PT_SCOPE)파싱 이후, Query Rewrite 수행 결과 (추가된 부분)
  • 수정 후: Action(PT_SCOPE) 파싱 결과를 다시 Rewrite하여 나온 구문을 카탈로그에 저장함.
insert into [dba.update_logs] ([event_code], [score], [dt]) values ([obj].[event_code], [obj].[score], '2024-12-11')

Remarks

N/A

jongmin-won added 3 commits December 19, 2024 21:08
…ondition columns of the db_trigger catalog when SP is included when performing create trigger, 2. When creating a trigger with the loaddb --no-user-specified-name utility, find the actual owner and modify it to save it in the db_trigger catalog, 3. When performing the unload utility, remove the owner’s [user_schema] from the action and condition columns.
@jongmin-won jongmin-won self-assigned this Dec 20, 2024
jongmin-won added 5 commits December 20, 2024 13:22
… rewritten into an unexecutable rewrite query.
…rewritten into an unexecutable rewrite query.
… rewritten into an unexecutable rewrite query.
…rewritten into an unexecutable rewrite query.
@jongmin-won jongmin-won changed the title [CBRD-25719] When executing loaddb with a past unload file (no user_schema) containing a trigger, the loaddb operation succeeds, but the trigger execution fails. [CBRD-25719] Fix an issue where [user_schema] was incorrectly stored or missing in the condition and action_definition columns of the db_trigger catalog during trigger creation or loaddb execution with legacy unload files Dec 20, 2024
@jongmin-won jongmin-won marked this pull request as ready for review December 23, 2024 04:11
jongmin-won added 3 commits December 24, 2024 00:57
…ory management issue in the change_trigger_action_query function might be the cause and have made adjustments to address it.
Comment on lines +1080 to +1094
char *p = NULL;
const char *remove_eval_prefix = "evaluate (";
size_t remove_eval_suffix_len;

p = strstr (result, remove_eval_prefix);
if (p != NULL)
{
p = (char *) memmove (p, p + strlen (remove_eval_prefix), strlen (p) - strlen (remove_eval_prefix) + 1);
}

remove_eval_suffix_len = strlen (p);
if (remove_eval_suffix_len > 0 && p[remove_eval_suffix_len - 1] == ')')
{
p[remove_eval_suffix_len - 1] = '\0';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

PR #5731 에서 다루는 코드와 동일한 것 같은데 함수로 만들어서 동일하게 유지 하는 것이 좋을 듯 합니다.

Comment on lines +1097 to +1112
result_len = strlen (result) + 1;
if (result_len < 0)
{
return NULL;
}

new_trigger_stmt_str = (char *) malloc (result_len);
if (new_trigger_stmt_str == NULL)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, (size_t) result_len);
return NULL;
}

snprintf (new_trigger_stmt_str, result_len, "%s", result);

return new_trigger_stmt_str;
Copy link
Contributor

Choose a reason for hiding this comment

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

return result; 로 충분할 듯 합니다.
따로 메모리를 할당해서 복사할 필요가 없는 함수로 보입니다.
필요하다면 이 함수의 리턴을 받은 쪽에서 별도 메모리가 필요한지 판단하면 될 것으로 보입니다.

* with_evaluate(in):
*/
static char *
change_trigger_action_query (PARSER_CONTEXT * parser, PT_NODE * statement, int with_evaluate)
Copy link
Contributor

Choose a reason for hiding this comment

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

with_evaluate 변수를 char*로 받아서 널 여부를 판단하는 것이 더 효율적이겠습니다.
이렇게 수정한다면 strstr()을 이 함수를 호출하는 쪽에서 한번만 해도 되겠네요

Comment on lines +1265 to +1267
free_and_init (*new_trigger_stmt);
*new_trigger_stmt = strdup (new_trigger_stmt_str);
free_and_init (new_trigger_stmt_str);
Copy link
Contributor

Choose a reason for hiding this comment

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

제가 위쪽에서 단 코멘트 중에 "return result; 로 충분할 듯 합니다." 이러 내용이 있었는데요,
그 코드를 수정하지 않는다면 반대로 이 부분에서 단지 아래와 같은 한 줄만 사용하면 될 것 같습니다.

*new_trigger_stmt = new_trigger_stmt_str;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants