Skip to content

[CBRD-26490] Add function to set referential_index for self-referencing FK#6825

Open
kangmin5505 wants to merge 2 commits intoCUBRID:developfrom
kangmin5505:_db_index-self-referencing
Open

[CBRD-26490] Add function to set referential_index for self-referencing FK#6825
kangmin5505 wants to merge 2 commits intoCUBRID:developfrom
kangmin5505:_db_index-self-referencing

Conversation

@kangmin5505
Copy link
Contributor

@kangmin5505 kangmin5505 commented Feb 3, 2026

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

Purpose

_db_index의 referencial_index 컬럼 추가 시 self referencing은 제외하고 구현이 되었기 때문에 이를 구현합니다.
기존에 추가하지 못 했던 이유는 지금 구조에서는 referencial_index 컬럼에 참조하는 _db_index를 넣으려면 해당하는 _db_index가 존재해야 하는데, self referencing의 경우는 아직 자기 자신이 생성되지 않은 상태였기 때문입니다.

Implementation

기존에 CREATE TABLE 구문과 함께 생성된 self-referencing FK의 경우 index_catalog_of_ref_class(foreign key가 참조하는 PK의 _db_index 레코드)를 생성할 수 없었던 이유는 해당 로직을 smt_check_foreign_key()에서 처리하고 있었기 때문입니다. smt_check_foreign_key()는 do_create_local() 함수 내에서 호출되는데, do_create_local()은 아직 클래스를 생성하기 전입니다.

따라서 이 로직을 클래스와 PK 관련한 정보가 모두 생성된 이후인 allocate_foreign_key()로 이전하였습니다. 참고로 allocate_foreign_key()는 FK를 생성하고 참조하고 있는 클래스에 해당 정보를 추가하는 함수입니다.

Remarks

  • 명확함을 위해 함수명 및 변수명 변경 - find_index_catalog_class() -> find_index_catalog()
  • smt_check_foreign_key ()에서 사용하지 않는 변수 제거

@kangmin5505 kangmin5505 self-assigned this Feb 3, 2026
@kangmin5505
Copy link
Contributor Author

/run all

1 similar comment
@kangmin5505
Copy link
Contributor Author

/run all

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 support for setting the referential_index column in _db_index for self-referencing foreign keys. Previously, this was excluded from the implementation because the logic ran before the class and its primary key were created. The solution is to move the logic from smt_check_foreign_key() (which runs before class creation) to allocate_foreign_key() (which runs after class and PK information is available).

Changes:

  • Moved logic for setting index_catalog_of_ref_class from smt_check_foreign_key() to allocate_foreign_key()
  • Renamed find_index_catalog_class() to find_index_catalog() and relocated it from schema_template.c to schema_manager.c
  • Removed unused variable ref_cls_name from smt_check_foreign_key()

Reviewed changes

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

File Description
src/object/schema_template.c Removed logic for setting index_catalog_of_ref_class, removed find_index_catalog_class() function, and cleaned up unused variable ref_cls_name
src/object/schema_manager.c Added find_index_catalog() function and new logic in allocate_foreign_key() to set index_catalog_of_ref_class for both self-referencing and regular foreign keys

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

@kangmin5505
Copy link
Contributor Author

실패한 sql 1 건은 PR 요청 완료하였습니다.

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