Skip to content

[CBRD-26514] suppress user name and comment from SP creation statement texts#6801

Open
hyunikn wants to merge 8 commits intoCUBRID:developfrom
hyunikn:cbrd-26514-drop-user-in-scode
Open

[CBRD-26514] suppress user name and comment from SP creation statement texts#6801
hyunikn wants to merge 8 commits intoCUBRID:developfrom
hyunikn:cbrd-26514-drop-user-in-scode

Conversation

@hyunikn
Copy link
Contributor

@hyunikn hyunikn commented Jan 27, 2026

http://jira.cubrid.org/browse/CBRD-26514
http://jira.cubrid.org/browse/CBRD-26513

Purpose

ALTER 에 의해 변경될 수 있는 SP 의 owner와 comment 를 _db_stored_procedure_code.scode 에 포함되지 않도록 합니다.

Implementation

PL/CSQL 컴파일러에게 보내는 CREATE PROCEDURE/FUNCTION 문의 텍스트를 parser_print_tree() 함수를 이용해서 얻습니다.
기존에는 사용자가 입력한 그대로를 사용했습니다.
PL/CSQL 컴파일러에게 보내는 텍스트가 결국 _db_stored_procedure_code.scode 에 저장됩니다.

…tement texts which go to PL/CSQL compiler and _db_stored_procedure_code.scode
…SP name in texts that PL/CSQL compiler receives
@hyunikn
Copy link
Contributor Author

hyunikn commented Jan 27, 2026

/run all

@hyunikn hyunikn self-assigned this Jan 27, 2026
@hyunikn
Copy link
Contributor Author

hyunikn commented Jan 28, 2026

/run all

@hyunikn
Copy link
Contributor Author

hyunikn commented Jan 29, 2026

/run all

q = pt_append_nulstring (parser, q, " ");
if (parser->custom_print & (PT_PRINT_NO_SPECIFIED_USER_NAME | PT_PRINT_NO_CURRENT_USER_NAME))
{
q = pt_append_name (parser, q, p->info.sp.name->info.name.original);
Copy link
Contributor Author

@hyunikn hyunikn Jan 29, 2026

Choose a reason for hiding this comment

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

기존 코드에 오류가 있었던 것으로 보입니다.
이렇게 하면 PT_PRINT_NO_SPECIFIED_USER_NAME | PT_PRINT_NO_CURRENT_USER_NAME 가 지정되어 있어도 <user>.<sp-name> 을 출력하게 (<user> 를 지우지 않게) 됩니다.

Copy link
Contributor

@jongmin-won jongmin-won Jan 29, 2026

Choose a reason for hiding this comment

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

<user>가 제거되지 않는 것처럼 보이는 현상은 PT_PRINT_NO_SPECIFIED_USER_NAME | PT_PRINT_NO_CURRENT_USER_NAME flag 문제와 무관합니다.

CREATE PROCEDURE 구문 실행 경로와 UNLOAD 유틸리티 실행 경로에서 생성되는 PT_CREATE_STORED_PROCEDURE 노드PT_NAME 정보가 서로 달라, CREATE PROCEDURE에서 <user>가 제거되지 않는 것으로 보여 집니다.

  1. CREATE PROCEDURE 수행 시
  • CREATE PROCEDURE는 항상 pt_set_user_specified_name()을 거친 뒤 jsp_create_stored_procedure()로 진입하며, 이 과정에서 PT_NAME 가 이미 가공됩니다.
  • pt_set_user_specified_name() 수행 전
PT_CREATE_STORED_PROCEDURE 노드의 PT_NAME 정보
statement->info.sp.name->info.name.original = "<sp_name>"
statement->info.sp.name->info.name.resolved = "<user>"
  • pt_set_user_specified_name() 수행 후
PT_CREATE_STORED_PROCEDURE 노드의 PT_NAME 정보
statement->info.sp.name->info.name.original = "<user>.<sp_name>"
statement->info.sp.name->info.name.resolved = 0x0
  1. UNLOAD 수행 시
  • UNLOADemit_stored_procedure_code() 로 진입하고 parser_parse_string() 으로 PT_NODE를 생성한 직후, parser_print_tree_with_quotes()를 바로 호출하여 가공되지 않은 PT_NAME 노드 기준으로 쿼리를 재작성합니다.
PT_CREATE_STORED_PROCEDURE 노드의 PT_NAME 정보
(*scode_ptr)->info.name->info.name.original = "<sp_name>"
(*scode_ptr)->info.name->info.name.resolved = "<user>"

Copy link
Contributor Author

@hyunikn hyunikn Jan 30, 2026

Choose a reason for hiding this comment

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

PT_PRINT_NO_SPECIFIED_USER_NAME 나 PT_PRINT_NO_CURRENT_USER_NAME flag 의 의도상
<user> 를 사용자가 붙여주었든 pt_set_user_specified_name() 가 붙여 주었든 상관없이
<user>.<sp_name> 대신 <sp_name> 가 출력되는 것이 올바른 결과인 것 같습니다.
기존 코드에 오류가 있었던 것이 맞지요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

현재 상황은 CREATE 문을 통해서 왔어도 <user> 가 출력되지 않은 결과를 얻고 싶은 것입니다.

Copy link
Contributor

@jongmin-won jongmin-won Jan 30, 2026

Choose a reason for hiding this comment

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

네, 다른 함수에서 해당 flag 사용 패턴을 확인해보니 처리 방식이 달랐습니다.
pt_print_name()처럼 flag 별로 관련 함수를 사용하면 를 제거할 수 있을 것 같습니다.

static PARSER_VARCHAR *
pt_print_name (PARSER_CONTEXT * parser, PT_NODE * p)
...
if (parser->custom_print & PT_PRINT_NO_SPECIFIED_USER_NAME)
 {
   q = pt_append_name (parser, q, pt_get_name_with_qualifier_removed (p->info.name.resolved));
 }
else if (parser->custom_print & PT_PRINT_NO_CURRENT_USER_NAME)
 {
   q = pt_append_name (parser, q, pt_get_name_without_current_user_name (p->info.name.resolved));
 }
else
 {
   q = pt_append_name (parser, q, p->info.name.resolved);
 }
...

Copy link
Contributor Author

@hyunikn hyunikn Jan 30, 2026

Choose a reason for hiding this comment

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

수정 이후 parse_tree_cl.c 의 7693 라인으로부터 pt_print_name() 으로 진행을 합니다.
수정 이후 jsp_cl.cpp 의 1226 라인에서 PT_PRINT_NO_SPECIFIED_USER_NAME flag 를 주고
1228 라인에서 parser_print_tree() 를 호출했을 때 SP 이름을 print 하기 위해 도달하는 pt_print_name() 안에서

if (parser->custom_print & PT_PRINT_NO_SPECIFIED_USER_NAME)
 {
   q = pt_append_name (parser, q, pt_get_name_with_qualifier_removed (p->info.name.resolved));

로 진행함을 디버거로 확인했습니다.
flag 별로 관련 함수를 사용하는 코드를 다시 추가할 필요는 없어 보입니다.

Copy link
Contributor

@jongmin-won jongmin-won Jan 30, 2026

Choose a reason for hiding this comment

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

네, 말씀하신대로 현재 구조에서는 flag를 별도로 추가할 필요가 없어 보입니다.

해당 로직은 과거에 scode<user>.<sp_name> 형태로 저장되던 시점에, 일반 사용자가 unload를 수행할 때 <user> 부분을 제거해야 해서 추가했던 것입니다.
emit_stored_procedure_code()에서 PT_NAME 노드의 original/resolved 값이 아래처럼 채워져 있어, <user> 제거를 위해 해당 처리를 추가했습니다.

  • pt_print_name() 에서 original/resolved 두 값이 채워져 있는 경우 <resolved>.<original> 로 합침.
PT_CREATE_STORED_PROCEDURE 노드의 PT_NAME 정보
(*scode_ptr)->info.name->info.name.original = "<sp_name>"
(*scode_ptr)->info.name->info.name.resolved = "<user>"

하지만, 수정 이후에는 scode<user> 정보가 포함되지 않으며, unload 수행 시 PT_NAME 노드를 확인한 결과 original만 채워지고 resolvedNULL로 확인됩니다.
따라서 현재 로직 처럼 제거를 해도 unload 수행에 문제가 없어 보입니다.

PT_CREATE_STORED_PROCEDURE 노드의 PT_NAME 정보
(*scode_ptr)->info.name->info.name.original = "<sp_name>"
(*scode_ptr)->info.name->info.name.resolved = 0x0



// CBRD-26513, CBRD-26514: rewrite the user code without the user name and the comment
char *rewritten_code;
Copy link
Contributor Author

@hyunikn hyunikn Jan 29, 2026

Choose a reason for hiding this comment

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

회의 때 말씀 드렸던 것과 달리
컴파일 할 때는 사용자가 쓴 코드 그대로 사용하고
scode 에 저장할 때 재작성합니다.
사용자가 쓴 코드에 오류가 있는 경우 재작성 코드가 틀리게 나오는 문제가 발견되었기 때문에 이런 방향으로 수정했습니다.

@hyunikn hyunikn marked this pull request as ready for review January 29, 2026 02:01
@hyunikn hyunikn requested a review from beyondykk9 as a code owner January 29, 2026 02:01
@hyunikn
Copy link
Contributor Author

hyunikn commented Jan 29, 2026

test_sql 실패 3건은 답지 수정 예정입니다.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements CBRD-26514 to suppress the owner name and comment from stored procedure creation statement texts stored in _db_stored_procedure_code.scode. Instead of storing the user-entered text verbatim, the system now stores a canonical form generated by parser_print_tree() with flags to suppress the owner name and comment.

Changes:

  • Modified stored procedure creation to rewrite source code without owner and comment before storing
  • Updated the parser's print logic to consistently use pt_print_bytes() which respects suppression flags
  • Added assertions to enforce the invariant that stored code should not contain comments
  • Removed obsolete owner validation logic from the PL/CSQL compiler

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/sp/jsp_cl.cpp Rewrites SP source code using parser_print_tree() with flags to suppress owner name and comment before storing in database
src/parser/parse_tree_cl.c Simplified SP name printing logic to always use pt_print_bytes() and added assertion that comment is excluded when unloading schema
src/executables/unload_schema.c Updated to assert that stored code doesn't contain comment and always outputs comment on separate line
pl_engine/pl_server/src/main/java/com/cubrid/plcsql/compiler/ParseTreeConverter.java Added assertion that owner is not specified in SP definition and removed obsolete owner validation code

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hyunikn
Copy link
Contributor Author

hyunikn commented Jan 29, 2026

/run all

@hyunikn
Copy link
Contributor Author

hyunikn commented Feb 3, 2026

/run all

@hyunikn
Copy link
Contributor Author

hyunikn commented Feb 4, 2026

/run all

1 similar comment
@hyunikn
Copy link
Contributor Author

hyunikn commented Feb 6, 2026

/run all

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.

7 participants