-
Notifications
You must be signed in to change notification settings - Fork 4
[#220] feat: auto-create composite primary-key indexes #272
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
Open
DPS0340
wants to merge
6
commits into
myyrakle:master
Choose a base branch
from
DPS0340:feat/220-composite-pk-index
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d721656
[#220] feat: parse table-level PRIMARY KEY constraint
DPS0340 9e85f7a
[#220] feat: composite index metadata and key encoding
DPS0340 3816e02
[#220] feat: auto-create composite primary key indexes
DPS0340 68f39fc
[#220] fix: fall back to full scan for composite indexes in the optim…
DPS0340 3bcd53b
[#220] fix: address CodeRabbit review findings
DPS0340 05530d5
[#220] fix: provide a default impl for FileSystem::remove_dir_all
DPS0340 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| //! Task 2 RED 테스트: 복합 인덱스 키 지원 (#220) | ||
| //! | ||
| //! - IndexMeta.columns (복수 컬럼) 지원 | ||
| //! - row_index_keys: 복수 컬럼 키 인코딩 (순서 보존, 단사) | ||
| //! - NULL 포함 컬럼 → 인덱스 제외 (PostgreSQL과 동일) | ||
|
|
||
| use crate::engine::actions::index::row_index_keys; | ||
| use crate::engine::ast::types::TableName; | ||
| use crate::engine::index::{IndexMeta, field_to_key}; | ||
| use crate::engine::schema::row::{TableDataField, TableDataFieldType, TableDataRow}; | ||
|
|
||
| fn table() -> TableName { | ||
| TableName::new(Some("rrdb".to_owned()), "memberships".to_owned()) | ||
| } | ||
|
|
||
| fn field(name: &str, data: TableDataFieldType) -> TableDataField { | ||
| TableDataField { | ||
| table_name: table(), | ||
| column_name: name.to_owned(), | ||
| data, | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn index_meta_supports_multiple_columns() { | ||
| let meta = IndexMeta::new_composite( | ||
| "rrdb.memberships_pkey".to_owned(), | ||
| table(), | ||
| vec!["user_id".to_owned(), "group_id".to_owned()], | ||
| true, | ||
| ); | ||
|
|
||
| assert_eq!(meta.columns(), vec!["user_id", "group_id"]); | ||
| // 하위 호환: 단일 컬럼 인덱스는 column_name()로 첫 컬럼을 반환 | ||
| let single = IndexMeta::new("rrdb.users_pkey".to_owned(), table(), "id".to_owned(), true); | ||
| assert_eq!(single.columns(), vec!["id"]); | ||
| assert_eq!(single.column_name(), "id"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn composite_key_is_concatenation_with_unambiguous_boundaries() { | ||
| let row = TableDataRow { | ||
| fields: vec![ | ||
| field("user_id", TableDataFieldType::Integer(1)), | ||
| field("group_id", TableDataFieldType::Integer(2)), | ||
| ], | ||
| }; | ||
|
|
||
| let keys = row_index_keys(&row, &["user_id".to_owned(), "group_id".to_owned()]).unwrap(); | ||
|
|
||
| // 두 키를 합친 값이 단사여야 함: 다른 컬럼 조합이 같은 키를 만들 수 없음 | ||
| let combined = keys.join(""); | ||
| assert!(combined.contains(&field_to_key(&TableDataFieldType::Integer(1)))); | ||
| assert!(combined.contains(&field_to_key(&TableDataFieldType::Integer(2)))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn composite_key_encoding_is_injective_across_value_shapes() { | ||
| use crate::engine::actions::index::join_composite_key; | ||
|
|
||
| // "S:ab" + "S:c" vs "S:a" + "S:bc" 가 같은 키가 되는 충돌을 막아야 함 | ||
| let row_a = TableDataRow { | ||
| fields: vec![ | ||
| field("x", TableDataFieldType::String("ab".to_owned())), | ||
| field("y", TableDataFieldType::String("c".to_owned())), | ||
| ], | ||
| }; | ||
| let row_b = TableDataRow { | ||
| fields: vec![ | ||
| field("x", TableDataFieldType::String("a".to_owned())), | ||
| field("y", TableDataFieldType::String("bc".to_owned())), | ||
| ], | ||
| }; | ||
|
|
||
| let keys_a = row_index_keys(&row_a, &["x".to_owned(), "y".to_owned()]).unwrap(); | ||
| let keys_b = row_index_keys(&row_b, &["x".to_owned(), "y".to_owned()]).unwrap(); | ||
|
|
||
| assert_ne!( | ||
| keys_a, keys_b, | ||
| "different value splits must not collide: {:?} vs {:?}", | ||
| keys_a, keys_b | ||
| ); | ||
|
|
||
| // 조합된 B-tree 키도 충돌 없어야 함 (길이 프리픽스 인코딩) | ||
| assert_ne!( | ||
| join_composite_key(&keys_a), | ||
| join_composite_key(&keys_b), | ||
| "joined composite keys must not collide" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn composite_key_preserves_column_order() { | ||
| let row = TableDataRow { | ||
| fields: vec![ | ||
| field("a", TableDataFieldType::Integer(1)), | ||
| field("b", TableDataFieldType::Integer(2)), | ||
| ], | ||
| }; | ||
|
|
||
| let ab = row_index_keys(&row, &["a".to_owned(), "b".to_owned()]).unwrap(); | ||
| let ba = row_index_keys(&row, &["b".to_owned(), "a".to_owned()]).unwrap(); | ||
|
|
||
| assert_ne!(ab, ba, "column order must affect the key"); | ||
| // 컴포넌트는 field_to_key 원본 키 | ||
| assert_eq!(ab[0], field_to_key(&TableDataFieldType::Integer(1))); | ||
| assert_eq!(ab[1], field_to_key(&TableDataFieldType::Integer(2))); | ||
| assert_eq!(ba[0], field_to_key(&TableDataFieldType::Integer(2))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn row_with_null_in_indexed_column_is_not_indexed() { | ||
| let row = TableDataRow { | ||
| fields: vec![ | ||
| field("user_id", TableDataFieldType::Integer(1)), | ||
| field("group_id", TableDataFieldType::Null), | ||
| ], | ||
| }; | ||
|
|
||
| assert!( | ||
| row_index_keys(&row, &["user_id".to_owned(), "group_id".to_owned()]).is_none(), | ||
| "NULL이 포함된 복합 키는 색인하지 않음 (PostgreSQL과 동일)" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn row_missing_indexed_column_is_not_indexed() { | ||
| let row = TableDataRow { | ||
| fields: vec![field("user_id", TableDataFieldType::Integer(1))], | ||
| }; | ||
|
|
||
| assert!(row_index_keys(&row, &["user_id".to_owned(), "missing".to_owned()]).is_none()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_single_column_row_index_keys_matches_row_index_key() { | ||
| use crate::engine::actions::index::{join_composite_key, row_index_key, row_index_keys}; | ||
|
|
||
| let row = TableDataRow { | ||
| fields: vec![field("id", TableDataFieldType::Integer(42))], | ||
| }; | ||
|
|
||
| let via_multi = row_index_keys(&row, &["id".to_owned()]).unwrap(); | ||
| let via_single = row_index_key(&row, "id").unwrap(); | ||
|
|
||
| // 단일 컬럼 복합 키를 join하면 기존 row_index_key와 정확히 일치해야 함: | ||
| // 단일 인덱스 경로가 동일 키 공간(옵티마이저 eq_key 포함)을 유지하는 계약 (#220) | ||
| assert_eq!(join_composite_key(&via_multi), via_single); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.